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
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
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.
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.
amountAMin = liquidity*reserve0/totalSupply
amountBMin = liquidity*reserve1/totalSupply
Link is dead; so re-posted from UniswapV2Router02.sol screen shot below: