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