pub fn try_provide_liquidity(
    deps: DepsMut,
    env: Env,
    msg_info: MessageInfo,
    asset: Asset,
) -> VaultResult {
    let deposit_info = DEPOSIT_INFO.load(deps.storage)?;
    let profit = PROFIT.load(deps.storage)?;
    let state = STATE.load(deps.storage)?;
    let info: PoolInfoRaw = POOL_INFO.load(deps.storage)?;
    let denom = deposit_info.clone().get_denom()?;

    if profit.last_balance != Uint128::zero() {
        return Err(StableVaultError::DepositDuringLoan {});
    }

    // Init vector for logging
    let mut attrs = vec![];
    // Check if deposit matches claimed deposit.
    deposit_info.assert(&asset.info)?;
    asset.assert_sent_native_token_balance(&msg_info)?;
    attrs.push(("Action:", String::from("Deposit to vault")));
    attrs.push(("Received funds:", asset.to_string()));

    // Received deposit to vault
    let deposit: Uint128 = asset.amount;

    // Get total value in Vault
    let (total_deposits_in_ust, stables_in_contract, _) =
        compute_total_value(&env, deps.as_ref(), &info)?;
    // Get total supply of LP tokens and calculate share
    let total_share = query_supply(&deps.querier, info.liquidity_token.clone())?;

    let share = if total_share == Uint128::zero()
        || total_deposits_in_ust.checked_sub(deposit)? == Uint128::zero()
    {
        // Initial share = collateral amount
        deposit
    } else {
        deposit.multiply_ratio(total_share, total_deposits_in_ust.checked_sub(deposit)?)
    };

    // mint LP token to sender
    let msg = CosmosMsg::Wasm(WasmMsg::Execute {
        contract_addr: info.liquidity_token.to_string(),
        msg: to_binary(&Cw20ExecuteMsg::Mint {
            recipient: msg_info.sender.to_string(),
            amount: share,
        })?,
        funds: vec![],
    });

    let response = Response::new().add_attributes(attrs).add_message(msg);

    // If contract holds more then ANCHOR_DEPOSIT_THRESHOLD [UST] then try deposit to anchor and leave UST_CAP [UST] in contract.
    if stables_in_contract > info.stable_cap * Decimal::percent(150) {
        let deposit_amount = stables_in_contract - info.stable_cap;
        let anchor_deposit = Coin::new(deposit_amount.u128(), denom);
        let deposit_msg = anchor_deposit_msg(
            deps.as_ref(),
            state.anchor_money_market_address,
            anchor_deposit,
        )?;
        return Ok(response.add_message(deposit_msg));
    };

    Ok(response)
}
// This function should be called alongside a deposit of UST into the contract.
This function should be called alongside a deposit of UST into the contract.
This function should be called alongside a deposit of UST into the contract .
pub fn try_provide_liquidity(
    deps: DepsMut,
    env: Env,
    msg_info: MessageInfo,
    asset: Asset,
) -> VaultResult {
    let deposit_info = DEPOSIT_INFO.load(deps.storage)?;
    let profit = PROFIT.load(deps.storage)?;
    let state = STATE.load(deps.storage)?;
    let info: PoolInfoRaw = POOL_INFO.load(deps.storage)?;
    let denom = deposit_info.clone().get_denom()?;
    if profit.last_balance != Uint128::zero() {
        return Err(StableVaultError::DepositDuringLoan {});
    }
    // Init vector for logging
    let mut attrs = vec![];
    // Check if deposit matches claimed deposit.
    deposit_info.assert(&asset.info)?;
    asset.assert_sent_native_token_balance(&msg_info)?;
    attrs.push(("Action:", String::from("Deposit to vault")));
    attrs.push(("Received funds:", asset.to_string()));
    // Received deposit to vault
    let deposit: Uint128 = asset.amount;
    // Get total value in Vault
    let (total_deposits_in_ust, stables_in_contract, _) =
        compute_total_value(&env, deps.as_ref(), &info)?;
    // Get total supply of LP tokens and calculate share
    let total_share = query_supply(&deps.querier, info.liquidity_token.clone())?;
    let share = if total_share == Uint128::zero()
        || total_deposits_in_ust.checked_sub(deposit)? == Uint128::zero()
    {
        // Initial share = collateral amount
        deposit
    } else {
        deposit.multiply_ratio(total_share, total_deposits_in_ust.checked_sub(deposit)?)
    };
    // mint LP token to sender
    let msg = CosmosMsg::Wasm(WasmMsg::Execute {
        contract_addr: info.liquidity_token.to_string(),
        msg: to_binary(&Cw20ExecuteMsg::Mint {
            recipient: msg_info.sender.to_string(),
            amount: share,
        })?,
        funds: vec![],
    });
    let response = Response::new().add_attributes(attrs).add_message(msg);
    // If contract holds more then ANCHOR_DEPOSIT_THRESHOLD [UST] then try deposit to anchor and leave UST_CAP [UST] in contract.
    if stables_in_contract > info.stable_cap * Decimal::percent(150) {
        let deposit_amount = stables_in_contract - info.stable_cap;
        let anchor_deposit = Coin::new(deposit_amount.u128(), denom);
        let deposit_msg = anchor_deposit_msg(
            deps.as_ref(),
            state.anchor_money_market_address,
            anchor_deposit,
        )?;
        return Ok(response.add_message(deposit_msg));
    };
    Ok(response)
}
pub fn try_provide_liquidity ( deps : DepsMut , env : Env , msg_info : MessageInfo , asset : Asset , ) -> VaultResult { let deposit_info = DEPOSIT_INFO . load ( deps . storage ) ? ; let profit = PROFIT . load ( deps . storage ) ? ; let state = STATE . load ( deps . storage ) ? ; let info : PoolInfoRaw = POOL_INFO . load ( deps . storage ) ? ; let denom = deposit_info . clone ( ) . get_denom ( ) ? ; if profit . last_balance != Uint128 :: zero ( ) { return Err ( StableVaultError :: DepositDuringLoan { } ) ; } // Init vector for logging let mut attrs = vec ! [ ] ; // Check if deposit matches claimed deposit. deposit_info . assert ( & asset . info ) ? ; asset . assert_sent_native_token_balance ( & msg_info ) ? ; attrs . push ( ( " " , String :: from ( " " ) ) ) ; attrs . push ( ( " " , asset . to_string ( ) ) ) ; // Received deposit to vault let deposit : Uint128 = asset . amount ; // Get total value in Vault let ( total_deposits_in_ust , stables_in_contract , _ ) = compute_total_value ( & env , deps . as_ref ( ) , & info ) ? ; // Get total supply of LP tokens and calculate share let total_share = query_supply ( & deps . querier , info . liquidity_token . clone ( ) ) ? ; let share = if total_share == Uint128 :: zero ( ) || total_deposits_in_ust . checked_sub ( deposit ) ? == Uint128 :: zero ( ) { // Initial share = collateral amount deposit } else { deposit . multiply_ratio ( total_share , total_deposits_in_ust . checked_sub ( deposit ) ? ) } ; // mint LP token to sender let msg = CosmosMsg :: Wasm ( WasmMsg :: Execute { contract_addr : info . liquidity_token . to_string ( ) , msg : to_binary ( & Cw20ExecuteMsg :: Mint { recipient : msg_info . sender . to_string ( ) , amount : share , } ) ? , funds : vec ! [ ] , } ) ; let response = Response :: new ( ) . add_attributes ( attrs ) . add_message ( msg ) ; // If contract holds more then ANCHOR_DEPOSIT_THRESHOLD [UST] then try deposit to anchor and leave UST_CAP [UST] in contract. if stables_in_contract > info . stable_cap * Decimal :: percent ( 150 ) { let deposit_amount = stables_in_contract - info . stable_cap ; let anchor_deposit = Coin :: new ( deposit_amount . u128 ( ) , denom ) ; let deposit_msg = anchor_deposit_msg ( deps . as_ref ( ) , state . anchor_money_market_address , anchor_deposit , ) ? ; return Ok ( response . add_message ( deposit_msg ) ) ; } ; Ok ( response ) }
This function should be called alongside a deposit of UST into the contract.
This function should be called alongside a deposit of UST into the contract .
deps
DepsMut
env
Env
msg_info
MessageInfo
asset
Asset
deps
DepsMut
env
Env
msg_info
MessageInfo
asset
Asset