1use {
4 solana_program::{
5 decode_error::DecodeError,
6 msg,
7 program_error::{PrintProgramError, ProgramError},
8 },
9 thiserror::Error,
10};
11
12#[derive(Clone, Debug, Eq, Error, num_derive::FromPrimitive, PartialEq)]
14pub enum SinglePoolError {
15 #[error("InvalidPoolAccount")]
19 InvalidPoolAccount,
20 #[error("InvalidPoolStakeAccount")]
23 InvalidPoolStakeAccount,
24 #[error("InvalidPoolMint")]
26 InvalidPoolMint,
27 #[error("InvalidPoolStakeAuthority")]
30 InvalidPoolStakeAuthority,
31 #[error("InvalidPoolMintAuthority")]
34 InvalidPoolMintAuthority,
35
36 #[error("InvalidPoolMplAuthority")]
40 InvalidPoolMplAuthority,
41 #[error("InvalidMetadataAccount")]
44 InvalidMetadataAccount,
45 #[error("InvalidMetadataSigner")]
48 InvalidMetadataSigner,
49 #[error("DepositTooSmall")]
51 DepositTooSmall,
52 #[error("WithdrawalTooSmall")]
54 WithdrawalTooSmall,
55
56 #[error("WithdrawalTooLarge")]
61 WithdrawalTooLarge,
62 #[error("SignatureMissing")]
64 SignatureMissing,
65 #[error("WrongStakeStake")]
67 WrongStakeStake,
68 #[error("ArithmeticOverflow")]
70 ArithmeticOverflow,
71 #[error("UnexpectedMathError")]
75 UnexpectedMathError,
76
77 #[error("LegacyVoteAccount")]
81 LegacyVoteAccount,
82 #[error("UnparseableVoteAccount")]
84 UnparseableVoteAccount,
85 #[error("WrongRentAmount")]
88 WrongRentAmount,
89 #[error("InvalidPoolStakeAccountUsage")]
91 InvalidPoolStakeAccountUsage,
92 #[error("PoolAlreadyInitialized")]
94 PoolAlreadyInitialized,
95}
96impl From<SinglePoolError> for ProgramError {
97 fn from(e: SinglePoolError) -> Self {
98 ProgramError::Custom(e as u32)
99 }
100}
101impl<T> DecodeError<T> for SinglePoolError {
102 fn type_of() -> &'static str {
103 "Single-Validator Stake Pool Error"
104 }
105}
106impl PrintProgramError for SinglePoolError {
107 fn print<E>(&self)
108 where
109 E: 'static
110 + std::error::Error
111 + DecodeError<E>
112 + PrintProgramError
113 + num_traits::FromPrimitive,
114 {
115 match self {
116 SinglePoolError::InvalidPoolAccount =>
117 msg!("Error: Provided pool account has the wrong address for its vote account, is uninitialized, \
118 or is otherwise invalid."),
119 SinglePoolError::InvalidPoolStakeAccount =>
120 msg!("Error: Provided pool stake account does not match address derived from the pool account."),
121 SinglePoolError::InvalidPoolMint =>
122 msg!("Error: Provided pool mint does not match address derived from the pool account."),
123 SinglePoolError::InvalidPoolStakeAuthority =>
124 msg!("Error: Provided pool stake authority does not match address derived from the pool account."),
125 SinglePoolError::InvalidPoolMintAuthority =>
126 msg!("Error: Provided pool mint authority does not match address derived from the pool account."),
127 SinglePoolError::InvalidPoolMplAuthority =>
128 msg!("Error: Provided pool MPL authority does not match address derived from the pool account."),
129 SinglePoolError::InvalidMetadataAccount =>
130 msg!("Error: Provided metadata account does not match metadata account derived for pool mint."),
131 SinglePoolError::InvalidMetadataSigner =>
132 msg!("Error: Authorized withdrawer provided for metadata update does not match the vote account."),
133 SinglePoolError::DepositTooSmall =>
134 msg!("Error: Not enough lamports provided for deposit to result in one pool token."),
135 SinglePoolError::WithdrawalTooSmall =>
136 msg!("Error: Not enough pool tokens provided to withdraw stake worth one lamport."),
137 SinglePoolError::WithdrawalTooLarge =>
138 msg!("Error: Not enough stake to cover the provided quantity of pool tokens. \
139 (Generally this should not happen absent user error, but may if the minimum delegation increases.)"),
140 SinglePoolError::SignatureMissing => msg!("Error: Required signature is missing."),
141 SinglePoolError::WrongStakeStake => msg!("Error: Stake account is not in the state expected by the program."),
142 SinglePoolError::ArithmeticOverflow => msg!("Error: Unsigned subtraction crossed the zero."),
143 SinglePoolError::UnexpectedMathError =>
144 msg!("Error: A calculation failed unexpectedly. \
145 (This error should never be surfaced; it stands in for failure conditions that should never be reached.)"),
146 SinglePoolError::UnparseableVoteAccount => msg!("Error: Failed to parse vote account."),
147 SinglePoolError::LegacyVoteAccount =>
148 msg!("Error: The V0_23_5 vote account type is unsupported and should be upgraded via `convert_to_current()`."),
149 SinglePoolError::WrongRentAmount =>
150 msg!("Error: Incorrect number of lamports provided for rent-exemption when initializing."),
151 SinglePoolError::InvalidPoolStakeAccountUsage =>
152 msg!("Error: Attempted to deposit from or withdraw to pool stake account."),
153 SinglePoolError::PoolAlreadyInitialized =>
154 msg!("Error: Attempted to initialize a pool that is already initialized."),
155 }
156 }
157}