Skip to main content

miden_standards/account/faucets/
mod.rs

1use alloc::string::String;
2
3use miden_protocol::account::StorageSlotName;
4use miden_protocol::errors::{AccountError, TokenSymbolError};
5use thiserror::Error;
6
7use crate::account::access::Ownable2StepError;
8use crate::utils::FixedWidthStringError;
9
10mod fungible;
11mod token_metadata;
12
13pub use fungible::{FungibleFaucet, FungibleFaucetBuilder, create_fungible_faucet};
14pub use token_metadata::{Description, ExternalLink, LogoURI, TokenMetadata, TokenName};
15
16// TOKEN METADATA ERROR
17// ================================================================================================
18
19/// Errors raised when parsing token metadata from storage.
20#[derive(Debug, Error)]
21pub enum TokenMetadataError {
22    #[error("failed to retrieve storage slot with name {slot_name}")]
23    StorageLookupFailed {
24        slot_name: StorageSlotName,
25        source: AccountError,
26    },
27    #[error("invalid string data in field '{field}'")]
28    InvalidStringField {
29        field: &'static str,
30        #[source]
31        source: FixedWidthStringError,
32    },
33    #[error("mutability flag at index {index} has invalid value {value}: must be 0 or 1")]
34    InvalidMutabilityFlag { index: usize, value: u64 },
35    #[error("storage slot name mismatch: expected {expected}, got {actual}")]
36    SlotNameMismatch {
37        expected: StorageSlotName,
38        actual: StorageSlotName,
39    },
40    #[error("invalid token symbol")]
41    InvalidTokenSymbol(#[source] TokenSymbolError),
42}
43
44// FUNGIBLE FAUCET ERROR
45// ================================================================================================
46
47/// Basic fungible faucet related errors.
48#[derive(Debug, Error)]
49pub enum FungibleFaucetError {
50    #[error("faucet metadata decimals is {actual} which exceeds max value of {max}")]
51    TooManyDecimals { actual: u64, max: u8 },
52    #[error("faucet metadata max supply is {actual} which exceeds max value of {max}")]
53    MaxSupplyTooLarge { actual: u64, max: u64 },
54    #[error("token supply {token_supply} exceeds max_supply {max_supply}")]
55    TokenSupplyExceedsMaxSupply { token_supply: u64, max_supply: u64 },
56    #[error(
57        "account interface does not have the procedures of the basic fungible faucet component"
58    )]
59    MissingFungibleFaucetInterface,
60    #[error("unsupported authentication method: {0}")]
61    UnsupportedAuthMethod(String),
62    #[error("AccessControl::AuthControlled is incompatible with the chosen auth method: {0}")]
63    IncompatibleAuthControlledAuth(String),
64    #[error("unsupported combination of AccessControl and AuthMethod: {0}")]
65    UnsupportedAccessControlAuthCombination(String),
66    #[error("account creation failed")]
67    AccountError(#[source] AccountError),
68    #[error("account is not a fungible faucet account")]
69    NotAFungibleFaucetAccount,
70    #[error("failed to read ownership data from storage")]
71    OwnershipError(#[source] Ownable2StepError),
72    #[error(transparent)]
73    TokenMetadata(#[from] TokenMetadataError),
74}