mpl_auction/
errors.rs

1use {
2    num_derive::FromPrimitive,
3    solana_program::{
4        decode_error::DecodeError,
5        msg,
6        program_error::{PrintProgramError, ProgramError},
7    },
8    thiserror::Error,
9};
10
11/// Errors that may be returned by the Auction program.
12#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
13pub enum AuctionError {
14    /// Account does not have correct owner
15    #[error("Account does not have correct owner")]
16    IncorrectOwner,
17
18    /// Lamport balance below rent-exempt threshold.
19    #[error("Lamport balance below rent-exempt threshold")]
20    NotRentExempt,
21
22    /// Bid account provided does not match the derived address.
23    #[error("Bid account provided does not match the derived address.")]
24    InvalidBidAccount,
25
26    /// Auction account specified is invalid.
27    #[error("Auction account specified is invalid.")]
28    InvalidAuctionAccount,
29
30    /// Balance too low to make bid.
31    #[error("Balance too low to make bid.")]
32    BalanceTooLow,
33
34    /// Auction is not currently running.
35    #[error("Auction is not currently running.")]
36    InvalidState,
37
38    /// Bid is too small.
39    #[error("Bid is too small.")]
40    BidTooSmall,
41
42    /// Invalid transition, auction state may only transition: Created -> Started -> Stopped
43    #[error("Invalid auction state transition.")]
44    AuctionTransitionInvalid,
45
46    /// Failed to derive an account from seeds.
47    #[error("Failed to derive an account from seeds.")]
48    DerivedKeyInvalid,
49
50    /// Token transfer failed
51    #[error("Token transfer failed")]
52    TokenTransferFailed,
53
54    /// Token mint to failed
55    #[error("Token mint to failed")]
56    TokenMintToFailed,
57
58    /// Token burn failed
59    #[error("Token burn failed")]
60    TokenBurnFailed,
61
62    /// Invalid authority
63    #[error("Invalid authority")]
64    InvalidAuthority,
65
66    /// Authority not signer
67    #[error("Authority not signer")]
68    AuthorityNotSigner,
69
70    /// Numerical overflow
71    #[error("Numerical overflow")]
72    NumericalOverflowError,
73
74    /// Bidder pot token account does not match
75    #[error("Bidder pot token account does not match")]
76    BidderPotTokenAccountOwnerMismatch,
77
78    /// Uninitialized
79    #[error("Uninitialized")]
80    Uninitialized,
81
82    /// Metadata account is missing or invalid.
83    #[error("Metadata account is missing or invalid.")]
84    MetadataInvalid,
85
86    /// Bidder pot is missing, and required for SPL trades.
87    #[error("Bidder pot is missing, and required for SPL trades.")]
88    BidderPotDoesNotExist,
89
90    /// Existing Bid is already active.
91    #[error("Existing Bid is already active.")]
92    BidAlreadyActive,
93
94    /// Incorrect mint specified, must match auction.
95    #[error("Incorrect mint specified, must match auction.")]
96    IncorrectMint,
97
98    /// Must reveal price when ending a blinded auction.
99    #[error("Must reveal price when ending a blinded auction.")]
100    MustReveal,
101
102    /// The revealing hash is invalid.
103    #[error("The revealing hash is invalid.")]
104    InvalidReveal,
105
106    /// The pot for this bid is already empty.
107    #[error("The pot for this bid is already empty.")]
108    BidderPotEmpty,
109
110    /// This is not a valid token program
111    #[error(" This is not a valid token program")]
112    InvalidTokenProgram,
113
114    /// Accept payment delegate should be none
115    #[error("Accept payment delegate should be none")]
116    DelegateShouldBeNone,
117
118    /// Accept payment close authority should be none
119    #[error("Accept payment close authority should be none")]
120    CloseAuthorityShouldBeNone,
121
122    /// Data type mismatch
123    #[error("Data type mismatch")]
124    DataTypeMismatch,
125
126    /// Bid must be multiple of tick size
127    #[error("Bid must be multiple of tick size")]
128    BidMustBeMultipleOfTickSize,
129
130    /// During the gap window, gap between next lowest bid must be of a certain percentage
131    #[error("During the gap window, gap between next lowest bid must be of a certain percentage")]
132    GapBetweenBidsTooSmall,
133
134    /// Gap tick size percentage must be between 0 and 100
135    #[error("Gap tick size percentage must be between 0 and 100")]
136    InvalidGapTickSizePercentage,
137
138    /// Gap tick size percentage must be between 0 and 100
139    #[error("Bidder Pot Token Must be a new account")]
140    BidderPotTokenAccountMustBeNew,
141}
142
143impl PrintProgramError for AuctionError {
144    fn print<E>(&self) {
145        msg!(&self.to_string());
146    }
147}
148
149impl From<AuctionError> for ProgramError {
150    fn from(e: AuctionError) -> Self {
151        ProgramError::Custom(e as u32)
152    }
153}
154
155impl<T> DecodeError<T> for AuctionError {
156    fn type_of() -> &'static str {
157        "Vault Error"
158    }
159}