emits.gno
1.29 Kb · 29 lines
1package launchpad
2
3import (
4 "chain"
5
6 "gno.land/p/gnoswap/utils"
7 "gno.land/r/gnoswap/launchpad"
8)
9
10// emitUpdateLaunchpadRewardAccumulation emits the persisted per-tier reward
11// accumulation state so that off-chain indexers can consume the authoritative
12// accumulator instead of re-deriving it. It must be emitted after every path that
13// calls updateRewardPerDepositX128 (deposit/withdraw/collect/admin-reclaim),
14// otherwise the off-chain accumulator drifts from the contract.
15//
16// The reward manager is keyed by projectTierId, so it is included to identify which
17// tier's accumulator this update belongs to. totalDepositAmount is the current tier
18// deposit total after the stake change (the divisor for the next accumulation delta),
19// and distributeAmountPerSecondX128 lets indexers project the accumulator forward.
20func emitUpdateLaunchpadRewardAccumulation(projectTierID string, r *launchpad.RewardManager, totalDepositAmount int64) {
21 chain.Emit(
22 "UpdateLaunchpadRewardAccumulation",
23 "projectTierId", projectTierID,
24 "totalDepositAmount", utils.FormatInt(totalDepositAmount),
25 "accumulatedRewardPerDepositX128", r.AccumulatedRewardPerDepositX128().ToString(),
26 "distributeAmountPerSecondX128", r.DistributeAmountPerSecondX128().ToString(),
27 "accumulatedTime", utils.FormatInt(r.AccumulatedTime()),
28 )
29}