From 17457bc071751b0af2db4534f107ab0d1c136d17 Mon Sep 17 00:00:00 2001 From: politeWall <138504353+politeWall@users.noreply.github.com> Date: Wed, 15 Nov 2023 17:02:16 +0100 Subject: [PATCH] feat: query margin order(s) --- Cargo.toml | 9 +-------- src/action/query/get_margin_order.rs | 13 ++++++++++--- src/action/query/get_margin_orders.rs | 5 +++-- src/entry_point/query.rs | 18 +++++++++--------- src/msg/query_msg.rs | 4 ++-- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bb534cf..c26d8d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,17 +14,10 @@ thiserror = "1" schemars = "0.8.1" cosmwasm-schema = "1.1.4" cw-utils = "0.13" -elys-bindings = { version = "0.1.0", git = "https://github.com/elys-network/bindings", branch = "margin_query" } +elys-bindings = { version = "0.1.0", git = "https://github.com/elys-network/bindings", branch = "main" } [dev-dependencies] -<<<<<<< HEAD -elys-bindings = { version = "0.1.0", git = "https://github.com/elys-network/bindings", features = [ - "testing", -], branch = "main" } -======= - ->>>>>>> a8dcd69 (feat: bindings repository integration) cw-multi-test = "0.13.4" serde_json = "1.0.107" elys-bindings = { version = "0.1.0", git = "https://github.com/elys-network/bindings", branch = "main", features = [ diff --git a/src/action/query/get_margin_order.rs b/src/action/query/get_margin_order.rs index 507bfec..960840b 100644 --- a/src/action/query/get_margin_order.rs +++ b/src/action/query/get_margin_order.rs @@ -1,12 +1,19 @@ +use cosmwasm_std::StdError; + use super::*; pub fn get_margin_order( deps: Deps, address: String, id: u64, -) -> Result { +) -> Result { let querier = ElysQuerier::new(&deps.querier); - let resp: MTPResponse = querier.mtp(address, id)?; - Ok(resp) + let resp: MarginMtpResponse = querier.mtp(address, id)?; + + if let Some(mtp) = resp.mtp { + Ok(mtp) + } else { + Err(StdError::not_found("margin trading prosition").into()) + } } diff --git a/src/action/query/get_margin_orders.rs b/src/action/query/get_margin_orders.rs index 812a3f5..9764298 100644 --- a/src/action/query/get_margin_orders.rs +++ b/src/action/query/get_margin_orders.rs @@ -3,9 +3,10 @@ use super::*; pub fn get_margin_orders( deps: Deps, pagination: PageRequest, -) -> Result { +) -> Result { let querier = ElysQuerier::new(&deps.querier); - let resp: PositionsResponse = querier.positions(pagination)?; + let resp: MarginQueryPositionsResponse = querier.positions(pagination)?; + Ok(resp) } diff --git a/src/entry_point/query.rs b/src/entry_point/query.rs index 041e97e..403845f 100644 --- a/src/entry_point/query.rs +++ b/src/entry_point/query.rs @@ -7,14 +7,14 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result Ok(to_binary(&query::get_spot_order(deps, order_id)?)?), - GetAllPrices {} => Ok(to_binary(&query::get_all_prices(deps)?)?), - AssetInfo { denom } => Ok(to_binary(&query::asset_info(deps, denom)?)?), - GetMarginOrder { address, id } => { - Ok(to_binary(&query::get_margin_order(deps, address, id)?)?) - } - GetMarginOrders { pagination } => { - Ok(to_binary(&query::get_margin_orders(deps, pagination)?)?) - } + GetSpotOrder { order_id } => Ok(to_json_binary(&query::get_spot_order(deps, order_id)?)?), + GetAllPrices {} => Ok(to_json_binary(&query::get_all_prices(deps)?)?), + AssetInfo { denom } => Ok(to_json_binary(&query::asset_info(deps, denom)?)?), + GetMarginOrder { address, id } => Ok(to_json_binary(&query::get_margin_order( + deps, address, id, + )?)?), + GetMarginOrders { pagination } => Ok(to_json_binary(&query::get_margin_orders( + deps, pagination, + )?)?), } } diff --git a/src/msg/query_msg.rs b/src/msg/query_msg.rs index 9ad9c00..af78223 100644 --- a/src/msg/query_msg.rs +++ b/src/msg/query_msg.rs @@ -14,8 +14,8 @@ pub enum QueryMsg { GetAllPrices {}, #[returns(OracleAssetInfoResponse)] AssetInfo { denom: String }, - #[returns(MTPResponse)] + #[returns(MarginMtpResponse)] GetMarginOrder { address: String, id: u64 }, - #[returns(PositionsResponse)] + #[returns(MarginQueryPositionsResponse)] GetMarginOrders { pagination: PageRequest }, }