From d70314817e6faf1b68260bf0fd53de823a879930 Mon Sep 17 00:00:00 2001 From: 0xTopaz Date: Thu, 9 Jan 2025 04:22:37 +0900 Subject: [PATCH] refactor: event message --- launchpad/deposit.gno | 34 ++++++++++++++++++---------------- launchpad/launchpad.gno | 14 +++++++------- launchpad/reward.gno | 30 ++++++++++++++++-------------- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/launchpad/deposit.gno b/launchpad/deposit.gno index 2bd3671a..1971a03e 100644 --- a/launchpad/deposit.gno +++ b/launchpad/deposit.gno @@ -3,6 +3,7 @@ package launchpad import ( "errors" "std" + "strconv" "time" "gno.land/p/demo/ufmt" @@ -158,7 +159,8 @@ func updateDepositIndices(deposit Deposit, state *DepositState) { // processFirstDeposit handles the first deposit for a project tier func processFirstDeposit(info ProjectTierInfo) (Tier, error) { - if info.Tier.totalParticipant != 0 { + info.Tier.totalParticipant++ + if info.Tier.totalParticipant > 1 { return info.Tier, nil } @@ -235,10 +237,10 @@ func DepositGns(targetProjectTierId string, amount uint64) string { "prevAddr", prevAddr, "prevRealm", prevPkgPath, "targetProjectTierId", targetProjectTierId, - "amount", ufmt.Sprintf("%d", amount), + "amount", strconv.FormatUint(amount, 10), "depositId", deposit.id, - "claimableHeight", ufmt.Sprintf("%d", deposit.claimableHeight), - "claimableTime", ufmt.Sprintf("%d", deposit.claimableTime), + "claimableHeight", strconv.FormatUint(deposit.claimableHeight, 10), + "claimableTime", strconv.FormatUint(deposit.claimableTime, 10), ) // Process first deposit if applicable @@ -249,14 +251,14 @@ func DepositGns(targetProjectTierId string, amount uint64) string { if updatedTier.started.height == info.Height { std.Emit( - "FirstDepoistForProjectTier", + "FirstDepositForProjectTier", "prevAddr", prevAddr, "prevRealm", prevPkgPath, "targetProjectTierId", targetProjectTierId, - "amount", ufmt.Sprintf("%d", amount), + "amount", strconv.FormatUint(amount, 10), "depositId", deposit.id, - "claimableHeight", ufmt.Sprintf("%d", deposit.claimableHeight), - "claimableTime", ufmt.Sprintf("%d", deposit.claimableTime), + "claimableHeight", strconv.FormatUint(deposit.claimableHeight, 10), + "claimableTime", strconv.FormatUint(deposit.claimableTime, 10), "tierAmountPerBlockX96", updatedTier.tierAmountPerBlockX96.ToString(), ) } @@ -279,7 +281,7 @@ func processDepositCollection( ) (uint64, error) { totalAmount := uint64(0) // gnsToUser height := uint64(std.GetHeight()) - prevAddr, prevRealm := getPrev() + prevAddr, prevPkgPath := getPrev() for _, dpstId := range dpsts { dpst := deposits[dpstId] @@ -313,18 +315,18 @@ func processDepositCollection( std.Emit( "CollectDepositGnsByProjectId", "prevAddr", prevAddr, - "prevRealm", prevRealm, + "prevRealm", prevPkgPath, "projectId", projectId, "depositId", dpstId, - "amount", ufmt.Sprintf("%d", dpst.amount), + "amount", strconv.FormatUint(dpst.amount, 10), ) } else { std.Emit( "CollectDepositGns", "prevAddr", prevAddr, - "prevRealm", prevRealm, + "prevRealm", prevPkgPath, "depositId", dpstId, - "amount", ufmt.Sprintf("%d", dpst.amount), + "amount", strconv.FormatUint(dpst.amount, 10), ) } } @@ -443,13 +445,13 @@ func CollectDepositGnsByDepositId(depositId string) uint64 { gs.SetAmountByProjectWallet(project.recipient, amount, false) // Emit collection event - prevAddr, prevRealm := getPrev() + prevAddr, prevPkgPath := getPrev() std.Emit( "CollectDepositGnsByDepositId", "prevAddr", prevAddr, - "prevRealm", prevRealm, + "prevRealm", prevPkgPath, "depositId", depositId, - "amount", ufmt.Sprintf("%d", amount), + "amount", strconv.FormatUint(amount, 10), ) // Process token transfers if amount > 0 diff --git a/launchpad/launchpad.gno b/launchpad/launchpad.gno index 558676e3..a84ddb37 100644 --- a/launchpad/launchpad.gno +++ b/launchpad/launchpad.gno @@ -301,13 +301,13 @@ func TransferLeftFromProjectByAdmin(projectId string, recipient std.Address) uin "projectId", projectId, "recipient", recipient.String(), "tokenPath", project.tokenPath, - "leftReward", ufmt.Sprintf("%d", leftReward), - "tier30Full", ufmt.Sprintf("%d", project.tiers[30].tierAmount), - "tier30Left", ufmt.Sprintf("%d", project.tiers[30].tierAmount-project.tiers[30].calculatedAmount), - "tier90Full", ufmt.Sprintf("%d", project.tiers[90].tierAmount), - "tier90Left", ufmt.Sprintf("%d", project.tiers[90].tierAmount-project.tiers[90].calculatedAmount), - "tier180Full", ufmt.Sprintf("%d", project.tiers[180].tierAmount), - "tier180Left", ufmt.Sprintf("%d", project.tiers[180].tierAmount-project.tiers[180].calculatedAmount), + "leftReward", strconv.FormatUint(leftReward, 10), + "tier30Full", strconv.FormatUint(project.tiers[30].tierAmount, 10), + "tier30Left", strconv.FormatUint(project.tiers[30].tierAmount-project.tiers[30].calculatedAmount, 10), + "tier90Full", strconv.FormatUint(project.tiers[90].tierAmount, 10), + "tier90Left", strconv.FormatUint(project.tiers[90].tierAmount-project.tiers[90].calculatedAmount, 10), + "tier180Full", strconv.FormatUint(project.tiers[180].tierAmount, 10), + "tier180Left", strconv.FormatUint(project.tiers[180].tierAmount-project.tiers[180].calculatedAmount, 10), ) project.refund = RefundInfo{ diff --git a/launchpad/reward.gno b/launchpad/reward.gno index 92831adf..43f4e504 100644 --- a/launchpad/reward.gno +++ b/launchpad/reward.gno @@ -3,6 +3,7 @@ package launchpad import ( "errors" "std" + "strconv" "time" "gno.land/p/demo/ufmt" @@ -13,7 +14,7 @@ import ( ) var ( - lastCalculatedHeight uint64 + lastCalculatedHeight uint64 lastCalculateHeightForProjectTier = make(map[string]uint64) // using height ) @@ -56,7 +57,7 @@ func calculateTierRewards(tier Tier, currentHeight uint64, lastCalcHeight uint64 endHeight := minU64(currentHeight, tier.ended.height) sinceLast := endHeight - minU64(endHeight, lastCalcHeight) - + if sinceLast == 0 { return u256.Zero(), 0, nil } @@ -79,7 +80,7 @@ func processDepositReward(deposit Deposit, rewardX96 *u256.Uint, tierAmount uint depositRewardX96 := u256.Zero().Div(depositRewardX96X96, q96) depositRewardX := u256.Zero().Div(depositRewardX96, q96) depositReward := depositRewardX.Uint64() - + deposit.rewardAmount += depositReward return deposit, nil } @@ -106,7 +107,7 @@ func CollectRewardByProjectId(projectId string) uint64 { height := uint64(std.GetHeight()) totalReward := uint64(0) // toUser - prevAddr, prevRealm := getPrev() + prevAddr, prevPkgPath := getPrev() for _, depositId := range depositIds { deposit := deposits[depositId] @@ -129,15 +130,15 @@ func CollectRewardByProjectId(projectId string) uint64 { std.Emit( "CollectRewardByProjectId", "prevAddr", prevAddr, - "prevRealm", prevRealm, + "prevRealm", prevPkgPath, "projectId", projectId, "depositId", depositId, - "amount", ufmt.Sprintf("%d", reward), + "amount", strconv.FormatUint(reward, 10), ) // Update project and tier stats project.stats.totalCollected += reward - + var tier Tier switch deposit.tier { case "30": @@ -200,14 +201,14 @@ func CollectRewardByDepositId(depositId string) uint64 { } reward := rewardStates.Get(deposit.projectId, deposit.tier).Claim(deposit.id, height) - - prevAddr, prevRealm := getPrev() + + prevAddr, prevPkgPath := getPrev() std.Emit( "CollectRewardByDepositId", "prevAddr", prevAddr, - "prevRealm", prevRealm, + "prevRealm", prevPkgPath, "depositId", depositId, - "internal_amount", ufmt.Sprintf("%d", reward), + "amount", strconv.FormatUint(reward, 10), ) // Update project @@ -239,6 +240,7 @@ func CollectRewardByDepositId(depositId string) uint64 { return reward } + /* // calculateProjectRewards calculates rewards for a project's deposits func calculateProjectRewards(project Project, height uint64) (Project, error) { @@ -271,11 +273,11 @@ func calculateProjectRewards(project Project, height uint64) (Project, error) { } // Calculate rewards for each tier - tier30RewardX96, reward30, _ := calculateTierRewards(tier30, height, + tier30RewardX96, reward30, _ := calculateTierRewards(tier30, height, lastCalculateHeightForProjectTier[tier30.id]) - tier90RewardX96, reward90, _ := calculateTierRewards(tier90, height, + tier90RewardX96, reward90, _ := calculateTierRewards(tier90, height, lastCalculateHeightForProjectTier[tier90.id]) - tier180RewardX96, reward180, _ := calculateTierRewards(tier180, height, + tier180RewardX96, reward180, _ := calculateTierRewards(tier180, height, lastCalculateHeightForProjectTier[tier180.id]) // Update project tiers