use anchor_lang::prelude::*;
use anchor_lang::solana_program::{decode_error::DecodeError, program_error::ProgramError};
#[error_code]
pub enum LendingError {
#[msg("Failed to unpack instruction data")]
InstructionUnpackError,
#[msg("Account is already initialized")]
AlreadyInitialized,
#[msg("Lamport balance below rent-exempt threshold")]
NotRentExempt,
#[msg("Market authority is invalid")]
InvalidMarketAuthority,
#[msg("Market owner is invalid")]
InvalidMarketOwner,
#[msg("Input account owner is not the program address")]
InvalidAccountOwner,
#[msg("Input token account is not owned by the correct token program id")]
InvalidTokenOwner,
#[msg("Input token account is not valid")]
InvalidTokenAccount,
#[msg("Input token mint account is not valid")]
InvalidTokenMint,
#[msg("Input token program account is not valid")]
InvalidTokenProgram,
#[msg("Input amount is invalid")]
InvalidAmount,
#[msg("Input config value is invalid")]
InvalidConfig,
#[msg("Input account must be a signer")]
InvalidSigner,
#[msg("Invalid account input")]
InvalidAccountInput,
#[msg("Math operation overflow")]
MathOverflow,
#[msg("Token initialize mint failed")]
TokenInitializeMintFailed,
#[msg("Token initialize account failed")]
TokenInitializeAccountFailed,
#[msg("Token transfer failed")]
TokenTransferFailed,
#[msg("Token mint to failed")]
TokenMintToFailed,
#[msg("Token burn failed")]
TokenBurnFailed,
#[msg("Insufficient liquidity available")]
InsufficientLiquidity,
#[msg("Input reserve has collateral disabled")]
ReserveCollateralDisabled,
#[msg("Reserve state needs to be refreshed")]
ReserveStale,
#[msg("Withdraw amount too small")]
WithdrawTooSmall,
#[msg("Withdraw amount too large")]
WithdrawTooLarge,
#[msg("Borrow amount too small to receive liquidity after fees")]
BorrowTooSmall,
#[msg("Borrow amount too large for deposited collateral")]
BorrowTooLarge,
#[msg("Repay amount too small to transfer liquidity")]
RepayTooSmall,
#[msg("Liquidation amount too small to receive collateral")]
LiquidationTooSmall,
#[msg("Cannot liquidate healthy obligations")]
ObligationHealthy,
#[msg("Obligation state needs to be refreshed")]
ObligationStale,
#[msg("Obligation reserve limit exceeded")]
ObligationReserveLimit,
#[msg("Obligation owner is invalid")]
InvalidObligationOwner,
#[msg("Obligation deposits are empty")]
ObligationDepositsEmpty,
#[msg("Obligation borrows are empty")]
ObligationBorrowsEmpty,
#[msg("Obligation deposits have zero value")]
ObligationDepositsZero,
#[msg("Obligation borrows have zero value")]
ObligationBorrowsZero,
#[msg("Invalid obligation collateral")]
InvalidObligationCollateral,
#[msg("Invalid obligation liquidity")]
InvalidObligationLiquidity,
#[msg("Obligation collateral is empty")]
ObligationCollateralEmpty,
#[msg("Obligation liquidity is empty")]
ObligationLiquidityEmpty,
#[msg("Interest rate is negative")]
NegativeInterestRate,
#[msg("Input oracle config is invalid")]
InvalidOracleConfig,
#[msg("Not enough liquidity after flash loan")]
NotEnoughLiquidityAfterFlashLoan,
#[msg("405 method not allowed")]
MethodNotAllowed,
#[msg("Invalid update pseudo deposit operation")]
InvalidUpdatePseudoDepositOperation,
#[msg("Unauthorized borrow signer")]
UnauthorizedBorrowAuthorizer,
#[msg("Invalid Pyth Price Account")]
InvalidPythPriceAccount,
}
impl From<LendingError> for ProgramError {
fn from(e: LendingError) -> Self {
ProgramError::Custom(e as u32)
}
}
impl<T> DecodeError<T> for LendingError {
fn type_of() -> &'static str {
"Lending Error"
}
}