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
96 #[error("InvalidPoolOnRampAccount")]
100 InvalidPoolOnRampAccount,
101 #[error("OnRampDoesntExist")]
104 OnRampDoesntExist,
105}
106impl From<SinglePoolError> for ProgramError {
107 fn from(e: SinglePoolError) -> Self {
108 ProgramError::Custom(e as u32)
109 }
110}
111impl<T> DecodeError<T> for SinglePoolError {
112 fn type_of() -> &'static str {
113 "Single-Validator Stake Pool Error"
114 }
115}
116impl PrintProgramError for SinglePoolError {
117 fn print<E>(&self)
118 where
119 E: 'static
120 + std::error::Error
121 + DecodeError<E>
122 + PrintProgramError
123 + num_traits::FromPrimitive,
124 {
125 match self {
126 SinglePoolError::InvalidPoolAccount =>
127 msg!("Error: Provided pool account has the wrong address for its vote account, is uninitialized, \
128 or is otherwise invalid."),
129 SinglePoolError::InvalidPoolStakeAccount =>
130 msg!("Error: Provided pool stake account does not match address derived from the pool account."),
131 SinglePoolError::InvalidPoolMint =>
132 msg!("Error: Provided pool mint does not match address derived from the pool account."),
133 SinglePoolError::InvalidPoolStakeAuthority =>
134 msg!("Error: Provided pool stake authority does not match address derived from the pool account."),
135 SinglePoolError::InvalidPoolMintAuthority =>
136 msg!("Error: Provided pool mint authority does not match address derived from the pool account."),
137 SinglePoolError::InvalidPoolMplAuthority =>
138 msg!("Error: Provided pool MPL authority does not match address derived from the pool account."),
139 SinglePoolError::InvalidMetadataAccount =>
140 msg!("Error: Provided metadata account does not match metadata account derived for pool mint."),
141 SinglePoolError::InvalidMetadataSigner =>
142 msg!("Error: Authorized withdrawer provided for metadata update does not match the vote account."),
143 SinglePoolError::DepositTooSmall =>
144 msg!("Error: Not enough lamports provided for deposit to result in one pool token."),
145 SinglePoolError::WithdrawalTooSmall =>
146 msg!("Error: Not enough pool tokens provided to withdraw stake worth one lamport."),
147 SinglePoolError::WithdrawalTooLarge =>
148 msg!("Error: Not enough stake to cover the provided quantity of pool tokens. \
149 (Generally this should not happen absent user error, but may if the minimum delegation increases \
150 beyond 1 sol.)"),
151 SinglePoolError::SignatureMissing => msg!("Error: Required signature is missing."),
152 SinglePoolError::WrongStakeStake => msg!("Error: Stake account is not in the state expected by the program."),
153 SinglePoolError::ArithmeticOverflow => msg!("Error: Unsigned subtraction crossed the zero."),
154 SinglePoolError::UnexpectedMathError =>
155 msg!("Error: A calculation failed unexpectedly. \
156 (This error should never be surfaced; it stands in for failure conditions that should never be reached.)"),
157 SinglePoolError::UnparseableVoteAccount => msg!("Error: Failed to parse vote account."),
158 SinglePoolError::LegacyVoteAccount =>
159 msg!("Error: The V0_23_5 vote account type is unsupported and should be upgraded via `convert_to_current()`."),
160 SinglePoolError::WrongRentAmount =>
161 msg!("Error: Incorrect number of lamports provided for rent-exemption when initializing."),
162 SinglePoolError::InvalidPoolStakeAccountUsage =>
163 msg!("Error: Attempted to deposit from or withdraw to pool stake account."),
164 SinglePoolError::PoolAlreadyInitialized =>
165 msg!("Error: Attempted to initialize a pool that is already initialized."),
166 SinglePoolError::InvalidPoolOnRampAccount =>
167 msg!("Error: Provided pool onramp account does not match address derived from the pool account."),
168 SinglePoolError::OnRampDoesntExist =>
169 msg!("The onramp account for this pool does not exist; you must call `InitializePoolOnRamp` \
170 before you can perform this operation."),
171 }
172 }
173}