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)]
17pub enum GovernanceError {
18 #[error("Invalid instruction passed to program")]
20 InvalidInstruction = 500,
21
22 #[error("Realm with the given name and governing mints already exists")]
24 RealmAlreadyExists,
25
26 #[error("Invalid realm")]
28 InvalidRealm,
29
30 #[error("Invalid Governing Token Mint")]
32 InvalidGoverningTokenMint, #[error("Governing Token Owner must sign transaction")]
36 GoverningTokenOwnerMustSign,
37
38 #[error("Governing Token Owner or Delegate must sign transaction")]
40 GoverningTokenOwnerOrDelegateMustSign, #[error("All votes must be relinquished to withdraw governing tokens")]
44 AllVotesMustBeRelinquishedToWithdrawGoverningTokens,
45
46 #[error("Invalid Token Owner Record account address")]
48 InvalidTokenOwnerRecordAccountAddress,
49
50 #[error("Invalid GoverningMint for TokenOwnerRecord")]
52 InvalidGoverningMintForTokenOwnerRecord, #[error("Invalid Realm for TokenOwnerRecord")]
56 InvalidRealmForTokenOwnerRecord, #[error("Invalid Proposal for ProposalTransaction,")]
60 InvalidProposalForProposalTransaction, #[error("Invalid Signatory account address")]
64 InvalidSignatoryAddress, #[error("Signatory already signed off")]
68 SignatoryAlreadySignedOff, #[error("Signatory must sign")]
72 SignatoryMustSign, #[error("Invalid Proposal Owner")]
76 InvalidProposalOwnerAccount, #[error("Invalid Proposal for VoterRecord")]
80 InvalidProposalForVoterRecord, #[error("Invalid GoverningTokenOwner for VoteRecord")]
84 InvalidGoverningTokenOwnerForVoteRecord, #[error("Invalid Governance config: Vote threshold percentage out of range")]
88 InvalidVoteThresholdPercentage, #[error("Proposal for the given Governance, Governing Token Mint and index already exists")]
93 ProposalAlreadyExists, #[error("Token Owner already voted on the Proposal")]
97 VoteAlreadyExists, #[error("Owner doesn't have enough governing tokens to create Proposal")]
101 NotEnoughTokensToCreateProposal, #[error("Invalid State: Can't edit Signatories")]
105 InvalidStateCannotEditSignatories, #[error("Invalid Proposal state")]
109 InvalidProposalState, #[error("Invalid State: Can't edit transactions")]
113 InvalidStateCannotEditTransactions, #[error("Invalid State: Can't execute transaction")]
117 InvalidStateCannotExecuteTransaction, #[error("Can't execute transaction within its hold up time")]
121 CannotExecuteTransactionWithinHoldUpTime, #[error("Transaction already executed")]
125 TransactionAlreadyExecuted, #[error("Invalid Transaction index")]
129 InvalidTransactionIndex, #[error("Transaction hold up time is below the min specified by Governance")]
133 TransactionHoldUpTimeBelowRequiredMin, #[error("Transaction at the given index for the Proposal already exists")]
137 TransactionAlreadyExists, #[error("Invalid State: Can't sign off")]
141 InvalidStateCannotSignOff, #[error("Invalid State: Can't vote")]
145 InvalidStateCannotVote, #[error("Invalid State: Can't finalize vote")]
149 InvalidStateCannotFinalize, #[error("Invalid State: Can't cancel Proposal")]
153 InvalidStateCannotCancelProposal, #[error("Vote already relinquished")]
157 VoteAlreadyRelinquished, #[error("Can't finalize vote. Voting still in progress")]
161 CannotFinalizeVotingInProgress, #[error("Proposal voting time expired")]
165 ProposalVotingTimeExpired, #[error("Invalid Signatory Mint")]
169 InvalidSignatoryMint, #[error("Proposal does not belong to the given Governance")]
173 InvalidGovernanceForProposal, #[error("Proposal does not belong to given Governing Mint")]
177 InvalidGoverningMintForProposal, #[error("Current mint authority must sign transaction")]
181 MintAuthorityMustSign, #[error("Invalid mint authority")]
185 InvalidMintAuthority, #[error("Mint has no authority")]
189 MintHasNoAuthority, #[error("Invalid Token account owner")]
195 SplTokenAccountWithInvalidOwner, #[error("Invalid Mint account owner")]
199 SplTokenMintWithInvalidOwner, #[error("Token Account is not initialized")]
203 SplTokenAccountNotInitialized, #[error("Token Account doesn't exist")]
207 SplTokenAccountDoesNotExist, #[error("Token account data is invalid")]
211 SplTokenInvalidTokenAccountData, #[error("Token mint account data is invalid")]
215 SplTokenInvalidMintAccountData, #[error("Token Mint account is not initialized")]
219 SplTokenMintNotInitialized, #[error("Token Mint account doesn't exist")]
223 SplTokenMintDoesNotExist, #[error("Invalid ProgramData account address")]
229 InvalidProgramDataAccountAddress, #[error("Invalid ProgramData account Data")]
233 InvalidProgramDataAccountData, #[error("Provided upgrade authority doesn't match current program upgrade authority")]
238 InvalidUpgradeAuthority, #[error("Current program upgrade authority must sign transaction")]
242 UpgradeAuthorityMustSign, #[error("Given program is not upgradable")]
246 ProgramNotUpgradable, #[error("Invalid token owner")]
250 InvalidTokenOwner, #[error("Current token owner must sign transaction")]
254 TokenOwnerMustSign, #[error("Given VoteThresholdType is not supported")]
258 VoteThresholdTypeNotSupported, #[error("Given VoteWeightSource is not supported")]
262 VoteWeightSourceNotSupported, #[error("Legacy1")]
266 Legacy1, #[error("Governance PDA must sign")]
270 GovernancePdaMustSign, #[error("Transaction already flagged with error")]
274 TransactionAlreadyFlaggedWithError, #[error("Invalid Realm for Governance")]
278 InvalidRealmForGovernance, #[error("Invalid Authority for Realm")]
282 InvalidAuthorityForRealm, #[error("Realm has no authority")]
286 RealmHasNoAuthority, #[error("Realm authority must sign")]
290 RealmAuthorityMustSign, #[error("Invalid governing token holding account")]
294 InvalidGoverningTokenHoldingAccount, #[error("Realm council mint change is not supported")]
298 RealmCouncilMintChangeIsNotSupported, #[error("Invalid max voter weight absolute value")]
302 InvalidMaxVoterWeightAbsoluteValue, #[error("Invalid max voter weight supply fraction")]
306 InvalidMaxVoterWeightSupplyFraction, #[error("Owner doesn't have enough governing tokens to create Governance")]
310 NotEnoughTokensToCreateGovernance, #[error("Too many outstanding proposals")]
314 TooManyOutstandingProposals, #[error("All proposals must be finalized to withdraw governing tokens")]
318 AllProposalsMustBeFinalisedToWithdrawGoverningTokens, #[error("Invalid VoterWeightRecord for Realm")]
322 InvalidVoterWeightRecordForRealm, #[error("Invalid VoterWeightRecord for GoverningTokenMint")]
326 InvalidVoterWeightRecordForGoverningTokenMint, #[error("Invalid VoterWeightRecord for TokenOwner")]
330 InvalidVoterWeightRecordForTokenOwner, #[error("VoterWeightRecord expired")]
334 VoterWeightRecordExpired, #[error("Invalid RealmConfig for Realm")]
338 InvalidRealmConfigForRealm, #[error("TokenOwnerRecord already exists")]
342 TokenOwnerRecordAlreadyExists, #[error("Governing token deposits not allowed")]
346 GoverningTokenDepositsNotAllowed, #[error("Invalid vote choice weight percentage")]
350 InvalidVoteChoiceWeightPercentage, #[error("Vote type not supported")]
354 VoteTypeNotSupported, #[error("Invalid proposal options")]
358 InvalidProposalOptions, #[error("Proposal is not not executable")]
362 ProposalIsNotExecutable, #[error("Deny vote is not allowed")]
366 DenyVoteIsNotAllowed, #[error("Cannot execute defeated option")]
370 CannotExecuteDefeatedOption, #[error("VoterWeightRecord invalid action")]
374 VoterWeightRecordInvalidAction, #[error("VoterWeightRecord invalid action target")]
378 VoterWeightRecordInvalidActionTarget, #[error("Invalid MaxVoterWeightRecord for Realm")]
382 InvalidMaxVoterWeightRecordForRealm, #[error("Invalid MaxVoterWeightRecord for GoverningTokenMint")]
386 InvalidMaxVoterWeightRecordForGoverningTokenMint, #[error("MaxVoterWeightRecord expired")]
390 MaxVoterWeightRecordExpired, #[error("Not supported VoteType")]
394 NotSupportedVoteType, #[error("RealmConfig change not allowed")]
398 RealmConfigChangeNotAllowed, #[error("GovernanceConfig change not allowed")]
402 GovernanceConfigChangeNotAllowed, #[error("At least one VoteThreshold is required")]
406 AtLeastOneVoteThresholdRequired, #[error("Reserved buffer must be empty")]
410 ReservedBufferMustBeEmpty, #[error("Cannot Relinquish in Finalizing state")]
414 CannotRelinquishInFinalizingState, #[error("Invalid RealmConfig account address")]
418 InvalidRealmConfigAddress, #[error("Cannot deposit dormant tokens")]
422 CannotDepositDormantTokens, #[error("Cannot withdraw membership tokens")]
426 CannotWithdrawMembershipTokens, #[error("Cannot revoke GoverningTokens")]
430 CannotRevokeGoverningTokens, #[error("Invalid Revoke amount")]
434 InvalidRevokeAmount, #[error("Invalid GoverningToken source")]
438 InvalidGoverningTokenSource, #[error("Cannot change community TokenType to Membership")]
442 CannotChangeCommunityTokenTypeToMembership, #[error("Voter weight threshold disabled")]
446 VoterWeightThresholdDisabled, #[error("Vote not allowed in cool off time")]
450 VoteNotAllowedInCoolOffTime, #[error("Cannot refund ProposalDeposit")]
454 CannotRefundProposalDeposit, #[error("Invalid Proposal for ProposalDeposit")]
458 InvalidProposalForProposalDeposit, #[error("Invalid deposit_exempt_proposal_count")]
462 InvalidDepositExemptProposalCount, #[error("GoverningTokenMint not allowed to vote")]
466 GoverningTokenMintNotAllowedToVote, #[error("Invalid deposit Payer for ProposalDeposit")]
470 InvalidDepositPayerForProposalDeposit, #[error("Invalid State: Proposal is not in final state")]
474 InvalidStateNotFinal, #[error("Invalid state for proposal state transition to Completed")]
478 InvalidStateToCompleteProposal, #[error("Invalid number of vote choices")]
482 InvalidNumberOfVoteChoices, #[error("Ranked vote is not supported")]
486 RankedVoteIsNotSupported, #[error("Choice weight must be 100%")]
490 ChoiceWeightMustBe100Percent, #[error("Single choice only is allowed")]
494 SingleChoiceOnlyIsAllowed, #[error("At least single choice is required")]
498 AtLeastSingleChoiceIsRequired, #[error("Total vote weight must be 100%")]
502 TotalVoteWeightMustBe100Percent, #[error("Invalid multi choice proposal parameters")]
506 InvalidMultiChoiceProposalParameters, #[error("Invalid Governance for RequiredSignatory")]
510 InvalidGovernanceForRequiredSignatory,
511
512 #[error("Signatory Record has already been created")]
514 SignatoryRecordAlreadyExists,
515
516 #[error("Instruction has been removed")]
518 InstructionDeprecated,
519
520 #[error("Proposal is missing required signatories")]
522 MissingRequiredSignatories,
523}
524
525impl PrintProgramError for GovernanceError {
526 fn print<E>(&self) {
527 msg!("GOVERNANCE-ERROR: {}", &self.to_string());
528 }
529}
530
531impl From<GovernanceError> for ProgramError {
532 fn from(e: GovernanceError) -> Self {
533 ProgramError::Custom(e as u32)
534 }
535}
536
537impl<T> DecodeError<T> for GovernanceError {
538 fn type_of() -> &'static str {
539 "Governance Error"
540 }
541}