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

Commit

Permalink
fix: Prevent short positions with non-UUSDC assets as collateral (#35)
Browse files Browse the repository at this point in the history
fix: fix issue with margin that the user could create a short position with other asset than uusdc
  • Loading branch information
politeWall authored Nov 20, 2023
1 parent 9f531ef commit 9829fa3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion front_end_script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion src/action/execute/create_margin_order.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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 {
Expand Down

0 comments on commit 9829fa3

Please sign in to comment.