Skip to main content

PositionBalanceLibrary

Git Source

Author: Axicon Labs Limited

Functions

storeBalanceData

Create a new PositionBalance given by positionSize, utilizations, and its tickData.

function storeBalanceData(uint128 _positionSize, uint32 _utilizations, uint96 _tickData)
internal
pure
returns (PositionBalance);

Parameters

NameTypeDescription
_positionSizeuint128The amount of option minted
_utilizationsuint32Packing of two uint16 utilizations into a 32 bit word
_tickDatauint96Packing of 4 int25s into a single uint96

Returns

NameTypeDescription
<none>PositionBalanceThe new PositionBalance with the given positionSize, utilization, and tickData

packTickData

Concatenate all oracle ticks into a single uint96.

function packTickData(int24 _currentTick, int24 _fastOracleTick, int24 _slowOracleTick, int24 _lastObservedTick)
internal
pure
returns (uint96);

Parameters

NameTypeDescription
_currentTickint24The current tick
_fastOracleTickint24The fast Oracle tick
_slowOracleTickint24The slow Oracle tick
_lastObservedTickint24The last observed tick

Returns

NameTypeDescription
<none>uint96A 96bit word concatenating all 4 input ticks

lastObservedTick

Get the last observed tick of self.

function lastObservedTick(PositionBalance self) internal pure returns (int24);

Parameters

NameTypeDescription
selfPositionBalanceThe PositionBalance to retrieve the last observed tick from

Returns

NameTypeDescription
<none>int24The last observed tick of self

slowOracleTick

Get the slow oracle tick of self.

function slowOracleTick(PositionBalance self) internal pure returns (int24);

Parameters

NameTypeDescription
selfPositionBalanceThe PositionBalance to retrieve the slow oracle tick from

Returns

NameTypeDescription
<none>int24The slow oracle tick of self

fastOracleTick

Get the fast oracle tick of self.

function fastOracleTick(PositionBalance self) internal pure returns (int24);

Parameters

NameTypeDescription
selfPositionBalanceThe PositionBalance to retrieve the fast oracle tick from

Returns

NameTypeDescription
<none>int24The fast oracle tick of self

currentTick

Get the current tick of self.

function currentTick(PositionBalance self) internal pure returns (int24);

Parameters

NameTypeDescription
selfPositionBalanceThe PositionBalance to retrieve the current tick from

Returns

NameTypeDescription
<none>int24The current tick of self

tickData

Get the tickData of self.

function tickData(PositionBalance self) internal pure returns (uint96);

Parameters

NameTypeDescription
selfPositionBalanceThe PositionBalance to retrieve the tickData from

Returns

NameTypeDescription
<none>uint96The packed tickData (currentTick, fastOracleTick, slowOracleTick, lastObservedTick)

unpackTickData

Unpack the current, last observed, and fast/slow oracle ticks from a 96-bit tickData encoding.

function unpackTickData(uint96 _tickData) internal pure returns (int24, int24, int24, int24);

Parameters

NameTypeDescription
_tickDatauint96The packed tickData to unpack ticks from

Returns

NameTypeDescription
<none>int24The current tick contained in _tickData
<none>int24The fast oracle tick contained in _tickData
<none>int24The slow oracle tick contained in _tickData
<none>int24The last observed tick contained in _tickData

utilization0

Get token0 utilization of self.

function utilization0(PositionBalance self) internal pure returns (int256);

Parameters

NameTypeDescription
selfPositionBalanceThe PositionBalance to retrieve the token0 utilization from

Returns

NameTypeDescription
<none>int256The token0 utilization, stored in bips

utilization1

Get token1 utilization of self.

function utilization1(PositionBalance self) internal pure returns (int256);

Parameters

NameTypeDescription
selfPositionBalanceThe PositionBalance to retrieve the token1 utilization from

Returns

NameTypeDescription
<none>int256The token1 utilization, stored in bips

utilizations

Get both token0 and token1 utilizations of self.

function utilizations(PositionBalance self) internal pure returns (uint32);

Parameters

NameTypeDescription
selfPositionBalanceThe PositionBalance to retrieve the utilizations from

Returns

NameTypeDescription
<none>uint32The token utilizations, stored in bips

positionSize

Get the positionSize of self.

function positionSize(PositionBalance self) internal pure returns (uint128);

Parameters

NameTypeDescription
selfPositionBalanceThe PositionBalance to retrieve the positionSize from

Returns

NameTypeDescription
<none>uint128The positionSize of self

unpackAll

Unpack all data from self.

function unpackAll(PositionBalance self)
external
pure
returns (
int24 currentTickAtMint,
int24 fastOracleTickAtMint,
int24 slowOracleTickAtMint,
int24 lastObservedTickAtMint,
int256 utilization0AtMint,
int256 utilization1AtMint,
uint128 _positionSize
);

Parameters

NameTypeDescription
selfPositionBalanceThe PositionBalance to get all data from

Returns

NameTypeDescription
currentTickAtMintint24currentTick at mint
fastOracleTickAtMintint24Fast oracle tick at mint
slowOracleTickAtMintint24Slow oracle tick at mint
lastObservedTickAtMintint24Last observed tick at mint
utilization0AtMintint256Utilization of token0 at mint
utilization1AtMintint256Utilization of token1 at mint
_positionSizeuint128Size of the position