1use num_derive::FromPrimitive;
4use gemachain_program::{decode_error::DecodeError, program_error::ProgramError};
5use thiserror::Error;
6
7#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
9pub enum TokenError {
10 #[error("Carat balance below rent-exempt threshold")]
13 NotRentExempt,
14 #[error("Insufficient funds")]
16 InsufficientFunds,
17 #[error("Invalid Mint")]
19 InvalidMint,
20 #[error("Account not associated with this Mint")]
22 MintMismatch,
23 #[error("Owner does not match")]
25 OwnerMismatch,
26
27 #[error("Fixed supply")]
30 FixedSupply,
31 #[error("Already in use")]
33 AlreadyInUse,
34 #[error("Invalid number of provided signers")]
36 InvalidNumberOfProvidedSigners,
37 #[error("Invalid number of required signers")]
39 InvalidNumberOfRequiredSigners,
40 #[error("State is unititialized")]
42 UninitializedState,
43
44 #[error("Instruction does not support native tokens")]
47 NativeNotSupported,
48 #[error("Non-native account can only be closed if its balance is zero")]
50 NonNativeHasBalance,
51 #[error("Invalid instruction")]
53 InvalidInstruction,
54 #[error("State is invalid for requested operation")]
56 InvalidState,
57 #[error("Operation overflowed")]
59 Overflow,
60
61 #[error("Account does not support specified authority type")]
64 AuthorityTypeNotSupported,
65 #[error("This token mint cannot freeze accounts")]
67 MintCannotFreeze,
68 #[error("Account is frozen")]
70 AccountFrozen,
71 #[error("The provided decimals value different from the Mint decimals")]
73 MintDecimalsMismatch,
74 #[error("Instruction does not support non-native tokens")]
76 NonNativeNotSupported,
77}
78impl From<TokenError> for ProgramError {
79 fn from(e: TokenError) -> Self {
80 ProgramError::Custom(e as u32)
81 }
82}
83impl<T> DecodeError<T> for TokenError {
84 fn type_of() -> &'static str {
85 "TokenError"
86 }
87}