1use num_derive::FromPrimitive;
4use num_traits::FromPrimitive;
5use solana_program::{decode_error::DecodeError, program_error::{ProgramError, PrintProgramError}, msg};
6use thiserror::Error;
7
8#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
10pub enum PortfolioError {
11 #[error("Lamport 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 #[error("Fixed supply")]
28 FixedSupply,
29 #[error("Already in use")]
31 AlreadyInUse,
32 #[error("Invalid number of provided signers")]
34 InvalidNumberOfProvidedSigners,
35 #[error("Invalid number of required signers")]
37 InvalidNumberOfRequiredSigners,
38 #[error("State is unititialized")]
40 UninitializedState,
41 #[error("Instruction does not support native tokens")]
43 NativeNotSupported,
44 #[error("Non-native account can only be closed if its balance is zero")]
46 NonNativeHasBalance,
47 #[error("Invalid instruction")]
49 InvalidInstruction,
50 #[error("State is invalid for requested operation")]
52 InvalidState,
53 #[error("Operation overflowed")]
55 Overflow,
56 #[error("Account does not support specified authority type")]
58 AuthorityTypeNotSupported,
59 #[error("This token mint cannot freeze accounts")]
61 MintCannotFreeze,
62 #[error("Account is frozen")]
64 AccountFrozen,
65 #[error("The provided decimals value different from the Mint decimals")]
67 MintDecimalsMismatch,
68 #[error("Input amount is invalid")]
70 InvalidAmount,
71 #[error("Invalid type account")]
73 InvalidTypeAccount,
74 #[error("Error while create user portfolio")]
76 ErrorWhileCreatePPU,
77 #[error("Exceeded numbre of splu")]
79 MaximumSPLUAdded,
80 #[error("Exceeded numbre of admins")]
82 MaximumADMINAdded,
83 #[error("Missing admin authorization")]
85 MissingAdminAuthorization,
86 #[error("Error while adding new asset to portfolio")]
88 ErrorWhileAddingNewAssetToPortfolio,
89 #[error("Error while adding new splu to user portfolio")]
91 ErrorWhileAddingNewSpluToUserPortfolio,
92 #[error("Maximum number of ppu was attended")]
94 MaximumNumberOfPPUWasAttended,
95 #[error("Error invalid state of user portfolio account")]
97 InvalidStateOfPPU,
98 #[error("Error invalid state of portfolio account")]
100 InvalidStateOfPPM,
101 #[error("Error while updating data account")]
103 ErrorWhileUpdatingDataAccount,
104 #[error("Error while executing an external transaction")]
106 ErrorFromExternalTransaction,
107
108}
109impl From<PortfolioError> for ProgramError {
110 fn from(e: PortfolioError) -> Self {
111 ProgramError::Custom(e as u32)
112 }
113}
114impl<T> DecodeError<T> for PortfolioError {
115 fn type_of() -> &'static str {
116 "PortfolioError"
117 }
118}
119
120
121
122impl PrintProgramError for PortfolioError {
123 fn print<E>(&self)
124 where
125 E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
126 {
127 match self {
128 PortfolioError::NotRentExempt => {
129 msg!("Error: Lamport balance below rent-exempt threshold")
130 }
131 PortfolioError::InsufficientFunds => msg!("Error: insufficient funds"),
132 PortfolioError::InvalidMint => msg!("Error: Invalid Mint"),
133 PortfolioError::MintMismatch => msg!("Error: Account not associated with this Mint"),
134 PortfolioError::OwnerMismatch => msg!("Error: owner does not match"),
135 PortfolioError::FixedSupply => msg!("Error: the total supply of this token is fixed"),
136 PortfolioError::AlreadyInUse => msg!("Error: account or token already in use"),
137 PortfolioError::InvalidNumberOfProvidedSigners => {
138 msg!("Error: Invalid number of provided signers")
139 }
140 PortfolioError::InvalidNumberOfRequiredSigners => {
141 msg!("Error: Invalid number of required signers")
142 }
143 PortfolioError::UninitializedState => msg!("Error: State is uninitialized"),
144 PortfolioError::NativeNotSupported => {
145 msg!("Error: Instruction does not support native tokens")
146 }
147 PortfolioError::NonNativeHasBalance => {
148 msg!("Error: Non-native account can only be closed if its balance is zero")
149 }
150 PortfolioError::InvalidInstruction => msg!("Error: Invalid instruction"),
151 PortfolioError::InvalidState => msg!("Error: Invalid account state for operation"),
152 PortfolioError::Overflow => msg!("Error: Operation overflowed"),
153 PortfolioError::AuthorityTypeNotSupported => {
154 msg!("Error: Account does not support specified authority type")
155 }
156 PortfolioError::MintCannotFreeze => {
157 msg!("Error: This token mint cannot freeze accounts")
158 }
159 PortfolioError::AccountFrozen => msg!("Error: Account is frozen"),
160 PortfolioError::MintDecimalsMismatch => {
161 msg!("Error: decimals different from the Mint decimals")
162 }
163 PortfolioError::InvalidAmount => {
164 msg!("Error: invalid amount ")
165 }
166 PortfolioError::InvalidTypeAccount => {
167 msg!("Error: Invalid type account ")
168 }
169 PortfolioError::ErrorWhileCreatePPU => {
170 msg!("Error: Error while create user portfolio ")
171 }
172
173 PortfolioError::MaximumSPLUAdded => {
174 msg!("Error: Maximum number of splu attended ")
175 }
176 PortfolioError::MaximumADMINAdded => {
177 msg!("Error: Maximum number of admins attended ")
178 }
179 PortfolioError::MissingAdminAuthorization => {
180 msg!("Error: Missing admin authorization ")
181 }
182 PortfolioError::ErrorWhileAddingNewAssetToPortfolio => {
183 msg!("Error: Error while adding new asset to portfolio ")
184 }
185 PortfolioError::ErrorWhileAddingNewSpluToUserPortfolio => {
186 msg!("Error: Error while adding new splu to user portfolio ")
187 }
188 PortfolioError::MaximumNumberOfPPUWasAttended => {
189 msg!("Error: Maximum number of ppu was attended ")
190 }
191 PortfolioError:: InvalidStateOfPPU => {
192 msg!("Error invalid state of user portfolio account")
193 }
194 PortfolioError:: InvalidStateOfPPM => {
195 msg!("Error invalid state of portfolio account")
196 }
197 PortfolioError:: ErrorWhileUpdatingDataAccount => {
198 msg!("Error Error while updating data account")
199 }
200 PortfolioError:: ErrorFromExternalTransaction => {
201 msg!("Error while executing an external transaction")
202 }
203
204 }
205 }
206}