diff --git a/packages/injective-cosmwasm/src/exchange_mock_querier.rs b/packages/injective-cosmwasm/src/exchange_mock_querier.rs index 974dc096..e5cc4475 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_json_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, }, diff --git a/packages/injective-math/src/fp_decimal/mod.rs b/packages/injective-math/src/fp_decimal/mod.rs index 1e0b7b51..40c2bbcf 100644 --- a/packages/injective-math/src/fp_decimal/mod.rs +++ b/packages/injective-math/src/fp_decimal/mod.rs @@ -384,7 +384,7 @@ impl FPDecimal { mod arithmetic; mod comparison; mod display; -mod error; +pub mod error; mod exp; mod factorial; mod from_str;