pub struct LiquidityPool { /* private fields */ }Implementations§
Source§impl LiquidityPool
impl LiquidityPool
pub fn new(native_reserve: u64, token_reserve: u64) -> Result<Self, PoolError>
pub fn get_native_reserve(&self) -> u64
pub fn get_token_reserve(&self) -> u64
pub fn get_constant_product(&self) -> u128
Sourcepub fn market_price(&self) -> f64
pub fn market_price(&self) -> f64
Returns the current market price of tokens in terms of native currency.
Sourcepub fn buy(
&mut self,
token_amount: u64,
max_native: Option<u64>,
) -> Result<u64, PoolError>
pub fn buy( &mut self, token_amount: u64, max_native: Option<u64>, ) -> Result<u64, PoolError>
Buys token_amount tokens from the pool, checking if the native currency spent does not exceed max_native.
Sourcepub fn sell(
&mut self,
token_amount: u64,
min_native: Option<u64>,
) -> Result<u64, PoolError>
pub fn sell( &mut self, token_amount: u64, min_native: Option<u64>, ) -> Result<u64, PoolError>
Sells token_amount tokens to the pool, checking if the native currency received is at least min_native.
Sourcepub fn simulate_buy(
&self,
token_amount: u64,
min_native: Option<u64>,
) -> Result<u64, PoolError>
pub fn simulate_buy( &self, token_amount: u64, min_native: Option<u64>, ) -> Result<u64, PoolError>
Simulates buying token_amount tokens and calculates the native currency that would be spent.
Sourcepub fn simulate_sell(
&self,
token_amount: u64,
max_native: Option<u64>,
) -> Result<u64, PoolError>
pub fn simulate_sell( &self, token_amount: u64, max_native: Option<u64>, ) -> Result<u64, PoolError>
Simulates selling token_amount tokens and calculates the native currency that would be received.
Sourcepub fn calculate_tokens_received(
&self,
native_amount: u64,
) -> Result<u64, PoolError>
pub fn calculate_tokens_received( &self, native_amount: u64, ) -> Result<u64, PoolError>
Calculates the amount of tokens that would be received for spending a specific amount of native currency.
Sourcepub fn buy_tokens_with_native(
&mut self,
native_amount: u64,
) -> Result<u64, PoolError>
pub fn buy_tokens_with_native( &mut self, native_amount: u64, ) -> Result<u64, PoolError>
Buys tokens using a specified amount of native currency.
pub fn calculate_price_impact(&self, token_amount: u64) -> f64
Trait Implementations§
Source§impl Clone for LiquidityPool
impl Clone for LiquidityPool
Source§fn clone(&self) -> LiquidityPool
fn clone(&self) -> LiquidityPool
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for LiquidityPool
impl RefUnwindSafe for LiquidityPool
impl Send for LiquidityPool
impl Sync for LiquidityPool
impl Unpin for LiquidityPool
impl UnwindSafe for LiquidityPool
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)