types.gno
4.83 Kb · 161 lines
1package governance
2
3import (
4 bptree "gno.land/p/nt/bptree/v0"
5)
6
7type IGovernance interface {
8 IGovernanceManager
9 IGovernanceGetter
10}
11
12type IGovernanceManager interface {
13 // Proposal management
14 ProposeText(
15 _ int, rlm realm,
16 title string,
17 description string,
18 ) int64
19
20 ProposeCommunityPoolSpend(
21 _ int, rlm realm,
22 title string,
23 description string,
24 to address,
25 tokenPath string,
26 amount int64,
27 ) int64
28
29 ProposeParameterChange(
30 _ int, rlm realm,
31 title string,
32 description string,
33 numToExecute int64,
34 executions string,
35 ) int64
36
37 // Voting
38 Vote(
39 _ int, rlm realm,
40 proposalId int64,
41 yes bool,
42 ) string
43
44 // Execution
45 Execute(
46 _ int, rlm realm,
47 proposalId int64,
48 ) int64
49
50 Cancel(
51 _ int, rlm realm,
52 proposalId int64,
53 ) int64
54
55 // Configuration
56 Reconfigure(
57 _ int, rlm realm,
58 votingStartDelay int64,
59 votingPeriod int64,
60 votingWeightSmoothingDuration int64,
61 quorum int64,
62 proposalCreationThreshold int64,
63 executionDelay int64,
64 executionWindow int64,
65 ) int64
66}
67
68// IGovernanceGetter provides read-only access to governance data.
69type IGovernanceGetter interface {
70 // Store data getters
71 GetLatestConfigVersion() int64
72 GetCurrentProposalID() int64
73 GetMaxSmoothingPeriod() int64
74
75 // Config getters
76 GetLatestConfig() Config
77 GetConfig(configVersion int64) (Config, error)
78
79 // Proposal getters
80 GetProposalCount() int
81 GetProposalIDs(offset, count int) []int64
82 ExistsProposal(proposalID int64) bool
83 GetProposal(proposalID int64) (*Proposal, error)
84 GetProposerByProposalId(proposalId int64) (address, error)
85 GetProposalTypeByProposalId(proposalId int64) (ProposalType, error)
86 GetYeaByProposalId(proposalId int64) (int64, error)
87 GetNayByProposalId(proposalId int64) (int64, error)
88 GetConfigVersionByProposalId(proposalId int64) (int64, error)
89 GetQuorumAmountByProposalId(proposalId int64) (int64, error)
90 GetTitleByProposalId(proposalId int64) (string, error)
91 GetDescriptionByProposalId(proposalId int64) (string, error)
92 GetProposalStatusByProposalId(proposalId int64) (string, error)
93
94 // Vote getters
95 GetVoteStatus(proposalId int64) (quorum, maxVotingWeight, yesWeight, noWeight int64, err error)
96 GetVotingInfoCount(proposalID int64) int
97 GetVotingInfoAddresses(proposalID int64, offset, count int) []address
98 ExistsVotingInfo(proposalID int64, addr address) bool
99 GetVotingInfo(proposalID int64, addr address) (*VotingInfo, error)
100 GetVoteWeight(proposalID int64, addr address) (int64, error)
101 GetVotedHeight(proposalID int64, addr address) (int64, error)
102 GetVotedAt(proposalID int64, addr address) (int64, error)
103
104 // User proposal getters
105 GetUserProposalCount(user address) int
106 GetUserProposalIDs(user address, offset, count int) []int64
107
108 // Active proposal query
109 GetOldestActiveProposalSnapshotTime() (int64, bool)
110
111 // Voting weight snapshot getters
112 GetCurrentVotingWeightSnapshot() (int64, int64, error)
113}
114
115type IGovernanceStore interface {
116 // Counter methods
117 HasConfigCounterStoreKey() bool
118 GetConfigCounter() *Counter
119 SetConfigCounter(_ int, rlm realm, counter *Counter) error
120
121 HasProposalCounterStoreKey() bool
122 GetProposalCounter() *Counter
123 SetProposalCounter(_ int, rlm realm, counter *Counter) error
124
125 // Config methods
126 HasConfigsStoreKey() bool
127 SetConfigs(_ int, rlm realm, configs *bptree.BPTree) error
128 SetConfig(_ int, rlm realm, version int64, config Config) error
129 GetConfig(version int64) (Config, bool)
130
131 // Proposal methods
132 HasProposalsStoreKey() bool
133 GetProposals() *bptree.BPTree
134 GetProposal(proposalID int64) (*Proposal, bool)
135 SetProposal(_ int, rlm realm, proposalID int64, proposal *Proposal) error
136 SetProposals(_ int, rlm realm, proposals *bptree.BPTree) error
137
138 // Proposal voting info methods
139 HasProposalUserVotingInfosStoreKey() bool
140 GetProposalUserVotingInfos() *bptree.BPTree
141 SetProposalUserVotingInfos(_ int, rlm realm, votingInfos *bptree.BPTree) error
142 GetProposalVotingInfos(proposalID int64) (*bptree.BPTree, bool)
143 SetProposalVotingInfos(_ int, rlm realm, proposalID int64, votingInfos *bptree.BPTree) error
144
145 // User proposals methods
146 HasUserProposalsStoreKey() bool
147 GetUserProposalIDs(user string) ([]int64, bool)
148 SetUserProposals(_ int, rlm realm, userProposals *bptree.BPTree) error
149 AddUserProposal(_ int, rlm realm, user string, proposalID int64) error
150 RemoveUserProposal(_ int, rlm realm, user string, proposalID int64) error
151}
152
153// GovStakerAccessor provides an interface for accessing gov staker functionality.
154// This abstraction allows for easier testing by enabling mock implementations.
155type GovStakerAccessor interface {
156 // GetTotalDelegationAmountAtSnapshot returns the total delegation amount at a specific snapshot time.
157 GetTotalDelegationAmountAtSnapshot(snapshotTime int64) (int64, bool)
158
159 // GetUserDelegationAmountAtSnapshot returns the user delegation amount at a specific snapshot time.
160 GetUserDelegationAmountAtSnapshot(userAddr address, snapshotTime int64) (int64, bool)
161}