address routerAddress = 0x7a250d5630b4cf539739df2c5dacb4c659f2488d;
address _WETH = address(0);
function setWETHOnChain(address routerAddress) external {
IUniswapV2Router02 router = IUniswapV2Router02(routerAddress);
_WETH = router.WETH();
}
This line of code no matter what will revert upon execution, to my surprise.
Remix debugger said _WETH = router.WETH();
is the last executed statement before revert.
I also have problems with @uniswap/v2-periphery/contracts/libraries/UniswapV2Library.sol@uniswap/v2-periphery/contracts/libraries/UniswapV2Library.sol
, specifically getReserve()getReserve()
.
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);
}
I would always revert on this line. (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
, directly after pairFor()pairFor()
has returned successfully.
I tried the first code on Solidity 0.6.12, 0.7.6, and 0.8.7 without any success.
The weirdest thing is, querying such values using a block explorer or an EOA using Ethers.js works just fine.