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

    if assets.len() != 2 {
        return Err(TerraswapError::NotTwoAssets {});
    }

    let treasury_address = &state.treasury_address;

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

    // Get pool info
    let pool_info: PoolResponse = query_pool(deps, &pair_address)?;

    // List with assets to send
    let mut assets_to_send: Vec<Asset> = vec![];

    // Iterate over provided assets
    for asset in assets {
        let (asset_token, asset_amount) = asset;
        // Make sure the asset_amount is greater than zero since zero transfers fail
        if asset_amount == Uint128::zero() {
            return Err(TerraswapError::ZeroAmount { asset: asset_token });
        }

        let asset_info = state.memory.query_asset(deps, &asset_token)?;
        // Check if pool contains the asset
        if pool_info.assets.iter().any(|a| a.info == asset_info) {
            let asset_balance = query_asset_balance(deps, &asset_info, treasury_address.clone())?;
            // Check if treasury has enough of this asset
            if asset_balance < asset_amount {
                return Err(BaseDAppError::Broke {}.into());
            }
            // Append asset to list
            assets_to_send.push(Asset {
                info: asset_info,
                amount: asset_amount,
            })
        } else {
            // Error if asset info not found in pool
            return Err(TerraswapError::NotInPool { id: asset_token });
        }
    }
    let asset_array: [Asset; 2] = [assets_to_send[0].clone(), assets_to_send[1].clone()];
    // Deposit lp msg either returns a bank send msg or a
    // increase allowance msg for each asset.
    let msgs: Vec<CosmosMsg> = deposit_lp_msg(deps, asset_array, pair_address, slippage_tolerance)?;

    Ok(Response::new().add_message(send_to_treasury(msgs, treasury_address)?))
}
/// Constructs and forwards the terraswap provide_liquidity message
/// You can provide custom asset amounts
Constructs and forwards the terraswap provide_liquidity message
You can provide custom asset amounts
Constructs and forwards the terraswap provide_liquidity message You can provide custom asset amounts
pub fn detailed_provide_liquidity(
    deps: Deps,
    msg_info: MessageInfo,
    assets: Vec<(String, Uint128)>,
    pool_id: String,
    slippage_tolerance: Option<Decimal>,
) -> TerraswapResult {
    let state = BASESTATE.load(deps.storage)?;
    // Check if caller is trader.
    if msg_info.sender != state.trader {
        return Err(BaseDAppError::Unauthorized {}.into());
    }
    if assets.len() != 2 {
        return Err(TerraswapError::NotTwoAssets {});
    }
    let treasury_address = &state.treasury_address;
    // Get pair address
    let pair_address = state.memory.query_contract(deps, &pool_id)?;
    // Get pool info
    let pool_info: PoolResponse = query_pool(deps, &pair_address)?;
    // List with assets to send
    let mut assets_to_send: Vec<Asset> = vec![];
    // Iterate over provided assets
    for asset in assets {
        let (asset_token, asset_amount) = asset;
        // Make sure the asset_amount is greater than zero since zero transfers fail
        if asset_amount == Uint128::zero() {
            return Err(TerraswapError::ZeroAmount { asset: asset_token });
        }
        let asset_info = state.memory.query_asset(deps, &asset_token)?;
        // Check if pool contains the asset
        if pool_info.assets.iter().any(|a| a.info == asset_info) {
            let asset_balance = query_asset_balance(deps, &asset_info, treasury_address.clone())?;
            // Check if treasury has enough of this asset
            if asset_balance < asset_amount {
                return Err(BaseDAppError::Broke {}.into());
            }
            // Append asset to list
            assets_to_send.push(Asset {
                info: asset_info,
                amount: asset_amount,
            })
        } else {
            // Error if asset info not found in pool
            return Err(TerraswapError::NotInPool { id: asset_token });
        }
    }
    let asset_array: [Asset; 2] = [assets_to_send[0].clone(), assets_to_send[1].clone()];
    // Deposit lp msg either returns a bank send msg or a
    // increase allowance msg for each asset.
    let msgs: Vec<CosmosMsg> = deposit_lp_msg(deps, asset_array, pair_address, slippage_tolerance)?;
    Ok(Response::new().add_message(send_to_treasury(msgs, treasury_address)?))
}
pub fn detailed_provide_liquidity ( deps : Deps , msg_info : MessageInfo , assets : Vec < ( String , Uint128 ) > , pool_id : String , slippage_tolerance : Option < Decimal > , ) -> TerraswapResult { let state = BASESTATE . load ( deps . storage ) ? ; // Check if caller is trader. if msg_info . sender != state . trader { return Err ( BaseDAppError :: Unauthorized { } . into ( ) ) ; } if assets . len ( ) != 2 { return Err ( TerraswapError :: NotTwoAssets { } ) ; } let treasury_address = & state . treasury_address ; // Get pair address let pair_address = state . memory . query_contract ( deps , & pool_id ) ? ; // Get pool info let pool_info : PoolResponse = query_pool ( deps , & pair_address ) ? ; // List with assets to send let mut assets_to_send : Vec < Asset > = vec ! [ ] ; // Iterate over provided assets for asset in assets { let ( asset_token , asset_amount ) = asset ; // Make sure the asset_amount is greater than zero since zero transfers fail if asset_amount == Uint128 :: zero ( ) { return Err ( TerraswapError :: ZeroAmount { asset : asset_token } ) ; } let asset_info = state . memory . query_asset ( deps , & asset_token ) ? ; // Check if pool contains the asset if pool_info . assets . iter ( ) . any ( | a | a . info == asset_info ) { let asset_balance = query_asset_balance ( deps , & asset_info , treasury_address . clone ( ) ) ? ; // Check if treasury has enough of this asset if asset_balance < asset_amount { return Err ( BaseDAppError :: Broke { } . into ( ) ) ; } // Append asset to list assets_to_send . push ( Asset { info : asset_info , amount : asset_amount , } ) } else { // Error if asset info not found in pool return Err ( TerraswapError :: NotInPool { id : asset_token } ) ; } } let asset_array : [ Asset ; 2 ] = [ assets_to_send [ 0 ] . clone ( ) , assets_to_send [ 1 ] . clone ( ) ] ; // Deposit lp msg either returns a bank send msg or a // increase allowance msg for each asset. let msgs : Vec < CosmosMsg > = deposit_lp_msg ( deps , asset_array , pair_address , slippage_tolerance ) ? ; Ok ( Response :: new ( ) . add_message ( send_to_treasury ( msgs , treasury_address ) ? ) ) }
Constructs and forwards the terraswap provide_liquidity message
You can provide custom asset amounts
Constructs and forwards the terraswap provide_liquidity message You can provide custom asset amounts
deps
Deps
msg_info
MessageInfo
assets
Vec<(String, Uint128)>
pool_id
String
slippage_tolerance
Option<Decimal>
deps
Deps
msg_info
MessageInfo
assets
Vec<(String, Uint128)>
pool_id
String
slippage_tolerance
Option<Decimal>