0
votes

So I am removing some liquidity from a ERC20>ETH pool but I want to store the ETH amount that I get when removing the liquidity.

function removeETHLiquidityFromToken() public {

// approve token
IERC20(tokenAddressLP).approve(UNISWAP_ROUTER_ADDRESS, IERC20(tokenAddressLP).balanceOf(address(this)));

// remove liquidity
uniswapRouter.removeLiquidityETH(tokenAddress, IERC20(tokenAddressLP).balanceOf(address(this)), 0, 0, address(this), now + 20);

// I want to use the ETH value later in this function

}

This works perfectly fine, it removes the liquidity.

But how can I get that amount of ETH so I can use it after?

https://uniswap.org/docs/v2/smart-contracts/router02/#removeliquidityeth

1

1 Answers

0
votes

The function returns two values. external returns (uint amountToken, uint amountETH);

Therefore you could identify a uint ethReceived; and assign the second uint returned to it like this:

( ,ethReceived) = uniswapRouter.removeLiquidityETH(tokenAddress, IERC20(tokenAddressLP).balanceOf(address(this)), 0, 0, address(this), now + 20);