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

fix: Prevent short positions with non-UUSDC assets as collateral #35

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading