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}
114impl From<SinglePoolError> for ProgramError {
115 fn from(e: SinglePoolError) -> Self {
116 ProgramError::Custom(e as u32)
117 }
118}
119impl ToStr for SinglePoolError {
120 fn to_str(&self) -> &'static str {
121 match self {
122 SinglePoolError::InvalidPoolAccount =>
123 "Error: Provided pool account has the wrong address for its vote account, is uninitialized, \
124 or is otherwise invalid.",
125 SinglePoolError::InvalidPoolStakeAccount =>
126 "Error: Provided pool stake account does not match address derived from the pool account.",
127 SinglePoolError::InvalidPoolMint =>
128 "Error: Provided pool mint does not match address derived from the pool account.",
129 SinglePoolError::InvalidPoolStakeAuthority =>
130 "Error: Provided pool stake authority does not match address derived from the pool account.",
131 SinglePoolError::InvalidPoolMintAuthority =>
132 "Error: Provided pool mint authority does not match address derived from the pool account.",
133 SinglePoolError::InvalidPoolMplAuthority =>
134 "Error: Provided pool MPL authority does not match address derived from the pool account.",
135 SinglePoolError::InvalidMetadataAccount =>
136 "Error: Provided metadata account does not match metadata account derived for pool mint.",
137 SinglePoolError::InvalidMetadataSigner =>
138 "Error: Authorized withdrawer provided for metadata update does not match the vote account.",
139 SinglePoolError::DepositTooSmall =>
140 "Error: Not enough lamports provided for deposit to result in one pool token.",
141 SinglePoolError::WithdrawalTooSmall =>
142 "Error: Not enough pool tokens provided to withdraw stake worth one lamport.",
143 SinglePoolError::WithdrawalTooLarge =>
144 "Error: Not enough stake to cover the provided quantity of pool tokens. \
145 This typically means the value exists in the pool as activating stake, \
146 and an epoch is required for it to become available. Otherwise, it means \
147 active stake in the onramp must be moved via `ReplenishPool`.",
148 SinglePoolError::SignatureMissing => "Error: Required signature is missing.",
149 SinglePoolError::WrongStakeState => "Error: Stake account is not in the state expected by the program.",
150 SinglePoolError::ArithmeticOverflow => "Error: Unsigned subtraction crossed the zero.",
151 SinglePoolError::UnexpectedMathError =>
152 "Error: A calculation failed unexpectedly. \
153 (This error should never be surfaced; it stands in for failure conditions that should never be reached.)",
154 SinglePoolError::UnparseableVoteAccount => "Error: Failed to parse vote account.",
155 SinglePoolError::LegacyVoteAccount =>
156 "Error: The V0_23_5 vote account type is unsupported and should be upgraded via `convert_to_current()`.",
157 SinglePoolError::WrongRentAmount =>
158 "Error: Incorrect number of lamports provided for rent-exemption when initializing.",
159 SinglePoolError::InvalidPoolStakeAccountUsage =>
160 "Error: Attempted to deposit from or withdraw to pool stake account.",
161 SinglePoolError::PoolAlreadyInitialized =>
162 "Error: Attempted to initialize a pool that is already initialized.",
163 SinglePoolError::InvalidPoolOnRampAccount =>
164 "Error: Provided pool onramp account does not match address derived from the pool account.",
165 SinglePoolError::OnRampDoesntExist =>
166 "Error: The onramp account for this pool does not exist; you must call `InitializePoolOnRamp` \
167 before you can perform this operation.",
168 SinglePoolError::ReplenishRequired =>
169 "Error: The present operation requires a `ReplenishPool` call, either because the pool stake account \
170 is in an exceptional state, or because the on-ramp account should be refreshed.",
171 SinglePoolError::WithdrawalViolatesPoolRequirements =>
172 "Error: Withdrawal would render the pool stake account impossible to redelegate. \
173 This can only occur if the Stake Program minimum delegation increases above 1 sol.",
174 }
175 }
176}