use super::invocation::SnsCanisterMethod;
use serde::Serialize;
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct MainnetSnsSwap {
pub swap_canister_id: String,
pub lifecycle_method: SnsCanisterMethod,
pub sale_parameters_method: SnsCanisterMethod,
pub derived_state_method: SnsCanisterMethod,
pub point_in_time_guaranteed: bool,
pub lifecycle: Option<SnsSwapLifecycle>,
pub sale_parameters: Option<SnsSwapSaleParameters>,
pub derived_state: Option<SnsSwapDerivedState>,
pub gaps: Vec<SnsSwapQueryGap>,
}
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum SnsSwapComponent {
Lifecycle,
SaleParameters,
DerivedState,
}
impl SnsSwapComponent {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Lifecycle => "lifecycle",
Self::SaleParameters => "sale_parameters",
Self::DerivedState => "derived_state",
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct SnsSwapQueryGap {
pub component: SnsSwapComponent,
pub method: SnsCanisterMethod,
pub reason: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct SnsSwapLifecycle {
pub lifecycle: Option<i32>,
pub decentralization_sale_open_timestamp_seconds: Option<u64>,
pub decentralization_swap_termination_timestamp_seconds: Option<u64>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct SnsSwapNeuronBasketConstructionParameters {
pub count: u64,
pub dissolve_delay_interval_seconds: u64,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct SnsSwapSaleParameters {
pub min_icp_e8s: u64,
pub max_icp_e8s: u64,
pub min_direct_participation_icp_e8s: Option<u64>,
pub max_direct_participation_icp_e8s: Option<u64>,
pub sns_token_e8s: u64,
pub min_participants: u32,
pub min_participant_icp_e8s: u64,
pub max_participant_icp_e8s: u64,
pub swap_due_timestamp_seconds: u64,
pub sale_delay_seconds: Option<u64>,
pub neuron_basket_construction_parameters: Option<SnsSwapNeuronBasketConstructionParameters>,
}
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct SnsSwapDerivedState {
pub sns_tokens_per_icp: Option<f64>,
pub buyer_total_icp_e8s: Option<u64>,
pub direct_participation_icp_e8s: Option<u64>,
pub neurons_fund_participation_icp_e8s: Option<u64>,
pub direct_participant_count: Option<u64>,
pub cf_participant_count: Option<u64>,
pub cf_neuron_count: Option<u64>,
}
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct SnsSwapReport {
pub schema_version: u32,
pub network: String,
pub sns_wasm_canister_id: String,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub id: usize,
pub name: String,
pub root_canister_id: String,
pub component_query_count: usize,
pub successful_component_query_count: usize,
pub component_gap_count: usize,
#[serde(flatten)]
pub swap: MainnetSnsSwap,
}
pub(in crate::sns::report) const fn sns_swap_lifecycle_name(
lifecycle: Option<i32>,
) -> Option<&'static str> {
match lifecycle {
None => None,
Some(0) => Some("unspecified"),
Some(1) => Some("pending"),
Some(2) => Some("open"),
Some(3) => Some("committed"),
Some(4) => Some("aborted"),
Some(5) => Some("adopted"),
Some(_) => Some("unknown"),
}
}
#[cfg(test)]
mod tests {
use super::sns_swap_lifecycle_name;
#[test]
fn lifecycle_names_preserve_native_codes_and_unknown_values() {
for (code, expected) in [
(None, None),
(Some(0), Some("unspecified")),
(Some(1), Some("pending")),
(Some(2), Some("open")),
(Some(3), Some("committed")),
(Some(4), Some("aborted")),
(Some(5), Some("adopted")),
(Some(99), Some("unknown")),
] {
assert_eq!(sns_swap_lifecycle_name(code), expected);
}
}
}