He implementado la función de enrutador Uniswap v2 llamada
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);Lo implementé así...
function swapTokensForExactEthTest( uint256 _amountOut, address _tokenIn, uint256 _amountInMax, address _to ) external { IERC20(_tokenIn).transferFrom(msg.sender, address(this), _amountInMax); IERC20(_tokenIn).approve(UNISWAP_ROUTER_ADDRESS, _amountInMax); address[] memory path; path = new address[](2); path[0] = _tokenIn; path[1] = WETH; IUniswapV2Router01(UNISWAP_ROUTER_ADDRESS).swapTokensForExactETH( _amountOut, _amountInMax, path, _to, block.timestamp ); }y probando asi...
//WBTC_WHALE=0xF977814e90dA44bFA03b6295A0616a897441aceC const WHALE = process.env.WBTC_WHALE; const AMOUNT_OUT_MIN = 1; const TOKEN_IN = WBTC; //0x2260fac5e5542a773aa44fbcfedf7c193bc2c599 const AMOUNT_IN = 100000000; it('should swap tokens for exact eth', async()=>{ tokenIn = await IERC20.at(TOKEN_IN); testUniswap = await TestUniswap.new(); await testUniswap.swapTokensForExactEthTest( AMOUNT_OUT_MIN, tokenIn.address, AMOUNT_IN, accounts[0], { from: WHALE } ); console.log(`sent ${balanceOf(accounts[0])}`); });Mi problema es que cuando lo pruebo como el código de prueba anterior, me sale...
Error: Returned error: VM Exception while processing transaction: revertCogí el error usando remix. El error se debe al limite de gas y dice...
Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Gas estimation: 0x2dc6c0 Gas limit: 0x2dc6c0más específicamente...
code -3200 "message": "VM Exception while processing transaction: revert"No puedo entender cómo resolverlo. Alguien por favor ayuda.
Alguien por favor ayuda.