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
1 Answer
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.
-
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
IUniswapV2Pair(pair).initialize(token0, token1)
from UniswapV2Factory.createPair and beforeTransferHelper.safeTransferFrom
atUniswapV2Router02.addLiquidity
. The only place that look suspiciuos ispairFor
called from getReserves. It uses a hash that depends on the compiled contract.