gpl_governance/state/
enums.rs

1//! State enumerations
2
3use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
4
5/// Defines all Governance accounts types
6#[repr(C)]
7#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
8pub enum GovernanceAccountType {
9    /// Default uninitialized account state
10    Uninitialized,
11
12    /// Top level aggregation for governances with Community Token (and optional Council Token)
13    Realm,
14
15    /// Token Owner Record for given governing token owner within a Realm
16    TokenOwnerRecord,
17
18    /// Generic Account Governance account
19    AccountGovernance,
20
21    /// Program Governance account
22    ProgramGovernance,
23
24    /// Proposal account for Governance account. A single Governance account can have multiple Proposal accounts
25    Proposal,
26
27    /// Proposal Signatory account
28    SignatoryRecord,
29
30    /// Vote record account for a given Proposal.  Proposal can have 0..n voting records
31    VoteRecord,
32
33    /// ProposalInstruction account which holds an instruction to execute for Proposal
34    ProposalInstruction,
35
36    /// Mint Governance account
37    MintGovernance,
38
39    /// Token Governance account
40    TokenGovernance,
41
42    /// Realm config account
43    RealmConfig,
44}
45
46impl Default for GovernanceAccountType {
47    fn default() -> Self {
48        GovernanceAccountType::Uninitialized
49    }
50}
51
52/// Vote  with number of votes
53#[repr(C)]
54#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
55pub enum VoteWeight {
56    /// Yes vote
57    Yes(u64),
58
59    /// No vote
60    No(u64),
61}
62
63/// What state a Proposal is in
64#[repr(C)]
65#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
66pub enum ProposalState {
67    /// Draft - Proposal enters Draft state when it's created
68    Draft,
69
70    /// SigningOff - The Proposal is being signed off by Signatories
71    /// Proposal enters the state when first Signatory Sings and leaves it when last Signatory signs
72    SigningOff,
73
74    /// Taking votes
75    Voting,
76
77    /// Voting ended with success
78    Succeeded,
79
80    /// Voting on Proposal succeeded and now instructions are being executed
81    /// Proposal enter this state when first instruction is executed and leaves when the last instruction is executed
82    Executing,
83
84    /// Completed
85    Completed,
86
87    /// Cancelled
88    Cancelled,
89
90    /// Defeated
91    Defeated,
92
93    /// Same as Executing but indicates some instructions failed to execute
94    /// Proposal can't be transitioned from ExecutingWithErrors to Completed state
95    ExecutingWithErrors,
96}
97
98impl Default for ProposalState {
99    fn default() -> Self {
100        ProposalState::Draft
101    }
102}
103
104/// The type of the vote threshold percentage used to resolve a vote on a Proposal
105#[repr(C)]
106#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
107pub enum VoteThresholdPercentage {
108    /// Voting threshold of Yes votes in % required to tip the vote
109    /// It's the percentage of tokens out of the entire pool of governance tokens eligible to vote
110    /// Note: If the threshold is below or equal to 50% then an even split of votes ex: 50:50 or 40:40 is always resolved as Defeated
111    /// In other words a '+1 vote' tie breaker is always required to have a successful vote
112    YesVote(u8),
113
114    /// The minimum number of votes in % out of the entire pool of governance tokens eligible to vote
115    /// which must be cast for the vote to be valid
116    /// Once the quorum is achieved a simple majority (50%+1) of Yes votes is required for the vote to succeed
117    /// Note: Quorum is not implemented in the current version
118    Quorum(u8),
119}
120
121/// The source of voter weights used to vote on proposals
122#[repr(C)]
123#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
124pub enum VoteWeightSource {
125    /// Governing token deposits into the Realm are used as voter weights
126    Deposit,
127    /// Governing token account snapshots as of the time a proposal entered voting state are used as voter weights
128    /// Note: Snapshot source is not supported in the current version
129    /// Support for account snapshots are required in gemachain and/or arweave as a prerequisite
130    Snapshot,
131}
132
133/// The status of instruction execution
134#[repr(C)]
135#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
136pub enum InstructionExecutionStatus {
137    /// Instruction was not executed yet
138    None,
139
140    /// Instruction was executed successfully
141    Success,
142
143    /// Instruction execution failed
144    Error,
145}
146
147/// Instruction execution flags defining how instructions are executed for a Proposal
148#[repr(C)]
149#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
150pub enum InstructionExecutionFlags {
151    /// No execution flags are specified
152    /// Instructions can be executed individually, in any order, as soon as they hold_up time expires
153    None,
154
155    /// Instructions are executed in a specific order
156    /// Note: Ordered execution is not supported in the current version
157    /// The implementation requires another account type to track deleted instructions
158    Ordered,
159
160    /// Multiple instructions can be executed as a single transaction
161    /// Note: Transactions are not supported in the current version
162    /// The implementation requires another account type to group instructions within a transaction
163    UseTransaction,
164}
165
166/// The source of max vote weight used for voting
167/// Values below 100% mint supply can be used when the governing token is fully minted but not distributed yet
168#[repr(C)]
169#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
170pub enum MintMaxVoteWeightSource {
171    /// Fraction (10^10 precision) of the governing mint supply is used as max vote weight
172    /// The default is 100% (10^10) to use all available mint supply for voting
173    SupplyFraction(u64),
174
175    /// Absolute value, irrelevant of the actual mint supply, is used as max vote weight
176    /// Note: this option is not implemented in the current version
177    Absolute(u64),
178}
179
180impl MintMaxVoteWeightSource {
181    /// Base for mint supply fraction calculation
182    pub const SUPPLY_FRACTION_BASE: u64 = 10_000_000_000;
183
184    /// 100% of mint supply
185    pub const FULL_SUPPLY_FRACTION: MintMaxVoteWeightSource =
186        MintMaxVoteWeightSource::SupplyFraction(MintMaxVoteWeightSource::SUPPLY_FRACTION_BASE);
187}