pub fn try_arb_above_peg(
    deps: DepsMut,
    env: Env,
    msg_info: MessageInfo,
    details: ArbDetails,
) -> VaultResult {
    let state = STATE.load(deps.storage)?;
    let deposit_info = ARB_BASE_ASSET.load(deps.storage)?;

    // Ensure the caller is the vault
    if msg_info.sender != state.vault_address {
        return Err(StableArbError::Unauthorized {});
    }

    // Set vars
    let pool_address = POOLS.load(deps.storage, &details.pool_name)?;
    let denom = deposit_info.get_denom()?;
    let lent_coin = deduct_tax(
        deps.as_ref(),
        Coin::new(details.asset.amount.u128(), denom.clone()),
    )?;
    let ask_denom = LUNA_DENOM.to_string();
    let response: Response<TerraMsgWrapper> = Response::new();

    // Check if we have enough funds
    let balance = query_balance(&deps.querier, env.contract.address.clone(), denom)?;
    if balance < details.asset.amount {
        return Err(StableArbError::Broke {});
    }
    // Simulate first tx with Terraswap
    let expected_luna_received =
        simulate_terraswap_swap(deps.as_ref(), pool_address.clone(), lent_coin.clone())?;

    // Construct offer for Market Swap
    let offer_coin = Coin {
        denom: ask_denom,
        amount: expected_luna_received,
    };

    // Terraswap msg, swap STABLE -> LUNA
    let terraswap_msg: CosmosMsg<TerraMsgWrapper> = CosmosMsg::Wasm(WasmMsg::Execute {
        contract_addr: pool_address.to_string(),
        funds: vec![lent_coin.clone()],
        msg: to_binary(&create_terraswap_msg(
            lent_coin.clone(),
            details.belief_price,
            Some(details.slippage),
        ))?,
    });

    // Market swap msg, swap LUNA -> STABLE
    let swap_msg = create_swap_msg(offer_coin, lent_coin.denom);

    let logs = vec![
        ("action", String::from("arb above peg")),
        ("offer_amount", lent_coin.amount.to_string()),
        ("expected_luna", expected_luna_received.to_string()),
    ];

    // Create callback, this will send the funds back to the vault.
    let callback_msg =
        CallbackMsg::AfterSuccessfulTradeCallback {}.to_cosmos_msg(&env.contract.address)?;

    Ok(response
        .add_attributes(logs)
        .add_message(terraswap_msg)
        .add_message(swap_msg)
        .add_message(callback_msg))
}
// Attempt to perform an arbitrage operation with the assumption that
// the currency to be arb'd is above peg. Needed funds should be provided
// by the earlier stablecoin vault flashloan call.
Attempt to perform an arbitrage operation with the assumption that
the currency to be arb'd is above peg. Needed funds should be provided
by the earlier stablecoin vault flashloan call.
Attempt to perform an arbitrage operation with the assumption that the currency to be arb ' d is above peg . Needed funds should be provided by the earlier stablecoin vault flashloan call .
pub fn try_arb_above_peg(
    deps: DepsMut,
    env: Env,
    msg_info: MessageInfo,
    details: ArbDetails,
) -> VaultResult {
    let state = STATE.load(deps.storage)?;
    let deposit_info = ARB_BASE_ASSET.load(deps.storage)?;
    // Ensure the caller is the vault
    if msg_info.sender != state.vault_address {
        return Err(StableArbError::Unauthorized {});
    }
    // Set vars
    let pool_address = POOLS.load(deps.storage, &details.pool_name)?;
    let denom = deposit_info.get_denom()?;
    let lent_coin = deduct_tax(
        deps.as_ref(),
        Coin::new(details.asset.amount.u128(), denom.clone()),
    )?;
    let ask_denom = LUNA_DENOM.to_string();
    let response: Response<TerraMsgWrapper> = Response::new();
    // Check if we have enough funds
    let balance = query_balance(&deps.querier, env.contract.address.clone(), denom)?;
    if balance < details.asset.amount {
        return Err(StableArbError::Broke {});
    }
    // Simulate first tx with Terraswap
    let expected_luna_received =
        simulate_terraswap_swap(deps.as_ref(), pool_address.clone(), lent_coin.clone())?;
    // Construct offer for Market Swap
    let offer_coin = Coin {
        denom: ask_denom,
        amount: expected_luna_received,
    };
    // Terraswap msg, swap STABLE -> LUNA
    let terraswap_msg: CosmosMsg<TerraMsgWrapper> = CosmosMsg::Wasm(WasmMsg::Execute {
        contract_addr: pool_address.to_string(),
        funds: vec![lent_coin.clone()],
        msg: to_binary(&create_terraswap_msg(
            lent_coin.clone(),
            details.belief_price,
            Some(details.slippage),
        ))?,
    });
    // Market swap msg, swap LUNA -> STABLE
    let swap_msg = create_swap_msg(offer_coin, lent_coin.denom);
    let logs = vec![
        ("action", String::from("arb above peg")),
        ("offer_amount", lent_coin.amount.to_string()),
        ("expected_luna", expected_luna_received.to_string()),
    ];
    // Create callback, this will send the funds back to the vault.
    let callback_msg =
        CallbackMsg::AfterSuccessfulTradeCallback {}.to_cosmos_msg(&env.contract.address)?;
    Ok(response
        .add_attributes(logs)
        .add_message(terraswap_msg)
        .add_message(swap_msg)
        .add_message(callback_msg))
}
pub fn try_arb_above_peg ( deps : DepsMut , env : Env , msg_info : MessageInfo , details : ArbDetails , ) -> VaultResult { let state = STATE . load ( deps . storage ) ? ; let deposit_info = ARB_BASE_ASSET . load ( deps . storage ) ? ; // Ensure the caller is the vault if msg_info . sender != state . vault_address { return Err ( StableArbError :: Unauthorized { } ) ; } // Set vars let pool_address = POOLS . load ( deps . storage , & details . pool_name ) ? ; let denom = deposit_info . get_denom ( ) ? ; let lent_coin = deduct_tax ( deps . as_ref ( ) , Coin :: new ( details . asset . amount . u128 ( ) , denom . clone ( ) ) , ) ? ; let ask_denom = LUNA_DENOM . to_string ( ) ; let response : Response < TerraMsgWrapper > = Response :: new ( ) ; // Check if we have enough funds let balance = query_balance ( & deps . querier , env . contract . address . clone ( ) , denom ) ? ; if balance < details . asset . amount { return Err ( StableArbError :: Broke { } ) ; } // Simulate first tx with Terraswap let expected_luna_received = simulate_terraswap_swap ( deps . as_ref ( ) , pool_address . clone ( ) , lent_coin . clone ( ) ) ? ; // Construct offer for Market Swap let offer_coin = Coin { denom : ask_denom , amount : expected_luna_received , } ; // Terraswap msg, swap STABLE -> LUNA let terraswap_msg : CosmosMsg < TerraMsgWrapper > = CosmosMsg :: Wasm ( WasmMsg :: Execute { contract_addr : pool_address . to_string ( ) , funds : vec ! [ lent_coin clone ( ) ] , msg : to_binary ( & create_terraswap_msg ( lent_coin . clone ( ) , details . belief_price , Some ( details . slippage ) , ) ) ? , } ) ; // Market swap msg, swap LUNA -> STABLE let swap_msg = create_swap_msg ( offer_coin , lent_coin . denom ) ; let logs = vec ! [ ( " " String from ( " " ) ) ( " " lent_coin amount to_string ( ) ) ( " " expected_luna_received to_string ( ) ) ] ; // Create callback, this will send the funds back to the vault. let callback_msg = CallbackMsg :: AfterSuccessfulTradeCallback { } . to_cosmos_msg ( & env . contract . address ) ? ; Ok ( response . add_attributes ( logs ) . add_message ( terraswap_msg ) . add_message ( swap_msg ) . add_message ( callback_msg ) ) }
Attempt to perform an arbitrage operation with the assumption that
the currency to be arb'd is above peg.
Attempt to perform an arbitrage operation with the assumption that the currency to be arb ' d is above peg .
deps
DepsMut
env
Env
msg_info
MessageInfo
details
ArbDetails
deps
DepsMut
env
Env
msg_info
MessageInfo
details
ArbDetails