Skip to main content

IV3CompatibleOracle

Git Source

Author: Axicon Labs Inc, credit to Uniswap Labs https://github.com/Uniswap/v3-core under GPL-2.0 license

This interface defines the set of functions called by Panoptic on its external oracle contract.

The interface is compatible with Uniswap V3 pools, but can also be implemented by a custom oracle contract.

Functions

slot0

The 0th storage slot in the oracle stores many values, and is exposed as a single method to save gas when accessed externally.

function slot0()
external
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16,
uint8,
bool
);

Returns

NameTypeDescription
sqrtPriceX96uint160The current price of the oracle as a sqrt(currency1/currency0) Q64.96 value
tickint24The current tick of the oracle, i.e. according to the last tick transition that was run. This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick boundary
observationIndexuint16The index of the last oracle observation that was written
observationCardinalityuint16The current maximum number of observations stored in the oracle
<none>uint16
<none>uint8
<none>bool

observations

Returns data about a specific observation index

function observations(uint256 index)
external
view
returns (uint32 blockTimestamp, int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128, bool initialized);

Parameters

NameTypeDescription
indexuint256The element of the observations array to fetch

Returns

NameTypeDescription
blockTimestampuint32The timestamp of the observation
tickCumulativeint56The tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp
secondsPerLiquidityCumulativeX128uint160The seconds per in range liquidity for the life of the pool as of the observation timestamp
initializedboolWhether the observation has been initialized and the values are safe to use

observe

Returns the cumulative tick and liquidity as of each timestamp secondsAgo from the current block timestamp

To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, you must call it with secondsAgos = [3600, 0].

The time weighted average tick represents the geometric time weighted average price of the pool, in log base sqrt(1.0001) of currency1 / currency0. The TickMath library can be used to go from a tick value to a ratio.

function observe(uint32[] calldata secondsAgos)
external
view
returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);

Parameters

NameTypeDescription
secondsAgosuint32[]From how long ago each cumulative tick and liquidity value should be returned

Returns

NameTypeDescription
tickCumulativesint56[]Cumulative tick values as of each secondsAgos from the current block timestamp
secondsPerLiquidityCumulativeX128suint160[]Cumulative seconds per liquidity-in-range value as of each secondsAgos from the current block timestamp

increaseObservationCardinalityNext

Increase the maximum number of price and liquidity observations that this oracle will store

function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;

Parameters

NameTypeDescription
observationCardinalityNextuint16The desired minimum number of observations for the oracle to store