Uniswap / v3-periphery

🦄 🦄 🦄 Peripheral smart contracts for interacting with Uniswap v3
https://uniswap.org
GNU General Public License v2.0
1.17k stars 1.09k forks source link

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

Open Developer5600 opened 2 years ago

Developer5600 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.