[R4R] incentive, hard migrations (#783)

* update v0_11 harvest genesis state

* wip: hard migration

* wip: incentive migration

* wip: incentive migration

* update incentive migration for multi-rewards

* address review comments

* sort slices for deterministic ordering

* update interest rate model and reserves

* fix: use correct conversion factor

* fix: remove auction size param

* remove ununsed module accounts

* update incentive claim multiplier for one month rewards

* address hard migration review comments

* add hard test

* migrate harvest mod account (#844)

* migrate harvest mod account

* update hard account permissions

* update hard module account permissions

Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com>
This commit is contained in:
Kevin Davis 2021-02-22 14:08:23 -07:00 committed by GitHub
parent 99fb79a1ae
commit 0865e40553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 384 additions and 7 deletions

View File

@ -102,7 +102,7 @@ var (
bep3.ModuleName: {supply.Minter, supply.Burner},
kavadist.ModuleName: {supply.Minter},
issuance.ModuleAccountName: {supply.Minter, supply.Burner},
hard.ModuleAccountName: {supply.Minter, supply.Burner},
hard.ModuleAccountName: {supply.Minter},
}
// module accounts that are allowed to receive tokens

View File

@ -652,7 +652,7 @@ func MigrateHarvest() v0_11harvest.GenesisState {
time.Hour*24,
),
},
), v0_11harvest.DefaultPreviousBlockTime, v0_11harvest.DefaultDistributionTimes)
), v0_11harvest.DefaultPreviousBlockTime, v0_11harvest.DefaultDistributionTimes, v0_11harvest.DefaultDeposits, v0_11harvest.DefaultClaims)
return harvestGS
}

View File

@ -1,6 +1,7 @@
package v0_13
import (
"fmt"
"sort"
"time"
@ -13,6 +14,17 @@ import (
v0_11cdp "github.com/kava-labs/kava/x/cdp/legacy/v0_11"
v0_13committee "github.com/kava-labs/kava/x/committee"
v0_11committee "github.com/kava-labs/kava/x/committee/legacy/v0_11"
v0_13hard "github.com/kava-labs/kava/x/hard"
v0_11hard "github.com/kava-labs/kava/x/hard/legacy/v0_11"
v0_13incentive "github.com/kava-labs/kava/x/incentive"
v0_11incentive "github.com/kava-labs/kava/x/incentive/legacy/v0_11"
"github.com/kava-labs/kava/x/kavadist"
)
var (
GenesisTime = time.Date(2021, 3, 4, 14, 0, 0, 0, time.UTC)
RewardEndTime = time.Date(2022, 2, 25, 14, 0, 0, 0, time.UTC)
ClaimEndTime = time.Date(2026, 2, 25, 14, 0, 0, 0, time.UTC)
)
// CDP migrates from a v0.11 cdp genesis state to a v0.13 cdp genesis state
@ -80,12 +92,242 @@ func CDP(oldGenState v0_11cdp.GenesisState) v0_13cdp.GenesisState {
)
}
// Hard migrates from a v0.11 hard (harvest) genesis state to a v0.13 hard genesis state
func Hard(genesisState v0_11hard.GenesisState) v0_13hard.GenesisState {
v13Deposits := v0_13hard.Deposits{}
v13DepositorMap := make(map[string]v0_13hard.Deposit)
v13GenesisAccumulationTimes := v0_13hard.GenesisAccumulationTimes{}
v13TotalSupplied := sdk.NewCoins()
for _, dep := range genesisState.Deposits {
v13Deposit, ok := v13DepositorMap[dep.Depositor.String()]
if !ok {
v13Deposit := v0_13hard.NewDeposit(dep.Depositor, sdk.NewCoins(dep.Amount), v0_13hard.SupplyInterestFactors{v0_13hard.NewSupplyInterestFactor(dep.Amount.Denom, sdk.OneDec())})
v13DepositorMap[dep.Depositor.String()] = v13Deposit
} else {
v13Deposit.Amount = v13Deposit.Amount.Add(dep.Amount)
v13Deposit.Index = append(v13Deposit.Index, v0_13hard.NewSupplyInterestFactor(dep.Amount.Denom, sdk.OneDec()))
v13DepositorMap[dep.Depositor.String()] = v13Deposit
}
}
defaultInterestModel := v0_13hard.NewInterestRateModel(sdk.ZeroDec(), sdk.MustNewDecFromStr("0.05"), sdk.MustNewDecFromStr("0.8"), sdk.MustNewDecFromStr("1.0"))
newParams := v0_13hard.NewParams(
v0_13hard.MoneyMarkets{
v0_13hard.NewMoneyMarket("btcb", v0_13hard.NewBorrowLimit(true, sdk.ZeroDec(), sdk.MustNewDecFromStr("0.5")), "btc:usd", sdk.NewInt(100000000),
defaultInterestModel,
sdk.MustNewDecFromStr("0.025"), sdk.MustNewDecFromStr("0.02"),
),
// bnb
v0_13hard.NewMoneyMarket("bnb", v0_13hard.NewBorrowLimit(true, sdk.ZeroDec(), sdk.MustNewDecFromStr("0.5")), "bnb:usd", sdk.NewInt(100000000),
defaultInterestModel,
sdk.MustNewDecFromStr("0.025"), sdk.MustNewDecFromStr("0.02"),
),
// xrpb
v0_13hard.NewMoneyMarket("xrpb", v0_13hard.NewBorrowLimit(true, sdk.ZeroDec(), sdk.MustNewDecFromStr("0.5")), "xrp:usd", sdk.NewInt(100000000),
defaultInterestModel,
sdk.MustNewDecFromStr("0.025"), sdk.MustNewDecFromStr("0.02"),
),
// busd
v0_13hard.NewMoneyMarket("busd", v0_13hard.NewBorrowLimit(true, sdk.MustNewDecFromStr("100000000000000"), sdk.MustNewDecFromStr("0.5")), "busd:usd", sdk.NewInt(100000000),
defaultInterestModel,
sdk.MustNewDecFromStr("0.025"), sdk.MustNewDecFromStr("0.02"),
),
// usdx
v0_13hard.NewMoneyMarket("usdx", v0_13hard.NewBorrowLimit(true, sdk.ZeroDec(), sdk.ZeroDec()), "usdx:usd", sdk.NewInt(1000000),
defaultInterestModel,
sdk.MustNewDecFromStr("0.025"), sdk.MustNewDecFromStr("0.02"),
),
// ukava
v0_13hard.NewMoneyMarket("ukava", v0_13hard.NewBorrowLimit(true, sdk.ZeroDec(), sdk.MustNewDecFromStr("0.5")), "kava:usd", sdk.NewInt(1000000),
defaultInterestModel,
sdk.MustNewDecFromStr("0.025"), sdk.MustNewDecFromStr("0.02"),
),
// hard
v0_13hard.NewMoneyMarket("hard", v0_13hard.NewBorrowLimit(true, sdk.ZeroDec(), sdk.MustNewDecFromStr("0.5")), "hard:usd", sdk.NewInt(1000000),
defaultInterestModel,
sdk.MustNewDecFromStr("0.025"), sdk.MustNewDecFromStr("0.02"),
),
},
sdk.MustNewDecFromStr("10.0"),
)
for _, newDep := range v13DepositorMap {
v13Deposits = append(v13Deposits, newDep)
v13TotalSupplied = v13TotalSupplied.Add(newDep.Amount...)
}
sort.Slice(v13Deposits, func(i, j int) bool {
return v13Deposits[i].Depositor.String() > v13Deposits[j].Depositor.String()
})
for _, mm := range newParams.MoneyMarkets {
genAccumulationTime := v0_13hard.NewGenesisAccumulationTime(mm.Denom, GenesisTime, sdk.OneDec(), sdk.OneDec())
v13GenesisAccumulationTimes = append(v13GenesisAccumulationTimes, genAccumulationTime)
}
return v0_13hard.NewGenesisState(newParams, v13GenesisAccumulationTimes, v13Deposits, v0_13hard.DefaultBorrows, v13TotalSupplied, v0_13hard.DefaultTotalBorrowed, v0_13hard.DefaultTotalReserves)
}
// Incentive migrates from a v0.11 incentive genesis state to a v0.13 incentive genesis state
func Incentive(hardGS v0_11hard.GenesisState, incentiveGS v0_11incentive.GenesisState) v0_13incentive.GenesisState {
usdxMintingRewardPeriods := v0_13incentive.RewardPeriods{}
usdxRewardsPerSecondMap := make(map[string]sdk.Coin)
usdxRewardsPerSecondMap["bnb-a"] = sdk.NewCoin("ukava", sdk.NewInt(122354))
usdxRewardsPerSecondMap["btcb-a"] = sdk.NewCoin("ukava", sdk.NewInt(158730))
usdxRewardsPerSecondMap["busd-a"] = sdk.NewCoin("ukava", sdk.NewInt(30588))
usdxRewardsPerSecondMap["hard-a"] = sdk.NewCoin("ukava", sdk.NewInt(23809))
usdxRewardsPerSecondMap["ukava-a"] = sdk.NewCoin("ukava", sdk.NewInt(31746))
usdxRewardsPerSecondMap["xrpb-a"] = sdk.NewCoin("ukava", sdk.NewInt(31746))
for _, rp := range incentiveGS.RewardPeriods {
rewardsPerSecond, ok := usdxRewardsPerSecondMap[rp.CollateralType]
if !ok {
panic(fmt.Sprintf("No rewards per second for collateral type: %s\n", rp.CollateralType))
}
newRP := v0_13incentive.NewRewardPeriod(true, rp.CollateralType, GenesisTime, RewardEndTime, rewardsPerSecond)
usdxMintingRewardPeriods = append(usdxMintingRewardPeriods, newRP)
}
hardSupplyRewardPeriods := v0_13incentive.MultiRewardPeriods{}
for _, rp := range hardGS.Params.LiquidityProviderSchedules {
newRP := v0_13incentive.NewMultiRewardPeriod(true, rp.DepositDenom, rp.Start, rp.End, sdk.NewCoins(rp.RewardsPerSecond))
hardSupplyRewardPeriods = append(hardSupplyRewardPeriods, newRP)
}
hardBorrowRewardPeriods := v0_13incentive.MultiRewardPeriods{}
hardDelegatorRewardPeriods := v0_13incentive.RewardPeriods{}
for _, rp := range hardGS.Params.DelegatorDistributionSchedules {
newRP := v0_13incentive.NewRewardPeriod(rp.DistributionSchedule.Active, rp.DistributionSchedule.DepositDenom, rp.DistributionSchedule.Start, rp.DistributionSchedule.End, rp.DistributionSchedule.RewardsPerSecond)
hardDelegatorRewardPeriods = append(hardDelegatorRewardPeriods, newRP)
}
params := v0_13incentive.NewParams(usdxMintingRewardPeriods, hardSupplyRewardPeriods, hardBorrowRewardPeriods, hardDelegatorRewardPeriods, v0_13incentive.Multipliers{v0_13incentive.NewMultiplier(v0_13incentive.Small, 1, sdk.MustNewDecFromStr("0.2")), v0_13incentive.NewMultiplier(v0_13incentive.Large, 12, sdk.MustNewDecFromStr("1.0"))}, ClaimEndTime)
usdxGenAccumulationTimes := v0_13incentive.GenesisAccumulationTimes{}
for _, rp := range params.USDXMintingRewardPeriods {
gat := v0_13incentive.NewGenesisAccumulationTime(rp.CollateralType, GenesisTime, sdk.ZeroDec())
usdxGenAccumulationTimes = append(usdxGenAccumulationTimes, gat)
}
hardSupplyGenAccumulationTimes := v0_13incentive.GenesisAccumulationTimes{}
for _, rp := range params.HardSupplyRewardPeriods {
gat := v0_13incentive.NewGenesisAccumulationTime(rp.CollateralType, GenesisTime, sdk.ZeroDec())
hardSupplyGenAccumulationTimes = append(hardSupplyGenAccumulationTimes, gat)
}
hardBorrowGenAccumulationTimes := v0_13incentive.GenesisAccumulationTimes{}
for _, rp := range params.HardBorrowRewardPeriods {
gat := v0_13incentive.NewGenesisAccumulationTime(rp.CollateralType, GenesisTime, sdk.ZeroDec())
hardBorrowGenAccumulationTimes = append(hardBorrowGenAccumulationTimes, gat)
}
hardDelegatorGenAccumulationTimes := v0_13incentive.GenesisAccumulationTimes{}
for _, rp := range params.HardDelegatorRewardPeriods {
gat := v0_13incentive.NewGenesisAccumulationTime(rp.CollateralType, GenesisTime, sdk.ZeroDec())
hardDelegatorGenAccumulationTimes = append(hardDelegatorGenAccumulationTimes, gat)
}
usdxClaims := v0_13incentive.USDXMintingClaims{}
usdxClaimMap := make(map[string]v0_13incentive.USDXMintingClaim)
claimEndMap := make(map[uint64]time.Time)
for _, cp := range incentiveGS.ClaimPeriods {
claimEndMap[cp.ID] = cp.End
}
for _, claim := range incentiveGS.Claims {
if claimEndMap[claim.ClaimPeriodID].Before(GenesisTime) {
continue
}
newClaim, ok := usdxClaimMap[claim.Owner.String()]
if !ok {
newClaim = v0_13incentive.NewUSDXMintingClaim(claim.Owner, claim.Reward, v0_13incentive.RewardIndexes{v0_13incentive.NewRewardIndex(claim.CollateralType, sdk.ZeroDec())})
} else {
newClaim.Reward = newClaim.Reward.Add(claim.Reward)
_, found := newClaim.RewardIndexes.GetRewardIndex(claim.CollateralType)
if !found {
newClaim.RewardIndexes = append(newClaim.RewardIndexes, v0_13incentive.NewRewardIndex(claim.CollateralType, sdk.ZeroDec()))
}
}
usdxClaimMap[newClaim.Owner.String()] = newClaim
}
for _, claim := range usdxClaimMap {
usdxClaims = append(usdxClaims, claim)
}
hardClaims := v0_13incentive.HardLiquidityProviderClaims{}
hardClaimMap := make(map[string]v0_13incentive.HardLiquidityProviderClaim)
for _, claim := range hardGS.Claims {
newClaim, ok := hardClaimMap[claim.Owner.String()]
if !ok {
// if claim.Type == "lp" -- hard supply
// if claim.Type == "stake" -- hard delegator
// hard barrow always empty
delegatorIndexes := v0_13incentive.RewardIndexes{}
supplyIndexes := v0_13incentive.MultiRewardIndexes{}
borrowIndexes := v0_13incentive.MultiRewardIndexes{}
if claim.Type == v0_11hard.Stake {
delegatorIndexes = v0_13incentive.RewardIndexes{v0_13incentive.NewRewardIndex(claim.DepositDenom, sdk.ZeroDec())}
}
if claim.Type == v0_11hard.LP {
supplyIndexes = v0_13incentive.MultiRewardIndexes{v0_13incentive.NewMultiRewardIndex(claim.DepositDenom, v0_13incentive.RewardIndexes{v0_13incentive.NewRewardIndex("hard", sdk.ZeroDec())})}
}
newClaim = v0_13incentive.NewHardLiquidityProviderClaim(claim.Owner, sdk.NewCoins(claim.Amount), supplyIndexes, borrowIndexes, delegatorIndexes)
} else {
newClaim.Reward = newClaim.Reward.Add(claim.Amount)
if claim.Type == v0_11hard.Stake {
newClaim.DelegatorRewardIndexes = v0_13incentive.RewardIndexes{v0_13incentive.NewRewardIndex(claim.DepositDenom, sdk.ZeroDec())}
}
if claim.Type == v0_11hard.LP {
_, found := newClaim.SupplyRewardIndexes.GetRewardIndex(claim.DepositDenom)
if !found {
newClaim.SupplyRewardIndexes = append(newClaim.SupplyRewardIndexes, v0_13incentive.NewMultiRewardIndex(claim.DepositDenom, v0_13incentive.RewardIndexes{v0_13incentive.NewRewardIndex("hard", sdk.ZeroDec())}))
}
}
}
hardClaimMap[claim.Owner.String()] = newClaim
}
for _, claim := range hardClaimMap {
hardClaims = append(hardClaims, claim)
}
sort.Slice(hardClaims, func(i, j int) bool { return hardClaims[i].Owner.String() < hardClaims[j].Owner.String() })
sort.Slice(usdxClaims, func(i, j int) bool { return usdxClaims[i].Owner.String() < usdxClaims[j].Owner.String() })
return v0_13incentive.NewGenesisState(
params,
usdxGenAccumulationTimes,
hardSupplyGenAccumulationTimes,
hardBorrowGenAccumulationTimes,
hardDelegatorGenAccumulationTimes,
usdxClaims,
hardClaims,
)
}
// Auth migrates from a v0.11 auth genesis state to a v0.13
func Auth(genesisState auth.GenesisState) auth.GenesisState {
savingsRateMaccCoins := sdk.NewCoins()
savingsMaccAddr := supply.NewModuleAddress(v0_11cdp.SavingsRateMacc)
savingsRateMaccIndex := 0
liquidatorMaccIndex := 0
// moves hard distributions from hard module account to kavadist module account
hardDelegatorAddr := supply.NewModuleAddress(v0_11hard.DelegatorAccount)
hardDelegatorIdx := 0
hardDelegatorCoins := sdk.NewCoins()
hardLPAddr := supply.NewModuleAddress(v0_11hard.LPAccount)
hardLPIdx := 0
hardLPCoins := sdk.NewCoins()
harvestAddr := supply.NewModuleAddress(v0_11hard.ModuleAccountName)
harvestIdx := 0
kavaDistAddr := supply.NewModuleAddress(kavadist.KavaDistMacc)
kavaDistIdx := 0
for idx, acc := range genesisState.Accounts {
if acc.GetAddress().Equals(savingsMaccAddr) {
savingsRateMaccCoins = acc.GetCoins()
@ -98,7 +340,23 @@ func Auth(genesisState auth.GenesisState) auth.GenesisState {
if acc.GetAddress().Equals(supply.NewModuleAddress(v0_13cdp.LiquidatorMacc)) {
liquidatorMaccIndex = idx
}
if acc.GetAddress().Equals(hardDelegatorAddr) {
hardDelegatorIdx = idx
hardDelegatorCoins = acc.GetCoins()
}
if acc.GetAddress().Equals(hardLPAddr) {
hardLPIdx = idx
hardLPCoins = acc.GetCoins()
}
if acc.GetAddress().Equals(kavaDistAddr) {
kavaDistIdx = idx
}
if acc.GetAddress().Equals(harvestAddr) {
harvestIdx = idx
}
}
// move remaining cdp savings to liquidator account
liquidatorAcc := genesisState.Accounts[liquidatorMaccIndex]
err := liquidatorAcc.SetCoins(liquidatorAcc.GetCoins().Add(savingsRateMaccCoins...))
if err != nil {
@ -106,7 +364,30 @@ func Auth(genesisState auth.GenesisState) auth.GenesisState {
}
genesisState.Accounts[liquidatorMaccIndex] = liquidatorAcc
genesisState.Accounts = removeIndex(genesisState.Accounts, savingsRateMaccIndex)
// migrate harvest account to new hard name
harvestAcc := genesisState.Accounts[harvestIdx].(*supply.ModuleAccount)
harvestAcc.Address = supply.NewModuleAddress(v0_13hard.ModuleAccountName)
harvestAcc.Name = v0_13hard.ModuleAccountName
harvestAcc.Permissions = []string{supply.Minter}
genesisState.Accounts[harvestIdx] = harvestAcc
// add hard module accounts to kavadist
kavaDistAcc := genesisState.Accounts[kavaDistIdx]
err = kavaDistAcc.SetCoins(kavaDistAcc.GetCoins().Add(hardDelegatorCoins...).Add(hardLPCoins...))
if err != nil {
panic(err)
}
genesisState.Accounts[kavaDistIdx] = kavaDistAcc
// reverse sort indexes of accounts to remove so that re-numbering is irrelevant
indexesToRemove := []int{savingsRateMaccIndex, hardDelegatorIdx, hardLPIdx}
sort.Slice(indexesToRemove, func(i, j int) bool { return indexesToRemove[i] > indexesToRemove[j] })
// delete hard delegator, hard lp, and savings rate module accounts
for _, idx := range indexesToRemove {
genesisState.Accounts = removeIndex(genesisState.Accounts, idx)
}
return genesisState
}
@ -228,5 +509,6 @@ func Committee(genesisState v0_11committee.GenesisState) v0_13committee.GenesisS
func removeIndex(accs authexported.GenesisAccounts, index int) authexported.GenesisAccounts {
ret := make(authexported.GenesisAccounts, 0)
ret = append(ret, accs[:index]...)
return append(ret, accs[index+1:]...)
newAccounts := append(ret, accs[index+1:]...)
return newAccounts
}

View File

@ -1,6 +1,7 @@
package v0_13
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -9,11 +10,18 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/supply"
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
"github.com/kava-labs/kava/app"
v0_11cdp "github.com/kava-labs/kava/x/cdp/legacy/v0_11"
v0_13committee "github.com/kava-labs/kava/x/committee"
v0_11committee "github.com/kava-labs/kava/x/committee/legacy/v0_11"
v0_13hard "github.com/kava-labs/kava/x/hard"
v0_11hard "github.com/kava-labs/kava/x/hard/legacy/v0_11"
v0_13incentive "github.com/kava-labs/kava/x/incentive"
v0_11incentive "github.com/kava-labs/kava/x/incentive/legacy/v0_11"
"github.com/stretchr/testify/require"
)
@ -54,11 +62,74 @@ func TestAuth(t *testing.T) {
require.NotPanics(t, func() {
cdc.MustUnmarshalJSON(bz, &oldGenState)
})
harvestCoins := getModuleAccount(oldGenState.Accounts, "harvest").GetCoins()
newGenState := Auth(oldGenState)
err = auth.ValidateGenesis(newGenState)
require.NoError(t, err)
require.Equal(t, len(oldGenState.Accounts), len(newGenState.Accounts)+1)
require.Equal(t, len(oldGenState.Accounts), len(newGenState.Accounts)+3)
require.Nil(t, getModuleAccount(newGenState.Accounts, "harvest"))
require.Equal(t, getModuleAccount(newGenState.Accounts, "hard").GetCoins(), harvestCoins)
}
func getModuleAccount(accounts authexported.GenesisAccounts, name string) supplyexported.ModuleAccountI {
modAcc, ok := getAccount(accounts, supply.NewModuleAddress(name)).(supplyexported.ModuleAccountI)
if !ok {
return nil
}
return modAcc
}
func getAccount(accounts authexported.GenesisAccounts, address sdk.AccAddress) authexported.GenesisAccount {
for _, acc := range accounts {
if acc.GetAddress().Equals(address) {
return acc
}
}
return nil
}
func TestIncentive(t *testing.T) {
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-4-incentive-state.json"))
require.NoError(t, err)
var oldIncentiveGenState v0_11incentive.GenesisState
cdc := app.MakeCodec()
require.NotPanics(t, func() {
cdc.MustUnmarshalJSON(bz, &oldIncentiveGenState)
})
bz, err = ioutil.ReadFile(filepath.Join("testdata", "kava-4-harvest-state.json"))
require.NoError(t, err)
var oldHarvestGenState v0_11hard.GenesisState
require.NotPanics(t, func() {
cdc.MustUnmarshalJSON(bz, &oldHarvestGenState)
})
newGenState := v0_13incentive.GenesisState{}
require.NotPanics(t, func() {
newGenState = Incentive(oldHarvestGenState, oldIncentiveGenState)
})
err = newGenState.Validate()
require.NoError(t, err)
fmt.Printf("Number of incentive claims in kava-4: %d\nNumber of incentive Claims in kava-5: %d\n",
len(oldIncentiveGenState.Claims), len(newGenState.USDXMintingClaims),
)
fmt.Printf("Number of harvest claims in kava-4: %d\nNumber of hard claims in kava-5: %d\n", len(oldHarvestGenState.Claims), len(newGenState.HardLiquidityProviderClaims))
}
func TestHard(t *testing.T) {
cdc := app.MakeCodec()
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-4-harvest-state.json"))
require.NoError(t, err)
var oldHarvestGenState v0_11hard.GenesisState
require.NotPanics(t, func() {
cdc.MustUnmarshalJSON(bz, &oldHarvestGenState)
})
newGenState := v0_13hard.GenesisState{}
require.NotPanics(t, func() {
newGenState = Hard(oldHarvestGenState)
})
err = newGenState.Validate()
require.NoError(t, err)
}
func TestCommittee(t *testing.T) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -39,6 +39,8 @@ var (
DefaultDelegatorSchedules = DelegatorDistributionSchedules{}
DefaultPreviousBlockTime = tmtime.Canonical(time.Unix(0, 0))
DefaultDistributionTimes = GenesisDistributionTimes{}
DefaultDeposits = Deposits{}
DefaultClaims = Claims{}
GovDenom = cdptypes.DefaultGovDenom
)
@ -47,14 +49,18 @@ type GenesisState struct {
Params Params `json:"params" yaml:"params"`
PreviousBlockTime time.Time `json:"previous_block_time" yaml:"previous_block_time"`
PreviousDistributionTimes GenesisDistributionTimes `json:"previous_distribution_times" yaml:"previous_distribution_times"`
Deposits Deposits `json:"deposits" yaml:"deposits"`
Claims Claims `json:"claims" yaml:"claims"`
}
// NewGenesisState returns a new genesis state
func NewGenesisState(params Params, previousBlockTime time.Time, previousDistTimes GenesisDistributionTimes) GenesisState {
func NewGenesisState(params Params, previousBlockTime time.Time, previousDistTimes GenesisDistributionTimes, deposits Deposits, claims Claims) GenesisState {
return GenesisState{
Params: params,
PreviousBlockTime: previousBlockTime,
PreviousDistributionTimes: previousDistTimes,
Deposits: deposits,
Claims: claims,
}
}
@ -79,6 +85,17 @@ func (gs GenesisState) Validate() error {
return nil
}
// DefaultGenesisState returns a default genesis state
func DefaultGenesisState() GenesisState {
return GenesisState{
Params: DefaultParams(),
PreviousBlockTime: DefaultPreviousBlockTime,
PreviousDistributionTimes: DefaultDistributionTimes,
Deposits: DefaultDeposits,
Claims: DefaultClaims,
}
}
// GenesisDistributionTime stores the previous distribution time and its corresponding denom
type GenesisDistributionTime struct {
Denom string `json:"denom" yaml:"denom"`
@ -422,6 +439,9 @@ func NewDeposit(depositor sdk.AccAddress, amount sdk.Coin, dtype DepositType) De
}
}
// Deposits slice of Deposit
type Deposits []Deposit
// Claim defines an amount of coins that the owner can claim
type Claim struct {
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
@ -440,6 +460,9 @@ func NewClaim(owner sdk.AccAddress, denom string, amount sdk.Coin, dtype Deposit
}
}
// Claims slice of Claim
type Claims []Claim
// NewPeriod returns a new vesting period
func NewPeriod(amount sdk.Coins, length int64) vesting.Period {
return vesting.Period{Amount: amount, Length: length}

View File

@ -18,7 +18,6 @@ type SupplyKeeper interface {
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error
}
// AccountKeeper defines the expected keeper interface for interacting with account