Getting error when attempting to remove liquidity via removeLiquidityETH (ds-math-sub-underflow)

Hi all,

Im trying to understand Uniswap better to learn more about DeFi so I’ve created a test token, created an LP for it, and added liq. However, when I try to remove the liq I get the following error: ‘ds-math-sub-underflow’. An underflow is obviously happening during a math operation but Im not sure whats causing it (dont worry, im not trying to rugpull, this is purely for personal learning purposes… I find defi fascinating and want to figure out how it works from top to bottom)

I created my LP by calling the router (on testnet) function addLiquidityETH with the following parameters:

  • token: My test token address

  • amountTokenDesired: 1000

  • amountETHDesired: 1

  • amountTokenMin: 0

  • amountETHMin: 0

  • to: My external test account

And heres how I try to withdraw the LP by calling removeLiquidityETH:

  • token: My test token address

  • liquidity: number of LP tokens that were created in the addLiquidityETH call

  • amountTokenMin: 0

  • amountETHMin: 0

  • to: My external test account

Any assistance would be appreciated, thanks!

4 Likes

Have you answered this question yet? I am having the exact same problem on a UniswapLP pool. Did you try varying amounts of the UniLP token? Were the decimals correct?

Try approving the LP tokens first for the contract that is spending it. This might be the issue actually but being masked by the overflow error

Basically it's a matter of approval and token transfers.

But we can't help you without you posting the code.

1 Like

Hey @glooty, welcome to the community.

I agree with the need for a code sample from your side to fully understand what are you trying to do and what is the math behind providing you an answer, but we haven't heard from you in a while, so I'm closing this thread.

Feel free to re-open another one if you still have the same question since I think it'd be an interesting learning exercise to be posted here in the forum, but please follow these guidelines for asking questions.