Skip to main content

ic_query/sns/report/model/reports/
metrics.rs

1//! Module: sns::report::model::reports::metrics
2//!
3//! Responsibility: bounded SNS Governance metrics report DTOs.
4//! Does not own: discovery, live calls, source validation, or rendering.
5//! Boundary: preserves raw cached treasury evidence and native optional values.
6
7use serde::Serialize;
8
9///
10/// SnsTreasuryKind
11///
12/// Native SNS treasury asset classification with unknown-value preservation.
13///
14
15#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize)]
16#[serde(rename_all = "snake_case")]
17pub enum SnsTreasuryKind {
18    /// Native code zero.
19    Unspecified,
20    /// Native ICP treasury code.
21    Icp,
22    /// Native SNS governance-token treasury code.
23    SnsToken,
24    /// Future or otherwise unknown native code.
25    Unknown,
26}
27
28impl SnsTreasuryKind {
29    /// Return the stable native classification label.
30    #[must_use]
31    pub const fn as_str(self) -> &'static str {
32        match self {
33            Self::Unspecified => "unspecified",
34            Self::Icp => "icp",
35            Self::SnsToken => "sns_token",
36            Self::Unknown => "unknown",
37        }
38    }
39}
40
41///
42/// SnsTreasuryMetricRow
43///
44/// One timestamped cached treasury metric returned by SNS Governance.
45///
46
47#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
48pub struct SnsTreasuryMetricRow {
49    /// Raw native treasury discriminant.
50    pub treasury: i32,
51    /// Native treasury classification derived from the raw discriminant.
52    pub treasury_kind: SnsTreasuryKind,
53    /// Human-readable treasury name returned by Governance.
54    pub name: Option<String>,
55    /// Ledger that is authoritative for the treasury account.
56    pub ledger_canister_id: Option<String>,
57    /// Owner of the authoritative treasury account.
58    pub account_owner: Option<String>,
59    /// Optional 32-byte account subaccount as lowercase hexadecimal text.
60    pub account_subaccount_hex: Option<String>,
61    /// Cached current treasury amount in native e8s.
62    pub amount_e8s: Option<u64>,
63    /// Treasury amount at swap finalization in native e8s.
64    pub original_amount_e8s: Option<u64>,
65    /// Unix timestamp when this cached treasury metric was updated.
66    pub timestamp_seconds: Option<u64>,
67}
68
69///
70/// SnsVotingPowerMetrics
71///
72/// Timestamped cached SNS Governance voting-power metrics.
73///
74
75#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
76pub struct SnsVotingPowerMetrics {
77    /// Total potential Governance voting power, when returned.
78    pub governance_total_potential_voting_power: Option<u64>,
79    /// Unix timestamp when the voting-power metric was updated.
80    pub timestamp_seconds: Option<u64>,
81}
82
83///
84/// SnsMetricsReport
85///
86/// Bounded live report of native SNS Governance metrics for one SNS.
87///
88
89#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
90pub struct SnsMetricsReport {
91    /// Report schema version.
92    pub schema_version: u32,
93    /// Requested IC network identity.
94    pub network: String,
95    /// Mainnet SNS-W canister used for discovery.
96    pub sns_wasm_canister_id: String,
97    /// Collection timestamp in UTC.
98    pub fetched_at: String,
99    /// IC API endpoint used for all client requests.
100    pub source_endpoint: String,
101    /// Collector identity recorded by the source request.
102    pub fetched_by: String,
103    /// SNS-W list id assigned to this deployed SNS.
104    pub id: usize,
105    /// SNS name resolved during discovery.
106    pub name: String,
107    /// Root canister identity used to resolve this SNS.
108    pub root_canister_id: String,
109    /// Governance canister queried for metrics.
110    pub governance_canister_id: String,
111    /// Native Governance metrics method.
112    pub method: String,
113    /// Native call type used for the Governance method.
114    pub call_type: String,
115    /// Requested recent-proposal window in seconds.
116    pub time_window_seconds: u64,
117    /// Whether all returned metrics represent one authoritative point in time.
118    pub point_in_time_guaranteed: bool,
119    /// Whether treasury values are cached Governance metrics.
120    pub treasury_metrics_cached: bool,
121    /// Recent submitted-proposal count for the requested window.
122    pub num_recently_submitted_proposals: Option<u64>,
123    /// Recent executed-proposal count for the requested window.
124    pub num_recently_executed_proposals: Option<u64>,
125    /// Latest SNS-ledger block timestamp observed by Governance.
126    pub last_ledger_block_timestamp: Option<u64>,
127    /// SNS genesis timestamp returned by Governance.
128    pub genesis_timestamp_seconds: Option<u64>,
129    /// Number of returned cached treasury rows.
130    pub treasury_metric_count: usize,
131    /// Canonically ordered cached treasury metrics.
132    pub treasury_metrics: Vec<SnsTreasuryMetricRow>,
133    /// Cached voting-power metrics, when returned.
134    pub voting_power_metrics: Option<SnsVotingPowerMetrics>,
135}