@@ -156,7 +156,6 @@ func (self *Pool) cacheRewardPerLiquidityUnit(startHeight, endHeight uint64, cur
156156}
157157
158158func (self *Pool) cacheInternalReward(currentHeight uint64, emissionUpdate en.EmissionUpdate, rewardDenominator uint64) {
159- println(">>>> cacheInternalReward", currentHeight, emissionUpdate, rewardDenominator)
160159 currentEmission := emissionUpdate.LastEmissionUpdate
161160
162161 startHeight := *self.lastRewardCacheHeight
@@ -176,7 +175,6 @@ func (self *Pool) cacheInternalReward(currentHeight uint64, emissionUpdate en.Em
176175
177176func (self *Pool) cacheExternalReward(endHeight uint64) {
178177 self.stakedLiquidity.Iterate(0, 9999999, func(key uint64, value interface{}) bool {
179- println("(((cacheExternalReward)))", key, value.(*u256.Uint).ToString())
180178 return false
181179 })
182180
@@ -193,7 +191,6 @@ func (self *Pool) cacheExternalReward(endHeight uint64) {
193191 self.incentives.cacheRewardPerLiquidityUnit(startHeight, endHeight, currentStakedLiquidity)
194192
195193 self.incentives.rewardCache.Iterate(0, 9999999, func(key uint64, value interface{}) bool {
196- println("cacheExternalReward", key, value)
197194 return false
198195 })
199196}
@@ -233,6 +230,7 @@ func (self *ExternalRewardState) Calculate(startHeight, endHeight int64, current
233230 rewards := make([]map[string]uint64, len(self.deposit.warmups))
234231 penalties := make([]map[string]uint64, len(self.deposit.warmups))
235232
233+
236234 for i := range self.rewards {
237235 rewards[i] = make(map[string]uint64)
238236 penalties[i] = make(map[string]uint64)
@@ -244,17 +242,20 @@ func (self *ExternalRewardState) Calculate(startHeight, endHeight int64, current
244242 }
245243 }
246244
247-
248245 return rewards, penalties
249246}
250247
251248func (self *ExternalRewardState) AccumulateReward(startHeight, endHeight uint64) {
252249 self.pool.incentives.rewardCache.RewardPerInterval(startHeight, endHeight, func(blockNumber uint64, poolRewardI interface{}) {
253- poolRewardRatios := map[string]*u256.Uint{}
254- if poolRewardI != nil {
255- poolRewardRatios = poolRewardI.(map[string]*u256.Uint)
256- }
257- for incentiveId, rewardRatio := range poolRewardRatios {
250+ incentiveRewardEntry := poolRewardI.(IncentiveRewardEntry)
251+ for _, incentiveId := range incentiveRewardEntry.ActiveIncentives {
252+ incentive, ok := self.pool.incentives.GetByIncentiveId(incentiveId)
253+ if !ok {
254+ panic("incentive not found")
255+ }
256+ rewardRatio := u256.NewUint(incentive.rewardPerBlock)
257+ rewardRatio.Mul(rewardRatio, q192)
258+ rewardRatio.Div(rewardRatio, incentiveRewardEntry.TotalStakedLiquidity)
258259 positionReward := u256.Zero().Mul(self.deposit.liquidity, rewardRatio)
259260 positionReward = u256.Zero().Mul(positionReward, u256.NewUint(blockNumber))
260261 acc, ok := self.rewards[self.currentWarmup.Index][incentiveId]
@@ -265,6 +266,7 @@ func (self *ExternalRewardState) AccumulateReward(startHeight, endHeight uint64)
265266 self.rewards[self.currentWarmup.Index][incentiveId] = acc
266267 }
267268 })
269+
268270}
269271
270272func (self *ExternalRewardState) ApplyWarmup() {
@@ -367,7 +369,6 @@ func (self *InternalRewardState) Calculate(startHeight, endHeight int64, current
367369}
368370
369371func (self *InternalRewardState) AccumulateReward(startHeight, endHeight uint64) {
370- println("!AccumulateReward", startHeight, endHeight)
371372 self.pool.rewardCache.RewardPerInterval(startHeight, endHeight, func(blockNumber uint64, poolRewardI interface{}) {
372373 poolRewardRatio := poolRewardI.(*u256.Uint)
373374 positionReward := u256.Zero().Mul(self.deposit.liquidity, poolRewardRatio)
0 commit comments