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