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/// MainnetSnsMetrics
12///
13/// Source-layer result from one bounded SNS Governance metrics query.
14///
15
16#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
17pub struct MainnetSnsMetrics {
18 /// Governance canister identity queried by the source.
19 pub governance_canister_id: String,
20 /// Native Governance method queried by the source.
21 pub method: SnsCanisterMethod,
22 /// Native call type used by the source.
23 pub call_type: SnsCanisterCallType,
24 /// Proposal-count window supplied to Governance.
25 pub time_window_seconds: u64,
26 /// Whether the source can prove one point-in-time snapshot.
27 pub point_in_time_guaranteed: bool,
28 /// Whether treasury values are cached Governance metrics.
29 pub treasury_metrics_cached: bool,
30 /// Recent submitted-proposal count.
31 pub num_recently_submitted_proposals: Option<u64>,
32 /// Recent executed-proposal count.
33 pub num_recently_executed_proposals: Option<u64>,
34 /// Latest SNS-ledger block timestamp observed by Governance.
35 pub last_ledger_block_timestamp: Option<u64>,
36 /// SNS genesis timestamp.
37 pub genesis_timestamp_seconds: Option<u64>,
38 /// Cached treasury metrics.
39 pub treasury_metrics: Vec<SnsTreasuryMetricRow>,
40 /// Cached voting-power metrics.
41 pub voting_power_metrics: Option<SnsVotingPowerMetrics>,
42}
43
44///
45/// SnsTreasuryMetricRow
46///
47/// One timestamped cached treasury metric returned by SNS Governance.
48///
49
50#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
51pub struct SnsTreasuryMetricRow {
52 /// Raw native treasury discriminant.
53 pub treasury: i32,
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 /// Number of returned cached treasury rows.
111 pub treasury_metric_count: usize,
112
113 /// Validated source payload shared with native collection.
114 #[serde(flatten)]
115 pub metrics: MainnetSnsMetrics,
116}
117
118pub(in crate::sns::report) const fn sns_treasury_kind(treasury: i32) -> &'static str {
119 match treasury {
120 0 => "unspecified",
121 1 => "icp",
122 2 => "sns_token",
123 _ => "unknown",
124 }
125}