Skip to content

Commit

Permalink
query subaccounts
Browse files Browse the repository at this point in the history
  • Loading branch information
dydxwill committed Jan 19, 2024
1 parent 9aa2ef9 commit 9627096
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
13 changes: 12 additions & 1 deletion protocol/contracts/dydx-messages-example/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cosmwasm_std::{
to_binary,
};
use cw2::set_contract_version;
use dydx_cosmwasm::{DydxQuerier, DydxQueryWrapper, MarketPrice, Order, OrderId, DydxMsg, SubaccountId, OrderSide};
use dydx_cosmwasm::{DydxQuerier, DydxQueryWrapper, MarketPrice, Subaccount, Order, OrderId, DydxMsg, SubaccountId, OrderSide, SubaccountResponse};

use crate::error::ContractError;
use crate::msg::{ArbiterResponse, ExecuteMsg, InstantiateMsg, QueryMsg};
Expand Down Expand Up @@ -200,6 +200,7 @@ fn place_order(deps: DepsMut, order: Order) -> Result<Response<DydxMsg>, Contrac
pub fn query(deps: Deps<DydxQueryWrapper>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::MarketPrice { id } => to_binary(&query_price(deps, id)?),
QueryMsg::Subaccount { address, subaccountNumber } => to_binary(&query_subaccount(deps, address, subaccountNumber)?),
QueryMsg::Arbiter {} => to_binary(&query_arbiter(deps)?),
}
}
Expand All @@ -213,6 +214,16 @@ fn query_price(
Ok(res?)
}

fn query_subaccount(
deps: Deps<DydxQueryWrapper>,
address: String,
subaccountNumber: u32,
) -> StdResult<SubaccountResponse> {
let querier = DydxQuerier::new(&deps.querier);
let res = querier.query_subaccount(address, subaccountNumber);
Ok(res?)
}

fn query_arbiter(deps: Deps<DydxQueryWrapper>) -> StdResult<ArbiterResponse> {
let config = CONFIG.load(deps.storage)?;
let addr = config.arbiter;
Expand Down
7 changes: 6 additions & 1 deletion protocol/contracts/dydx-messages-example/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Addr, Coin};
use cw_utils::Expiration;
use dydx_cosmwasm::{OrderConditionType, OrderSide, OrderTimeInForce, SubaccountId, MarketPrice};
use dydx_cosmwasm::{OrderConditionType, OrderSide, OrderTimeInForce, SubaccountId, MarketPrice, Subaccount};

#[cw_serde]
pub struct InstantiateMsg {
Expand Down Expand Up @@ -51,6 +51,11 @@ pub enum QueryMsg {
#[returns(MarketPrice)]
MarketPrice {
id: u32,
},
#[returns(SubaccountResponse)]
Subaccount {
address: String,
subaccountNumber: u32,
}
}

Expand Down
3 changes: 2 additions & 1 deletion protocol/dydx-cosmwasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ mod response_helper;
pub use msg::{DydxMsg, SubaccountId, Transfer, Order, OrderSide, OrderTimeInForce, OrderConditionType, OrderId};
pub use querier::DydxQuerier;
pub use query::{
DydxQuery, DydxQueryWrapper,
DydxQuery, DydxQueryWrapper, SubaccountResponse,
};
// TODO: Export MarketPriceResponse instead for style consistency.
pub use proto_structs::MarketPrice;
pub use proto_structs::Subaccount;
pub use route::DydxRoute;

// This export is added to all contracts that import this package, signifying that they require
Expand Down

0 comments on commit 9627096

Please sign in to comment.