use {
num_derive::FromPrimitive,
safecoin_program::{decode_error::DecodeError, program_error::ProgramError},
thiserror::Error,
};
#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
pub enum TokenError {
#[error("Lamport balance below rent-exempt threshold")]
NotRentExempt,
#[error("Insufficient funds")]
InsufficientFunds,
#[error("Invalid Mint")]
InvalidMint,
#[error("Account not associated with this Mint")]
MintMismatch,
#[error("Owner does not match")]
OwnerMismatch,
#[error("Fixed supply")]
FixedSupply,
#[error("Already in use")]
AlreadyInUse,
#[error("Invalid number of provided signers")]
InvalidNumberOfProvidedSigners,
#[error("Invalid number of required signers")]
InvalidNumberOfRequiredSigners,
#[error("State is unititialized")]
UninitializedState,
#[error("Instruction does not support native tokens")]
NativeNotSupported,
#[error("Non-native account can only be closed if its balance is zero")]
NonNativeHasBalance,
#[error("Invalid instruction")]
InvalidInstruction,
#[error("State is invalid for requested operation")]
InvalidState,
#[error("Operation overflowed")]
Overflow,
#[error("Account does not support specified authority type")]
AuthorityTypeNotSupported,
#[error("This token mint cannot freeze accounts")]
MintCannotFreeze,
#[error("Account is frozen")]
AccountFrozen,
#[error("The provided decimals value different from the Mint decimals")]
MintDecimalsMismatch,
#[error("Instruction does not support non-native tokens")]
NonNativeNotSupported,
#[error("Extension type does not match already existing extensions")]
ExtensionTypeMismatch,
#[error("Extension does not match the base type provided")]
ExtensionBaseMismatch,
#[error("Extension already initialized on this account")]
ExtensionAlreadyInitialized,
#[error("An account can only be closed if its confidential balance is zero")]
ConfidentialTransferAccountHasBalance,
#[error("Account not approved for confidential transfers")]
ConfidentialTransferAccountNotApproved,
#[error("Account not accepting deposits or transfers")]
ConfidentialTransferDepositsAndTransfersDisabled,
#[error("ElGamal public key mismatch")]
ConfidentialTransferElGamalPubkeyMismatch,
#[error("Balance mismatch")]
ConfidentialTransferBalanceMismatch,
#[error("Mint has non-zero supply. Burn all tokens before closing the mint")]
MintHasSupply,
#[error("No authority exists to perform the desired operation")]
NoAuthorityExists,
#[error("Transfer fee exceeds maximum of 10,000 basis points")]
TransferFeeExceedsMaximum,
#[error("Mint required for this account to transfer tokens, use `transfer_checked` or `transfer_checked_with_fee`")]
MintRequiredForTransfer,
#[error("Calculated fee does not match expected fee")]
FeeMismatch,
#[error(
"Fee parameters associated with zero-knowledge proofs do not match fee parameters in mint"
)]
FeeParametersMismatch,
#[error("The owner authority cannot be changed")]
ImmutableOwner,
#[error("An account can only be closed if its withheld fee balance is zero, harvest fees to the mint and try again")]
AccountHasWithheldTransferFees,
#[error("No memo in previous instruction; required for recipient to receive a transfer")]
NoMemo,
}
impl From<TokenError> for ProgramError {
fn from(e: TokenError) -> Self {
ProgramError::Custom(e as u32)
}
}
impl<T> DecodeError<T> for TokenError {
fn type_of() -> &'static str {
"TokenError"
}
}