Skip to content

Commit 30f110b

Browse files
author
0xTopaz
committed
refactor: governance event message
1 parent f249136 commit 30f110b

File tree

4 files changed

+58
-27
lines changed

4 files changed

+58
-27
lines changed

gov/governance/config.gno

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ func reconfigure(
9797
en.MintAndDistributeGns()
9898
updateProposalsState()
9999

100-
newVersion := getLatestVersion() + 1
100+
prevVersion := getLatestVersion()
101+
newVersion := prevVersion + 1
101102

102103
config = Config{
103104
VotingStartDelay: votingStartDelay,
@@ -121,8 +122,9 @@ func reconfigure(
121122
"quorum", formatUint64(config.Quorum),
122123
"proposalCreationThreshold", formatUint64(config.ProposalCreationThreshold),
123124
"executionDelay", formatUint64(config.ExecutionDelay),
124-
"executionWindow", formatUint64(config.ExecutionWindow),
125+
"executionPeriod", formatUint64(config.ExecutionWindow),
125126
"newConfigVersion", formatUint64(newVersion),
127+
"prevConfigVersion", formatUint64(prevVersion),
126128
)
127129

128130
return newVersion

gov/governance/proposal.gno

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func ProposeText(
5353
// votingMax does not include quantities delegated through Launchpad.
5454
votingMax, possibleAddressWithWeight := gs.GetPossibleVotingAddressWithWeight(now - config.VotingWeightSmoothingDuration)
5555

56+
maxVotingWeight := u256.NewUint(votingMax)
57+
quorumAmount := maxVotingWeight.Uint64() * config.Quorum / 100
58+
5659
proposal := ProposalInfo{
5760
Proposer: proposer,
5861
ProposalType: Text,
@@ -63,10 +66,10 @@ func ProposeText(
6366
},
6467
Yea: u256.Zero(),
6568
Nay: u256.Zero(),
66-
MaxVotingWeight: u256.NewUint(votingMax),
69+
MaxVotingWeight: maxVotingWeight,
6770
PossibleAddressWithWeight: possibleAddressWithWeight,
6871
ConfigVersion: uint64(configVersions.Size()), // use latest config version
69-
QuorumAmount: xgns.VotingSupply() * config.Quorum / 100,
72+
QuorumAmount: quorumAmount,
7073
Title: title,
7174
Description: description,
7275
}
@@ -83,10 +86,10 @@ func ProposeText(
8386
"title", title,
8487
"description", description,
8588
"proposalId", formatUint64(proposalId),
89+
"quorumAmount", formatUint64(proposal.QuorumAmount),
8690
"maxVotingWeight", proposal.MaxVotingWeight.ToString(),
87-
"createdAt", formatUint64(proposal.State.CreatedAt),
8891
"configVersion", formatUint64(proposal.ConfigVersion),
89-
"quorumAmount", formatUint64(proposal.QuorumAmount),
92+
"createdAt", formatUint64(proposal.State.CreatedAt),
9093
)
9194
return proposalId
9295
}
@@ -120,6 +123,9 @@ func ProposeCommunityPoolSpend(
120123
now := uint64(time.Now().Unix())
121124
votingMax, possibleAddressWithWeight := gs.GetPossibleVotingAddressWithWeight(now - config.VotingWeightSmoothingDuration)
122125

126+
maxVotingWeight := u256.NewUint(votingMax)
127+
quorumAmount := maxVotingWeight.Uint64() * config.Quorum / 100
128+
123129
proposal := ProposalInfo{
124130
Proposer: proposer,
125131
ProposalType: CommunityPoolSpend,
@@ -130,10 +136,10 @@ func ProposeCommunityPoolSpend(
130136
},
131137
Yea: u256.Zero(),
132138
Nay: u256.Zero(),
133-
MaxVotingWeight: u256.NewUint(votingMax),
139+
MaxVotingWeight: maxVotingWeight,
134140
PossibleAddressWithWeight: possibleAddressWithWeight,
135141
ConfigVersion: uint64(configVersions.Size()),
136-
QuorumAmount: xgns.VotingSupply() * config.Quorum / 100,
142+
QuorumAmount: quorumAmount,
137143
Title: title,
138144
Description: description,
139145
CommunityPoolSpend: CommunityPoolSpendInfo{
@@ -147,17 +153,21 @@ func ProposeCommunityPoolSpend(
147153
proposals.Set(formatUint64(proposalId), proposal)
148154
latestProposalByProposer.Set(proposer.String(), proposalId)
149155

150-
prevAddr, prevRealm := getPrev()
156+
prevAddr, prevPkgPath := getPrev()
151157
std.Emit(
152158
"ProposeCommunityPoolSpend",
153159
"prevAddr", prevAddr,
154-
"prevRealm", prevRealm,
160+
"prevRealm", prevPkgPath,
155161
"title", title,
156162
"description", description,
157163
"to", to.String(),
158164
"tokenPath", tokenPath,
159165
"amount", formatUint64(amount),
160-
"internal_proposalId", formatUint64(proposalId),
166+
"proposalId", formatUint64(proposalId),
167+
"quorumAmount", formatUint64(proposal.QuorumAmount),
168+
"maxVotingWeight", proposal.MaxVotingWeight.ToString(),
169+
"configVersion", formatUint64(proposal.ConfigVersion),
170+
"createdAt", formatUint64(proposal.State.CreatedAt),
161171
)
162172

163173
return proposalId
@@ -207,6 +217,9 @@ func ProposeParameterChange(
207217
now := uint64(time.Now().Unix())
208218
votingMax, possibleAddressWithWeight := gs.GetPossibleVotingAddressWithWeight(now - config.VotingWeightSmoothingDuration)
209219

220+
maxVotingWeight := u256.NewUint(votingMax)
221+
quorumAmount := maxVotingWeight.Uint64() * config.Quorum / 100
222+
210223
proposal := ProposalInfo{
211224
Proposer: proposer,
212225
ProposalType: ParameterChange,
@@ -217,10 +230,10 @@ func ProposeParameterChange(
217230
},
218231
Yea: u256.Zero(),
219232
Nay: u256.Zero(),
220-
MaxVotingWeight: u256.NewUint(votingMax),
233+
MaxVotingWeight: maxVotingWeight,
221234
PossibleAddressWithWeight: possibleAddressWithWeight,
222235
ConfigVersion: uint64(configVersions.Size()),
223-
QuorumAmount: xgns.VotingSupply() * config.Quorum / 100,
236+
QuorumAmount: quorumAmount,
224237
Title: title,
225238
Description: description,
226239
Execution: ExecutionInfo{
@@ -233,16 +246,20 @@ func ProposeParameterChange(
233246
proposals.Set(formatUint64(proposalId), proposal)
234247
latestProposalByProposer.Set(proposer.String(), proposalId)
235248

236-
prevAddr, prevRealm := getPrev()
249+
prevAddr, prevPkgPath := getPrev()
237250
std.Emit(
238251
"ProposeParameterChange",
239252
"prevAddr", prevAddr,
240-
"prevRealm", prevRealm,
253+
"prevRealm", prevPkgPath,
241254
"title", title,
242255
"description", description,
243256
"numToExecute", formatUint64(numToExecute),
244257
"executions", executions,
245-
"internal_proposalId", formatUint64(proposalId),
258+
"proposalId", formatUint64(proposalId),
259+
"quorumAmount", formatUint64(proposal.QuorumAmount),
260+
"maxVotingWeight", proposal.MaxVotingWeight.ToString(),
261+
"configVersion", formatUint64(proposal.ConfigVersion),
262+
"createdAt", formatUint64(proposal.State.CreatedAt),
246263
)
247264

248265
return proposalId

gov/governance/vote.gno

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ type voteWithWeight struct {
2323
}
2424

2525
var (
26-
votes = avl.NewTree() // voteKey(proposalId:user) -> yes/no
27-
userVotes = avl.NewTree() // user -> proposalId -> voteWithWeight
26+
votes = avl.NewTree() // voteKey(proposalId:user) -> yes/no
27+
userVotes = avl.NewTree() // user -> proposalId -> voteWithWeight
28+
accumYesVotes = make(map[uint64]uint64) // proposalId -> yes
29+
accumNoVotes = make(map[uint64]uint64) // proposalId -> no
2830
)
2931

3032
func createVoteKey(pid uint64, voter string) string {
@@ -40,7 +42,8 @@ func getVote(pid uint64, voter string) (bool, bool) {
4042
}
4143

4244
func setVote(pid uint64, voter string, vote bool) {
43-
votes.Set(createVoteKey(pid, voter), vote)
45+
voteKey := createVoteKey(pid, voter)
46+
votes.Set(voteKey, vote)
4447
}
4548

4649
func createUserVoteKey(voter std.Address, pid uint64) string {
@@ -56,6 +59,11 @@ func getUserVote(voter std.Address, pid uint64) (voteWithWeight, bool) {
5659
}
5760

5861
func setUserVote(voter std.Address, pid uint64, vote voteWithWeight) {
62+
if vote.Yes {
63+
accumYesVotes[pid] += vote.Weight
64+
} else {
65+
accumNoVotes[pid] += vote.Weight
66+
}
5967
userVotes.Set(createUserVoteKey(voter, pid), vote)
6068
}
6169

@@ -109,6 +117,8 @@ func Vote(pid uint64, yes bool) string {
109117
"voter", voter.String(),
110118
"yes", voteToString(yes),
111119
"voteWeight", formatUint64(state.userWeight),
120+
"voteYes", formatUint64(accumYesVotes[pid]),
121+
"voteNo", formatUint64(accumNoVotes[pid]),
112122
)
113123

114124
return voteKey
@@ -240,11 +250,11 @@ func Cancel(proposalId uint64) {
240250

241251
proposals.Set(formatUint64(proposalId), proposal)
242252

243-
prevAddr, prevRealm := getPrev()
253+
prevAddr, prevPkgPath := getPrev()
244254
std.Emit(
245255
"Cancel",
246256
"prevAddr", prevAddr,
247-
"prevRealm", prevRealm,
257+
"prevRealm", prevPkgPath,
248258
"proposalId", formatUint64(proposalId),
249259
)
250260
}

gov/staker/staker.gno

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,18 @@ func CollectReward() {
315315
// still, this is a tangled with the policy issue, so should be discussed.
316316
gns.Transfer(a2u(caller), reward)
317317

318-
// TODO:
319318
emissionReward := collectEmissionReward(caller)
320319
if emissionReward > 0 {
321320
std.Emit(
322321
"CollectEmissionReward",
323322
"prevAddr", prevAddr,
324323
"prevRealm", prevPkgPath,
324+
"from", consts.GOV_STAKER_ADDR.String(),
325325
"to", caller.String(),
326326
"emissionRewardAmount", formatUint(emissionReward),
327327
)
328328
}
329329

330-
// TODO::
331330
collectedFees := collectProtocolFeeReward(caller)
332331
for tokenPath, amount := range collectedFees {
333332
if tokenPath == consts.WUGNOT_PATH {
@@ -338,6 +337,8 @@ func CollectReward() {
338337
"prevAddr", prevAddr,
339338
"prevRealm", prevPkgPath,
340339
"tokenPath", tokenPath,
340+
"from", consts.GOV_STAKER_ADDR.String(),
341+
"to", caller.String(),
341342
"collectedAmount", formatUint(amount),
342343
)
343344
}
@@ -354,27 +355,28 @@ func CollectRewardFromLaunchPad(to std.Address) {
354355

355356
prevAddr, prevPkgPath := getPrev()
356357

357-
// TODO::
358358
emissionReward := collectEmissionReward(to)
359359
if emissionReward > 0 {
360360
std.Emit(
361361
"CollectEmissionFromLaunchPad",
362362
"prevAddr", prevAddr,
363363
"prevRealm", prevPkgPath,
364+
"from", consts.GOV_STAKER_ADDR.String(),
364365
"to", to.String(),
365-
"amount", formatUint(emissionReward),
366+
"emissionRewardAmount", formatUint(emissionReward),
366367
)
367368
}
368369

369-
// TODO::
370370
collectedFees := collectProtocolFeeReward(to)
371371
for tokenPath, amount := range collectedFees {
372372
std.Emit(
373373
"CollectProtocolFeeFromLaunchPad",
374374
"prevAddr", prevAddr,
375375
"prevRealm", prevPkgPath,
376376
"tokenPath", tokenPath,
377-
"amount", formatUint(amount),
377+
"from", consts.GOV_STAKER_ADDR.String(),
378+
"to", caller.String(),
379+
"collectedAmount", formatUint(amount),
378380
)
379381
}
380382
}

0 commit comments

Comments
 (0)