fn trading_tokens_to_pool_tokens(
        &self,
        source_amount: u128,
        swap_token_a_amount: u128,
        swap_token_b_amount: u128,
        pool_supply: u128,
        trade_direction: TradeDirection,
    ) -> Option<u128> {
        let token_b_offset = self.token_b_offset as u128;
        let swap_source_amount = match trade_direction {
            TradeDirection::AtoB => swap_token_a_amount,
            TradeDirection::BtoA => swap_token_b_amount.checked_add(token_b_offset)?,
        };
        let swap_source_amount = PreciseNumber::new(swap_source_amount)?;
        let source_amount = PreciseNumber::new(source_amount)?;
        let ratio = source_amount.checked_div(&swap_source_amount)?;
        let one = PreciseNumber::new(1)?;
        let base = one.checked_add(&ratio)?;
        let root = base.sqrt()?.checked_sub(&one)?;
        let pool_supply = PreciseNumber::new(pool_supply)?;
        pool_supply.checked_mul(&root)?.to_imprecise()
    }
/// Get the amount of pool tokens for the given amount of token A and B,
/// taking into account the offset
Get the amount of pool tokens for the given amount of token A and B,
taking into account the offset
Get the amount of pool tokens for the given amount of token A and B taking into account the offset
fn trading_tokens_to_pool_tokens(
        &self,
        source_amount: u128,
        swap_token_a_amount: u128,
        swap_token_b_amount: u128,
        pool_supply: u128,
        trade_direction: TradeDirection,
    ) -> Option<u128> {
        let token_b_offset = self.token_b_offset as u128;
        let swap_source_amount = match trade_direction {
            TradeDirection::AtoB => swap_token_a_amount,
            TradeDirection::BtoA => swap_token_b_amount.checked_add(token_b_offset)?,
        };
        let swap_source_amount = PreciseNumber::new(swap_source_amount)?;
        let source_amount = PreciseNumber::new(source_amount)?;
        let ratio = source_amount.checked_div(&swap_source_amount)?;
        let one = PreciseNumber::new(1)?;
        let base = one.checked_add(&ratio)?;
        let root = base.sqrt()?.checked_sub(&one)?;
        let pool_supply = PreciseNumber::new(pool_supply)?;
        pool_supply.checked_mul(&root)?.to_imprecise()
    }
fn trading_tokens_to_pool_tokens ( & self , source_amount : u128 , swap_token_a_amount : u128 , swap_token_b_amount : u128 , pool_supply : u128 , trade_direction : TradeDirection , ) -> Option < u128 > { let token_b_offset = self . token_b_offset as u128 ; let swap_source_amount = match trade_direction { TradeDirection :: AtoB => swap_token_a_amount , TradeDirection :: BtoA => swap_token_b_amount . checked_add ( token_b_offset ) ? , } ; let swap_source_amount = PreciseNumber :: new ( swap_source_amount ) ? ; let source_amount = PreciseNumber :: new ( source_amount ) ? ; let ratio = source_amount . checked_div ( & swap_source_amount ) ? ; let one = PreciseNumber :: new ( 1 ) ? ; let base = one . checked_add ( & ratio ) ? ; let root = base . sqrt ( ) ? . checked_sub ( & one ) ? ; let pool_supply = PreciseNumber :: new ( pool_supply ) ? ; pool_supply . checked_mul ( & root ) ? . to_imprecise ( ) }
Get the amount of pool tokens for the given amount of token A and B,
taking into account the offset
Get the amount of pool tokens for the given amount of token A and B taking into account the offset
&self
source_amount
u128
swap_token_a_amount
u128
swap_token_b_amount
u128
pool_supply
u128
trade_direction
TradeDirection
&self
source_amount
u128
swap_token_a_amount
u128
swap_token_b_amount
u128
pool_supply
u128
trade_direction
TradeDirection