1

I'm trying to redeem my LP tokens with ethersJS and Uniswap's Router02 contract. How do I calculate the arguments amountAMin and amountAMin for the function linked below?

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

3 Answers 3

0

The amountAMin is parameter is present to prevent a sandwich attack on your transaction.

Lets say that, you have 1 share to a uniswap v2 pair which gives 1.1 ETH and 2200 DAI.

If you pass a value for e.g. 1 ETH to the amountAMin when calling remove liquidity, then the Router contract will make sure that ETH sent to you is >= 1 ETH. And if there is a sandwich attack that changes price of ETH such that you now get only 0.9 ETH, then for safety the Router contract will purposely revert the transaction.

0

You need token balances and total supply of the liquidity pair, let's me share - example gist

It uses real token addresses from Cronos mainnet.

0

amountAMin = liquidity*reserve0/totalSupply

amountBMin = liquidity*reserve1/totalSupply

Link is dead; so re-posted from UniswapV2Router02.sol screen shot below:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.