spl_stake_pool/
error.rs

1//! Error types
2
3use {
4    num_derive::FromPrimitive,
5    solana_program::{decode_error::DecodeError, program_error::ProgramError},
6    thiserror::Error,
7};
8
9/// Errors that may be returned by the StakePool program.
10#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
11pub enum StakePoolError {
12    // 0.
13    /// The account cannot be initialized because it is already being used.
14    #[error("AlreadyInUse")]
15    AlreadyInUse,
16    /// The program address provided doesn't match the value generated by the program.
17    #[error("InvalidProgramAddress")]
18    InvalidProgramAddress,
19    /// The stake pool state is invalid.
20    #[error("InvalidState")]
21    InvalidState,
22    /// The calculation failed.
23    #[error("CalculationFailure")]
24    CalculationFailure,
25    /// Stake pool fee > 1.
26    #[error("FeeTooHigh")]
27    FeeTooHigh,
28
29    // 5.
30    /// Token account is associated with the wrong mint.
31    #[error("WrongAccountMint")]
32    WrongAccountMint,
33    /// Wrong pool manager account.
34    #[error("WrongManager")]
35    WrongManager,
36    /// Required signature is missing.
37    #[error("SignatureMissing")]
38    SignatureMissing,
39    /// Invalid validator stake list account.
40    #[error("InvalidValidatorStakeList")]
41    InvalidValidatorStakeList,
42    /// Invalid manager fee account.
43    #[error("InvalidFeeAccount")]
44    InvalidFeeAccount,
45
46    // 10.
47    /// Specified pool mint account is wrong.
48    #[error("WrongPoolMint")]
49    WrongPoolMint,
50    /// Stake account is not in the state expected by the program.
51    #[error("WrongStakeState")]
52    WrongStakeState,
53    /// User stake is not active
54    #[error("UserStakeNotActive")]
55    UserStakeNotActive,
56    /// Stake account voting for this validator already exists in the pool.
57    #[error("ValidatorAlreadyAdded")]
58    ValidatorAlreadyAdded,
59    /// Stake account for this validator not found in the pool.
60    #[error("ValidatorNotFound")]
61    ValidatorNotFound,
62
63    // 15.
64    /// Stake account address not properly derived from the validator address.
65    #[error("InvalidStakeAccountAddress")]
66    InvalidStakeAccountAddress,
67    /// Identify validator stake accounts with old balances and update them.
68    #[error("StakeListOutOfDate")]
69    StakeListOutOfDate,
70    /// First update old validator stake account balances and then pool stake balance.
71    #[error("StakeListAndPoolOutOfDate")]
72    StakeListAndPoolOutOfDate,
73    /// Validator stake account is not found in the list storage.
74    #[error("UnknownValidatorStakeAccount")]
75    UnknownValidatorStakeAccount,
76    /// Wrong minting authority set for mint pool account
77    #[error("WrongMintingAuthority")]
78    WrongMintingAuthority,
79
80    // 20.
81    /// The size of the given validator stake list does match the expected amount
82    #[error("UnexpectedValidatorListAccountSize")]
83    UnexpectedValidatorListAccountSize,
84    /// Wrong pool staker account.
85    #[error("WrongStaker")]
86    WrongStaker,
87    /// Pool token supply is not zero on initialization
88    #[error("NonZeroPoolTokenSupply")]
89    NonZeroPoolTokenSupply,
90    /// The lamports in the validator stake account is not equal to the minimum
91    #[error("StakeLamportsNotEqualToMinimum")]
92    StakeLamportsNotEqualToMinimum,
93    /// The provided deposit stake account is not delegated to the preferred deposit vote account
94    #[error("IncorrectDepositVoteAddress")]
95    IncorrectDepositVoteAddress,
96
97    // 25.
98    /// The provided withdraw stake account is not the preferred deposit vote account
99    #[error("IncorrectWithdrawVoteAddress")]
100    IncorrectWithdrawVoteAddress,
101    /// The mint has an invalid freeze authority
102    #[error("InvalidMintFreezeAuthority")]
103    InvalidMintFreezeAuthority,
104    /// Proposed fee increase exceeds stipulated ratio
105    #[error("FeeIncreaseTooHigh")]
106    FeeIncreaseTooHigh,
107    /// Not enough pool tokens provided to withdraw stake with one lamport
108    #[error("WithdrawalTooSmall")]
109    WithdrawalTooSmall,
110    /// Not enough lamports provided for deposit to result in one pool token
111    #[error("DepositTooSmall")]
112    DepositTooSmall,
113
114    // 30.
115    /// Provided stake deposit authority does not match the program's
116    #[error("InvalidStakeDepositAuthority")]
117    InvalidStakeDepositAuthority,
118    /// Provided sol deposit authority does not match the program's
119    #[error("InvalidSolDepositAuthority")]
120    InvalidSolDepositAuthority,
121    /// Provided preferred validator is invalid
122    #[error("InvalidPreferredValidator")]
123    InvalidPreferredValidator,
124    /// Provided validator stake account already has a transient stake account in use
125    #[error("TransientAccountInUse")]
126    TransientAccountInUse,
127    /// Provided sol withdraw authority does not match the program's
128    #[error("InvalidSolWithdrawAuthority")]
129    InvalidSolWithdrawAuthority,
130
131    // 35.
132    /// Too much SOL withdrawn from the stake pool's reserve account
133    #[error("SolWithdrawalTooLarge")]
134    SolWithdrawalTooLarge,
135    /// Provided metadata account does not match metadata account derived for pool mint
136    #[error("InvalidMetadataAccount")]
137    InvalidMetadataAccount,
138    /// The mint has an unsupported extension
139    #[error("UnsupportedMintExtension")]
140    UnsupportedMintExtension,
141    /// The fee account has an unsupported extension
142    #[error("UnsupportedFeeAccountExtension")]
143    UnsupportedFeeAccountExtension,
144    /// Instruction exceeds desired slippage limit
145    #[error("Instruction exceeds desired slippage limit")]
146    ExceededSlippage,
147}
148impl From<StakePoolError> for ProgramError {
149    fn from(e: StakePoolError) -> Self {
150        ProgramError::Custom(e as u32)
151    }
152}
153impl<T> DecodeError<T> for StakePoolError {
154    fn type_of() -> &'static str {
155        "Stake Pool Error"
156    }
157}