1use {
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#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
15pub enum VaultError {
16 #[error("Failed to unpack instruction data")]
18 InstructionUnpackError,
19
20 #[error("Lamport balance below rent-exempt threshold")]
22 NotRentExempt,
23
24 #[error("Already initialized")]
26 AlreadyInitialized,
27
28 #[error("Uninitialized")]
30 Uninitialized,
31
32 #[error("Account does not have correct owner")]
34 IncorrectOwner,
35
36 #[error("NumericalOverflowError")]
38 NumericalOverflowError,
39
40 #[error("Provided token account contains no tokens")]
42 TokenAccountContainsNoTokens,
43
44 #[error("Provided token account cannot provide amount specified")]
46 TokenAccountAmountLessThanAmountSpecified,
47
48 #[error("Provided vault account contains is not empty")]
50 VaultAccountIsNotEmpty,
51
52 #[error("Provided vault account is not owned by program derived address with seed of prefix and program id")]
54 VaultAccountIsNotOwnedByProgram,
55
56 #[error(
58 "The provided safety deposit account address does not match the expected program derived address"
59 )]
60 SafetyDepositAddressInvalid,
61
62 #[error("Token transfer failed")]
64 TokenTransferFailed,
65 #[error("Token mint to failed")]
67 TokenMintToFailed,
68 #[error("Token burn failed")]
70 TokenBurnFailed,
71
72 #[error("Vault mint not empty on init")]
74 VaultMintNotEmpty,
75
76 #[error("Vault mint's authority not set to program PDA with seed of prefix and program id")]
78 VaultAuthorityNotProgram,
79
80 #[error("Vault treasury not empty on init")]
82 TreasuryNotEmpty,
83
84 #[error("Vault treasury's owner not set to program pda with seed of prefix and program id")]
86 TreasuryOwnerNotProgram,
87
88 #[error("Vault should be inactive")]
90 VaultShouldBeInactive,
91
92 #[error("Vault should be active")]
94 VaultShouldBeActive,
95
96 #[error("Vault should be combined")]
98 VaultShouldBeCombined,
99
100 #[error("Vault treasury needs to match fraction mint")]
102 VaultTreasuryMintDoesNotMatchVaultMint,
103
104 #[error("Redeem Treasury cannot be same mint as fraction")]
106 RedeemTreasuryCantShareSameMintAsFraction,
107
108 #[error("Invalid program authority provided")]
110 InvalidAuthority,
111
112 #[error("Redeem treasury mint must match lookup mint")]
114 RedeemTreasuryMintMustMatchLookupMint,
115
116 #[error("You must pay with the same mint as the external pricing oracle")]
118 PaymentMintShouldMatchPricingMint,
119
120 #[error("Your share account should match the mint of the fractional mint")]
122 ShareMintShouldMatchFractionalMint,
123
124 #[error("Vault mint provided does not match that on the token vault")]
126 VaultMintNeedsToMatchVault,
127
128 #[error("Redeem treasury provided does not match that on the token vault")]
130 RedeemTreasuryNeedsToMatchVault,
131
132 #[error("Fraction treasury provided does not match that on the token vault")]
134 FractionTreasuryNeedsToMatchVault,
135
136 #[error("Not allowed to combine at this time")]
138 NotAllowedToCombine,
139
140 #[error("You cannot afford to combine this vault")]
142 CannotAffordToCombineThisVault,
143
144 #[error("You have no shares to redeem")]
146 NoShares,
147
148 #[error("Your outstanding share account is the incorrect mint")]
150 OutstandingShareAccountNeedsToMatchFractionalMint,
151
152 #[error("Your destination account is the incorrect mint")]
154 DestinationAccountNeedsToMatchRedeemMint,
155
156 #[error("Fractional mint is empty")]
158 FractionSupplyEmpty,
159
160 #[error("Token Program Provided Needs To Match Vault")]
162 TokenProgramProvidedDoesNotMatchVault,
163
164 #[error("Authority of vault needs to be signer for this action")]
166 AuthorityIsNotSigner,
167
168 #[error("Authority of vault does not match authority provided")]
170 AuthorityDoesNotMatch,
171
172 #[error("This safety deposit box does not belong to this vault!")]
174 SafetyDepositBoxVaultMismatch,
175
176 #[error("The store provided does not match the store key on the safety deposit box!")]
178 StoreDoesNotMatchSafetyDepositBox,
179
180 #[error("This safety deposit box is empty!")]
182 StoreEmpty,
183
184 #[error("The destination account to receive your token needs to be the same mint as the token's mint")]
186 DestinationAccountNeedsToMatchTokenMint,
187
188 #[error("The destination account to receive your shares needs to be the same mint as the vault's fraction mint")]
190 DestinationAccountNeedsToMatchFractionMint,
191
192 #[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 #[error("This vault does not allow the minting of new shares!")]
198 VaultDoesNotAllowNewShareMinting,
199
200 #[error("There are not enough shares")]
202 NotEnoughShares,
203
204 #[error("External price account must be signer")]
206 ExternalPriceAccountMustBeSigner,
207
208 #[error("Very bad, someone changed external account's price mint after vault creation!")]
210 RedeemTreasuryMintShouldMatchPricingMint,
211
212 #[error("Store has less than amount desired")]
214 StoreLessThanAmount,
215
216 #[error("Invalid token program")]
218 InvalidTokenProgram,
219
220 #[error("Data type mismatch")]
222 DataTypeMismatch,
223
224 #[error("Accept payment delegate should be none")]
226 DelegateShouldBeNone,
227
228 #[error("Accept payment close authority should be none")]
230 CloseAuthorityShouldBeNone,
231
232 #[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}