Oracle
Provides price and liquidity data useful for a wide variety of system designs
Instances of stored oracle data, "observations", are collected in the oracle array Every pool is initialized with an oracle array length of 1. Anyone can pay the SSTOREs to increase the maximum length of the oracle array. New slots will be added when the array is fully populated. Observations are overwritten when the full length of the oracle array is populated. The most recent observation is available, independent of the length of the oracle array, by passing 0 to observe()
Functions
initialize
Initialize the oracle array by writing the first slot. Called once for the lifecycle of the observations array
Parameters:
self
struct Oracle.Observation[65535]
The stored oracle array
time
uint32
The time of the oracle initialization, via block.timestamp truncated to uint32
Return Values:
cardinality
uint16
The number of populated elements in the oracle array
cardinalityNext
uint16
The new length of the oracle array, independent of population
write
Writes an oracle observation to the array
Writable at most once per block. Index represents the most recently written element. cardinality and index must be tracked externally. If the index is at the end of the allowable array length (according to cardinality), and the next cardinality is greater than the current one, cardinality may be increased. This restriction is created to preserve ordering.
Parameters:
self
struct Oracle.Observation[65535]
The stored oracle array
index
uint16
The location of the most recently updated observation
blockTimestamp
uint32
The timestamp of the new observation
tick
int24
The active tick at the time of the new observation
liquidity
uint128
The total in-range liquidity at the time of the new observation
cardinality
uint16
The number of populated elements in the oracle array
cardinalityNext
uint16
The new length of the oracle array, independent of population
Return Values:
indexUpdated
uint16
The new index of the most recently written element in the oracle array
cardinalityUpdated
uint16
The new cardinality of the oracle array
grow
Prepares the oracle array to store up to next
observations
Parameters:
self
struct Oracle.Observation[65535]
The stored oracle array
current
uint16
The current next cardinality of the oracle array
next
uint16
The proposed next cardinality which will be populated in the oracle array
Return Values:
next
uint16
The next cardinality which will be populated in the oracle array
observe
Returns the accumulator values as of each time seconds ago from the given time in the array of secondsAgos
Reverts if secondsAgos
> oldest observation
Parameters:
self
struct Oracle.Observation[65535]
The stored oracle array
time
uint32
The current block.timestamp
secondsAgos
uint32[]
Each amount of time to look back, in seconds, at which point to return an observation
tick
int24
The current tick
index
uint16
The location of a given observation within the oracle array
liquidity
uint128
The current in-range pool liquidity
cardinality
uint16
The number of populated elements in the oracle array
Return Values:
tickCumulatives
int56[]
The tick * time elapsed since the pool was first initialized, as of each secondsAgo
liquidityCumulatives
uint160[]
The liquidity * time elapsed since the pool was first initialized, as of each secondsAgo
Last updated