Skip to content

Commit

Permalink
chore(gov/staker): Change Non-getter function names (#504)
Browse files Browse the repository at this point in the history
* change function names


Co-authored-by: 0xTopaz <[email protected]>
  • Loading branch information
notJoon and onlyhyde authored Feb 6, 2025
1 parent 275bda4 commit 8034593
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion contract/r/gnoswap/gov/staker/api_staker.gno
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func GetLockedInfoByAddress(addr std.Address) string {
}

func GetClaimableRewardByAddress(addr std.Address) string {
rewardState.finalize(getCurrentBalance(), getCurrentProtocolFeeBalance())
rewardState.finalize(collectAndGetGNSBalance(), updateAndGetProtocolFeeBalance())

emissionReward, protocolFeeRewards := rewardState.CalculateReward(addr)

Expand Down
12 changes: 6 additions & 6 deletions contract/r/gnoswap/gov/staker/reward_calculation.gno
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ var (
currentProtocolFeeBalance map[string]uint64 = make(map[string]uint64) // protocol fee balance of gov/staker (tokenPath -> balance)
)

// getCurrentBalance gets the acuumulated GNS balance from emission to gov/staker
// collectAndGetGNSBalance gets the acuumulated GNS balance from emission to gov/staker
// Need to clear the distributed GNS to gov/staker in emission to get the latest accumulated GNS balance
func getCurrentBalance() uint64 {
func collectAndGetGNSBalance() uint64 {
gotGnsForEmission := en.GetDistributedToGovStaker()
en.ClearDistributedToGovStaker()

Expand All @@ -30,9 +30,9 @@ func getCurrentBalance() uint64 {
return currentGNSBalance
}

// getCurrentProtocolFeeBalance gets the accumulated protocol fee balance from protocol_fee to gov/staker
// updateAndGetProtocolFeeBalance gets the accumulated protocol fee balance from protocol_fee to gov/staker
// Need to clear the accumulated protocol fee to gov/staker in protocol fee to get the latest accumulated protocol fee balance
func getCurrentProtocolFeeBalance() map[string]uint64 {
func updateAndGetProtocolFeeBalance() map[string]uint64 {
pf.DistributeProtocolFee()
gotAccuProtocolFee := pf.GetAccuTransferToGovStaker()

Expand Down Expand Up @@ -316,10 +316,10 @@ func SetAmountByProjectWallet(addr std.Address, amount uint64, add bool) {
currentAmount := getAmountByProjectWallet(addr)
if add {
amountByProjectWallet.Set(addr.String(), currentAmount+amount)
rewardState.addStake(uint64(std.GetHeight()), caller, amount, getCurrentBalance(), getCurrentProtocolFeeBalance())
rewardState.addStake(uint64(std.GetHeight()), caller, amount, collectAndGetGNSBalance(), updateAndGetProtocolFeeBalance())
} else {
amountByProjectWallet.Set(addr.String(), currentAmount-amount)
rewardState.removeStake(caller, amount, getCurrentBalance(), getCurrentProtocolFeeBalance())
rewardState.removeStake(caller, amount, collectAndGetGNSBalance(), updateAndGetProtocolFeeBalance())
}
}

Expand Down
9 changes: 5 additions & 4 deletions contract/r/gnoswap/gov/staker/staker.gno
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Delegate(to std.Address, amount uint64) {
))
}

rewardState.addStake(uint64(std.GetHeight()), caller, amount, getCurrentBalance(), getCurrentProtocolFeeBalance())
rewardState.addStake(uint64(std.GetHeight()), caller, amount, collectAndGetGNSBalance(), updateAndGetProtocolFeeBalance())

// GNS // caller -> GovStaker
gns.TransferFrom(caller, std.CurrentRealm().Addr(), amount)
Expand Down Expand Up @@ -201,7 +201,7 @@ func Undelegate(from std.Address, amount uint64) {
))
}

reward, protocolFeeRewards := rewardState.removeStake(caller, amount, getCurrentBalance(), getCurrentProtocolFeeBalance())
reward, protocolFeeRewards := rewardState.removeStake(caller, amount, collectAndGetGNSBalance(), updateAndGetProtocolFeeBalance())

// burn equivalent amount of xGNS
xgns.Burn(caller, amount)
Expand Down Expand Up @@ -306,7 +306,7 @@ func CollectReward() {
prevAddr, prevPkgPath := getPrev()
caller := std.PrevRealm().Addr()

reward, protocolFeeRewards := rewardState.claim(caller, getCurrentBalance(), getCurrentProtocolFeeBalance())
reward, protocolFeeRewards := rewardState.claim(caller, collectAndGetGNSBalance(), updateAndGetProtocolFeeBalance())

// XXX (@notJoon): There could be cases where the reward pool is empty, In such case,
// it seems appropriate to return 0 and continue processing.
Expand Down Expand Up @@ -372,7 +372,8 @@ func CollectRewardFromLaunchPad(to std.Address) {

prevAddr, prevPkgPath := getPrev()

emissionReward, protocolFeeRewards := rewardState.claim(to, getCurrentBalance(), getCurrentProtocolFeeBalance())
emissionReward, protocolFeeRewards := rewardState.claim(to, collectAndGetGNSBalance(), updateAndGetProtocolFeeBalance())

if emissionReward > 0 {
gns.Transfer(to, emissionReward)
std.Emit(
Expand Down

0 comments on commit 8034593

Please sign in to comment.