pub fn withdraw_liquidity(
    deps: Deps,
    msg_info: MessageInfo,
    lp_token_id: String,
    amount: Uint128,
) -> AstroportResult {
    let state = BASESTATE.load(deps.storage)?;
    // Sender must be trader
    if msg_info.sender != state.trader {
        return Err(BaseDAppError::Unauthorized {}.into());
    }
    let treasury_address = &state.treasury_address;

    // Get lp token address
    let lp_token = &state.memory.query_asset(deps, &lp_token_id)?;
    let lp_token_address = get_identifier(lp_token);
    // Get pair address
    let pair_address = state
        .memory
        .query_contract(deps, &(lp_token_id.clone() + PAIR_POSTFIX))?;

    // Check if the treasury has enough lp tokens
    has_sufficient_balance(deps, &state.memory, &lp_token_id, treasury_address, amount)?;

    // Msg that gets called on the pair address.
    let withdraw_msg: Binary = to_binary(&Cw20HookMsg::WithdrawLiquidity {})?;

    // cw20 send message that transfers the LP tokens to the pair address
    let cw20_msg = Cw20ExecuteMsg::Send {
        contract: pair_address.into_string(),
        amount,
        msg: withdraw_msg,
    };

    // Call on LP token.
    let lp_call = CosmosMsg::Wasm(WasmMsg::Execute {
        contract_addr: String::from(lp_token_address),
        msg: to_binary(&cw20_msg)?,
        funds: vec![],
    });

    Ok(Response::new().add_message(send_to_treasury(vec![lp_call], treasury_address)?))
}
/// Constructs withdraw liquidity msg and forwards it to treasury
Constructs withdraw liquidity msg and forwards it to treasury
Constructs withdraw liquidity msg and forwards it to treasury
pub fn withdraw_liquidity(
    deps: Deps,
    msg_info: MessageInfo,
    lp_token_id: String,
    amount: Uint128,
) -> AstroportResult {
    let state = BASESTATE.load(deps.storage)?;
    // Sender must be trader
    if msg_info.sender != state.trader {
        return Err(BaseDAppError::Unauthorized {}.into());
    }
    let treasury_address = &state.treasury_address;
    // Get lp token address
    let lp_token = &state.memory.query_asset(deps, &lp_token_id)?;
    let lp_token_address = get_identifier(lp_token);
    // Get pair address
    let pair_address = state
        .memory
        .query_contract(deps, &(lp_token_id.clone() + PAIR_POSTFIX))?;
    // Check if the treasury has enough lp tokens
    has_sufficient_balance(deps, &state.memory, &lp_token_id, treasury_address, amount)?;
    // Msg that gets called on the pair address.
    let withdraw_msg: Binary = to_binary(&Cw20HookMsg::WithdrawLiquidity {})?;
    // cw20 send message that transfers the LP tokens to the pair address
    let cw20_msg = Cw20ExecuteMsg::Send {
        contract: pair_address.into_string(),
        amount,
        msg: withdraw_msg,
    };
    // Call on LP token.
    let lp_call = CosmosMsg::Wasm(WasmMsg::Execute {
        contract_addr: String::from(lp_token_address),
        msg: to_binary(&cw20_msg)?,
        funds: vec![],
    });
    Ok(Response::new().add_message(send_to_treasury(vec![lp_call], treasury_address)?))
}
pub fn withdraw_liquidity ( deps : Deps , msg_info : MessageInfo , lp_token_id : String , amount : Uint128 , ) -> AstroportResult { let state = BASESTATE . load ( deps . storage ) ? ; // Sender must be trader if msg_info . sender != state . trader { return Err ( BaseDAppError :: Unauthorized { } . into ( ) ) ; } let treasury_address = & state . treasury_address ; // Get lp token address let lp_token = & state . memory . query_asset ( deps , & lp_token_id ) ? ; let lp_token_address = get_identifier ( lp_token ) ; // Get pair address let pair_address = state . memory . query_contract ( deps , & ( lp_token_id . clone ( ) + PAIR_POSTFIX ) ) ? ; // Check if the treasury has enough lp tokens has_sufficient_balance ( deps , & state . memory , & lp_token_id , treasury_address , amount ) ? ; // Msg that gets called on the pair address. let withdraw_msg : Binary = to_binary ( & Cw20HookMsg :: WithdrawLiquidity { } ) ? ; // cw20 send message that transfers the LP tokens to the pair address let cw20_msg = Cw20ExecuteMsg :: Send { contract : pair_address . into_string ( ) , amount , msg : withdraw_msg , } ; // Call on LP token. let lp_call = CosmosMsg :: Wasm ( WasmMsg :: Execute { contract_addr : String :: from ( lp_token_address ) , msg : to_binary ( & cw20_msg ) ? , funds : vec ! [ ] , } ) ; Ok ( Response :: new ( ) . add_message ( send_to_treasury ( vec ! [ lp_call ] , treasury_address ) ? ) ) }
Constructs withdraw liquidity msg and forwards it to treasury
Constructs withdraw liquidity msg and forwards it to treasury
deps
Deps
msg_info
MessageInfo
lp_token_id
String
amount
Uint128
deps
Deps
msg_info
MessageInfo
lp_token_id
String
amount
Uint128