Skip to content

Commit

Permalink
Merge branch 'dev' into chore/workspace_dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
DrunkenRandomWalker authored Nov 7, 2023
2 parents 1a66b15 + 2b45055 commit a817114
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
21 changes: 21 additions & 0 deletions packages/injective-cosmwasm/src/exchange_mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Check failure on line 336 in packages/injective-cosmwasm/src/exchange_mock_querier.rs

View workflow job for this annotation

GitHub Actions / Lints

cannot find function `to_binary` in this scope

Check failure on line 336 in packages/injective-cosmwasm/src/exchange_mock_querier.rs

View workflow job for this annotation

GitHub Actions / Test Suite

cannot find function `to_binary` in this scope

Check failure on line 336 in packages/injective-cosmwasm/src/exchange_mock_querier.rs

View workflow job for this annotation

GitHub Actions / Lints

cannot find function `to_binary` in this scope

Check failure on line 336 in packages/injective-cosmwasm/src/exchange_mock_querier.rs

View workflow job for this annotation

GitHub Actions / Test Suite

cannot find function `to_binary` in this scope
}

fn default_market_atomic_execution_fee_multiplier_response_handler() -> QuerierResult {
let response = QueryMarketAtomicExecutionFeeMultiplierResponse {
multiplier: FPDecimal::from_str("2.0").unwrap(),
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -482,6 +497,7 @@ pub struct WasmMockQuerier {
pub all_balances_query_handler: Option<Box<dyn HandlesBankAllBalancesQuery>>,
pub registered_contract_info_query_handler: Option<Box<dyn HandlesByAddressQuery>>,
pub spot_market_orderbook_response_handler: Option<Box<dyn HandlesPriceLevelsQuery>>,
pub derivative_market_orderbook_response_handler: Option<Box<dyn HandlesDerivativePriceLevelsQuery>>,
pub market_atomic_execution_fee_multiplier_response_handler: Option<Box<dyn HandlesMarketIdQuery>>,
}

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
}
}
Expand Down
17 changes: 17 additions & 0 deletions packages/injective-cosmwasm/src/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,23 @@ impl<'a> InjectiveQuerier<'a> {
Ok(res)
}

pub fn query_derivative_market_orderbook<T: Into<MarketId> + Clone>(
&self,
market_id: &'a T,
limit_cumulative_notional: FPDecimal,
) -> StdResult<QueryOrderbookResponse> {
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<T: Into<MarketId> + Clone>(
&self,
market_id: &'a T,
Expand Down
5 changes: 5 additions & 0 deletions packages/injective-cosmwasm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ pub enum InjectiveQuery {
limit_cumulative_quantity: Option<FPDecimal>,
limit_cumulative_notional: Option<FPDecimal>,
},
DerivativeOrderbook {
market_id: MarketId,
limit: u64,
limit_cumulative_notional: Option<FPDecimal>,
},
DerivativeMarketMidPriceAndTob {
market_id: MarketId,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/injective-math/src/fp_decimal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl FPDecimal {
mod arithmetic;
mod comparison;
mod display;
mod error;
pub mod error;
mod exp;
mod factorial;
mod from_str;
Expand Down

0 comments on commit a817114

Please sign in to comment.