sei_cosmwasm/query.rs
1use cosmwasm_std::{Addr, CustomQuery, Decimal, Uint128};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5use crate::proto_structs::{DenomOracleExchangeRatePair, DexPair, DexTwap, Epoch, OracleTwap};
6use crate::route::SeiRoute;
7use crate::sei_types::{DenomAuthorityMetadata, OrderResponse};
8use crate::Order;
9
10/// SeiQueryWrapper is an override of QueryRequest::Custom to access Sei-specific modules
11#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
12#[serde(rename_all = "snake_case")]
13pub struct SeiQueryWrapper {
14 pub route: SeiRoute,
15 pub query_data: SeiQuery,
16}
17
18// implement custom query
19impl CustomQuery for SeiQueryWrapper {}
20
21/// SeiQuery is defines available query datas
22#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
23#[serde(rename_all = "snake_case")]
24pub enum SeiQuery {
25 ExchangeRates {},
26 OracleTwaps {
27 lookback_seconds: u64,
28 },
29 DexTwaps {
30 contract_address: Addr,
31 lookback_seconds: u64,
32 },
33 Epoch {},
34 GetOrders {
35 contract_address: Addr,
36 account: Addr,
37 },
38 GetOrderById {
39 contract_address: Addr,
40 price_denom: String,
41 asset_denom: String,
42 id: u64,
43 },
44 GetLatestPrice {
45 contract_address: Addr,
46 price_denom: String,
47 asset_denom: String,
48 },
49 OrderSimulation {
50 contract_address: Addr,
51 order: Order,
52 },
53 DenomAuthorityMetadata {
54 denom: String,
55 },
56 DenomsFromCreator {
57 creator: Addr,
58 },
59
60 /// Query to for static call to EVM contract.
61 /// StaticCall executes the contract associated deployed at `to` address with the given `data`
62 /// as parameters while disallowing any modifications to the state during the call.
63 StaticCall {
64 /// Sei native (bech32-encoded 'sei*') address calling the contract
65 from: String,
66 /// The address of the EVM contract to call
67 to: String,
68 /// Base64 encoded data to pass to the contract
69 data: String, // base64
70 },
71 /// Query to get hex payload for the ERC-20 `transfer` function
72 Erc20TransferPayload {
73 /// Recipient Sei native (bech32-encoded 'sei*') address
74 recipient: String,
75 /// Amount to transfer
76 amount: Uint128,
77 },
78 /// Query to get hex payload for the ERC-20 `transferFrom` function
79 Erc20TransferFromPayload {
80 /// Owner Sei native (bech32-encoded 'sei*') address
81 owner: String,
82 /// Recipient Sei native (bech32-encoded 'sei*') address
83 recipient: String,
84 /// Amount to transfer
85 amount: Uint128,
86 },
87 /// Query to get hex payload for the ERC-20 `approve` function
88 Erc20ApprovePayload {
89 /// Spender Sei native (bech32-encoded 'sei*') address
90 spender: String,
91 /// Amount to approve
92 amount: Uint128,
93 },
94 /// Query to get the remaining number of tokens that spender will be allowed to spend on behalf
95 /// of owner through
96 Erc20Allowance {
97 /// ERC-20 contract address
98 contract_address: String,
99 /// Owner Sei native (bech32-encoded 'sei*') address
100 owner: String,
101 /// Spender Sei native (bech32-encoded 'sei*') address
102 spender: String,
103 },
104 /// Query to get the token info, including the name, symbol, decimals and total supply
105 Erc20TokenInfo {
106 /// ERC-20 contract address
107 contract_address: String,
108 /// Caller Sei native (bech32-encoded 'sei*') address
109 caller: String,
110 },
111 /// Query to get the balance of the account with the given Sei native (bech32-encoded 'sei*') address.
112 /// Executes the `balanceOf` ERC-20 function under the hood.
113 Erc20Balance {
114 /// ERC-20 contract address
115 contract_address: String,
116 /// Account Sei native (bech32-encoded 'sei*') address
117 account: String,
118 },
119 /// Query to get the hex payload for the ERC-721 `transferFrom` function
120 Erc721TransferPayload {
121 /// Sei native (bech32-encoded 'sei*') address of the sender
122 from: String,
123 /// Sei native (bech32-encoded 'sei*') address of the recipient
124 recipient: String,
125 /// The identifier for an NFT. String representation of the token ID
126 token_id: String,
127 },
128 /// Query to get the hex payload for the ERC-721 `approve` function
129 Erc721ApprovePayload {
130 /// Sei native (bech32-encoded 'sei*') address of the spender
131 spender: String,
132 /// The identifier for an NFT. String representation of the token ID
133 token_id: String,
134 },
135 /// Query to get the Sei native (bech32-encoded 'sei*') address of the owner of the NFT.
136 /// Executes ERC-721 `ownerOf` function under the hood.
137 Erc721Owner {
138 /// Caller Sei native (bech32-encoded 'sei*') address
139 caller: String,
140 /// ERC-721 contract address
141 contract_address: String,
142 /// The identifier for an NFT. String representation of the token ID
143 token_id: String,
144 },
145 /// Query to get the approved address for a single NFT. Executes ERC-721 `getApproved` function
146 Erc721Approved {
147 /// Caller Sei native (bech32-encoded 'sei*') address
148 caller: String,
149 /// ERC-721 contract address
150 contract_address: String,
151 /// The identifier for an NFT. String representation of the token ID
152 token_id: String,
153 },
154 /// Query if an address is an authorized operator for another address. Executes ERC-721
155 /// `isApprovedForAll` function.
156 Erc721IsApprovedForAll {
157 /// Caller Sei native (bech32-encoded 'sei*') address
158 caller: String,
159 /// ERC-721 contract address
160 contract_address: String,
161 /// The owner of the NFT Sei native (bech32-encoded 'sei*') address
162 owner: String,
163 /// The operator Sei address that acts on behalf of the owner
164 operator: String,
165 },
166 /// Query to get the hex payload for the ERC-721 `setApprovalForAll` function.
167 Erc721SetApprovalAllPayload {
168 /// Sei native (bech32-encoded 'sei*') address of the operator
169 to: String,
170 /// Boolean representing the status to set
171 approved: bool,
172 },
173 /// Query to get the name and symbol of the ERC-721 contract. Executes ERC-721 `name` and
174 /// `symbol` functions under the hood.
175 Erc721NameSymbol {
176 /// Caller Sei native (bech32-encoded 'sei*') address
177 caller: String,
178 /// ERC-721 contract address
179 contract_address: String,
180 },
181 /// Query to get the URI for a given NFT. Executes ERC-721 `tokenURI` function under the hood.
182 Erc721Uri {
183 /// Caller Sei native (bech32-encoded 'sei*') address
184 caller: String,
185 /// ERC-721 contract address
186 contract_address: String,
187
188 token_id: String,
189 },
190 /// Query to get the EVM address associated with the given SEI address.
191 GetEvmAddress {
192 sei_address: String,
193 },
194 /// Query to get the SEI address associated with the given EVM address.
195 GetSeiAddress {
196 evm_address: String,
197 },
198}
199
200/// ExchangeRatesResponse is data format returned from OracleRequest::ExchangeRates query
201#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
202pub struct ExchangeRatesResponse {
203 pub denom_oracle_exchange_rate_pairs: Vec<DenomOracleExchangeRatePair>,
204}
205
206/// OracleTwapsResponse is data format returned from OracleRequest::OracleTwaps query
207#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
208pub struct OracleTwapsResponse {
209 pub oracle_twaps: Vec<OracleTwap>,
210}
211
212/// DexTwapsResponse is data format returned from DexTwaps query
213#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
214pub struct DexTwapsResponse {
215 pub twaps: Vec<DexTwap>,
216}
217
218/// EpochResponse is data format returned from Epoch query
219#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
220pub struct EpochResponse {
221 pub epoch: Epoch,
222}
223
224/// GetOrdersResponse is data format returned from GetOrders query
225#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
226pub struct GetOrdersResponse {
227 pub orders: Vec<OrderResponse>,
228}
229
230/// GetOrderdByIdResponse is data format returned from GetOrderById query
231#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
232pub struct GetOrderByIdResponse {
233 pub order: OrderResponse,
234}
235
236/// PriceResponse is data format for a price of an asset pair
237#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
238#[serde(rename_all = "snake_case")]
239pub struct PriceResponse {
240 pub snapshot_timestamp_in_seconds: u64,
241 pub price: Decimal,
242 pub pair: DexPair,
243}
244
245/// GetLatestPriceResponse is data format returned from GetLatestPrice query
246#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
247pub struct GetLatestPriceResponse {
248 pub price: PriceResponse,
249}
250
251/// OrderSimulationResponse is data format returned from OrderSimulation query
252#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
253pub struct OrderSimulationResponse {
254 pub executed_quantity: Decimal,
255}
256
257/// DenomAuthorityMetadataResponse is data format returned from DenomAuthorityMetadata query
258#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
259pub struct DenomAuthorityMetadataResponse {
260 pub authority_metadata: DenomAuthorityMetadata,
261}
262
263/// DenomsFromCreatorResponse is data format returned from DenomsFromCreator query
264#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
265pub struct DenomsFromCreatorResponse {
266 pub denoms: Vec<String>,
267}
268
269/// `StaticCallResponse` is a struct that represents a response containing the result of a static
270/// call to an EVM contract.
271#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
272pub struct StaticCallResponse {
273 /// The result of the static call to the EVM contract. It's represented as a base64 encoded
274 /// string.
275 pub encoded_data: String, // base64
276}
277
278/// `ErcPayloadResponse` is a struct that represents a response containing the encoded payload for
279/// payload generation queries.
280#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
281pub struct ErcPayloadResponse {
282 /// The hex encoded payload
283 pub encoded_payload: String,
284}
285
286/// `Erc20AllowanceResponse` is a struct that represents a response containing the remaining number
287/// of tokens that spender will be allowed to spend on behalf of owner.
288#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
289pub struct Erc20AllowanceResponse {
290 /// The amount which spender is still allowed to withdraw from owner
291 pub allowance: Uint128,
292}
293
294/// `Erc721OwnerResponse` is a struct that represents a response containing the Sei native (bech32-encoded 'sei*') address
295/// of the owner.
296#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
297pub struct Erc721OwnerResponse {
298 /// The Sei native (bech32-encoded 'sei*') address of the owner of the NFT
299 pub owner: String,
300}
301
302/// `Erc721ApprovedResponse` is a struct that represents a response containing the address of the
303/// approved address for a single NFT.
304#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
305pub struct Erc721ApprovedResponse {
306 /// The approved address for this NFT, or the zero address if there is none
307 pub approved: String,
308}
309
310/// `Erc721IsApprovedForAllResponse` is a struct that represents a response containing a boolean
311/// value indicating if an address is an authorized operator for another address
312#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
313pub struct Erc721IsApprovedForAllResponse {
314 /// True if `operator` is an approved operator for `owner`, false otherwise
315 pub is_approved: bool,
316}
317
318/// `Erc721NameSymbolResponse` is a struct that represents a response containing the name and symbol
319/// of the ERC-721 contract.
320#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
321pub struct Erc721NameSymbolResponse {
322 /// The name of the ERC-721 contract
323 pub name: String,
324 /// The symbol of the ERC-721 contract
325 pub symbol: String,
326}
327
328/// `Erc721UriResponse` is a struct that represents a response containing the URI for a given NFT.
329#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
330pub struct Erc721UriResponse {
331 /// The URI for the given NFT
332 pub uri: String,
333}
334
335/// `EvmAddressResponse` is a struct that represents a response containing an EVM address.
336#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
337pub struct EvmAddressResponse {
338 /// The 20-byte EVM address associated to Sei address that's derived from the public part of a
339 /// public-private key pair. It's represented as a hex string.
340 /// Address is empty if the Sei native (bech32-encoded 'sei*') address is not associated with any EVM address.
341 pub evm_address: String,
342
343 /// A boolean value indicating whether the EVM address is associated.
344 pub associated: bool,
345}
346
347/// `SeiAddressResponse` is a struct that represents a response containing a SEI address.
348#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
349pub struct SeiAddressResponse {
350 /// The Sei native (bech32-encoded 'sei*') address associated to EVM address. Empty if the EVM address is
351 /// not associated with any Sei native (bech32-encoded 'sei*') address.
352 pub sei_address: String,
353
354 /// A boolean value indicating whether the Sei native (bech32-encoded 'sei*') address is associated to EVM address.
355 pub associated: bool,
356}