solana-program-library/stake-pool/program/src/error.rs

57 lines
1.8 KiB
Rust

//! Error types
use num_derive::FromPrimitive;
use solana_program::{decode_error::DecodeError, program_error::ProgramError};
use thiserror::Error;
/// Errors that may be returned by the StakePool program.
#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
pub enum Error {
/// The account cannot be initialized because it is already being used.
#[error("AlreadyInUse")]
AlreadyInUse,
/// The program address provided doesn't match the value generated by the program.
#[error("InvalidProgramAddress")]
InvalidProgramAddress,
/// The owner of the input isn't set to the program address generated by the program.
#[error("InvalidOwner")]
InvalidOwner,
/// The deserialization of the Token state returned something besides State::Token.
#[error("ExpectedToken")]
ExpectedToken,
/// The deserialization of the Token state returned something besides State::Account.
#[error("ExpectedAccount")]
ExpectedAccount,
/// The initialized pool had a non zero supply.
#[error("InvalidSupply")]
InvalidSupply,
/// The initialized token has a delegate.
#[error("InvalidDelegate")]
InvalidDelegate,
/// The token swap state is invalid.
#[error("InvalidState")]
InvalidState,
/// The input token is invalid for swap.
#[error("InvalidInput")]
InvalidInput,
/// The output token is invalid for swap.
#[error("InvalidOutput")]
InvalidOutput,
/// The calculation failed.
#[error("CalculationFailure")]
CalculationFailure,
/// Stake pool fee > 1.
#[error("FeeTooHigh")]
FeeTooHigh,
}
impl From<Error> for ProgramError {
fn from(e: Error) -> Self {
ProgramError::Custom(e as u32)
}
}
impl<T> DecodeError<T> for Error {
fn type_of() -> &'static str {
"Stake Pool Error"
}
}