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.)
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}
96impl From<SinglePoolError> for ProgramError {
97    fn from(e: SinglePoolError) -> Self {
98        ProgramError::Custom(e as u32)
99    }
100}
101impl<T> DecodeError<T> for SinglePoolError {
102    fn type_of() -> &'static str {
103        "Single-Validator Stake Pool Error"
104    }
105}
106impl PrintProgramError for SinglePoolError {
107    fn print<E>(&self)
108    where
109        E: 'static
110            + std::error::Error
111            + DecodeError<E>
112            + PrintProgramError
113            + num_traits::FromPrimitive,
114    {
115        match self {
116            SinglePoolError::InvalidPoolAccount =>
117                msg!("Error: Provided pool account has the wrong address for its vote account, is uninitialized, \
118                     or is otherwise invalid."),
119            SinglePoolError::InvalidPoolStakeAccount =>
120                msg!("Error: Provided pool stake account does not match address derived from the pool account."),
121            SinglePoolError::InvalidPoolMint =>
122                msg!("Error: Provided pool mint does not match address derived from the pool account."),
123            SinglePoolError::InvalidPoolStakeAuthority =>
124                msg!("Error: Provided pool stake authority does not match address derived from the pool account."),
125            SinglePoolError::InvalidPoolMintAuthority =>
126                msg!("Error: Provided pool mint authority does not match address derived from the pool account."),
127            SinglePoolError::InvalidPoolMplAuthority =>
128                msg!("Error: Provided pool MPL authority does not match address derived from the pool account."),
129            SinglePoolError::InvalidMetadataAccount =>
130                msg!("Error: Provided metadata account does not match metadata account derived for pool mint."),
131            SinglePoolError::InvalidMetadataSigner =>
132                msg!("Error: Authorized withdrawer provided for metadata update does not match the vote account."),
133            SinglePoolError::DepositTooSmall =>
134                msg!("Error: Not enough lamports provided for deposit to result in one pool token."),
135            SinglePoolError::WithdrawalTooSmall =>
136                msg!("Error: Not enough pool tokens provided to withdraw stake worth one lamport."),
137            SinglePoolError::WithdrawalTooLarge =>
138                msg!("Error: Not enough stake to cover the provided quantity of pool tokens. \
139                     (Generally this should not happen absent user error, but may if the minimum delegation increases.)"),
140            SinglePoolError::SignatureMissing => msg!("Error: Required signature is missing."),
141            SinglePoolError::WrongStakeStake => msg!("Error: Stake account is not in the state expected by the program."),
142            SinglePoolError::ArithmeticOverflow => msg!("Error: Unsigned subtraction crossed the zero."),
143            SinglePoolError::UnexpectedMathError =>
144                msg!("Error: A calculation failed unexpectedly. \
145                     (This error should never be surfaced; it stands in for failure conditions that should never be reached.)"),
146            SinglePoolError::UnparseableVoteAccount => msg!("Error: Failed to parse vote account."),
147            SinglePoolError::LegacyVoteAccount =>
148                msg!("Error: The V0_23_5 vote account type is unsupported and should be upgraded via `convert_to_current()`."),
149            SinglePoolError::WrongRentAmount =>
150                msg!("Error: Incorrect number of lamports provided for rent-exemption when initializing."),
151            SinglePoolError::InvalidPoolStakeAccountUsage =>
152                msg!("Error: Attempted to deposit from or withdraw to pool stake account."),
153            SinglePoolError::PoolAlreadyInitialized =>
154                msg!("Error: Attempted to initialize a pool that is already initialized."),
155        }
156    }
157}