Skip to content

Commit

Permalink
added cancellation strategy enum
Browse files Browse the repository at this point in the history
  • Loading branch information
stackman27 committed Sep 19, 2023
1 parent 5f7faed commit 07ce85c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 20 deletions.
10 changes: 10 additions & 0 deletions packages/injective-cosmwasm/src/exchange/cancel.rs
Original file line number Diff line number Diff line change
@@ -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,
}
1 change: 1 addition & 0 deletions packages/injective-cosmwasm/src/exchange/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod cancel;
pub mod derivative;
pub mod derivative_market;
pub mod market;
Expand Down
3 changes: 0 additions & 3 deletions packages/injective-cosmwasm/src/exchange/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
18 changes: 9 additions & 9 deletions packages/injective-cosmwasm/src/exchange_mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -347,7 +347,7 @@ pub trait HandlesTraderSpotOrdersToCancelUpToAmountQuery {
subaccount_id: SubaccountId,
base_amount: FPDecimal,
quote_amount: FPDecimal,
strategy: i32,
strategy: CancellationStrategy,
reference_price: Option<FPDecimal>,
) -> QuerierResult;
}
Expand All @@ -358,7 +358,7 @@ pub trait HandlesTraderDerivativeOrdersToCancelUpToAmountQuery {
market_id: MarketId,
subaccount_id: SubaccountId,
quote_amount: FPDecimal,
strategy: i32,
strategy: CancellationStrategy,
reference_price: Option<FPDecimal>,
) -> QuerierResult;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -898,7 +898,7 @@ pub mod handlers {
Some(Box::new(Temp { markets }))
}

pub type SpotUpToAmountConsumingFunction = fn(MarketId, SubaccountId, FPDecimal, FPDecimal, i32, Option<FPDecimal>);
pub type SpotUpToAmountConsumingFunction = fn(MarketId, SubaccountId, FPDecimal, FPDecimal, CancellationStrategy, Option<FPDecimal>);

pub fn create_spot_orders_up_to_amount_handler(
orders: Option<Vec<TrimmedSpotLimitOrder>>,
Expand All @@ -915,7 +915,7 @@ pub mod handlers {
subaccount_id: SubaccountId,
base_amount: FPDecimal,
quote_amount: FPDecimal,
strategy: i32,
strategy: CancellationStrategy,
reference_price: Option<FPDecimal>,
) -> QuerierResult {
if self.assertion.is_some() {
Expand All @@ -930,7 +930,7 @@ pub mod handlers {
Some(Box::new(Temp { orders, assertion }))
}

pub type DerivativeUpToAmountConsumingFunction = fn(MarketId, SubaccountId, FPDecimal, i32, Option<FPDecimal>);
pub type DerivativeUpToAmountConsumingFunction = fn(MarketId, SubaccountId, FPDecimal, CancellationStrategy, Option<FPDecimal>);

pub fn create_derivative_orders_up_to_amount_handler(
orders: Option<Vec<TrimmedDerivativeLimitOrder>>,
Expand All @@ -946,7 +946,7 @@ pub mod handlers {
market_id: MarketId,
subaccount_id: SubaccountId,
quote_amount: FPDecimal,
strategy: i32,
strategy: CancellationStrategy,
reference_price: Option<FPDecimal>,
) -> QuerierResult {
if self.assertion.is_some() {
Expand Down
6 changes: 2 additions & 4 deletions packages/injective-cosmwasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub use exchange::{
cancel::CancellationStrategy,
derivative::{
DerivativeLimitOrder, DerivativeMarketOrder, DerivativeOrder, DerivativePosition, EffectivePosition, Position, TrimmedDerivativeLimitOrder,
},
Expand All @@ -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},
Expand Down
5 changes: 3 additions & 2 deletions packages/injective-cosmwasm/src/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<FPDecimal>,
) -> StdResult<TraderSpotOrdersResponse> {
let request = InjectiveQueryWrapper {
Expand All @@ -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<FPDecimal>,
) -> StdResult<TraderDerivativeOrdersResponse> {
let request = InjectiveQueryWrapper {
Expand Down
5 changes: 3 additions & 2 deletions packages/injective-cosmwasm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
use injective_math::FPDecimal;

use crate::exchange::{
cancel::CancellationStrategy,
order::OrderSide,
types::{MarketId, SubaccountId},
};
Expand Down Expand Up @@ -58,14 +59,14 @@ pub enum InjectiveQuery {
subaccount_id: SubaccountId,
base_amount: FPDecimal,
quote_amount: FPDecimal,
strategy: i32,
strategy: CancellationStrategy,
reference_price: Option<FPDecimal>,
},
TraderDerivativeOrdersToCancelUpToAmount {
market_id: MarketId,
subaccount_id: SubaccountId,
quote_amount: FPDecimal,
strategy: i32,
strategy: CancellationStrategy,
reference_price: Option<FPDecimal>,
},
DerivativeMarket {
Expand Down

0 comments on commit 07ce85c

Please sign in to comment.