pub fn add_liquidity(
        &mut self,
        sender_id: &AccountId,
        amounts: &Vec<Balance>,
        min_shares: Balance,
        fees: &AdminFees,
    ) -> Balance {
        let n_coins = self.token_account_ids.len();
        assert_eq!(amounts.len(), n_coins, "{}", ERR64_TOKENS_COUNT_ILLEGAL);

        let (new_shares, fee_part) = self.calc_add_liquidity(amounts, fees);

        //slippage check on the LP tokens.
        assert!(new_shares >= min_shares, "{}", ERR68_SLIPPAGE);

        for i in 0..n_coins {
            self.c_amounts[i] = self.c_amounts[i].checked_add(self.amount_to_c_amount(amounts[i], i)).unwrap();
        }

        self.mint_shares(sender_id, new_shares);
        env::log(
            format!(
                "Mint {} shares for {}, fee is {} shares",
                new_shares, sender_id, fee_part,
            )
            .as_bytes(),
        );

        if fee_part > 0 {
            // referral fee
            if let Some(referral) = &fees.referral_id {
                if self.shares.get(referral).is_some() {
                    let referral_share = fee_part * fees.referral_fee as u128 / FEE_DIVISOR as u128;
                    self.mint_shares(referral, referral_share);
                    env::log(
                        format!("Referral {} got {} shares", referral, referral_share).as_bytes(),
                    );
                }
            }
            // exchange fee
            let exchange_share = fee_part * fees.exchange_fee as u128 / FEE_DIVISOR as u128;
            self.mint_shares(&fees.exchange_id, exchange_share);
            env::log(
                format!("Admin {} got {} shares", &fees.exchange_id, exchange_share).as_bytes(),
            );
        }
        new_shares
    }
/// Add liquidity into the pool.
/// Allows to add liquidity of a subset of tokens,
/// by set other tokens balance into 0.
Add liquidity into the pool.
Allows to add liquidity of a subset of tokens,
by set other tokens balance into 0.
Add liquidity into the pool . Allows to add liquidity of a subset of tokens by set other tokens balance into 0 .
pub fn add_liquidity(
        &mut self,
        sender_id: &AccountId,
        amounts: &Vec<Balance>,
        min_shares: Balance,
        fees: &AdminFees,
    ) -> Balance {
        let n_coins = self.token_account_ids.len();
        assert_eq!(amounts.len(), n_coins, "{}", ERR64_TOKENS_COUNT_ILLEGAL);
        let (new_shares, fee_part) = self.calc_add_liquidity(amounts, fees);
        //slippage check on the LP tokens.
        assert!(new_shares >= min_shares, "{}", ERR68_SLIPPAGE);
        for i in 0..n_coins {
            self.c_amounts[i] = self.c_amounts[i].checked_add(self.amount_to_c_amount(amounts[i], i)).unwrap();
        }
        self.mint_shares(sender_id, new_shares);
        env::log(
            format!(
                "Mint {} shares for {}, fee is {} shares",
                new_shares, sender_id, fee_part,
            )
            .as_bytes(),
        );
        if fee_part > 0 {
            // referral fee
            if let Some(referral) = &fees.referral_id {
                if self.shares.get(referral).is_some() {
                    let referral_share = fee_part * fees.referral_fee as u128 / FEE_DIVISOR as u128;
                    self.mint_shares(referral, referral_share);
                    env::log(
                        format!("Referral {} got {} shares", referral, referral_share).as_bytes(),
                    );
                }
            }
            // exchange fee
            let exchange_share = fee_part * fees.exchange_fee as u128 / FEE_DIVISOR as u128;
            self.mint_shares(&fees.exchange_id, exchange_share);
            env::log(
                format!("Admin {} got {} shares", &fees.exchange_id, exchange_share).as_bytes(),
            );
        }
        new_shares
    }
pub fn add_liquidity ( & mut self , sender_id : & AccountId , amounts : & Vec < Balance > , min_shares : Balance , fees : & AdminFees , ) -> Balance { let n_coins = self . token_account_ids . len ( ) ; assert_eq ! ( amounts len ( ) n_coins " " ERR64_TOKENS_COUNT_ILLEGAL ) ; let ( new_shares , fee_part ) = self . calc_add_liquidity ( amounts , fees ) ; //slippage check on the LP tokens. assert ! ( new_shares min_shares " " ERR68_SLIPPAGE ) ; for i in 0 .. n_coins { self . c_amounts [ i ] = self . c_amounts [ i ] . checked_add ( self . amount_to_c_amount ( amounts [ i ] , i ) ) . unwrap ( ) ; } self . mint_shares ( sender_id , new_shares ) ; env :: log ( format ! ( " " new_shares sender_id fee_part ) . as_bytes ( ) , ) ; if fee_part > 0 { // referral fee if let Some ( referral ) = & fees . referral_id { if self . shares . get ( referral ) . is_some ( ) { let referral_share = fee_part * fees . referral_fee as u128 / FEE_DIVISOR as u128 ; self . mint_shares ( referral , referral_share ) ; env :: log ( format ! ( " " referral referral_share ) . as_bytes ( ) , ) ; } } // exchange fee let exchange_share = fee_part * fees . exchange_fee as u128 / FEE_DIVISOR as u128 ; self . mint_shares ( & fees . exchange_id , exchange_share ) ; env :: log ( format ! ( " " fees exchange_id exchange_share ) . as_bytes ( ) , ) ; } new_shares }
Add liquidity into the pool.
Add liquidity into the pool .
&mut self
sender_id
&AccountId
amounts
&Vec<Balance>
min_shares
Balance
fees
&AdminFees
&mut self
sender_id
&AccountId
amounts
&Vec<Balance>
min_shares
Balance
fees
&AdminFees