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_price = self.token_b_price as u128;
        let given_value = match trade_direction {
            TradeDirection::AtoB => source_amount,
            TradeDirection::BtoA => source_amount.checked_mul(token_b_price)?,
        };
        let total_value = swap_token_b_amount
            .checked_mul(token_b_price)?
            .checked_add(swap_token_a_amount)?;
        pool_supply
            .checked_mul(given_value)?
            .checked_div(total_value)
    }
/// Get the amount of pool tokens for the given amount of token A and B
/// For the constant price curve, the total value of the pool is weighted
/// by the price of token B.
Get the amount of pool tokens for the given amount of token A and B
For the constant price curve, the total value of the pool is weighted
by the price of token B.
Get the amount of pool tokens for the given amount of token A and B For the constant price curve the total value of the pool is weighted by the price of token B .
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_price = self.token_b_price as u128;
        let given_value = match trade_direction {
            TradeDirection::AtoB => source_amount,
            TradeDirection::BtoA => source_amount.checked_mul(token_b_price)?,
        };
        let total_value = swap_token_b_amount
            .checked_mul(token_b_price)?
            .checked_add(swap_token_a_amount)?;
        pool_supply
            .checked_mul(given_value)?
            .checked_div(total_value)
    }
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_price = self . token_b_price as u128 ; let given_value = match trade_direction { TradeDirection :: AtoB => source_amount , TradeDirection :: BtoA => source_amount . checked_mul ( token_b_price ) ? , } ; let total_value = swap_token_b_amount . checked_mul ( token_b_price ) ? . checked_add ( swap_token_a_amount ) ? ; pool_supply . checked_mul ( given_value ) ? . checked_div ( total_value ) }
Get the amount of pool tokens for the given amount of token A and B
For the constant price curve, the total value of the pool is weighted
by the price of token B.
Get the amount of pool tokens for the given amount of token A and B For the constant price curve the total value of the pool is weighted by the price of token B .
&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