pub fn add_liquidity(&mut self, sender_id: &AccountId, amounts: &mut Vec<Balance>) -> Balance {
        assert_eq!(
            amounts.len(),
            self.token_account_ids.len(),
            "ERR_WRONG_TOKEN_COUNT"
        );
        let shares = if self.shares_total_supply > 0 {
            let mut fair_supply = U256::max_value();
            for i in 0..self.token_account_ids.len() {
                assert!(amounts[i] > 0, "{}", ERR31_ZERO_AMOUNT);
                fair_supply = min(
                    fair_supply,
                    U256::from(amounts[i]) * U256::from(self.shares_total_supply) / self.amounts[i],
                );
            }
            for i in 0..self.token_account_ids.len() {
                let amount = (U256::from(self.amounts[i]) * fair_supply
                    / U256::from(self.shares_total_supply))
                .as_u128();
                assert!(amount > 0, "{}", ERR31_ZERO_AMOUNT);
                self.amounts[i] += amount;
                amounts[i] = amount;
            }
            fair_supply.as_u128()
        } else {
            for i in 0..self.token_account_ids.len() {
                self.amounts[i] += amounts[i];
            }
            INIT_SHARES_SUPPLY
        };
        self.mint_shares(&sender_id, shares);
        assert!(shares > 0, "{}", ERR32_ZERO_SHARES);
        env::log(
            format!(
                "Liquidity added {:?}, minted {} shares",
                amounts
                    .iter()
                    .zip(self.token_account_ids.iter())
                    .map(|(amount, token_id)| format!("{} {}", amount, token_id))
                    .collect::<Vec<String>>(),
                shares
            )
            .as_bytes(),
        );
        shares
    }
/// Adds the amounts of tokens to liquidity pool and returns number of shares that this user receives.
/// Updates amount to amount kept in the pool.
Adds the amounts of tokens to liquidity pool and returns number of shares that this user receives.
Updates amount to amount kept in the pool.
Adds the amounts of tokens to liquidity pool and returns number of shares that this user receives . Updates amount to amount kept in the pool .
pub fn add_liquidity(&mut self, sender_id: &AccountId, amounts: &mut Vec<Balance>) -> Balance {
        assert_eq!(
            amounts.len(),
            self.token_account_ids.len(),
            "ERR_WRONG_TOKEN_COUNT"
        );
        let shares = if self.shares_total_supply > 0 {
            let mut fair_supply = U256::max_value();
            for i in 0..self.token_account_ids.len() {
                assert!(amounts[i] > 0, "{}", ERR31_ZERO_AMOUNT);
                fair_supply = min(
                    fair_supply,
                    U256::from(amounts[i]) * U256::from(self.shares_total_supply) / self.amounts[i],
                );
            }
            for i in 0..self.token_account_ids.len() {
                let amount = (U256::from(self.amounts[i]) * fair_supply
                    / U256::from(self.shares_total_supply))
                .as_u128();
                assert!(amount > 0, "{}", ERR31_ZERO_AMOUNT);
                self.amounts[i] += amount;
                amounts[i] = amount;
            }
            fair_supply.as_u128()
        } else {
            for i in 0..self.token_account_ids.len() {
                self.amounts[i] += amounts[i];
            }
            INIT_SHARES_SUPPLY
        };
        self.mint_shares(&sender_id, shares);
        assert!(shares > 0, "{}", ERR32_ZERO_SHARES);
        env::log(
            format!(
                "Liquidity added {:?}, minted {} shares",
                amounts
                    .iter()
                    .zip(self.token_account_ids.iter())
                    .map(|(amount, token_id)| format!("{} {}", amount, token_id))
                    .collect::<Vec<String>>(),
                shares
            )
            .as_bytes(),
        );
        shares
    }
pub fn add_liquidity ( & mut self , sender_id : & AccountId , amounts : & mut Vec < Balance > ) -> Balance { assert_eq ! ( amounts len ( ) self token_account_ids len ( ) " " ) ; let shares = if self . shares_total_supply > 0 { let mut fair_supply = U256 :: max_value ( ) ; for i in 0 .. self . token_account_ids . len ( ) { assert ! ( amounts [ i ] 0 " " ERR31_ZERO_AMOUNT ) ; fair_supply = min ( fair_supply , U256 :: from ( amounts [ i ] ) * U256 :: from ( self . shares_total_supply ) / self . amounts [ i ] , ) ; } for i in 0 .. self . token_account_ids . len ( ) { let amount = ( U256 :: from ( self . amounts [ i ] ) * fair_supply / U256 :: from ( self . shares_total_supply ) ) . as_u128 ( ) ; assert ! ( amount 0 " " ERR31_ZERO_AMOUNT ) ; self . amounts [ i ] += amount ; amounts [ i ] = amount ; } fair_supply . as_u128 ( ) } else { for i in 0 .. self . token_account_ids . len ( ) { self . amounts [ i ] += amounts [ i ] ; } INIT_SHARES_SUPPLY } ; self . mint_shares ( & sender_id , shares ) ; assert ! ( shares 0 " " ERR32_ZERO_SHARES ) ; env :: log ( format ! ( " " amounts iter ( ) zip ( self token_account_ids iter ( ) ) map ( ( amount token_id ) format ( " " amount token_id ) ) collect Vec String ( ) shares ) . as_bytes ( ) , ) ; shares }
Adds the amounts of tokens to liquidity pool and returns number of shares that this user receives.
Adds the amounts of tokens to liquidity pool and returns number of shares that this user receives .
&mut self
sender_id
&AccountId
amounts
&mut Vec<Balance>
&mut self
sender_id
&AccountId
amounts
&mut Vec<Balance>