Skip to content

Commit

Permalink
chore: gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Dec 31, 2024
1 parent d98779f commit de425c3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 75 deletions.
71 changes: 36 additions & 35 deletions staker/reward_calculation_incentives.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,35 @@ import (

"gno.land/p/demo/ufmt"

i256 "gno.land/p/gnoswap/int256"
u256 "gno.land/p/gnoswap/uint256"
)

type IncentiveBound struct {
Incentive ExternalIncentive
IsEnter bool
IsEnter bool
}

// per-pool incentives
type Incentives struct {
byTime *avl.Tree // (startTime, endTime, creator, rewardToken) => ExternalIncentive
byHeight *avl.Tree // (startHeight, endHeight, creator, rewardToken) => ExternalIncentive
byTime *avl.Tree // (startTime, endTime, creator, rewardToken) => ExternalIncentive
byHeight *avl.Tree // (startHeight, endHeight, creator, rewardToken) => ExternalIncentive
byCreator *avl.Tree // (creator, startHeight, endHeight, rewardToken) => ExternalIncentive

incentiveBound *UintTree // blockNumber -> []IncentiveBound

rewardCache *RewardCacheTree // blockNumber -> map[string]*u256.Uint
rewardCache *RewardCacheTree // blockNumber -> map[string]*u256.Uint
lastRewardCacheHeight *uint64
}

func NewIncentives(currentHeight uint64) Incentives {
return Incentives{
byTime: avl.NewTree(),
byHeight: avl.NewTree(),
byTime: avl.NewTree(),
byHeight: avl.NewTree(),
byCreator: avl.NewTree(),

incentiveBound: NewUintTree(),

rewardCache: NewRewardCacheTree(),
rewardCache: NewRewardCacheTree(),
lastRewardCacheHeight: &currentHeight,
}
}
Expand All @@ -52,7 +51,7 @@ func (self *Incentives) Get(startTime, endTime int64, creator std.Address, rewar
if !ok {
return nil, false
}
return value.(*ExternalIncentive), true
return value.(*ExternalIncentive), true
}

func (self *Incentives) GetByIncentiveId(incentiveId string) (*ExternalIncentive, bool) {
Expand Down Expand Up @@ -91,7 +90,7 @@ func (self *Incentives) CurrentReward(currentHeight uint64) map[string]*u256.Uin
}

func (self *Incentives) create(
creator std.Address,
creator std.Address,
incentive *ExternalIncentive,
) {
byTimeId := incentiveIdByTime(uint64(incentive.startTimestamp), uint64(incentive.endTimestamp), creator, incentive.rewardToken)
Expand All @@ -111,48 +110,50 @@ func (self *Incentives) create(
startIncentiveBound := self.GetBound(uint64(incentive.startHeight))
startIncentiveBound = append(startIncentiveBound, IncentiveBound{
Incentive: *incentive,
IsEnter: true,
IsEnter: true,
})
self.incentiveBound.Set(uint64(incentive.startHeight), startIncentiveBound)

endHeight := uint64(incentive.endHeight)
endIncentiveBound := self.GetBound(endHeight)
endIncentiveBound = append(endIncentiveBound, IncentiveBound{
Incentive: *incentive,
IsEnter: false,
IsEnter: false,
})
self.incentiveBound.Set(endHeight, endIncentiveBound)

println("endIncentiveBound")
for _, bound := range endIncentiveBound {
println(bound.Incentive.rewardToken, bound.IsEnter)
}
/*
println("endIncentiveBound")
for _, bound := range endIncentiveBound {
println(bound.Incentive.rewardToken, bound.IsEnter)
}
*/
}

// endHeight MUST be less than or equal to the current block height
func (self *Incentives) cacheRewardPerLiquidityUnit(startHeight, endHeight uint64, stakedLiquidity *u256.Uint) {
currentReward := self.CurrentReward(startHeight)

/*
delta := self.GetDelta(startHeight)
reward := make(map[string]*u256.Uint)
for token, deltaAmount := range delta {
delta := i256.NewInt(deltaAmount)
deltaQ96 := delta.Mul(delta, _iQ96)
currentRewardToken, ok := currentReward[token]
if !ok {
currentRewardToken = u256.Zero()
}
deltaApplied := liquidityMathAddDelta(currentRewardToken, deltaQ96)
if deltaApplied.IsZero() {
continue
/*
delta := self.GetDelta(startHeight)
reward := make(map[string]*u256.Uint)
for token, deltaAmount := range delta {
delta := i256.NewInt(deltaAmount)
deltaQ96 := delta.Mul(delta, _iQ96)
currentRewardToken, ok := currentReward[token]
if !ok {
currentRewardToken = u256.Zero()
}
deltaApplied := liquidityMathAddDelta(currentRewardToken, deltaQ96)
if deltaApplied.IsZero() {
continue
}
reward[token] = deltaApplied
println(startHeight, token, deltaAmount, deltaQ96.ToString(), currentRewardToken.ToString(), deltaApplied.ToString())
}
reward[token] = deltaApplied
println(startHeight, token, deltaAmount, deltaQ96.ToString(), currentRewardToken.ToString(), deltaApplied.ToString())
}

self.rewardCache.Set(startHeight, reward)
*/
self.rewardCache.Set(startHeight, reward)
*/

self.incentiveBound.Iterate(startHeight, endHeight, func(key uint64, value interface{}) bool {
bound := value.([]IncentiveBound)
Expand All @@ -174,4 +175,4 @@ func (self *Incentives) cacheRewardPerLiquidityUnit(startHeight, endHeight uint6
return false
})
*self.lastRewardCacheHeight = endHeight
}
}
2 changes: 1 addition & 1 deletion staker/reward_calculation_tick.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"
"strings"

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

i256 "gno.land/p/gnoswap/int256"
u256 "gno.land/p/gnoswap/uint256"
Expand Down
79 changes: 40 additions & 39 deletions staker/type.gno
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ func newInternalTier(tier uint64, startTimestamp int64) InternalTier {
}

type ExternalIncentive struct {
incentiveId string // incentive id
startTimestamp int64 // start time for external reward
endTimestamp int64 // end time for external reward
createdHeight int64 // block height when the incentive was created
depositGnsAmount uint64 // deposited gns amount
targetPoolPath string // external reward target pool path
rewardToken string // external reward token path
rewardAmount uint64 // total reward amount
rewardLeft uint64 // remaining reward amount
startHeight int64 // start height for external reward
endHeight int64 // end height for external reward
rewardPerBlock uint64 // reward per block
refundee std.Address // refundee address
incentiveId string // incentive id
startTimestamp int64 // start time for external reward
endTimestamp int64 // end time for external reward
createdHeight int64 // block height when the incentive was created
depositGnsAmount uint64 // deposited gns amount
targetPoolPath string // external reward target pool path
rewardToken string // external reward token path
rewardAmount uint64 // total reward amount
rewardLeft uint64 // remaining reward amount
startHeight int64 // start height for external reward
endHeight int64 // end height for external reward
rewardPerBlock uint64 // reward per block
refundee std.Address // refundee address
}

func (e ExternalIncentive) StartTimestamp() int64 {
Expand Down Expand Up @@ -69,21 +69,21 @@ func newExternalIncentive(
refundee std.Address,
) ExternalIncentive {
return ExternalIncentive{
startTimestamp: startTimestamp,
endTimestamp: endTimestamp,
createdHeight: createdHeight,
depositGnsAmount: depositGnsAmount,
targetPoolPath: targetPoolPath,
rewardToken: rewardToken,
rewardAmount: rewardAmount,
rewardLeft: rewardLeft,
rewardPerBlock: rewardPerBlock,
refundee: refundee,
startTimestamp: startTimestamp,
endTimestamp: endTimestamp,
createdHeight: createdHeight,
depositGnsAmount: depositGnsAmount,
targetPoolPath: targetPoolPath,
rewardToken: rewardToken,
rewardAmount: rewardAmount,
rewardLeft: rewardLeft,
rewardPerBlock: rewardPerBlock,
refundee: refundee,
}
}


func NewExternalIncentive(
incentiveId string,
targetPoolPath string,
rewardToken string,
rewardAmount uint64,
Expand All @@ -107,16 +107,17 @@ func NewExternalIncentive(
endHeight := std.GetHeight() + blocksLeftUntilEndHeight

return &ExternalIncentive{
targetPoolPath: targetPoolPath,
rewardToken: rewardToken,
rewardAmount: rewardAmount,
startTimestamp: startTimestamp,
endTimestamp: endTimestamp,
startHeight: startHeight,
endHeight: endHeight,
rewardPerBlock: rewardPerBlock,
refundee: refundee,
createdHeight: createdHeight,
incentiveId: incentiveId,
targetPoolPath: targetPoolPath,
rewardToken: rewardToken,
rewardAmount: rewardAmount,
startTimestamp: startTimestamp,
endTimestamp: endTimestamp,
startHeight: startHeight,
endHeight: endHeight,
rewardPerBlock: rewardPerBlock,
refundee: refundee,
createdHeight: createdHeight,
depositGnsAmount: depositGnsAmount,
}
}
Expand Down Expand Up @@ -154,12 +155,12 @@ type Deposit struct {
stakeTimestamp int64 // staked time
stakeHeight int64 // staked block height

targetPoolPath string // staked position's pool path
tickLower int32 // tick lower
tickUpper int32 // tick upper
liquidity *u256.Uint // liquidity
targetPoolPath string // staked position's pool path
tickLower int32 // tick lower
tickUpper int32 // tick upper
liquidity *u256.Uint // liquidity

lastCollectHeight uint64 // last collect block height

warmups []Warmup // warmup information
warmups []Warmup // warmup information
}

0 comments on commit de425c3

Please sign in to comment.