From ed7ce81e307e7f97218e36623e614470c493bd7b Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Wed, 30 Sep 2020 19:07:30 -0400 Subject: [PATCH] Harvest Migration (#672) * add harvest to kava-4 migration * add mainnet harvest incentive schedules * fix: check for 0 lockup instead of assuming small in always 0 --- migrate/v0_11/migrate.go | 25 +++++++++++++++++++++++++ migrate/v0_11/migrate_test.go | 5 +++++ x/harvest/keeper/claim.go | 7 ++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/migrate/v0_11/migrate.go b/migrate/v0_11/migrate.go index c3050ad1..68f34995 100644 --- a/migrate/v0_11/migrate.go +++ b/migrate/v0_11/migrate.go @@ -9,6 +9,7 @@ import ( v0_9bep3 "github.com/kava-labs/kava/x/bep3/legacy/v0_9" v0_11cdp "github.com/kava-labs/kava/x/cdp" v0_9cdp "github.com/kava-labs/kava/x/cdp/legacy/v0_9" + v0_11harvest "github.com/kava-labs/kava/x/harvest" v0_11incentive "github.com/kava-labs/kava/x/incentive" v0_9incentive "github.com/kava-labs/kava/x/incentive/legacy/v0_9" v0_11pricefeed "github.com/kava-labs/kava/x/pricefeed" @@ -72,6 +73,30 @@ func MigrateBep3(oldGenState v0_9bep3.GenesisState) v0_11bep3.GenesisState { } } +// MigrateHarvest initializes the harvest genesis state for kava-4 +func MigrateHarvest() v0_11harvest.GenesisState { + // total HARD per second for lps (week one): 633761 + // HARD per second for delegators (week one): 1267522 + incentiveGoLiveDate := time.Date(2020, 10, 16, 14, 0, 0, 0, time.UTC) + incentiveEndDate := time.Date(2024, 10, 16, 14, 0, 0, 0, time.UTC) + claimEndDate := time.Date(2025, 10, 16, 14, 0, 0, 0, time.UTC) + harvestGS := v0_11harvest.NewGenesisState(v0_11harvest.NewParams( + true, + v0_11harvest.DistributionSchedules{ + v0_11harvest.NewDistributionSchedule(true, "usdx", incentiveGoLiveDate, incentiveEndDate, sdk.NewCoin("hard", sdk.NewInt(310543)), claimEndDate, v0_11harvest.Multipliers{v0_11harvest.NewMultiplier(v0_11harvest.Small, 1, sdk.MustNewDecFromStr("0.33")), v0_11harvest.NewMultiplier(v0_11harvest.Large, 12, sdk.OneDec())}), + v0_11harvest.NewDistributionSchedule(true, "hard", incentiveGoLiveDate, incentiveEndDate, sdk.NewCoin("hard", sdk.NewInt(285193)), claimEndDate, v0_11harvest.Multipliers{v0_11harvest.NewMultiplier(v0_11harvest.Small, 1, sdk.MustNewDecFromStr("0.33")), v0_11harvest.NewMultiplier(v0_11harvest.Large, 12, sdk.OneDec())}), + v0_11harvest.NewDistributionSchedule(true, "bnb", incentiveGoLiveDate, incentiveEndDate, sdk.NewCoin("hard", sdk.NewInt(12675)), claimEndDate, v0_11harvest.Multipliers{v0_11harvest.NewMultiplier(v0_11harvest.Small, 1, sdk.MustNewDecFromStr("0.33")), v0_11harvest.NewMultiplier(v0_11harvest.Large, 12, sdk.OneDec())}), + v0_11harvest.NewDistributionSchedule(true, "ukava", incentiveGoLiveDate, incentiveEndDate, sdk.NewCoin("hard", sdk.NewInt(25350)), claimEndDate, v0_11harvest.Multipliers{v0_11harvest.NewMultiplier(v0_11harvest.Small, 1, sdk.MustNewDecFromStr("0.33")), v0_11harvest.NewMultiplier(v0_11harvest.Large, 12, sdk.OneDec())}), + }, + v0_11harvest.DelegatorDistributionSchedules{v0_11harvest.NewDelegatorDistributionSchedule( + v0_11harvest.NewDistributionSchedule(true, "ukava", incentiveGoLiveDate, incentiveEndDate, sdk.NewCoin("hard", sdk.NewInt(1267522)), claimEndDate, v0_11harvest.Multipliers{v0_11harvest.NewMultiplier(v0_11harvest.Small, 1, sdk.MustNewDecFromStr("0.33")), v0_11harvest.NewMultiplier(v0_11harvest.Large, 12, sdk.OneDec())}), + time.Hour*24, + ), + }, + ), v0_11harvest.DefaultPreviousBlockTime, v0_11harvest.DefaultDistributionTimes) + return harvestGS +} + // MigrateCDP migrates from a v0.9 (or v0.10) cdp genesis state to a v0.11 cdp genesis state func MigrateCDP(oldGenState v0_9cdp.GenesisState) v0_11cdp.GenesisState { var newCDPs v0_11cdp.CDPs diff --git a/migrate/v0_11/migrate_test.go b/migrate/v0_11/migrate_test.go index 2b451ec8..0c03944f 100644 --- a/migrate/v0_11/migrate_test.go +++ b/migrate/v0_11/migrate_test.go @@ -39,6 +39,11 @@ func TestMigrateBep3(t *testing.T) { require.NoError(t, err) } +func TestMigrateHarvest(t *testing.T) { + newGenState := MigrateHarvest() + err := newGenState.Validate() + require.NoError(t, err) +} func TestMigrateCdp(t *testing.T) { bz, err := ioutil.ReadFile(filepath.Join("testdata", "cdp-v09.json")) require.NoError(t, err) diff --git a/x/harvest/keeper/claim.go b/x/harvest/keeper/claim.go index a85f0fb5..ff947472 100644 --- a/x/harvest/keeper/claim.go +++ b/x/harvest/keeper/claim.go @@ -61,10 +61,11 @@ func (k Keeper) ClaimReward(ctx sdk.Context, claimHolder sdk.AccAddress, receive // note that pay dates are always the 1st or 15th of the month at 14:00UTC. func (k Keeper) GetPeriodLength(ctx sdk.Context, multiplier types.Multiplier) (int64, error) { - switch multiplier.Name { - case types.Small: + if multiplier.MonthsLockup == 0 { return 0, nil - case types.Medium, types.Large: + } + switch multiplier.Name { + case types.Small, types.Medium, types.Large: currentDay := ctx.BlockTime().Day() payDay := BeginningOfMonth monthOffset := int64(1)