2020-04-24 15:20:34 +00:00
|
|
|
package incentive
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-04-30 14:13:31 +00:00
|
|
|
|
2020-04-24 15:20:34 +00:00
|
|
|
"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.
|
2021-01-20 05:42:50 +00:00
|
|
|
func InitGenesis(ctx sdk.Context, k keeper.Keeper, supplyKeeper types.SupplyKeeper, cdpKeeper types.CdpKeeper, gs types.GenesisState) {
|
2020-04-24 15:20:34 +00:00
|
|
|
|
|
|
|
// 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))
|
|
|
|
}
|
|
|
|
|
2021-01-21 13:52:09 +00:00
|
|
|
for _, rp := range gs.Params.USDXMintingRewardPeriods {
|
2021-01-20 05:42:50 +00:00
|
|
|
_, found := cdpKeeper.GetCollateral(ctx, rp.CollateralType)
|
|
|
|
if !found {
|
|
|
|
panic(fmt.Sprintf("usdx minting collateral type %s not found in cdp collateral types", rp.CollateralType))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 15:20:34 +00:00
|
|
|
k.SetParams(ctx, gs.Params)
|
|
|
|
|
2021-01-21 13:52:09 +00:00
|
|
|
// TODO: previous hard module accrual times/indexes should be set here
|
|
|
|
|
2021-01-18 19:12:37 +00:00
|
|
|
for _, gat := range gs.PreviousAccumulationTimes {
|
2021-01-21 13:52:09 +00:00
|
|
|
k.SetPreviousUSDXMintingAccrualTime(ctx, gat.CollateralType, gat.PreviousAccumulationTime)
|
|
|
|
k.SetUSDXMintingRewardFactor(ctx, gat.CollateralType, gat.RewardFactor)
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 19:12:37 +00:00
|
|
|
for _, claim := range gs.USDXMintingClaims {
|
2021-01-21 13:52:09 +00:00
|
|
|
k.SetUSDXMintingClaim(ctx, claim)
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExportGenesis export genesis state for incentive module
|
|
|
|
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
|
|
|
|
params := k.GetParams(ctx)
|
|
|
|
|
2021-01-21 13:52:09 +00:00
|
|
|
claims := k.GetAllUSDXMintingClaims(ctx)
|
2020-04-24 15:20:34 +00:00
|
|
|
|
2021-01-18 19:12:37 +00:00
|
|
|
var gats GenesisAccumulationTimes
|
|
|
|
|
2021-01-21 13:52:09 +00:00
|
|
|
for _, rp := range params.USDXMintingRewardPeriods {
|
|
|
|
pat, found := k.GetPreviousUSDXMintingAccrualTime(ctx, rp.CollateralType)
|
2021-01-18 19:12:37 +00:00
|
|
|
if !found {
|
|
|
|
pat = ctx.BlockTime()
|
|
|
|
}
|
2021-01-21 13:52:09 +00:00
|
|
|
factor, found := k.GetUSDXMintingRewardFactor(ctx, rp.CollateralType)
|
2021-01-18 19:12:37 +00:00
|
|
|
if !found {
|
|
|
|
factor = sdk.ZeroDec()
|
|
|
|
}
|
|
|
|
gat := types.NewGenesisAccumulationTime(rp.CollateralType, pat, factor)
|
|
|
|
gats = append(gats, gat)
|
|
|
|
}
|
|
|
|
|
|
|
|
return types.NewGenesisState(params, gats, claims)
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|