v3-periphery icon indicating copy to clipboard operation
v3-periphery copied to clipboard

Using Oracle Library to consult WETH-USDC Pool from Ropsten always reverts

Open Developer5600 opened this issue 3 years ago • 2 comments
trafficstars

My transaction always reverts with this contract.

pragma solidity >=0.5.0 <0.8.0;
import "https://raw.githubusercontent.com/Uniswap/v3-periphery/main/contracts/libraries/OracleLibrary.sol";

contract USDCPriceOracle {
  address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
  //address WETHUSDCPool = 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640;
  address WETHUSDCPool = 0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8; //?? linked from uniswap
  
  address WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
  
  function getEthPriceTick() public view returns (int24 arithmeticMeanTick, uint128 harmonicMeanLiquidity) {
    return OracleLibrary.consult(WETHUSDCPool, 32);
  }

I have tried both of these for pools: //address WETHUSDCPool = 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640; from https://etherscan.io/address/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640#readContract -- this looks like the right pool from searching

address WETHUSDCPool = 0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8; //?? linked from uniswap from https://info.uniswap.org/#/pools/0x8ad599c3a0ff1de082011efddc58f1908eb6e6d -- this one I get from UNISWAP

but both pool addresses revert on this line

       (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) =
            IUniswapV3Pool(pool).observe(secondsAgos);

which the docs say will revert if there are no reserves available.

What's wrong with my code?

How can I consult the V3 Pool on Ropsten for Price Oracle? I need this to work on Ropsten before I deploy a mainnet! Is there another reliable Oracle contract I can use?

Developer5600 avatar Apr 07 '22 23:04 Developer5600

The info I was getting from uniswap was a mainnet pool despite being connected to Ropsten in my metamask. Hm. How do I find the pool for WETH-USDC on Ropsten?

Developer5600 avatar Apr 07 '22 23:04 Developer5600

I found https://ropsten.etherscan.io/address/0x1F98431c8aD98523631AE4a59f267346ea31F984#code and using values 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 (USDC Ropsten) 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 (WETH Ropsten) and 3000 for the pool rate I got "0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8"

this still always reverts.

Developer5600 avatar Apr 07 '22 23:04 Developer5600