From 07ce85c1baaac3f3038f2582d7a3abbce5b9a013 Mon Sep 17 00:00:00 2001 From: stackman27 Date: Tue, 19 Sep 2023 12:34:03 -0700 Subject: [PATCH] added cancellation strategy enum --- .../injective-cosmwasm/src/exchange/cancel.rs | 10 ++++++++++ .../injective-cosmwasm/src/exchange/mod.rs | 1 + .../injective-cosmwasm/src/exchange/types.rs | 3 --- .../src/exchange_mock_querier.rs | 18 +++++++++--------- packages/injective-cosmwasm/src/lib.rs | 6 ++---- packages/injective-cosmwasm/src/querier.rs | 5 +++-- packages/injective-cosmwasm/src/query.rs | 5 +++-- 7 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 packages/injective-cosmwasm/src/exchange/cancel.rs diff --git a/packages/injective-cosmwasm/src/exchange/cancel.rs b/packages/injective-cosmwasm/src/exchange/cancel.rs new file mode 100644 index 00000000..a58fc0e9 --- /dev/null +++ b/packages/injective-cosmwasm/src/exchange/cancel.rs @@ -0,0 +1,10 @@ +use schemars::JsonSchema; +use serde_repr::{Deserialize_repr, Serialize_repr}; + +#[derive(Serialize_repr, Deserialize_repr, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[repr(u8)] +pub enum CancellationStrategy { + UnspecifiedOrder = 0, + FromWorstToBest = 1, + FromBestToWorst = 2, +} diff --git a/packages/injective-cosmwasm/src/exchange/mod.rs b/packages/injective-cosmwasm/src/exchange/mod.rs index 1a489671..5b59957c 100644 --- a/packages/injective-cosmwasm/src/exchange/mod.rs +++ b/packages/injective-cosmwasm/src/exchange/mod.rs @@ -1,3 +1,4 @@ +pub mod cancel; pub mod derivative; pub mod derivative_market; pub mod market; diff --git a/packages/injective-cosmwasm/src/exchange/types.rs b/packages/injective-cosmwasm/src/exchange/types.rs index ff6245b2..b8f89aa3 100644 --- a/packages/injective-cosmwasm/src/exchange/types.rs +++ b/packages/injective-cosmwasm/src/exchange/types.rs @@ -9,9 +9,6 @@ use std::fmt; use crate::InjectiveQuerier; -pub const UNSORTED_CANCELLATION_STRATEGY: i32 = 0; -pub const FROM_WORST_TO_BEST_CANCELLATION_STRATEGY: i32 = 1; - /// Params is the response type for the exchange params #[allow(non_snake_case)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] diff --git a/packages/injective-cosmwasm/src/exchange_mock_querier.rs b/packages/injective-cosmwasm/src/exchange_mock_querier.rs index 7c64a063..d2b0da98 100644 --- a/packages/injective-cosmwasm/src/exchange_mock_querier.rs +++ b/packages/injective-cosmwasm/src/exchange_mock_querier.rs @@ -21,7 +21,7 @@ use crate::oracle::{ use crate::tokenfactory::response::{TokenFactoryCreateDenomFeeResponse, TokenFactoryDenomSupplyResponse}; use crate::wasmx::response::QueryContractRegistrationInfoResponse; use crate::{ - Deposit, DerivativeMarketResponse, ExchangeParamsResponse, FullDerivativeMarket, InjectiveQuery, InjectiveQueryWrapper, + CancellationStrategy, Deposit, DerivativeMarketResponse, ExchangeParamsResponse, FullDerivativeMarket, InjectiveQuery, InjectiveQueryWrapper, MarketMidPriceAndTOBResponse, MarketStatus, MarketVolatilityResponse, OracleInfo, OracleVolatilityResponse, OrderSide, PerpetualMarketFundingResponse, PerpetualMarketInfoResponse, PythPriceResponse, QueryAggregateMarketVolumeResponse, QueryAggregateVolumeResponse, QueryDenomDecimalResponse, QueryDenomDecimalsResponse, QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarket, SpotMarketResponse, @@ -347,7 +347,7 @@ pub trait HandlesTraderSpotOrdersToCancelUpToAmountQuery { subaccount_id: SubaccountId, base_amount: FPDecimal, quote_amount: FPDecimal, - strategy: i32, + strategy: CancellationStrategy, reference_price: Option, ) -> QuerierResult; } @@ -358,7 +358,7 @@ pub trait HandlesTraderDerivativeOrdersToCancelUpToAmountQuery { market_id: MarketId, subaccount_id: SubaccountId, quote_amount: FPDecimal, - strategy: i32, + strategy: CancellationStrategy, reference_price: Option, ) -> QuerierResult; } @@ -772,8 +772,8 @@ pub mod handlers { use crate::tokenfactory::response::{TokenFactoryCreateDenomFeeResponse, TokenFactoryDenomSupplyResponse}; use crate::wasmx::{response::QueryContractRegistrationInfoResponse, types::RegisteredContract}; use crate::{ - exchange_mock_querier::TestCoin, Deposit, DerivativeMarket, DerivativeMarketResponse, EffectivePosition, FullDerivativeMarket, - FullDerivativeMarketPerpetualInfo, HandlesMarketAndSubaccountQuery, HandlesMarketIdQuery, HandlesOracleVolatilityQuery, + exchange_mock_querier::TestCoin, CancellationStrategy, Deposit, DerivativeMarket, DerivativeMarketResponse, EffectivePosition, + FullDerivativeMarket, FullDerivativeMarketPerpetualInfo, HandlesMarketAndSubaccountQuery, HandlesMarketIdQuery, HandlesOracleVolatilityQuery, HandlesPriceLevelsQuery, HandlesSmartQuery, HandlesSubaccountAndDenomQuery, HandlesTraderSpotOrdersToCancelUpToAmountQuery, MarketId, MetadataStatistics, OracleVolatilityResponse, OrderSide, Position, PriceLevel, QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarket, SpotMarketResponse, SubaccountDepositResponse, SubaccountEffectivePositionInMarketResponse, SubaccountId, SubaccountPositionInMarketResponse, @@ -898,7 +898,7 @@ pub mod handlers { Some(Box::new(Temp { markets })) } - pub type SpotUpToAmountConsumingFunction = fn(MarketId, SubaccountId, FPDecimal, FPDecimal, i32, Option); + pub type SpotUpToAmountConsumingFunction = fn(MarketId, SubaccountId, FPDecimal, FPDecimal, CancellationStrategy, Option); pub fn create_spot_orders_up_to_amount_handler( orders: Option>, @@ -915,7 +915,7 @@ pub mod handlers { subaccount_id: SubaccountId, base_amount: FPDecimal, quote_amount: FPDecimal, - strategy: i32, + strategy: CancellationStrategy, reference_price: Option, ) -> QuerierResult { if self.assertion.is_some() { @@ -930,7 +930,7 @@ pub mod handlers { Some(Box::new(Temp { orders, assertion })) } - pub type DerivativeUpToAmountConsumingFunction = fn(MarketId, SubaccountId, FPDecimal, i32, Option); + pub type DerivativeUpToAmountConsumingFunction = fn(MarketId, SubaccountId, FPDecimal, CancellationStrategy, Option); pub fn create_derivative_orders_up_to_amount_handler( orders: Option>, @@ -946,7 +946,7 @@ pub mod handlers { market_id: MarketId, subaccount_id: SubaccountId, quote_amount: FPDecimal, - strategy: i32, + strategy: CancellationStrategy, reference_price: Option, ) -> QuerierResult { if self.assertion.is_some() { diff --git a/packages/injective-cosmwasm/src/lib.rs b/packages/injective-cosmwasm/src/lib.rs index e5265d04..e7554597 100644 --- a/packages/injective-cosmwasm/src/lib.rs +++ b/packages/injective-cosmwasm/src/lib.rs @@ -1,4 +1,5 @@ pub use exchange::{ + cancel::CancellationStrategy, derivative::{ DerivativeLimitOrder, DerivativeMarketOrder, DerivativeOrder, DerivativePosition, EffectivePosition, Position, TrimmedDerivativeLimitOrder, }, @@ -20,10 +21,7 @@ pub use exchange::{ addr_to_bech32, bech32_to_hex, checked_address_to_subaccount_id, get_default_subaccount_id_for_checked_address, is_default_subaccount, subaccount_id_to_ethereum_address, subaccount_id_to_injective_address, subaccount_id_to_unchecked_injective_address, }, - types::{ - DenomDecimals, Deposit, Hash, MarketId, MarketType, Params, PriceLevel, ShortSubaccountId, SubaccountId, - FROM_WORST_TO_BEST_CANCELLATION_STRATEGY, UNSORTED_CANCELLATION_STRATEGY, - }, + types::{DenomDecimals, Deposit, Hash, MarketId, MarketType, Params, PriceLevel, ShortSubaccountId, SubaccountId}, }; pub use oracle::{ response::{OraclePriceResponse, PythPriceResponse}, diff --git a/packages/injective-cosmwasm/src/querier.rs b/packages/injective-cosmwasm/src/querier.rs index 567cae3c..6f7951b0 100644 --- a/packages/injective-cosmwasm/src/querier.rs +++ b/packages/injective-cosmwasm/src/querier.rs @@ -5,6 +5,7 @@ use injective_math::FPDecimal; use crate::authz::response::{GranteeGrantsResponse, GranterGrantsResponse, GrantsResponse}; use crate::exchange::response::StakedAmountResponse; use crate::exchange::{ + cancel::CancellationStrategy, order::OrderSide, response::{ DerivativeMarketResponse, ExchangeParamsResponse, MarketMidPriceAndTOBResponse, MarketVolatilityResponse, OracleVolatilityResponse, @@ -236,7 +237,7 @@ impl<'a> InjectiveQuerier<'a> { subaccount_id: &'a P, base_amount: FPDecimal, quote_amount: FPDecimal, - strategy: i32, + strategy: CancellationStrategy, reference_price: Option, ) -> StdResult { let request = InjectiveQueryWrapper { @@ -260,7 +261,7 @@ impl<'a> InjectiveQuerier<'a> { market_id: &'a T, subaccount_id: &'a P, quote_amount: FPDecimal, - strategy: i32, + strategy: CancellationStrategy, reference_price: Option, ) -> StdResult { let request = InjectiveQueryWrapper { diff --git a/packages/injective-cosmwasm/src/query.rs b/packages/injective-cosmwasm/src/query.rs index ad2db33c..7671f327 100644 --- a/packages/injective-cosmwasm/src/query.rs +++ b/packages/injective-cosmwasm/src/query.rs @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize}; use injective_math::FPDecimal; use crate::exchange::{ + cancel::CancellationStrategy, order::OrderSide, types::{MarketId, SubaccountId}, }; @@ -58,14 +59,14 @@ pub enum InjectiveQuery { subaccount_id: SubaccountId, base_amount: FPDecimal, quote_amount: FPDecimal, - strategy: i32, + strategy: CancellationStrategy, reference_price: Option, }, TraderDerivativeOrdersToCancelUpToAmount { market_id: MarketId, subaccount_id: SubaccountId, quote_amount: FPDecimal, - strategy: i32, + strategy: CancellationStrategy, reference_price: Option, }, DerivativeMarket {