reward_state.gno
4.22 Kb · 131 lines
1package launchpad
2
3import (
4 u256 "gno.land/p/gnoswap/uint256"
5)
6
7// RewardState represents the state of a reward for a deposit.
8// It contains the necessary data to manage and distribute rewards for a specific deposit.
9type RewardState struct {
10 priceDebtX128 *u256.Uint // price debt per GNS stake, Q128
11 claimableTime int64 // time when reward can be claimed
12
13 depositAmount int64 // amount of GNS staked
14 distributeStartTime int64 // time when launchpad started staking
15 distributeEndTime int64 // end time of reward calculation
16 accumulatedRewardAmount int64 // calculated, not collected
17 accumulatedTime int64 // last time when reward was calculated
18 claimedAmount int64 // amount of reward claimed so far
19}
20
21// NewRewardState returns a pointer to a new RewardState with the given values.
22func NewRewardState(
23 accumulatedRewardPerDepositX128 *u256.Uint,
24 depositAmount,
25 distributeStartTime,
26 distributeEndTime int64,
27 claimableTime int64,
28) *RewardState {
29 return &RewardState{
30 priceDebtX128: accumulatedRewardPerDepositX128,
31 depositAmount: depositAmount,
32 distributeStartTime: distributeStartTime,
33 distributeEndTime: distributeEndTime,
34 claimableTime: claimableTime,
35 accumulatedRewardAmount: 0,
36 claimedAmount: 0,
37 }
38}
39
40// PriceDebtX128 returns the price debt (Q128) of the reward state.
41func (rs *RewardState) PriceDebtX128() *u256.Uint {
42 return rs.priceDebtX128
43}
44
45// SetPriceDebtX128 sets the price debt (Q128) of the reward state.
46func (rs *RewardState) SetPriceDebtX128(debt *u256.Uint) {
47 rs.priceDebtX128 = u256.Zero().Set(debt)
48}
49
50// ClaimableTime returns the claimable time of the reward state.
51func (rs *RewardState) ClaimableTime() int64 {
52 return rs.claimableTime
53}
54
55// SetClaimableTime sets the claimable time of the reward state.
56func (rs *RewardState) SetClaimableTime(time int64) {
57 rs.claimableTime = time
58}
59
60// DepositAmount returns the deposit amount of the reward state.
61func (rs *RewardState) DepositAmount() int64 {
62 return rs.depositAmount
63}
64
65// SetDepositAmount sets the deposit amount of the reward state.
66func (rs *RewardState) SetDepositAmount(amount int64) {
67 rs.depositAmount = amount
68}
69
70// DistributeStartTime returns the distribute start time of the reward state.
71func (rs *RewardState) DistributeStartTime() int64 {
72 return rs.distributeStartTime
73}
74
75// SetDistributeStartTime sets the distribute start time of the reward state.
76func (rs *RewardState) SetDistributeStartTime(time int64) {
77 rs.distributeStartTime = time
78}
79
80// DistributeEndTime returns the distribute end time of the reward state.
81func (rs *RewardState) DistributeEndTime() int64 {
82 return rs.distributeEndTime
83}
84
85// SetDistributeEndTime sets the distribute end time of the reward state.
86func (rs *RewardState) SetDistributeEndTime(time int64) {
87 rs.distributeEndTime = time
88}
89
90// AccumulatedRewardAmount returns the accumulated reward amount of the reward state.
91func (rs *RewardState) AccumulatedRewardAmount() int64 {
92 return rs.accumulatedRewardAmount
93}
94
95// SetAccumulatedRewardAmount sets the accumulated reward amount of the reward state.
96func (rs *RewardState) SetAccumulatedRewardAmount(amount int64) {
97 rs.accumulatedRewardAmount = amount
98}
99
100// AccumulatedTime returns the accumulated time of the reward state.
101func (rs *RewardState) AccumulatedTime() int64 {
102 return rs.accumulatedTime
103}
104
105// SetAccumulatedTime sets the accumulated time of the reward state.
106func (rs *RewardState) SetAccumulatedTime(time int64) {
107 rs.accumulatedTime = time
108}
109
110// ClaimedAmount returns the claimed amount of the reward state.
111func (rs *RewardState) ClaimedAmount() int64 {
112 return rs.claimedAmount
113}
114
115// SetClaimedAmount sets the claimed amount of the reward state.
116func (rs *RewardState) SetClaimedAmount(amount int64) {
117 rs.claimedAmount = amount
118}
119
120func (rs RewardState) Clone() *RewardState {
121 return &RewardState{
122 priceDebtX128: rs.priceDebtX128.Clone(),
123 claimableTime: rs.claimableTime,
124 depositAmount: rs.depositAmount,
125 distributeStartTime: rs.distributeStartTime,
126 distributeEndTime: rs.distributeEndTime,
127 accumulatedRewardAmount: rs.accumulatedRewardAmount,
128 accumulatedTime: rs.accumulatedTime,
129 claimedAmount: rs.claimedAmount,
130 }
131}