spl_single_pool/
error.rs

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