pub fn remove_liquidity(
        &mut self,
        sender_id: &AccountId,
        shares: Balance,
        min_amounts: Vec<Balance>,
    ) -> Vec<Balance> {
        assert_eq!(
            min_amounts.len(),
            self.token_account_ids.len(),
            "ERR_WRONG_TOKEN_COUNT"
        );
        let prev_shares_amount = self.shares.get(&sender_id).expect("ERR_NO_SHARES");
        assert!(prev_shares_amount >= shares, "ERR_NOT_ENOUGH_SHARES");
        let mut result = vec![];
        for i in 0..self.token_account_ids.len() {
            let amount = (U256::from(self.amounts[i]) * U256::from(shares)
                / U256::from(self.shares_total_supply))
            .as_u128();
            assert!(amount >= min_amounts[i], "ERR_MIN_AMOUNT");
            self.amounts[i] -= amount;
            result.push(amount);
        }
        if prev_shares_amount == shares {
            // [AUDIT_13] Never unregister a LP when he removed all his liquidity.
            self.shares.insert(&sender_id, &0);
        } else {
            self.shares
                .insert(&sender_id, &(prev_shares_amount - shares));
        }
        env::log(
            format!(
                "{} shares of liquidity removed: receive back {:?}",
                shares,
                result
                    .iter()
                    .zip(self.token_account_ids.iter())
                    .map(|(amount, token_id)| format!("{} {}", amount, token_id))
                    .collect::<Vec<String>>(),
            )
            .as_bytes(),
        );
        self.shares_total_supply -= shares;
        result
    }
/// Removes given number of shares from the pool and returns amounts to the parent.
Removes given number of shares from the pool and returns amounts to the parent.
Removes given number of shares from the pool and returns amounts to the parent .
pub fn remove_liquidity(
        &mut self,
        sender_id: &AccountId,
        shares: Balance,
        min_amounts: Vec<Balance>,
    ) -> Vec<Balance> {
        assert_eq!(
            min_amounts.len(),
            self.token_account_ids.len(),
            "ERR_WRONG_TOKEN_COUNT"
        );
        let prev_shares_amount = self.shares.get(&sender_id).expect("ERR_NO_SHARES");
        assert!(prev_shares_amount >= shares, "ERR_NOT_ENOUGH_SHARES");
        let mut result = vec![];
        for i in 0..self.token_account_ids.len() {
            let amount = (U256::from(self.amounts[i]) * U256::from(shares)
                / U256::from(self.shares_total_supply))
            .as_u128();
            assert!(amount >= min_amounts[i], "ERR_MIN_AMOUNT");
            self.amounts[i] -= amount;
            result.push(amount);
        }
        if prev_shares_amount == shares {
            // [AUDIT_13] Never unregister a LP when he removed all his liquidity.
            self.shares.insert(&sender_id, &0);
        } else {
            self.shares
                .insert(&sender_id, &(prev_shares_amount - shares));
        }
        env::log(
            format!(
                "{} shares of liquidity removed: receive back {:?}",
                shares,
                result
                    .iter()
                    .zip(self.token_account_ids.iter())
                    .map(|(amount, token_id)| format!("{} {}", amount, token_id))
                    .collect::<Vec<String>>(),
            )
            .as_bytes(),
        );
        self.shares_total_supply -= shares;
        result
    }
pub fn remove_liquidity ( & mut self , sender_id : & AccountId , shares : Balance , min_amounts : Vec < Balance > , ) -> Vec < Balance > { assert_eq ! ( min_amounts len ( ) self token_account_ids len ( ) " " ) ; let prev_shares_amount = self . shares . get ( & sender_id ) . expect ( " " ) ; assert ! ( prev_shares_amount shares " " ) ; let mut result = vec ! [ ] ; for i in 0 .. self . token_account_ids . len ( ) { let amount = ( U256 :: from ( self . amounts [ i ] ) * U256 :: from ( shares ) / U256 :: from ( self . shares_total_supply ) ) . as_u128 ( ) ; assert ! ( amount min_amounts [ i ] " " ) ; self . amounts [ i ] -= amount ; result . push ( amount ) ; } if prev_shares_amount == shares { // [AUDIT_13] Never unregister a LP when he removed all his liquidity. self . shares . insert ( & sender_id , & 0 ) ; } else { self . shares . insert ( & sender_id , & ( prev_shares_amount - shares ) ) ; } env :: log ( format ! ( " " shares result iter ( ) zip ( self token_account_ids iter ( ) ) map ( ( amount token_id ) format ( " " amount token_id ) ) collect Vec String ( ) ) . as_bytes ( ) , ) ; self . shares_total_supply -= shares ; result }
Removes given number of shares from the pool and returns amounts to the parent.
Removes given number of shares from the pool and returns amounts to the parent .
&mut self
sender_id
&AccountId
shares
Balance
min_amounts
Vec<Balance>
&mut self
sender_id
&AccountId
shares
Balance
min_amounts
Vec<Balance>