mpl_token_vault/
error.rs

1//! Error types
2
3use {
4    num_derive::FromPrimitive,
5    solana_program::{
6        decode_error::DecodeError,
7        msg,
8        program_error::{PrintProgramError, ProgramError},
9    },
10    thiserror::Error,
11};
12
13/// Errors that may be returned by the Vault program.
14#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
15pub enum VaultError {
16    /// Invalid instruction data passed in.
17    #[error("Failed to unpack instruction data")]
18    InstructionUnpackError,
19
20    /// Lamport balance below rent-exempt threshold.
21    #[error("Lamport balance below rent-exempt threshold")]
22    NotRentExempt,
23
24    /// Already initialized
25    #[error("Already initialized")]
26    AlreadyInitialized,
27
28    /// Uninitialized
29    #[error("Uninitialized")]
30    Uninitialized,
31
32    /// Account does not have correct owner
33    #[error("Account does not have correct owner")]
34    IncorrectOwner,
35
36    /// NumericalOverflowError
37    #[error("NumericalOverflowError")]
38    NumericalOverflowError,
39
40    /// Provided token account contains no tokens
41    #[error("Provided token account contains no tokens")]
42    TokenAccountContainsNoTokens,
43
44    /// Provided token account cannot provide amount specified
45    #[error("Provided token account cannot provide amount specified")]
46    TokenAccountAmountLessThanAmountSpecified,
47
48    /// Provided vault account contains is not empty
49    #[error("Provided vault account contains is not empty")]
50    VaultAccountIsNotEmpty,
51
52    /// Provided vault account is not owned by program
53    #[error("Provided vault account is not owned by program derived address with seed of prefix and program id")]
54    VaultAccountIsNotOwnedByProgram,
55
56    /// The provided safety deposit account address does not match the expected program derived address
57    #[error(
58        "The provided safety deposit account address does not match the expected program derived address"
59    )]
60    SafetyDepositAddressInvalid,
61
62    /// Token transfer failed
63    #[error("Token transfer failed")]
64    TokenTransferFailed,
65    /// Token mint to failed
66    #[error("Token mint to failed")]
67    TokenMintToFailed,
68    /// Token burn failed
69    #[error("Token burn failed")]
70    TokenBurnFailed,
71
72    /// Vault mint not empty on int
73    #[error("Vault mint not empty on init")]
74    VaultMintNotEmpty,
75
76    /// Vault mint's authority not set to program
77    #[error("Vault mint's authority not set to program PDA with seed of prefix and program id")]
78    VaultAuthorityNotProgram,
79
80    /// Vault treasury not empty on init
81    #[error("Vault treasury not empty on init")]
82    TreasuryNotEmpty,
83
84    /// Vault treasury's owner not set to program
85    #[error("Vault treasury's owner not set to program pda with seed of prefix and program id")]
86    TreasuryOwnerNotProgram,
87
88    /// Vault should be inactive
89    #[error("Vault should be inactive")]
90    VaultShouldBeInactive,
91
92    /// Vault should be active
93    #[error("Vault should be active")]
94    VaultShouldBeActive,
95
96    /// Vault should be combined
97    #[error("Vault should be combined")]
98    VaultShouldBeCombined,
99
100    /// Vault treasury needs to match fraction mint
101    #[error("Vault treasury needs to match fraction mint")]
102    VaultTreasuryMintDoesNotMatchVaultMint,
103
104    /// Redeem Treasury cannot be same mint as fraction
105    #[error("Redeem Treasury cannot be same mint as fraction")]
106    RedeemTreasuryCantShareSameMintAsFraction,
107
108    /// Invalid program authority provided
109    #[error("Invalid program authority provided")]
110    InvalidAuthority,
111
112    /// Redeem treasury mint must match lookup mint
113    #[error("Redeem treasury mint must match lookup mint")]
114    RedeemTreasuryMintMustMatchLookupMint,
115
116    /// You must pay with the same mint as the external pricing oracle
117    #[error("You must pay with the same mint as the external pricing oracle")]
118    PaymentMintShouldMatchPricingMint,
119
120    /// Your share account should match the mint of the fractional mint
121    #[error("Your share account should match the mint of the fractional mint")]
122    ShareMintShouldMatchFractionalMint,
123
124    /// Vault mint provided does not match that on the token vault
125    #[error("Vault mint provided does not match that on the token vault")]
126    VaultMintNeedsToMatchVault,
127
128    /// Redeem treasury provided does not match that on the token vault
129    #[error("Redeem treasury provided does not match that on the token vault")]
130    RedeemTreasuryNeedsToMatchVault,
131
132    /// Fraction treasury provided does not match that on the token vault
133    #[error("Fraction treasury provided does not match that on the token vault")]
134    FractionTreasuryNeedsToMatchVault,
135
136    /// Not allowed to combine at this time
137    #[error("Not allowed to combine at this time")]
138    NotAllowedToCombine,
139
140    /// You cannot afford to combine this pool
141    #[error("You cannot afford to combine this vault")]
142    CannotAffordToCombineThisVault,
143
144    /// You have no shares to redeem
145    #[error("You have no shares to redeem")]
146    NoShares,
147
148    /// Your outstanding share account is the incorrect mint
149    #[error("Your outstanding share account is the incorrect mint")]
150    OutstandingShareAccountNeedsToMatchFractionalMint,
151
152    /// Your destination account is the incorrect mint
153    #[error("Your destination account is the incorrect mint")]
154    DestinationAccountNeedsToMatchRedeemMint,
155
156    /// Fractional mint is empty
157    #[error("Fractional mint is empty")]
158    FractionSupplyEmpty,
159
160    /// Token Program Provided Needs To Match Vault
161    #[error("Token Program Provided Needs To Match Vault")]
162    TokenProgramProvidedDoesNotMatchVault,
163
164    /// Authority of vault needs to be signer for this action
165    #[error("Authority of vault needs to be signer for this action")]
166    AuthorityIsNotSigner,
167
168    /// Authority of vault does not match authority provided
169    #[error("Authority of vault does not match authority provided")]
170    AuthorityDoesNotMatch,
171
172    /// This safety deposit box does not belong to this vault!
173    #[error("This safety deposit box does not belong to this vault!")]
174    SafetyDepositBoxVaultMismatch,
175
176    /// The store provided does not match the store key on the safety deposit box!
177    #[error("The store provided does not match the store key on the safety deposit box!")]
178    StoreDoesNotMatchSafetyDepositBox,
179
180    /// This safety deposit box is empty!
181    #[error("This safety deposit box is empty!")]
182    StoreEmpty,
183
184    /// The destination account to receive your token needs to be the same mint as the token's mint
185    #[error("The destination account to receive your token needs to be the same mint as the token's mint")]
186    DestinationAccountNeedsToMatchTokenMint,
187
188    /// The destination account to receive your shares needs to be the same mint as the vault's fraction mint
189    #[error("The destination account to receive your shares needs to be the same mint as the vault's fraction mint")]
190    DestinationAccountNeedsToMatchFractionMint,
191
192    /// The source account to send your shares from needs to be the same mint as the vault's fraction mint
193    #[error("The source account to send your shares from needs to be the same mint as the vault's fraction mint")]
194    SourceAccountNeedsToMatchFractionMint,
195
196    /// This vault does not allow the minting of new shares!
197    #[error("This vault does not allow the minting of new shares!")]
198    VaultDoesNotAllowNewShareMinting,
199
200    /// There are not enough shares
201    #[error("There are not enough shares")]
202    NotEnoughShares,
203
204    /// External price account must be signer
205    #[error("External price account must be signer")]
206    ExternalPriceAccountMustBeSigner,
207
208    ///Very bad, someone changed external account's price mint after vault creation!
209    #[error("Very bad, someone changed external account's price mint after vault creation!")]
210    RedeemTreasuryMintShouldMatchPricingMint,
211
212    /// Store has less than amount desired
213    #[error("Store has less than amount desired")]
214    StoreLessThanAmount,
215
216    /// Invalid token program
217    #[error("Invalid token program")]
218    InvalidTokenProgram,
219
220    /// Data type mismatch
221    #[error("Data type mismatch")]
222    DataTypeMismatch,
223
224    /// Accept payment delegate should be none
225    #[error("Accept payment delegate should be none")]
226    DelegateShouldBeNone,
227
228    /// Accept payment close authority should be none
229    #[error("Accept payment close authority should be none")]
230    CloseAuthorityShouldBeNone,
231
232    /// Derived key invalid
233    #[error("Derived key invalid")]
234    DerivedKeyInvalid,
235}
236
237impl PrintProgramError for VaultError {
238    fn print<E>(&self) {
239        msg!(&self.to_string());
240    }
241}
242
243impl From<VaultError> for ProgramError {
244    fn from(e: VaultError) -> Self {
245        ProgramError::Custom(e as u32)
246    }
247}
248
249impl<T> DecodeError<T> for VaultError {
250    fn type_of() -> &'static str {
251        "Vault Error"
252    }
253}