DataStorageOperator

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 AdaptiveFee.Configuration feeConfigZto

struct AdaptiveFee.Configuration feeConfigOtz

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 AdaptiveFee.Configuration _feeConfig) external external

Changes fee configuration for the pool

NameTypeDescription
ztobool
_feeConfigstruct AdaptiveFee.Configuration

getSingleTimepoint

function getSingleTimepoint(uint32 time, uint32 secondsAgo, int24 tick, uint16 index, uint128 liquidity) external view returns (int56 tickCumulative, uint160 secondsPerLiquidityCumulative, uint112 volatilityCumulative, uint256 volumePerAvgLiquidity) view external

Developer note: Reverts if an 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 an timepoint
tickint24The current tick
indexuint16The index of the timepoint that was most recently written to the timepoints array
liquidityuint128The current in-range pool liquidity

Returns:

NameTypeDescription
tickCumulativeint56The cumulative tick since the pool was first initialized, as of `secondsAgo`
secondsPerLiquidityCumulativeuint160The cumulative seconds / max(1, liquidity) since the pool was first initialized, as of `secondsAgo`
volatilityCumulativeuint112The cumulative volatility value since the pool was first initialized, as of `secondsAgo`
volumePerAvgLiquidityuint256The cumulative volume per liquidity value since the pool was first initialized, as of `secondsAgo`

getTimepoints

function getTimepoints(uint32 time, uint32[] secondsAgos, int24 tick, uint16 index, uint128 liquidity) external view returns (int56[] tickCumulatives, uint160[] secondsPerLiquidityCumulatives, uint112[] volatilityCumulatives, uint256[] volumePerAvgLiquiditys) 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
timeuint32The current block.timestamp
secondsAgosuint32[]Each amount of time to look back, in seconds, at which point to return an timepoint
tickint24The current tick
indexuint16The index of the timepoint that was most recently written to the timepoints array
liquidityuint128The current in-range pool liquidity

Returns:

NameTypeDescription
tickCumulativesint56[]The cumulative tick since the pool was first initialized, as of each `secondsAgo`
secondsPerLiquidityCumulativesuint160[]The cumulative seconds / max(1, liquidity) 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`
volumePerAvgLiquiditysuint256[]The cumulative volume per liquidity values since the pool was first initialized, as of each `secondsAgo`

getAverages

function getAverages(uint32 time, int24 tick, uint16 index, uint128 liquidity) external view returns (uint112 TWVolatilityAverage, uint256 TWVolumePerLiqAverage) view external

Returns average volatility in the range from time-WINDOW to time

NameTypeDescription
timeuint32The current block.timestamp
tickint24The current tick
indexuint16The index of the timepoint that was most recently written to the timepoints array
liquidityuint128The current in-range pool liquidity

Returns:

NameTypeDescription
TWVolatilityAverageuint112The average volatility in the recent range
TWVolumePerLiqAverageuint256The average volume per liquidity in the recent range

write

function write(uint16 index, uint32 blockTimestamp, int24 tick, uint128 liquidity, uint128 volumePerLiquidity) external returns (uint16 indexUpdated) external

Writes an 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
liquidityuint128The total in-range liquidity at the time of the new timepoint
volumePerLiquidityuint128The gmean(volumes)/liquidity at the time of the new timepoint

Returns:

NameTypeDescription
indexUpdateduint16The new index of the most recently written element in the dataStorage array

calculateVolumePerLiquidity

function calculateVolumePerLiquidity(uint128 liquidity, int256 amount0, int256 amount1) external pure returns (uint128 volumePerLiquidity) pure external

Calculates gmean(volume/liquidity) for block

NameTypeDescription
liquidityuint128The current in-range pool liquidity
amount0int256Total amount of swapped token0
amount1int256Total amount of swapped token1

Returns:

NameTypeDescription
volumePerLiquidityuint128gmean(volume/liquidity) capped by 100000 << 64

window

function window() external pure returns (uint32) pure external

Returns:

NameTypeDescription
[0]uint32

getFees

function getFees(uint32 _time, int24 _tick, uint16 _index, uint128 _liquidity) external view returns (uint16 feeZto, uint16 feeOtz) view external

Calculates fee based on combination of sigmoids

NameTypeDescription
_timeuint32
_tickint24
_indexuint16
_liquidityuint128

Returns:

NameTypeDescription
feeZtouint16The fee for ZtO swaps in hundredths of a bip, i.e. 1e-6
feeOtzuint16The fee for OtZ swaps in hundredths of a bip, i.e. 1e-6