Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: event message change #483

Merged
merged 5 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contract/r/gnoswap/common/halt.gno
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ func SetHalt(halt bool) {
func setHalt(halt bool) {
halted = halt

prevAddr, prevRealm := getPrevAsString()
prevAddr, prevPkgPath := getPrevAsString()
std.Emit(
"setHalt",
"prevAddr", prevAddr,
"prevRealm", prevRealm,
"prevRealm", prevPkgPath,
"halt", strconv.FormatBool(halt),
)
}
5 changes: 3 additions & 2 deletions contract/r/gnoswap/community_pool/community_pool.gno
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ func transferToken(tokenPath string, to std.Address, amount uint64) {
teller := common.GetTokenTeller(tokenPath)
checkErr(teller.Transfer(to, amount))

prevAddr, prevRealm := getPrevAsString()
prevAddr, prevPkgPath := getPrevAsString()

std.Emit(
"TransferToken",
"prevAddr", prevAddr,
"prevRealm", prevRealm,
"prevRealm", prevPkgPath,
"tokenPath", tokenPath,
"to", to.String(),
"amount", strconv.FormatUint(amount, 10),
Expand Down
23 changes: 19 additions & 4 deletions contract/r/gnoswap/emission/distribution.gno
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ func changeDistributionPcts(
"ChangeDistributionPct",
"prevAddr", prevAddr,
"prevRealm", prevPkgPath,
"target01", formatInt(target01),
"target01", targetToStr(target01),
"pct01", formatUint(pct01),
"target02", formatInt(target02),
"target02", targetToStr(target02),
"pct02", formatUint(pct02),
"target03", formatInt(target03),
"target03", targetToStr(target03),
"pct03", formatUint(pct03),
"target04", formatInt(target04),
"target04", targetToStr(target04),
"pct04", formatUint(pct04),
)
}
Expand Down Expand Up @@ -287,3 +287,18 @@ func GetHalvingBlocksInRange(start, end int64) ([]int64, []uint64) {
}
return halvingBlocks, halvingEmissions
}

func targetToStr(target int) string {
switch target {
case LIQUIDITY_STAKER:
return "LIQUIDITY_STAKER"
case DEVOPS:
return "DEVOPS"
case COMMUNITY_POOL:
return "COMMUNITY_POOL"
case GOV_STAKER:
return "GOV_STAKER"
default:
return "UNKNOWN"
r3v4s marked this conversation as resolved.
Show resolved Hide resolved
}
}
26 changes: 16 additions & 10 deletions contract/r/gnoswap/emission/emission.gno
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ func MintAndDistributeGns() uint64 {
return 0
}
// Mint new tokens and add any leftover amounts from previous distribution
mintedEmissionRewardAmount := gns.MintGns(consts.EMISSION_ADDR)
mintedEmissionRewardAmount := gns.MintGns(a2u(consts.EMISSION_ADDR))

distributableAmount := mintedEmissionRewardAmount
prevLeftAmount := GetLeftGNSAmount()
if hasLeftGNSAmount() {
mintedEmissionRewardAmount += GetLeftGNSAmount()
distributableAmount += prevLeftAmount
setLeftGNSAmount(0)
}
// Distribute tokens and track any undistributed amount
distributedGNSAmount := distributeToTarget(mintedEmissionRewardAmount)
if mintedEmissionRewardAmount != distributedGNSAmount {
setLeftGNSAmount(mintedEmissionRewardAmount - distributedGNSAmount)
distributedGNSAmount := distributeToTarget(distributableAmount)
if distributableAmount != distributedGNSAmount {
setLeftGNSAmount(distributableAmount - distributedGNSAmount)
}

// Emit event with distribution details
Expand All @@ -44,11 +47,14 @@ func MintAndDistributeGns() uint64 {
"MintAndDistributeGns",
"prevAddr", prevAddr,
"prevRealm", prevPkgPath,
"internal_lastHeight", formatInt(lastExecutedHeight),
"internal_height", formatInt(currentHeight),
"internal_time", formatInt(time.Now().Unix()),
"internal_amount", formatUint(mintedEmissionRewardAmount),
"internal_totalSupply", formatUint(gns.TotalSupply()),
"lastHeight", formatInt(lastExecutedHeight),
"currentHeight", formatInt(currentHeight),
"currentTimestamp", formatInt(time.Now().Unix()),
"mintedAmount", formatUint(mintedEmissionRewardAmount),
"prevLeftAmount", formatUint(prevLeftAmount),
"distributedAmount", formatUint(distributedGNSAmount),
"currentLeftAmount", formatUint(GetLeftGNSAmount()),
"gnsTotalSupply", formatUint(gns.TotalSupply()),
)

setLastExecutedHeight(currentHeight)
Expand Down
4 changes: 2 additions & 2 deletions contract/r/gnoswap/gnft/gnft.gno
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ func setTokenURI(tid grc721.TokenID, tURI grc721.TokenURI) error {
"SetTokenURI",
"prevAddr", prevAddr,
"prevRealm", prevPkgPath,
"lpTokenId", "tid",
"tokenURI", "tURI",
"lpTokenId", string(tid),
"tokenURI", string(tURI),
)

return nil
Expand Down
34 changes: 30 additions & 4 deletions contract/r/gnoswap/gns/halving.gno
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,26 @@ func SetAvgBlockTimeInMsByAdmin(ms int64) {
prevAvgBlockTimeInMs := GetAvgBlockTimeInMs()
setAvgBlockTimeInMs(ms)

halvingData := GetEmissionState().getHalvingData()
prevAddr, prevPkgPath := getPrev()
std.Emit(
"SetAvgBlockTimeInMsByAdmin",
"prevAddr", prevAddr,
"prevRealm", prevPkgPath,
"prevAvgBlockTimeInMs", formatInt(prevAvgBlockTimeInMs),
"avgBlockTimeInMs", formatInt(ms),
"prevAvgBlockTimeMs", formatInt(prevAvgBlockTimeInMs),
"newAvgBlockTimeMs", formatInt(ms),
"endBlock1Year", formatInt(halvingData.getEndBlockHeight(1)),
"endBlock2Year", formatInt(halvingData.getEndBlockHeight(2)),
"endBlock3Year", formatInt(halvingData.getEndBlockHeight(3)),
"endBlock4Year", formatInt(halvingData.getEndBlockHeight(4)),
"endBlock5Year", formatInt(halvingData.getEndBlockHeight(4)),
"endBlock6Year", formatInt(halvingData.getEndBlockHeight(5)),
"endBlock7Year", formatInt(halvingData.getEndBlockHeight(6)),
"endBlock8Year", formatInt(halvingData.getEndBlockHeight(7)),
"endBlock9Year", formatInt(halvingData.getEndBlockHeight(8)),
"endBlock10Year", formatInt(halvingData.getEndBlockHeight(9)),
"endBlock11Year", formatInt(halvingData.getEndBlockHeight(10)),
"endBlock12Year", formatInt(halvingData.getEndBlockHeight(11)),
)
}

Expand All @@ -351,13 +364,26 @@ func SetAvgBlockTimeInMs(ms int64) {
prevAvgBlockTimeInMs := GetAvgBlockTimeInMs()
setAvgBlockTimeInMs(ms)

halvingData := GetEmissionState().getHalvingData()
prevAddr, prevPkgPath := getPrev()
std.Emit(
"SetAvgBlockTimeInMs",
"prevAddr", prevAddr,
"prevRealm", prevPkgPath,
"prevAvgBlockTimeInMs", formatInt(prevAvgBlockTimeInMs),
"avgBlockTimeInMs", formatInt(ms),
"prevAvgBlockTimeMs", formatInt(prevAvgBlockTimeInMs),
"newAvgBlockTimeMs", formatInt(ms),
"endBlock1Year", formatInt(halvingData.getEndBlockHeight(1)),
"endBlock2Year", formatInt(halvingData.getEndBlockHeight(2)),
"endBlock3Year", formatInt(halvingData.getEndBlockHeight(3)),
"endBlock4Year", formatInt(halvingData.getEndBlockHeight(4)),
"endBlock5Year", formatInt(halvingData.getEndBlockHeight(4)),
"endBlock6Year", formatInt(halvingData.getEndBlockHeight(5)),
"endBlock7Year", formatInt(halvingData.getEndBlockHeight(6)),
"endBlock8Year", formatInt(halvingData.getEndBlockHeight(7)),
"endBlock9Year", formatInt(halvingData.getEndBlockHeight(8)),
"endBlock10Year", formatInt(halvingData.getEndBlockHeight(9)),
"endBlock11Year", formatInt(halvingData.getEndBlockHeight(10)),
"endBlock12Year", formatInt(halvingData.getEndBlockHeight(11)),
)
}

Expand Down
6 changes: 4 additions & 2 deletions contract/r/gnoswap/gov/governance/config.gno
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ func reconfigure(
en.MintAndDistributeGns()
updateProposalsState()

newVersion := getLatestVersion() + 1
prevVersion := getLatestVersion()
newVersion := prevVersion + 1

config = Config{
VotingStartDelay: votingStartDelay,
Expand All @@ -121,8 +122,9 @@ func reconfigure(
"quorum", formatUint(config.Quorum),
"proposalCreationThreshold", formatUint(config.ProposalCreationThreshold),
"executionDelay", formatUint(config.ExecutionDelay),
"executionWindow", formatUint(config.ExecutionWindow),
"executionPeriod", formatUint(config.ExecutionWindow),
"newConfigVersion", formatUint(newVersion),
"prevConfigVersion", formatUint(prevVersion),
)

return newVersion
Expand Down
45 changes: 31 additions & 14 deletions contract/r/gnoswap/gov/governance/proposal.gno
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func ProposeText(
// votingMax does not include quantities delegated through Launchpad.
votingMax, possibleAddressWithWeight := gs.GetPossibleVotingAddressWithWeight(now - config.VotingWeightSmoothingDuration)

maxVotingWeight := u256.NewUint(votingMax)
quorumAmount := maxVotingWeight.Uint64() * config.Quorum / 100

proposal := ProposalInfo{
Proposer: proposer,
ProposalType: Text,
Expand All @@ -63,10 +66,10 @@ func ProposeText(
},
Yea: u256.Zero(),
Nay: u256.Zero(),
MaxVotingWeight: u256.NewUint(votingMax),
MaxVotingWeight: maxVotingWeight,
PossibleAddressWithWeight: possibleAddressWithWeight,
ConfigVersion: uint64(configVersions.Size()), // use latest config version
QuorumAmount: xgns.VotingSupply() * config.Quorum / 100,
QuorumAmount: quorumAmount,
Title: title,
Description: description,
}
Expand All @@ -83,10 +86,10 @@ func ProposeText(
"title", title,
"description", description,
"proposalId", formatUint(proposalId),
"quorumAmount", formatUint(proposal.QuorumAmount),
"maxVotingWeight", proposal.MaxVotingWeight.ToString(),
"createdAt", formatUint(proposal.State.CreatedAt),
"configVersion", formatUint(proposal.ConfigVersion),
"quorumAmount", formatUint(proposal.QuorumAmount),
"createdAt", formatUint(proposal.State.CreatedAt),
)
return proposalId
}
Expand Down Expand Up @@ -120,6 +123,9 @@ func ProposeCommunityPoolSpend(
now := uint64(time.Now().Unix())
votingMax, possibleAddressWithWeight := gs.GetPossibleVotingAddressWithWeight(now - config.VotingWeightSmoothingDuration)

maxVotingWeight := u256.NewUint(votingMax)
quorumAmount := maxVotingWeight.Uint64() * config.Quorum / 100

proposal := ProposalInfo{
Proposer: proposer,
ProposalType: CommunityPoolSpend,
Expand All @@ -130,10 +136,10 @@ func ProposeCommunityPoolSpend(
},
Yea: u256.Zero(),
Nay: u256.Zero(),
MaxVotingWeight: u256.NewUint(votingMax),
MaxVotingWeight: maxVotingWeight,
PossibleAddressWithWeight: possibleAddressWithWeight,
ConfigVersion: uint64(configVersions.Size()),
QuorumAmount: xgns.VotingSupply() * config.Quorum / 100,
QuorumAmount: quorumAmount,
Title: title,
Description: description,
CommunityPoolSpend: CommunityPoolSpendInfo{
Expand All @@ -147,17 +153,21 @@ func ProposeCommunityPoolSpend(
proposals.Set(formatUint(proposalId), proposal)
latestProposalByProposer.Set(proposer.String(), proposalId)

prevAddr, prevRealm := getPrev()
prevAddr, prevPkgPath := getPrev()
std.Emit(
"ProposeCommunityPoolSpend",
"prevAddr", prevAddr,
"prevRealm", prevRealm,
"prevRealm", prevPkgPath,
"title", title,
"description", description,
"to", to.String(),
"tokenPath", tokenPath,
"amount", formatUint(amount),
"internal_proposalId", formatUint(proposalId),
"proposalId", formatUint(proposalId),
"quorumAmount", formatUint(proposal.QuorumAmount),
"maxVotingWeight", proposal.MaxVotingWeight.ToString(),
"configVersion", formatUint(proposal.ConfigVersion),
"createdAt", formatUint(proposal.State.CreatedAt),
)

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

maxVotingWeight := u256.NewUint(votingMax)
quorumAmount := maxVotingWeight.Uint64() * config.Quorum / 100

proposal := ProposalInfo{
Proposer: proposer,
ProposalType: ParameterChange,
Expand All @@ -217,10 +230,10 @@ func ProposeParameterChange(
},
Yea: u256.Zero(),
Nay: u256.Zero(),
MaxVotingWeight: u256.NewUint(votingMax),
MaxVotingWeight: maxVotingWeight,
PossibleAddressWithWeight: possibleAddressWithWeight,
ConfigVersion: uint64(configVersions.Size()),
QuorumAmount: xgns.VotingSupply() * config.Quorum / 100,
QuorumAmount: quorumAmount,
Title: title,
Description: description,
Execution: ExecutionInfo{
Expand All @@ -233,16 +246,20 @@ func ProposeParameterChange(
proposals.Set(formatUint(proposalId), proposal)
latestProposalByProposer.Set(proposer.String(), proposalId)

prevAddr, prevRealm := getPrev()
prevAddr, prevPkgPath := getPrev()
std.Emit(
"ProposeParameterChange",
"prevAddr", prevAddr,
"prevRealm", prevRealm,
"prevRealm", prevPkgPath,
"title", title,
"description", description,
"numToExecute", formatUint(numToExecute),
"executions", executions,
"internal_proposalId", formatUint(proposalId),
"proposalId", formatUint(proposalId),
"quorumAmount", formatUint(proposal.QuorumAmount),
"maxVotingWeight", proposal.MaxVotingWeight.ToString(),
"configVersion", formatUint(proposal.ConfigVersion),
"createdAt", formatUint(proposal.State.CreatedAt),
)

return proposalId
Expand Down
20 changes: 15 additions & 5 deletions contract/r/gnoswap/gov/governance/vote.gno
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ type voteWithWeight struct {
}

var (
votes = avl.NewTree() // voteKey(proposalId:user) -> yes/no
userVotes = avl.NewTree() // user -> proposalId -> voteWithWeight
votes = avl.NewTree() // voteKey(proposalId:user) -> yes/no
userVotes = avl.NewTree() // user -> proposalId -> voteWithWeight
accumYesVotes = make(map[uint64]uint64) // proposalId -> yes
accumNoVotes = make(map[uint64]uint64) // proposalId -> no
)

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

func setVote(pid uint64, voter string, vote bool) {
votes.Set(createVoteKey(pid, voter), vote)
voteKey := createVoteKey(pid, voter)
votes.Set(voteKey, vote)
}

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

func setUserVote(voter std.Address, pid uint64, vote voteWithWeight) {
if vote.Yes {
accumYesVotes[pid] += vote.Weight
} else {
accumNoVotes[pid] += vote.Weight
}
userVotes.Set(createUserVoteKey(voter, pid), vote)
}

Expand Down Expand Up @@ -109,6 +117,8 @@ func Vote(pid uint64, yes bool) string {
"voter", voter.String(),
"yes", voteToString(yes),
"voteWeight", formatUint(state.userWeight),
"voteYes", formatUint(accumYesVotes[pid]),
"voteNo", formatUint(accumNoVotes[pid]),
)

return voteKey
Expand Down Expand Up @@ -240,11 +250,11 @@ func Cancel(proposalId uint64) {

proposals.Set(formatUint(proposalId), proposal)

prevAddr, prevRealm := getPrev()
prevAddr, prevPkgPath := getPrev()
std.Emit(
"Cancel",
"prevAddr", prevAddr,
"prevRealm", prevRealm,
"prevRealm", prevPkgPath,
"proposalId", formatUint(proposalId),
)
}
Loading
Loading