1

The two tokens have been approve to the router contract, but they always fail when the addLiquidity method is called. "false Transaction mined but execution failed" is displayed in remix. Transaction hash: https://kovan.etherscan.io/tx/0x918668d3b0218cf8861b48a5b763ad5ffdd1cb35b4629a0ce44886141a2bbe0d enter image description here enter image description here

1
  • After looking at the internal transaction it seems the contract breaks after at IUniswapV2Pair(pair).initialize(token0, token1) from UniswapV2Factory.createPair and before TransferHelper.safeTransferFrom at UniswapV2Router02.addLiquidity. The only place that look suspiciuos is pairFor called from getReserves. It uses a hash that depends on the compiled contract.
    – Ismael
    Commented Feb 26, 2021 at 3:51

1 Answer 1

0

I met the exact same issue and spent 5 hours to finally found the root cause.

addLiquidity invokes _addLiquidity and then fails at:

(uint reserveA, uint reserveB) = UniswapV2Library.getReserves(factory, tokenA, tokenB);

Inside getReserves it calls pairFor(factory, tokenA, tokenB).

The author didn't update the init code hash which is used to calculate the pair address, cauing IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves() revert because the pair not found.

This often happens when you deploy your own Uniswap and forget to update INIT_CODE_HASH.

1
  • hi bai Bing, I think I am facing the same problem. Can you explain hoy can I update INIT_CODE_HASH? Commented Jul 11, 2023 at 13:01

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.