Skip to main content

GeometricBWAP

Git Source

State Variables

MINIMUM_LONG_TERM_INTERVAL

uint8 public constant MINIMUM_LONG_TERM_INTERVAL = 16;

MID_TERM_ARRAY_LENGTH

uint8 public constant MID_TERM_ARRAY_LENGTH = 65;

LONG_TERM_ARRAY_LENGTH

uint8 public constant LONG_TERM_ARRAY_LENGTH = 9;

MID_TERM_ARRAY_LAST_INDEX

uint8 private constant MID_TERM_ARRAY_LAST_INDEX = MID_TERM_ARRAY_LENGTH - 1;

LONG_TERM_ARRAY_LAST_INDEX

uint8 private constant LONG_TERM_ARRAY_LAST_INDEX = LONG_TERM_ARRAY_LENGTH - 1;

Functions

initialObservationStruct

function initialObservationStruct(Observations storage self, uint24 longTermIntervalConfig) internal;

configLongTermInterval

Configures the size of long-term block observations.

This function is used to set the long-term block observations for the long term buffer. It ensures that the provided longTermIntervalSize value is greater than 64.

function configLongTermInterval(Observations storage self, uint24 newInterval) internal;

Parameters

NameTypeDescription
selfObservationsThe storage reference to the Observations struct.
newIntervaluint24The desired number of blocks for each long-term period. The size is set larger than the midTerm to ensure a sufficient buffer, requiring a minimum of 16 blocks per period. A minimum of 16 blocks per period is necessary, resulting in a total of 128 blocks (16 * 8) for the long-term buffer.

recordObservation

Records a new observation tick value and updates the observation data.

This function is used to record new observation data for the contract. It ensures that the provided tick value is stored appropriately in both mid-term and long-term observations, updates interval counters, and handles tick cumulative values based on the current interval configuration. Ensures that this function is called in chronological order, with increasing block numbers. Reverting is triggered if the provided block number is less than or equal to the last recorded block number.

function recordObservation(Observations storage self, int24 newTick) internal;

Parameters

NameTypeDescription
selfObservationsThe storage structure containing observation data.
newTickint24The new tick value to be recorded, representing the most recent update of reserveX and reserveY.

getTickRange

Gets the min and max range of tick values from the stored oracle observations.

This function calculates the minimum and maximum tick values among three observed ticks: long-term tick, mid-term tick, and current tick.

function getTickRange(Observations storage self) internal view returns (int24 minTick, int24 maxTick);

Parameters

NameTypeDescription
selfObservationsThe observation struct where stored oracle array containing the tick observations.

Returns

NameTypeDescription
minTickint24The minimum tick value among the three observed ticks.
maxTickint24The maximum tick value among the three observed ticks.

getObservedTicks

Retrieves the long-term, mid-term, and current tick values based on the stored observations.

function getObservedTicks(Observations storage self) internal view returns (int24, int24, int24);

Parameters

NameTypeDescription
selfObservationsThe observation struct.

Returns

NameTypeDescription
<none>int24The long-term, mid-term, and last tick values.
<none>int24
<none>int24

getLastIndex

function getLastIndex(uint8 index, uint8 lastIndex) private pure returns (uint8);

Errors

AmmalgamInvalidLongTermInterval

error AmmalgamInvalidLongTermInterval();

AmmalgamBlockNumberValidationFailed

error AmmalgamBlockNumberValidationFailed();

AmmalgamLongTermBufferIsNotInitialized

error AmmalgamLongTermBufferIsNotInitialized();

Structs

Observations

Struct for storing observations related to the Geometric BWAP calculation.

This struct holds various data points used in the Block-Weighted Average Price (BWAP) calculation.

struct Observations {
uint8 midTermIndex;
uint8 longTermIndex;
int24 lastTick;
int24 midTermIntervalDelta;
int24 longTermIntervalDelta;
uint24 longTermIntervalConfig;
uint24 longTermActiveBlockCounter;
uint24[MID_TERM_ARRAY_LENGTH] midTermObservationInterval;
uint24[LONG_TERM_ARRAY_LENGTH] longTermObservationInterval;
int56[MID_TERM_ARRAY_LENGTH] midTerm;
int56[LONG_TERM_ARRAY_LENGTH] longTerm;
uint256 lastBlock;
}