Skip to content

Commit

Permalink
refactor: event message
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyhyde committed Jan 8, 2025
1 parent d973fab commit f249136
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 139 deletions.
7 changes: 4 additions & 3 deletions _deploy/r/gnoswap/common/halt.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"std"
"strconv"

"gno.land/p/demo/ufmt"
"gno.land/r/gnoswap/v1/consts"
Expand Down Expand Up @@ -89,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,
"halt", ufmt.Sprintf("%t", halt),
"prevRealm", prevPkgPath,
"halt", strconv.FormatBool(halt),
)
}
3 changes: 2 additions & 1 deletion _deploy/r/gnoswap/common/limit_caller.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"std"
"strconv"

"gno.land/p/demo/ufmt"
)
Expand Down Expand Up @@ -47,6 +48,6 @@ func SetLimitCaller(v bool) {
"SetLimitCaller",
"prevAddr", prevAddr,
"prevRealm", prevPkgPath,
"limitCaller", ufmt.Sprintf("%t", v),
"limitCaller", strconv.FormatBool(v),
)
}
4 changes: 2 additions & 2 deletions _deploy/r/gnoswap/gnft/gnft.gno
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,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
42 changes: 34 additions & 8 deletions _deploy/r/gnoswap/gns/halving.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"strconv"
"time"

"gno.land/p/demo/ufmt"

"gno.land/r/gnoswap/v1/common"
"gno.land/r/gnoswap/v1/consts"

Expand Down Expand Up @@ -125,14 +123,28 @@ func SetAvgBlockTimeInMsByAdmin(ms int64) {
panic(err)
}

prevAvgBlockTimeMs := avgBlockTimeMs
setAvgBlockTimeInMs(ms)

prevAddr, prevRealm := getPrev()
prevAddr, prevPkgPath := getPrev()
std.Emit(
"SetAvgBlockTimeInMsByAdmin",
"prevAddr", prevAddr,
"prevRealm", prevRealm,
"ms", ufmt.Sprintf("%d", ms),
"prevRealm", prevPkgPath,
"newAvgBlockTimeMs", strconv.FormatInt(ms, 10),
"prevAvgBlockTimeMs", strconv.FormatInt(prevAvgBlockTimeMs, 10),
"endBlock1Year", strconv.FormatInt(halvingYearEndBlock[0], 10),
"endBlock2Year", strconv.FormatInt(halvingYearEndBlock[1], 10),
"endBlock3Year", strconv.FormatInt(halvingYearEndBlock[2], 10),
"endBlock4Year", strconv.FormatInt(halvingYearEndBlock[3], 10),
"endBlock5Year", strconv.FormatInt(halvingYearEndBlock[4], 10),
"endBlock6Year", strconv.FormatInt(halvingYearEndBlock[5], 10),
"endBlock7Year", strconv.FormatInt(halvingYearEndBlock[6], 10),
"endBlock8Year", strconv.FormatInt(halvingYearEndBlock[7], 10),
"endBlock9Year", strconv.FormatInt(halvingYearEndBlock[8], 10),
"endBlock10Year", strconv.FormatInt(halvingYearEndBlock[9], 10),
"endBlock11Year", strconv.FormatInt(halvingYearEndBlock[10], 10),
"endBlock12Year", strconv.FormatInt(halvingYearEndBlock[11], 10),
)
}

Expand All @@ -144,14 +156,28 @@ func SetAvgBlockTimeInMs(ms int64) {
panic(err)
}

prevAvgBlockTimeMs := avgBlockTimeMs
setAvgBlockTimeInMs(ms)

prevAddr, prevRealm := getPrev()
prevAddr, prevPkgPath := getPrev()
std.Emit(
"SetAvgBlockTimeInMs",
"prevAddr", prevAddr,
"prevRealm", prevRealm,
"ms", ufmt.Sprintf("%d", ms),
"prevRealm", prevPkgPath,
"newAvgBlockTimeMs", strconv.FormatInt(ms, 10),
"prevAvgBlockTimeMs", strconv.FormatInt(prevAvgBlockTimeMs, 10),
"endBlock1Year", strconv.FormatInt(halvingYearEndBlock[0], 10),
"endBlock2Year", strconv.FormatInt(halvingYearEndBlock[1], 10),
"endBlock3Year", strconv.FormatInt(halvingYearEndBlock[2], 10),
"endBlock4Year", strconv.FormatInt(halvingYearEndBlock[3], 10),
"endBlock5Year", strconv.FormatInt(halvingYearEndBlock[4], 10),
"endBlock6Year", strconv.FormatInt(halvingYearEndBlock[5], 10),
"endBlock7Year", strconv.FormatInt(halvingYearEndBlock[6], 10),
"endBlock8Year", strconv.FormatInt(halvingYearEndBlock[7], 10),
"endBlock9Year", strconv.FormatInt(halvingYearEndBlock[8], 10),
"endBlock10Year", strconv.FormatInt(halvingYearEndBlock[9], 10),
"endBlock11Year", strconv.FormatInt(halvingYearEndBlock[10], 10),
"endBlock12Year", strconv.FormatInt(halvingYearEndBlock[11], 10),
)
}

Expand Down
10 changes: 5 additions & 5 deletions community_pool/community_pool.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package community_pool

import (
"std"

"gno.land/p/demo/ufmt"
"strconv"

"gno.land/r/gnoswap/v1/common"
)
Expand All @@ -30,14 +29,15 @@ 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", ufmt.Sprintf("%d", amount),
"amount", strconv.FormatUint(amount, 10),
)
}

Expand Down
23 changes: 19 additions & 4 deletions emission/distribution.gno
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ func changeDistributionPcts(
"ChangeDistributionPct",
"prevAddr", prevAddr,
"prevRealm", prevPkgPath,
"target01", strconv.Itoa(target01),
"target01", targetToStr(target01),
"pct01", strconv.FormatUint(pct01, 10),
"target02", strconv.Itoa(target02),
"target02", targetToStr(target02),
"pct02", strconv.FormatUint(pct02, 10),
"target03", strconv.Itoa(target03),
"target03", targetToStr(target03),
"pct03", strconv.FormatUint(pct03, 10),
"target04", strconv.Itoa(target04),
"target04", targetToStr(target04),
"pct04", strconv.FormatUint(pct04, 10),
)
}
Expand Down Expand Up @@ -260,3 +260,18 @@ func ClearDistributedToGovStaker() {
func setDistributionBpsPct(target int, pct uint64) {
distributionBpsPct.Set(strconv.Itoa(target), pct)
}

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"
}
}
28 changes: 16 additions & 12 deletions emission/emission.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package emission

import (
"std"
"strconv"
"time"

"gno.land/p/demo/ufmt"

"gno.land/r/gnoswap/v1/common"
"gno.land/r/gnoswap/v1/consts"
"gno.land/r/gnoswap/v1/gns"
)
Expand All @@ -32,15 +30,18 @@ func MintAndDistributeGns() uint64 {

// Mint new tokens and add any leftover amounts from previous distribution
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 @@ -49,11 +50,14 @@ func MintAndDistributeGns() uint64 {
"MintAndDistributeGns",
"prevAddr", prevAddr,
"prevRealm", prevPkgPath,
"internal_lastHeight", ufmt.Sprintf("%d", lastExecutedHeight),
"internal_height", ufmt.Sprintf("%d", currentHeight),
"internal_time", ufmt.Sprintf("%d", time.Now().Unix()),
"internal_amount", ufmt.Sprintf("%d", mintedEmissionRewardAmount),
"internal_totalSupply", ufmt.Sprintf("%d", gns.TotalSupply()),
"lastHeight", strconv.FormatInt(lastExecutedHeight, 10),
"currentHeight", strconv.FormatInt(currentHeight, 10),
"currentTimestamp", strconv.FormatInt(time.Now().Unix(), 10),
"mintedAmount", strconv.FormatUint(mintedEmissionRewardAmount, 10),
"prevLeftAmount", strconv.FormatUint(prevLeftAmount, 10),
"distributedAmount", strconv.FormatUint(distributedGNSAmount, 10),
"currentLeftAmount", strconv.FormatUint(GetLeftGNSAmount(), 10),
"gnsTotalSupply", strconv.FormatUint(gns.TotalSupply(), 10),
)

setLastExecutedHeight(currentHeight)
Expand Down
23 changes: 12 additions & 11 deletions pool/pool.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pool

import (
"std"
"strconv"

"gno.land/p/demo/ufmt"

Expand Down Expand Up @@ -267,11 +268,11 @@ func setFeeProtocolInternal(feeProtocol0, feeProtocol1 uint8, eventName string)
eventName,
"prevAddr", prevAddr,
"prevRealm", prevPkgPath,
"feeProtocol0Old", ufmt.Sprintf("%d", feeProtocol0Old),
"feeProtocol1Old", ufmt.Sprintf("%d", feeProtocol1Old),
"feeProtocol0", ufmt.Sprintf("%d", feeProtocol0),
"feeProtocol1", ufmt.Sprintf("%d", feeProtocol1),
"internal_newFee", ufmt.Sprintf("%d", newFee),
"prevFeeProtocol0", strconv.FormatUint(uint64(feeProtocol0Old), 10),
"prevFeeProtocol1", strconv.FormatUint(uint64(feeProtocol1Old), 10),
"feeProtocol0", strconv.FormatUint(uint64(feeProtocol0), 10),
"feeProtocol1", strconv.FormatUint(uint64(feeProtocol1), 10),
"newFee", strconv.FormatUint(uint64(newFee), 10),
)
}

Expand Down Expand Up @@ -383,10 +384,10 @@ func CollectProtocolByAdmin(
"prevRealm", prevPkgPath,
"token0Path", token0Path,
"token1Path", token1Path,
"fee", ufmt.Sprintf("%d", fee),
"fee", strconv.FormatUint(uint64(fee), 10),
"recipient", recipient.String(),
"internal_amount0", amount0,
"internal_amount1", amount1,
"collectedAmount0", amount0,
"collectedAmount1", amount1,
)

return amount0, amount1
Expand Down Expand Up @@ -421,10 +422,10 @@ func CollectProtocol(
"prevRealm", prevPkgPath,
"token0Path", token0Path,
"token1Path", token1Path,
"fee", ufmt.Sprintf("%d", fee),
"fee", strconv.FormatUint(uint64(fee), 10),
"recipient", recipient.String(),
"internal_amount0", amount0,
"internal_amount1", amount1,
"collectedAmount0", amount0,
"collectedAmount1", amount1,
)

return amount0, amount1
Expand Down
14 changes: 9 additions & 5 deletions pool/pool_manager.gno
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,28 @@ func CreatePool(
"PoolCreationFee",
"prevAddr", prevAddr,
"prevRealm", prevRealm,
"internal_poolPath", poolPath,
"internal_tokenPath", consts.GNS_PATH,
"internal_amount", ufmt.Sprintf("%d", poolCreationFee),
"poolPath", poolPath,
"feeTokenPath", consts.GNS_PATH,
"feeAmount", strconv.FormatUint(poolCreationFee, 10),
)
}

pool = newPool(poolInfo)
pools.Set(poolPath, pool)

currentTick := common.TickMathGetTickAtSqrtRatio(sqrtPriceX96)

std.Emit(
"CreatePool",
"prevAddr", prevAddr,
"prevRealm", prevRealm,
"token0Path", token0Path,
"token1Path", token1Path,
"fee", ufmt.Sprintf("%d", fee),
"fee", strconv.FormatUint(uint64(fee), 10),
"sqrtPriceX96", sqrtPriceX96,
"internal_poolPath", poolPath,
"poolPath", poolPath,
"tick", strconv.FormatInt(int64(currentTick), 10),
"tickSpacing", strconv.FormatInt(int64(poolInfo.TickSpacing()), 10),
)
}

Expand Down
22 changes: 11 additions & 11 deletions pool/protocol_fee_pool_creation.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package pool

import (
"std"
"strconv"

"gno.land/p/demo/ufmt"
"gno.land/r/gnoswap/v1/common"
)

Expand All @@ -23,43 +23,43 @@ func GetPoolCreationFee() uint64 {
// Only governance contract can execute this function via proposal
// ref: https://docs.gnoswap.io/contracts/pool/protocol_fee_pool_creation.gno#setpoolcreationfee
func SetPoolCreationFee(fee uint64) {
// TODO:
// 1. IsHalted name chnage to assertIsHalted
common.IsHalted()
caller := std.PrevRealm().Addr()
assertOnlyNotHalted()
caller := getPrevAddr()
if err := common.GovernanceOnly(caller); err != nil {
panic(err.Error())
}
prevPoolCreationFee := poolCreationFee
setPoolCreationFee(fee)

prevAddr, prevPkgPath := getPrevAsString()
std.Emit(
"SetPoolCreationFee",
"prevAddr", prevAddr,
"prevRealm", prevPkgPath,
"fee", ufmt.Sprintf("%d", fee),
"prevFee", strconv.FormatUint(prevPoolCreationFee, 10),
"newFee", strconv.FormatUint(fee, 10),
)
}

// SetPoolCreationFeeByAdmin sets the poolCreationFee by Admin.
// Only admin can execute this function.
func SetPoolCreationFeeByAdmin(fee uint64) {
// TODO:
// 1. IsHalted name chnage to assertIsHalted
common.IsHalted()
assertOnlyNotHalted()

caller := std.PrevRealm().Addr()
caller := getPrevAddr()
if err := common.AdminOnly(caller); err != nil {
panic(err.Error())
}
prevPoolCreationFee := poolCreationFee
setPoolCreationFee(fee)

prevAddr, prevPkgPath := getPrevAsString()
std.Emit(
"SetPoolCreationFeeByAdmin",
"prevAddr", prevAddr,
"prevRealm", prevPkgPath,
"fee", ufmt.Sprintf("%d", fee),
"prevFee", strconv.FormatUint(prevPoolCreationFee, 10),
"newFee", strconv.FormatUint(fee, 10),
)
}

Expand Down
Loading

0 comments on commit f249136

Please sign in to comment.