pub fn after_trade(
    mut deps: DepsMut,
    env: Env,
    info: MessageInfo,
    loan_fee: Uint128,
) -> VaultResult {
    // Deposit funds into anchor if applicable.
    let response = try_anchor_deposit(deps.branch(), env.clone())?;

    let mut conf = PROFIT.load(deps.storage)?;

    let balance = total_value(deps.as_ref(), &env)?.0;

    // Check if balance increased with expected fee, otherwise cancel everything
    if balance < conf.last_balance + loan_fee {
        return Err(StableVaultError::CancelLosingTrade {});
    }

    let profit = balance - conf.last_balance;

    conf.last_profit = profit;
    conf.last_balance = Uint128::zero();
    PROFIT.save(deps.storage, &conf)?;

    let commission_response = send_commissions(deps.as_ref(), info, profit)?;

    Ok(response
        // Send commission of profit to Treasury
        .add_submessages(commission_response.messages)
        .add_attributes(commission_response.attributes)
        .add_attribute("value after commission: ", balance.to_string()))
}
// Checks if balance increased after the trade
Checks if balance increased after the trade
Checks if balance increased after the trade
pub fn after_trade(
    mut deps: DepsMut,
    env: Env,
    info: MessageInfo,
    loan_fee: Uint128,
) -> VaultResult {
    // Deposit funds into anchor if applicable.
    let response = try_anchor_deposit(deps.branch(), env.clone())?;
    let mut conf = PROFIT.load(deps.storage)?;
    let balance = total_value(deps.as_ref(), &env)?.0;
    // Check if balance increased with expected fee, otherwise cancel everything
    if balance < conf.last_balance + loan_fee {
        return Err(StableVaultError::CancelLosingTrade {});
    }
    let profit = balance - conf.last_balance;
    conf.last_profit = profit;
    conf.last_balance = Uint128::zero();
    PROFIT.save(deps.storage, &conf)?;
    let commission_response = send_commissions(deps.as_ref(), info, profit)?;
    Ok(response
        // Send commission of profit to Treasury
        .add_submessages(commission_response.messages)
        .add_attributes(commission_response.attributes)
        .add_attribute("value after commission: ", balance.to_string()))
}
pub fn after_trade ( mut deps : DepsMut , env : Env , info : MessageInfo , loan_fee : Uint128 , ) -> VaultResult { // Deposit funds into anchor if applicable. let response = try_anchor_deposit ( deps . branch ( ) , env . clone ( ) ) ? ; let mut conf = PROFIT . load ( deps . storage ) ? ; let balance = total_value ( deps . as_ref ( ) , & env ) ? . 0 ; // Check if balance increased with expected fee, otherwise cancel everything if balance < conf . last_balance + loan_fee { return Err ( StableVaultError :: CancelLosingTrade { } ) ; } let profit = balance - conf . last_balance ; conf . last_profit = profit ; conf . last_balance = Uint128 :: zero ( ) ; PROFIT . save ( deps . storage , & conf ) ? ; let commission_response = send_commissions ( deps . as_ref ( ) , info , profit ) ? ; Ok ( response // Send commission of profit to Treasury . add_submessages ( commission_response . messages ) . add_attributes ( commission_response . attributes ) . add_attribute ( " " , balance . to_string ( ) ) ) }
Checks if balance increased after the trade
Checks if balance increased after the trade
deps
DepsMut
env
Env
info
MessageInfo
loan_fee
Uint128
deps
DepsMut
env
Env
info
MessageInfo
loan_fee
Uint128