miden_usdcx/account/xreserve/builder/
error.rs1use core::fmt;
7
8use miden_protocol::errors::{AccountError, StorageMapError};
9use miden_standards::account::auth::NetworkAccountNoteAllowlistError;
10use miden_standards::account::faucets::FungibleFaucetError;
11use miden_standards::account::policies::{BurnPolicyError, MintPolicyError};
12use miden_tx::NotePricingError;
13
14use super::{
15 ATTESTATION_MINT_POLICY_PROC_PATH,
16 MIN_BURN_SIZE_FLOOR,
17 XRESERVE_BURN_POLICY_PROC_PATH,
18};
19
20#[derive(Debug)]
22pub enum XReserveStablecoinBuilderError {
23 FaucetComposition(FungibleFaucetError),
28 NetworkAuth(NetworkAccountNoteAllowlistError),
32 AccountComposition(AccountError),
36 FeePricing(NotePricingError),
38 AttestationPolicyProcNotFound,
41 BurnPolicyProcNotFound,
43 MinBurnSizeBelowFloor(u64),
49 BlocklistManagerNotIsolated { collides_with: &'static str },
54 PauserNotIsolated { collides_with: &'static str },
58 DuplicateRoleMember { role: &'static str },
60 AttesterAllowlist(StorageMapError),
62 MintPolicy(MintPolicyError),
65 BurnPolicy(BurnPolicyError),
68}
69
70impl fmt::Display for XReserveStablecoinBuilderError {
71 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72 match self {
73 Self::FaucetComposition(_) => {
74 write!(f, "the fixed-identity USDCx faucet could not be constructed")
75 },
76 Self::NetworkAuth(_) => {
77 write!(f, "the production network-account auth component could not be assembled")
78 },
79 Self::AccountComposition(_) => {
80 write!(f, "the composed faucet account could not be built")
81 },
82 Self::FeePricing(_) => write!(f, "the xUSDC fee schedule could not be priced"),
83 Self::AttestationPolicyProcNotFound => write!(
84 f,
85 "the xreserve component does not export the attestation mint policy procedure \
86 '{ATTESTATION_MINT_POLICY_PROC_PATH}'"
87 ),
88 Self::BurnPolicyProcNotFound => write!(
89 f,
90 "the burn-policy component does not export the burn policy procedure \
91 '{XRESERVE_BURN_POLICY_PROC_PATH}'"
92 ),
93 Self::MinBurnSizeBelowFloor(value) => write!(
94 f,
95 "min_burn_amount {value} is below the construction floor \
96 {MIN_BURN_SIZE_FLOOR}"
97 ),
98 Self::BlocklistManagerNotIsolated { collides_with } => write!(
99 f,
100 "a BLK_MANAGER holder (transfer-blocklist administrator) must be an external entity \
101 with no other faucet-admin capability, but one collides with the {collides_with} — \
102 F4-reversal two-way capability isolation is violated"
103 ),
104 Self::PauserNotIsolated { collides_with } => write!(
105 f,
106 "a DOM_PAUSER holder must hold no other role, but one collides with {collides_with}"
107 ),
108 Self::DuplicateRoleMember { role } => {
109 write!(f, "the {role} role lists the same member twice")
110 },
111 Self::AttesterAllowlist(_) => {
112 write!(f, "the build-seeded attester allowlist lists a key twice")
113 },
114 Self::MintPolicy(_) => write!(f, "mint policy descriptor construction failed"),
115 Self::BurnPolicy(_) => write!(f, "burn policy descriptor construction failed"),
116 }
117 }
118}
119
120impl core::error::Error for XReserveStablecoinBuilderError {
121 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
122 match self {
123 Self::MintPolicy(source) => Some(source),
124 Self::BurnPolicy(source) => Some(source),
125 Self::FaucetComposition(source) => Some(source),
126 Self::NetworkAuth(source) => Some(source),
127 Self::AccountComposition(source) => Some(source),
128 Self::FeePricing(source) => Some(source),
129 Self::AttesterAllowlist(source) => Some(source),
130 _ => None,
131 }
132 }
133}
134
135impl From<MintPolicyError> for XReserveStablecoinBuilderError {
136 fn from(source: MintPolicyError) -> Self {
137 Self::MintPolicy(source)
138 }
139}
140
141impl From<BurnPolicyError> for XReserveStablecoinBuilderError {
142 fn from(source: BurnPolicyError) -> Self {
143 Self::BurnPolicy(source)
144 }
145}
146
147impl From<NetworkAccountNoteAllowlistError> for XReserveStablecoinBuilderError {
148 fn from(source: NetworkAccountNoteAllowlistError) -> Self {
149 Self::NetworkAuth(source)
150 }
151}
152
153impl From<NotePricingError> for XReserveStablecoinBuilderError {
154 fn from(source: NotePricingError) -> Self {
155 Self::FeePricing(source)
156 }
157}