1use {
4 solana_program_error::{ProgramError, ToStr},
5 thiserror::Error,
6};
7
8#[derive(
10 Clone, Debug, Eq, Error, num_enum::TryFromPrimitive, num_derive::FromPrimitive, PartialEq,
11)]
12#[repr(u32)]
13pub enum SinglePoolError {
14 #[error("InvalidPoolAccount")]
18 InvalidPoolAccount,
19 #[error("InvalidPoolStakeAccount")]
22 InvalidPoolStakeAccount,
23 #[error("InvalidPoolMint")]
25 InvalidPoolMint,
26 #[error("InvalidPoolStakeAuthority")]
29 InvalidPoolStakeAuthority,
30 #[error("InvalidPoolMintAuthority")]
33 InvalidPoolMintAuthority,
34
35 #[error("InvalidPoolMplAuthority")]
39 InvalidPoolMplAuthority,
40 #[error("InvalidMetadataAccount")]
43 InvalidMetadataAccount,
44 #[error("InvalidMetadataSigner")]
47 InvalidMetadataSigner,
48 #[error("DepositTooSmall")]
50 DepositTooSmall,
51 #[error("WithdrawalTooSmall")]
53 WithdrawalTooSmall,
54
55 #[error("WithdrawalTooLarge")]
61 WithdrawalTooLarge,
62 #[error("SignatureMissing")]
64 SignatureMissing,
65 #[error("WrongStakeState")]
67 WrongStakeState,
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 #[error("ReplenishRequired")]
108 ReplenishRequired,
109 #[error("WithdrawalViolatesPoolRequirements")]
112 WithdrawalViolatesPoolRequirements,
113 #[error("InvalidDepositSolSource")]
115 InvalidDepositSolSource,
116}
117impl From<SinglePoolError> for ProgramError {
118 fn from(e: SinglePoolError) -> Self {
119 ProgramError::Custom(e as u32)
120 }
121}
122impl ToStr for SinglePoolError {
123 fn to_str(&self) -> &'static str {
124 match self {
125 SinglePoolError::InvalidPoolAccount =>
126 "Error: Provided pool account has the wrong address for its vote account, is uninitialized, \
127 or is otherwise invalid.",
128 SinglePoolError::InvalidPoolStakeAccount =>
129 "Error: Provided pool stake account does not match address derived from the pool account.",
130 SinglePoolError::InvalidPoolMint =>
131 "Error: Provided pool mint does not match address derived from the pool account.",
132 SinglePoolError::InvalidPoolStakeAuthority =>
133 "Error: Provided pool stake authority does not match address derived from the pool account.",
134 SinglePoolError::InvalidPoolMintAuthority =>
135 "Error: Provided pool mint authority does not match address derived from the pool account.",
136 SinglePoolError::InvalidPoolMplAuthority =>
137 "Error: Provided pool MPL authority does not match address derived from the pool account.",
138 SinglePoolError::InvalidMetadataAccount =>
139 "Error: Provided metadata account does not match metadata account derived for pool mint.",
140 SinglePoolError::InvalidMetadataSigner =>
141 "Error: Authorized withdrawer provided for metadata update does not match the vote account.",
142 SinglePoolError::DepositTooSmall =>
143 "Error: Not enough lamports provided for deposit to result in one pool token.",
144 SinglePoolError::WithdrawalTooSmall =>
145 "Error: Not enough pool tokens provided to withdraw stake worth one lamport.",
146 SinglePoolError::WithdrawalTooLarge =>
147 "Error: Not enough stake to cover the provided quantity of pool tokens. \
148 This typically means the value exists in the pool as activating stake, \
149 and an epoch is required for it to become available. Otherwise, it means \
150 active stake in the onramp must be moved via `ReplenishPool`.",
151 SinglePoolError::SignatureMissing => "Error: Required signature is missing.",
152 SinglePoolError::WrongStakeState => "Error: Stake account is not in the state expected by the program.",
153 SinglePoolError::ArithmeticOverflow => "Error: Unsigned subtraction crossed the zero.",
154 SinglePoolError::UnexpectedMathError =>
155 "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 => "Error: Failed to parse vote account.",
158 SinglePoolError::LegacyVoteAccount =>
159 "Error: The V0_23_5 vote account type is unsupported and should be upgraded via `convert_to_current()`.",
160 SinglePoolError::WrongRentAmount =>
161 "Error: Incorrect number of lamports provided for rent-exemption when initializing.",
162 SinglePoolError::InvalidPoolStakeAccountUsage =>
163 "Error: Attempted to deposit from or withdraw to pool stake account.",
164 SinglePoolError::PoolAlreadyInitialized =>
165 "Error: Attempted to initialize a pool that is already initialized.",
166 SinglePoolError::InvalidPoolOnRampAccount =>
167 "Error: Provided pool onramp account does not match address derived from the pool account.",
168 SinglePoolError::OnRampDoesntExist =>
169 "Error: The onramp account for this pool does not exist; you must call `InitializePoolOnRamp` \
170 before you can perform this operation.",
171 SinglePoolError::ReplenishRequired =>
172 "Error: The present operation requires a `ReplenishPool` call, either because the pool stake account \
173 is in an exceptional state, or because the on-ramp account should be refreshed.",
174 SinglePoolError::WithdrawalViolatesPoolRequirements =>
175 "Error: Withdrawal would render the pool stake account impossible to redelegate. \
176 This can only occur if the Stake Program minimum delegation increases above 1 sol.",
177 SinglePoolError::InvalidDepositSolSource =>
178 "Error: The user-owned lamport source cannot be validated for `DepositSol`.",
179 }
180 }
181}