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

Commit

Permalink
feat: add query to margin position by address (#73)
Browse files Browse the repository at this point in the history
* feat: add query to margin position by address

* docs: docs  and js script update
  • Loading branch information
politeWall authored Dec 21, 2023
1 parent 7707c4c commit 790d482
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 65 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ thiserror = "1"
schemars = "0.8.1"
cosmwasm-schema = "1.1.4"
cw-utils = "0.13"
elys-bindings = { git = "https://github.com/elys-network/bindings", tag = "v0.12.0" }
elys-bindings = { git = "https://github.com/elys-network/bindings", tag = "v0.13.0" }

[dev-dependencies]

cw-multi-test = "0.13.4"
serde_json = "1.0.107"
elys-bindings = { git = "https://github.com/elys-network/bindings", tag = "v0.12.0", features = [
elys-bindings = { git = "https://github.com/elys-network/bindings", tag = "v0.13.0", features = [
"testing",
] }
elys-bindings-test = { git = "https://github.com/elys-network/bindings", tag = "v0.12.0" }
elys-bindings-test = { git = "https://github.com/elys-network/bindings", tag = "v0.13.0" }
118 changes: 58 additions & 60 deletions front_end_script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,29 +397,20 @@ stake_request(
stake_request(
3000000,
"uelys",
"elysvaloper17wc3s7am5qgjk4pm0k96kg6laxq8hkyq0dzq5n",
"elysvaloper17wc3s7am5qgjk4pm0k96kg6laxq8hkyq0dzq5n"
);
```
```js
stake_request(
3000000,
"ueden",
);
stake_request(3000000, "ueden");
```
```js
stake_request(
3000000,
"uedenb",
);
stake_request(3000000, "uedenb");
```
```js
stake_request(
3000000,
"uusdc",
);
stake_request(3000000, "uusdc");
```
### 15. unstakeRequest (amount, asset, validator_address?)
Expand Down Expand Up @@ -448,29 +439,20 @@ unstake_request(
unstake_request(
3000000,
"uelys",
"elysvaloper17wc3s7am5qgjk4pm0k96kg6laxq8hkyq0dzq5n",
"elysvaloper17wc3s7am5qgjk4pm0k96kg6laxq8hkyq0dzq5n"
);
```
```js
unstake_request(
3000000,
"ueden",
);
unstake_request(3000000, "ueden");
```
```js
unstake_request(
3000000,
"uedenb",
);
unstake_request(3000000, "uedenb");
```
```js
unstake_request(
3000000,
"uusdc",
);
unstake_request(3000000, "uusdc");
```
### 16. elysRedelegationRequest (validator_src_address, validator_dst_address, amount)
Expand All @@ -489,7 +471,7 @@ you can use this function to re-delegate token.
elys_redelegation_request(
"validator_src_address",
"validator_dst_address",
"amount",
"amount"
);
```
Expand All @@ -499,7 +481,7 @@ elys_redelegation_request(
elys_redelegation_request(
"elysvaloper12tzylat4udvjj56uuhu3vj2n4vgp7cf9pwcqcs",
"elysvaloper17wc3s7am5qgjk4pm0k96kg6laxq8hkyq0dzq5n",
{ denom: "uelys", amount: "20000" },
{ denom: "uelys", amount: "20000" }
);
```
Expand All @@ -516,11 +498,7 @@ you can use this function to cancel unbonding.
#### Usage
```js
elys_cancel_unstake_request(
"validator_address",
"amount",
"creation_height",
);
elys_cancel_unstake_request("validator_address", "amount", "creation_height");
```
#### Example
Expand All @@ -529,7 +507,7 @@ elys_cancel_unstake_request(
elys_cancel_unstake_request(
"elysvaloper12tzylat4udvjj56uuhu3vj2n4vgp7cf9pwcqcs",
{ denom: "uelys", amount: "20000" },
100000,
100000
);
```
Expand All @@ -544,17 +522,13 @@ you can use this function to vest eden token
#### Usage
```js
eden_vest_request(
"amount",
);
eden_vest_request("amount");
```
#### Example
```js
eden_vest_request(
{ denom: "uelys", amount: "20000" },
);
eden_vest_request({ denom: "uelys", amount: "20000" });
```
### 19. edenCancelVestRequest (amount)
Expand All @@ -568,17 +542,13 @@ you can use this function to cancel vesting of eden.
#### Usage
```js
eden_cancel_vest_request(
"amount",
);
eden_cancel_vest_request("amount");
```
#### Example
```js
eden_cancel_vest_request(
{ denom: "uelys", amount: "20000" },
);
eden_cancel_vest_request({ denom: "uelys", amount: "20000" });
```
### 20. claimRewardsRequest (amount)
Expand All @@ -592,20 +562,19 @@ you can use this function to claim rewards.
#### Usage
```js
claim_rewards_request(
"withdraw_type",
);
claim_rewards_request("withdraw_type");
```
#### Example
```js
claim_rewards_request(
1, // Earntype_UsdcProgram
1 // Earntype_UsdcProgram
);
```
#### Enum types
```
pub enum EarnType {
AllProgram = 0,
Expand All @@ -627,16 +596,14 @@ you can use this function to claim validator's commission.
#### Usage
```js
claim_validator_commission_request(
"validator_address",
);
claim_validator_commission_request("validator_address");
```
#### Example
```js
claim_validator_commission_request(
"elysvaloper12tzylat4udvjj56uuhu3vj2n4vgp7cf9pwcqcs",
"elysvaloper12tzylat4udvjj56uuhu3vj2n4vgp7cf9pwcqcs"
);
```
Expand All @@ -658,7 +625,7 @@ amm_join_pool_request(
"pool_id",
"max_amounts_in",
"share_amount_out",
"no_remaining",
"no_remaining"
);
```
Expand All @@ -667,9 +634,12 @@ amm_join_pool_request(
```js
amm_join_pool_request(
1,
[{denom: "uelys", amount: "20000"}, {denom: "usdc", amount: "10000"}],
[
{ denom: "uelys", amount: "20000" },
{ denom: "usdc", amount: "10000" },
],
10000,
true,
true
);
```
Expand All @@ -691,7 +661,7 @@ amm_exit_pool_request(
"pool_id",
"min_amounts_out",
"share_amount_in",
"token_out_denom",
"token_out_denom"
);
```
Expand All @@ -700,9 +670,12 @@ amm_exit_pool_request(
```js
amm_exit_pool_request(
1,
[{denom: "uelys", amount: "20000"}, {denom: "usdc", amount: "10000"}],
[
{ denom: "uelys", amount: "20000" },
{ denom: "usdc", amount: "10000" },
],
10000,
"uelys",
"uelys"
);
```
Expand Down Expand Up @@ -753,6 +726,31 @@ get_liquidity_pools(
"{"offset":0, "limit":10, "count_total": false, "reverse": false}}}",
);
```
### 24. marginGetPositionsForAddress(address, pagination)
Query margin position using address
- `address` (String) addres of the user
- `pagination` (PageRequest)
#### Usage.
```js
marginGetPositionsForAddress("address", "pagination");
```
#### Exemple
```js
marginGetPositionsForAddress("elys1x5fehwug2vtkyn4vpunwkfn9zxkpxl8jg0lwuu", {
offset: 0,
limit: 10,
count_total: false,
reverse: true,
});
```
## Configuration
Before using these functions, you need to configure the following parameters in the script:
Expand Down
21 changes: 21 additions & 0 deletions front_end_script/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,24 @@ async function marginOpenEstimation(
);
console.log(`Result: `, result);
}

async function marginGetPositionsForAddress(address, pagination) {
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_get_position_for_address: {
address: address,
pagination: pagination,
},
}
);
console.log(`Result: `, result);
}
2 changes: 2 additions & 0 deletions src/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod query {
mod get_margin_positions;
mod get_spot_order;
mod get_spot_orders;
mod margin_get_position_for_address;
mod margin_open_estimation;
mod swap_estimation_by_denom;

Expand All @@ -29,6 +30,7 @@ pub mod query {
pub use get_margin_positions::get_margin_positions;
pub use get_spot_order::get_spot_order;
pub use get_spot_orders::get_spot_orders;
pub use margin_get_position_for_address::margin_get_position_for_address;
pub use margin_open_estimation::margin_open_estimation;
pub use swap_estimation_by_denom::swap_estimation_by_denom;
}
Expand Down
13 changes: 13 additions & 0 deletions src/action/query/margin_get_position_for_address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use super::*;

pub fn margin_get_position_for_address(
deps: Deps<ElysQuery>,
address: String,
pagination: PageRequest,
) -> Result<MarginGetPositionsForAddressResponse, ContractError> {
let querier = ElysQuerier::new(&deps.querier);

let resp = querier.margin_get_position_for_address(address, pagination)?;

Ok(resp)
}
1 change: 1 addition & 0 deletions src/action/reply/open_margin_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn reply_to_open_margin_position(
};

order.status = Status::Executed;
order.position_id = Some(res.id);

MARGIN_ORDER.save(deps.storage, order_id, &order)?;

Expand Down
6 changes: 6 additions & 0 deletions src/entry_point/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,11 @@ pub fn query(deps: Deps<ElysQuery>, _env: Env, msg: QueryMsg) -> Result<Binary,
take_profit_price,
user_address,
)?)?),
MarginGetPositionsForAddress {
address,
pagination,
} => Ok(to_json_binary(&query::margin_get_position_for_address(
deps, address, pagination,
)?)?),
}
}
5 changes: 5 additions & 0 deletions src/msg/query_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ pub enum QueryMsg {
take_profit_price: Decimal,
user_address: Option<String>,
},
#[returns(MarginGetPositionsForAddressResponse)]
MarginGetPositionsForAddress {
address: String,
pagination: PageRequest,
},
}

0 comments on commit 790d482

Please sign in to comment.