The Uniswap oracle uses a mock contract with hard-coded prices to retrieve the price, which is not feasible in production. Also, note that even when using the real deal @uniswap/v3-periphery/contracts/libraries/OracleLibrary.sol it does not, in fact, return the prices.
The price could change from the set price. Meanwhile, always updating new prices with set will be too slow and gas expensive.
Recommend using cumulativeTicks = pool.observe([secondsAgo, 0]) // [a_t1, a_t2] and applying equation 5.5 from the Uniswap V3 whitepaper to compute the token0 TWAP.
Note that even the official .consult call seems to only return the averaged cumulative ticks; youd still need to compute the 1.0001^timeWeightedAverageTick in the function.
albertocuestacanada (Yield) acknowledged:
albertocuestacanada (Yield) commented:
