I am developing a token using ganache
/brownie
. As the title says, if I try and use removeLiquidityETH
to test removing liquidity tokens, for example like this
pair.approve(pair_address, lp_balance, {'from':accounts[0]})
router.removeLiquidityETH(my_token.address,lp_balance, 0,0, accounts[0], int(time.time())+60, {'from': accounts[0]})
Then I get an error
IUniswapV2Router02.removeLiquidityETH confirmed (ds-math-sub-underflow)
and I do not see the ETH back in accounts[0]
.
However, looking at how removeLiquidityETH
works I can implement each step manually
pair.approve(pair_address, lp_balance, {'from':accounts[0]})
pair.transferFrom(accounts[0], pair_address, lp_balance, {'from': pair_address})
tx = pair.burn(accounts[0], {'from': pair_address})
interface.IWETH(router.WETH()).withdraw(tx.events['Burn']['amount1'], {'from':accounts[0]})
And everything works as intended with my ETH
and MyToken
balances being transferred back to accounts[0]
.
I think the error is somewhere in approve
or the transaction params {'from'}
but I have tried every combination I can think of with pair.approve
router.approve
and my_token.approve
and I still get the same error.
Does anyone have an example of how to use removeLiquidityETH
properly? I have no issues with addLiquidityETH
, in which I just use MyToken
to approve
the router
spending.