0g-chain/x/incentive/abci.go
Derrick Lee dce631d3de
Add generic incentive AccumulateRewards method (#1392)
* Add generic accumulator

* Add MultiRewardPeriodOfClaimType type to params

* Add adapters wrapper

* Add MultiRewardPeriodsOfClaimType to params

* Add multireward period to genesis test

* Rename MultiRewardPeriodOfClaimType to TypedMultiRewardPeriod

* Use source adapters wrapper
2022-11-29 13:59:11 -08:00

46 lines
1.2 KiB
Go

package incentive
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/incentive/keeper"
)
// BeginBlocker runs at the start of every block
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
params := k.GetParams(ctx)
for _, rp := range params.USDXMintingRewardPeriods {
k.AccumulateUSDXMintingRewards(ctx, rp)
}
for _, rp := range params.HardSupplyRewardPeriods {
k.AccumulateHardSupplyRewards(ctx, rp)
}
for _, rp := range params.HardBorrowRewardPeriods {
k.AccumulateHardBorrowRewards(ctx, rp)
}
for _, rp := range params.DelegatorRewardPeriods {
k.AccumulateDelegatorRewards(ctx, rp)
}
for _, rp := range params.SwapRewardPeriods {
k.AccumulateSwapRewards(ctx, rp)
}
for _, rp := range params.SavingsRewardPeriods {
k.AccumulateSavingsRewards(ctx, rp)
}
for _, rp := range params.EarnRewardPeriods {
if err := k.AccumulateEarnRewards(ctx, rp); err != nil {
panic(fmt.Sprintf("failed to accumulate earn rewards: %s", err))
}
}
// New generic RewardPeriods
for _, mrp := range params.RewardPeriods {
for _, rp := range mrp.RewardPeriods {
k.AccumulateRewards(ctx, mrp.ClaimType, rp)
}
}
}