|
7 | 7 |
|
8 | 8 | "gno.land/p/demo/avl"
|
9 | 9 |
|
| 10 | + ufmt "gno.land/p/demo/ufmt" |
| 11 | + |
10 | 12 | i256 "gno.land/p/gnoswap/int256"
|
11 | 13 | u256 "gno.land/p/gnoswap/uint256"
|
12 | 14 | )
|
@@ -404,13 +406,6 @@ func (self *Pool) modifyDeposit(tokenId uint64, liquidity *i256.Int, currentHeig
|
404 | 406 | self.stakedLiquidity.Set(currentHeight, liquidityMathAddDelta(lastStakedLiquidity, liquidity))
|
405 | 407 | }
|
406 | 408 |
|
407 |
| -func (self *Pool) processUnclaimableInternalReward(poolTier *PoolTier, endHeight uint64) uint64 { |
408 |
| - startHeight := *self.lastUnclaimableHeight |
409 |
| - unclaimable := self.UnclaimableInternalReward(poolTier, startHeight, endHeight) |
410 |
| - self.lastUnclaimableHeight = &endHeight |
411 |
| - return unclaimable |
412 |
| -} |
413 |
| - |
414 | 409 | func (self *Pool) UnclaimableInternalReward(poolTier *PoolTier, startHeight, endHeight uint64) uint64 {
|
415 | 410 | tierRewardHeights, tierRewardUpdates := poolTier.TierRewardUpdates(self.poolPath, startHeight, endHeight)
|
416 | 411 |
|
@@ -448,6 +443,57 @@ func (self *Pool) UnclaimableInternalReward(poolTier *PoolTier, startHeight, end
|
448 | 443 | return unclaimable
|
449 | 444 | }
|
450 | 445 |
|
| 446 | +func (self *Pool) UnclaimableExternalReward(incentiveId string, startHeight, endHeight uint64) uint64 { |
| 447 | + incentive, ok := self.incentives.GetByIncentiveId(incentiveId) |
| 448 | + if !ok { |
| 449 | + return 0 |
| 450 | + } |
| 451 | + |
| 452 | + if startHeight > uint64(incentive.endHeight) || endHeight < uint64(incentive.startHeight) { |
| 453 | + return 0 |
| 454 | + } |
| 455 | + |
| 456 | + if startHeight < uint64(incentive.startHeight) { |
| 457 | + startHeight = uint64(incentive.startHeight) |
| 458 | + } |
| 459 | + |
| 460 | + if endHeight > uint64(incentive.endHeight) { |
| 461 | + endHeight = uint64(incentive.endHeight) |
| 462 | + } |
| 463 | + |
| 464 | + rewardPerBlock := incentive.rewardPerBlock |
| 465 | + |
| 466 | + unclaimable := uint64(0) |
| 467 | + |
| 468 | + currentStakedLiquidity := self.CurrentStakedLiquidity(startHeight) |
| 469 | + |
| 470 | + self.stakedLiquidity.Iterate(startHeight, endHeight, func(height uint64, value interface{}) bool { |
| 471 | + if currentStakedLiquidity.IsZero() { |
| 472 | + unclaimable += rewardPerBlock * (height - startHeight) |
| 473 | + } |
| 474 | + startHeight = height |
| 475 | + currentStakedLiquidity = value.(*u256.Uint) |
| 476 | + return false |
| 477 | + }) |
| 478 | + |
| 479 | + if currentStakedLiquidity.IsZero() { |
| 480 | + unclaimable += rewardPerBlock * (endHeight - startHeight) |
| 481 | + } |
| 482 | + |
| 483 | + return unclaimable |
| 484 | +} |
| 485 | + |
| 486 | +func (self *Pool) processUnclaimableReward(poolTier *PoolTier, endHeight uint64) (uint64, map[string]uint64) { |
| 487 | + startHeight := *self.lastUnclaimableHeight |
| 488 | + internalUnclaimable := self.UnclaimableInternalReward(poolTier, startHeight, endHeight) |
| 489 | + externalUnclaimable := make(map[string]uint64) |
| 490 | + for incentiveId := range self.incentives.CurrentReward(startHeight) { |
| 491 | + externalUnclaimable[incentiveId] = self.UnclaimableExternalReward(incentiveId, startHeight, endHeight) |
| 492 | + } |
| 493 | + self.lastUnclaimableHeight = &endHeight |
| 494 | + return internalUnclaimable, externalUnclaimable |
| 495 | +} |
| 496 | + |
451 | 497 | // ============================================
|
452 | 498 | // API/helpers
|
453 | 499 | // ============================================
|
|
0 commit comments