spl_binary_oracle_pair/
error.rs1use num_derive::FromPrimitive;
4use num_traits::FromPrimitive;
5use solana_program::{
6 decode_error::DecodeError, msg, program_error::PrintProgramError, program_error::ProgramError,
7};
8use thiserror::Error;
9
10#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
12pub enum PoolError {
13 #[error("Pool account already in use")]
15 AlreadyInUse,
16 #[error("Deposit account already in use")]
18 DepositAccountInUse,
19 #[error("Token account already in use")]
21 TokenMintInUse,
22 #[error("Failed to generate program account because of invalid data")]
24 InvalidAuthorityData,
25 #[error("Invalid authority account provided")]
27 InvalidAuthorityAccount,
28 #[error("Lamport balance below rent-exempt threshold")]
30 NotRentExempt,
31 #[error("Input token mint account is not valid")]
33 InvalidTokenMint,
34 #[error("Amount should be more than zero")]
36 InvalidAmount,
37 #[error("Wrong decider account was sent")]
39 WrongDeciderAccount,
40 #[error("Signature missing in transaction")]
42 SignatureMissing,
43 #[error("Decision was already made for this pool")]
45 DecisionAlreadyMade,
46 #[error("Decision can't be made in current slot")]
48 InvalidSlotForDecision,
49 #[error("Deposit can't be made in current slot")]
51 InvalidSlotForDeposit,
52 #[error("No decision has been made yet")]
54 NoDecisionMadeYet,
55}
56
57impl From<PoolError> for ProgramError {
58 fn from(e: PoolError) -> Self {
59 ProgramError::Custom(e as u32)
60 }
61}
62
63impl<T> DecodeError<T> for PoolError {
64 fn type_of() -> &'static str {
65 "Binary Oracle Pair Error"
66 }
67}
68
69impl PrintProgramError for PoolError {
70 fn print<E>(&self)
71 where
72 E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
73 {
74 match self {
75 PoolError::AlreadyInUse => msg!("Error: Pool account already in use"),
76 PoolError::DepositAccountInUse => msg!("Error: Deposit account already in use"),
77 PoolError::TokenMintInUse => msg!("Error: Token account already in use"),
78 PoolError::InvalidAuthorityData => {
79 msg!("Error: Failed to generate program account because of invalid data")
80 }
81 PoolError::InvalidAuthorityAccount => msg!("Error: Invalid authority account provided"),
82 PoolError::NotRentExempt => msg!("Error: Lamport balance below rent-exempt threshold"),
83 PoolError::InvalidTokenMint => msg!("Error: Input token mint account is not valid"),
84 PoolError::InvalidAmount => msg!("Error: Amount should be more than zero"),
85 PoolError::WrongDeciderAccount => msg!("Error: Wrong decider account was sent"),
86 PoolError::SignatureMissing => msg!("Error: Signature missing in transaction"),
87 PoolError::DecisionAlreadyMade => {
88 msg!("Error: Decision was already made for this pool")
89 }
90 PoolError::InvalidSlotForDecision => {
91 msg!("Error: Decision can't be made in current slot")
92 }
93 PoolError::InvalidSlotForDeposit => msg!("Deposit can't be made in current slot"),
94 PoolError::NoDecisionMadeYet => msg!("Error: No decision has been made yet"),
95 }
96 }
97}