use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use solana_program::{decode_error::DecodeError, program_error::{ProgramError, PrintProgramError}, msg};
use thiserror::Error;
#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
pub enum PortfolioError {
#[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("Input amount is invalid")]
InvalidAmount,
#[error("Invalid type account")]
InvalidTypeAccount,
#[error("Error while create user portfolio")]
ErrorWhileCreatePPU,
#[error("Exceeded numbre of splu")]
MaximumSPLUAdded,
#[error("Exceeded numbre of admins")]
MaximumADMINAdded,
#[error("Missing admin authorization")]
MissingAdminAuthorization,
#[error("Error while adding new asset to portfolio")]
ErrorWhileAddingNewAssetToPortfolio,
#[error("Error while adding new splu to user portfolio")]
ErrorWhileAddingNewSpluToUserPortfolio,
#[error("Maximum number of ppu was attended")]
MaximumNumberOfPPUWasAttended,
#[error("Error invalid state of user portfolio account")]
InvalidStateOfPPU,
#[error("Error invalid state of portfolio account")]
InvalidStateOfPPM,
#[error("Error while updating data account")]
ErrorWhileUpdatingDataAccount,
#[error("Error while executing an external transaction")]
ErrorFromExternalTransaction,
}
impl From<PortfolioError> for ProgramError {
fn from(e: PortfolioError) -> Self {
ProgramError::Custom(e as u32)
}
}
impl<T> DecodeError<T> for PortfolioError {
fn type_of() -> &'static str {
"PortfolioError"
}
}
impl PrintProgramError for PortfolioError {
fn print<E>(&self)
where
E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
{
match self {
PortfolioError::NotRentExempt => {
msg!("Error: Lamport balance below rent-exempt threshold")
}
PortfolioError::InsufficientFunds => msg!("Error: insufficient funds"),
PortfolioError::InvalidMint => msg!("Error: Invalid Mint"),
PortfolioError::MintMismatch => msg!("Error: Account not associated with this Mint"),
PortfolioError::OwnerMismatch => msg!("Error: owner does not match"),
PortfolioError::FixedSupply => msg!("Error: the total supply of this token is fixed"),
PortfolioError::AlreadyInUse => msg!("Error: account or token already in use"),
PortfolioError::InvalidNumberOfProvidedSigners => {
msg!("Error: Invalid number of provided signers")
}
PortfolioError::InvalidNumberOfRequiredSigners => {
msg!("Error: Invalid number of required signers")
}
PortfolioError::UninitializedState => msg!("Error: State is uninitialized"),
PortfolioError::NativeNotSupported => {
msg!("Error: Instruction does not support native tokens")
}
PortfolioError::NonNativeHasBalance => {
msg!("Error: Non-native account can only be closed if its balance is zero")
}
PortfolioError::InvalidInstruction => msg!("Error: Invalid instruction"),
PortfolioError::InvalidState => msg!("Error: Invalid account state for operation"),
PortfolioError::Overflow => msg!("Error: Operation overflowed"),
PortfolioError::AuthorityTypeNotSupported => {
msg!("Error: Account does not support specified authority type")
}
PortfolioError::MintCannotFreeze => {
msg!("Error: This token mint cannot freeze accounts")
}
PortfolioError::AccountFrozen => msg!("Error: Account is frozen"),
PortfolioError::MintDecimalsMismatch => {
msg!("Error: decimals different from the Mint decimals")
}
PortfolioError::InvalidAmount => {
msg!("Error: invalid amount ")
}
PortfolioError::InvalidTypeAccount => {
msg!("Error: Invalid type account ")
}
PortfolioError::ErrorWhileCreatePPU => {
msg!("Error: Error while create user portfolio ")
}
PortfolioError::MaximumSPLUAdded => {
msg!("Error: Maximum number of splu attended ")
}
PortfolioError::MaximumADMINAdded => {
msg!("Error: Maximum number of admins attended ")
}
PortfolioError::MissingAdminAuthorization => {
msg!("Error: Missing admin authorization ")
}
PortfolioError::ErrorWhileAddingNewAssetToPortfolio => {
msg!("Error: Error while adding new asset to portfolio ")
}
PortfolioError::ErrorWhileAddingNewSpluToUserPortfolio => {
msg!("Error: Error while adding new splu to user portfolio ")
}
PortfolioError::MaximumNumberOfPPUWasAttended => {
msg!("Error: Maximum number of ppu was attended ")
}
PortfolioError:: InvalidStateOfPPU => {
msg!("Error invalid state of user portfolio account")
}
PortfolioError:: InvalidStateOfPPM => {
msg!("Error invalid state of portfolio account")
}
PortfolioError:: ErrorWhileUpdatingDataAccount => {
msg!("Error Error while updating data account")
}
PortfolioError:: ErrorFromExternalTransaction => {
msg!("Error while executing an external transaction")
}
}
}
}