pub fn provide_liquidity(
    deps: Deps,
    msg_info: MessageInfo,
    main_asset_id: String,
    pool_id: String,
    amount: Uint128,
) -> TerraswapResult {
    let state = BASESTATE.load(deps.storage)?;
    // Check if caller is trader.
    if msg_info.sender != state.trader {
        return Err(BaseDAppError::Unauthorized {}.into());
    }

    let treasury_address = &state.treasury_address;

    // Get pair address using memory single query
    let pair_address = state.memory.query_contract(deps, &pool_id)?;

    // Get pool info
    let pool_info: PoolResponse = query_pool(deps, &pair_address)?;
    let asset_1 = &pool_info.assets[0];
    let asset_2 = &pool_info.assets[1];

    let ratio = Decimal::from_ratio(asset_1.amount, asset_2.amount);

    let main_asset_info = state.memory.query_asset(deps, &main_asset_id)?;
    let main_asset = Asset {
        info: main_asset_info,
        amount,
    };
    let mut first_asset: Asset;
    let mut second_asset: Asset;

    // Determine second asset and required amount to do a 50/50 LP
    if asset_2.info.equal(&main_asset.info) {
        first_asset = asset_1.clone();
        first_asset.amount = ratio * amount;
        second_asset = main_asset;
    } else {
        second_asset = asset_2.clone();
        second_asset.amount = ratio.inv().unwrap_or_default() * amount;
        first_asset = main_asset;
    }

    // Does the treasury have enough of these assets?
    let first_asset_balance =
        query_asset_balance(deps, &first_asset.info, treasury_address.clone())?;
    let second_asset_balance =
        query_asset_balance(deps, &second_asset.info, treasury_address.clone())?;
    if second_asset_balance < second_asset.amount || first_asset_balance < first_asset.amount {
        return Err(BaseDAppError::Broke {}.into());
    }

    // Deposit lp msg either returns a bank send msg or an
    // increase allowance msg for each asset.
    let msgs: Vec<CosmosMsg> =
        deposit_lp_msg(deps, [second_asset, first_asset], pair_address, None)?;

    Ok(Response::new().add_message(send_to_treasury(msgs, treasury_address)?))
}
/// Constructs and forwards the terraswap provide_liquidity message
Constructs and forwards the terraswap provide_liquidity message
Constructs and forwards the terraswap provide_liquidity message
pub fn provide_liquidity(
    deps: Deps,
    msg_info: MessageInfo,
    main_asset_id: String,
    pool_id: String,
    amount: Uint128,
) -> TerraswapResult {
    let state = BASESTATE.load(deps.storage)?;
    // Check if caller is trader.
    if msg_info.sender != state.trader {
        return Err(BaseDAppError::Unauthorized {}.into());
    }
    let treasury_address = &state.treasury_address;
    // Get pair address using memory single query
    let pair_address = state.memory.query_contract(deps, &pool_id)?;
    // Get pool info
    let pool_info: PoolResponse = query_pool(deps, &pair_address)?;
    let asset_1 = &pool_info.assets[0];
    let asset_2 = &pool_info.assets[1];
    let ratio = Decimal::from_ratio(asset_1.amount, asset_2.amount);
    let main_asset_info = state.memory.query_asset(deps, &main_asset_id)?;
    let main_asset = Asset {
        info: main_asset_info,
        amount,
    };
    let mut first_asset: Asset;
    let mut second_asset: Asset;
    // Determine second asset and required amount to do a 50/50 LP
    if asset_2.info.equal(&main_asset.info) {
        first_asset = asset_1.clone();
        first_asset.amount = ratio * amount;
        second_asset = main_asset;
    } else {
        second_asset = asset_2.clone();
        second_asset.amount = ratio.inv().unwrap_or_default() * amount;
        first_asset = main_asset;
    }
    // Does the treasury have enough of these assets?
    let first_asset_balance =
        query_asset_balance(deps, &first_asset.info, treasury_address.clone())?;
    let second_asset_balance =
        query_asset_balance(deps, &second_asset.info, treasury_address.clone())?;
    if second_asset_balance < second_asset.amount || first_asset_balance < first_asset.amount {
        return Err(BaseDAppError::Broke {}.into());
    }
    // Deposit lp msg either returns a bank send msg or an
    // increase allowance msg for each asset.
    let msgs: Vec<CosmosMsg> =
        deposit_lp_msg(deps, [second_asset, first_asset], pair_address, None)?;
    Ok(Response::new().add_message(send_to_treasury(msgs, treasury_address)?))
}
pub fn provide_liquidity ( deps : Deps , msg_info : MessageInfo , main_asset_id : String , pool_id : String , amount : Uint128 , ) -> TerraswapResult { let state = BASESTATE . load ( deps . storage ) ? ; // Check if caller is trader. if msg_info . sender != state . trader { return Err ( BaseDAppError :: Unauthorized { } . into ( ) ) ; } let treasury_address = & state . treasury_address ; // Get pair address using memory single query let pair_address = state . memory . query_contract ( deps , & pool_id ) ? ; // Get pool info let pool_info : PoolResponse = query_pool ( deps , & pair_address ) ? ; let asset_1 = & pool_info . assets [ 0 ] ; let asset_2 = & pool_info . assets [ 1 ] ; let ratio = Decimal :: from_ratio ( asset_1 . amount , asset_2 . amount ) ; let main_asset_info = state . memory . query_asset ( deps , & main_asset_id ) ? ; let main_asset = Asset { info : main_asset_info , amount , } ; let mut first_asset : Asset ; let mut second_asset : Asset ; // Determine second asset and required amount to do a 50/50 LP if asset_2 . info . equal ( & main_asset . info ) { first_asset = asset_1 . clone ( ) ; first_asset . amount = ratio * amount ; second_asset = main_asset ; } else { second_asset = asset_2 . clone ( ) ; second_asset . amount = ratio . inv ( ) . unwrap_or_default ( ) * amount ; first_asset = main_asset ; } // Does the treasury have enough of these assets? let first_asset_balance = query_asset_balance ( deps , & first_asset . info , treasury_address . clone ( ) ) ? ; let second_asset_balance = query_asset_balance ( deps , & second_asset . info , treasury_address . clone ( ) ) ? ; if second_asset_balance < second_asset . amount || first_asset_balance < first_asset . amount { return Err ( BaseDAppError :: Broke { } . into ( ) ) ; } // Deposit lp msg either returns a bank send msg or an // increase allowance msg for each asset. let msgs : Vec < CosmosMsg > = deposit_lp_msg ( deps , [ second_asset , first_asset ] , pair_address , None ) ? ; Ok ( Response :: new ( ) . add_message ( send_to_treasury ( msgs , treasury_address ) ? ) ) }
Constructs and forwards the terraswap provide_liquidity message
Constructs and forwards the terraswap provide_liquidity message
deps
Deps
msg_info
MessageInfo
main_asset_id
String
pool_id
String
amount
Uint128
deps
Deps
msg_info
MessageInfo
main_asset_id
String
pool_id
String
amount
Uint128