i created a contract in Remix to get the reserves of a pair on Uniswap, and it works fine, but when i try to do the same thing using the Sushiswap factory address the function gives me a "LiquidityValueCalculator.pairInfo errored: execution reverted" error. Up to now using other contracts i have created a pair and added/removed liquidity in Uniswap and Sushiswap by changing only the factory address, but when it comes to get reserves it doesn't work. Where am i wrong?

Addresses used:

UniswapV2Factory: 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f

SushiV2Factory: 0xc35DADB65012eC5796536bD9864eD8773aBc74C4

// SPDX-License-Identifier: MIT
pragma solidity =0.6.6;

import "@uniswap/v2-periphery/contracts/libraries/UniswapV2Library.sol";
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";

contract LiquidityValueCalculator {

address public factory;
constructor(address factory_) public {
    factory = factory_;

function pairInfo(address tokenA, address tokenB) public view returns (uint reserveA, uint reserveB, uint totalSupply) {
    IUniswapV2Pair pair = IUniswapV2Pair(UniswapV2Library.pairFor(factory, tokenA, tokenB));
    totalSupply = pair.totalSupply();
    (uint reserves0, uint reserves1,) = pair.getReserves();
    (reserveA, reserveB) = tokenA == pair.token0() ? (reserves0, reserves1) : (reserves1, reserves0);


2 Answers 2


The SushiV2Factory address you provided seem to be some Access control contract, not the factory. That is probably the cause of your error.

You probably ment SushiV2Factory: 0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac

  • Sorry I forgot to specify, it's the testnet address, actually i'm using Goerli network, i've also tried with the mainnet address but doesn't work. The only way to make it work is to import UniswapV2Library.sol and IUniswapV2Pair.sol from Sushiswap repository instead of Uniswap ones, but i don't understand why and it doesn't solve my problem since I want to recover the reserves with a single contract.
    – MattC
    Jan 17, 2023 at 13:21
  • I see, which tokens did you use as a pair?
    – Nal Luksic
    Jan 17, 2023 at 13:32
  • And if I'm not mistaken both of the addresses point to separate instances of UniswapV2Factory on goerli?
    – Nal Luksic
    Jan 17, 2023 at 13:36
  • Just two compliant ERC20 tokens generated by me, I created two pools containing them, one on Uniswap and one on Sushiswap.
    – MattC
    Jan 17, 2023 at 13:44
  • I mean looking at the two contracts you supplied, the getReserves() method looks the same. Can you provide the address of your contract and exact parameters you use, so I am able to replicate the issue?
    – Nal Luksic
    Jan 17, 2023 at 13:46

i have spotted the problem, the pure function UniswapV2Library.pairFor used to obtain the address of the pair is different between the Uniswap and Sushiswap repositories, it uses different values inside(hex), for this reason if i use the Uniswap repository with the Sushiswap factory address i get a non-existent pair address. So the solution is to use the correct values in the UniswapV2Library.pairFor function depending on whether you are querying a pair of Uniswap or Sushiswap using their respective factory addresses.

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.