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