7
7
8
8
"gno.land/p/demo/avl"
9
9
10
- u256 "gno.land/p/gnoswap/uint256"
11
10
i256 "gno.land/p/gnoswap/int256"
11
+ u256 "gno.land/p/gnoswap/uint256"
12
12
)
13
13
14
14
var q128 = u256.MustFromDecimal(consts.Q128)
@@ -66,15 +66,15 @@ type Pool struct {
66
66
67
67
ticks *Ticks
68
68
}
69
-
69
+
70
70
func NewPool(poolPath string, currentHeight uint64) *Pool {
71
71
return &Pool{
72
- poolPath: poolPath,
73
- stakedLiquidity: NewUintTree(),
74
- rewardCache: NewRewardCacheTree(),
72
+ poolPath: poolPath,
73
+ stakedLiquidity: NewUintTree(),
74
+ rewardCache: NewRewardCacheTree(),
75
75
lastRewardCacheHeight: ¤tHeight,
76
- incentives: NewIncentives(currentHeight),
77
- ticks: NewTicks(),
76
+ incentives: NewIncentives(currentHeight),
77
+ ticks: NewTicks(),
78
78
}
79
79
}
80
80
@@ -97,7 +97,7 @@ func (self *Pool) CurrentReward(currentHeight uint64) *u256.Uint {
97
97
return u256.Zero()
98
98
}
99
99
return reward.(*u256.Uint)
100
- }
100
+ }
101
101
102
102
// cacheReward() MUST be called before this function
103
103
func (self *Pool) IsExternallyIncentivizedPool(currentHeight uint64) bool {
@@ -132,7 +132,7 @@ func (self *Pool) cacheInternalReward(poolTier *PoolTier, endHeight uint64) {
132
132
startHeight = membershipUpdateHeight
133
133
currentTier = value.(uint64)
134
134
return false
135
- }
135
+ }
136
136
137
137
currentTierReward = poolTier.CurrentReward(currentTier, startHeight)
138
138
@@ -162,7 +162,7 @@ func (self *Pool) cacheInternalReward(poolTier *PoolTier, endHeight uint64) {
162
162
startHeight = height
163
163
return false
164
164
})
165
-
165
+
166
166
self.cacheRewardPerLiquidityUnit(startHeight, endHeight, currentTierReward)
167
167
}
168
168
@@ -181,20 +181,20 @@ func (self *Pool) cacheExternalReward(endHeight uint64) {
181
181
}
182
182
183
183
type ExternalRewardState struct {
184
- pool *Pool
185
- deposit *Deposit
184
+ pool *Pool
185
+ deposit *Deposit
186
186
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
189
189
}
190
190
191
191
func (self *Pool) ExternalRewardOf(deposit *Deposit) *ExternalRewardState {
192
192
result := &ExternalRewardState{
193
- pool: self,
194
- deposit: deposit,
193
+ pool: self,
194
+ deposit: deposit,
195
195
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)),
198
198
}
199
199
200
200
for i := range result.rewards {
@@ -230,7 +230,7 @@ func (self *ExternalRewardState) Calculate(startHeight, endHeight int64, current
230
230
}
231
231
232
232
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{}) {
234
234
poolRewardRatios := poolRewardI.(map[string]*u256.Uint)
235
235
for incentiveId, rewardRatio := range poolRewardRatios {
236
236
positionReward := u256.Zero().Mul(self.deposit.liquidity, rewardRatio)
@@ -307,20 +307,20 @@ func (self *ExternalRewardState) TickCrossesToExternalReward(startHeight, endHei
307
307
}
308
308
309
309
type InternalRewardState struct {
310
- pool *Pool
311
- deposit *Deposit
310
+ pool *Pool
311
+ deposit *Deposit
312
312
currentWarmup Warmup
313
- rewards []*u256.Uint
314
- penalties []*u256.Uint
313
+ rewards []*u256.Uint
314
+ penalties []*u256.Uint
315
315
}
316
316
317
317
func (self *Pool) InternalRewardOf(deposit *Deposit) *InternalRewardState {
318
318
result := &InternalRewardState{
319
- pool: self,
320
- deposit: deposit,
319
+ pool: self,
320
+ deposit: deposit,
321
321
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)),
324
324
}
325
325
326
326
for i := range result.rewards {
@@ -346,7 +346,7 @@ func (self *InternalRewardState) Calculate(startHeight, endHeight int64, current
346
346
}
347
347
348
348
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{}) {
350
350
poolRewardRatio := poolRewardI.(*u256.Uint)
351
351
positionReward := u256.Zero().Mul(self.deposit.liquidity, poolRewardRatio)
352
352
positionReward = u256.Zero().Mul(positionReward, u256.NewUint(blockNumber))
@@ -365,7 +365,7 @@ func (self *InternalRewardState) ApplyWarmup() {
365
365
reward := u256.Zero()
366
366
reward = reward.Mul(self.rewards[i], u256.NewUint(warmup.WarmupRatio))
367
367
reward = reward.Div(reward, u256.NewUint(100))
368
-
368
+
369
369
penalty := u256.Zero().Sub(self.rewards[i], reward)
370
370
371
371
reward = reward.Div(reward, q128)
@@ -415,8 +415,6 @@ func (self *InternalRewardState) TickCrossesToInternalReward(startHeight, endHei
415
415
self.ApplyWarmup()
416
416
}
417
417
418
-
419
-
420
418
func (self *Pool) modifyDeposit(tokenId uint64, liquidity *i256.Int, currentHeight uint64) {
421
419
// update staker side pool info
422
420
lastStakedLiquidity := self.CurrentStakedLiquidity(currentHeight)
@@ -426,17 +424,16 @@ func (self *Pool) modifyDeposit(tokenId uint64, liquidity *i256.Int, currentHeig
426
424
// ============================================
427
425
// API/helpers
428
426
// ============================================
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