pub fn swap_to(
        &self,
        token_in_idx: usize, // token_in index in token vector,
        token_in_amount: Balance, // token_in amount in comparable precision (1e18),
        token_out_idx: usize, // token_out index in token vector,
        current_c_amounts: &Vec<Balance>, // in-pool tokens comparable amounts vector, 
        fees: &Fees,
    ) -> Option<SwapResult> {
        let y = self.compute_y(
            token_in_amount + current_c_amounts[token_in_idx], 
            current_c_amounts,
            token_in_idx,
            token_out_idx,
        )?.as_u128();

        let dy = current_c_amounts[token_out_idx].checked_sub(y)?;
        let trade_fee = fees.trade_fee(dy);
        let admin_fee = fees.admin_trade_fee(trade_fee);
        let amount_swapped = dy.checked_sub(trade_fee)?;

        let new_destination_amount = current_c_amounts[token_out_idx]
            .checked_sub(amount_swapped)?
            .checked_sub(admin_fee)?;
        let new_source_amount = current_c_amounts[token_in_idx]
            .checked_add(token_in_amount)?;

        Some(SwapResult {
            new_source_amount,
            new_destination_amount,
            amount_swapped,
            admin_fee,
            fee: trade_fee,
        })
    }
/// Compute SwapResult after an exchange
/// all tokens in and out with comparable precision
Compute SwapResult after an exchange
all tokens in and out with comparable precision
Compute SwapResult after an exchange all tokens in and out with comparable precision
pub fn swap_to(
        &self,
        token_in_idx: usize, // token_in index in token vector,
        token_in_amount: Balance, // token_in amount in comparable precision (1e18),
        token_out_idx: usize, // token_out index in token vector,
        current_c_amounts: &Vec<Balance>, // in-pool tokens comparable amounts vector, 
        fees: &Fees,
    ) -> Option<SwapResult> {
        let y = self.compute_y(
            token_in_amount + current_c_amounts[token_in_idx], 
            current_c_amounts,
            token_in_idx,
            token_out_idx,
        )?.as_u128();
        let dy = current_c_amounts[token_out_idx].checked_sub(y)?;
        let trade_fee = fees.trade_fee(dy);
        let admin_fee = fees.admin_trade_fee(trade_fee);
        let amount_swapped = dy.checked_sub(trade_fee)?;
        let new_destination_amount = current_c_amounts[token_out_idx]
            .checked_sub(amount_swapped)?
            .checked_sub(admin_fee)?;
        let new_source_amount = current_c_amounts[token_in_idx]
            .checked_add(token_in_amount)?;
        Some(SwapResult {
            new_source_amount,
            new_destination_amount,
            amount_swapped,
            admin_fee,
            fee: trade_fee,
        })
    }
pub fn swap_to ( & self , token_in_idx : usize , // token_in index in token vector, token_in_amount : Balance , // token_in amount in comparable precision (1e18), token_out_idx : usize , // token_out index in token vector, current_c_amounts : & Vec < Balance > , // in-pool tokens comparable amounts vector,  fees : & Fees , ) -> Option < SwapResult > { let y = self . compute_y ( token_in_amount + current_c_amounts [ token_in_idx ] , current_c_amounts , token_in_idx , token_out_idx , ) ? . as_u128 ( ) ; let dy = current_c_amounts [ token_out_idx ] . checked_sub ( y ) ? ; let trade_fee = fees . trade_fee ( dy ) ; let admin_fee = fees . admin_trade_fee ( trade_fee ) ; let amount_swapped = dy . checked_sub ( trade_fee ) ? ; let new_destination_amount = current_c_amounts [ token_out_idx ] . checked_sub ( amount_swapped ) ? . checked_sub ( admin_fee ) ? ; let new_source_amount = current_c_amounts [ token_in_idx ] . checked_add ( token_in_amount ) ? ; Some ( SwapResult { new_source_amount , new_destination_amount , amount_swapped , admin_fee , fee : trade_fee , } ) }
Compute SwapResult after an exchange
all tokens in and out with comparable precision
Compute SwapResult after an exchange all tokens in and out with comparable precision
&self
token_in_idx
usize
token_in_amount
Balance
token_out_idx
usize
current_c_amounts
&Vec<Balance>
fees
&Fees
&self
token_in_idx
usize
token_in_amount
Balance
token_out_idx
usize
current_c_amounts
&Vec<Balance>
fees
&Fees