From 57f6e625e227e643ab42cf01d132d7b1c4c3c2d6 Mon Sep 17 00:00:00 2001 From: politeWall <138504353+politeWall@users.noreply.github.com> Date: Mon, 20 Nov 2023 14:56:01 +0100 Subject: [PATCH] fix: fix issue with margin that the user could create a short position with other asset than uusdc --- front_end_script/README.md | 8 +++++++- src/action/execute/create_margin_order.rs | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/front_end_script/README.md b/front_end_script/README.md index a5f0f1d..b1b02ce 100644 --- a/front_end_script/README.md +++ b/front_end_script/README.md @@ -161,7 +161,13 @@ createMarginOrder( #### Exemple ```javascript -createMarginOrder("short", { denom: "BTC", amount: "2" }, "4.3", "ETH", "2.2"); +createMarginOrder( + "short", + { denom: "uusdc", amount: "2002" }, + "4.3", + "ueth", + "2.2" +); ``` ### 7. cancelMarginOrder(order_id) diff --git a/src/action/execute/create_margin_order.rs b/src/action/execute/create_margin_order.rs index a9344a1..0c03648 100644 --- a/src/action/execute/create_margin_order.rs +++ b/src/action/execute/create_margin_order.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_json_binary, Coin, Decimal, Int128, SubMsg}; +use cosmwasm_std::{to_json_binary, Coin, Decimal, Int128, StdError, SubMsg}; use crate::msg::ReplyType; @@ -21,6 +21,12 @@ pub fn create_margin_order( return Err(ContractError::CollateralAmount); } + if position == MarginPosition::Short && collateral.denom == "uusdc" { + return Err( + StdError::generic_err("the collateral asset for a short can only be USDC").into(), + ); + } + cw_utils::must_pay(&info, &info.funds[0].denom)?; let borrow_token = Coin {