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 = "host")]
8use candid::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 = "host", derive(CandidType))]
40#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
41pub struct CmcIcpXdrConversionRate {
42 /// Unix timestamp for the market data represented by this rate.
43 pub timestamp_seconds: u64,
44 /// Number of ten-thousandths of XDR corresponding to one ICP.
45 pub xdr_permyriad_per_icp: u64,
46}
47
48///
49/// CmcCertification
50///
51/// Authenticated application-level certificate and hash-tree evidence for a CMC rate.
52///
53
54#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
55pub struct CmcCertification {
56 /// Whether the built-in source authenticated the certificate and rate witness.
57 pub certificate_verified: bool,
58 /// CBOR system certificate encoded as lowercase hexadecimal.
59 pub certificate_hex: String,
60 /// Raw certificate length in bytes.
61 pub certificate_bytes: usize,
62 /// CBOR witness hash tree encoded as lowercase hexadecimal.
63 pub hash_tree_hex: String,
64 /// Raw witness hash-tree length in bytes.
65 pub hash_tree_bytes: usize,
66}
67
68///
69/// CmcXdrReport
70///
71/// Certified point-in-time CMC ICP/XDR conversion-rate report.
72///
73
74#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
75pub struct CmcXdrReport {
76 /// Query and authority provenance.
77 #[serde(flatten)]
78 pub context: CmcReportContext,
79 /// Raw CMC conversion-rate value.
80 pub rate: CmcIcpXdrConversionRate,
81 /// Authenticated certificate and witness evidence.
82 pub certification: CmcCertification,
83}
84
85///
86/// CmcCyclesReport
87///
88/// Cycles conversion derived from a certified CMC rate and the IC protocol constant.
89///
90
91#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
92pub struct CmcCyclesReport {
93 /// Query and authority provenance.
94 #[serde(flatten)]
95 pub context: CmcReportContext,
96 /// Raw CMC conversion-rate value used by the derivation.
97 pub rate: CmcIcpXdrConversionRate,
98 /// IC protocol constant for the number of cycles corresponding to one XDR.
99 pub cycles_per_xdr: u128,
100 /// Authority label for `cycles_per_xdr`, distinct from the certified CMC rate.
101 pub cycles_per_xdr_source: String,
102 /// Number of cycles corresponding to one ICP at the certified rate.
103 pub cycles_per_icp: u128,
104 /// Exact formula used to derive `cycles_per_icp`.
105 pub cycles_per_icp_formula: String,
106 /// Authenticated certificate and witness evidence for `rate`.
107 pub certification: CmcCertification,
108}
109
110///
111/// CmcCertifiedRate
112///
113/// Source result accepted after the CMC certificate and rate witness are validated.
114///
115
116#[cfg(feature = "host")]
117#[derive(Clone, Debug, Eq, PartialEq)]
118pub struct CmcCertifiedRate {
119 /// Native certified CMC rate.
120 pub rate: CmcIcpXdrConversionRate,
121 /// Authenticated certificate and hash-tree evidence.
122 pub certification: CmcCertification,
123}