1use num_derive::FromPrimitive;
4use gemachain_program::{
5 decode_error::DecodeError,
6 msg,
7 program_error::{PrintProgramError, ProgramError},
8};
9use thiserror::Error;
10
11#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
13pub enum GovernanceError {
14 #[error("Invalid instruction passed to program")]
16 InvalidInstruction = 500, #[error("Realm with the given name and governing mints already exists")]
20 RealmAlreadyExists,
21
22 #[error("Invalid realm")]
24 InvalidRealm,
25
26 #[error("Invalid Governing Token Mint")]
28 InvalidGoverningTokenMint,
29
30 #[error("Governing Token Owner must sign transaction")]
32 GoverningTokenOwnerMustSign,
33
34 #[error("Governing Token Owner or Delegate must sign transaction")]
36 GoverningTokenOwnerOrDelegateMustSign,
37
38 #[error("All votes must be relinquished to withdraw governing tokens")]
40 AllVotesMustBeRelinquishedToWithdrawGoverningTokens,
41
42 #[error("Invalid Token Owner Record account address")]
44 InvalidTokenOwnerRecordAccountAddress,
45
46 #[error("Invalid GoverningMint for TokenOwnerRecord")]
48 InvalidGoverningMintForTokenOwnerRecord,
49
50 #[error("Invalid Realm for TokenOwnerRecord")]
52 InvalidRealmForTokenOwnerRecord,
53
54 #[error("Invalid Proposal for ProposalInstruction")]
56 InvalidProposalForProposalInstruction,
57
58 #[error("Invalid Signatory account address")]
60 InvalidSignatoryAddress,
61
62 #[error("Signatory already signed off")]
64 SignatoryAlreadySignedOff,
65
66 #[error("Signatory must sign")]
68 SignatoryMustSign,
69
70 #[error("Invalid Proposal Owner")]
72 InvalidProposalOwnerAccount,
73
74 #[error("Invalid Proposal for VoterRecord")]
76 InvalidProposalForVoterRecord,
77
78 #[error("Invalid GoverningTokenOwner for VoteRecord")]
80 InvalidGoverningTokenOwnerForVoteRecord,
81
82 #[error("Invalid Governance config: Vote threshold percentage out of range")]
84 InvalidVoteThresholdPercentage,
85
86 #[error("Proposal for the given Governance, Governing Token Mint and index already exists")]
88 ProposalAlreadyExists,
89
90 #[error("Token Owner already voted on the Proposal")]
92 VoteAlreadyExists,
93
94 #[error("Owner doesn't have enough governing tokens to create Proposal")]
96 NotEnoughTokensToCreateProposal,
97
98 #[error("Invalid State: Can't edit Signatories")]
100 InvalidStateCannotEditSignatories,
101
102 #[error("Invalid Proposal state")]
104 InvalidProposalState,
105 #[error("Invalid State: Can't edit instructions")]
107 InvalidStateCannotEditInstructions,
108
109 #[error("Invalid State: Can't execute instruction")]
111 InvalidStateCannotExecuteInstruction,
112
113 #[error("Can't execute instruction within its hold up time")]
115 CannotExecuteInstructionWithinHoldUpTime,
116
117 #[error("Instruction already executed")]
119 InstructionAlreadyExecuted,
120
121 #[error("Invalid Instruction index")]
123 InvalidInstructionIndex,
124
125 #[error("Instruction hold up time is below the min specified by Governance")]
127 InstructionHoldUpTimeBelowRequiredMin,
128
129 #[error("Instruction at the given index for the Proposal already exists")]
131 InstructionAlreadyExists,
132
133 #[error("Invalid State: Can't sign off")]
135 InvalidStateCannotSignOff,
136
137 #[error("Invalid State: Can't vote")]
139 InvalidStateCannotVote,
140
141 #[error("Invalid State: Can't finalize vote")]
143 InvalidStateCannotFinalize,
144
145 #[error("Invalid State: Can't cancel Proposal")]
147 InvalidStateCannotCancelProposal,
148
149 #[error("Vote already relinquished")]
151 VoteAlreadyRelinquished,
152
153 #[error("Can't finalize vote. Voting still in progress")]
155 CannotFinalizeVotingInProgress,
156
157 #[error("Proposal voting time expired")]
159 ProposalVotingTimeExpired,
160
161 #[error("Invalid Signatory Mint")]
163 InvalidSignatoryMint,
164
165 #[error("Proposal does not belong to the given Governance")]
167 InvalidGovernanceForProposal,
168
169 #[error("Proposal does not belong to given Governing Mint")]
171 InvalidGoverningMintForProposal,
172
173 #[error("Current mint authority must sign transaction")]
175 MintAuthorityMustSign,
176
177 #[error("Invalid mint authority")]
179 InvalidMintAuthority,
180
181 #[error("Mint has no authority")]
183 MintHasNoAuthority,
184
185 #[error("Invalid Token account owner")]
189 GplTokenAccountWithInvalidOwner,
190
191 #[error("Invalid Mint account owner")]
193 GplTokenMintWithInvalidOwner,
194
195 #[error("Token Account is not initialized")]
197 GplTokenAccountNotInitialized,
198
199 #[error("Token Account doesn't exist")]
201 GplTokenAccountDoesNotExist,
202
203 #[error("Token account data is invalid")]
205 GplTokenInvalidTokenAccountData,
206
207 #[error("Token mint account data is invalid")]
209 GplTokenInvalidMintAccountData,
210
211 #[error("Token Mint account is not initialized")]
213 GplTokenMintNotInitialized,
214
215 #[error("Token Mint account doesn't exist")]
217 GplTokenMintDoesNotExist,
218
219 #[error("Invalid ProgramData account address")]
223 InvalidProgramDataAccountAddress,
224
225 #[error("Invalid ProgramData account Data")]
227 InvalidProgramDataAccountData,
228
229 #[error("Provided upgrade authority doesn't match current program upgrade authority")]
231 InvalidUpgradeAuthority,
232
233 #[error("Current program upgrade authority must sign transaction")]
235 UpgradeAuthorityMustSign,
236
237 #[error("Given program is not upgradable")]
239 ProgramNotUpgradable,
240
241 #[error("Invalid token owner")]
243 InvalidTokenOwner,
244
245 #[error("Current token owner must sign transaction")]
247 TokenOwnerMustSign,
248
249 #[error("Given VoteThresholdPercentageType is not supported")]
251 VoteThresholdPercentageTypeNotSupported,
252
253 #[error("Given VoteWeightSource is not supported")]
255 VoteWeightSourceNotSupported,
256
257 #[error("Proposal cool off time is not supported")]
259 ProposalCoolOffTimeNotSupported,
260
261 #[error("Governance PDA must sign")]
263 GovernancePdaMustSign,
264
265 #[error("Instruction already flagged with error")]
267 InstructionAlreadyFlaggedWithError,
268
269 #[error("Invalid Realm for Governance")]
271 InvalidRealmForGovernance,
272
273 #[error("Invalid Authority for Realm")]
275 InvalidAuthorityForRealm,
276
277 #[error("Realm has no authority")]
279 RealmHasNoAuthority,
280
281 #[error("Realm authority must sign")]
283 RealmAuthorityMustSign,
284
285 #[error("Invalid governing token holding account")]
287 InvalidGoverningTokenHoldingAccount,
288
289 #[error("Realm council mint change is not supported")]
291 RealmCouncilMintChangeIsNotSupported,
292
293 #[error("Not supported mint max vote weight source")]
295 MintMaxVoteWeightSourceNotSupported,
296
297 #[error("Invalid max vote weight supply fraction")]
299 InvalidMaxVoteWeightSupplyFraction,
300
301 #[error("Owner doesn't have enough governing tokens to create Governance")]
303 NotEnoughTokensToCreateGovernance,
304
305 #[error("Too many outstanding proposals")]
307 TooManyOutstandingProposals,
308
309 #[error("All proposals must be finalized to withdraw governing tokens")]
311 AllProposalsMustBeFinalisedToWithdrawGoverningTokens,
312
313 #[error("Invalid VoterWeightRecord for Realm")]
315 InvalidVoterWeightRecordForRealm,
316
317 #[error("Invalid VoterWeightRecord for GoverningTokenMint")]
319 InvalidVoterWeightRecordForGoverningTokenMint,
320
321 #[error("Invalid VoterWeightRecord for TokenOwner")]
323 InvalidVoterWeightRecordForTokenOwner,
324
325 #[error("VoterWeightRecord expired")]
327 VoterWeightRecordExpired,
328
329 #[error("Invalid RealmConfig for Realm")]
331 InvalidRealmConfigForRealm,
332
333 #[error("TokenOwnerRecord already exists")]
335 TokenOwnerRecordAlreadyExists,
336
337 #[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}