2020-04-24 15:20:34 +00:00
|
|
|
package incentive
|
|
|
|
|
|
|
|
import (
|
2022-09-28 20:20:01 +00:00
|
|
|
"fmt"
|
2023-08-25 22:14:35 +00:00
|
|
|
"time"
|
2022-09-28 20:20:01 +00:00
|
|
|
|
2023-08-25 22:14:35 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/telemetry"
|
2020-04-24 15:20:34 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-04-30 14:13:31 +00:00
|
|
|
|
2024-05-01 03:17:24 +00:00
|
|
|
"github.com/0glabs/0g-chain/x/incentive/keeper"
|
|
|
|
"github.com/0glabs/0g-chain/x/incentive/types"
|
2020-04-24 15:20:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// BeginBlocker runs at the start of every block
|
|
|
|
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
|
2023-08-25 22:14:35 +00:00
|
|
|
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
|
|
|
|
|
2021-01-21 13:52:09 +00:00
|
|
|
params := k.GetParams(ctx)
|
2021-07-22 12:53:18 +00:00
|
|
|
|
2021-01-21 13:52:09 +00:00
|
|
|
for _, rp := range params.USDXMintingRewardPeriods {
|
2021-07-22 12:53:18 +00:00
|
|
|
k.AccumulateUSDXMintingRewards(ctx, rp)
|
2021-01-21 13:52:09 +00:00
|
|
|
}
|
|
|
|
for _, rp := range params.HardSupplyRewardPeriods {
|
2021-07-22 12:53:18 +00:00
|
|
|
k.AccumulateHardSupplyRewards(ctx, rp)
|
2021-01-21 13:52:09 +00:00
|
|
|
}
|
|
|
|
for _, rp := range params.HardBorrowRewardPeriods {
|
2021-07-22 12:53:18 +00:00
|
|
|
k.AccumulateHardBorrowRewards(ctx, rp)
|
2021-01-18 19:12:37 +00:00
|
|
|
}
|
2021-07-07 16:50:14 +00:00
|
|
|
for _, rp := range params.DelegatorRewardPeriods {
|
2021-07-22 12:53:18 +00:00
|
|
|
k.AccumulateDelegatorRewards(ctx, rp)
|
2021-01-29 20:32:07 +00:00
|
|
|
}
|
2021-07-07 13:23:06 +00:00
|
|
|
for _, rp := range params.SwapRewardPeriods {
|
|
|
|
k.AccumulateSwapRewards(ctx, rp)
|
|
|
|
}
|
2022-04-12 14:14:14 +00:00
|
|
|
for _, rp := range params.SavingsRewardPeriods {
|
|
|
|
k.AccumulateSavingsRewards(ctx, rp)
|
|
|
|
}
|
2022-09-22 18:26:08 +00:00
|
|
|
for _, rp := range params.EarnRewardPeriods {
|
2022-09-28 20:20:01 +00:00
|
|
|
if err := k.AccumulateEarnRewards(ctx, rp); err != nil {
|
|
|
|
panic(fmt.Sprintf("failed to accumulate earn rewards: %s", err))
|
|
|
|
}
|
2022-09-22 18:26:08 +00:00
|
|
|
}
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|