solana_extra_wasm/program/spl_token_2022/
error.rs

1//! Error types
2
3use {
4    num_derive::FromPrimitive,
5    solana_sdk::{decode_error::DecodeError, program_error::ProgramError},
6    thiserror::Error,
7};
8
9/// Errors that may be returned by the Token program.
10#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
11pub enum TokenError {
12    // 0
13    /// Lamport balance below rent-exempt threshold.
14    #[error("Lamport balance below rent-exempt threshold")]
15    NotRentExempt,
16    /// Insufficient funds for the operation requested.
17    #[error("Insufficient funds")]
18    InsufficientFunds,
19    /// Invalid Mint.
20    #[error("Invalid Mint")]
21    InvalidMint,
22    /// Account not associated with this Mint.
23    #[error("Account not associated with this Mint")]
24    MintMismatch,
25    /// Owner does not match.
26    #[error("Owner does not match")]
27    OwnerMismatch,
28
29    // 5
30    /// This token's supply is fixed and new tokens cannot be minted.
31    #[error("Fixed supply")]
32    FixedSupply,
33    /// The account cannot be initialized because it is already being used.
34    #[error("Already in use")]
35    AlreadyInUse,
36    /// Invalid number of provided signers.
37    #[error("Invalid number of provided signers")]
38    InvalidNumberOfProvidedSigners,
39    /// Invalid number of required signers.
40    #[error("Invalid number of required signers")]
41    InvalidNumberOfRequiredSigners,
42    /// State is uninitialized.
43    #[error("State is unititialized")]
44    UninitializedState,
45
46    // 10
47    /// Instruction does not support native tokens
48    #[error("Instruction does not support native tokens")]
49    NativeNotSupported,
50    /// Non-native account can only be closed if its balance is zero
51    #[error("Non-native account can only be closed if its balance is zero")]
52    NonNativeHasBalance,
53    /// Invalid instruction
54    #[error("Invalid instruction")]
55    InvalidInstruction,
56    /// State is invalid for requested operation.
57    #[error("State is invalid for requested operation")]
58    InvalidState,
59    /// Operation overflowed
60    #[error("Operation overflowed")]
61    Overflow,
62
63    // 15
64    /// Account does not support specified authority type.
65    #[error("Account does not support specified authority type")]
66    AuthorityTypeNotSupported,
67    /// This token mint cannot freeze accounts.
68    #[error("This token mint cannot freeze accounts")]
69    MintCannotFreeze,
70    /// Account is frozen; all account operations will fail
71    #[error("Account is frozen")]
72    AccountFrozen,
73    /// Mint decimals mismatch between the client and mint
74    #[error("The provided decimals value different from the Mint decimals")]
75    MintDecimalsMismatch,
76    /// Instruction does not support non-native tokens
77    #[error("Instruction does not support non-native tokens")]
78    NonNativeNotSupported,
79
80    // 20
81    /// Extension type does not match already existing extensions
82    #[error("Extension type does not match already existing extensions")]
83    ExtensionTypeMismatch,
84    /// Extension does not match the base type provided
85    #[error("Extension does not match the base type provided")]
86    ExtensionBaseMismatch,
87    /// Extension already initialized on this account
88    #[error("Extension already initialized on this account")]
89    ExtensionAlreadyInitialized,
90    /// An account can only be closed if its confidential balance is zero
91    #[error("An account can only be closed if its confidential balance is zero")]
92    ConfidentialTransferAccountHasBalance,
93    /// Account not approved for confidential transfers
94    #[error("Account not approved for confidential transfers")]
95    ConfidentialTransferAccountNotApproved,
96
97    // 25
98    /// Account not accepting deposits or transfers
99    #[error("Account not accepting deposits or transfers")]
100    ConfidentialTransferDepositsAndTransfersDisabled,
101    /// ElGamal public key mismatch
102    #[error("ElGamal public key mismatch")]
103    ConfidentialTransferElGamalPubkeyMismatch,
104    /// Balance mismatch
105    #[error("Balance mismatch")]
106    ConfidentialTransferBalanceMismatch,
107    /// Mint has non-zero supply. Burn all tokens before closing the mint.
108    #[error("Mint has non-zero supply. Burn all tokens before closing the mint")]
109    MintHasSupply,
110    /// No authority exists to perform the desired operation
111    #[error("No authority exists to perform the desired operation")]
112    NoAuthorityExists,
113
114    // 30
115    /// Transfer fee exceeds maximum of 10,000 basis points
116    #[error("Transfer fee exceeds maximum of 10,000 basis points")]
117    TransferFeeExceedsMaximum,
118    /// Mint required for this account to transfer tokens, use `transfer_checked` or `transfer_checked_with_fee`
119    #[error("Mint required for this account to transfer tokens, use `transfer_checked` or `transfer_checked_with_fee`")]
120    MintRequiredForTransfer,
121    /// Calculated fee does not match expected fee
122    #[error("Calculated fee does not match expected fee")]
123    FeeMismatch,
124    /// Fee parameters associated with confidential transfer zero-knowledge proofs do not match fee parameters in mint
125    #[error(
126        "Fee parameters associated with zero-knowledge proofs do not match fee parameters in mint"
127    )]
128    FeeParametersMismatch,
129    /// The owner authority cannot be changed
130    #[error("The owner authority cannot be changed")]
131    ImmutableOwner,
132
133    // 35
134    /// An account can only be closed if its withheld fee balance is zero, harvest fees to the
135    /// mint and try again
136    #[error("An account can only be closed if its withheld fee balance is zero, harvest fees to the mint and try again")]
137    AccountHasWithheldTransferFees,
138
139    /// No memo in previous instruction; required for recipient to receive a transfer
140    #[error("No memo in previous instruction; required for recipient to receive a transfer")]
141    NoMemo,
142    /// Transfer is disabled for this mint
143    #[error("Transfer is disabled for this mint")]
144    NonTransferable,
145    /// Non-transferable tokens can't be minted to an account without immutable ownership
146    #[error("Non-transferable tokens can't be minted to an account without immutable ownership")]
147    NonTransferableNeedsImmutableOwnership,
148    /// The total number of `Deposit` and `Transfer` instructions to an account cannot exceed the
149    /// associated `maximum_pending_balance_credit_counter`
150    #[error(
151        "The total number of `Deposit` and `Transfer` instructions to an account cannot exceed
152            the associated `maximum_pending_balance_credit_counter`"
153    )]
154    MaximumPendingBalanceCreditCounterExceeded,
155}
156impl From<TokenError> for ProgramError {
157    fn from(e: TokenError) -> Self {
158        ProgramError::Custom(e as u32)
159    }
160}
161impl<T> DecodeError<T> for TokenError {
162    fn type_of() -> &'static str {
163        "TokenError"
164    }
165}