DataStorageOperator

DataStorageOperator

DataStorageOperator

Algebra timepoints data operator

This contract stores timepoints and calculates adaptive fee and statistical averages

Modifiers

onlyPool

modifier onlyPool() internal

Variables

struct DataStorage.Timepoint[65536] timepoints

Returns data belonging to a certain timepoint

Developer note: There is more convenient function to fetch a timepoint: getTimepoints(). Which requires not an index but seconds

struct AlgebraFeeConfiguration feeConfigZtO

struct AlgebraFeeConfiguration feeConfigOtZ

bytes32 FEE_CONFIG_MANAGER constant

Developer note: The role can be granted in AlgebraFactory

Functions

constructor

constructor(address _pool) public public

NameTypeDescription
_pooladdress

initialize

function initialize(uint32 time, int24 tick) external external

Initialize the dataStorage array by writing the first slot. Called once for the lifecycle of the timepoints array

NameTypeDescription
timeuint32The time of the dataStorage initialization, via block.timestamp truncated to uint32
tickint24Initial tick

changeFeeConfiguration

function changeFeeConfiguration(bool zto, struct AlgebraFeeConfiguration _config) external external

Changes fee configuration for the pool

NameTypeDescription
ztobool
_configstruct AlgebraFeeConfiguration

getSingleTimepoint

function getSingleTimepoint(uint32 time, uint32 secondsAgo, int24 tick, uint16 lastIndex) external view returns (int56 tickCumulative, uint112 volatilityCumulative) view external

Developer note: Reverts if a timepoint at or before the desired timepoint timestamp does not exist. 0 may be passed as `secondsAgo' to return the current cumulative values. If called with a timestamp falling between two timepoints, returns the counterfactual accumulator values at exactly the timestamp between the two timepoints.

NameTypeDescription
timeuint32The current block timestamp
secondsAgouint32The amount of time to look back, in seconds, at which point to return a timepoint
tickint24The current tick
lastIndexuint16

Returns:

NameTypeDescription
tickCumulativeint56The cumulative tick since the pool was first initialized, as of `secondsAgo`
volatilityCumulativeuint112The cumulative volatility value since the pool was first initialized, as of `secondsAgo`

getTimepoints

function getTimepoints(uint32[] secondsAgos) external view returns (int56[] tickCumulatives, uint112[] volatilityCumulatives) view external

Returns the accumulator values as of each time seconds ago from the given time in the array of `secondsAgos` Developer note: Reverts if `secondsAgos` > oldest timepoint

NameTypeDescription
secondsAgosuint32[]Each amount of time to look back, in seconds, at which point to return a timepoint

Returns:

NameTypeDescription
tickCumulativesint56[]The cumulative tick since the pool was first initialized, as of each `secondsAgo`
volatilityCumulativesuint112[]The cumulative volatility values since the pool was first initialized, as of each `secondsAgo`

write

function write(uint16 index, uint32 blockTimestamp, int24 tick) external returns (uint16 indexUpdated, uint16 newFeeZtO, uint16 newFeeOtZ) external

Writes a dataStorage timepoint to the array Developer note: Writable at most once per block. Index represents the most recently written element. index must be tracked externally.

NameTypeDescription
indexuint16The index of the timepoint that was most recently written to the timepoints array
blockTimestampuint32The timestamp of the new timepoint
tickint24The active tick at the time of the new timepoint

Returns:

NameTypeDescription
indexUpdateduint16The new index of the most recently written element in the dataStorage array
newFeeZtOuint16The fee for ZtO swaps in hundredths of a bip, i.e. 1e-6
newFeeOtZuint16The fee for OtZ swaps in hundredths of a bip, i.e. 1e-6

prepayTimepointsStorageSlots

function prepayTimepointsStorageSlots(uint16 startIndex, uint16 amount) external external

Fills uninitialized timepoints with nonzero value Developer note: Can be used to reduce the gas cost of future swaps

NameTypeDescription
startIndexuint16The start index, must be not initialized
amountuint16of slots to fill, startIndex + amount must be <= type(uint16).max