Search Apps Documentation Source Content File Folder Download Copy Actions Download

reward_state.gno

4.66 Kb ยท 144 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	accumulatedHeight       int64 // last height when reward was calculated
 18	accumulatedTime         int64 // last time when reward was calculated
 19	claimedAmount           int64 // amount of reward claimed so far
 20}
 21
 22// NewRewardState returns a pointer to a new RewardState with the given values.
 23func NewRewardState(
 24	accumulatedRewardPerDepositX128 *u256.Uint,
 25	depositAmount,
 26	distributeStartTime,
 27	distributeEndTime int64,
 28	claimableTime int64,
 29) *RewardState {
 30	return &RewardState{
 31		priceDebtX128:           accumulatedRewardPerDepositX128,
 32		depositAmount:           depositAmount,
 33		distributeStartTime:     distributeStartTime,
 34		distributeEndTime:       distributeEndTime,
 35		claimableTime:           claimableTime,
 36		accumulatedRewardAmount: 0,
 37		claimedAmount:           0,
 38		accumulatedHeight:       0,
 39	}
 40}
 41
 42// PriceDebtX128 returns the price debt (Q128) of the reward state.
 43func (rs *RewardState) PriceDebtX128() *u256.Uint {
 44	return rs.priceDebtX128
 45}
 46
 47// SetPriceDebtX128 sets the price debt (Q128) of the reward state.
 48func (rs *RewardState) SetPriceDebtX128(debt *u256.Uint) {
 49	rs.priceDebtX128 = debt
 50}
 51
 52// ClaimableTime returns the claimable time of the reward state.
 53func (rs *RewardState) ClaimableTime() int64 {
 54	return rs.claimableTime
 55}
 56
 57// SetClaimableTime sets the claimable time of the reward state.
 58func (rs *RewardState) SetClaimableTime(time int64) {
 59	rs.claimableTime = time
 60}
 61
 62// DepositAmount returns the deposit amount of the reward state.
 63func (rs *RewardState) DepositAmount() int64 {
 64	return rs.depositAmount
 65}
 66
 67// SetDepositAmount sets the deposit amount of the reward state.
 68func (rs *RewardState) SetDepositAmount(amount int64) {
 69	rs.depositAmount = amount
 70}
 71
 72// DistributeStartTime returns the distribute start time of the reward state.
 73func (rs *RewardState) DistributeStartTime() int64 {
 74	return rs.distributeStartTime
 75}
 76
 77// SetDistributeStartTime sets the distribute start time of the reward state.
 78func (rs *RewardState) SetDistributeStartTime(time int64) {
 79	rs.distributeStartTime = time
 80}
 81
 82// DistributeEndTime returns the distribute end time of the reward state.
 83func (rs *RewardState) DistributeEndTime() int64 {
 84	return rs.distributeEndTime
 85}
 86
 87// SetDistributeEndTime sets the distribute end time of the reward state.
 88func (rs *RewardState) SetDistributeEndTime(time int64) {
 89	rs.distributeEndTime = time
 90}
 91
 92// AccumulatedRewardAmount returns the accumulated reward amount of the reward state.
 93func (rs *RewardState) AccumulatedRewardAmount() int64 {
 94	return rs.accumulatedRewardAmount
 95}
 96
 97// SetAccumulatedRewardAmount sets the accumulated reward amount of the reward state.
 98func (rs *RewardState) SetAccumulatedRewardAmount(amount int64) {
 99	rs.accumulatedRewardAmount = amount
100}
101
102// AccumulatedHeight returns the accumulated height of the reward state.
103func (rs *RewardState) AccumulatedHeight() int64 {
104	return rs.accumulatedHeight
105}
106
107// SetAccumulatedHeight sets the accumulated height of the reward state.
108func (rs *RewardState) SetAccumulatedHeight(height int64) {
109	rs.accumulatedHeight = height
110}
111
112// AccumulatedTime returns the accumulated time of the reward state.
113func (rs *RewardState) AccumulatedTime() int64 {
114	return rs.accumulatedTime
115}
116
117// SetAccumulatedTime sets the accumulated time of the reward state.
118func (rs *RewardState) SetAccumulatedTime(time int64) {
119	rs.accumulatedTime = time
120}
121
122// ClaimedAmount returns the claimed amount of the reward state.
123func (rs *RewardState) ClaimedAmount() int64 {
124	return rs.claimedAmount
125}
126
127// SetClaimedAmount sets the claimed amount of the reward state.
128func (rs *RewardState) SetClaimedAmount(amount int64) {
129	rs.claimedAmount = amount
130}
131
132func (rs RewardState) Clone() *RewardState {
133	return &RewardState{
134		priceDebtX128:           rs.priceDebtX128.Clone(),
135		claimableTime:           rs.claimableTime,
136		depositAmount:           rs.depositAmount,
137		distributeStartTime:     rs.distributeStartTime,
138		distributeEndTime:       rs.distributeEndTime,
139		accumulatedRewardAmount: rs.accumulatedRewardAmount,
140		accumulatedHeight:       rs.accumulatedHeight,
141		accumulatedTime:         rs.accumulatedTime,
142		claimedAmount:           rs.claimedAmount,
143	}
144}