Skip to content

Commit

Permalink
fix nil reference issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mconcat committed Dec 30, 2024
1 parent 24c5cd1 commit 5732cbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion staker/reward_calculation_canonical_env_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (self *canonicalRewardState) EmulateCalcPositionReward(tokenId uint64) ([]u

self.t.Logf("pool.cacheReward")
pool.cacheReward(poolTier, currentHeight)

// eligible(in-range) intervals for a position
upperTick := pool.ticks.Get(deposit.tickUpper)
lowerTick := pool.ticks.Get(deposit.tickLower)
Expand Down
8 changes: 8 additions & 0 deletions staker/reward_calculation_pool.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"gno.land/p/demo/avl"

ufmt "gno.land/p/demo/ufmt"

u256 "gno.land/p/gnoswap/uint256"
i256 "gno.land/p/gnoswap/int256"
)
Expand Down Expand Up @@ -117,6 +119,12 @@ func (self *Pool) StakedLiquidityUpdates(startHeight, endHeight uint64) ([]uint6
*/

func (self *Pool) cacheRewardPerLiquidityUnit(poolTier *PoolTier, startHeight, endHeight uint64, currentTierReward uint64) {
stakedLiquidity := self.CurrentStakedLiquidity(startHeight)
ratio := u256.NewUint(currentTierReward)
ratio = ratio.Mul(ratio, q96)
ratio = ratio.Div(ratio, stakedLiquidity)
self.rewardCache.Set(startHeight, ratio)

self.stakedLiquidity.Iterate(startHeight, endHeight, func(height uint64, value interface{}) bool {
stakedLiquidity := value.(*u256.Uint)
ratio := u256.NewUint(currentTierReward)
Expand Down

0 comments on commit 5732cbd

Please sign in to comment.