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
Browse files Browse the repository at this point in the history
  • Loading branch information
politeWall committed Dec 21, 2023
1 parent 7707c4c commit 56c4fcd
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 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" }
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 56c4fcd

Please sign in to comment.