/// CONTRACT - should approve contract to use the amount of token
should approve contract to use the amount of token
should approve contract to use the amount of token
pub fn try_provide_liquidity<S: Storage, A: Api, Q: Querier>(
    deps: &mut Extern<S, A, Q>,
    env: Env,
    assets_deposits: Vec<TokenAmount>,
    cancel_if_no_bonus: Option<bool>,
) -> HandleResult {
    let supported_tokens = read_all_assets(&deps.storage)?;
    let mut messages = vec![];
    let mut logs = vec![log("action", "provide_liquidity")];
    for deposited_token in assets_deposits.iter() {
        if !supported_tokens
            .iter()
            .any(|supported_token| supported_token.address == deposited_token.address)
        {
            return Err(StdError::generic_err(format!(
                "Token not supported: {:?} ",
                deposited_token
            )));
        }
        // Execute TransferFrom msg to receive funds
        messages.push(snip20_utils::transfer_from_msg(
            env.message.sender.clone(),
            env.contract.address.clone(),
            deposited_token.amount,
            None,
            256,
            deposited_token.code_hash.clone(),
            deposited_token.address.clone(),
        )?);
        logs.push(log("token", deposited_token.address));
    }
    if Some(true) == cancel_if_no_bonus {
        // TODO
    }
    let config = read_config(&deps.storage)?;
    // For now share = sum of all deposits
    let mut share = Uint128::zero();
    for token_deposit in assets_deposits.iter() {
        let decimals: u8 = supported_tokens
            .iter()
            .find(|a| a.address == token_deposit.address)
            .unwrap() // can unwrap because if we're here then it's already tested
            .decimals;
        let factor: u128 = 10u128.pow(18 - decimals as u32); // not checked_pow because 10^18 < 2^128
        let normalized_deposit: u128 =
            token_deposit
                .amount
                .u128()
                .checked_mul(factor)
                .ok_or_else(|| {
                    StdError::generic_err(format!(
                        "Cannot normalize token deposit for 18 decimals: {:?}",
                        token_deposit
                    ))
                })?;
        share += normalized_deposit.into();
    }
    messages.push(snip20_utils::mint_msg(
        env.message.sender,
        share,
        None,
        256,
        config.lp_token_code_hash,
        config.lp_token_address,
    )?);
    logs.push(log("share", share.to_string()));
    Ok(HandleResponse {
        messages,
        log: logs,
        data: None,
    })
}
pub fn try_provide_liquidity < S : Storage , A : Api , Q : Querier > ( deps : & mut Extern < S , A , Q > , env : Env , assets_deposits : Vec < TokenAmount > , cancel_if_no_bonus : Option < bool > , ) -> HandleResult { let supported_tokens = read_all_assets ( & deps . storage ) ? ; let mut messages = vec ! [ ] ; let mut logs = vec ! [ log ( " " " " ) ] ; for deposited_token in assets_deposits . iter ( ) { if ! supported_tokens . iter ( ) . any ( | supported_token | supported_token . address == deposited_token . address ) { return Err ( StdError :: generic_err ( format ! ( " " deposited_token ) ) ) ; } // Execute TransferFrom msg to receive funds messages . push ( snip20_utils :: transfer_from_msg ( env . message . sender . clone ( ) , env . contract . address . clone ( ) , deposited_token . amount , None , 256 , deposited_token . code_hash . clone ( ) , deposited_token . address . clone ( ) , ) ? ) ; logs . push ( log ( " " , deposited_token . address ) ) ; } if Some ( true ) == cancel_if_no_bonus { // TODO } let config = read_config ( & deps . storage ) ? ; // For now share = sum of all deposits let mut share = Uint128 :: zero ( ) ; for token_deposit in assets_deposits . iter ( ) { let decimals : u8 = supported_tokens . iter ( ) . find ( | a | a . address == token_deposit . address ) . unwrap ( ) // can unwrap because if we're here then it's already tested . decimals ; let factor : u128 = 10u128 . pow ( 18 - decimals as u32 ) ; // not checked_pow because 10^18 < 2^128 let normalized_deposit : u128 = token_deposit . amount . u128 ( ) . checked_mul ( factor ) . ok_or_else ( | | { StdError :: generic_err ( format ! ( " " token_deposit ) ) } ) ? ; share += normalized_deposit . into ( ) ; } messages . push ( snip20_utils :: mint_msg ( env . message . sender , share , None , 256 , config . lp_token_code_hash , config . lp_token_address , ) ? ) ; logs . push ( log ( " " , share . to_string ( ) ) ) ; Ok ( HandleResponse { messages , log : logs , data : None , } ) }
CONTRACT - should approve contract to use the amount of token
CONTRACT - should approve contract to use the amount of token
deps
&mut Extern<S, A, Q>
env
Env
assets_deposits
Vec<TokenAmount>
cancel_if_no_bonus
Option<bool>