spl_single_pool/
error.rs

1//! Error types
2
3use {
4    solana_program_error::{ProgramError, ToStr},
5    thiserror::Error,
6};
7
8/// Errors that may be returned by the `SinglePool` program.
9#[derive(
10    Clone, Debug, Eq, Error, num_enum::TryFromPrimitive, num_derive::FromPrimitive, PartialEq,
11)]
12#[repr(u32)]
13pub enum SinglePoolError {
14    // 0.
15    /// Provided pool account has the wrong address for its vote account, is
16    /// uninitialized, or otherwise invalid.
17    #[error("InvalidPoolAccount")]
18    InvalidPoolAccount,
19    /// Provided pool stake account does not match address derived from the pool
20    /// account.
21    #[error("InvalidPoolStakeAccount")]
22    InvalidPoolStakeAccount,
23    /// Provided pool mint does not match address derived from the pool account.
24    #[error("InvalidPoolMint")]
25    InvalidPoolMint,
26    /// Provided pool stake authority does not match address derived from the
27    /// pool account.
28    #[error("InvalidPoolStakeAuthority")]
29    InvalidPoolStakeAuthority,
30    /// Provided pool mint authority does not match address derived from the
31    /// pool account.
32    #[error("InvalidPoolMintAuthority")]
33    InvalidPoolMintAuthority,
34
35    // 5.
36    /// Provided pool MPL authority does not match address derived from the pool
37    /// account.
38    #[error("InvalidPoolMplAuthority")]
39    InvalidPoolMplAuthority,
40    /// Provided metadata account does not match metadata account derived for
41    /// pool mint.
42    #[error("InvalidMetadataAccount")]
43    InvalidMetadataAccount,
44    /// Authorized withdrawer provided for metadata update does not match the
45    /// vote account.
46    #[error("InvalidMetadataSigner")]
47    InvalidMetadataSigner,
48    /// Not enough lamports provided for deposit to result in one pool token.
49    #[error("DepositTooSmall")]
50    DepositTooSmall,
51    /// Not enough pool tokens provided to withdraw stake worth one lamport.
52    #[error("WithdrawalTooSmall")]
53    WithdrawalTooSmall,
54
55    // 10
56    /// Not enough stake to cover the provided quantity of pool tokens.
57    /// (Generally this should not happen absent user error, but may if the
58    /// minimum delegation increases beyond 1 sol.)
59    #[error("WithdrawalTooLarge")]
60    WithdrawalTooLarge,
61    /// Required signature is missing.
62    #[error("SignatureMissing")]
63    SignatureMissing,
64    /// Stake account is not in the state expected by the program.
65    #[error("WrongStakeStake")]
66    WrongStakeStake,
67    /// Unsigned subtraction crossed the zero.
68    #[error("ArithmeticOverflow")]
69    ArithmeticOverflow,
70    /// A calculation failed unexpectedly.
71    /// (This error should never be surfaced; it stands in for failure
72    /// conditions that should never be reached.)
73    #[error("UnexpectedMathError")]
74    UnexpectedMathError,
75
76    // 15
77    /// The `V0_23_5` vote account type is unsupported and should be upgraded via
78    /// `convert_to_current()`.
79    #[error("LegacyVoteAccount")]
80    LegacyVoteAccount,
81    /// Failed to parse vote account.
82    #[error("UnparseableVoteAccount")]
83    UnparseableVoteAccount,
84    /// Incorrect number of lamports provided for rent-exemption when
85    /// initializing.
86    #[error("WrongRentAmount")]
87    WrongRentAmount,
88    /// Attempted to deposit from or withdraw to pool stake account.
89    #[error("InvalidPoolStakeAccountUsage")]
90    InvalidPoolStakeAccountUsage,
91    /// Attempted to initialize a pool that is already initialized.
92    #[error("PoolAlreadyInitialized")]
93    PoolAlreadyInitialized,
94
95    // 20
96    /// Provided pool on-ramp account does not match address derived from the pool
97    /// account.
98    #[error("InvalidPoolOnRampAccount")]
99    InvalidPoolOnRampAccount,
100    /// The on-ramp account for this pool does not exist; you must call `InitializePoolOnRamp`
101    /// before you can perform this operation.
102    #[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}