This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3beb612
commit 64ad795
Showing
34 changed files
with
151 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use cosmwasm_std::{coins, from_json, Binary, DepsMut, StdError, SubMsgResult}; | ||
|
||
use super::*; | ||
|
||
pub fn reply_to_spot_order_market( | ||
deps: DepsMut<ElysQuery>, | ||
data: Option<Binary>, | ||
module_resp: SubMsgResult, | ||
) -> Result<Response<ElysMsg>, ContractError> { | ||
let response = match module_resp.into_result() { | ||
Ok(response) => response, | ||
Err(err) => return Err(StdError::generic_err(err).into()), | ||
}; | ||
|
||
let meta_data = match response.data { | ||
Some(data) => data, | ||
None => return Err(StdError::generic_err("No Data").into()), | ||
}; | ||
|
||
let amm_response: AmmSwapExactAmountInResp = from_json(&meta_data)?; | ||
|
||
let orders: Vec<SpotOrder> = SPOT_ORDER.load(deps.storage)?; | ||
|
||
let order_id: u64 = match data { | ||
Some(order_id) => from_json(&order_id)?, | ||
None => return Err(StdError::generic_err("no meta_data".to_string()).into()), | ||
}; | ||
|
||
let order: SpotOrder = match orders.iter().find(|order| order.order_id == order_id) { | ||
Some(order) => order.to_owned(), | ||
None => return Err(ContractError::OrderNotFound { order_id }), | ||
}; | ||
|
||
let bank_msg = BankMsg::Send { | ||
to_address: order.owner_address.to_string(), | ||
amount: coins( | ||
amm_response.token_out_amount.i64() as u128, | ||
order.order_target_denom.to_string(), | ||
), | ||
}; | ||
|
||
let mut processd_spot_orders = PROCESSED_SPOT_ORDER.load(deps.storage)?; | ||
processd_spot_orders.push((order_id, bank_msg)); | ||
PROCESSED_SPOT_ORDER.save(deps.storage, &processd_spot_orders)?; | ||
|
||
let resp: Response<ElysMsg> = Response::new(); | ||
|
||
Ok(resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ pub enum ReplyType { | |
MarginBrokerOpen, | ||
MarginBrokerClose, | ||
MarginBrokerOpenMarketBuy, | ||
SpotOrderMarketBuy, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.