gpl_governance/
error.rs

1//! Error types
2
3use num_derive::FromPrimitive;
4use gemachain_program::{
5    decode_error::DecodeError,
6    msg,
7    program_error::{PrintProgramError, ProgramError},
8};
9use thiserror::Error;
10
11/// Errors that may be returned by the Governance program
12#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
13pub enum GovernanceError {
14    /// Invalid instruction passed to program
15    #[error("Invalid instruction passed to program")]
16    InvalidInstruction = 500, // Start Governance custom errors from 500 to avoid conflicts with programs invoked via CPI
17
18    /// Realm with the given name and governing mints already exists
19    #[error("Realm with the given name and governing mints already exists")]
20    RealmAlreadyExists,
21
22    /// Invalid Realm
23    #[error("Invalid realm")]
24    InvalidRealm,
25
26    /// Invalid Governing Token Mint
27    #[error("Invalid Governing Token Mint")]
28    InvalidGoverningTokenMint,
29
30    /// Governing Token Owner must sign transaction
31    #[error("Governing Token Owner must sign transaction")]
32    GoverningTokenOwnerMustSign,
33
34    /// Governing Token Owner or Delegate  must sign transaction
35    #[error("Governing Token Owner or Delegate  must sign transaction")]
36    GoverningTokenOwnerOrDelegateMustSign,
37
38    /// All votes must be relinquished to withdraw governing tokens
39    #[error("All votes must be relinquished to withdraw governing tokens")]
40    AllVotesMustBeRelinquishedToWithdrawGoverningTokens,
41
42    /// Invalid Token Owner Record account address
43    #[error("Invalid Token Owner Record account address")]
44    InvalidTokenOwnerRecordAccountAddress,
45
46    /// Invalid GoverningMint for TokenOwnerRecord
47    #[error("Invalid GoverningMint for TokenOwnerRecord")]
48    InvalidGoverningMintForTokenOwnerRecord,
49
50    /// Invalid Realm for TokenOwnerRecord
51    #[error("Invalid Realm for TokenOwnerRecord")]
52    InvalidRealmForTokenOwnerRecord,
53
54    /// Invalid Proposal for ProposalInstruction
55    #[error("Invalid Proposal for ProposalInstruction")]
56    InvalidProposalForProposalInstruction,
57
58    /// Invalid Signatory account address
59    #[error("Invalid Signatory account address")]
60    InvalidSignatoryAddress,
61
62    /// Signatory already signed off
63    #[error("Signatory already signed off")]
64    SignatoryAlreadySignedOff,
65
66    /// Signatory must sign
67    #[error("Signatory must sign")]
68    SignatoryMustSign,
69
70    /// Invalid Proposal Owner
71    #[error("Invalid Proposal Owner")]
72    InvalidProposalOwnerAccount,
73
74    /// Invalid Proposal for VoterRecord
75    #[error("Invalid Proposal for VoterRecord")]
76    InvalidProposalForVoterRecord,
77
78    /// Invalid GoverningTokenOwner  for VoteRecord
79    #[error("Invalid GoverningTokenOwner for VoteRecord")]
80    InvalidGoverningTokenOwnerForVoteRecord,
81
82    /// Invalid Governance config: Vote threshold percentage out of range"
83    #[error("Invalid Governance config: Vote threshold percentage out of range")]
84    InvalidVoteThresholdPercentage,
85
86    /// Proposal for the given Governance, Governing Token Mint and index already exists
87    #[error("Proposal for the given Governance, Governing Token Mint and index already exists")]
88    ProposalAlreadyExists,
89
90    /// Token Owner already voted on the Proposal
91    #[error("Token Owner already voted on the Proposal")]
92    VoteAlreadyExists,
93
94    /// Owner doesn't have enough governing tokens to create Proposal
95    #[error("Owner doesn't have enough governing tokens to create Proposal")]
96    NotEnoughTokensToCreateProposal,
97
98    /// Invalid State: Can't edit Signatories
99    #[error("Invalid State: Can't edit Signatories")]
100    InvalidStateCannotEditSignatories,
101
102    /// Invalid Proposal state
103    #[error("Invalid Proposal state")]
104    InvalidProposalState,
105    /// Invalid State: Can't edit instructions
106    #[error("Invalid State: Can't edit instructions")]
107    InvalidStateCannotEditInstructions,
108
109    /// Invalid State: Can't execute instruction
110    #[error("Invalid State: Can't execute instruction")]
111    InvalidStateCannotExecuteInstruction,
112
113    /// Can't execute instruction within its hold up time
114    #[error("Can't execute instruction within its hold up time")]
115    CannotExecuteInstructionWithinHoldUpTime,
116
117    /// Instruction already executed
118    #[error("Instruction already executed")]
119    InstructionAlreadyExecuted,
120
121    /// Invalid Instruction index
122    #[error("Invalid Instruction index")]
123    InvalidInstructionIndex,
124
125    /// Instruction hold up time is below the min specified by Governance
126    #[error("Instruction hold up time is below the min specified by Governance")]
127    InstructionHoldUpTimeBelowRequiredMin,
128
129    /// Instruction at the given index for the Proposal already exists
130    #[error("Instruction at the given index for the Proposal already exists")]
131    InstructionAlreadyExists,
132
133    /// Invalid State: Can't sign off
134    #[error("Invalid State: Can't sign off")]
135    InvalidStateCannotSignOff,
136
137    /// Invalid State: Can't vote
138    #[error("Invalid State: Can't vote")]
139    InvalidStateCannotVote,
140
141    /// Invalid State: Can't finalize vote
142    #[error("Invalid State: Can't finalize vote")]
143    InvalidStateCannotFinalize,
144
145    /// Invalid State: Can't cancel Proposal
146    #[error("Invalid State: Can't cancel Proposal")]
147    InvalidStateCannotCancelProposal,
148
149    /// Vote already relinquished
150    #[error("Vote already relinquished")]
151    VoteAlreadyRelinquished,
152
153    /// Can't finalize vote. Voting still in progress
154    #[error("Can't finalize vote. Voting still in progress")]
155    CannotFinalizeVotingInProgress,
156
157    /// Proposal voting time expired
158    #[error("Proposal voting time expired")]
159    ProposalVotingTimeExpired,
160
161    /// Invalid Signatory Mint
162    #[error("Invalid Signatory Mint")]
163    InvalidSignatoryMint,
164
165    /// Proposal does not belong to the given Governance
166    #[error("Proposal does not belong to the given Governance")]
167    InvalidGovernanceForProposal,
168
169    /// Proposal does not belong to given Governing Mint"
170    #[error("Proposal does not belong to given Governing Mint")]
171    InvalidGoverningMintForProposal,
172
173    /// Current mint authority must sign transaction
174    #[error("Current mint authority must sign transaction")]
175    MintAuthorityMustSign,
176
177    /// Invalid mint authority
178    #[error("Invalid mint authority")]
179    InvalidMintAuthority,
180
181    /// Mint has no authority
182    #[error("Mint has no authority")]
183    MintHasNoAuthority,
184
185    /// ---- GPL Token Tools Errors ----
186
187    /// Invalid Token account owner
188    #[error("Invalid Token account owner")]
189    GplTokenAccountWithInvalidOwner,
190
191    /// Invalid Mint account owner
192    #[error("Invalid Mint account owner")]
193    GplTokenMintWithInvalidOwner,
194
195    /// Token Account is not initialized
196    #[error("Token Account is not initialized")]
197    GplTokenAccountNotInitialized,
198
199    /// Token Account doesn't exist
200    #[error("Token Account doesn't exist")]
201    GplTokenAccountDoesNotExist,
202
203    /// Token account data is invalid
204    #[error("Token account data is invalid")]
205    GplTokenInvalidTokenAccountData,
206
207    /// Token mint account data is invalid
208    #[error("Token mint account data is invalid")]
209    GplTokenInvalidMintAccountData,
210
211    /// Token Mint is not initialized
212    #[error("Token Mint account is not initialized")]
213    GplTokenMintNotInitialized,
214
215    /// Token Mint account doesn't exist
216    #[error("Token Mint account doesn't exist")]
217    GplTokenMintDoesNotExist,
218
219    /// ---- Bpf Upgradable Loader Tools Errors ----
220
221    /// Invalid ProgramData account Address
222    #[error("Invalid ProgramData account address")]
223    InvalidProgramDataAccountAddress,
224
225    /// Invalid ProgramData account data
226    #[error("Invalid ProgramData account Data")]
227    InvalidProgramDataAccountData,
228
229    /// Provided upgrade authority doesn't match current program upgrade authority
230    #[error("Provided upgrade authority doesn't match current program upgrade authority")]
231    InvalidUpgradeAuthority,
232
233    /// Current program upgrade authority must sign transaction
234    #[error("Current program upgrade authority must sign transaction")]
235    UpgradeAuthorityMustSign,
236
237    /// Given program is not upgradable
238    #[error("Given program is not upgradable")]
239    ProgramNotUpgradable,
240
241    /// Invalid token owner
242    #[error("Invalid token owner")]
243    InvalidTokenOwner,
244
245    /// Current token owner must sign transaction
246    #[error("Current token owner must sign transaction")]
247    TokenOwnerMustSign,
248
249    /// Given VoteThresholdPercentageType is not supported
250    #[error("Given VoteThresholdPercentageType is not supported")]
251    VoteThresholdPercentageTypeNotSupported,
252
253    /// Given VoteWeightSource is not supported
254    #[error("Given VoteWeightSource is not supported")]
255    VoteWeightSourceNotSupported,
256
257    /// Proposal cool off time is not supported
258    #[error("Proposal cool off time is not supported")]
259    ProposalCoolOffTimeNotSupported,
260
261    /// Governance PDA must sign
262    #[error("Governance PDA must sign")]
263    GovernancePdaMustSign,
264
265    /// Instruction already flagged with error
266    #[error("Instruction already flagged with error")]
267    InstructionAlreadyFlaggedWithError,
268
269    /// Invalid Realm for Governance
270    #[error("Invalid Realm for Governance")]
271    InvalidRealmForGovernance,
272
273    /// Invalid Authority for Realm
274    #[error("Invalid Authority for Realm")]
275    InvalidAuthorityForRealm,
276
277    /// Realm has no authority
278    #[error("Realm has no authority")]
279    RealmHasNoAuthority,
280
281    /// Realm authority must sign
282    #[error("Realm authority must sign")]
283    RealmAuthorityMustSign,
284
285    /// Invalid governing token holding account
286    #[error("Invalid governing token holding account")]
287    InvalidGoverningTokenHoldingAccount,
288
289    /// Realm council mint change is not supported
290    #[error("Realm council mint change is not supported")]
291    RealmCouncilMintChangeIsNotSupported,
292
293    /// Not supported mint max vote weight source
294    #[error("Not supported mint max vote weight source")]
295    MintMaxVoteWeightSourceNotSupported,
296
297    /// Invalid max vote weight supply fraction
298    #[error("Invalid max vote weight supply fraction")]
299    InvalidMaxVoteWeightSupplyFraction,
300
301    /// Owner doesn't have enough governing tokens to create Governance
302    #[error("Owner doesn't have enough governing tokens to create Governance")]
303    NotEnoughTokensToCreateGovernance,
304
305    /// Too many outstanding proposals
306    #[error("Too many outstanding proposals")]
307    TooManyOutstandingProposals,
308
309    /// All proposals must be finalized to withdraw governing tokens
310    #[error("All proposals must be finalized to withdraw governing tokens")]
311    AllProposalsMustBeFinalisedToWithdrawGoverningTokens,
312
313    /// Invalid VoterWeightRecord for Realm
314    #[error("Invalid VoterWeightRecord for Realm")]
315    InvalidVoterWeightRecordForRealm,
316
317    /// Invalid VoterWeightRecord for GoverningTokenMint
318    #[error("Invalid VoterWeightRecord for GoverningTokenMint")]
319    InvalidVoterWeightRecordForGoverningTokenMint,
320
321    /// Invalid VoterWeightRecord for TokenOwner
322    #[error("Invalid VoterWeightRecord for TokenOwner")]
323    InvalidVoterWeightRecordForTokenOwner,
324
325    /// VoterWeightRecord expired
326    #[error("VoterWeightRecord expired")]
327    VoterWeightRecordExpired,
328
329    /// Invalid RealmConfig for Realm
330    #[error("Invalid RealmConfig for Realm")]
331    InvalidRealmConfigForRealm,
332
333    /// TokenOwnerRecord already exists
334    #[error("TokenOwnerRecord already exists")]
335    TokenOwnerRecordAlreadyExists,
336
337    /// Governing token deposits not allowed
338    #[error("Governing token deposits not allowed")]
339    GoverningTokenDepositsNotAllowed,
340}
341
342impl PrintProgramError for GovernanceError {
343    fn print<E>(&self) {
344        msg!("GOVERNANCE-ERROR: {}", &self.to_string());
345    }
346}
347
348impl From<GovernanceError> for ProgramError {
349    fn from(e: GovernanceError) -> Self {
350        ProgramError::Custom(e as u32)
351    }
352}
353
354impl<T> DecodeError<T> for GovernanceError {
355    fn type_of() -> &'static str {
356        "Governance Error"
357    }
358}