use {
solana_program_error::{ProgramError, ToStr},
thiserror::Error,
};
#[derive(
Clone, Debug, Eq, Error, num_enum::TryFromPrimitive, num_derive::FromPrimitive, PartialEq,
)]
#[repr(u32)]
pub enum SinglePoolError {
#[error("InvalidPoolAccount")]
InvalidPoolAccount,
#[error("InvalidPoolStakeAccount")]
InvalidPoolStakeAccount,
#[error("InvalidPoolMint")]
InvalidPoolMint,
#[error("InvalidPoolStakeAuthority")]
InvalidPoolStakeAuthority,
#[error("InvalidPoolMintAuthority")]
InvalidPoolMintAuthority,
#[error("InvalidPoolMplAuthority")]
InvalidPoolMplAuthority,
#[error("InvalidMetadataAccount")]
InvalidMetadataAccount,
#[error("InvalidMetadataSigner")]
InvalidMetadataSigner,
#[error("DepositTooSmall")]
DepositTooSmall,
#[error("WithdrawalTooSmall")]
WithdrawalTooSmall,
#[error("WithdrawalTooLarge")]
WithdrawalTooLarge,
#[error("SignatureMissing")]
SignatureMissing,
#[error("WrongStakeState")]
WrongStakeState,
#[error("ArithmeticOverflow")]
ArithmeticOverflow,
#[error("UnexpectedMathError")]
UnexpectedMathError,
#[error("LegacyVoteAccount")]
LegacyVoteAccount,
#[error("UnparseableVoteAccount")]
UnparseableVoteAccount,
#[error("WrongRentAmount")]
WrongRentAmount,
#[error("InvalidPoolStakeAccountUsage")]
InvalidPoolStakeAccountUsage,
#[error("PoolAlreadyInitialized")]
PoolAlreadyInitialized,
#[error("InvalidPoolOnRampAccount")]
InvalidPoolOnRampAccount,
#[error("OnRampDoesntExist")]
OnRampDoesntExist,
#[error("ReplenishRequired")]
ReplenishRequired,
#[error("WithdrawalViolatesPoolRequirements")]
WithdrawalViolatesPoolRequirements,
}
impl From<SinglePoolError> for ProgramError {
fn from(e: SinglePoolError) -> Self {
ProgramError::Custom(e as u32)
}
}
impl ToStr for SinglePoolError {
fn to_str(&self) -> &'static str {
match self {
SinglePoolError::InvalidPoolAccount =>
"Error: Provided pool account has the wrong address for its vote account, is uninitialized, \
or is otherwise invalid.",
SinglePoolError::InvalidPoolStakeAccount =>
"Error: Provided pool stake account does not match address derived from the pool account.",
SinglePoolError::InvalidPoolMint =>
"Error: Provided pool mint does not match address derived from the pool account.",
SinglePoolError::InvalidPoolStakeAuthority =>
"Error: Provided pool stake authority does not match address derived from the pool account.",
SinglePoolError::InvalidPoolMintAuthority =>
"Error: Provided pool mint authority does not match address derived from the pool account.",
SinglePoolError::InvalidPoolMplAuthority =>
"Error: Provided pool MPL authority does not match address derived from the pool account.",
SinglePoolError::InvalidMetadataAccount =>
"Error: Provided metadata account does not match metadata account derived for pool mint.",
SinglePoolError::InvalidMetadataSigner =>
"Error: Authorized withdrawer provided for metadata update does not match the vote account.",
SinglePoolError::DepositTooSmall =>
"Error: Not enough lamports provided for deposit to result in one pool token.",
SinglePoolError::WithdrawalTooSmall =>
"Error: Not enough pool tokens provided to withdraw stake worth one lamport.",
SinglePoolError::WithdrawalTooLarge =>
"Error: Not enough stake to cover the provided quantity of pool tokens. \
This typically means the value exists in the pool as activating stake, \
and an epoch is required for it to become available. Otherwise, it means \
active stake in the onramp must be moved via `ReplenishPool`.",
SinglePoolError::SignatureMissing => "Error: Required signature is missing.",
SinglePoolError::WrongStakeState => "Error: Stake account is not in the state expected by the program.",
SinglePoolError::ArithmeticOverflow => "Error: Unsigned subtraction crossed the zero.",
SinglePoolError::UnexpectedMathError =>
"Error: A calculation failed unexpectedly. \
(This error should never be surfaced; it stands in for failure conditions that should never be reached.)",
SinglePoolError::UnparseableVoteAccount => "Error: Failed to parse vote account.",
SinglePoolError::LegacyVoteAccount =>
"Error: The V0_23_5 vote account type is unsupported and should be upgraded via `convert_to_current()`.",
SinglePoolError::WrongRentAmount =>
"Error: Incorrect number of lamports provided for rent-exemption when initializing.",
SinglePoolError::InvalidPoolStakeAccountUsage =>
"Error: Attempted to deposit from or withdraw to pool stake account.",
SinglePoolError::PoolAlreadyInitialized =>
"Error: Attempted to initialize a pool that is already initialized.",
SinglePoolError::InvalidPoolOnRampAccount =>
"Error: Provided pool onramp account does not match address derived from the pool account.",
SinglePoolError::OnRampDoesntExist =>
"Error: The onramp account for this pool does not exist; you must call `InitializePoolOnRamp` \
before you can perform this operation.",
SinglePoolError::ReplenishRequired =>
"Error: The present operation requires a `ReplenishPool` call, either because the pool stake account \
is in an exceptional state, or because the on-ramp account should be refreshed.",
SinglePoolError::WithdrawalViolatesPoolRequirements =>
"Error: Withdrawal would render the pool stake account impossible to redelegate. \
This can only occur if the Stake Program minimum delegation increases above 1 sol.",
}
}
}