solend_sdk/
error.rs

1//! Error types
2
3use 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/// Errors that may be returned by the TokenLending program.
10#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
11pub enum LendingError {
12    // 0
13    /// Invalid instruction data passed in.
14    #[error("Failed to unpack instruction data")]
15    InstructionUnpackError,
16    /// The account cannot be initialized because it is already in use.
17    #[error("Account is already initialized")]
18    AlreadyInitialized,
19    /// Lamport balance below rent-exempt threshold.
20    #[error("Lamport balance below rent-exempt threshold")]
21    NotRentExempt,
22    /// The program address provided doesn't match the value generated by the program.
23    #[error("Market authority is invalid")]
24    InvalidMarketAuthority,
25    /// Expected a different market owner
26    #[error("Market owner is invalid")]
27    InvalidMarketOwner,
28
29    // 5
30    /// The owner of the input isn't set to the program address generated by the program.
31    #[error("Input account owner is not the program address")]
32    InvalidAccountOwner,
33    /// The owner of the account input isn't set to the correct token program id.
34    #[error("Input token account is not owned by the correct token program id")]
35    InvalidTokenOwner,
36    /// Expected an SPL Token account
37    #[error("Input token account is not valid")]
38    InvalidTokenAccount,
39    /// Expected an SPL Token mint
40    #[error("Input token mint account is not valid")]
41    InvalidTokenMint,
42    /// Expected a different SPL Token program
43    #[error("Input token program account is not valid")]
44    InvalidTokenProgram,
45
46    // 10
47    /// Invalid amount, must be greater than zero
48    #[error("Input amount is invalid")]
49    InvalidAmount,
50    /// Invalid config value
51    #[error("Input config value is invalid")]
52    InvalidConfig,
53    /// Invalid config value
54    #[error("Input account must be a signer")]
55    InvalidSigner,
56    /// Invalid account input
57    #[error("Invalid account input")]
58    InvalidAccountInput,
59    /// Math operation overflow
60    #[error("Math operation overflow")]
61    MathOverflow,
62
63    // 15
64    /// Token initialize mint failed
65    #[error("Token initialize mint failed")]
66    TokenInitializeMintFailed,
67    /// Token initialize account failed
68    #[error("Token initialize account failed")]
69    TokenInitializeAccountFailed,
70    /// Token transfer failed
71    #[error("Token transfer failed")]
72    TokenTransferFailed,
73    /// Token mint to failed
74    #[error("Token mint to failed")]
75    TokenMintToFailed,
76    /// Token burn failed
77    #[error("Token burn failed")]
78    TokenBurnFailed,
79
80    // 20
81    /// Insufficient liquidity available
82    #[error("Insufficient liquidity available")]
83    InsufficientLiquidity,
84    /// This reserve's collateral cannot be used for borrows
85    #[error("Input reserve has collateral disabled")]
86    ReserveCollateralDisabled,
87    /// Reserve state stale
88    #[error("Reserve state needs to be refreshed")]
89    ReserveStale,
90    /// Withdraw amount too small
91    #[error("Withdraw amount too small")]
92    WithdrawTooSmall,
93    /// Withdraw amount too large
94    #[error("Withdraw amount too large")]
95    WithdrawTooLarge,
96
97    // 25
98    /// Borrow amount too small
99    #[error("Borrow amount too small to receive liquidity after fees")]
100    BorrowTooSmall,
101    /// Borrow amount too large
102    #[error("Borrow amount too large for deposited collateral")]
103    BorrowTooLarge,
104    /// Repay amount too small
105    #[error("Repay amount too small to transfer liquidity")]
106    RepayTooSmall,
107    /// Liquidation amount too small
108    #[error("Liquidation amount too small to receive collateral")]
109    LiquidationTooSmall,
110    /// Cannot liquidate healthy obligations
111    #[error("Cannot liquidate healthy obligations")]
112    ObligationHealthy,
113
114    // 30
115    /// Obligation state stale
116    #[error("Obligation state needs to be refreshed")]
117    ObligationStale,
118    /// Obligation reserve limit exceeded
119    #[error("Obligation reserve limit exceeded")]
120    ObligationReserveLimit,
121    /// Expected a different obligation owner
122    #[error("Obligation owner is invalid")]
123    InvalidObligationOwner,
124    /// Obligation deposits are empty
125    #[error("Obligation deposits are empty")]
126    ObligationDepositsEmpty,
127    /// Obligation borrows are empty
128    #[error("Obligation borrows are empty")]
129    ObligationBorrowsEmpty,
130
131    // 35
132    /// Obligation deposits have zero value
133    #[error("Obligation deposits have zero value")]
134    ObligationDepositsZero,
135    /// Obligation borrows have zero value
136    #[error("Obligation borrows have zero value")]
137    ObligationBorrowsZero,
138    /// Invalid obligation collateral
139    #[error("Invalid obligation collateral")]
140    InvalidObligationCollateral,
141    /// Invalid obligation liquidity
142    #[error("Invalid obligation liquidity")]
143    InvalidObligationLiquidity,
144    /// Obligation collateral is empty
145    #[error("Obligation collateral is empty")]
146    ObligationCollateralEmpty,
147
148    // 40
149    /// Obligation liquidity is empty
150    #[error("Obligation liquidity is empty")]
151    ObligationLiquidityEmpty,
152    /// Negative interest rate
153    #[error("Interest rate is negative")]
154    NegativeInterestRate,
155    /// Oracle config is invalid
156    #[error("Input oracle config is invalid")]
157    InvalidOracleConfig,
158    /// Expected a different flash loan receiver program
159    #[error("Input flash loan receiver program account is not valid")]
160    InvalidFlashLoanReceiverProgram,
161    /// Not enough liquidity after flash loan
162    #[error("Not enough liquidity after flash loan")]
163    NotEnoughLiquidityAfterFlashLoan,
164
165    // 45
166    /// Null oracle config
167    #[error("Null oracle config")]
168    NullOracleConfig,
169    /// Insufficent protocol fees to redeem or no liquidity availible to process redeem
170    #[error("Insufficent protocol fees to claim or no liquidity availible")]
171    InsufficientProtocolFeesToRedeem,
172    /// No cpi flash borrows allowed
173    #[error("No cpi flash borrows allowed")]
174    FlashBorrowCpi,
175    /// No corresponding repay found for flash borrow
176    #[error("No corresponding repay found for flash borrow")]
177    NoFlashRepayFound,
178    /// Invalid flash repay found for borrow
179    #[error("Invalid repay found")]
180    InvalidFlashRepay,
181
182    // 50
183    /// No cpi flash repays allowed
184    #[error("No cpi flash repays allowed")]
185    FlashRepayCpi,
186    /// Multiple flash borrows not allowed in the same transaction
187    #[error("Multiple flash borrows not allowed in the same transaction")]
188    MultipleFlashBorrows,
189    /// Flash loans are disabled for this reserve
190    #[error("Flash loans are disabled for this reserve")]
191    FlashLoansDisabled,
192    /// Deprecated instruction
193    #[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}