Skip to main content

PoolAmm

Struct PoolAmm 

Source
#[repr(C)]
pub struct PoolAmm {
Show 13 fields pub reserve0_lo: u64, pub reserve0_hi: u64, pub reserve1_lo: u64, pub reserve1_hi: u64, pub sqrt_price_x64: u128, pub liquidity: u128, pub tick: i32, pub tick_spacing: i32, pub fee_ppm: u32, pub pool_type: u8, pub _pad0: [u8; 3], pub last_block: u64, pub last_update_ns: u64,
}
Expand description

Raw AMM state for a single pool. Slot i corresponds to PoolBooks.metas[i].

Strategies use this to compute swap output from the pricing function directly rather than relying on pre-computed synthetic L2Books.

  • V2 pools: use reserve0(), reserve1(), fee_ppm
  • V3/CLMM pools: use sqrt_price_x64, tick, liquidity, fee_ppm, tick_spacing

Fields§

§reserve0_lo: u64

Lower 64 bits of reserve0.

§reserve0_hi: u64

Upper 64 bits of reserve0 (usually 0 for practical pools).

§reserve1_lo: u64

Lower 64 bits of reserve1.

§reserve1_hi: u64

Upper 64 bits of reserve1.

§sqrt_price_x64: u128

sqrt(price) in Q64.64 fixed-point (converted from Q64.96 by CC). To get price: (sqrt_price_x64 as f64 / 2^64)^2.

§liquidity: u128

Active liquidity at the current tick.

§tick: i32

Current tick index. Price at tick t ≈ 1.0001^t.

§tick_spacing: i32

Tick spacing (V3 only: 1, 10, 60, 200).

§fee_ppm: u32

Swap fee in parts-per-million (3000 = 0.3%).

§pool_type: u8

Pool type: 0=V2, 1=V3/CLMM, 2=stableswap.

§_pad0: [u8; 3]§last_block: u64

Block/slot number when this state was observed.

§last_update_ns: u64

Nanosecond timestamp of last update.

Implementations§

Source§

impl PoolAmm

Source

pub fn reserve0(&self) -> u128

Reconstruct reserve0 as u128.

Source

pub fn reserve1(&self) -> u128

Reconstruct reserve1 as u128.

Source

pub fn is_v2(&self) -> bool

Whether this is a V2 (constant-product) pool.

Source

pub fn is_v3(&self) -> bool

Whether this is a V3/CLMM (concentrated liquidity) pool.

Source

pub fn is_valid(&self) -> bool

Whether this state has been populated (non-zero block).

Source

pub fn fee_bps(&self) -> u32

Fee as basis points (e.g. 3000 ppm → 30 bps).

Trait Implementations§

Source§

impl Clone for PoolAmm

Source§

fn clone(&self) -> PoolAmm

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 PoolAmm

Source§

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

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

impl Default for PoolAmm

Source§

fn default() -> Self

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

impl Copy for PoolAmm

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.

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> 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.