Skip to main content

clp_feed_interface/
msg.rs

1use cosmwasm_schema::{cw_serde, QueryResponses};
2use cosmwasm_std::{Addr, Timestamp};
3
4pub type AssetName = String;
5
6
7#[cw_serde]
8pub struct AssetInfo {
9    pub name: AssetName,
10    pub denom: String,
11    pub decimals: u8,
12}
13
14#[cw_serde]
15pub struct ValidatorInfo {
16    pub public_key: String,
17    pub active: bool,
18}
19
20#[cw_serde]
21pub struct PriceSubmission {
22    pub validator_id: String,
23    pub asset: String,
24    pub price: String,
25    pub timestamp: u64,
26    pub sources: Vec<String>,
27    pub signature: String,
28}
29
30#[cw_serde]
31pub struct AggregatedPrice {
32    pub asset: String,
33    pub price: String,
34    pub timestamp: Timestamp,
35    pub deviation: Option<String>,
36    pub submissions: Vec<PriceSubmission>,
37    pub feed_block_height: u64,
38    pub chain_block_height: Option<u64>,
39}
40
41#[cw_serde]
42pub struct InstantiateMsg {
43    /// Admin address (can manage validators and operators)
44    pub admin: String,
45    /// Initial list of validators with their public keys
46    pub validators: Vec<(String, String)>, // (validator_id, public_key_hex)
47    /// Initial list of operators (relayers)
48    pub operators: Vec<String>,
49    /// Minimum number of validator signatures required (default: 1)
50    pub min_signatures: Option<u32>,
51    /// Maximum age of price submissions in seconds (default: 300 = 5 minutes)
52    pub max_price_age: Option<u64>,
53    /// Initial list of assets info including denom and name to match for queries
54    pub assets: Vec<AssetInfo>,
55}
56
57#[cw_serde]
58pub enum ExecuteMsg {
59    /// Submit aggregated price with validator signatures (operator only)
60    SubmitPrice {
61        /// Aggregated price from Oracle ABCI state
62        aggregated_price: AggregatedPrice,
63        /// Individual validator submissions that were used in aggregation
64        /// TODO: remove this, it is already included in the aggregated price or remove it from the aggregated price
65        validator_submissions: Vec<PriceSubmission>,
66    },
67
68    // ===== ADMIN FUNCTIONS =====
69    /// Add a validator (admin only)
70    AddValidator {
71        validator_id: String,
72        public_key: String,
73    },
74
75    /// Remove a validator (admin only)
76    RemoveValidator { validator_id: String },
77
78    /// Update validator active status (admin only)
79    UpdateValidatorStatus { validator_id: String, active: bool },
80
81    /// Add an operator (admin only)
82    AddOperator { operator: String },
83
84    /// Remove an operator (admin only)
85    RemoveOperator { operator: String },
86
87    /// Update configuration (admin only)
88    UpdateConfig {
89        min_signatures: Option<u32>,
90        max_price_age: Option<u64>,
91    },
92
93    /// Update denoms (admin only)
94    UpdateDenoms {
95        add: Vec<AssetInfo>,
96        remove: Vec<String>,
97    },
98}
99
100#[cw_serde]
101#[derive(QueryResponses)]
102pub enum QueryMsg {
103    /// Get the current aggregated price for an asset
104    #[returns(AggregatedPriceResponse)]
105    GetPrice { asset: String },
106
107    /// Get the current aggregated price for a denom
108    #[returns(AggregatedPriceResponse)]
109    GetPriceByDenom { denom: String },
110
111    /// Get all current aggregated prices
112    #[returns(AllPricesResponse)]
113    GetAllPrices {},
114
115    /// Get validator information
116    #[returns(ValidatorInfoResponse)]
117    GetValidator { validator_id: String },
118
119    /// Get all validators
120    #[returns(AllValidatorsResponse)]
121    GetAllValidators {},
122
123    /// Get recent submission from a specific validator for an asset
124    #[returns(PriceSubmissionResponse)]
125    GetRecentSubmission { asset: String, validator_id: String },
126
127    /// Get contract configuration
128    #[returns(ConfigResponse)]
129    GetConfig {},
130
131    /// Get admin address
132    #[returns(AdminResponse)]
133    GetAdmin {},
134
135    /// Get all operators
136    #[returns(OperatorsResponse)]
137    GetOperators {},
138
139    /// Check if a denom exists
140    #[returns(DenomExistsResponse)]
141    GetDenomExists { denom: String },
142}
143
144// ------------------------------------------------------------------------------------------------
145// RESPONSE TYPES
146// ------------------------------------------------------------------------------------------------
147
148#[cw_serde]
149pub struct AggregatedPriceResponse {
150    pub price: Option<AggregatedPrice>,
151}
152
153#[cw_serde]
154pub struct AllPricesResponse {
155    pub prices: Vec<AggregatedPrice>,
156}
157
158#[cw_serde]
159pub struct ValidatorInfoResponse {
160    pub validator_id: String,
161    pub info: Option<ValidatorInfo>,
162}
163
164#[cw_serde]
165pub struct AllValidatorsResponse {
166    pub validators: Vec<(String, ValidatorInfo)>,
167}
168
169#[cw_serde]
170pub struct PriceSubmissionResponse {
171    pub submission: Option<PriceSubmission>,
172}
173
174#[cw_serde]
175pub struct ConfigResponse {
176    pub min_signatures: u32,
177    pub max_price_age: u64,
178}
179
180#[cw_serde]
181pub struct AdminResponse {
182    pub admin: Addr,
183}
184
185#[cw_serde]
186pub struct OperatorsResponse {
187    pub operators: Vec<Addr>,
188}
189
190#[cw_serde]
191pub struct DenomExistsResponse {
192    pub exists: bool,
193    pub asset: Option<AssetInfo>,
194}
195
196#[cw_serde]
197pub struct MigrateMsg {}