diff --git a/contracts/sei-tester/src/contract.rs b/contracts/sei-tester/src/contract.rs index 9e3c863..567b31a 100644 --- a/contracts/sei-tester/src/contract.rs +++ b/contracts/sei-tester/src/contract.rs @@ -9,8 +9,8 @@ use crate::msg::{ }; use sei_cosmwasm::{ DexTwapsResponse, EpochResponse, ExchangeRatesResponse, GetOrderByIdResponse, - GetOrdersResponse, OracleTwapsResponse, Order, OrderType, PositionDirection, SeiMsg, - SeiQuerier, SeiQueryWrapper, + GetOrdersResponse, OracleTwapsResponse, Order, OrderSimulationResponse, OrderType, + PositionDirection, SeiMsg, SeiQuerier, SeiQueryWrapper, }; #[entry_point] @@ -212,6 +212,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult contract_address, lookback_seconds, } => to_binary(&query_dex_twaps(deps, contract_address, lookback_seconds)?), + QueryMsg::OrderSimulation { order } => to_binary(&query_order_simulation(deps, order)?), QueryMsg::Epoch {} => to_binary(&query_epoch(deps)?), QueryMsg::GetOrders { contract_address, @@ -261,6 +262,16 @@ pub fn query_dex_twaps( Ok(res) } +pub fn query_order_simulation( + deps: Deps, + order: Order, +) -> StdResult { + let querier = SeiQuerier::new(&deps.querier); + let res: OrderSimulationResponse = querier.query_order_simulation(order)?; + + Ok(res) +} + pub fn query_epoch(deps: Deps) -> StdResult { let querier = SeiQuerier::new(&deps.querier); let res: EpochResponse = querier.query_epoch()?; diff --git a/contracts/sei-tester/src/msg.rs b/contracts/sei-tester/src/msg.rs index c86dfb7..bb107ce 100644 --- a/contracts/sei-tester/src/msg.rs +++ b/contracts/sei-tester/src/msg.rs @@ -97,6 +97,9 @@ pub enum QueryMsg { contract_address: String, lookback_seconds: u64, }, + OrderSimulation { + order: Order, + }, Epoch {}, GetOrders { contract_address: String, diff --git a/packages/sei-cosmwasm/src/lib.rs b/packages/sei-cosmwasm/src/lib.rs index ee15498..a1e265a 100644 --- a/packages/sei-cosmwasm/src/lib.rs +++ b/packages/sei-cosmwasm/src/lib.rs @@ -12,7 +12,7 @@ pub use proto_structs::{ pub use querier::SeiQuerier; pub use query::{ DexTwapsResponse, EpochResponse, ExchangeRatesResponse, GetOrderByIdResponse, - GetOrdersResponse, OracleTwapsResponse, SeiQuery, SeiQueryWrapper, + GetOrdersResponse, OracleTwapsResponse, OrderSimulationResponse, SeiQuery, SeiQueryWrapper, }; pub use route::SeiRoute; pub use sei_types::{Order, OrderResponse, OrderType, PositionDirection}; diff --git a/packages/sei-cosmwasm/src/querier.rs b/packages/sei-cosmwasm/src/querier.rs index f685e49..a7d8661 100644 --- a/packages/sei-cosmwasm/src/querier.rs +++ b/packages/sei-cosmwasm/src/querier.rs @@ -2,9 +2,10 @@ use cosmwasm_std::{Addr, QuerierWrapper, StdResult}; use crate::query::{ DexTwapsResponse, EpochResponse, ExchangeRatesResponse, GetOrderByIdResponse, - GetOrdersResponse, OracleTwapsResponse, SeiQuery, SeiQueryWrapper, + GetOrdersResponse, OracleTwapsResponse, OrderSimulationResponse, SeiQuery, SeiQueryWrapper, }; use crate::route::SeiRoute; +use crate::Order; /// This is a helper wrapper to easily use our custom queries pub struct SeiQuerier<'a> { @@ -16,6 +17,9 @@ impl<'a> SeiQuerier<'a> { SeiQuerier { querier } } + /* + query oracle module + */ pub fn query_exchange_rates(&self) -> StdResult { let request = SeiQueryWrapper { route: SeiRoute::Oracle, @@ -36,6 +40,9 @@ impl<'a> SeiQuerier<'a> { self.querier.query(&request) } + /* + query dex module + */ pub fn query_dex_twaps( &self, lookback_seconds: u64, @@ -53,12 +60,13 @@ impl<'a> SeiQuerier<'a> { self.querier.query(&request) } - pub fn query_epoch(&self) -> StdResult { + pub fn query_order_simulation(&self, order: Order) -> StdResult { let request = SeiQueryWrapper { - route: SeiRoute::Epoch, - query_data: SeiQuery::Epoch {}, + route: SeiRoute::Dex, + query_data: SeiQuery::OrderSimulation { order }, } .into(); + self.querier.query(&request) } @@ -97,4 +105,16 @@ impl<'a> SeiQuerier<'a> { .into(); self.querier.query(&request) } + + /* + query epoch module + */ + pub fn query_epoch(&self) -> StdResult { + let request = SeiQueryWrapper { + route: SeiRoute::Epoch, + query_data: SeiQuery::Epoch {}, + } + .into(); + self.querier.query(&request) + } } diff --git a/packages/sei-cosmwasm/src/query.rs b/packages/sei-cosmwasm/src/query.rs index 29cb4f5..3db14bc 100644 --- a/packages/sei-cosmwasm/src/query.rs +++ b/packages/sei-cosmwasm/src/query.rs @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::proto_structs::{DenomOracleExchangeRatePair, DexTwap, Epoch, OracleTwap}; use crate::route::SeiRoute; use crate::sei_types::OrderResponse; +use crate::Order; /// SeiQueryWrapper is an override of QueryRequest::Custom to access Sei-specific modules #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] @@ -40,6 +41,9 @@ pub enum SeiQuery { asset_denom: String, id: u64, }, + OrderSimulation { + order: Order, + }, } /// ExchangeRatesResponse is data format returned from OracleRequest::ExchangeRates query @@ -77,3 +81,9 @@ pub struct GetOrdersResponse { pub struct GetOrderByIdResponse { pub order: OrderResponse, } + +/// OrderSimulationResponse is data format returned from OrderSimulation query +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct OrderSimulationResponse { + pub executed_quantity: String, +}