pub struct TickMap {
pub liquidity: u128,
pub max_liquidity_per_tick: u128,
/* private fields */
}Expand description
A tick map implementation for managing liquidity distribution in an AMM (Automated Market Maker).
This structure maintains a mapping of price ticks to liquidity data, allowing efficient navigation and manipulation of concentrated liquidity positions. It tracks active liquidity, global fee growth, and uses a bitmap for efficient tick traversal during swaps.
Fields§
§liquidity: u128Current active liquidity
max_liquidity_per_tick: u128Maximum liquidity that can be concentrated in a single tick based on tick spacing.
Implementations§
Source§impl TickMap
impl TickMap
Sourcepub fn get_tick(&self, tick: i32) -> Option<&PoolTick>
pub fn get_tick(&self, tick: i32) -> Option<&PoolTick>
Retrieves a reference to the tick data at the specified tick index.
Sourcepub fn get_tick_or_init(&mut self, tick: i32) -> &mut PoolTick
pub fn get_tick_or_init(&mut self, tick: i32) -> &mut PoolTick
Gets a mutable reference to the tick data, initializing it if it doesn’t exist.
Sourcepub fn get_fee_growth_inside(
&mut self,
lower_tick: i32,
upper_tick: i32,
current_tick: i32,
fee_growth_global_0: U256,
fee_growth_global_1: U256,
) -> (U256, U256)
pub fn get_fee_growth_inside( &mut self, lower_tick: i32, upper_tick: i32, current_tick: i32, fee_growth_global_0: U256, fee_growth_global_1: U256, ) -> (U256, U256)
Calculates the fee growth inside a price range defined by lower and upper ticks.
Sourcepub fn update(
&mut self,
tick: i32,
tick_current: i32,
liquidity_delta: i128,
upper: bool,
fee_growth_global_0: U256,
fee_growth_global_1: U256,
) -> bool
pub fn update( &mut self, tick: i32, tick_current: i32, liquidity_delta: i128, upper: bool, fee_growth_global_0: U256, fee_growth_global_1: U256, ) -> bool
Updates liquidity at a specific tick and manages the tick bitmap.
Sourcepub fn cross_tick(
&mut self,
tick: i32,
fee_growth_global_0: U256,
fee_growth_global_1: U256,
) -> i128
pub fn cross_tick( &mut self, tick: i32, fee_growth_global_0: U256, fee_growth_global_1: U256, ) -> i128
Crosses a tick during a swap, updating fee growth tracking.
Sourcepub fn active_tick_count(&self) -> usize
pub fn active_tick_count(&self) -> usize
Returns the number of currently active (initialized) ticks.
Sourcepub fn total_tick_count(&self) -> usize
pub fn total_tick_count(&self) -> usize
Returns the total number of ticks stored in the map.
Sourcepub fn get_all_ticks(&self) -> &AHashMap<i32, PoolTick>
pub fn get_all_ticks(&self) -> &AHashMap<i32, PoolTick>
Returns a reference to all ticks in the map for debugging/analysis purposes.
Sourcepub fn restore_tick(&mut self, tick_data: PoolTick)
pub fn restore_tick(&mut self, tick_data: PoolTick)
Restores a tick from a snapshot, updating both tick data and bitmap.
This method is used when restoring pool state from a saved snapshot. It sets the tick data and updates the bitmap if the tick is initialized.
Sourcepub fn next_initialized_tick(&self, tick: i32, lte: bool) -> (i32, bool)
pub fn next_initialized_tick(&self, tick: i32, lte: bool) -> (i32, bool)
Finds the next initialized tick after the given tick.
Sourcepub fn is_tick_initialized(&self, tick: i32) -> bool
pub fn is_tick_initialized(&self, tick: i32) -> bool
Checks if a tick is initialized in the bitmap.