/// Get the amount of trading tokens for the given amount of pool tokens,
/// provided the total trading tokens and supply of pool tokens.
/// For the constant price curve, the total value of the pool is weighted
/// by the price of token B.
Get the amount of trading tokens for the given amount of pool tokens,
provided the total trading tokens and supply of pool tokens.
For the constant price curve, the total value of the pool is weighted
by the price of token B.
Get the amount of trading tokens for the given amount of pool tokens provided the total trading tokens and supply of pool tokens . For the constant price curve the total value of the pool is weighted by the price of token B .
fn pool_tokens_to_trading_tokens(
        &self,
        pool_tokens: u128,
        pool_token_supply: u128,
        swap_token_a_amount: u128,
        swap_token_b_amount: u128,
    ) -> Option<TradingTokenResult> {
        // Split the pool tokens in half, send half as token A, half as token B
        let token_a_pool_tokens = pool_tokens.checked_div(2)?;
        let token_b_pool_tokens = pool_tokens.checked_sub(token_a_pool_tokens)?;
        let token_b_price = self.token_b_price as u128;
        let total_value = swap_token_b_amount
            .checked_mul(token_b_price)?
            .checked_add(swap_token_a_amount)?;
        let token_a_amount = token_a_pool_tokens
            .checked_mul(total_value)?
            .checked_div(pool_token_supply)?;
        let token_b_amount = token_b_pool_tokens
            .checked_mul(total_value)?
            .checked_div(token_b_price)?
            .checked_div(pool_token_supply)?;
        Some(TradingTokenResult {
            token_a_amount,
            token_b_amount,
        })
    }
fn pool_tokens_to_trading_tokens ( & self , pool_tokens : u128 , pool_token_supply : u128 , swap_token_a_amount : u128 , swap_token_b_amount : u128 , ) -> Option < TradingTokenResult > { // Split the pool tokens in half, send half as token A, half as token B let token_a_pool_tokens = pool_tokens . checked_div ( 2 ) ? ; let token_b_pool_tokens = pool_tokens . checked_sub ( token_a_pool_tokens ) ? ; let token_b_price = self . token_b_price as u128 ; let total_value = swap_token_b_amount . checked_mul ( token_b_price ) ? . checked_add ( swap_token_a_amount ) ? ; let token_a_amount = token_a_pool_tokens . checked_mul ( total_value ) ? . checked_div ( pool_token_supply ) ? ; let token_b_amount = token_b_pool_tokens . checked_mul ( total_value ) ? . checked_div ( token_b_price ) ? . checked_div ( pool_token_supply ) ? ; Some ( TradingTokenResult { token_a_amount , token_b_amount , } ) }
Get the amount of trading tokens for the given amount of pool tokens,
provided the total trading tokens and supply of pool tokens.
Get the amount of trading tokens for the given amount of pool tokens provided the total trading tokens and supply of pool tokens .
&self
pool_tokens
u128
pool_token_supply
u128
swap_token_a_amount
u128
swap_token_b_amount
u128