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:
Name | Type | Description |
---|---|---|
| struct Oracle.Observation[65535] | The stored oracle array |
| uint32 | The time of the oracle initialization, via block.timestamp truncated to uint32 |
Return Values:
Name | Type | Description |
---|---|---|
| uint16 | The number of populated elements in the oracle array |
| 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:
Name | Type | Description |
---|---|---|
| struct Oracle.Observation[65535] | The stored oracle array |
| uint16 | The location of the most recently updated observation |
| uint32 | The timestamp of the new observation |
| int24 | The active tick at the time of the new observation |
| uint128 | The total in-range liquidity at the time of the new observation |
| uint16 | The number of populated elements in the oracle array |
| uint16 | The new length of the oracle array, independent of population |
Return Values:
Name | Type | Description |
---|---|---|
| uint16 | The new index of the most recently written element in the oracle array |
| uint16 | The new cardinality of the oracle array |
grow
Prepares the oracle array to store up to next
observations
Parameters:
Name | Type | Description |
---|---|---|
| struct Oracle.Observation[65535] | The stored oracle array |
| uint16 | The current next cardinality of the oracle array |
| uint16 | The proposed next cardinality which will be populated in the oracle array |
Return Values:
Name | Type | Description |
---|---|---|
| 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:
Name | Type | Description |
---|---|---|
| struct Oracle.Observation[65535] | The stored oracle array |
| uint32 | The current block.timestamp |
| uint32[] | Each amount of time to look back, in seconds, at which point to return an observation |
| int24 | The current tick |
| uint16 | The location of a given observation within the oracle array |
| uint128 | The current in-range pool liquidity |
| uint16 | The number of populated elements in the oracle array |
Return Values:
Name | Type | Description |
---|---|---|
| int56[] | The tick * time elapsed since the pool was first initialized, as of each |
| uint160[] | The liquidity * time elapsed since the pool was first initialized, as of each |
Last updated