mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-27 00:35:18 +00:00
1ef9bd331b
* USDX incentives implementation (#399) * feat: upgrade to cosmos-sdk v0.38 Co-authored-by: Denali Marsh <denali@kava.io> Co-authored-by: John Maheswaran <jmaheswaran@users.noreply.github.com> Co-authored-by: John Maheswaran <john@kava.io>
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package incentive
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/kava-labs/kava/x/incentive/keeper"
|
|
"github.com/kava-labs/kava/x/incentive/types"
|
|
)
|
|
|
|
// InitGenesis initializes the store state from a genesis state.
|
|
func InitGenesis(ctx sdk.Context, k keeper.Keeper, supplyKeeper types.SupplyKeeper, gs types.GenesisState) {
|
|
|
|
// check if the module account exists
|
|
moduleAcc := supplyKeeper.GetModuleAccount(ctx, types.IncentiveMacc)
|
|
if moduleAcc == nil {
|
|
panic(fmt.Sprintf("%s module account has not been set", types.IncentiveMacc))
|
|
}
|
|
|
|
if err := gs.Validate(); err != nil {
|
|
panic(fmt.Sprintf("failed to validate %s genesis state: %s", types.ModuleName, err))
|
|
}
|
|
|
|
k.SetParams(ctx, gs.Params)
|
|
|
|
for _, r := range gs.Params.Rewards {
|
|
k.SetNextClaimPeriodID(ctx, r.Denom, 1)
|
|
}
|
|
|
|
// only set the previous block time if it's different than default
|
|
if !gs.PreviousBlockTime.Equal(types.DefaultPreviousBlockTime) {
|
|
k.SetPreviousBlockTime(ctx, gs.PreviousBlockTime)
|
|
}
|
|
|
|
// set store objects
|
|
for _, rp := range gs.RewardPeriods {
|
|
k.SetRewardPeriod(ctx, rp)
|
|
}
|
|
|
|
for _, cp := range gs.ClaimPeriods {
|
|
k.SetClaimPeriod(ctx, cp)
|
|
}
|
|
|
|
for _, c := range gs.Claims {
|
|
k.SetClaim(ctx, c)
|
|
}
|
|
|
|
for _, id := range gs.NextClaimPeriodIDs {
|
|
k.SetNextClaimPeriodID(ctx, id.Denom, id.ID)
|
|
}
|
|
|
|
}
|
|
|
|
// ExportGenesis export genesis state for incentive module
|
|
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
|
|
// get all objects out of the store
|
|
params := k.GetParams(ctx)
|
|
previousBlockTime, found := k.GetPreviousBlockTime(ctx)
|
|
|
|
// since it is not set in genesis, if somehow the chain got started and was exported
|
|
// immediately after InitGenesis, there would be no previousBlockTime value.
|
|
if !found {
|
|
previousBlockTime = types.DefaultPreviousBlockTime
|
|
}
|
|
|
|
// Get all objects from the store
|
|
rewardPeriods := k.GetAllRewardPeriods(ctx)
|
|
claimPeriods := k.GetAllClaimPeriods(ctx)
|
|
claims := k.GetAllClaims(ctx)
|
|
claimPeriodIDs := k.GetAllClaimPeriodIDPairs(ctx)
|
|
|
|
return types.NewGenesisState(params, previousBlockTime, rewardPeriods, claimPeriods, claims, claimPeriodIDs)
|
|
}
|