diff --git a/Cargo.lock b/Cargo.lock index ac9d498c..2a55a051 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -863,7 +863,7 @@ dependencies = [ [[package]] name = "injective-cosmwasm" -version = "0.2.15" +version = "0.2.16" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -945,7 +945,7 @@ dependencies = [ "base64 0.13.1", "cosmwasm-std", "cw-multi-test", - "injective-cosmwasm 0.2.15", + "injective-cosmwasm 0.2.16", "injective-math 0.2.2", "rand 0.4.6", "secp256k1", diff --git a/packages/injective-cosmwasm/Cargo.toml b/packages/injective-cosmwasm/Cargo.toml index a88cf4ce..7b3a947b 100644 --- a/packages/injective-cosmwasm/Cargo.toml +++ b/packages/injective-cosmwasm/Cargo.toml @@ -11,7 +11,7 @@ license = "Apache-2.0" name = "injective-cosmwasm" readme = "README.md" repository = "https://github.com/InjectiveLabs/cw-injective/tree/master/packages/bindings" -version = "0.2.15" +version = "0.2.16" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/packages/injective-cosmwasm/src/exchange_mock_querier.rs b/packages/injective-cosmwasm/src/exchange_mock_querier.rs index 7395488a..1020ab24 100644 --- a/packages/injective-cosmwasm/src/exchange_mock_querier.rs +++ b/packages/injective-cosmwasm/src/exchange_mock_querier.rs @@ -325,6 +325,17 @@ fn default_spot_market_orderbook_response_handler() -> QuerierResult { SystemResult::Ok(ContractResult::from(to_binary(&response))) } +fn default_derivative_market_orderbook_response_handler() -> QuerierResult { + let response = QueryOrderbookResponse { + buys_price_level: vec![PriceLevel::new(9u128.into(), 10u128.into()), PriceLevel::new(8u128.into(), 10u128.into())], + sells_price_level: vec![ + PriceLevel::new(11u128.into(), 10u128.into()), + PriceLevel::new(12u128.into(), 10u128.into()), + ], + }; + SystemResult::Ok(ContractResult::from(to_binary(&response))) +} + fn default_market_atomic_execution_fee_multiplier_response_handler() -> QuerierResult { let response = QueryMarketAtomicExecutionFeeMultiplierResponse { multiplier: FPDecimal::from_str("2.0").unwrap(), @@ -444,6 +455,10 @@ pub trait HandlesPriceLevelsQuery { fn handle(&self, market_id: MarketId, order_side: OrderSide) -> QuerierResult; } +pub trait HandlesDerivativePriceLevelsQuery { + fn handle(&self, market_id: MarketId) -> QuerierResult; +} + pub trait HandlesExchangeParamsQuery { fn handle(&self) -> QuerierResult; } @@ -482,6 +497,7 @@ pub struct WasmMockQuerier { pub all_balances_query_handler: Option>, pub registered_contract_info_query_handler: Option>, pub spot_market_orderbook_response_handler: Option>, + pub derivative_market_orderbook_response_handler: Option>, pub market_atomic_execution_fee_multiplier_response_handler: Option>, } @@ -677,6 +693,10 @@ impl WasmMockQuerier { Some(handler) => handler.handle(market_id, order_side), None => default_spot_market_orderbook_response_handler(), }, + InjectiveQuery::DerivativeOrderbook { market_id, .. } => match &self.derivative_market_orderbook_response_handler { + Some(handler) => handler.handle(market_id), + None => default_derivative_market_orderbook_response_handler(), + }, InjectiveQuery::MarketAtomicExecutionFeeMultiplier { market_id } => { match &self.market_atomic_execution_fee_multiplier_response_handler { Some(handler) => handler.handle(market_id), @@ -731,6 +751,7 @@ impl WasmMockQuerier { registered_contract_info_query_handler: None, denom_decimals_handler: None, spot_market_orderbook_response_handler: None, + derivative_market_orderbook_response_handler: None, market_atomic_execution_fee_multiplier_response_handler: None, } } diff --git a/packages/injective-cosmwasm/src/querier.rs b/packages/injective-cosmwasm/src/querier.rs index 6f7951b0..f0f0bd3d 100644 --- a/packages/injective-cosmwasm/src/querier.rs +++ b/packages/injective-cosmwasm/src/querier.rs @@ -419,6 +419,23 @@ impl<'a> InjectiveQuerier<'a> { Ok(res) } + pub fn query_derivative_market_orderbook + Clone>( + &self, + market_id: &'a T, + limit_cumulative_notional: FPDecimal, + ) -> StdResult { + let request = InjectiveQueryWrapper { + route: InjectiveRoute::Exchange, + query_data: InjectiveQuery::DerivativeOrderbook { + market_id: market_id.clone().into(), + limit: 0, + limit_cumulative_notional: Some(limit_cumulative_notional), + }, + }; + let res: QueryOrderbookResponse = self.querier.query(&request.into())?; + Ok(res) + } + pub fn query_market_atomic_execution_fee_multiplier + Clone>( &self, market_id: &'a T, diff --git a/packages/injective-cosmwasm/src/query.rs b/packages/injective-cosmwasm/src/query.rs index 7671f327..5b8378c3 100644 --- a/packages/injective-cosmwasm/src/query.rs +++ b/packages/injective-cosmwasm/src/query.rs @@ -115,6 +115,11 @@ pub enum InjectiveQuery { limit_cumulative_quantity: Option, limit_cumulative_notional: Option, }, + DerivativeOrderbook { + market_id: MarketId, + limit: u64, + limit_cumulative_notional: Option, + }, DerivativeMarketMidPriceAndTob { market_id: MarketId, },