LiquidityPool

Struct LiquidityPool 

Source
pub struct LiquidityPool { /* private fields */ }

Implementations§

Source§

impl LiquidityPool

Source

pub fn new(native_reserve: u64, token_reserve: u64) -> Result<Self, PoolError>

Source

pub fn get_native_reserve(&self) -> u64

Source

pub fn get_token_reserve(&self) -> u64

Source

pub fn get_constant_product(&self) -> u128

Source

pub fn market_price(&self) -> f64

Returns the current market price of tokens in terms of native currency.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn buy_tokens_with_native( &mut self, native_amount: u64, ) -> Result<u64, PoolError>

Buys tokens using a specified amount of native currency.

Source

pub fn calculate_price_impact(&self, token_amount: u64) -> f64

Source

pub fn calculate_additional_tokens_for_desired_native( &mut self, sell_tokens: u64, desired_native: u64, ) -> Result<u64, PoolError>

Calculates the number of additional tokens required to reach a desired native currency amount.

Trait Implementations§

Source§

impl Clone for LiquidityPool

Source§

fn clone(&self) -> LiquidityPool

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for LiquidityPool

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.