types::{CurrentSwapOperation, CurrentSwapStep, FPCoin, SwapEstimationAmount, SwapQuantityMode, SwapResults},
use cosmwasm_std::{BankMsg, Deps, DepsMut, Env, Event, MessageInfo, Reply, Response, StdError, StdResult, SubMsg};
create_spot_market_order_msg, get_default_subaccount_id_for_checked_address, InjectiveMsgWrapper, InjectiveQuerier, InjectiveQueryWrapper,
let first_market = querier.query_spot_market(&first_market_id)?.market.expect("market should be available");
let input_spendable_before = query_contract_spendable_balance(&deps.as_ref(), &env, ¤t_balance.denom)?;
let order_message = SubMsg::reply_on_success(create_spot_market_order_msg(contract.to_owned(), order), ATOMIC_ORDER_REPLY_ID);
pub fn handle_atomic_order_reply(deps: DepsMut<InjectiveQueryWrapper>, env: Env, msg: Reply) -> Result<Response<InjectiveMsgWrapper>, ContractError> {
let dec_scale_factor = dec_scale_factor(); // protobuf serializes Dec values with extra 10^18 factor
let input_spendable_after = query_contract_spendable_balance(&deps.as_ref(), &env, ¤t_step.current_balance.denom)?;
let next_market = querier.query_spot_market(&next_market_id)?.market.expect("market should be available");
return execute_swap_step(deps, env, swap, current_step.step_idx + 1, new_balance).map_err(ContractError::Std);
fn query_contract_spendable_balance(deps: &Deps<InjectiveQueryWrapper>, env: &Env, denom: &str) -> StdResult<FPDecimal> {
let bank_balance: FPDecimal = deps.querier.query_balance(&env.contract.address, denom)?.amount.into();
pub(crate) fn ensure_support_funds_preserved(denom: &str, minimum_remaining: FPDecimal, actual_remaining: FPDecimal) -> Result<(), ContractError> {
pub(crate) fn ensure_minimum_output(output: &cosmwasm_std::Coin, minimum: FPDecimal) -> Result<(), ContractError> {
let order_response = MsgCreateSpotMarketOrderResponse::decode(first_message.unwrap().value.as_slice())