Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
notJoon committed Jan 9, 2025
1 parent 0484f69 commit 2dc6624
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions gov/staker/reward_calculation.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
currentGNSBalance uint64
)

func currentBalance() uint64 {
func getCurrentGNSBalance() uint64 {
// TODO: implement this after checking gns distribution is working
// pf.DistributeProtocolFee()
// accuProtocolFee := pf.GetAccuTransferToGovStaker()
Expand All @@ -32,6 +32,28 @@ func currentBalance() uint64 {
return currentGNSBalance
}

var (
currentProtocolFeeBalance *avl.Tree
)

func getCurrentProtocolFeeBalance() *avl.Tree {
gotAccuProtocolFee := pf.GetAccuTransferToGovStaker()
pf.ClearAccuTransferToGovStaker()

gotAccuProtocolFee.Iterate("", "", func(key string, value interface{}) bool {
amount := value.(uint64)
currentValue := uint64(0)
currentValueI, ok := currentProtocolFeeBalance.Get(key)
if ok {
currentValue += currentValueI.(uint64)
}
currentProtocolFeeBalance.Set(key, currentValue + amount)
return false
})

return currentProtocolFeeBalance
}

type StakerRewardInfo struct {
StartHeight uint64 // height when staker started staking
PriceDebt *u256.Uint // price debt per xGNS stake, Q128
Expand Down Expand Up @@ -67,6 +89,7 @@ func NewRewardState() *RewardState {
}

var rewardState = NewRewardState()
var protocolFeeState = NewRewardState()

func (self *RewardState) Debug() string {
return ufmt.Sprintf("{ CurrentBalance: %d, PriceAccumulation: %d, TotalStake: %d, info: len(%d) }", self.CurrentBalance, self.PriceAccumulationUint64(), self.TotalStake, self.info.Size())
Expand Down Expand Up @@ -195,9 +218,10 @@ var (
)

var (
userXGnsRatio = avl.NewTree() // address -> ratioX96
userEmissionReward = avl.NewTree() // address -> gnsAmount
userProtocolFeeReward = avl.NewTree() // address -> tokenPath -> tokenAmount
// userXGnsRatio = avl.NewTree() // address -> ratioX96
// userEmissionReward = avl.NewTree() // address -> gnsAmount
// XXX: 업데이트 안 되고 있음.
// userProtocolFeeReward = avl.NewTree() // address -> tokenPath -> tokenAmount
)

// === LAUNCHPAD DEPOSIT
Expand Down Expand Up @@ -337,6 +361,7 @@ func calculateGNSEmission() {
}

func calculateProtocolFee() {
// XXX: 사용안됨. Set이 안되중 protocol 뭐시기가 업데이트 안되는 중
// gov_staker received protocol_fee
// but no gns has been staked, left amount will be used next time
if userXGnsRatio.Size() == 0 {
Expand Down Expand Up @@ -398,6 +423,7 @@ func calculateProtocolFee() {
if val, exists := alreadyCalculatedProtocolFee.Get(tokenPath); exists {
current = val.(uint64)
}
// XXXXX
alreadyCalculatedProtocolFee.Set(tokenPath, current+tokenBalance.(uint64))
leftProtocolFeeFromLast.Set(tokenPath, tokenBalance.(uint64)-calculated)
}
Expand Down

0 comments on commit 2dc6624

Please sign in to comment.