spl_token_lending/
error.rs

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