pub struct LBPool {Show 19 fields
pub address: Address,
pub token_x: Address,
pub token_y: Address,
pub bin_step: u16,
pub active_id: u32,
pub bins: BTreeMap<u32, (u128, u128)>,
pub base_factor: u16,
pub filter_period: u16,
pub decay_period: u16,
pub reduction_factor: u16,
pub variable_fee_control: u32,
pub protocol_share: u16,
pub max_volatility_accumulator: u32,
pub volatility_accumulator: u32,
pub volatility_reference: u32,
pub id_reference: u32,
pub time_of_last_update: u64,
pub last_updated: u64,
pub created_at: u64,
}Expand description
TraderJoe Liquidity Book pool.
Bin-based AMM where each bin uses constant-sum liquidity: L = price * x + y.
Swaps iterate through bins from active_id, consuming input per bin.
Fields§
§address: Address§token_x: Address§token_y: Address§bin_step: u16§active_id: u32§bins: BTreeMap<u32, (u128, u128)>Bin ID -> (reserve_x, reserve_y). Only non-empty bins are stored.
base_factor: u16§filter_period: u16§decay_period: u16§reduction_factor: u16§variable_fee_control: u32§max_volatility_accumulator: u32§volatility_accumulator: u32§volatility_reference: u32§id_reference: u32§time_of_last_update: u64§last_updated: u64§created_at: u64Implementations§
Source§impl LBPool
impl LBPool
pub fn new( address: Address, token_x: Address, token_y: Address, bin_step: u16, active_id: u32, bins: BTreeMap<u32, (u128, u128)>, base_factor: u16, filter_period: u16, decay_period: u16, reduction_factor: u16, variable_fee_control: u32, protocol_share: u16, max_volatility_accumulator: u32, volatility_accumulator: u32, volatility_reference: u32, id_reference: u32, time_of_last_update: u64, ) -> Self
Sourcepub fn get_total_fee(&self) -> u128
pub fn get_total_fee(&self) -> u128
Current total fee in 1e18 precision.
Sourcepub fn update_bin(&mut self, id: u32, reserve_x: u128, reserve_y: u128)
pub fn update_bin(&mut self, id: u32, reserve_x: u128, reserve_y: u128)
Update a bin’s reserves. Removes the bin if both reserves are zero.
Sourcepub fn simulate_swap_out(
&self,
amount_in: u128,
swap_for_y: bool,
) -> Result<(u128, u128, u128)>
pub fn simulate_swap_out( &self, amount_in: u128, swap_for_y: bool, ) -> Result<(u128, u128, u128)>
Simulate getSwapOut: given amount_in of one token, compute output.
Uses current wall-clock time for volatility decay. For exact on-chain
comparison at a specific block, use [simulate_swap_out_at].
Sourcepub fn simulate_swap_out_at(
&self,
amount_in: u128,
swap_for_y: bool,
timestamp: u64,
) -> Result<(u128, u128, u128)>
pub fn simulate_swap_out_at( &self, amount_in: u128, swap_for_y: bool, timestamp: u64, ) -> Result<(u128, u128, u128)>
Simulate getSwapOut with an explicit timestamp for volatility decay.
Exact port of LBPair.getSwapOut(). Returns (amount_in_left, amount_out, fee).
The timestamp should be the block timestamp for exact on-chain comparison.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for LBPool
impl<'de> Deserialize<'de> for LBPool
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl EventApplicable for LBPool
impl EventApplicable for LBPool
Source§impl PoolInterface for LBPool
impl PoolInterface for LBPool
Source§fn calculate_output(&self, token_in: &Address, amount_in: U256) -> Result<U256>
fn calculate_output(&self, token_in: &Address, amount_in: U256) -> Result<U256>
Source§fn calculate_input(&self, token_out: &Address, amount_out: U256) -> Result<U256>
fn calculate_input(&self, token_out: &Address, amount_out: U256) -> Result<U256>
Source§fn apply_swap(
&mut self,
_token_in: &Address,
_amount_in: U256,
_amount_out: U256,
) -> Result<()>
fn apply_swap( &mut self, _token_in: &Address, _amount_in: U256, _amount_out: U256, ) -> Result<()>
fn fee_raw(&self) -> u64
Source§fn contains_token(&self, token: &Address) -> bool
fn contains_token(&self, token: &Address) -> bool
Source§fn log_summary(&self) -> String
fn log_summary(&self) -> String
fn as_any_mut(&mut self) -> &mut dyn Any
Auto Trait Implementations§
impl Freeze for LBPool
impl RefUnwindSafe for LBPool
impl Send for LBPool
impl Sync for LBPool
impl Unpin for LBPool
impl UnsafeUnpin for LBPool
impl UnwindSafe for LBPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.