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

    BigNumber.from(0), // don't know how to calculate this
    BigNumber.from(0), // don't know how to calculate this
      gasLimit: process.env.GAS_LIMIT,
      gasPrice: 20e9,
  • what does balanceOf return for your LP token?
    – Huge
    Jun 21 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.