Skip to content

Commit

Permalink
feat: migration test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrobot committed Oct 31, 2024
1 parent a694d8f commit 255467f
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 2,562 deletions.
205 changes: 50 additions & 155 deletions contracts/swap/src/queries.rs

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion contracts/swap/src/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn execute_swap_step(
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 order_response = MsgCreateSpotMarketOrderResponse::decode(msg.payload.as_slice()).unwrap();
let order_response = parse_market_order_response(msg)?;

let trade_data = match order_response.results {
Some(trade_data) => Ok(trade_data),
Expand Down Expand Up @@ -256,3 +256,18 @@ pub fn handle_atomic_order_reply(deps: DepsMut<InjectiveQueryWrapper>, env: Env,

Ok(response)
}

pub fn parse_market_order_response(msg: Reply) -> StdResult<MsgCreateSpotMarketOrderResponse> {
let binding = msg.result.into_result().map_err(ContractError::SubMsgFailure).unwrap();

let first_messsage = binding.msg_responses.first();

let order_response = MsgCreateSpotMarketOrderResponse::decode(first_messsage.unwrap().value.as_slice())
.map_err(|err| ContractError::ReplyParseFailure {
id: msg.id,
err: err.to_string(),
})
.unwrap();

Ok(order_response)
}
Loading

0 comments on commit 255467f

Please sign in to comment.