I'm trying to fork uniswap in Remix, and I did those steps until now:

  1. Deployed core contract - uniswap factory
  2. Deployed WETH contract (got the code from WETH contract on https://rinkeby.etherscan.io/address/0xc778417e063141139fce010982780140aa0cd5ab#code)
  3. Before moving to periphery got the init code from UniswapV2Pair.sol(in uniswap core repo). For that, compiled it and copied the byte code and used https://emn178.github.io/online-tools/keccak_256.html to get the init code. Changed the init code in UniswapV2Library in periphery with new value.
  4. Deployed UniswapV2Router02.sol with my factory and weth addresses
  5. Deployed 2 ERC20 tokens (tokenA and tokenB)
  6. Approved the Router address to spend all the token balance in both tokens
  7. Trying to call addLiquidity in Router and getting this error: AddLiquidity error

Can anybody help me? What am I missing here?


I just ran debug and found out that the Revert occurs inside UniswapV2Library (periphery) at getReserves() function:

    // fetches and sorts the reserves for a pair
    function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
        (address token0,) = sortTokens(tokenA, tokenB);
        (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
        (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);

The Revert occurs on the second line of this function, to be more precise.

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.