1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use cosmwasm_std::{Addr, CustomQuery};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use injective_math::FPDecimal;

use crate::oracle::{
    types::{OracleHistoryOptions, OracleInfo, OracleType},
    volatility::TradeHistoryOptions,
};
use crate::route::InjectiveRoute;
use crate::{
    exchange::{
        cancel::CancellationStrategy,
        order::OrderSide,
        types::{MarketId, SubaccountId},
    },
    oracle::types::ScalingOptions,
};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct InjectiveQueryWrapper {
    pub route: InjectiveRoute,
    pub query_data: InjectiveQuery,
}

/// InjectiveQuery is an override of QueryRequest::Custom to access Injective-specific modules
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum InjectiveQuery {
    // Exchange
    ExchangeParams {},
    SubaccountDeposit {
        subaccount_id: SubaccountId,
        denom: String,
    },
    SpotMarket {
        market_id: MarketId,
    },
    TraderSpotOrders {
        market_id: MarketId,
        subaccount_id: SubaccountId,
    },
    TraderSpotOrdersToCancelUpToAmount {
        market_id: MarketId,
        subaccount_id: SubaccountId,
        base_amount: FPDecimal,
        quote_amount: FPDecimal,
        strategy: CancellationStrategy,
        reference_price: Option<FPDecimal>,
    },
    TraderDerivativeOrdersToCancelUpToAmount {
        market_id: MarketId,
        subaccount_id: SubaccountId,
        quote_amount: FPDecimal,
        strategy: CancellationStrategy,
        reference_price: Option<FPDecimal>,
    },
    DerivativeMarket {
        market_id: MarketId,
    },
    SubaccountPositions {
        subaccount_id: SubaccountId,
    },
    SubaccountPositionInMarket {
        market_id: MarketId,
        subaccount_id: SubaccountId,
    },
    SubaccountEffectivePositionInMarket {
        market_id: MarketId,
        subaccount_id: SubaccountId,
    },
    TraderDerivativeOrders {
        market_id: MarketId,
        subaccount_id: SubaccountId,
    },
    TraderTransientSpotOrders {
        market_id: MarketId,
        subaccount_id: SubaccountId,
    },
    TraderTransientDerivativeOrders {
        market_id: MarketId,
        subaccount_id: SubaccountId,
    },
    PerpetualMarketInfo {
        market_id: MarketId,
    },
    PerpetualMarketFunding {
        market_id: MarketId,
    },
    // Make sure you are aware of the potential to run out of gas when using this query
    MarketVolatility {
        market_id: MarketId,
        trade_history_options: TradeHistoryOptions,
    },
    SpotMarketMidPriceAndTob {
        market_id: MarketId,
    },
    SpotOrderbook {
        market_id: MarketId,
        limit: u64,
        order_side: OrderSide,
        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,
    },
    AggregateMarketVolume {
        market_id: MarketId,
    },
    AggregateAccountVolume {
        account: String,
    },
    MarketAtomicExecutionFeeMultiplier {
        market_id: MarketId,
    },
    // Staking
    StakedAmount {
        delegator_address: Addr,
        max_delegations: u16,
    },
    // Oracle
    OracleVolatility {
        base_info: Option<OracleInfo>,
        quote_info: Option<OracleInfo>,
        oracle_history_options: Option<OracleHistoryOptions>,
    },
    OraclePrice {
        oracle_type: OracleType,
        base: String,
        quote: String,
        scaling_options: Option<ScalingOptions>,
    },
    PythPrice {
        price_id: String,
    },
    TokenFactoryDenomTotalSupply {
        denom: String,
    },
    TokenFactoryDenomCreationFee {},
    // Wasmx
    WasmxRegisteredContractInfo {
        contract_address: String,
    },
}

impl CustomQuery for InjectiveQueryWrapper {}