Skip to main content

PoolInterface

Trait PoolInterface 

Source
pub trait PoolInterface:
    Debug
    + Send
    + Sync
    + PoolTypeTrait
    + EventApplicable {
Show 15 methods // Required methods fn calculate_output( &self, token_in: &Address, amount_in: U256, ) -> Result<U256>; fn calculate_input( &self, token_out: &Address, amount_out: U256, ) -> Result<U256>; fn apply_swap( &mut self, token_in: &Address, amount_in: U256, amount_out: U256, ) -> Result<()>; fn address(&self) -> Address; fn tokens(&self) -> (Address, Address); fn fee(&self) -> f64; fn fee_raw(&self) -> u64; fn id(&self) -> String; fn contains_token(&self, token: &Address) -> bool; fn clone_box(&self) -> Box<dyn PoolInterface + Send + Sync>; fn log_summary(&self) -> String; fn as_any(&self) -> &dyn Any; fn as_any_mut(&mut self) -> &mut dyn Any; // Provided methods fn token0(&self) -> Address { ... } fn token1(&self) -> Address { ... }
}

Required Methods§

Source

fn calculate_output(&self, token_in: &Address, amount_in: U256) -> Result<U256>

Calculate output amount for a swap given an input amount and token

Source

fn calculate_input(&self, token_out: &Address, amount_out: U256) -> Result<U256>

Calculate input amount for a swap given an output amount and token

Source

fn apply_swap( &mut self, token_in: &Address, amount_in: U256, amount_out: U256, ) -> Result<()>

Apply a swap to the pool state

Source

fn address(&self) -> Address

Get the pool address

Source

fn tokens(&self) -> (Address, Address)

Get the tokens in the pool

Source

fn fee(&self) -> f64

Get the pool fee as a fraction (e.g., 0.003 for 0.3%)

Source

fn fee_raw(&self) -> u64

Source

fn id(&self) -> String

Get a unique identifier for the pool

Source

fn contains_token(&self, token: &Address) -> bool

Check if the pool contains a token

Source

fn clone_box(&self) -> Box<dyn PoolInterface + Send + Sync>

Clone the pool interface to a box

Source

fn log_summary(&self) -> String

Log summary of the pool

Source

fn as_any(&self) -> &dyn Any

Helper method for downcasting

Source

fn as_any_mut(&mut self) -> &mut dyn Any

Provided Methods§

Source

fn token0(&self) -> Address

Get token0 of the pool

Source

fn token1(&self) -> Address

Get token1 of the pool

Implementations§

Source§

impl dyn PoolInterface + Send + Sync

Source

pub fn downcast_ref<T: 'static>(&self) -> Option<&T>

Downcast to a concrete pool type

Source

pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T>

Downcast to a concrete pool type (mutable)

Implementors§