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

static-callable opinionated oracle contract

Open moodysalem opened this issue 3 years ago • 2 comments

we need an easy to use deployed contract for quoting some token amount using the v3 oracles. this is fairly easy to build using our existing oracle libraries

we can choose 4 levels of manipulation resistance - strong, medium, weak, dangerous and have a single method on this contract (dangerous would refer to "spot" pricing as of the block start, see https://github.com/Uniswap/uniswap-v3-periphery/issues/158)

enum ManipulationResistance {
  strong, medium, weak, dangerous
}

two methods

prepare(address tokenA, address tokenB) external

this sets up the observation cardinality for the opinionated implementation of the oracle

quote(address baseToken, address quoteToken, uint256 baseTokenAmount, ManipulationResistance resistance) view returns (uint256 quoteTokenAmount)

unknowns:

  • how to handle new (unprepared) pool fee tier creation
  • what opinionated aggregation across fee pools to use (highest harmonic mean liquidity, or weighted by harmonic mean liquidity)
  • what opinionated periods to use for strong/medium/weak
  • upgradeability?

moodysalem avatar Aug 12 '21 15:08 moodysalem

for new fee tiers, this oracle contract can support permissionless addition of the fee tier to the ones it considers. this would increase the gas cost for all future calls to the oracle since it has to consider the new fee tiers, so it may be important to allow specifying the pool fee tiers to consider instead of using all of them

moodysalem avatar Sep 08 '21 18:09 moodysalem

some doc links

startedAt and timestamp may be something like the block.timestamp - secondsAgo and block.timestamp for our oracle https://docs.chain.link/docs/get-the-latest-price/

probably not necessary for the static callable contract, but it allows you to get historical prices. we could implement this in a callable contract that stores and creates round ids when you query it https://docs.chain.link/docs/historical-price-data/

moodysalem avatar Sep 08 '21 18:09 moodysalem