Skip to main content

ic_query/system/cmc/
model.rs

1//! Module: system::cmc::model
2//!
3//! Responsibility: define stable CMC report and certified-rate models.
4//! Does not own: live transport, certificate verification, CLI parsing, or text output.
5//! Boundary: preserves the native CMC permyriad rate and explicit evidence provenance.
6
7#[cfg(feature = "cmc-host")]
8use ic_platform::candid::contract::CandidType;
9use serde::{Deserialize, Serialize};
10
11///
12/// CmcReportContext
13///
14/// Provenance shared by direct Cycle Minting Canister reports.
15///
16
17#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
18pub struct CmcReportContext {
19    /// Report schema version.
20    pub schema_version: u32,
21    /// Queried network identity.
22    pub network: String,
23    /// Cycle Minting Canister principal.
24    pub cmc_canister_id: String,
25    /// UTC collection timestamp.
26    pub fetched_at: String,
27    /// Replica endpoint used for the query.
28    pub source_endpoint: String,
29    /// Collector identity.
30    pub fetched_by: String,
31}
32
33///
34/// CmcIcpXdrConversionRate
35///
36/// Native CMC ICP/XDR conversion-rate value committed by certified data.
37///
38
39#[cfg_attr(feature = "cmc-host", derive(CandidType))]
40#[cfg_attr(feature = "cmc-host", candid_path("ic_platform::candid::contract"))]
41#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
42pub struct CmcIcpXdrConversionRate {
43    /// Unix timestamp for the market data represented by this rate.
44    pub timestamp_seconds: u64,
45    /// Number of ten-thousandths of XDR corresponding to one ICP.
46    pub xdr_permyriad_per_icp: u64,
47}
48
49///
50/// CmcCertification
51///
52/// Authenticated application-level certificate and hash-tree evidence for a CMC rate.
53///
54
55#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
56pub struct CmcCertification {
57    /// Whether the built-in source authenticated the certificate and rate witness.
58    pub certificate_verified: bool,
59    /// CBOR system certificate encoded as lowercase hexadecimal.
60    pub certificate_hex: String,
61    /// Raw certificate length in bytes.
62    pub certificate_bytes: usize,
63    /// CBOR witness hash tree encoded as lowercase hexadecimal.
64    pub hash_tree_hex: String,
65    /// Raw witness hash-tree length in bytes.
66    pub hash_tree_bytes: usize,
67}
68
69///
70/// CmcXdrReport
71///
72/// Certified point-in-time CMC ICP/XDR conversion-rate report.
73///
74
75#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
76pub struct CmcXdrReport {
77    /// Query and authority provenance.
78    #[serde(flatten)]
79    pub context: CmcReportContext,
80    /// Raw CMC conversion-rate value.
81    pub rate: CmcIcpXdrConversionRate,
82    /// Authenticated certificate and witness evidence.
83    pub certification: CmcCertification,
84}
85
86///
87/// CmcCyclesReport
88///
89/// Cycles conversion derived from a certified CMC rate and the IC protocol constant.
90///
91
92#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
93pub struct CmcCyclesReport {
94    /// Complete certified rate and provenance used by the derivation.
95    #[serde(flatten)]
96    pub xdr: CmcXdrReport,
97    /// IC protocol constant for the number of cycles corresponding to one XDR.
98    pub cycles_per_xdr: u128,
99    /// Authority label for `cycles_per_xdr`, distinct from the certified CMC rate.
100    pub cycles_per_xdr_source: String,
101    /// Number of cycles corresponding to one ICP at the certified rate.
102    pub cycles_per_icp: u128,
103    /// Exact formula used to derive `cycles_per_icp`.
104    pub cycles_per_icp_formula: String,
105}
106
107///
108/// CmcCertifiedRate
109///
110/// Source result accepted after the CMC certificate and rate witness are validated.
111///
112
113#[cfg(feature = "cmc-host")]
114#[derive(Clone, Debug, Eq, PartialEq)]
115pub struct CmcCertifiedRate {
116    /// Native certified CMC rate.
117    pub rate: CmcIcpXdrConversionRate,
118    /// Authenticated certificate and hash-tree evidence.
119    pub certification: CmcCertification,
120}