defund_cosmwasm/
query.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::{Coin, CustomQuery};
5
6use crate::defund::{Fund, Broker, PageRequest};
7
8/// DefundRoute is the module path route for the query
9#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
10#[serde(rename_all = "snake_case")]
11pub enum DefundRoute {
12    Etf,
13    Broker,
14}
15
16// implement custom query
17impl CustomQuery for DefundQueryWrapper {}
18
19/// DefundQuery is an override of QueryRequest::Custom to access Defund-specific modules
20#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
21#[serde(rename_all = "snake_case")]
22pub enum DefundQuery {
23    //////////// Etf Module /////////////
24    // Get a fund by its symbol
25    GetFund { symbol: String },
26    // Get all funds in store
27    GetFunds { pagination: PageRequest },
28    // Get current fund price in base denom by symbol
29    GetFundPrice { symbol: String },
30
31    //////////// Broker Module /////////////
32    // Get a broker by its id
33    GetBroker { broker: String },
34    // Get all brokers in store
35    GetBrokers { pagination: PageRequest }
36}
37
38/// SeiQueryWrapper is an override of QueryRequest::Custom to access Sei-specific modules
39#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
40#[serde(rename_all = "snake_case")]
41pub struct DefundQueryWrapper {
42    pub route: DefundRoute,
43    pub query_data: DefundQuery,
44}
45
46/// GetFundResponse is data format returned from GetFund query
47#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
48pub struct GetFundResponse {
49    pub fund: Fund,
50}
51
52/// GetFundsResponse is data format returned from GetFunds query
53#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
54pub struct GetFundsResponse {
55    pub funds: Vec<Fund>,
56}
57
58/// GetFundPriceResponse is data format returned from GetFundPrice query
59#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
60pub struct GetFundPriceResponse {
61    pub receive: Coin,
62}
63
64/// GetBrokerResponse is data format returned from GetBroker query
65#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
66pub struct GetBrokerResponse {
67    pub broker: Broker,
68}
69
70/// GetBrokersResponse is data format returned from GetBrokers query
71#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
72pub struct GetBrokersResponse {
73    pub brokers: Vec<Broker>,
74}