diff --git a/Cargo.lock b/Cargo.lock index 98ecb43e..2ae515ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -756,7 +756,7 @@ dependencies = [ [[package]] name = "injective-cosmwasm" -version = "0.2.12" +version = "0.2.13" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -839,7 +839,7 @@ dependencies = [ "base64", "cosmwasm-std", "cw-multi-test", - "injective-cosmwasm 0.2.12", + "injective-cosmwasm 0.2.13", "injective-math 0.1.21", "rand 0.4.6", "secp256k1", diff --git a/packages/injective-cosmwasm/Cargo.toml b/packages/injective-cosmwasm/Cargo.toml index 576cf2f4..7d11fd78 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.12" +version = "0.2.13" # 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/response.rs b/packages/injective-cosmwasm/src/exchange/response.rs index 50574d2f..53af1c15 100644 --- a/packages/injective-cosmwasm/src/exchange/response.rs +++ b/packages/injective-cosmwasm/src/exchange/response.rs @@ -8,10 +8,15 @@ use crate::exchange::{ derivative_market::{FullDerivativeMarket, PerpetualMarketFunding, PerpetualMarketInfo}, spot::TrimmedSpotLimitOrder, spot_market::SpotMarket, - types::{DenomDecimals, Deposit, MarketVolume, PriceLevel, VolumeByType}, + types::{DenomDecimals, Deposit, MarketVolume, Params, PriceLevel, VolumeByType}, }; use crate::oracle::volatility::{MetadataStatistics, TradeRecord}; +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +pub struct ExchangeParamsResponse { + pub params: Option, +} + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] pub struct SubaccountDepositResponse { pub deposits: Deposit, diff --git a/packages/injective-cosmwasm/src/exchange/types.rs b/packages/injective-cosmwasm/src/exchange/types.rs index 94a6b25a..ff6245b2 100644 --- a/packages/injective-cosmwasm/src/exchange/types.rs +++ b/packages/injective-cosmwasm/src/exchange/types.rs @@ -1,9 +1,10 @@ -use cosmwasm_std::{Empty, StdError, StdResult}; +use cosmwasm_std::{Coin, Empty, StdError, StdResult}; use cw_storage_plus::{Key, KeyDeserialize, Prefixer, PrimaryKey}; use injective_math::FPDecimal; use schemars::JsonSchema; use serde::ser::Error as SerError; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; +use serde_repr::{Deserialize_repr, Serialize_repr}; use std::fmt; use crate::InjectiveQuerier; @@ -11,6 +12,36 @@ 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)] +pub struct Params { + pub spot_market_instant_listing_fee: Coin, + pub derivative_market_instant_listing_fee: Coin, + pub default_spot_maker_fee_rate: FPDecimal, + pub default_spot_taker_fee_rate: FPDecimal, + pub default_derivative_maker_fee_rate: FPDecimal, + pub default_derivative_taker_fee_rate: FPDecimal, + pub default_initial_margin_ratio: FPDecimal, + pub default_maintenance_margin_ratio: FPDecimal, + pub default_funding_interval: i64, + pub relayer_fee_share_rate: FPDecimal, + pub default_hourly_funding_rate_cap: FPDecimal, + pub default_hourly_interest_rate: FPDecimal, + pub max_derivative_order_side_count: u32, + pub inj_reward_staked_requirement_threshold: FPDecimal, + pub trading_rewards_vesting_duration: i64, + pub liquidator_reward_share_rate: FPDecimal, + pub binary_options_market_instant_listing_fee: Coin, + #[serde(default)] + pub atomic_market_order_access_level: AtomicMarketOrderAccessLevel, + pub spot_atomic_market_order_fee_multiplier: FPDecimal, + pub derivative_atomic_market_order_fee_multiplier: FPDecimal, + pub binary_options_atomic_market_order_fee_multiplier: FPDecimal, + pub minimal_protocol_fee_rate: FPDecimal, + pub is_instant_derivative_market_launch_enabled: bool, +} + /// Deposit is data format for the subaccount deposit #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] pub struct Deposit { @@ -57,6 +88,16 @@ pub enum MarketType { Derivative, } +#[derive(Serialize_repr, Deserialize_repr, Default, Clone, Debug, PartialEq, Eq, JsonSchema, Copy)] +#[repr(i32)] +pub enum AtomicMarketOrderAccessLevel { + #[default] + Nobody = 0, + BeginBlockerSmartContractsOnly = 1, + SmartContractsOnly = 2, + Everyone = 3, +} + #[derive(Serialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, JsonSchema)] pub struct MarketId(String); diff --git a/packages/injective-cosmwasm/src/exchange_mock_querier.rs b/packages/injective-cosmwasm/src/exchange_mock_querier.rs index 3e4fa0c1..7c64a063 100644 --- a/packages/injective-cosmwasm/src/exchange_mock_querier.rs +++ b/packages/injective-cosmwasm/src/exchange_mock_querier.rs @@ -12,7 +12,7 @@ use injective_math::FPDecimal; use crate::exchange::{ derivative_market::DerivativeMarket, response::QueryOrderbookResponse, - types::{MarketVolume, PriceLevel, VolumeByType}, + types::{AtomicMarketOrderAccessLevel, MarketVolume, Params, PriceLevel, VolumeByType}, }; use crate::oracle::{ types::{OracleHistoryOptions, OracleType, PriceState, PythPriceState}, @@ -21,11 +21,12 @@ use crate::oracle::{ use crate::tokenfactory::response::{TokenFactoryCreateDenomFeeResponse, TokenFactoryDenomSupplyResponse}; use crate::wasmx::response::QueryContractRegistrationInfoResponse; use crate::{ - Deposit, DerivativeMarketResponse, FullDerivativeMarket, InjectiveQuery, InjectiveQueryWrapper, MarketMidPriceAndTOBResponse, MarketStatus, - MarketVolatilityResponse, OracleInfo, OracleVolatilityResponse, OrderSide, PerpetualMarketFundingResponse, PerpetualMarketInfoResponse, - PythPriceResponse, QueryAggregateMarketVolumeResponse, QueryAggregateVolumeResponse, QueryDenomDecimalResponse, QueryDenomDecimalsResponse, - QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarket, SpotMarketResponse, SubaccountDepositResponse, - SubaccountEffectivePositionInMarketResponse, SubaccountPositionInMarketResponse, TraderDerivativeOrdersResponse, TraderSpotOrdersResponse, + Deposit, DerivativeMarketResponse, ExchangeParamsResponse, FullDerivativeMarket, InjectiveQuery, InjectiveQueryWrapper, + MarketMidPriceAndTOBResponse, MarketStatus, MarketVolatilityResponse, OracleInfo, OracleVolatilityResponse, OrderSide, + PerpetualMarketFundingResponse, PerpetualMarketInfoResponse, PythPriceResponse, QueryAggregateMarketVolumeResponse, QueryAggregateVolumeResponse, + QueryDenomDecimalResponse, QueryDenomDecimalsResponse, QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarket, SpotMarketResponse, + SubaccountDepositResponse, SubaccountEffectivePositionInMarketResponse, SubaccountPositionInMarketResponse, TraderDerivativeOrdersResponse, + TraderSpotOrdersResponse, }; use crate::{MarketId, SubaccountId}; @@ -279,6 +280,40 @@ fn default_all_balances_bank_query_handler() -> QuerierResult { SystemResult::Ok(ContractResult::from(to_binary(&response))) } +fn default_exchange_params_response_handler() -> QuerierResult { + let denom = "inj"; + + let response = ExchangeParamsResponse { + params: Some(Params { + spot_market_instant_listing_fee: Coin::new(100000000000000000000, denom), + derivative_market_instant_listing_fee: Coin::new(1000000000000000000000, denom), + default_spot_maker_fee_rate: FPDecimal::must_from_str("-0.0001"), + default_spot_taker_fee_rate: FPDecimal::must_from_str("0.001"), + default_derivative_maker_fee_rate: FPDecimal::must_from_str("-0.0001"), + default_derivative_taker_fee_rate: FPDecimal::must_from_str("0.001"), + default_initial_margin_ratio: FPDecimal::must_from_str("0.05"), + default_maintenance_margin_ratio: FPDecimal::must_from_str("0.02"), + default_funding_interval: 3600i64, + // default_multiple: 3600i64, + relayer_fee_share_rate: FPDecimal::must_from_str("0.4"), + default_hourly_funding_rate_cap: FPDecimal::must_from_str("0.000625"), + default_hourly_interest_rate: FPDecimal::must_from_str("0.00000416666"), + max_derivative_order_side_count: 20u32, + inj_reward_staked_requirement_threshold: FPDecimal::must_from_str("25000000000000000000"), + trading_rewards_vesting_duration: 1209600i64, + liquidator_reward_share_rate: FPDecimal::must_from_str("0.05"), + binary_options_market_instant_listing_fee: Coin::new(10000000000000000000, denom), + atomic_market_order_access_level: AtomicMarketOrderAccessLevel::SmartContractsOnly, + spot_atomic_market_order_fee_multiplier: FPDecimal::must_from_str("2.0"), + derivative_atomic_market_order_fee_multiplier: FPDecimal::must_from_str("2.0"), + binary_options_atomic_market_order_fee_multiplier: FPDecimal::must_from_str("2.0"), + minimal_protocol_fee_rate: FPDecimal::must_from_str("0.00001"), + is_instant_derivative_market_launch_enabled: true, + }), + }; + SystemResult::Ok(ContractResult::from(to_binary(&response))) +} + fn default_spot_market_orderbook_response_handler() -> QuerierResult { let response = QueryOrderbookResponse { buys_price_level: vec![PriceLevel::new(9u128.into(), 10u128.into()), PriceLevel::new(8u128.into(), 10u128.into())], @@ -409,9 +444,14 @@ pub trait HandlesPriceLevelsQuery { fn handle(&self, market_id: MarketId, order_side: OrderSide) -> QuerierResult; } +pub trait HandlesExchangeParamsQuery { + fn handle(&self) -> QuerierResult; +} + pub struct WasmMockQuerier { pub smart_query_handler: Option>, pub subaccount_deposit_response_handler: Option>, + pub exchange_params_response_handler: Option>, pub spot_market_response_handler: Option>, pub trader_spot_orders_response_handler: Option>, pub trader_spot_orders_to_cancel_up_to_amount_response_handler: Option>, @@ -492,6 +532,10 @@ impl WasmMockQuerier { Some(handler) => handler.handle(subaccount_id, denom), None => default_subaccount_deposit_response_handler(), }, + InjectiveQuery::ExchangeParams {} => match &self.exchange_params_response_handler { + Some(handler) => handler.handle(), + None => default_exchange_params_response_handler(), + }, InjectiveQuery::SpotMarket { market_id } => match &self.spot_market_response_handler { Some(handler) => handler.handle(market_id), None => default_spot_market_response_handler(market_id), @@ -656,6 +700,7 @@ impl WasmMockQuerier { WasmMockQuerier { smart_query_handler: None, subaccount_deposit_response_handler: None, + exchange_params_response_handler: None, spot_market_response_handler: None, trader_spot_orders_response_handler: None, trader_spot_orders_to_cancel_up_to_amount_response_handler: None, diff --git a/packages/injective-cosmwasm/src/lib.rs b/packages/injective-cosmwasm/src/lib.rs index c40970e9..e5265d04 100644 --- a/packages/injective-cosmwasm/src/lib.rs +++ b/packages/injective-cosmwasm/src/lib.rs @@ -8,10 +8,11 @@ pub use exchange::{ market::MarketStatus, order::{GenericOrder, GenericTrimmedOrder, OrderData, OrderInfo, OrderSide, OrderType}, response::{ - DerivativeMarketResponse, MarketMidPriceAndTOBResponse, MarketVolatilityResponse, OracleVolatilityResponse, PerpetualMarketFundingResponse, - PerpetualMarketInfoResponse, QueryAggregateMarketVolumeResponse, QueryAggregateVolumeResponse, QueryDenomDecimalResponse, - QueryDenomDecimalsResponse, QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarketResponse, SubaccountDepositResponse, - SubaccountEffectivePositionInMarketResponse, SubaccountPositionInMarketResponse, TraderDerivativeOrdersResponse, TraderSpotOrdersResponse, + DerivativeMarketResponse, ExchangeParamsResponse, MarketMidPriceAndTOBResponse, MarketVolatilityResponse, OracleVolatilityResponse, + PerpetualMarketFundingResponse, PerpetualMarketInfoResponse, QueryAggregateMarketVolumeResponse, QueryAggregateVolumeResponse, + QueryDenomDecimalResponse, QueryDenomDecimalsResponse, QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarketResponse, + SubaccountDepositResponse, SubaccountEffectivePositionInMarketResponse, SubaccountPositionInMarketResponse, TraderDerivativeOrdersResponse, + TraderSpotOrdersResponse, }, spot::{MsgCreateSpotMarketOrderResponse, SpotLimitOrder, SpotMarketOrder, SpotOrder, TrimmedSpotLimitOrder}, spot_market::SpotMarket, @@ -20,8 +21,8 @@ pub use exchange::{ subaccount_id_to_ethereum_address, subaccount_id_to_injective_address, subaccount_id_to_unchecked_injective_address, }, types::{ - DenomDecimals, Deposit, Hash, MarketId, MarketType, PriceLevel, ShortSubaccountId, SubaccountId, FROM_WORST_TO_BEST_CANCELLATION_STRATEGY, - UNSORTED_CANCELLATION_STRATEGY, + DenomDecimals, Deposit, Hash, MarketId, MarketType, Params, PriceLevel, ShortSubaccountId, SubaccountId, + FROM_WORST_TO_BEST_CANCELLATION_STRATEGY, UNSORTED_CANCELLATION_STRATEGY, }, }; pub use oracle::{ diff --git a/packages/injective-cosmwasm/src/querier.rs b/packages/injective-cosmwasm/src/querier.rs index 64b347df..567cae3c 100644 --- a/packages/injective-cosmwasm/src/querier.rs +++ b/packages/injective-cosmwasm/src/querier.rs @@ -7,10 +7,11 @@ use crate::exchange::response::StakedAmountResponse; use crate::exchange::{ order::OrderSide, response::{ - DerivativeMarketResponse, MarketMidPriceAndTOBResponse, MarketVolatilityResponse, OracleVolatilityResponse, PerpetualMarketFundingResponse, - PerpetualMarketInfoResponse, QueryAggregateVolumeResponse, QueryDenomDecimalResponse, QueryDenomDecimalsResponse, - QueryMarketAtomicExecutionFeeMultiplierResponse, QueryOrderbookResponse, SpotMarketResponse, SubaccountDepositResponse, - SubaccountEffectivePositionInMarketResponse, SubaccountPositionInMarketResponse, TraderDerivativeOrdersResponse, TraderSpotOrdersResponse, + DerivativeMarketResponse, ExchangeParamsResponse, MarketMidPriceAndTOBResponse, MarketVolatilityResponse, OracleVolatilityResponse, + PerpetualMarketFundingResponse, PerpetualMarketInfoResponse, QueryAggregateVolumeResponse, QueryDenomDecimalResponse, + QueryDenomDecimalsResponse, QueryMarketAtomicExecutionFeeMultiplierResponse, QueryOrderbookResponse, SpotMarketResponse, + SubaccountDepositResponse, SubaccountEffectivePositionInMarketResponse, SubaccountPositionInMarketResponse, TraderDerivativeOrdersResponse, + TraderSpotOrdersResponse, }, types::{MarketId, SubaccountId}, }; @@ -76,6 +77,16 @@ impl<'a> InjectiveQuerier<'a> { } // Exchange + pub fn query_exchange_params(&self) -> StdResult { + let request = InjectiveQueryWrapper { + route: InjectiveRoute::Exchange, + query_data: InjectiveQuery::ExchangeParams {}, + }; + + let res: ExchangeParamsResponse = self.querier.query(&request.into())?; + Ok(res) + } + pub fn query_subaccount_deposit + Clone, P: Into + Clone>( &self, subaccount_id: &'a T, diff --git a/packages/injective-cosmwasm/src/query.rs b/packages/injective-cosmwasm/src/query.rs index e371e5be..ad2db33c 100644 --- a/packages/injective-cosmwasm/src/query.rs +++ b/packages/injective-cosmwasm/src/query.rs @@ -41,6 +41,7 @@ pub enum InjectiveQuery { pagination: Option, }, // Exchange + ExchangeParams {}, SubaccountDeposit { subaccount_id: SubaccountId, denom: String,