Skip to main content

Storage

This section provides an in-depth exploration of key data structures integral to the Invariant protocol's storage mechanism. These structs are specifically crafted to facilitate the sharing of the state of the exchange within the CLAMM model. These data structures play a pivotal role in maintaining and organizing information related to the exchange, ensuring efficient and organized handling of data.

Contract State

pub struct InvariantConfig {
pub admin: ActorId,
pub protocol_fee: Percentage,
}
NameTypeDescription
adminActorIdAccount address of protocol admin. Admin is able to change fee, claim protocol fee or set the fee receiver, but cannot interfere with user positions or deposits and cannot close the pool.
protocol_feePercentagePercentage of the fee collected upon every swap in the pool that goes to the protocol, rest goes to LP.

FeeTier

pub struct FeeTier {
pub fee: Percentage,
pub tick_spacing: u16,
}
NameTypeDescription
feePercentagePercentage of the fee collected upon every swap in the pool.
tick_spacingu16The spacing between usable ticks.

PoolKey

pub struct PoolKey {
pub token_x: ActorId,
pub token_y: ActorId,
pub fee_tier: FeeTier,
}
NameTypeDescription
token_xActorIdaddress of x token.
token_yActorIdaddress of y token.
fee_tierFeeTierFeeTier associated with pool.

Pool

pub struct Pool {
pub liquidity: Liquidity,
pub sqrt_price: SqrtPrice,
pub current_tick_index: i32,
pub fee_growth_global_x: FeeGrowth,
pub fee_growth_global_y: FeeGrowth,
pub fee_protocol_token_x: TokenAmount,
pub fee_protocol_token_y: TokenAmount,
pub start_timestamp: u64,
pub last_timestamp: u64,
pub fee_receiver: ActorId,
}
NameTypeDescription
liquidityLiquidityAmount of virtual liquidity on pool. The difference between virtual and actual liquidity reflect the increased capital efficiency in Invariant.
sqrt_priceSqrtPriceSquare root of current price.
current_tick_indexi32The nearest tick below the current price.
fee_growth_global_xFeeGrowthAmount of fees accumulated in x token in per one integer unit of Liquidity since pool initialization.
fee_growth_global_yFeeGrowthAmount of fees accumulated in y token in per one integer unit of Liquidity since pool initialization.
fee_protocol_token_xTokenAmountAmount of protocol tokens accumulated in x token that are available to claim.
fee_protocol_token_yTokenAmountAmount of protocol tokens accumulated in y token that are available to claim.
start_timestampu64Time of pool initialization.
last_timestampu64Last update of pool.
fee_receiverActorIdAddress of entity enabling to claim protocol fee. By default it's admin but can be change for specific pool.

Position

pub struct Position {
pub pool_key: PoolKey,
pub liquidity: Liquidity,
pub lower_tick_index: i32,
pub upper_tick_index: i32,
pub fee_growth_inside_x: FeeGrowth,
pub fee_growth_inside_y: FeeGrowth,
pub last_block_number: u64,
pub tokens_owed_x: TokenAmount,
pub tokens_owed_y: TokenAmount,
}
NameTypeDescription
pool_keyPoolKeyPool key identificating on which Pool the position has been opened.
liquidityLiquidityAmount of immutable virtual liquidity that the position represents.
lower_tick_indexi32Lower tick index of the Position.
upper_tick_indexi32Upper tick index of the Position.
fee_growth_inside_xFeeGrowthAmount of fees accumulated in x token per one integer unit of Liquidity in-range. It is used to determine the shares of collected fees.
fee_growth_inside_yFeeGrowthAmount of fees accumulated in y token per one integer unit of Liquidity in-range. It is used to determine the shares of collected fees.
last_block_numberu64Last update of position expressed in block number.
tokens_owed_xTokenAmountThe quantity of x tokens collected in fees that is available for claiming.
tokens_owed_yTokenAmountThe quantity of y tokens collected in fees that is available for claiming.

Tick

pub struct Tick {
pub index: i32,
pub sign: bool,
pub liquidity_change: Liquidity,
pub liquidity_gross: Liquidity,
pub sqrt_price: SqrtPrice,
pub fee_growth_outside_x: FeeGrowth,
pub fee_growth_outside_y: FeeGrowth,
pub seconds_outside: u64,
}
NameTypeDescription
indexi32Index of tick.
signboolDetermine if the liquidity will be added or subtracted on cross.
liquidity_changeLiquidityAmount of virtual liquidity to adjust while. crossing.
liquidity_grossLiquidityAmount of virtual liquidity to be added on the tick, excluding liquidity taken on that tick. It is used to impose the maximum liquidity that can be place on a single tick.
sqrt_priceSqrtPriceSquare root of tick price.
fee_growth_outside_xFeeGrowthAmount of Fees accumulated in x token outside-range.
fee_growth_outside_yFeeGrowthAmount of Fees accumulated in y token outside-range.
seconds_outsideu64Seconds outside-range.