TickMap

Struct TickMap 

Source
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: u128

Current active liquidity

§max_liquidity_per_tick: u128

Maximum liquidity that can be concentrated in a single tick based on tick spacing.

Implementations§

Source§

impl TickMap

Source

pub fn new(tick_spacing: u32) -> Self

Creates a new TickMap with the specified tick spacing.

Source

pub fn get_tick(&self, tick: i32) -> Option<&PoolTick>

Retrieves a reference to the tick data at the specified tick index.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn active_tick_count(&self) -> usize

Returns the number of currently active (initialized) ticks.

Source

pub fn total_tick_count(&self) -> usize

Returns the total number of ticks stored in the map.

Source

pub fn get_all_ticks(&self) -> &HashMap<i32, PoolTick>

Returns a reference to all ticks in the map for debugging/analysis purposes.

Source

pub fn set_tick(&mut self, tick_data: PoolTick)

Sets the tick data for a specific tick index.

Source

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.

Source

pub fn clear(&mut self, tick: i32)

Clears all data in a tick by removing it from the tick map.

Source

pub fn next_initialized_tick(&self, tick: i32, lte: bool) -> (i32, bool)

Finds the next initialized tick after the given tick.

Source

pub fn is_tick_initialized(&self, tick: i32) -> bool

Checks if a tick is initialized in the bitmap.

Trait Implementations§

Source§

impl Clone for TickMap

Source§

fn clone(&self) -> TickMap

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TickMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TickMap

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Ungil for T
where T: Send,