Incentive genesis refactor: remove sync on export (#954)

* move defualt values to file where they're used

* add type to hold RewardIndexes in genesis state

* add reward indexes state to genesis

* fix genesis state importers

* add iterator keeper methods for accrual times

* remove syncing from export/init genesis

* separate incentive migration to new file

* refactor out common funcs from incentive migration

* update legacy genesis state to v0.14.3

* add test and example migrated json

* fully initialize rewards in genesis builder

* add kava-7-mainnet incentive state

* run aliasgen

* add missing type to incentive/legacy

Co-authored-by: karzak <kjydavis3@gmail.com>
This commit is contained in:
Ruaridh 2021-07-15 15:41:55 +01:00 committed by GitHub
parent e48fed1e27
commit 013093ecb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 1620 additions and 497 deletions

164
migrate/v0_15/incentive.go Normal file
View File

@ -0,0 +1,164 @@
package v0_15
import (
sdk "github.com/cosmos/cosmos-sdk/types"
v0_14incentive "github.com/kava-labs/kava/x/incentive/legacy/v0_14"
v0_15incentive "github.com/kava-labs/kava/x/incentive/types"
)
// Incentive migrates from a v0.14 incentive genesis state to a v0.15 incentive genesis state
func Incentive(incentiveGS v0_14incentive.GenesisState) v0_15incentive.GenesisState {
// Migrate params
claimMultipliers := v0_15incentive.Multipliers{}
for _, m := range incentiveGS.Params.ClaimMultipliers {
newMultiplier := v0_15incentive.NewMultiplier(v0_15incentive.MultiplierName(m.Name), m.MonthsLockup, m.Factor)
claimMultipliers = append(claimMultipliers, newMultiplier)
}
usdxMintingRewardPeriods := v0_15incentive.RewardPeriods{}
for _, rp := range incentiveGS.Params.USDXMintingRewardPeriods {
usdxMintingRewardPeriod := v0_15incentive.NewRewardPeriod(rp.Active,
rp.CollateralType, rp.Start, rp.End, rp.RewardsPerSecond)
usdxMintingRewardPeriods = append(usdxMintingRewardPeriods, usdxMintingRewardPeriod)
}
hardDelegatorRewardPeriods := v0_15incentive.MultiRewardPeriods{}
for _, rp := range incentiveGS.Params.HardDelegatorRewardPeriods {
rewardsPerSecond := sdk.NewCoins(rp.RewardsPerSecond, SwpRewardsPerSecond)
hardDelegatorRewardPeriod := v0_15incentive.NewMultiRewardPeriod(rp.Active,
rp.CollateralType, rp.Start, rp.End, rewardsPerSecond)
hardDelegatorRewardPeriods = append(hardDelegatorRewardPeriods, hardDelegatorRewardPeriod)
}
swapRewardPeriods := v0_15incentive.DefaultMultiRewardPeriods
// TODO add expected swap reward periods
// Build new params from migrated values
params := v0_15incentive.NewParams(
usdxMintingRewardPeriods,
migrateMultiRewardPeriods(incentiveGS.Params.HardSupplyRewardPeriods),
migrateMultiRewardPeriods(incentiveGS.Params.HardBorrowRewardPeriods),
hardDelegatorRewardPeriods,
swapRewardPeriods,
claimMultipliers,
incentiveGS.Params.ClaimEnd,
)
// Migrate accumulation times and reward indexes
usdxGenesisRewardState := migrateGenesisRewardState(incentiveGS.USDXAccumulationTimes, incentiveGS.USDXRewardIndexes)
hardSupplyGenesisRewardState := migrateGenesisRewardState(incentiveGS.HardSupplyAccumulationTimes, incentiveGS.HardSupplyRewardIndexes)
hardBorrowGenesisRewardState := migrateGenesisRewardState(incentiveGS.HardBorrowAccumulationTimes, incentiveGS.HardBorrowRewardIndexes)
delegatorGenesisRewardState := migrateGenesisRewardState(incentiveGS.HardDelegatorAccumulationTimes, incentiveGS.HardDelegatorRewardIndexes)
swapGenesisRewardState := v0_15incentive.DefaultGenesisRewardState // There is no previous swap rewards so accumulation starts at genesis time.
// Migrate USDX minting claims
usdxMintingClaims := v0_15incentive.USDXMintingClaims{}
for _, claim := range incentiveGS.USDXMintingClaims {
rewardIndexes := migrateRewardIndexes(claim.RewardIndexes)
usdxMintingClaim := v0_15incentive.NewUSDXMintingClaim(claim.Owner, claim.Reward, rewardIndexes)
usdxMintingClaims = append(usdxMintingClaims, usdxMintingClaim)
}
// Migrate Hard protocol claims (includes creating new Delegator claims)
hardClaims := v0_15incentive.HardLiquidityProviderClaims{}
delegatorClaims := v0_15incentive.DelegatorClaims{}
for _, claim := range incentiveGS.HardLiquidityProviderClaims {
// Migrate supply multi reward indexes
supplyMultiRewardIndexes := migrateMultiRewardIndexes(claim.SupplyRewardIndexes)
// Migrate borrow multi reward indexes
borrowMultiRewardIndexes := migrateMultiRewardIndexes(claim.BorrowRewardIndexes)
// Migrate delegator reward indexes to multi reward indexes inside DelegatorClaims
delegatorMultiRewardIndexes := v0_15incentive.MultiRewardIndexes{}
delegatorRewardIndexes := v0_15incentive.RewardIndexes{}
for _, ri := range claim.DelegatorRewardIndexes {
// TODO add checks to ensure old reward indexes are as expected
delegatorRewardIndex := v0_15incentive.NewRewardIndex(v0_14incentive.HardLiquidityRewardDenom, ri.RewardFactor)
delegatorRewardIndexes = append(delegatorRewardIndexes, delegatorRewardIndex)
}
// TODO should this include indexes if none exist on the old claim?
delegatorMultiRewardIndex := v0_15incentive.NewMultiRewardIndex(v0_14incentive.BondDenom, delegatorRewardIndexes)
delegatorMultiRewardIndexes = append(delegatorMultiRewardIndexes, delegatorMultiRewardIndex)
// TODO: It's impossible to distinguish between rewards from delegation vs. liquidity providing
// as they're all combined inside claim.Reward, so I'm just putting them all inside
// the hard claim to avoid duplicating rewards.
delegatorClaim := v0_15incentive.NewDelegatorClaim(claim.Owner, sdk.NewCoins(), delegatorMultiRewardIndexes)
delegatorClaims = append(delegatorClaims, delegatorClaim)
hardClaim := v0_15incentive.NewHardLiquidityProviderClaim(claim.Owner, claim.Reward,
supplyMultiRewardIndexes, borrowMultiRewardIndexes)
hardClaims = append(hardClaims, hardClaim)
}
// Add Swap Claims
swapClaims := v0_15incentive.DefaultSwapClaims
return v0_15incentive.NewGenesisState(
params,
usdxGenesisRewardState,
hardSupplyGenesisRewardState,
hardBorrowGenesisRewardState,
delegatorGenesisRewardState,
swapGenesisRewardState,
usdxMintingClaims,
hardClaims,
delegatorClaims,
swapClaims,
)
}
func migrateMultiRewardPeriods(oldPeriods v0_14incentive.MultiRewardPeriods) v0_15incentive.MultiRewardPeriods {
newPeriods := v0_15incentive.MultiRewardPeriods{}
for _, rp := range oldPeriods {
newPeriod := v0_15incentive.NewMultiRewardPeriod(
rp.Active,
rp.CollateralType,
rp.Start,
rp.End,
rp.RewardsPerSecond,
)
newPeriods = append(newPeriods, newPeriod)
}
return newPeriods
}
func migrateGenesisRewardState(oldAccumulationTimes v0_14incentive.GenesisAccumulationTimes, oldIndexes v0_14incentive.GenesisRewardIndexesSlice) v0_15incentive.GenesisRewardState {
accumulationTimes := v0_15incentive.AccumulationTimes{}
for _, t := range oldAccumulationTimes {
newAccumulationTime := v0_15incentive.NewAccumulationTime(t.CollateralType, t.PreviousAccumulationTime)
accumulationTimes = append(accumulationTimes, newAccumulationTime)
}
multiRewardIndexes := v0_15incentive.MultiRewardIndexes{}
for _, gri := range oldIndexes {
multiRewardIndex := v0_15incentive.NewMultiRewardIndex(gri.CollateralType, migrateRewardIndexes(gri.RewardIndexes))
multiRewardIndexes = append(multiRewardIndexes, multiRewardIndex)
}
return v0_15incentive.NewGenesisRewardState(
accumulationTimes,
multiRewardIndexes,
)
}
func migrateMultiRewardIndexes(oldIndexes v0_14incentive.MultiRewardIndexes) v0_15incentive.MultiRewardIndexes {
newIndexes := v0_15incentive.MultiRewardIndexes{}
for _, mri := range oldIndexes {
multiRewardIndex := v0_15incentive.NewMultiRewardIndex(
mri.CollateralType,
migrateRewardIndexes(mri.RewardIndexes),
)
newIndexes = append(newIndexes, multiRewardIndex)
}
return newIndexes
}
func migrateRewardIndexes(oldIndexes v0_14incentive.RewardIndexes) v0_15incentive.RewardIndexes {
newIndexes := v0_15incentive.RewardIndexes{}
for _, ri := range oldIndexes {
rewardIndex := v0_15incentive.NewRewardIndex(ri.CollateralType, ri.RewardFactor)
newIndexes = append(newIndexes, rewardIndex)
}
return newIndexes
}

View File

@ -22,6 +22,7 @@ var (
GenesisTime = time.Date(2021, 4, 8, 15, 0, 0, 0, time.UTC)
ChainID = "kava-8"
// TODO: update SWP reward per second amount before production
// TODO: add swap tokens to kavadist module account
SwpRewardsPerSecond = sdk.NewCoin("swp", sdk.OneInt())
)
@ -306,152 +307,3 @@ func loadStabilityComMembers() ([]sdk.AccAddress, error) {
func Swap() v0_15swap.GenesisState {
return v0_15swap.NewGenesisState(v0_15swap.DefaultParams())
}
// Incentive migrates from a v0.14 incentive genesis state to a v0.15 incentive genesis state
func Incentive(incentiveGS v0_14incentive.GenesisState) v0_15incentive.GenesisState {
// Migrate params
var claimMultipliers v0_15incentive.Multipliers
for _, m := range incentiveGS.Params.ClaimMultipliers {
newMultiplier := v0_15incentive.NewMultiplier(v0_15incentive.MultiplierName(m.Name), m.MonthsLockup, m.Factor)
claimMultipliers = append(claimMultipliers, newMultiplier)
}
var usdxMintingRewardPeriods v0_15incentive.RewardPeriods
for _, rp := range incentiveGS.Params.USDXMintingRewardPeriods {
usdxMintingRewardPeriod := v0_15incentive.NewRewardPeriod(rp.Active,
rp.CollateralType, rp.Start, rp.End, rp.RewardsPerSecond)
usdxMintingRewardPeriods = append(usdxMintingRewardPeriods, usdxMintingRewardPeriod)
}
var hardSupplyRewardPeriods v0_15incentive.MultiRewardPeriods
for _, rp := range incentiveGS.Params.HardSupplyRewardPeriods {
hardSupplyRewardPeriod := v0_15incentive.NewMultiRewardPeriod(rp.Active,
rp.CollateralType, rp.Start, rp.End, rp.RewardsPerSecond)
hardSupplyRewardPeriods = append(hardSupplyRewardPeriods, hardSupplyRewardPeriod)
}
var hardBorrowRewardPeriods v0_15incentive.MultiRewardPeriods
for _, rp := range incentiveGS.Params.HardBorrowRewardPeriods {
hardBorrowRewardPeriod := v0_15incentive.NewMultiRewardPeriod(rp.Active,
rp.CollateralType, rp.Start, rp.End, rp.RewardsPerSecond)
hardBorrowRewardPeriods = append(hardBorrowRewardPeriods, hardBorrowRewardPeriod)
}
var hardDelegatorRewardPeriods v0_15incentive.MultiRewardPeriods
for _, rp := range incentiveGS.Params.HardDelegatorRewardPeriods {
rewardsPerSecond := sdk.NewCoins(rp.RewardsPerSecond, SwpRewardsPerSecond)
hardDelegatorRewardPeriod := v0_15incentive.NewMultiRewardPeriod(rp.Active,
rp.CollateralType, rp.Start, rp.End, rewardsPerSecond)
hardDelegatorRewardPeriods = append(hardDelegatorRewardPeriods, hardDelegatorRewardPeriod)
}
// Build new params from migrated values
params := v0_15incentive.NewParams(
usdxMintingRewardPeriods,
hardSupplyRewardPeriods,
hardBorrowRewardPeriods,
hardDelegatorRewardPeriods,
v0_15incentive.DefaultMultiRewardPeriods, // TODO add expected swap reward periods
claimMultipliers,
incentiveGS.Params.ClaimEnd,
)
// Migrate accumulation times
var usdxAccumulationTimes v0_15incentive.GenesisAccumulationTimes
for _, t := range incentiveGS.USDXAccumulationTimes {
newAccumulationTime := v0_15incentive.NewGenesisAccumulationTime(t.CollateralType, t.PreviousAccumulationTime)
usdxAccumulationTimes = append(usdxAccumulationTimes, newAccumulationTime)
}
var hardSupplyAccumulationTimes v0_15incentive.GenesisAccumulationTimes
for _, t := range incentiveGS.HardSupplyAccumulationTimes {
newAccumulationTime := v0_15incentive.NewGenesisAccumulationTime(t.CollateralType, t.PreviousAccumulationTime)
hardSupplyAccumulationTimes = append(hardSupplyAccumulationTimes, newAccumulationTime)
}
var hardBorrowAccumulationTimes v0_15incentive.GenesisAccumulationTimes
for _, t := range incentiveGS.HardBorrowAccumulationTimes {
newAccumulationTime := v0_15incentive.NewGenesisAccumulationTime(t.CollateralType, t.PreviousAccumulationTime)
hardBorrowAccumulationTimes = append(hardBorrowAccumulationTimes, newAccumulationTime)
}
var hardDelegatorAccumulationTimes v0_15incentive.GenesisAccumulationTimes
for _, t := range incentiveGS.HardDelegatorAccumulationTimes {
newAccumulationTime := v0_15incentive.NewGenesisAccumulationTime(t.CollateralType, t.PreviousAccumulationTime)
hardDelegatorAccumulationTimes = append(hardDelegatorAccumulationTimes, newAccumulationTime)
}
// Migrate USDX minting claims
var usdxMintingClaims v0_15incentive.USDXMintingClaims
for _, claim := range incentiveGS.USDXMintingClaims {
var rewardIndexes v0_15incentive.RewardIndexes
for _, ri := range claim.RewardIndexes {
rewardIndex := v0_15incentive.NewRewardIndex(ri.CollateralType, ri.RewardFactor)
rewardIndexes = append(rewardIndexes, rewardIndex)
}
usdxMintingClaim := v0_15incentive.NewUSDXMintingClaim(claim.Owner, claim.Reward, rewardIndexes)
usdxMintingClaims = append(usdxMintingClaims, usdxMintingClaim)
}
// Migrate Hard protocol claims (includes creating new Delegator claims)
var hardClaims v0_15incentive.HardLiquidityProviderClaims
var delegatorClaims v0_15incentive.DelegatorClaims
for _, claim := range incentiveGS.HardLiquidityProviderClaims {
// Migrate supply multi reward indexes
var supplyMultiRewardIndexes v0_15incentive.MultiRewardIndexes
for _, sri := range claim.SupplyRewardIndexes {
var rewardIndexes v0_15incentive.RewardIndexes
for _, ri := range sri.RewardIndexes {
rewardIndex := v0_15incentive.NewRewardIndex(ri.CollateralType, ri.RewardFactor)
rewardIndexes = append(rewardIndexes, rewardIndex)
}
supplyMultiRewardIndex := v0_15incentive.NewMultiRewardIndex(sri.CollateralType, rewardIndexes)
supplyMultiRewardIndexes = append(supplyMultiRewardIndexes, supplyMultiRewardIndex)
}
// Migrate borrow multi reward indexes
var borrowMultiRewardIndexes v0_15incentive.MultiRewardIndexes
for _, bri := range claim.BorrowRewardIndexes {
var rewardIndexes v0_15incentive.RewardIndexes
for _, ri := range bri.RewardIndexes {
rewardIndex := v0_15incentive.NewRewardIndex(ri.CollateralType, ri.RewardFactor)
rewardIndexes = append(rewardIndexes, rewardIndex)
}
borrowMultiRewardIndex := v0_15incentive.NewMultiRewardIndex(bri.CollateralType, rewardIndexes)
borrowMultiRewardIndexes = append(borrowMultiRewardIndexes, borrowMultiRewardIndex)
}
// Migrate delegator reward indexes to multi reward indexes inside DelegatorClaims
var delegatorMultiRewardIndexes v0_15incentive.MultiRewardIndexes
var delegatorRewardIndexes v0_15incentive.RewardIndexes
for _, ri := range claim.DelegatorRewardIndexes {
delegatorRewardIndex := v0_15incentive.NewRewardIndex(ri.CollateralType, ri.RewardFactor)
delegatorRewardIndexes = append(delegatorRewardIndexes, delegatorRewardIndex)
}
delegatorMultiRewardIndex := v0_15incentive.NewMultiRewardIndex(v0_15incentive.BondDenom, delegatorRewardIndexes)
delegatorMultiRewardIndexes = append(delegatorMultiRewardIndexes, delegatorMultiRewardIndex)
// TODO: It's impossible to distinguish between rewards from delegation vs. liquidity providing
// as they're all combined inside claim.Reward, so I'm just putting them all inside
// the hard claim to avoid duplicating rewards.
delegatorClaim := v0_15incentive.NewDelegatorClaim(claim.Owner, sdk.NewCoins(), delegatorMultiRewardIndexes)
delegatorClaims = append(delegatorClaims, delegatorClaim)
hardClaim := v0_15incentive.NewHardLiquidityProviderClaim(claim.Owner, claim.Reward,
supplyMultiRewardIndexes, borrowMultiRewardIndexes)
hardClaims = append(hardClaims, hardClaim)
}
return v0_15incentive.NewGenesisState(
params,
usdxAccumulationTimes,
hardSupplyAccumulationTimes,
hardBorrowAccumulationTimes,
hardDelegatorAccumulationTimes,
v0_15incentive.DefaultGenesisAccumulationTimes, // There is no previous swap rewards so accumulation starts at genesis time.
usdxMintingClaims,
hardClaims,
delegatorClaims,
v0_15incentive.DefaultSwapClaims,
)
}

View File

@ -8,6 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/stretchr/testify/require"
@ -63,7 +64,8 @@ func exportGenesisJSON(genState v0_15committee.GenesisState) {
ioutil.WriteFile(filepath.Join("testdata", "kava-8-committee-state.json"), v15Cdc.MustMarshalJSON(genState), 0644)
}
func TestIncentive(t *testing.T) {
func TestIncentive_MainnetState(t *testing.T) {
// TODO add copy of mainnet state to json
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-7-incentive-state.json"))
require.NoError(t, err)
var oldIncentiveGenState v0_14incentive.GenesisState
@ -84,3 +86,16 @@ func TestIncentive(t *testing.T) {
// 1 new DelegatorClaim should have been created for each existing HardLiquidityProviderClaim
require.Equal(t, len(oldIncentiveGenState.HardLiquidityProviderClaims), len(newGenState.DelegatorClaims))
}
func TestIncentive(t *testing.T) {
bz, err := ioutil.ReadFile(filepath.Join("testdata", "v0_14-incentive-state.json"))
require.NoError(t, err)
appState := genutil.AppMap{v0_14incentive.ModuleName: bz}
MigrateAppState(appState)
bz, err = ioutil.ReadFile(filepath.Join("testdata", "v0_15-incentive-state.json"))
require.NoError(t, err)
require.JSONEq(t, string(bz), string(appState[v0_15incentive.ModuleName]))
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,277 @@
{
"hard_borrow_accumulation_times": [],
"hard_borrow_reward_indexes": [],
"hard_delegator_accumulation_times": [
{
"collateral_type": "ukava",
"previous_accumulation_time": "2021-04-08T15:00:00Z"
}
],
"hard_delegator_reward_indexes": [
{
"collateral_type": "ukava",
"reward_indexes": [
{
"collateral_type": "hard",
"reward_factor": "0.000000000000000000"
}
]
}
],
"hard_liquidity_provider_claims": [
{
"base_claim": {
"owner": "kava1zx2gfs37vszrgrxke22mtlfj6hpl72y03ur7xr",
"reward": [
{
"amount": "48396109",
"denom": "hard"
},
{
"amount": "1",
"denom": "ukava"
}
]
},
"borrow_reward_indexes": [],
"delegator_reward_indexes": [
{
"collateral_type": "ukava",
"reward_factor": "0.000000000000000000"
}
],
"supply_reward_indexes": [
{
"collateral_type": "bnb",
"reward_indexes": [
{
"collateral_type": "hard",
"reward_factor": "0.000000000000000000"
}
]
},
{
"collateral_type": "usdx",
"reward_indexes": [
{
"collateral_type": "hard",
"reward_factor": "0.000000000000000000"
},
{
"collateral_type": "ukava",
"reward_factor": "0.000000000000000000"
}
]
}
]
},
{
"base_claim": {
"owner": "kava1zyu77sruwsk7vw8pkcrj20ees0gyjlfntrgahy",
"reward": []
},
"borrow_reward_indexes": [],
"delegator_reward_indexes": [],
"supply_reward_indexes": []
},
{
"base_claim": {
"owner": "kava1zyu7gxmdcd7x83ndl2nvegj57lasf7cel4nrex",
"reward": [
{
"amount": "6442528",
"denom": "hard"
}
]
},
"borrow_reward_indexes": [],
"delegator_reward_indexes": [
{
"collateral_type": "ukava",
"reward_factor": "0.000000000000000000"
}
],
"supply_reward_indexes": []
}
],
"hard_supply_accumulation_times": [
{
"collateral_type": "bnb",
"previous_accumulation_time": "2021-04-08T15:00:00Z"
},
{
"collateral_type": "usdx",
"previous_accumulation_time": "2021-04-08T15:00:00Z"
}
],
"hard_supply_reward_indexes": [
{
"collateral_type": "bnb",
"reward_indexes": [
{
"collateral_type": "hard",
"reward_factor": "0.000000000000000000"
}
]
},
{
"collateral_type": "usdx",
"reward_indexes": [
{
"collateral_type": "hard",
"reward_factor": "0.000000000000000000"
},
{
"collateral_type": "ukava",
"reward_factor": "0.000000000000000000"
}
]
}
],
"params": {
"claim_end": "2026-04-08T14:00:00Z",
"claim_multipliers": [
{
"factor": "0.200000000000000000",
"months_lockup": "1",
"name": "small"
},
{
"factor": "1.000000000000000000",
"months_lockup": "12",
"name": "large"
}
],
"hard_borrow_reward_periods": [],
"hard_delegator_reward_periods": [
{
"active": true,
"collateral_type": "ukava",
"end": "2024-10-16T14:00:00Z",
"rewards_per_second": {
"amount": "633761",
"denom": "hard"
},
"start": "2020-10-16T14:00:00Z"
}
],
"hard_supply_reward_periods": [
{
"active": true,
"collateral_type": "usdx",
"end": "2024-10-16T14:00:00Z",
"rewards_per_second": [
{
"amount": "373919",
"denom": "hard"
},
{
"amount": "373919",
"denom": "ukava"
}
],
"start": "2020-10-16T14:00:00Z"
},
{
"active": true,
"collateral_type": "bnb",
"end": "2024-10-16T14:00:00Z",
"rewards_per_second": [
{
"amount": "12675",
"denom": "hard"
}
],
"start": "2020-10-16T14:00:00Z"
}
],
"usdx_minting_reward_periods": [
{
"active": true,
"collateral_type": "btcb-a",
"end": "2022-04-08T14:00:00Z",
"rewards_per_second": {
"amount": "110780",
"denom": "ukava"
},
"start": "2021-04-08T15:00:00Z"
},
{
"active": true,
"collateral_type": "bnb-a",
"end": "2022-04-08T14:00:00Z",
"rewards_per_second": {
"amount": "122354",
"denom": "ukava"
},
"start": "2021-04-08T15:00:00Z"
}
]
},
"usdx_accumulation_times": [
{
"collateral_type": "bnb-a",
"previous_accumulation_time": "2021-04-08T15:00:00Z"
},
{
"collateral_type": "btcb-a",
"previous_accumulation_time": "2021-04-08T15:00:00Z"
}
],
"usdx_minting_claims": [
{
"base_claim": {
"owner": "kava177dtrf8ahjp3wud6p3aqurpuyqae3mq8n069m9",
"reward": {
"amount": "81528",
"denom": "ukava"
}
},
"reward_indexes": [
{
"collateral_type": "bnb-a",
"reward_factor": "0.000000000000000000"
}
]
},
{
"base_claim": {
"owner": "kava18dde5uvs9h474wj5pe69wg66s2v30whpsqgwee",
"reward": {
"amount": "4825232",
"denom": "ukava"
}
},
"reward_indexes": [
{
"collateral_type": "bnb-a",
"reward_factor": "0.000000000000000000"
},
{
"collateral_type": "btcb-a",
"reward_factor": "0.000000000000000000"
}
]
}
],
"usdx_reward_indexes": [
{
"collateral_type": "bnb-a",
"reward_indexes": [
{
"collateral_type": "ukava",
"reward_factor": "0.000000000000000000"
}
]
},
{
"collateral_type": "btcb-a",
"reward_indexes": [
{
"collateral_type": "ukava",
"reward_factor": "0.000000000000000000"
}
]
}
]
}

View File

@ -0,0 +1,332 @@
{
"delegator_claims": [
{
"base_claim": {
"owner": "kava1zx2gfs37vszrgrxke22mtlfj6hpl72y03ur7xr",
"reward": []
},
"reward_indexes": [
{
"collateral_type": "ukava",
"reward_indexes": [
{
"collateral_type": "hard",
"reward_factor": "0.000000000000000000"
}
]
}
]
},
{
"base_claim": {
"owner": "kava1zyu77sruwsk7vw8pkcrj20ees0gyjlfntrgahy",
"reward": []
},
"reward_indexes": [
{
"collateral_type": "ukava",
"reward_indexes": []
}
]
},
{
"base_claim": {
"owner": "kava1zyu7gxmdcd7x83ndl2nvegj57lasf7cel4nrex",
"reward": []
},
"reward_indexes": [
{
"collateral_type": "ukava",
"reward_indexes": [
{
"collateral_type": "hard",
"reward_factor": "0.000000000000000000"
}
]
}
]
}
],
"delegator_reward_state": {
"accumulation_times": [
{
"collateral_type": "ukava",
"previous_accumulation_time": "2021-04-08T15:00:00Z"
}
],
"multi_reward_indexes": [
{
"collateral_type": "ukava",
"reward_indexes": [
{
"collateral_type": "hard",
"reward_factor": "0.000000000000000000"
}
]
}
]
},
"hard_borrow_reward_state": {
"accumulation_times": [],
"multi_reward_indexes": []
},
"hard_liquidity_provider_claims": [
{
"base_claim": {
"owner": "kava1zx2gfs37vszrgrxke22mtlfj6hpl72y03ur7xr",
"reward": [
{
"amount": "48396109",
"denom": "hard"
},
{
"amount": "1",
"denom": "ukava"
}
]
},
"borrow_reward_indexes": [],
"supply_reward_indexes": [
{
"collateral_type": "bnb",
"reward_indexes": [
{
"collateral_type": "hard",
"reward_factor": "0.000000000000000000"
}
]
},
{
"collateral_type": "usdx",
"reward_indexes": [
{
"collateral_type": "hard",
"reward_factor": "0.000000000000000000"
},
{
"collateral_type": "ukava",
"reward_factor": "0.000000000000000000"
}
]
}
]
},
{
"base_claim": {
"owner": "kava1zyu77sruwsk7vw8pkcrj20ees0gyjlfntrgahy",
"reward": []
},
"borrow_reward_indexes": [],
"supply_reward_indexes": []
},
{
"base_claim": {
"owner": "kava1zyu7gxmdcd7x83ndl2nvegj57lasf7cel4nrex",
"reward": [
{
"amount": "6442528",
"denom": "hard"
}
]
},
"borrow_reward_indexes": [],
"supply_reward_indexes": []
}
],
"hard_supply_reward_state": {
"accumulation_times": [
{
"collateral_type": "bnb",
"previous_accumulation_time": "2021-04-08T15:00:00Z"
},
{
"collateral_type": "usdx",
"previous_accumulation_time": "2021-04-08T15:00:00Z"
}
],
"multi_reward_indexes": [
{
"collateral_type": "bnb",
"reward_indexes": [
{
"collateral_type": "hard",
"reward_factor": "0.000000000000000000"
}
]
},
{
"collateral_type": "usdx",
"reward_indexes": [
{
"collateral_type": "hard",
"reward_factor": "0.000000000000000000"
},
{
"collateral_type": "ukava",
"reward_factor": "0.000000000000000000"
}
]
}
]
},
"params": {
"claim_end": "2026-04-08T14:00:00Z",
"claim_multipliers": [
{
"factor": "0.200000000000000000",
"months_lockup": "1",
"name": "small"
},
{
"factor": "1.000000000000000000",
"months_lockup": "12",
"name": "large"
}
],
"delegator_reward_periods": [
{
"active": true,
"collateral_type": "ukava",
"end": "2024-10-16T14:00:00Z",
"rewards_per_second": [
{
"amount": "633761",
"denom": "hard"
},
{
"amount": "1",
"denom": "swp"
}
],
"start": "2020-10-16T14:00:00Z"
}
],
"hard_borrow_reward_periods": [],
"hard_supply_reward_periods": [
{
"active": true,
"collateral_type": "usdx",
"end": "2024-10-16T14:00:00Z",
"rewards_per_second": [
{
"amount": "373919",
"denom": "hard"
},
{
"amount": "373919",
"denom": "ukava"
}
],
"start": "2020-10-16T14:00:00Z"
},
{
"active": true,
"collateral_type": "bnb",
"end": "2024-10-16T14:00:00Z",
"rewards_per_second": [
{
"amount": "12675",
"denom": "hard"
}
],
"start": "2020-10-16T14:00:00Z"
}
],
"swap_reward_periods": [],
"usdx_minting_reward_periods": [
{
"active": true,
"collateral_type": "btcb-a",
"end": "2022-04-08T14:00:00Z",
"rewards_per_second": {
"amount": "110780",
"denom": "ukava"
},
"start": "2021-04-08T15:00:00Z"
},
{
"active": true,
"collateral_type": "bnb-a",
"end": "2022-04-08T14:00:00Z",
"rewards_per_second": {
"amount": "122354",
"denom": "ukava"
},
"start": "2021-04-08T15:00:00Z"
}
]
},
"swap_claims": [],
"swap_reward_state": {
"accumulation_times": [],
"multi_reward_indexes": []
},
"usdx_minting_claims": [
{
"base_claim": {
"owner": "kava177dtrf8ahjp3wud6p3aqurpuyqae3mq8n069m9",
"reward": {
"amount": "81528",
"denom": "ukava"
}
},
"reward_indexes": [
{
"collateral_type": "bnb-a",
"reward_factor": "0.000000000000000000"
}
]
},
{
"base_claim": {
"owner": "kava18dde5uvs9h474wj5pe69wg66s2v30whpsqgwee",
"reward": {
"amount": "4825232",
"denom": "ukava"
}
},
"reward_indexes": [
{
"collateral_type": "bnb-a",
"reward_factor": "0.000000000000000000"
},
{
"collateral_type": "btcb-a",
"reward_factor": "0.000000000000000000"
}
]
}
],
"usdx_reward_state": {
"accumulation_times": [
{
"collateral_type": "bnb-a",
"previous_accumulation_time": "2021-04-08T15:00:00Z"
},
{
"collateral_type": "btcb-a",
"previous_accumulation_time": "2021-04-08T15:00:00Z"
}
],
"multi_reward_indexes": [
{
"collateral_type": "bnb-a",
"reward_indexes": [
{
"collateral_type": "ukava",
"reward_factor": "0.000000000000000000"
}
]
},
{
"collateral_type": "btcb-a",
"reward_indexes": [
{
"collateral_type": "ukava",
"reward_factor": "0.000000000000000000"
}
]
}
]
}
}

View File

@ -57,9 +57,10 @@ var (
FilterCoins = types.FilterCoins
GetTotalVestingPeriodLength = types.GetTotalVestingPeriodLength
MultiplyCoins = types.MultiplyCoins
NewAccumulationTime = types.NewAccumulationTime
NewAccumulator = types.NewAccumulator
NewDelegatorClaim = types.NewDelegatorClaim
NewGenesisAccumulationTime = types.NewGenesisAccumulationTime
NewGenesisRewardState = types.NewGenesisRewardState
NewGenesisState = types.NewGenesisState
NewHardLiquidityProviderClaim = types.NewHardLiquidityProviderClaim
NewMsgClaimDelegatorReward = types.NewMsgClaimDelegatorReward
@ -88,7 +89,7 @@ var (
DefaultActive = types.DefaultActive
DefaultClaimEnd = types.DefaultClaimEnd
DefaultDelegatorClaims = types.DefaultDelegatorClaims
DefaultGenesisAccumulationTimes = types.DefaultGenesisAccumulationTimes
DefaultGenesisRewardState = types.DefaultGenesisRewardState
DefaultHardClaims = types.DefaultHardClaims
DefaultMultiRewardPeriods = types.DefaultMultiRewardPeriods
DefaultMultipliers = types.DefaultMultipliers
@ -140,6 +141,8 @@ type (
Hooks = keeper.Hooks
Keeper = keeper.Keeper
AccountKeeper = types.AccountKeeper
AccumulationTime = types.AccumulationTime
AccumulationTimes = types.AccumulationTimes
Accumulator = types.Accumulator
BaseClaim = types.BaseClaim
BaseMultiClaim = types.BaseMultiClaim
@ -149,8 +152,7 @@ type (
Claims = types.Claims
DelegatorClaim = types.DelegatorClaim
DelegatorClaims = types.DelegatorClaims
GenesisAccumulationTime = types.GenesisAccumulationTime
GenesisAccumulationTimes = types.GenesisAccumulationTimes
GenesisRewardState = types.GenesisRewardState
GenesisState = types.GenesisState
HARDHooks = types.HARDHooks
HardKeeper = types.HardKeeper

View File

@ -2,6 +2,7 @@ package incentive
import (
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -23,103 +24,67 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, supplyKeeper types.SupplyKeep
}
for _, rp := range gs.Params.USDXMintingRewardPeriods {
_, found := cdpKeeper.GetCollateral(ctx, rp.CollateralType)
if !found {
panic(fmt.Sprintf("usdx minting collateral type %s not found in cdp collateral types", rp.CollateralType))
if _, found := cdpKeeper.GetCollateral(ctx, rp.CollateralType); !found {
panic(fmt.Sprintf("incentive params contain collateral not found in cdp params: %s", rp.CollateralType))
}
k.SetUSDXMintingRewardFactor(ctx, rp.CollateralType, sdk.ZeroDec())
}
for _, mrp := range gs.Params.HardSupplyRewardPeriods {
newRewardIndexes := types.RewardIndexes{}
for _, rc := range mrp.RewardsPerSecond {
ri := types.NewRewardIndex(rc.Denom, sdk.ZeroDec())
newRewardIndexes = append(newRewardIndexes, ri)
}
k.SetHardSupplyRewardIndexes(ctx, mrp.CollateralType, newRewardIndexes)
}
for _, mrp := range gs.Params.HardBorrowRewardPeriods {
newRewardIndexes := types.RewardIndexes{}
for _, rc := range mrp.RewardsPerSecond {
ri := types.NewRewardIndex(rc.Denom, sdk.ZeroDec())
newRewardIndexes = append(newRewardIndexes, ri)
}
k.SetHardBorrowRewardIndexes(ctx, mrp.CollateralType, newRewardIndexes)
}
for _, drp := range gs.Params.DelegatorRewardPeriods {
newRewardIndexes := types.RewardIndexes{}
for _, rc := range drp.RewardsPerSecond {
ri := types.NewRewardIndex(rc.Denom, sdk.ZeroDec())
newRewardIndexes = append(newRewardIndexes, ri)
}
k.SetDelegatorRewardIndexes(ctx, drp.CollateralType, newRewardIndexes)
}
// TODO more param validation?
k.SetParams(ctx, gs.Params)
for _, gat := range gs.USDXAccumulationTimes {
k.SetPreviousUSDXMintingAccrualTime(ctx, gat.CollateralType, gat.PreviousAccumulationTime)
}
for _, gat := range gs.HardSupplyAccumulationTimes {
k.SetPreviousHardSupplyRewardAccrualTime(ctx, gat.CollateralType, gat.PreviousAccumulationTime)
}
for _, gat := range gs.HardBorrowAccumulationTimes {
k.SetPreviousHardBorrowRewardAccrualTime(ctx, gat.CollateralType, gat.PreviousAccumulationTime)
}
for _, gat := range gs.DelegatorAccumulationTimes {
k.SetPreviousDelegatorRewardAccrualTime(ctx, gat.CollateralType, gat.PreviousAccumulationTime)
}
for _, gat := range gs.SwapAccumulationTimes {
k.SetSwapRewardAccrualTime(ctx, gat.CollateralType, gat.PreviousAccumulationTime)
}
for i, claim := range gs.USDXMintingClaims {
for j, ri := range claim.RewardIndexes {
if ri.RewardFactor != sdk.ZeroDec() {
gs.USDXMintingClaims[i].RewardIndexes[j].RewardFactor = sdk.ZeroDec()
}
}
// USDX Minting
for _, claim := range gs.USDXMintingClaims {
k.SetUSDXMintingClaim(ctx, claim)
}
for _, gat := range gs.USDXRewardState.AccumulationTimes {
k.SetPreviousUSDXMintingAccrualTime(ctx, gat.CollateralType, gat.PreviousAccumulationTime)
}
for _, mri := range gs.USDXRewardState.MultiRewardIndexes {
factor, found := mri.RewardIndexes.Get(types.USDXMintingRewardDenom)
if !found || len(mri.RewardIndexes) != 1 {
panic(fmt.Sprintf("USDX Minting reward factors must only have denom %s", types.USDXMintingRewardDenom))
}
k.SetUSDXMintingRewardFactor(ctx, mri.CollateralType, factor)
}
for i, claim := range gs.HardLiquidityProviderClaims {
for j, mri := range claim.SupplyRewardIndexes {
for k, ri := range mri.RewardIndexes {
if ri.RewardFactor != sdk.ZeroDec() {
gs.HardLiquidityProviderClaims[i].SupplyRewardIndexes[j].RewardIndexes[k].RewardFactor = sdk.ZeroDec()
}
}
}
for j, mri := range claim.BorrowRewardIndexes {
for k, ri := range mri.RewardIndexes {
if ri.RewardFactor != sdk.ZeroDec() {
gs.HardLiquidityProviderClaims[i].BorrowRewardIndexes[j].RewardIndexes[k].RewardFactor = sdk.ZeroDec()
}
}
}
// Hard Supply / Borrow
for _, claim := range gs.HardLiquidityProviderClaims {
k.SetHardLiquidityProviderClaim(ctx, claim)
}
for i, claim := range gs.DelegatorClaims {
for j, mri := range claim.RewardIndexes {
for k, ri := range mri.RewardIndexes {
if ri.RewardFactor != sdk.ZeroDec() {
gs.DelegatorClaims[i].RewardIndexes[j].RewardIndexes[k].RewardFactor = sdk.ZeroDec()
}
}
}
k.SetDelegatorClaim(ctx, claim)
for _, gat := range gs.HardSupplyRewardState.AccumulationTimes {
k.SetPreviousHardSupplyRewardAccrualTime(ctx, gat.CollateralType, gat.PreviousAccumulationTime)
}
for _, mri := range gs.HardSupplyRewardState.MultiRewardIndexes {
k.SetHardSupplyRewardIndexes(ctx, mri.CollateralType, mri.RewardIndexes)
}
for _, gat := range gs.HardBorrowRewardState.AccumulationTimes {
k.SetPreviousHardBorrowRewardAccrualTime(ctx, gat.CollateralType, gat.PreviousAccumulationTime)
}
for _, mri := range gs.HardBorrowRewardState.MultiRewardIndexes {
k.SetHardBorrowRewardIndexes(ctx, mri.CollateralType, mri.RewardIndexes)
}
// TODO no synchronization of swap claims as it is about to be removed in a subsequent PR
// Delegator
for _, claim := range gs.DelegatorClaims {
k.SetDelegatorClaim(ctx, claim)
}
for _, gat := range gs.DelegatorRewardState.AccumulationTimes {
k.SetPreviousDelegatorRewardAccrualTime(ctx, gat.CollateralType, gat.PreviousAccumulationTime)
}
for _, mri := range gs.DelegatorRewardState.MultiRewardIndexes {
k.SetDelegatorRewardIndexes(ctx, mri.CollateralType, mri.RewardIndexes)
}
// Swap
for _, claim := range gs.SwapClaims {
k.SetSwapClaim(ctx, claim)
}
for _, gat := range gs.SwapRewardState.AccumulationTimes {
k.SetSwapRewardAccrualTime(ctx, gat.CollateralType, gat.PreviousAccumulationTime)
}
for _, mri := range gs.SwapRewardState.MultiRewardIndexes {
k.SetSwapRewardIndexes(ctx, mri.CollateralType, mri.RewardIndexes)
}
}
// ExportGenesis export genesis state for incentive module
@ -127,111 +92,112 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
params := k.GetParams(ctx)
usdxClaims := k.GetAllUSDXMintingClaims(ctx)
usdxRewardState := getUSDXMintingGenesisRewardState(ctx, k)
hardClaims := k.GetAllHardLiquidityProviderClaims(ctx)
hardSupplyRewardState := getHardSupplyGenesisRewardState(ctx, k)
hardBorrowRewardState := getHardBorrowGenesisRewardState(ctx, k)
delegatorClaims := k.GetAllDelegatorClaims(ctx)
delegatorRewardState := getDelegatorGenesisRewardState(ctx, k)
swapClaims := k.GetAllSwapClaims(ctx)
synchronizedUsdxClaims := types.USDXMintingClaims{}
synchronizedHardClaims := types.HardLiquidityProviderClaims{}
synchronizedDelegatorClaims := types.DelegatorClaims{}
// TODO no synchronization of swap claims as it is about to be removed in a subsequent PR
for _, usdxClaim := range usdxClaims {
claim, err := k.SynchronizeUSDXMintingClaim(ctx, usdxClaim)
if err != nil {
panic(err)
}
for i := range claim.RewardIndexes {
claim.RewardIndexes[i].RewardFactor = sdk.ZeroDec()
}
synchronizedUsdxClaims = append(synchronizedUsdxClaims, claim)
}
for _, hardClaim := range hardClaims {
k.SynchronizeHardLiquidityProviderClaim(ctx, hardClaim.Owner)
claim, found := k.GetHardLiquidityProviderClaim(ctx, hardClaim.Owner)
if !found {
panic("hard liquidity provider claim should always be found after synchronization")
}
for i, bri := range claim.BorrowRewardIndexes {
for j := range bri.RewardIndexes {
claim.BorrowRewardIndexes[i].RewardIndexes[j].RewardFactor = sdk.ZeroDec()
}
}
for i, sri := range claim.SupplyRewardIndexes {
for j := range sri.RewardIndexes {
claim.SupplyRewardIndexes[i].RewardIndexes[j].RewardFactor = sdk.ZeroDec()
}
}
synchronizedHardClaims = append(synchronizedHardClaims, claim)
}
for _, delegatorClaim := range delegatorClaims {
claim, err := k.SynchronizeDelegatorClaim(ctx, delegatorClaim)
if err != nil {
panic(err)
}
for i, ri := range claim.RewardIndexes {
for j := range ri.RewardIndexes {
claim.RewardIndexes[i].RewardIndexes[j].RewardFactor = sdk.ZeroDec()
}
}
synchronizedDelegatorClaims = append(synchronizedDelegatorClaims, delegatorClaim)
}
var usdxMintingGats GenesisAccumulationTimes
for _, rp := range params.USDXMintingRewardPeriods {
pat, found := k.GetPreviousUSDXMintingAccrualTime(ctx, rp.CollateralType)
if !found {
panic(fmt.Sprintf("expected previous usdx minting reward accrual time to be set in state for %s", rp.CollateralType))
}
gat := types.NewGenesisAccumulationTime(rp.CollateralType, pat)
usdxMintingGats = append(usdxMintingGats, gat)
}
var hardSupplyGats GenesisAccumulationTimes
for _, rp := range params.HardSupplyRewardPeriods {
pat, found := k.GetPreviousHardSupplyRewardAccrualTime(ctx, rp.CollateralType)
if !found {
panic(fmt.Sprintf("expected previous hard supply reward accrual time to be set in state for %s", rp.CollateralType))
}
gat := types.NewGenesisAccumulationTime(rp.CollateralType, pat)
hardSupplyGats = append(hardSupplyGats, gat)
}
var hardBorrowGats GenesisAccumulationTimes
for _, rp := range params.HardBorrowRewardPeriods {
pat, found := k.GetPreviousHardBorrowRewardAccrualTime(ctx, rp.CollateralType)
if !found {
panic(fmt.Sprintf("expected previous hard borrow reward accrual time to be set in state for %s", rp.CollateralType))
}
gat := types.NewGenesisAccumulationTime(rp.CollateralType, pat)
hardBorrowGats = append(hardBorrowGats, gat)
}
var delegatorGats GenesisAccumulationTimes
for _, rp := range params.DelegatorRewardPeriods {
pat, found := k.GetPreviousDelegatorRewardAccrualTime(ctx, rp.CollateralType)
if !found {
panic(fmt.Sprintf("expected previous delegator reward accrual time to be set in state for %s", rp.CollateralType))
}
gat := types.NewGenesisAccumulationTime(rp.CollateralType, pat)
delegatorGats = append(delegatorGats, gat)
}
var swapGats GenesisAccumulationTimes
for _, rp := range params.SwapRewardPeriods {
pat, found := k.GetSwapRewardAccrualTime(ctx, rp.CollateralType)
if !found {
panic(fmt.Sprintf("expected previous swap reward accrual time to be set in state for %s", rp.CollateralType))
}
gat := types.NewGenesisAccumulationTime(rp.CollateralType, pat)
swapGats = append(swapGats, gat)
}
swapRewardState := getSwapGenesisRewardState(ctx, k)
return types.NewGenesisState(
params,
usdxMintingGats, hardSupplyGats, hardBorrowGats, delegatorGats, swapGats,
synchronizedUsdxClaims, synchronizedHardClaims, synchronizedDelegatorClaims, swapClaims,
usdxRewardState, hardSupplyRewardState, hardBorrowRewardState, delegatorRewardState, swapRewardState,
usdxClaims, hardClaims, delegatorClaims, swapClaims,
)
}
func getUSDXMintingGenesisRewardState(ctx sdk.Context, keeper keeper.Keeper) types.GenesisRewardState {
var ats AccumulationTimes
keeper.IterateUSDXMintingAccrualTimes(ctx, func(ctype string, accTime time.Time) bool {
ats = append(ats, types.NewAccumulationTime(ctype, accTime))
return false
})
var mris MultiRewardIndexes
keeper.IterateUSDXMintingRewardFactors(ctx, func(ctype string, factor sdk.Dec) bool {
mris = append(
mris,
types.NewMultiRewardIndex(
ctype,
types.RewardIndexes{types.NewRewardIndex(types.USDXMintingRewardDenom, factor)},
),
)
return false
})
return types.NewGenesisRewardState(ats, mris)
}
func getHardSupplyGenesisRewardState(ctx sdk.Context, keeper keeper.Keeper) types.GenesisRewardState {
var ats AccumulationTimes
keeper.IterateHardSupplyRewardAccrualTimes(ctx, func(ctype string, accTime time.Time) bool {
ats = append(ats, types.NewAccumulationTime(ctype, accTime))
return false
})
var mris MultiRewardIndexes
keeper.IterateHardSupplyRewardIndexes(ctx, func(ctype string, indexes types.RewardIndexes) bool {
mris = append(mris, types.NewMultiRewardIndex(ctype, indexes))
return false
})
return types.NewGenesisRewardState(ats, mris)
}
func getHardBorrowGenesisRewardState(ctx sdk.Context, keeper keeper.Keeper) types.GenesisRewardState {
var ats AccumulationTimes
keeper.IterateHardBorrowRewardAccrualTimes(ctx, func(ctype string, accTime time.Time) bool {
ats = append(ats, types.NewAccumulationTime(ctype, accTime))
return false
})
var mris MultiRewardIndexes
keeper.IterateHardBorrowRewardIndexes(ctx, func(ctype string, indexes types.RewardIndexes) bool {
mris = append(mris, types.NewMultiRewardIndex(ctype, indexes))
return false
})
return types.NewGenesisRewardState(ats, mris)
}
func getDelegatorGenesisRewardState(ctx sdk.Context, keeper keeper.Keeper) types.GenesisRewardState {
var ats AccumulationTimes
keeper.IterateDelegatorRewardAccrualTimes(ctx, func(ctype string, accTime time.Time) bool {
ats = append(ats, types.NewAccumulationTime(ctype, accTime))
return false
})
var mris MultiRewardIndexes
keeper.IterateDelegatorRewardIndexes(ctx, func(ctype string, indexes types.RewardIndexes) bool {
mris = append(mris, types.NewMultiRewardIndex(ctype, indexes))
return false
})
return types.NewGenesisRewardState(ats, mris)
}
func getSwapGenesisRewardState(ctx sdk.Context, keeper keeper.Keeper) types.GenesisRewardState {
var ats AccumulationTimes
keeper.IterateSwapRewardAccrualTimes(ctx, func(ctype string, accTime time.Time) bool {
ats = append(ats, types.NewAccumulationTime(ctype, accTime))
return false
})
var mris MultiRewardIndexes
keeper.IterateSwapRewardIndexes(ctx, func(ctype string, indexes types.RewardIndexes) bool {
mris = append(mris, types.NewMultiRewardIndex(ctype, indexes))
return false
})
return types.NewGenesisRewardState(ats, mris)
}

View File

@ -36,7 +36,7 @@ func (suite *GenesisTestSuite) SetupTest() {
keeper := tApp.GetIncentiveKeeper()
suite.genesisTime = time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)
_, addrs := app.GeneratePrivKeyAddressPairs(3)
_, addrs := app.GeneratePrivKeyAddressPairs(5)
authBuilder := app.NewAuthGenesisBuilder().
WithSimpleAccount(addrs[0], cs(c("bnb", 1e10), c("ukava", 1e10))).
@ -69,11 +69,11 @@ func (suite *GenesisTestSuite) SetupTest() {
incentive.Multipliers{incentive.NewMultiplier(incentive.Small, 1, d("0.25")), incentive.NewMultiplier(incentive.Large, 12, d("1.0"))},
suite.genesisTime.Add(5*oneYear),
),
incentive.DefaultGenesisAccumulationTimes,
incentive.DefaultGenesisAccumulationTimes,
incentive.DefaultGenesisAccumulationTimes,
incentive.DefaultGenesisAccumulationTimes,
incentive.DefaultGenesisAccumulationTimes,
incentive.DefaultGenesisRewardState,
incentive.DefaultGenesisRewardState,
incentive.DefaultGenesisRewardState,
incentive.DefaultGenesisRewardState,
incentive.DefaultGenesisRewardState,
incentive.DefaultUSDXClaims,
incentive.DefaultHardClaims,
incentive.DefaultDelegatorClaims,
@ -124,6 +124,117 @@ func (suite *GenesisTestSuite) TestPaidOutClaimsPassValidateGenesis() {
)
}
func (suite *GenesisTestSuite) TestExportedGenesisMatchesImported() {
genesisTime := time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)
genesisState := incentive.NewGenesisState(
incentive.NewParams(
incentive.RewardPeriods{incentive.NewRewardPeriod(true, "bnb-a", genesisTime.Add(-1*oneYear), genesisTime.Add(oneYear), c("ukava", 122354))},
incentive.MultiRewardPeriods{incentive.NewMultiRewardPeriod(true, "bnb", genesisTime.Add(-1*oneYear), genesisTime.Add(oneYear), cs(c("hard", 122354)))},
incentive.MultiRewardPeriods{incentive.NewMultiRewardPeriod(true, "bnb", genesisTime.Add(-1*oneYear), genesisTime.Add(oneYear), cs(c("hard", 122354)))},
incentive.MultiRewardPeriods{incentive.NewMultiRewardPeriod(true, "ukava", genesisTime.Add(-1*oneYear), genesisTime.Add(oneYear), cs(c("hard", 122354)))},
incentive.MultiRewardPeriods{incentive.NewMultiRewardPeriod(true, "btcb/usdx", genesisTime.Add(-1*oneYear), genesisTime.Add(oneYear), cs(c("swap", 122354)))},
incentive.Multipliers{incentive.NewMultiplier(incentive.Small, 1, d("0.25")), incentive.NewMultiplier(incentive.Large, 12, d("1.0"))},
genesisTime.Add(5*oneYear),
),
incentive.NewGenesisRewardState(
incentive.AccumulationTimes{
incentive.NewAccumulationTime("bnb-a", genesisTime),
},
incentive.MultiRewardIndexes{
incentive.NewMultiRewardIndex("bnb-a", incentive.RewardIndexes{{CollateralType: "ukava", RewardFactor: d("0.3")}}),
},
),
incentive.NewGenesisRewardState(
incentive.AccumulationTimes{
incentive.NewAccumulationTime("bnb", genesisTime.Add(-1*time.Hour)),
},
incentive.MultiRewardIndexes{
incentive.NewMultiRewardIndex("bnb", incentive.RewardIndexes{{CollateralType: "hard", RewardFactor: d("0.1")}}),
},
),
incentive.NewGenesisRewardState(
incentive.AccumulationTimes{
incentive.NewAccumulationTime("bnb", genesisTime.Add(-2*time.Hour)),
},
incentive.MultiRewardIndexes{
incentive.NewMultiRewardIndex("bnb", incentive.RewardIndexes{{CollateralType: "hard", RewardFactor: d("0.05")}}),
},
),
incentive.NewGenesisRewardState(
incentive.AccumulationTimes{
incentive.NewAccumulationTime("ukava", genesisTime.Add(-3*time.Hour)),
},
incentive.MultiRewardIndexes{
incentive.NewMultiRewardIndex("ukava", incentive.RewardIndexes{{CollateralType: "hard", RewardFactor: d("0.2")}}),
},
),
incentive.NewGenesisRewardState(
incentive.AccumulationTimes{
incentive.NewAccumulationTime("bctb/usdx", genesisTime.Add(-4*time.Hour)),
},
incentive.MultiRewardIndexes{
incentive.NewMultiRewardIndex("btcb/usdx", incentive.RewardIndexes{{CollateralType: "swap", RewardFactor: d("0.001")}}),
},
),
incentive.USDXMintingClaims{
incentive.NewUSDXMintingClaim(
suite.addrs[0],
c("ukava", 1e9),
incentive.RewardIndexes{{CollateralType: "bnb-a", RewardFactor: d("0.3")}},
),
incentive.NewUSDXMintingClaim(
suite.addrs[1],
c("ukava", 1),
incentive.RewardIndexes{{CollateralType: "bnb-a", RewardFactor: d("0.001")}},
),
},
incentive.HardLiquidityProviderClaims{
incentive.NewHardLiquidityProviderClaim(
suite.addrs[0],
cs(c("ukava", 1e9), c("hard", 1e9)),
incentive.MultiRewardIndexes{{CollateralType: "bnb", RewardIndexes: incentive.RewardIndexes{{CollateralType: "hard", RewardFactor: d("0.01")}}}},
incentive.MultiRewardIndexes{{CollateralType: "bnb", RewardIndexes: incentive.RewardIndexes{{CollateralType: "hard", RewardFactor: d("0.0")}}}},
),
incentive.NewHardLiquidityProviderClaim(
suite.addrs[1],
cs(c("hard", 1)),
incentive.MultiRewardIndexes{{CollateralType: "bnb", RewardIndexes: incentive.RewardIndexes{{CollateralType: "hard", RewardFactor: d("0.1")}}}},
incentive.MultiRewardIndexes{{CollateralType: "bnb", RewardIndexes: incentive.RewardIndexes{{CollateralType: "hard", RewardFactor: d("0.0")}}}},
),
},
incentive.DelegatorClaims{
incentive.NewDelegatorClaim(
suite.addrs[2],
cs(c("hard", 5)),
incentive.MultiRewardIndexes{{CollateralType: "ukava", RewardIndexes: incentive.RewardIndexes{{CollateralType: "hard", RewardFactor: d("0.2")}}}},
),
},
incentive.SwapClaims{
incentive.NewSwapClaim(
suite.addrs[3],
nil,
incentive.MultiRewardIndexes{{CollateralType: "btcb/usdx", RewardIndexes: incentive.RewardIndexes{{CollateralType: "swap", RewardFactor: d("0.0")}}}},
),
},
)
tApp := app.NewTestApp()
ctx := tApp.NewContext(true, abci.Header{Height: 1})
// Incentive init genesis reads from the cdp keeper to check params are ok. So it needs to be initialized first.
// Then the cdp keeper reads from pricefeed keeper to check its params are ok. So it also need initialization.
tApp.InitializeFromGenesisStates(
NewCDPGenStateMulti(),
NewPricefeedGenStateMultiFromTime(genesisTime),
)
incentive.InitGenesis(ctx, tApp.GetIncentiveKeeper(), tApp.GetSupplyKeeper(), tApp.GetCDPKeeper(), genesisState)
exportedGenesisState := incentive.ExportGenesis(ctx, tApp.GetIncentiveKeeper())
suite.Equal(genesisState, exportedGenesisState)
}
func TestGenesisTestSuite(t *testing.T) {
suite.Run(t, new(GenesisTestSuite))
}

View File

@ -120,11 +120,10 @@ func (k Keeper) IterateUSDXMintingAccrualTimes(ctx sdk.Context, cb func(string,
iterator := sdk.KVStorePrefixIterator(store, []byte{})
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
denom := string(iterator.Key())
var accrualTime time.Time
var collateralType string
k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &collateralType)
k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &accrualTime)
if cb(collateralType, accrualTime) {
if cb(denom, accrualTime) {
break
}
}
@ -341,6 +340,20 @@ func (k Keeper) IterateHardSupplyRewardIndexes(ctx sdk.Context, cb func(denom st
}
}
func (k Keeper) IterateHardSupplyRewardAccrualTimes(ctx sdk.Context, cb func(string, time.Time) (stop bool)) {
store := prefix.NewStore(ctx.KVStore(k.key), types.PreviousHardSupplyRewardAccrualTimeKeyPrefix)
iterator := sdk.KVStorePrefixIterator(store, []byte{})
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
denom := string(iterator.Key())
var accrualTime time.Time
k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &accrualTime)
if cb(denom, accrualTime) {
break
}
}
}
// SetHardBorrowRewardIndexes sets the current reward indexes for an individual denom
func (k Keeper) SetHardBorrowRewardIndexes(ctx sdk.Context, denom string, indexes types.RewardIndexes) {
store := prefix.NewStore(ctx.KVStore(k.key), types.HardBorrowRewardIndexesKeyPrefix)
@ -374,6 +387,20 @@ func (k Keeper) IterateHardBorrowRewardIndexes(ctx sdk.Context, cb func(denom st
}
}
func (k Keeper) IterateHardBorrowRewardAccrualTimes(ctx sdk.Context, cb func(string, time.Time) (stop bool)) {
store := prefix.NewStore(ctx.KVStore(k.key), types.PreviousHardBorrowRewardAccrualTimeKeyPrefix)
iterator := sdk.KVStorePrefixIterator(store, []byte{})
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
denom := string(iterator.Key())
var accrualTime time.Time
k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &accrualTime)
if cb(denom, accrualTime) {
break
}
}
}
// GetDelegatorRewardIndexes gets the current reward indexes for an individual denom
func (k Keeper) GetDelegatorRewardIndexes(ctx sdk.Context, denom string) (types.RewardIndexes, bool) {
store := prefix.NewStore(ctx.KVStore(k.key), types.DelegatorRewardIndexesKeyPrefix)
@ -407,6 +434,20 @@ func (k Keeper) IterateDelegatorRewardIndexes(ctx sdk.Context, cb func(denom str
}
}
func (k Keeper) IterateDelegatorRewardAccrualTimes(ctx sdk.Context, cb func(string, time.Time) (stop bool)) {
store := prefix.NewStore(ctx.KVStore(k.key), types.PreviousDelegatorRewardAccrualTimeKeyPrefix)
iterator := sdk.KVStorePrefixIterator(store, []byte{})
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
denom := string(iterator.Key())
var accrualTime time.Time
k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &accrualTime)
if cb(denom, accrualTime) {
break
}
}
}
// GetPreviousHardSupplyRewardAccrualTime returns the last time a denom accrued Hard protocol supply-side rewards
func (k Keeper) GetPreviousHardSupplyRewardAccrualTime(ctx sdk.Context, denom string) (blockTime time.Time, found bool) {
store := prefix.NewStore(ctx.KVStore(k.key), types.PreviousHardSupplyRewardAccrualTimeKeyPrefix)
@ -507,3 +548,17 @@ func (k Keeper) SetSwapRewardAccrualTime(ctx sdk.Context, poolID string, blockTi
store := prefix.NewStore(ctx.KVStore(k.key), types.PreviousSwapRewardAccrualTimeKeyPrefix)
store.Set([]byte(poolID), k.cdc.MustMarshalBinaryBare(blockTime))
}
func (k Keeper) IterateSwapRewardAccrualTimes(ctx sdk.Context, cb func(string, time.Time) (stop bool)) {
store := prefix.NewStore(ctx.KVStore(k.key), types.PreviousSwapRewardAccrualTimeKeyPrefix)
iterator := sdk.KVStorePrefixIterator(store, []byte{})
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
poolID := string(iterator.Key())
var accrualTime time.Time
k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &accrualTime)
if cb(poolID, accrualTime) {
break
}
}
}

View File

@ -275,6 +275,112 @@ func (suite *KeeperTestSuite) TestGetSetSwapRewardAccrualTimes() {
}
}
type accrualtime struct {
denom string
time time.Time
}
var nonEmptyAccrualTimes = []accrualtime{
{
denom: "",
time: time.Time{},
},
{
denom: "btcb",
time: time.Date(1998, 1, 1, 0, 0, 0, 1, time.UTC),
},
}
func (suite *KeeperTestSuite) TestIterateUSDXMintingAccrualTimes() {
suite.SetupApp()
expectedAccrualTimes := nonEmptyAccrualTimes
for _, at := range expectedAccrualTimes {
suite.keeper.SetPreviousUSDXMintingAccrualTime(suite.ctx, at.denom, at.time)
}
var actualAccrualTimes []accrualtime
suite.keeper.IterateUSDXMintingAccrualTimes(suite.ctx, func(denom string, accrualTime time.Time) bool {
actualAccrualTimes = append(actualAccrualTimes, accrualtime{denom: denom, time: accrualTime})
return false
})
suite.Equal(expectedAccrualTimes, actualAccrualTimes)
}
func (suite *KeeperTestSuite) TestIterateHardSupplyRewardAccrualTimes() {
suite.SetupApp()
expectedAccrualTimes := nonEmptyAccrualTimes
for _, at := range expectedAccrualTimes {
suite.keeper.SetPreviousHardSupplyRewardAccrualTime(suite.ctx, at.denom, at.time)
}
var actualAccrualTimes []accrualtime
suite.keeper.IterateHardSupplyRewardAccrualTimes(suite.ctx, func(denom string, accrualTime time.Time) bool {
actualAccrualTimes = append(actualAccrualTimes, accrualtime{denom: denom, time: accrualTime})
return false
})
suite.Equal(expectedAccrualTimes, actualAccrualTimes)
}
func (suite *KeeperTestSuite) TestIterateHardBorrowrRewardAccrualTimes() {
suite.SetupApp()
expectedAccrualTimes := nonEmptyAccrualTimes
for _, at := range expectedAccrualTimes {
suite.keeper.SetPreviousHardBorrowRewardAccrualTime(suite.ctx, at.denom, at.time)
}
var actualAccrualTimes []accrualtime
suite.keeper.IterateHardBorrowRewardAccrualTimes(suite.ctx, func(denom string, accrualTime time.Time) bool {
actualAccrualTimes = append(actualAccrualTimes, accrualtime{denom: denom, time: accrualTime})
return false
})
suite.Equal(expectedAccrualTimes, actualAccrualTimes)
}
func (suite *KeeperTestSuite) TestIterateDelegatorRewardAccrualTimes() {
suite.SetupApp()
expectedAccrualTimes := nonEmptyAccrualTimes
for _, at := range expectedAccrualTimes {
suite.keeper.SetPreviousDelegatorRewardAccrualTime(suite.ctx, at.denom, at.time)
}
var actualAccrualTimes []accrualtime
suite.keeper.IterateDelegatorRewardAccrualTimes(suite.ctx, func(denom string, accrualTime time.Time) bool {
actualAccrualTimes = append(actualAccrualTimes, accrualtime{denom: denom, time: accrualTime})
return false
})
suite.Equal(expectedAccrualTimes, actualAccrualTimes)
}
func (suite *KeeperTestSuite) TestIterateSwapRewardAccrualTimes() {
suite.SetupApp()
expectedAccrualTimes := nonEmptyAccrualTimes
for _, at := range expectedAccrualTimes {
suite.keeper.SetSwapRewardAccrualTime(suite.ctx, at.denom, at.time)
}
var actualAccrualTimes []accrualtime
suite.keeper.IterateSwapRewardAccrualTimes(suite.ctx, func(denom string, accrualTime time.Time) bool {
actualAccrualTimes = append(actualAccrualTimes, accrualtime{denom: denom, time: accrualTime})
return false
})
suite.Equal(expectedAccrualTimes, actualAccrualTimes)
}
func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

View File

@ -42,10 +42,14 @@ var (
DefaultUSDXClaims = USDXMintingClaims{}
DefaultHardClaims = HardLiquidityProviderClaims{}
DefaultGenesisAccumulationTimes = GenesisAccumulationTimes{}
DefaultGenesisRewardIndexes = GenesisRewardIndexesSlice{}
DefaultClaimEnd = tmtime.Canonical(time.Unix(1, 0))
GovDenom = cdptypes.DefaultGovDenom
PrincipalDenom = "usdx"
IncentiveMacc = kavadistTypes.ModuleName
USDXMintingRewardDenom = "ukava"
HardLiquidityRewardDenom = "hard"
)
// RegisterCodec registers the necessary types for incentive module
@ -59,21 +63,35 @@ func RegisterCodec(cdc *codec.Codec) {
type GenesisState struct {
Params Params `json:"params" yaml:"params"`
USDXAccumulationTimes GenesisAccumulationTimes `json:"usdx_accumulation_times" yaml:"usdx_accumulation_times"`
USDXRewardIndexes GenesisRewardIndexesSlice `json:"usdx_reward_indexes" yaml:"usdx_reward_indexes"`
HardSupplyAccumulationTimes GenesisAccumulationTimes `json:"hard_supply_accumulation_times" yaml:"hard_supply_accumulation_times"`
HardSupplyRewardIndexes GenesisRewardIndexesSlice `json:"hard_supply_reward_indexes" yaml:"hard_supply_reward_indexes"`
HardBorrowAccumulationTimes GenesisAccumulationTimes `json:"hard_borrow_accumulation_times" yaml:"hard_borrow_accumulation_times"`
HardBorrowRewardIndexes GenesisRewardIndexesSlice `json:"hard_borrow_reward_indexes" yaml:"hard_borrow_reward_indexes"`
HardDelegatorAccumulationTimes GenesisAccumulationTimes `json:"hard_delegator_accumulation_times" yaml:"hard_delegator_accumulation_times"`
HardDelegatorRewardIndexes GenesisRewardIndexesSlice `json:"hard_delegator_reward_indexes" yaml:"hard_delegator_reward_indexes"`
USDXMintingClaims USDXMintingClaims `json:"usdx_minting_claims" yaml:"usdx_minting_claims"`
HardLiquidityProviderClaims HardLiquidityProviderClaims `json:"hard_liquidity_provider_claims" yaml:"hard_liquidity_provider_claims"`
}
// NewGenesisState returns a new genesis state
func NewGenesisState(params Params, usdxAccumTimes, hardSupplyAccumTimes, hardBorrowAccumTimes, hardDelegatorAccumTimes GenesisAccumulationTimes, c USDXMintingClaims, hc HardLiquidityProviderClaims) GenesisState {
func NewGenesisState(
params Params,
usdxAccumTimes, hardSupplyAccumTimes, hardBorrowAccumTimes, hardDelegatorAccumTimes GenesisAccumulationTimes,
usdxIndexes, hardSupplyIndexes, hardBorrowIndexes, hardDelegatorIndexes GenesisRewardIndexesSlice,
c USDXMintingClaims,
hc HardLiquidityProviderClaims,
) GenesisState {
return GenesisState{
Params: params,
USDXAccumulationTimes: usdxAccumTimes,
USDXRewardIndexes: usdxIndexes,
HardSupplyAccumulationTimes: hardSupplyAccumTimes,
HardSupplyRewardIndexes: hardSupplyIndexes,
HardBorrowAccumulationTimes: hardBorrowAccumTimes,
HardBorrowRewardIndexes: hardBorrowIndexes,
HardDelegatorAccumulationTimes: hardDelegatorAccumTimes,
HardDelegatorRewardIndexes: hardDelegatorIndexes,
USDXMintingClaims: c,
HardLiquidityProviderClaims: hc,
}
@ -83,10 +101,14 @@ func NewGenesisState(params Params, usdxAccumTimes, hardSupplyAccumTimes, hardBo
func DefaultGenesisState() GenesisState {
return GenesisState{
Params: DefaultParams(),
USDXAccumulationTimes: GenesisAccumulationTimes{},
HardSupplyAccumulationTimes: GenesisAccumulationTimes{},
HardBorrowAccumulationTimes: GenesisAccumulationTimes{},
HardDelegatorAccumulationTimes: GenesisAccumulationTimes{},
USDXAccumulationTimes: DefaultGenesisAccumulationTimes,
USDXRewardIndexes: DefaultGenesisRewardIndexes,
HardSupplyAccumulationTimes: DefaultGenesisAccumulationTimes,
HardSupplyRewardIndexes: DefaultGenesisRewardIndexes,
HardBorrowAccumulationTimes: DefaultGenesisAccumulationTimes,
HardBorrowRewardIndexes: DefaultGenesisRewardIndexes,
HardDelegatorAccumulationTimes: DefaultGenesisAccumulationTimes,
HardDelegatorRewardIndexes: DefaultGenesisRewardIndexes,
USDXMintingClaims: DefaultUSDXClaims,
HardLiquidityProviderClaims: DefaultHardClaims,
}
@ -98,23 +120,52 @@ func (gs GenesisState) Validate() error {
if err := gs.Params.Validate(); err != nil {
return err
}
if err := gs.USDXAccumulationTimes.Validate(); err != nil {
return err
}
if err := gs.USDXRewardIndexes.Validate(); err != nil {
return err
}
for _, ri := range gs.USDXRewardIndexes {
if len(ri.RewardIndexes) > 1 {
return fmt.Errorf("USDX reward indexes cannot have more than one reward denom, found: %s", ri.RewardIndexes)
}
}
if err := gs.HardSupplyAccumulationTimes.Validate(); err != nil {
return err
}
if err := gs.HardSupplyRewardIndexes.Validate(); err != nil {
return err
}
if err := gs.HardBorrowAccumulationTimes.Validate(); err != nil {
return err
}
if err := gs.HardBorrowRewardIndexes.Validate(); err != nil {
return err
}
if err := gs.HardDelegatorAccumulationTimes.Validate(); err != nil {
return err
}
if err := gs.HardDelegatorRewardIndexes.Validate(); err != nil {
return err
}
for _, ri := range gs.HardDelegatorRewardIndexes {
if len(ri.RewardIndexes) > 1 {
return fmt.Errorf("Delegator reward indexes cannot have more than one reward denom, found: %s", ri.RewardIndexes)
}
}
if err := gs.HardLiquidityProviderClaims.Validate(); err != nil {
return err
}
return gs.USDXMintingClaims.Validate()
if err := gs.USDXMintingClaims.Validate(); err != nil {
return err
}
return nil
}
// GenesisAccumulationTime stores the previous reward distribution time and its corresponding collateral type
@ -152,6 +203,41 @@ func (gat GenesisAccumulationTime) Validate() error {
return nil
}
type GenesisRewardIndexes struct {
CollateralType string `json:"collateral_type" yaml:"collateral_type"`
RewardIndexes RewardIndexes `json:"reward_indexes" yaml:"reward_indexes"`
}
// NewGenesisRewardIndexes returns a new GenesisRewardIndexes
func NewGenesisRewardIndexes(ctype string, indexes RewardIndexes) GenesisRewardIndexes {
return GenesisRewardIndexes{
CollateralType: ctype,
RewardIndexes: indexes,
}
}
func (gris GenesisRewardIndexes) Validate() error {
if len(gris.CollateralType) == 0 {
return fmt.Errorf("genesis reward indexes's collateral type must be defined")
}
if err := gris.RewardIndexes.Validate(); err != nil {
return fmt.Errorf("invalid reward indexes: %v", err)
}
return nil
}
type GenesisRewardIndexesSlice []GenesisRewardIndexes
// Validate performs validation of GenesisAccumulationTimes
func (gris GenesisRewardIndexesSlice) Validate() error {
for _, gri := range gris {
if err := gri.Validate(); err != nil {
return err
}
}
return nil
}
// Params governance parameters for the incentive module
type Params struct {
USDXMintingRewardPeriods RewardPeriods `json:"usdx_minting_reward_periods" yaml:"usdx_minting_reward_periods"`

View File

@ -49,80 +49,101 @@ func (builder IncentiveGenesisBuilder) WithGenesisTime(time time.Time) Incentive
func (builder IncentiveGenesisBuilder) WithInitializedBorrowRewardPeriod(period types.MultiRewardPeriod) IncentiveGenesisBuilder {
builder.Params.HardBorrowRewardPeriods = append(builder.Params.HardBorrowRewardPeriods, period)
accumulationTimeForPeriod := types.NewGenesisAccumulationTime(period.CollateralType, builder.genesisTime)
builder.HardBorrowAccumulationTimes = append(builder.HardBorrowAccumulationTimes, accumulationTimeForPeriod)
accumulationTimeForPeriod := types.NewAccumulationTime(period.CollateralType, builder.genesisTime)
builder.HardBorrowRewardState.AccumulationTimes = append(
builder.HardBorrowRewardState.AccumulationTimes,
accumulationTimeForPeriod,
)
builder.HardBorrowRewardState.MultiRewardIndexes = builder.HardBorrowRewardState.MultiRewardIndexes.With(
period.CollateralType,
newZeroRewardIndexesFromCoins(period.RewardsPerSecond...),
)
return builder
}
func (builder IncentiveGenesisBuilder) WithSimpleBorrowRewardPeriod(ctype string, rewardsPerSecond sdk.Coins) IncentiveGenesisBuilder {
return builder.WithInitializedBorrowRewardPeriod(types.NewMultiRewardPeriod(
true,
ctype,
builder.genesisTime,
builder.genesisTime.Add(4*oneYear),
rewardsPerSecond,
))
return builder.WithInitializedBorrowRewardPeriod(builder.simpleRewardPeriod(ctype, rewardsPerSecond))
}
func (builder IncentiveGenesisBuilder) WithInitializedSupplyRewardPeriod(period types.MultiRewardPeriod) IncentiveGenesisBuilder {
builder.Params.HardSupplyRewardPeriods = append(builder.Params.HardSupplyRewardPeriods, period)
accumulationTimeForPeriod := types.NewGenesisAccumulationTime(period.CollateralType, builder.genesisTime)
builder.HardSupplyAccumulationTimes = append(builder.HardSupplyAccumulationTimes, accumulationTimeForPeriod)
accumulationTimeForPeriod := types.NewAccumulationTime(period.CollateralType, builder.genesisTime)
builder.HardSupplyRewardState.AccumulationTimes = append(
builder.HardSupplyRewardState.AccumulationTimes,
accumulationTimeForPeriod,
)
builder.HardSupplyRewardState.MultiRewardIndexes = builder.HardSupplyRewardState.MultiRewardIndexes.With(
period.CollateralType,
newZeroRewardIndexesFromCoins(period.RewardsPerSecond...),
)
return builder
}
func (builder IncentiveGenesisBuilder) WithSimpleSupplyRewardPeriod(ctype string, rewardsPerSecond sdk.Coins) IncentiveGenesisBuilder {
return builder.WithInitializedSupplyRewardPeriod(types.NewMultiRewardPeriod(
true,
ctype,
builder.genesisTime,
builder.genesisTime.Add(4*oneYear),
rewardsPerSecond,
))
return builder.WithInitializedSupplyRewardPeriod(builder.simpleRewardPeriod(ctype, rewardsPerSecond))
}
func (builder IncentiveGenesisBuilder) WithInitializedDelegatorRewardPeriod(period types.MultiRewardPeriod) IncentiveGenesisBuilder {
builder.Params.DelegatorRewardPeriods = append(builder.Params.DelegatorRewardPeriods, period)
accumulationTimeForPeriod := types.NewGenesisAccumulationTime(period.CollateralType, builder.genesisTime)
builder.DelegatorAccumulationTimes = append(builder.DelegatorAccumulationTimes, accumulationTimeForPeriod)
accumulationTimeForPeriod := types.NewAccumulationTime(period.CollateralType, builder.genesisTime)
builder.DelegatorRewardState.AccumulationTimes = append(
builder.DelegatorRewardState.AccumulationTimes,
accumulationTimeForPeriod,
)
builder.DelegatorRewardState.MultiRewardIndexes = builder.DelegatorRewardState.MultiRewardIndexes.With(
period.CollateralType,
newZeroRewardIndexesFromCoins(period.RewardsPerSecond...),
)
return builder
}
func (builder IncentiveGenesisBuilder) WithSimpleDelegatorRewardPeriod(ctype string, rewardsPerSecond sdk.Coins) IncentiveGenesisBuilder {
return builder.WithInitializedDelegatorRewardPeriod(types.NewMultiRewardPeriod(
true,
ctype,
builder.genesisTime,
builder.genesisTime.Add(4*oneYear),
rewardsPerSecond,
))
return builder.WithInitializedDelegatorRewardPeriod(builder.simpleRewardPeriod(ctype, rewardsPerSecond))
}
func (builder IncentiveGenesisBuilder) WithInitializedSwapRewardPeriod(period types.MultiRewardPeriod) IncentiveGenesisBuilder {
builder.Params.SwapRewardPeriods = append(builder.Params.SwapRewardPeriods, period)
accumulationTimeForPeriod := types.NewGenesisAccumulationTime(period.CollateralType, builder.genesisTime)
builder.SwapAccumulationTimes = append(builder.SwapAccumulationTimes, accumulationTimeForPeriod)
accumulationTimeForPeriod := types.NewAccumulationTime(period.CollateralType, builder.genesisTime)
builder.SwapRewardState.AccumulationTimes = append(
builder.SwapRewardState.AccumulationTimes,
accumulationTimeForPeriod,
)
builder.SwapRewardState.MultiRewardIndexes = builder.SwapRewardState.MultiRewardIndexes.With(
period.CollateralType,
newZeroRewardIndexesFromCoins(period.RewardsPerSecond...),
)
return builder
}
func (builder IncentiveGenesisBuilder) WithSimpleSwapRewardPeriod(poolID string, rewardsPerSecond sdk.Coins) IncentiveGenesisBuilder {
return builder.WithInitializedSwapRewardPeriod(types.NewMultiRewardPeriod(
true,
poolID,
builder.genesisTime,
builder.genesisTime.Add(4*oneYear),
rewardsPerSecond,
))
return builder.WithInitializedSwapRewardPeriod(builder.simpleRewardPeriod(poolID, rewardsPerSecond))
}
func (builder IncentiveGenesisBuilder) WithInitializedUSDXRewardPeriod(period types.RewardPeriod) IncentiveGenesisBuilder {
builder.Params.USDXMintingRewardPeriods = append(builder.Params.USDXMintingRewardPeriods, period)
accumulationTimeForPeriod := types.NewGenesisAccumulationTime(period.CollateralType, builder.genesisTime)
builder.USDXAccumulationTimes = append(builder.USDXAccumulationTimes, accumulationTimeForPeriod)
accumulationTimeForPeriod := types.NewAccumulationTime(period.CollateralType, builder.genesisTime)
builder.USDXRewardState.AccumulationTimes = append(
builder.USDXRewardState.AccumulationTimes,
accumulationTimeForPeriod,
)
builder.USDXRewardState.MultiRewardIndexes = builder.USDXRewardState.MultiRewardIndexes.With(
period.CollateralType,
newZeroRewardIndexesFromCoins(period.RewardsPerSecond),
)
return builder
}
@ -141,6 +162,24 @@ func (builder IncentiveGenesisBuilder) WithMultipliers(multipliers types.Multipl
return builder
}
func (builder IncentiveGenesisBuilder) simpleRewardPeriod(ctype string, rewardsPerSecond sdk.Coins) types.MultiRewardPeriod {
return types.NewMultiRewardPeriod(
true,
ctype,
builder.genesisTime,
builder.genesisTime.Add(4*oneYear),
rewardsPerSecond,
)
}
func newZeroRewardIndexesFromCoins(coins ...sdk.Coin) types.RewardIndexes {
var ri types.RewardIndexes
for _, coin := range coins {
ri = ri.With(coin.Denom, sdk.ZeroDec())
}
return ri
}
// HardGenesisBuilder is a tool for creating a hard genesis state.
// Helper methods add values onto a default genesis state.
// All methods are immutable and return updated copies of the builder.

View File

@ -657,6 +657,60 @@ func TestMultiRewardIndexes(t *testing.T) {
})
}
})
t.Run("Validate", func(t *testing.T) {
testcases := []struct {
name string
multiRewardIndexes MultiRewardIndexes
wantErr bool
}{
{
name: "normal case",
multiRewardIndexes: MultiRewardIndexes{
{CollateralType: "btcb", RewardIndexes: normalRewardIndexes},
{CollateralType: "bnb", RewardIndexes: normalRewardIndexes},
},
wantErr: false,
},
{
name: "empty",
multiRewardIndexes: nil,
wantErr: false,
},
{
name: "empty collateral type",
multiRewardIndexes: MultiRewardIndexes{
{RewardIndexes: normalRewardIndexes},
},
wantErr: true,
},
{
name: "invalid reward index",
multiRewardIndexes: MultiRewardIndexes{
{CollateralType: "btcb", RewardIndexes: invalidRewardIndexes},
},
wantErr: true,
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
err := tc.multiRewardIndexes.Validate()
if tc.wantErr {
require.NotNil(t, err)
} else {
require.Nil(t, err)
}
})
}
})
}
var normalRewardIndexes = RewardIndexes{
NewRewardIndex("hard", sdk.MustNewDecFromStr("0.000001")),
NewRewardIndex("ukava", sdk.MustNewDecFromStr("0.1")),
}
var invalidRewardIndexes = RewardIndexes{
RewardIndex{"hard", sdk.MustNewDecFromStr("-0.01")},
}
func appendUniqueRewardIndex(indexes RewardIndexes) RewardIndexes {

View File

@ -6,14 +6,27 @@ import (
"time"
)
var (
DefaultUSDXClaims = USDXMintingClaims{}
DefaultHardClaims = HardLiquidityProviderClaims{}
DefaultDelegatorClaims = DelegatorClaims{}
DefaultSwapClaims = SwapClaims{}
DefaultGenesisRewardState = NewGenesisRewardState(
AccumulationTimes{},
MultiRewardIndexes{},
)
)
// GenesisState is the state that must be provided at genesis.
type GenesisState struct {
Params Params `json:"params" yaml:"params"`
USDXAccumulationTimes GenesisAccumulationTimes `json:"usdx_accumulation_times" yaml:"usdx_accumulation_times"`
HardSupplyAccumulationTimes GenesisAccumulationTimes `json:"hard_supply_accumulation_times" yaml:"hard_supply_accumulation_times"`
HardBorrowAccumulationTimes GenesisAccumulationTimes `json:"hard_borrow_accumulation_times" yaml:"hard_borrow_accumulation_times"`
DelegatorAccumulationTimes GenesisAccumulationTimes `json:"delegator_accumulation_times" yaml:"delegator_accumulation_times"`
SwapAccumulationTimes GenesisAccumulationTimes `json:"swap_accumulation_times" yaml:"swap_accumulation_times"`
Params Params `json:"params" yaml:"params"`
USDXRewardState GenesisRewardState `json:"usdx_reward_state" yaml:"usdx_reward_state"`
HardSupplyRewardState GenesisRewardState `json:"hard_supply_reward_state" yaml:"hard_supply_reward_state"`
HardBorrowRewardState GenesisRewardState `json:"hard_borrow_reward_state" yaml:"hard_borrow_reward_state"`
DelegatorRewardState GenesisRewardState `json:"delegator_reward_state" yaml:"delegator_reward_state"`
SwapRewardState GenesisRewardState `json:"swap_reward_state" yaml:"swap_reward_state"`
USDXMintingClaims USDXMintingClaims `json:"usdx_minting_claims" yaml:"usdx_minting_claims"`
HardLiquidityProviderClaims HardLiquidityProviderClaims `json:"hard_liquidity_provider_claims" yaml:"hard_liquidity_provider_claims"`
DelegatorClaims DelegatorClaims `json:"delegator_claims" yaml:"delegator_claims"`
@ -21,15 +34,20 @@ type GenesisState struct {
}
// NewGenesisState returns a new genesis state
func NewGenesisState(params Params, usdxAccumTimes, hardSupplyAccumTimes, hardBorrowAccumTimes, delegatorAccumTimes,
swapAccumTimes GenesisAccumulationTimes, c USDXMintingClaims, hc HardLiquidityProviderClaims, dc DelegatorClaims, sc SwapClaims) GenesisState {
func NewGenesisState(
params Params,
usdxState, hardSupplyState, hardBorrowState, delegatorState, swapState GenesisRewardState,
c USDXMintingClaims, hc HardLiquidityProviderClaims, dc DelegatorClaims, sc SwapClaims,
) GenesisState {
return GenesisState{
Params: params,
USDXAccumulationTimes: usdxAccumTimes,
HardSupplyAccumulationTimes: hardSupplyAccumTimes,
HardBorrowAccumulationTimes: hardBorrowAccumTimes,
DelegatorAccumulationTimes: delegatorAccumTimes,
SwapAccumulationTimes: swapAccumTimes,
Params: params,
USDXRewardState: usdxState,
HardSupplyRewardState: hardSupplyState,
HardBorrowRewardState: hardBorrowState,
DelegatorRewardState: delegatorState,
SwapRewardState: swapState,
USDXMintingClaims: c,
HardLiquidityProviderClaims: hc,
DelegatorClaims: dc,
@ -41,11 +59,11 @@ func NewGenesisState(params Params, usdxAccumTimes, hardSupplyAccumTimes, hardBo
func DefaultGenesisState() GenesisState {
return GenesisState{
Params: DefaultParams(),
USDXAccumulationTimes: GenesisAccumulationTimes{},
HardSupplyAccumulationTimes: GenesisAccumulationTimes{},
HardBorrowAccumulationTimes: GenesisAccumulationTimes{},
DelegatorAccumulationTimes: GenesisAccumulationTimes{},
SwapAccumulationTimes: GenesisAccumulationTimes{},
USDXRewardState: DefaultGenesisRewardState,
HardSupplyRewardState: DefaultGenesisRewardState,
HardBorrowRewardState: DefaultGenesisRewardState,
DelegatorRewardState: DefaultGenesisRewardState,
SwapRewardState: DefaultGenesisRewardState,
USDXMintingClaims: DefaultUSDXClaims,
HardLiquidityProviderClaims: DefaultHardClaims,
DelegatorClaims: DefaultDelegatorClaims,
@ -59,19 +77,20 @@ func (gs GenesisState) Validate() error {
if err := gs.Params.Validate(); err != nil {
return err
}
if err := gs.USDXAccumulationTimes.Validate(); err != nil {
if err := gs.USDXRewardState.Validate(); err != nil {
return err
}
if err := gs.HardSupplyAccumulationTimes.Validate(); err != nil {
if err := gs.HardSupplyRewardState.Validate(); err != nil {
return err
}
if err := gs.HardBorrowAccumulationTimes.Validate(); err != nil {
if err := gs.HardBorrowRewardState.Validate(); err != nil {
return err
}
if err := gs.DelegatorAccumulationTimes.Validate(); err != nil {
if err := gs.DelegatorRewardState.Validate(); err != nil {
return err
}
if err := gs.SwapAccumulationTimes.Validate(); err != nil {
if err := gs.SwapRewardState.Validate(); err != nil {
return err
}
@ -99,25 +118,55 @@ func (gs GenesisState) IsEmpty() bool {
return gs.Equal(GenesisState{})
}
// GenesisAccumulationTime stores the previous reward distribution time and its corresponding collateral type
type GenesisAccumulationTime struct {
// GenesisRewardState groups together the global state for a particular reward so it can be exported in genesis.
type GenesisRewardState struct {
AccumulationTimes AccumulationTimes `json:"accumulation_times" yaml:"accumulation_times"`
MultiRewardIndexes MultiRewardIndexes `json:"multi_reward_indexes" yaml:"multi_reward_indexes"`
}
// NewGenesisRewardState returns a new GenesisRewardState
func NewGenesisRewardState(accumTimes AccumulationTimes, indexes MultiRewardIndexes) GenesisRewardState {
return GenesisRewardState{
AccumulationTimes: accumTimes,
MultiRewardIndexes: indexes,
}
}
// Validate performs validation of a GenesisRewardState
func (grs GenesisRewardState) Validate() error {
if err := grs.AccumulationTimes.Validate(); err != nil {
return err
}
return grs.MultiRewardIndexes.Validate()
}
// AccumulationTime stores the previous reward distribution time and its corresponding collateral type
type AccumulationTime struct {
CollateralType string `json:"collateral_type" yaml:"collateral_type"`
PreviousAccumulationTime time.Time `json:"previous_accumulation_time" yaml:"previous_accumulation_time"`
}
// NewGenesisAccumulationTime returns a new GenesisAccumulationTime
func NewGenesisAccumulationTime(ctype string, prevTime time.Time) GenesisAccumulationTime {
return GenesisAccumulationTime{
// NewAccumulationTime returns a new GenesisAccumulationTime
func NewAccumulationTime(ctype string, prevTime time.Time) AccumulationTime {
return AccumulationTime{
CollateralType: ctype,
PreviousAccumulationTime: prevTime,
}
}
// GenesisAccumulationTimes slice of GenesisAccumulationTime
type GenesisAccumulationTimes []GenesisAccumulationTime
// Validate performs validation of GenesisAccumulationTime
func (gat AccumulationTime) Validate() error {
if len(gat.CollateralType) == 0 {
return fmt.Errorf("genesis accumulation time's collateral type must be defined")
}
return nil
}
// AccumulationTimes slice of GenesisAccumulationTime
type AccumulationTimes []AccumulationTime
// Validate performs validation of GenesisAccumulationTimes
func (gats GenesisAccumulationTimes) Validate() error {
func (gats AccumulationTimes) Validate() error {
for _, gat := range gats {
if err := gat.Validate(); err != nil {
return err
@ -125,11 +174,3 @@ func (gats GenesisAccumulationTimes) Validate() error {
}
return nil
}
// Validate performs validation of GenesisAccumulationTime
func (gat GenesisAccumulationTime) Validate() error {
if len(gat.CollateralType) == 0 {
return fmt.Errorf("genesis accumulation time's collateral type must be defined")
}
return nil
}

View File

@ -10,13 +10,7 @@ import (
"github.com/tendermint/tendermint/crypto"
)
func TestGenesisStateValidate(t *testing.T) {
type args struct {
params Params
genAccTimes GenesisAccumulationTimes
claims USDXMintingClaims
}
func TestGenesisState_Validate(t *testing.T) {
type errArgs struct {
expectPass bool
contains string
@ -24,25 +18,20 @@ func TestGenesisStateValidate(t *testing.T) {
testCases := []struct {
name string
args args
genesis GenesisState
errArgs errArgs
}{
{
name: "default",
args: args{
params: DefaultParams(),
genAccTimes: DefaultGenesisAccumulationTimes,
claims: DefaultUSDXClaims,
},
name: "default",
genesis: DefaultGenesisState(),
errArgs: errArgs{
expectPass: true,
contains: "",
},
},
{
name: "valid",
args: args{
params: NewParams(
genesis: GenesisState{
Params: NewParams(
RewardPeriods{
NewRewardPeriod(
true,
@ -61,11 +50,17 @@ func TestGenesisStateValidate(t *testing.T) {
},
time.Date(2025, 10, 15, 14, 0, 0, 0, time.UTC),
),
genAccTimes: GenesisAccumulationTimes{GenesisAccumulationTime{
CollateralType: "bnb-a",
PreviousAccumulationTime: time.Date(2020, 10, 15, 14, 0, 0, 0, time.UTC),
}},
claims: USDXMintingClaims{
USDXRewardState: GenesisRewardState{
AccumulationTimes: AccumulationTimes{{
CollateralType: "bnb-a",
PreviousAccumulationTime: time.Date(2020, 10, 15, 14, 0, 0, 0, time.UTC),
}},
MultiRewardIndexes: MultiRewardIndexes{{
CollateralType: "bnb-a",
RewardIndexes: normalRewardIndexes,
}},
},
USDXMintingClaims: USDXMintingClaims{
{
BaseClaim: BaseClaim{
Owner: sdk.AccAddress(crypto.AddressHash([]byte("KavaTestUser1"))),
@ -82,20 +77,23 @@ func TestGenesisStateValidate(t *testing.T) {
},
errArgs: errArgs{
expectPass: true,
contains: "",
},
},
{
name: "invalid genesis accumulation time",
args: args{
params: DefaultParams(),
genAccTimes: GenesisAccumulationTimes{
{
genesis: GenesisState{
Params: DefaultParams(),
USDXRewardState: GenesisRewardState{
AccumulationTimes: AccumulationTimes{{
CollateralType: "",
PreviousAccumulationTime: time.Date(2020, 10, 15, 14, 0, 0, 0, time.UTC),
},
}},
MultiRewardIndexes: MultiRewardIndexes{{
CollateralType: "bnb-a",
RewardIndexes: normalRewardIndexes,
}},
},
claims: DefaultUSDXClaims,
USDXMintingClaims: DefaultUSDXClaims,
},
errArgs: errArgs{
expectPass: false,
@ -104,13 +102,13 @@ func TestGenesisStateValidate(t *testing.T) {
},
{
name: "invalid claim",
args: args{
params: DefaultParams(),
genAccTimes: DefaultGenesisAccumulationTimes,
claims: USDXMintingClaims{
genesis: GenesisState{
Params: DefaultParams(),
USDXRewardState: DefaultGenesisRewardState,
USDXMintingClaims: USDXMintingClaims{
{
BaseClaim: BaseClaim{
Owner: sdk.AccAddress{},
Owner: nil, // invalid address
Reward: sdk.NewCoin("ukava", sdk.NewInt(100000000)),
},
RewardIndexes: []RewardIndex{
@ -131,19 +129,7 @@ func TestGenesisStateValidate(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
gs := NewGenesisState(
tc.args.params,
tc.args.genAccTimes,
tc.args.genAccTimes,
tc.args.genAccTimes,
tc.args.genAccTimes,
tc.args.genAccTimes,
tc.args.claims,
DefaultHardClaims,
DefaultDelegatorClaims,
DefaultSwapClaims,
)
err := gs.Validate()
err := tc.genesis.Validate()
if tc.errArgs.expectPass {
require.NoError(t, err, tc.name)
} else {
@ -153,3 +139,45 @@ func TestGenesisStateValidate(t *testing.T) {
})
}
}
func TestGenesisAccumulationTimes_Validate(t *testing.T) {
testCases := []struct {
name string
gats AccumulationTimes
wantErr bool
}{
{
name: "normal",
gats: AccumulationTimes{
{CollateralType: "btcb", PreviousAccumulationTime: normalAccumulationtime},
{CollateralType: "bnb", PreviousAccumulationTime: normalAccumulationtime},
},
wantErr: false,
},
{
name: "empty",
gats: nil,
wantErr: false,
},
{
name: "empty collateral type",
gats: AccumulationTimes{
{PreviousAccumulationTime: normalAccumulationtime},
},
wantErr: true,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := tc.gats.Validate()
if tc.wantErr {
require.NotNil(t, err)
} else {
require.Nil(t, err)
}
})
}
}
var normalAccumulationtime = time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)

View File

@ -25,26 +25,21 @@ const (
// Parameter keys and default values
var (
KeyUSDXMintingRewardPeriods = []byte("USDXMintingRewardPeriods")
KeyHardSupplyRewardPeriods = []byte("HardSupplyRewardPeriods")
KeyHardBorrowRewardPeriods = []byte("HardBorrowRewardPeriods")
KeyDelegatorRewardPeriods = []byte("DelegatorRewardPeriods")
KeySwapRewardPeriods = []byte("SwapRewardPeriods")
KeyClaimEnd = []byte("ClaimEnd")
KeyMultipliers = []byte("ClaimMultipliers")
DefaultActive = false
DefaultRewardPeriods = RewardPeriods{}
DefaultMultiRewardPeriods = MultiRewardPeriods{}
DefaultMultipliers = Multipliers{}
DefaultUSDXClaims = USDXMintingClaims{}
DefaultHardClaims = HardLiquidityProviderClaims{}
DefaultDelegatorClaims = DelegatorClaims{}
DefaultSwapClaims = SwapClaims{}
DefaultGenesisAccumulationTimes = GenesisAccumulationTimes{}
DefaultClaimEnd = tmtime.Canonical(time.Unix(1, 0))
GovDenom = cdptypes.DefaultGovDenom
PrincipalDenom = "usdx"
IncentiveMacc = kavadistTypes.ModuleName
KeyUSDXMintingRewardPeriods = []byte("USDXMintingRewardPeriods")
KeyHardSupplyRewardPeriods = []byte("HardSupplyRewardPeriods")
KeyHardBorrowRewardPeriods = []byte("HardBorrowRewardPeriods")
KeyDelegatorRewardPeriods = []byte("DelegatorRewardPeriods")
KeySwapRewardPeriods = []byte("SwapRewardPeriods")
KeyClaimEnd = []byte("ClaimEnd")
KeyMultipliers = []byte("ClaimMultipliers")
DefaultActive = false
DefaultRewardPeriods = RewardPeriods{}
DefaultMultiRewardPeriods = MultiRewardPeriods{}
DefaultMultipliers = Multipliers{}
DefaultClaimEnd = tmtime.Canonical(time.Unix(1, 0))
GovDenom = cdptypes.DefaultGovDenom
PrincipalDenom = "usdx"
IncentiveMacc = kavadistTypes.ModuleName
)
// Params governance parameters for the incentive module