pub(crate) fn withdraw_passive_strategy(
    deps: &Deps,
    withdraw_amount: Uint128,
    requested_info: AssetInfo,
    astro_lp_token_address: &Addr,
    astro_lp_address: &Addr,
    response: Response,
) -> VaultResult<Response> {
    // convert requested_info into an Astroport asset
    let requested_info = requested_info.to_astroport(deps)?;

    let pool_info: astroport::pair::PoolResponse = deps.querier.query_wasm_smart(
        astro_lp_address,
        &astroport::pair_stable_bluna::QueryMsg::Pool {},
    )?;

    let requested_asset = astroport::asset::Asset {
        amount: withdraw_amount,
        info: requested_info,
    };

    let share_to_withdraw =
        get_share_amount(deps, astro_lp_address.clone(), requested_asset.clone())?;

    // cw20 send message that transfers the LP tokens to the pair address and withdraws liquidity
    let cw20_withdraw_liquidity_msg: CosmosMsg = WasmMsg::Execute {
        contract_addr: astro_lp_token_address.clone().into_string(),
        msg: to_binary(&Cw20ExecuteMsg::Send {
            contract: astro_lp_address.clone().into_string(),
            amount: share_to_withdraw,
            msg: to_binary(&astroport::pair::Cw20HookMsg::WithdrawLiquidity {})?,
        })?,
        funds: vec![],
    }
    .into();

    // provide liquidity with the remaining bLuna as single-sided LP provision
    let pool_non_desired_asset = pool_info
        .assets
        .iter()
        .find(|asset| asset.info != requested_asset.info)
        .ok_or_else(|| {
            LunaVaultError::generic_err(
                "Failed to get non-desired asset when providing single-sided liquidity",
            )
        })?;

    // reference: https://github.com/astroport-fi/astroport-core/blob/c0a121798157ea3e5540a19b8061eb0196b15667/contracts/pair_stable_bluna/src/contract.rs#L729-L737
    let unwanted_amount_returned = Decimal::from_ratio(share_to_withdraw, pool_info.total_share)
        * pool_non_desired_asset.amount;

    let bluna_lp_msg = WasmMsg::Execute {
        contract_addr: astro_lp_address.clone().into_string(),
        msg: to_binary(
            &astroport::pair_stable_bluna::ExecuteMsg::ProvideLiquidity {
                assets: [
                    astroport::asset::Asset {
                        amount: Uint128::zero(),
                        info: requested_asset.info.clone(),
                    },
                    astroport::asset::Asset {
                        amount: unwanted_amount_returned,
                        info: pool_non_desired_asset.info.clone(),
                    },
                ],
                slippage_tolerance: None,
                auto_stake: None,
                receiver: None,
            },
        )?,
        funds: vec![],
    }
    .into();

    let response = response.add_messages(vec![
        cw20_withdraw_liquidity_msg, // 1. withdraw bluna and Luna from LP.
        bluna_lp_msg,                // 2. provide single-sided LP provision to astroport pool
    ]);

    Ok(response)
}
// Withdraws Luna from the passive strategy (Astroport): luna-bluna LP -> Luna + bLuna
Withdraws Luna from the passive strategy (Astroport): luna-bluna LP -> Luna + bLuna
Withdraws Luna from the passive strategy ( Astroport ) : luna - bluna LP - > Luna + bLuna
pub(crate) fn withdraw_passive_strategy(
    deps: &Deps,
    withdraw_amount: Uint128,
    requested_info: AssetInfo,
    astro_lp_token_address: &Addr,
    astro_lp_address: &Addr,
    response: Response,
) -> VaultResult<Response> {
    // convert requested_info into an Astroport asset
    let requested_info = requested_info.to_astroport(deps)?;
    let pool_info: astroport::pair::PoolResponse = deps.querier.query_wasm_smart(
        astro_lp_address,
        &astroport::pair_stable_bluna::QueryMsg::Pool {},
    )?;
    let requested_asset = astroport::asset::Asset {
        amount: withdraw_amount,
        info: requested_info,
    };
    let share_to_withdraw =
        get_share_amount(deps, astro_lp_address.clone(), requested_asset.clone())?;
    // cw20 send message that transfers the LP tokens to the pair address and withdraws liquidity
    let cw20_withdraw_liquidity_msg: CosmosMsg = WasmMsg::Execute {
        contract_addr: astro_lp_token_address.clone().into_string(),
        msg: to_binary(&Cw20ExecuteMsg::Send {
            contract: astro_lp_address.clone().into_string(),
            amount: share_to_withdraw,
            msg: to_binary(&astroport::pair::Cw20HookMsg::WithdrawLiquidity {})?,
        })?,
        funds: vec![],
    }
    .into();
    // provide liquidity with the remaining bLuna as single-sided LP provision
    let pool_non_desired_asset = pool_info
        .assets
        .iter()
        .find(|asset| asset.info != requested_asset.info)
        .ok_or_else(|| {
            LunaVaultError::generic_err(
                "Failed to get non-desired asset when providing single-sided liquidity",
            )
        })?;
    // reference: https://github.com/astroport-fi/astroport-core/blob/c0a121798157ea3e5540a19b8061eb0196b15667/contracts/pair_stable_bluna/src/contract.rs#L729-L737
    let unwanted_amount_returned = Decimal::from_ratio(share_to_withdraw, pool_info.total_share)
        * pool_non_desired_asset.amount;
    let bluna_lp_msg = WasmMsg::Execute {
        contract_addr: astro_lp_address.clone().into_string(),
        msg: to_binary(
            &astroport::pair_stable_bluna::ExecuteMsg::ProvideLiquidity {
                assets: [
                    astroport::asset::Asset {
                        amount: Uint128::zero(),
                        info: requested_asset.info.clone(),
                    },
                    astroport::asset::Asset {
                        amount: unwanted_amount_returned,
                        info: pool_non_desired_asset.info.clone(),
                    },
                ],
                slippage_tolerance: None,
                auto_stake: None,
                receiver: None,
            },
        )?,
        funds: vec![],
    }
    .into();
    let response = response.add_messages(vec![
        cw20_withdraw_liquidity_msg, // 1. withdraw bluna and Luna from LP.
        bluna_lp_msg,                // 2. provide single-sided LP provision to astroport pool
    ]);
    Ok(response)
}
pub ( crate ) fn withdraw_passive_strategy ( deps : & Deps , withdraw_amount : Uint128 , requested_info : AssetInfo , astro_lp_token_address : & Addr , astro_lp_address : & Addr , response : Response , ) -> VaultResult < Response > { // convert requested_info into an Astroport asset let requested_info = requested_info . to_astroport ( deps ) ? ; let pool_info : astroport :: pair :: PoolResponse = deps . querier . query_wasm_smart ( astro_lp_address , & astroport :: pair_stable_bluna :: QueryMsg :: Pool { } , ) ? ; let requested_asset = astroport :: asset :: Asset { amount : withdraw_amount , info : requested_info , } ; let share_to_withdraw = get_share_amount ( deps , astro_lp_address . clone ( ) , requested_asset . clone ( ) ) ? ; // cw20 send message that transfers the LP tokens to the pair address and withdraws liquidity let cw20_withdraw_liquidity_msg : CosmosMsg = WasmMsg :: Execute { contract_addr : astro_lp_token_address . clone ( ) . into_string ( ) , msg : to_binary ( & Cw20ExecuteMsg :: Send { contract : astro_lp_address . clone ( ) . into_string ( ) , amount : share_to_withdraw , msg : to_binary ( & astroport :: pair :: Cw20HookMsg :: WithdrawLiquidity { } ) ? , } ) ? , funds : vec ! [ ] , } . into ( ) ; // provide liquidity with the remaining bLuna as single-sided LP provision let pool_non_desired_asset = pool_info . assets . iter ( ) . find ( | asset | asset . info != requested_asset . info ) . ok_or_else ( | | { LunaVaultError :: generic_err ( " " , ) } ) ? ; // reference: https://github.com/astroport-fi/astroport-core/blob/c0a121798157ea3e5540a19b8061eb0196b15667/contracts/pair_stable_bluna/src/contract.rs#L729-L737 let unwanted_amount_returned = Decimal :: from_ratio ( share_to_withdraw , pool_info . total_share ) * pool_non_desired_asset . amount ; let bluna_lp_msg = WasmMsg :: Execute { contract_addr : astro_lp_address . clone ( ) . into_string ( ) , msg : to_binary ( & astroport :: pair_stable_bluna :: ExecuteMsg :: ProvideLiquidity { assets : [ astroport :: asset :: Asset { amount : Uint128 :: zero ( ) , info : requested_asset . info . clone ( ) , } , astroport :: asset :: Asset { amount : unwanted_amount_returned , info : pool_non_desired_asset . info . clone ( ) , } , ] , slippage_tolerance : None , auto_stake : None , receiver : None , } , ) ? , funds : vec ! [ ] , } . into ( ) ; let response = response . add_messages ( vec ! [ cw20_withdraw_liquidity_msg // 1. withdraw bluna and Luna from LP. bluna_lp_msg // 2. provide single-sided LP provision to astroport pool ] ) ; Ok ( response ) }
Withdraws Luna from the passive strategy (Astroport): luna-bluna LP -> Luna + bLuna
Withdraws Luna from the passive strategy ( Astroport ) : luna - bluna LP - > Luna + bLuna
deps
&Deps
withdraw_amount
Uint128
requested_info
AssetInfo
astro_lp_token_address
&Addr
astro_lp_address
&Addr
response
Response
deps
&Deps
withdraw_amount
Uint128
requested_info
AssetInfo
astro_lp_token_address
&Addr
astro_lp_address
&Addr
response
Response