Skip to main content

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

1//! Module: sns::report::model::reports::swap
2//!
3//! Responsibility: SNS decentralization-swap report DTOs.
4//! Does not own: swap canister calls, source validation, lookup, or rendering.
5//! Boundary: preserves native swap lifecycle, sale parameters, derived state, and query gaps.
6
7use serde::Serialize;
8
9///
10/// SnsSwapComponent
11///
12/// Native swap query component represented by a report value or typed gap.
13///
14
15#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize)]
16#[serde(rename_all = "snake_case")]
17pub enum SnsSwapComponent {
18    /// Swap lifecycle state and lifecycle timestamps.
19    Lifecycle,
20    /// Decentralization-sale parameters.
21    SaleParameters,
22    /// Participation totals and derived token rate.
23    DerivedState,
24}
25
26impl SnsSwapComponent {
27    /// Return the stable lowercase component label used in text reports.
28    #[must_use]
29    pub const fn as_str(self) -> &'static str {
30        match self {
31            Self::Lifecycle => "lifecycle",
32            Self::SaleParameters => "sale_parameters",
33            Self::DerivedState => "derived_state",
34        }
35    }
36}
37
38///
39/// SnsSwapQueryGap
40///
41/// One swap query that failed while the other bounded components were retained.
42///
43
44#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
45pub struct SnsSwapQueryGap {
46    /// Typed swap component whose query failed.
47    pub component: SnsSwapComponent,
48    /// Native query method that failed.
49    pub method: String,
50    /// Transport, encoding, or decoding failure retained for diagnostics.
51    pub reason: String,
52}
53
54///
55/// SnsSwapLifecycle
56///
57/// Raw lifecycle code and timestamps returned by the SNS swap canister.
58///
59
60#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
61pub struct SnsSwapLifecycle {
62    /// Optional native lifecycle numeric discriminant.
63    pub lifecycle: Option<i32>,
64    /// Native lifecycle label, or `unknown` for an unrecognized numeric discriminant.
65    pub lifecycle_name: Option<String>,
66    /// Timestamp at which the decentralization sale opened, when returned.
67    pub decentralization_sale_open_timestamp_seconds: Option<u64>,
68    /// Timestamp at which the decentralization swap terminated, when returned.
69    pub decentralization_swap_termination_timestamp_seconds: Option<u64>,
70}
71
72///
73/// SnsSwapNeuronBasketConstructionParameters
74///
75/// Native neuron-basket construction parameters returned by the swap canister.
76///
77
78#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
79pub struct SnsSwapNeuronBasketConstructionParameters {
80    /// Number of neurons created in each participant basket.
81    pub count: u64,
82    /// Dissolve-delay interval between neurons in a basket, in seconds.
83    pub dissolve_delay_interval_seconds: u64,
84}
85
86///
87/// SnsSwapSaleParameters
88///
89/// Native decentralization-sale parameters returned by the swap canister.
90///
91
92#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
93pub struct SnsSwapSaleParameters {
94    /// Minimum legacy total ICP target in e8s.
95    pub min_icp_e8s: u64,
96    /// Maximum legacy total ICP target in e8s.
97    pub max_icp_e8s: u64,
98    /// Minimum direct participation target in ICP e8s, when returned.
99    pub min_direct_participation_icp_e8s: Option<u64>,
100    /// Maximum direct participation target in ICP e8s, when returned.
101    pub max_direct_participation_icp_e8s: Option<u64>,
102    /// SNS tokens offered by the sale in e8s.
103    pub sns_token_e8s: u64,
104    /// Minimum number of direct participants.
105    pub min_participants: u32,
106    /// Minimum ICP contribution per participant in e8s.
107    pub min_participant_icp_e8s: u64,
108    /// Maximum ICP contribution per participant in e8s.
109    pub max_participant_icp_e8s: u64,
110    /// Scheduled swap deadline in Unix seconds.
111    pub swap_due_timestamp_seconds: u64,
112    /// Optional delay before the sale opens, in seconds.
113    pub sale_delay_seconds: Option<u64>,
114    /// Neuron-basket construction parameters, when configured.
115    pub neuron_basket_construction_parameters: Option<SnsSwapNeuronBasketConstructionParameters>,
116}
117
118///
119/// SnsSwapDerivedState
120///
121/// Native aggregate participation values returned by the swap canister.
122///
123
124#[derive(Clone, Debug, PartialEq, Serialize)]
125pub struct SnsSwapDerivedState {
126    /// Derived SNS-token amount per ICP, when returned.
127    pub sns_tokens_per_icp: Option<f64>,
128    /// Total buyer ICP in e8s, when returned.
129    pub buyer_total_icp_e8s: Option<u64>,
130    /// Direct-participation ICP in e8s, when returned.
131    pub direct_participation_icp_e8s: Option<u64>,
132    /// Neurons' Fund participation ICP in e8s, when returned.
133    pub neurons_fund_participation_icp_e8s: Option<u64>,
134    /// Number of direct participants, when returned.
135    pub direct_participant_count: Option<u64>,
136    /// Number of Community Fund participants, when returned by older swap state.
137    pub cf_participant_count: Option<u64>,
138    /// Number of Community Fund neurons, when returned by older swap state.
139    pub cf_neuron_count: Option<u64>,
140}
141
142///
143/// SnsSwapReport
144///
145/// Bounded live report for one resolved SNS decentralization swap.
146///
147
148#[derive(Clone, Debug, PartialEq, Serialize)]
149pub struct SnsSwapReport {
150    /// Report schema version.
151    pub schema_version: u32,
152    /// Requested IC network identity.
153    pub network: String,
154    /// Mainnet SNS-W canister used to resolve the SNS.
155    pub sns_wasm_canister_id: String,
156    /// Collection timestamp in UTC.
157    pub fetched_at: String,
158    /// IC API endpoint used for SNS-W and swap calls.
159    pub source_endpoint: String,
160    /// Collector identity recorded by the source request.
161    pub fetched_by: String,
162    /// SNS-W list id assigned to this deployed SNS.
163    pub id: usize,
164    /// SNS name resolved during discovery.
165    pub name: String,
166    /// Root canister identity used to resolve this SNS.
167    pub root_canister_id: String,
168    /// Swap canister queried for lifecycle and sale state.
169    pub swap_canister_id: String,
170    /// Native method used for lifecycle state.
171    pub lifecycle_method: String,
172    /// Native method used for sale parameters.
173    pub sale_parameters_method: String,
174    /// Native method used for derived participation state.
175    pub derived_state_method: String,
176    /// Whether all component values represent one authoritative point in time.
177    pub point_in_time_guaranteed: bool,
178    /// Fixed number of bounded swap component queries attempted.
179    pub component_query_count: usize,
180    /// Number of component queries that returned successfully.
181    pub successful_component_query_count: usize,
182    /// Number of typed component query gaps.
183    pub component_gap_count: usize,
184    /// Lifecycle response, absent only when its query failed.
185    pub lifecycle: Option<SnsSwapLifecycle>,
186    /// Sale parameters; `None` can also be a successful response with no configured parameters.
187    pub sale_parameters: Option<SnsSwapSaleParameters>,
188    /// Derived-state response, absent only when its query failed.
189    pub derived_state: Option<SnsSwapDerivedState>,
190    /// Canonically ordered component query failures.
191    pub gaps: Vec<SnsSwapQueryGap>,
192}