Skip to content

Commit

Permalink
refactor: event message change (#483)
Browse files Browse the repository at this point in the history
* refactor: event message change
* refactor: staker event
* refactor: staker and gns event update

---------

Co-authored-by: Dongwon <[email protected]>
  • Loading branch information
2 people authored and moul committed Jan 24, 2025
1 parent 4f4dd5b commit 575b694
Show file tree
Hide file tree
Showing 27 changed files with 424 additions and 262 deletions.
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"
}
}
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
8 changes: 8 additions & 0 deletions contract/r/gnoswap/gns/gns.gno
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ func calculateAmountToMint(fromHeight, toHeight int64) uint64 {
setHalvingYearMintAmount(year, GetHalvingYearMintAmount(year)+yearAmountToMint)
setHalvingYearLeftAmount(year, GetHalvingYearLeftAmount(year)-yearAmountToMint)

std.Emit(
"CalculateAmountToMint",
"fromHeight", formatInt(curFrom),
"toHeight", formatInt(mintUntilHeight),
"year", formatInt(year),
"singleBlockAmount", formatUint(singleBlockAmount),
)

// update fromHeight for next year (if necessary)
curFrom = mintUntilHeight + 1
if curFrom > toHeight {
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
Loading

0 comments on commit 575b694

Please sign in to comment.