tefi_oracle/
hub.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::Decimal;
5
6pub const DEFAULT_PRIORITY: u8 = 10;
7pub const MAX_WHITELISTED_PROXIES: u8 = 15;
8
9#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
10pub struct InstantiateMsg {
11    pub owner: String,
12    pub base_denom: String,
13    pub max_proxies_per_symbol: u8,
14}
15
16#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
17#[serde(rename_all = "snake_case")]
18pub enum HubExecuteMsg {
19    /// Owner operation to update the owner parameter
20    UpdateOwner { owner: String },
21    /// Owner operation to update the max_proxies_per_symbol parameter
22    UpdateMaxProxies { max_proxies_per_symbol: u8 },
23    /// Register a new source for a symbol
24    RegisterSource {
25        symbol: String,
26        proxy_addr: String,
27        priority: Option<u8>,
28    },
29    /// Registers a list of sources
30    BulkRegisterSource {
31        sources: Vec<(String, String, Option<u8>)>, // (symbol, proxy_addr, priority)
32    },
33    /// Updates the priorities for proxies registered
34    UpdateSourcePriorityList {
35        symbol: String,
36        priority_list: Vec<(String, u8)>,
37    },
38    /// Removes an already registered proxy
39    RemoveSource { symbol: String, proxy_addr: String },
40    /// Whitelists a new proxy in hub. After a proxy is whitelisted
41    /// it can be registered as a source
42    WhitelistProxy {
43        proxy_addr: String,
44        provider_name: String,
45    },
46    /// Removes a proxy from the whitelist
47    RemoveProxy { proxy_addr: String },
48    /// Updates the map of `asset_token` to `symbol`
49    /// overwrites storage if already mapped
50    InsertAssetSymbolMap {
51        map: Vec<(String, String)>, // (address, symbol)
52    },
53}
54
55#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
56#[serde(rename_all = "snake_case")]
57pub enum HubQueryMsg {
58    /// Queries contract configuration
59    Config {},
60    /// Queries the list of whitelisted proxies
61    ProxyWhitelist {},
62    /// Returns the list of all symbols with all the sources
63    AllSources {
64        start_after: Option<String>, // symbol for pagination
65        limit: Option<u32>,
66    },
67    /// Queries the information of all registered proxies for the provided asset_token
68    Sources { asset_token: String },
69    /// Queries the information of all registered proxies for the provided symbol
70    SourcesBySymbol { symbol: String },
71    /// Queries the highes priority available price within the timeframe
72    /// If timeframe is not provided, it will ignore the price age
73    Price {
74        asset_token: String,
75        timeframe: Option<u64>,
76    },
77    /// Queries the highes priority available price within the timeframe
78    /// If timeframe is not provided, it will ignore the price age
79    PriceBySymbol {
80        symbol: String,
81        timeframe: Option<u64>,
82    },
83    /// Queries all registered proxy prices for the provied asset_token
84    PriceList { asset_token: String },
85    /// Queries all registered proxy prices for the provied symbol
86    PriceListBySymbol { symbol: String },
87    /// Returns the map of `asset_token` to `symbol`
88    AssetSymbolMap {
89        start_after: Option<String>, // address for pagination
90        limit: Option<u32>,
91    },
92    /// Query to check if `proxy_addr` is whitelisted and has price feed
93    /// for the specified `symbol`. The purpose of this query is to have a
94    /// way of checking if a price feed is valid and available before registering
95    /// Returns the PriceResponse or an error
96    CheckSource { proxy_addr: String, symbol: String },
97}
98
99#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
100pub struct ConfigResponse {
101    pub owner: String,
102    pub base_denom: String,
103    pub max_proxies_per_symbol: u8,
104}
105
106#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
107pub struct PriceResponse {
108    pub rate: Decimal,
109    pub last_updated: u64,
110}
111
112#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
113#[serde(rename_all = "snake_case")]
114pub enum PriceQueryResult {
115    Success(PriceResponse),
116    Fail,
117}
118
119#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
120pub struct PriceListResponse {
121    pub price_list: Vec<(u8, ProxyInfoResponse, PriceQueryResult)>, // (priority, proxy_info, result)
122}
123
124#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
125pub struct SourcesResponse {
126    pub symbol: String,
127    pub proxies: Vec<(u8, ProxyInfoResponse)>,
128}
129
130#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
131pub struct AllSourcesResponse {
132    pub list: Vec<SourcesResponse>,
133}
134
135impl From<crate::proxy::ProxyPriceResponse> for PriceResponse {
136    fn from(proxy_res: crate::proxy::ProxyPriceResponse) -> Self {
137        PriceResponse {
138            rate: proxy_res.rate,
139            last_updated: proxy_res.last_updated,
140        }
141    }
142}
143
144#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
145pub struct ProxyWhitelistResponse {
146    pub proxies: Vec<ProxyInfoResponse>,
147}
148
149#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
150pub struct ProxyInfoResponse {
151    pub address: String,
152    pub provider_name: String,
153}
154
155#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
156pub struct AssetSymbolMapResponse {
157    pub map: Vec<(String, String)>, // address, symbol
158}