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