Skip to content

Commit aef34d9

Browse files
committed
fix
1 parent f2691d0 commit aef34d9

File tree

2 files changed

+42
-45
lines changed

2 files changed

+42
-45
lines changed

staker/reward_calculation_pool.gno

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77

88
"gno.land/p/demo/avl"
99

10-
u256 "gno.land/p/gnoswap/uint256"
1110
i256 "gno.land/p/gnoswap/int256"
11+
u256 "gno.land/p/gnoswap/uint256"
1212
)
1313

1414
var q128 = u256.MustFromDecimal(consts.Q128)
@@ -66,15 +66,15 @@ type Pool struct {
6666

6767
ticks *Ticks
6868
}
69-
69+
7070
func NewPool(poolPath string, currentHeight uint64) *Pool {
7171
return &Pool{
72-
poolPath: poolPath,
73-
stakedLiquidity: NewUintTree(),
74-
rewardCache: NewRewardCacheTree(),
72+
poolPath: poolPath,
73+
stakedLiquidity: NewUintTree(),
74+
rewardCache: NewRewardCacheTree(),
7575
lastRewardCacheHeight: &currentHeight,
76-
incentives: NewIncentives(currentHeight),
77-
ticks: NewTicks(),
76+
incentives: NewIncentives(currentHeight),
77+
ticks: NewTicks(),
7878
}
7979
}
8080

@@ -97,7 +97,7 @@ func (self *Pool) CurrentReward(currentHeight uint64) *u256.Uint {
9797
return u256.Zero()
9898
}
9999
return reward.(*u256.Uint)
100-
}
100+
}
101101

102102
// cacheReward() MUST be called before this function
103103
func (self *Pool) IsExternallyIncentivizedPool(currentHeight uint64) bool {
@@ -132,7 +132,7 @@ func (self *Pool) cacheInternalReward(poolTier *PoolTier, endHeight uint64) {
132132
startHeight = membershipUpdateHeight
133133
currentTier = value.(uint64)
134134
return false
135-
}
135+
}
136136

137137
currentTierReward = poolTier.CurrentReward(currentTier, startHeight)
138138

@@ -162,7 +162,7 @@ func (self *Pool) cacheInternalReward(poolTier *PoolTier, endHeight uint64) {
162162
startHeight = height
163163
return false
164164
})
165-
165+
166166
self.cacheRewardPerLiquidityUnit(startHeight, endHeight, currentTierReward)
167167
}
168168

@@ -181,20 +181,20 @@ func (self *Pool) cacheExternalReward(endHeight uint64) {
181181
}
182182

183183
type ExternalRewardState struct {
184-
pool *Pool
185-
deposit *Deposit
184+
pool *Pool
185+
deposit *Deposit
186186
currentWarmup Warmup
187-
rewards []map[string]*u256.Uint
188-
penalties []map[string]*u256.Uint
187+
rewards []map[string]*u256.Uint
188+
penalties []map[string]*u256.Uint
189189
}
190190

191191
func (self *Pool) ExternalRewardOf(deposit *Deposit) *ExternalRewardState {
192192
result := &ExternalRewardState{
193-
pool: self,
194-
deposit: deposit,
193+
pool: self,
194+
deposit: deposit,
195195
currentWarmup: deposit.warmups[0],
196-
rewards: make([]map[string]*u256.Uint, len(deposit.warmups)),
197-
penalties: make([]map[string]*u256.Uint, len(deposit.warmups)),
196+
rewards: make([]map[string]*u256.Uint, len(deposit.warmups)),
197+
penalties: make([]map[string]*u256.Uint, len(deposit.warmups)),
198198
}
199199

200200
for i := range result.rewards {
@@ -230,7 +230,7 @@ func (self *ExternalRewardState) Calculate(startHeight, endHeight int64, current
230230
}
231231

232232
func (self *ExternalRewardState) AccumulateReward(startHeight, endHeight uint64) {
233-
self.pool.incentives.rewardCache.RewardPerInterval(startHeight, endHeight, func(blockNumber uint64, poolRewardI interface{}) {
233+
self.pool.incentives.rewardCache.RewardPerInterval(startHeight, endHeight, func(blockNumber uint64, poolRewardI interface{}) {
234234
poolRewardRatios := poolRewardI.(map[string]*u256.Uint)
235235
for incentiveId, rewardRatio := range poolRewardRatios {
236236
positionReward := u256.Zero().Mul(self.deposit.liquidity, rewardRatio)
@@ -307,20 +307,20 @@ func (self *ExternalRewardState) TickCrossesToExternalReward(startHeight, endHei
307307
}
308308

309309
type InternalRewardState struct {
310-
pool *Pool
311-
deposit *Deposit
310+
pool *Pool
311+
deposit *Deposit
312312
currentWarmup Warmup
313-
rewards []*u256.Uint
314-
penalties []*u256.Uint
313+
rewards []*u256.Uint
314+
penalties []*u256.Uint
315315
}
316316

317317
func (self *Pool) InternalRewardOf(deposit *Deposit) *InternalRewardState {
318318
result := &InternalRewardState{
319-
pool: self,
320-
deposit: deposit,
319+
pool: self,
320+
deposit: deposit,
321321
currentWarmup: deposit.warmups[0],
322-
rewards: make([]*u256.Uint, len(deposit.warmups)),
323-
penalties: make([]*u256.Uint, len(deposit.warmups)),
322+
rewards: make([]*u256.Uint, len(deposit.warmups)),
323+
penalties: make([]*u256.Uint, len(deposit.warmups)),
324324
}
325325

326326
for i := range result.rewards {
@@ -346,7 +346,7 @@ func (self *InternalRewardState) Calculate(startHeight, endHeight int64, current
346346
}
347347

348348
func (self *InternalRewardState) AccumulateReward(startHeight, endHeight uint64) {
349-
self.pool.rewardCache.RewardPerInterval(startHeight, endHeight, func(blockNumber uint64, poolRewardI interface{}) {
349+
self.pool.rewardCache.RewardPerInterval(startHeight, endHeight, func(blockNumber uint64, poolRewardI interface{}) {
350350
poolRewardRatio := poolRewardI.(*u256.Uint)
351351
positionReward := u256.Zero().Mul(self.deposit.liquidity, poolRewardRatio)
352352
positionReward = u256.Zero().Mul(positionReward, u256.NewUint(blockNumber))
@@ -365,7 +365,7 @@ func (self *InternalRewardState) ApplyWarmup() {
365365
reward := u256.Zero()
366366
reward = reward.Mul(self.rewards[i], u256.NewUint(warmup.WarmupRatio))
367367
reward = reward.Div(reward, u256.NewUint(100))
368-
368+
369369
penalty := u256.Zero().Sub(self.rewards[i], reward)
370370

371371
reward = reward.Div(reward, q128)
@@ -415,8 +415,6 @@ func (self *InternalRewardState) TickCrossesToInternalReward(startHeight, endHei
415415
self.ApplyWarmup()
416416
}
417417

418-
419-
420418
func (self *Pool) modifyDeposit(tokenId uint64, liquidity *i256.Int, currentHeight uint64) {
421419
// update staker side pool info
422420
lastStakedLiquidity := self.CurrentStakedLiquidity(currentHeight)
@@ -426,17 +424,16 @@ func (self *Pool) modifyDeposit(tokenId uint64, liquidity *i256.Int, currentHeig
426424
// ============================================
427425
// API/helpers
428426
// ============================================
429-
430-
func (self *Pool) RewardTokens(height uint64) []string {
431-
reward := self.CurrentReward(height)
432-
rewardTokens := []string{}
433-
if
434-
for incentiveId := range reward {
435-
ictv, exist := self.GetByIncentiveId(incentiveId)
436-
if !exist {
437-
continue
438-
}
439-
rewardTokens = append(rewardTokens, ictv.RewardToken())
440-
}
441-
return rewardTokens
442-
}
427+
// func (self *Pool) RewardTokens(height uint64) []string {
428+
// reward := self.CurrentReward(height)
429+
// rewardTokens := []string{}
430+
// if
431+
// for incentiveId := range reward {
432+
// ictv, exist := self.GetByIncentiveId(incentiveId)
433+
// if !exist {
434+
// continue
435+
// }
436+
// rewardTokens = append(rewardTokens, ictv.RewardToken())
437+
// }
438+
// return rewardTokens
439+
// }

0 commit comments

Comments
 (0)