Search Apps Documentation Source Content File Folder Download Copy Actions Download

emission_reward_state.gno

3.04 Kb ยท 78 lines
 1package staker
 2
 3import (
 4	u256 "gno.land/p/gnoswap/uint256"
 5)
 6
 7// EmissionRewardState tracks emission reward information for an individual staker.
 8// This struct maintains reward debt, accumulated rewards, and claiming history
 9// to ensure accurate reward calculations and prevent double-claiming.
10type EmissionRewardState struct {
11	// rewardDebtX128 represents the reward debt with 128-bit precision scaling
12	// Used to calculate rewards earned since the last update
13	rewardDebtX128 *u256.Uint
14	// accumulatedRewardAmount is the total rewards accumulated but not yet claimed
15	accumulatedRewardAmount int64
16	// accumulatedTimestamp is the last timestamp when rewards were accumulated
17	accumulatedTimestamp int64
18	// claimedRewardAmount is the total amount of rewards that have been claimed
19	claimedRewardAmount int64
20	// claimedTimestamp is the last timestamp when rewards were claimed
21	claimedTimestamp int64
22	// stakedAmount is the current amount of tokens staked by this address
23	stakedAmount int64
24}
25
26// NewEmissionRewardState creates a new emission reward state for a staker.
27// This factory function initializes the state with the current system reward debt.
28//
29// Parameters:
30//   - accumulatedRewardX128PerStake: current system-wide accumulated reward per stake
31//
32// Returns:
33//   - *EmissionRewardState: new emission reward state instance
34func NewEmissionRewardState(accumulatedRewardX128PerStake *u256.Uint) *EmissionRewardState {
35	return &EmissionRewardState{
36		// Deep copy the input to snapshot the current accumulator value.
37		rewardDebtX128:          accumulatedRewardX128PerStake.Clone(),
38		accumulatedRewardAmount: 0,
39		accumulatedTimestamp:    0,
40		claimedRewardAmount:     0,
41		claimedTimestamp:        0,
42		stakedAmount:            0,
43	}
44}
45
46/* Getters */
47
48func (e *EmissionRewardState) GetRewardDebtX128() *u256.Uint     { return e.rewardDebtX128 }
49func (e *EmissionRewardState) GetAccumulatedRewardAmount() int64 { return e.accumulatedRewardAmount }
50func (e *EmissionRewardState) GetAccumulatedTimestamp() int64    { return e.accumulatedTimestamp }
51func (e *EmissionRewardState) GetClaimedRewardAmount() int64     { return e.claimedRewardAmount }
52func (e *EmissionRewardState) GetClaimedTimestamp() int64        { return e.claimedTimestamp }
53func (e *EmissionRewardState) GetStakedAmount() int64            { return e.stakedAmount }
54
55/* Setters */
56func (e *EmissionRewardState) SetRewardDebtX128(rewardDebtX128 *u256.Uint) {
57	e.rewardDebtX128 = rewardDebtX128
58}
59
60func (e *EmissionRewardState) SetAccumulatedRewardAmount(accumulatedRewardAmount int64) {
61	e.accumulatedRewardAmount = accumulatedRewardAmount
62}
63
64func (e *EmissionRewardState) SetAccumulatedTimestamp(accumulatedTimestamp int64) {
65	e.accumulatedTimestamp = accumulatedTimestamp
66}
67
68func (e *EmissionRewardState) SetClaimedRewardAmount(claimedRewardAmount int64) {
69	e.claimedRewardAmount = claimedRewardAmount
70}
71
72func (e *EmissionRewardState) SetClaimedTimestamp(claimedTimestamp int64) {
73	e.claimedTimestamp = claimedTimestamp
74}
75
76func (e *EmissionRewardState) SetStakedAmount(stakedAmount int64) {
77	e.stakedAmount = stakedAmount
78}