Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
fix: porcessed closed position
Browse files Browse the repository at this point in the history
  • Loading branch information
politeWall committed Dec 22, 2023
1 parent 94ebafa commit 0e805ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/action/sudo/process_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::msg::ReplyType;
use cosmwasm_std::{
to_json_binary, Decimal, Int128, OverflowError, StdError, StdResult, Storage, SubMsg,
};
use elys_bindings::query_resp::AmmSwapEstimationByDenomResponse;
use elys_bindings::query_resp::{AmmSwapEstimationByDenomResponse, MarginMtpResponse};
use std::ops::Div;

use super::*;
Expand Down Expand Up @@ -91,8 +91,20 @@ fn process_margin_order(
ReplyType::MarginBrokerOpen,
)
} else {
let mtp = querier.mtp(order.owner.clone(), order.position_id.unwrap())?;
let amount = mtp.mtp.unwrap().custodies[0].amount.u128() as i128;
let mtp = match querier
.mtp(order.owner.clone(), order.position_id.unwrap())?
.mtp
{
Some(mtp) => mtp,
None => {
let mut order = order.to_owned();
order.status = Status::error("Position Already Closed");
PENDING_MARGIN_ORDER.remove(storage, order.order_id);
return Ok(());
}
};

let amount = mtp.custodies[0].amount.u128() as i128;
(
ElysMsg::margin_close_position(&order.owner, order.position_id.unwrap(), amount),
ReplyType::MarginBrokerClose,
Expand Down Expand Up @@ -129,7 +141,6 @@ fn check_margin_order(
) -> bool {
if order.order_type == MarginOrderType::MarketClose
|| order.order_type == MarginOrderType::MarketOpen
|| order.status != Status::Pending
{
return false;
}
Expand Down Expand Up @@ -174,9 +185,6 @@ fn check_spot_order(
if order.order_type == SpotOrderType::MarketBuy {
return false;
}
if order.status != Status::Pending {
return false;
}

let order_spot_price = match order.order_amount.denom == order.order_price.base_denom {
true => order.order_price.rate,
Expand Down
7 changes: 7 additions & 0 deletions src/types/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ pub enum Status {
Pending,
Executed,
Canceled,
Error(String),
}

impl Status {
pub fn error(msg: impl Into<String>) -> Self {
Self::Error(msg.into())
}
}

0 comments on commit 0e805ce

Please sign in to comment.