mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-29 09:45:18 +00:00
4a8b5696cb
* initial sketch * add module migrations * add migrations for all accout types * test account migration * add tendermint migration and migrate cmd * remove need for errors pkg dependency * add bech32 decoding fork * add suggested params and cmd to write them * add basic upgrade instructions * fix tests * address some migration todos * tidy contrib folder * finalize params values * align cdp init genesis with other modules * add tendermint and distribution test add custom distribution migration to patch bug * add staking migration test * add slashing, evidence tests, refactor auth tests * add full migration test * remove go-amino dependency from go.mod also tidy up unused indirect dependencies * address remaining TODOs * remove commented out code from legacy types * add spot/liquidation markets ids to kava-3 params * Apply suggestions from code review Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * address code review suggestions * add validate genesis to migrate test * refactor add params func * remove commented out code from old types * fix add params * add deputy address * add tests using exported kava-2 state * incorporate new cdp params from master * update params from review Co-authored-by: Kevin Davis <karzak@users.noreply.github.com> * add deputy account * add committee permissions for new params Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>
99 lines
3.0 KiB
Go
99 lines
3.0 KiB
Go
package v038
|
|
|
|
import (
|
|
v038dist "github.com/cosmos/cosmos-sdk/x/distribution"
|
|
|
|
v18de63dist "github.com/kava-labs/kava/migrate/v0_8/sdk/distribution/v18de63"
|
|
)
|
|
|
|
func Migrate(oldGenState v18de63dist.GenesisState) v038dist.GenesisState {
|
|
|
|
// Changes: some fields moved into a params struct, some changes in json tags
|
|
|
|
params := v038dist.Params{
|
|
CommunityTax: oldGenState.CommunityTax,
|
|
BaseProposerReward: oldGenState.BaseProposerReward,
|
|
BonusProposerReward: oldGenState.BonusProposerReward,
|
|
WithdrawAddrEnabled: oldGenState.WithdrawAddrEnabled,
|
|
}
|
|
|
|
withdrawInfos := []v038dist.DelegatorWithdrawInfo{}
|
|
for _, v := range oldGenState.DelegatorWithdrawInfos {
|
|
withdrawInfos = append(withdrawInfos, v038dist.DelegatorWithdrawInfo(v))
|
|
}
|
|
|
|
outstandingRewards := []v038dist.ValidatorOutstandingRewardsRecord{}
|
|
for _, v := range oldGenState.OutstandingRewards {
|
|
outstandingRewards = append(outstandingRewards, v038dist.ValidatorOutstandingRewardsRecord(v))
|
|
}
|
|
|
|
accumulatedComs := []v038dist.ValidatorAccumulatedCommissionRecord{}
|
|
for _, v := range oldGenState.ValidatorAccumulatedCommissions {
|
|
accumulatedComs = append(accumulatedComs, v038dist.ValidatorAccumulatedCommissionRecord(v))
|
|
}
|
|
|
|
histRewards := []v038dist.ValidatorHistoricalRewardsRecord{}
|
|
for _, v := range oldGenState.ValidatorHistoricalRewards {
|
|
histRewards = append(histRewards, v038dist.ValidatorHistoricalRewardsRecord{
|
|
ValidatorAddress: v.ValidatorAddress,
|
|
Period: v.Period,
|
|
Rewards: v038dist.NewValidatorHistoricalRewards(
|
|
v.Rewards.CumulativeRewardRatio,
|
|
v.Rewards.ReferenceCount,
|
|
),
|
|
})
|
|
}
|
|
|
|
currRewards := []v038dist.ValidatorCurrentRewardsRecord{}
|
|
for _, v := range oldGenState.ValidatorCurrentRewards {
|
|
currRewards = append(currRewards, v038dist.ValidatorCurrentRewardsRecord{
|
|
ValidatorAddress: v.ValidatorAddress,
|
|
Rewards: v038dist.NewValidatorCurrentRewards(
|
|
v.Rewards.Rewards,
|
|
v.Rewards.Period,
|
|
),
|
|
})
|
|
}
|
|
|
|
startInfos := []v038dist.DelegatorStartingInfoRecord{}
|
|
for _, v := range oldGenState.DelegatorStartingInfos {
|
|
startInfos = append(startInfos, v038dist.DelegatorStartingInfoRecord{
|
|
DelegatorAddress: v.DelegatorAddress,
|
|
ValidatorAddress: v.ValidatorAddress,
|
|
StartingInfo: v038dist.NewDelegatorStartingInfo(
|
|
v.StartingInfo.PreviousPeriod,
|
|
v.StartingInfo.Stake,
|
|
v.StartingInfo.Height,
|
|
),
|
|
})
|
|
}
|
|
|
|
slashEvents := []v038dist.ValidatorSlashEventRecord{}
|
|
for _, v := range oldGenState.ValidatorSlashEvents {
|
|
slashEvents = append(slashEvents, v038dist.ValidatorSlashEventRecord{
|
|
ValidatorAddress: v.ValidatorAddress,
|
|
Height: v.Height,
|
|
Period: v.Period,
|
|
Event: v038dist.NewValidatorSlashEvent(
|
|
v.Event.ValidatorPeriod,
|
|
v.Event.Fraction,
|
|
),
|
|
})
|
|
}
|
|
|
|
newGenState := v038dist.NewGenesisState(
|
|
params,
|
|
v038dist.FeePool(oldGenState.FeePool),
|
|
withdrawInfos,
|
|
oldGenState.PreviousProposer,
|
|
outstandingRewards,
|
|
accumulatedComs,
|
|
histRewards,
|
|
currRewards,
|
|
startInfos,
|
|
slashEvents,
|
|
)
|
|
|
|
return newGenState
|
|
}
|