I am able to add liquidity and remove liquidity on uniswap, but I am having trouble calculating the min values for the token pairs.
For removing liquidity I am trying to get the amount of each token by doing the following:
const pathA = [liquidityToken.address, tokenA.address];
const amountsA = await uniswap.getAmountsOut(liquidityAmount, pathA);
const desiredAmtA = amountsA[1];
const pathB = [liquidityToken.address, tokenB.address];
const amountsB = await uniswap.getAmountsOut(liquidityAmount, pathA);
const desiredAmtB = amountsB[1];
This is throwing an error, but I'm not sure how to get the amount of tokena/b that my liquidity token represents. And consequently, I"m trying to calculate the min from it like this. I don't understand how these slippage tolerances get calculated.
const minAmtA = desiredAmtA.mul(BigNumber.from(9)).div(BigNumber.from(10));
const minAmtB = desiredAmtB.mul(BigNumber.from(9)).div(BigNumber.from(10));
It works when I put 0, but obviously I don't want 100% slippage
tokenA.address,
tokenB.address,
liquidityAmount,
BigNumber.from(0), // don't know how to calculate this
BigNumber.from(0), // don't know how to calculate this
wallet.address,
deadline,
{
gasLimit: process.env.GAS_LIMIT,
gasPrice: 20e9,
}
);