1use num_derive::FromPrimitive;
4use num_traits::FromPrimitive;
5use solana_program::{decode_error::DecodeError, program_error::ProgramError};
6use solana_program::{msg, program_error::PrintProgramError};
7use thiserror::Error;
8
9#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
11pub enum LendingError {
12 #[error("Failed to unpack instruction data")]
15 InstructionUnpackError,
16 #[error("Account is already initialized")]
18 AlreadyInitialized,
19 #[error("Lamport balance below rent-exempt threshold")]
21 NotRentExempt,
22 #[error("Market authority is invalid")]
24 InvalidMarketAuthority,
25 #[error("Market owner is invalid")]
27 InvalidMarketOwner,
28
29 #[error("Input account owner is not the program address")]
32 InvalidAccountOwner,
33 #[error("Input token account is not owned by the correct token program id")]
35 InvalidTokenOwner,
36 #[error("Input token account is not valid")]
38 InvalidTokenAccount,
39 #[error("Input token mint account is not valid")]
41 InvalidTokenMint,
42 #[error("Input token program account is not valid")]
44 InvalidTokenProgram,
45
46 #[error("Input amount is invalid")]
49 InvalidAmount,
50 #[error("Input config value is invalid")]
52 InvalidConfig,
53 #[error("Input account must be a signer")]
55 InvalidSigner,
56 #[error("Invalid account input")]
58 InvalidAccountInput,
59 #[error("Math operation overflow")]
61 MathOverflow,
62
63 #[error("Token initialize mint failed")]
66 TokenInitializeMintFailed,
67 #[error("Token initialize account failed")]
69 TokenInitializeAccountFailed,
70 #[error("Token transfer failed")]
72 TokenTransferFailed,
73 #[error("Token mint to failed")]
75 TokenMintToFailed,
76 #[error("Token burn failed")]
78 TokenBurnFailed,
79
80 #[error("Insufficient liquidity available")]
83 InsufficientLiquidity,
84 #[error("Input reserve has collateral disabled")]
86 ReserveCollateralDisabled,
87 #[error("Reserve state needs to be refreshed")]
89 ReserveStale,
90 #[error("Withdraw amount too small")]
92 WithdrawTooSmall,
93 #[error("Withdraw amount too large")]
95 WithdrawTooLarge,
96
97 #[error("Borrow amount too small to receive liquidity after fees")]
100 BorrowTooSmall,
101 #[error("Borrow amount too large for deposited collateral")]
103 BorrowTooLarge,
104 #[error("Repay amount too small to transfer liquidity")]
106 RepayTooSmall,
107 #[error("Liquidation amount too small to receive collateral")]
109 LiquidationTooSmall,
110 #[error("Cannot liquidate healthy obligations")]
112 ObligationHealthy,
113
114 #[error("Obligation state needs to be refreshed")]
117 ObligationStale,
118 #[error("Obligation reserve limit exceeded")]
120 ObligationReserveLimit,
121 #[error("Obligation owner is invalid")]
123 InvalidObligationOwner,
124 #[error("Obligation deposits are empty")]
126 ObligationDepositsEmpty,
127 #[error("Obligation borrows are empty")]
129 ObligationBorrowsEmpty,
130
131 #[error("Obligation deposits have zero value")]
134 ObligationDepositsZero,
135 #[error("Obligation borrows have zero value")]
137 ObligationBorrowsZero,
138 #[error("Invalid obligation collateral")]
140 InvalidObligationCollateral,
141 #[error("Invalid obligation liquidity")]
143 InvalidObligationLiquidity,
144 #[error("Obligation collateral is empty")]
146 ObligationCollateralEmpty,
147
148 #[error("Obligation liquidity is empty")]
151 ObligationLiquidityEmpty,
152 #[error("Interest rate is negative")]
154 NegativeInterestRate,
155 #[error("Input oracle config is invalid")]
157 InvalidOracleConfig,
158 #[error("Input flash loan receiver program account is not valid")]
160 InvalidFlashLoanReceiverProgram,
161 #[error("Not enough liquidity after flash loan")]
163 NotEnoughLiquidityAfterFlashLoan,
164
165 #[error("Null oracle config")]
168 NullOracleConfig,
169 #[error("Insufficent protocol fees to claim or no liquidity availible")]
171 InsufficientProtocolFeesToRedeem,
172 #[error("No cpi flash borrows allowed")]
174 FlashBorrowCpi,
175 #[error("No corresponding repay found for flash borrow")]
177 NoFlashRepayFound,
178 #[error("Invalid repay found")]
180 InvalidFlashRepay,
181
182 #[error("No cpi flash repays allowed")]
185 FlashRepayCpi,
186 #[error("Multiple flash borrows not allowed in the same transaction")]
188 MultipleFlashBorrows,
189 #[error("Flash loans are disabled for this reserve")]
191 FlashLoansDisabled,
192 #[error("Instruction is deprecated")]
194 DeprecatedInstruction,
195}
196
197impl From<LendingError> for ProgramError {
198 fn from(e: LendingError) -> Self {
199 ProgramError::Custom(e as u32)
200 }
201}
202
203impl<T> DecodeError<T> for LendingError {
204 fn type_of() -> &'static str {
205 "Lending Error"
206 }
207}
208
209impl PrintProgramError for LendingError {
210 fn print<E>(&self)
211 where
212 E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
213 {
214 msg!(&self.to_string());
215 }
216}