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

Commit

Permalink
fix: remove raw dicount field and use user address
Browse files Browse the repository at this point in the history
  • Loading branch information
politeWall committed Dec 18, 2023
1 parent a275fdb commit bf0f929
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 15 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trade_shield_contract"
version = "0.11.0"
version = "0.12.0"
edition = "2021"

[lib]
Expand All @@ -14,13 +14,13 @@ thiserror = "1"
schemars = "0.8.1"
cosmwasm-schema = "1.1.4"
cw-utils = "0.13"
elys-bindings = { version = "0.9.0", git = "https://github.com/elys-network/bindings", tag = "v0.9.0" }
elys-bindings = { version = "0.10.0", git = "https://github.com/elys-network/bindings", tag = "v0.10.0" }

[dev-dependencies]

cw-multi-test = "0.13.4"
serde_json = "1.0.107"
elys-bindings = { version = "0.9.0", git = "https://github.com/elys-network/bindings", tag = "v0.9.0", features = [
elys-bindings = { version = "0.10.0", git = "https://github.com/elys-network/bindings", tag = "v0.10.0", features = [
"testing",
] }
elys-bindings-test = { version = "0.9.0", git = "https://github.com/elys-network/bindings", tag = "v0.9.0" }
elys-bindings-test = { version = "0.10.0", git = "https://github.com/elys-network/bindings", tag = "v0.10.0" }
41 changes: 40 additions & 1 deletion front_end_script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ This function retrieves information about multiple order by querying a CosmWasm
getMarginOrders({"count_total", "limit", "reverse", "key"}, "order_type", "order_owner", status)
```

####
#### Exemple

```js
getMarginOrders(
Expand All @@ -330,6 +330,45 @@ getMarginOrders(
);
```

### 13. marginOpenEstimation (position,leverage,trading_asset,collateral,take_profit_price,user_address)

this function query an estimation on opening a MarginPosition.

#### Parameters

- `position` (String): The type of position for the margin order (e.g., "long", "short")
- `leverage` (String): The leverage for the margin position
- `trading_asset` (String): The trading asset
- `collateral` (Coin {`denom`: String, `amount`: String}) The amount that the user would like to send as a collateral
- `take_profit_price` (String): the take profit price for the open position
- `user_address` (String): user_address to calculate the discount that the user have access

#### Usage

```js
marginOpenEstimation(
"position",
"leverage",
"trading_asset",
"collateral",
"take_profit_price",
"user_address"
);
```

#### Exemple

```js
marginOpenEstimation(
"long",
"2.5",
"ubtc",
{ denom: "uusdc", amount: "20000" },
"1.5",
"elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w"
);
```

## Configuration

Before using these functions, you need to configure the following parameters in the script:
Expand Down
32 changes: 32 additions & 0 deletions front_end_script/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,35 @@ async function getMarginPositions(pagination) {
);
console.log(`Result: `, result);
}

async function getMarginPositions(
position,
leverage,
trading_asset,
collateral,
take_profit_price,
user_address
) {
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(
sender.mnemonic,
{ prefix: "elys" }
);
const sender_client = await SigningCosmWasmClient.connectWithSigner(
rpcEndpoint,
sender_wallet
);
const result = await sender_client.queryContractSmart(
trade_shield_contract_addr,
{
margin_open_estimation: {
position: position,
leverage: leverage,
trading_asset: trading_asset,
collateral: collateral,
take_profit_price: take_profit_price,
user_address: user_address,
},
}
);
console.log(`Result: `, result);
}
4 changes: 2 additions & 2 deletions src/action/query/margin_open_estimation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn margin_open_estimation(
trading_asset: String,
collateral: Coin,
take_profit_price: Decimal,
discount: Decimal,
_user_address: String,
) -> StdResult<MarginOpenEstimationResponse> {
let querier = ElysQuerier::new(&deps.querier);

Expand All @@ -19,6 +19,6 @@ pub fn margin_open_estimation(
trading_asset,
collateral,
take_profit_price,
discount,
Decimal::zero(),
)
}
4 changes: 2 additions & 2 deletions src/entry_point/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ pub fn query(deps: Deps<ElysQuery>, _env: Env, msg: QueryMsg) -> Result<Binary,
trading_asset,
collateral,
take_profit_price,
discount,
user_address,
} => Ok(to_json_binary(&query::margin_open_estimation(
deps,
position,
leverage,
trading_asset,
collateral,
take_profit_price,
discount,
user_address,
)?)?),
}
}
2 changes: 1 addition & 1 deletion src/msg/query_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ pub enum QueryMsg {
trading_asset: String,
collateral: Coin,
take_profit_price: Decimal,
discount: Decimal,
user_address: String,
},
}

0 comments on commit bf0f929

Please sign in to comment.