我在Remix中创建了一份合同,以便在Uniswap上获得一对备份,它工作得很好,但是当我尝试使用Sushiswap工厂地址做同样的事情时,函数会给我一个"LiquidityValueCalculator.pairInfo错误:执行恢复“错误。到目前为止,我只通过更改工厂地址,在Uniswap和Sushiswap中创建了一对合同,并增加/消除了流动性,但当涉及到获得准备金时,它就行不通了。我哪里错了?
使用的地址:
UniswapV2Factory: 0x5C69bEe701 ef814a2B6a3EDD4B1652CB9cc5a6f
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);
}
}发布于 2023-01-17 16:59:49
我注意到了这个问题,用于获得这对地址的纯函数UniswapV2Library.pairFor在Uniswap和Sushiswap存储库之间是不同的,它在内部使用不同的值(十六进制),因此,如果我使用带有Sushiswap工厂地址的Uniswap存储库,就会得到一个不存在的对地址。因此,解决方案是在UniswapV2Library.pairFor函数中使用正确的值,这取决于您是使用各自的工厂地址查询一对Uniswap还是Sushiswap。
发布于 2023-01-17 12:05:15
您提供的SushiV2Factory地址似乎是一些访问控制合同,而不是工厂。这可能是你的错误的原因。
您可能使用SushiV2Factory: 0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac
https://ethereum.stackexchange.com/questions/143134
复制相似问题