mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-23 23:05:18 +00:00
Add bep3 migration (#819)
* feat: add bep-3 migration * remove comments * address review comments * update min/max block locks * set open swaps to expired and adjust asset supply * fix: handle open swaps
This commit is contained in:
parent
aa3cf66707
commit
4753504a68
@ -10,6 +10,7 @@ import (
|
||||
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/supply"
|
||||
|
||||
"github.com/kava-labs/kava/x/bep3"
|
||||
v0_13cdp "github.com/kava-labs/kava/x/cdp"
|
||||
v0_11cdp "github.com/kava-labs/kava/x/cdp/legacy/v0_11"
|
||||
v0_13committee "github.com/kava-labs/kava/x/committee"
|
||||
@ -410,6 +411,36 @@ func Auth(genesisState auth.GenesisState) auth.GenesisState {
|
||||
return genesisState
|
||||
}
|
||||
|
||||
// Bep3 migrates a v0.11 bep3 genesis state to a v0.13 genesis state
|
||||
func Bep3(genesisState bep3.GenesisState) bep3.GenesisState {
|
||||
var newSupplies bep3.AssetSupplies
|
||||
for _, supply := range genesisState.Supplies {
|
||||
if supply.GetDenom() == "bnb" {
|
||||
supply.CurrentSupply = supply.CurrentSupply.Sub(sdk.NewCoin("bnb", sdk.NewInt(1000000000000)))
|
||||
}
|
||||
newSupplies = append(newSupplies, supply)
|
||||
}
|
||||
var newSwaps bep3.AtomicSwaps
|
||||
for _, swap := range genesisState.AtomicSwaps {
|
||||
if swap.Status == bep3.Completed {
|
||||
swap.ClosedBlock = 1 // reset closed block to one so completed swaps are removed from long term storage properly
|
||||
}
|
||||
if swap.Status == bep3.Open || swap.Status == bep3.Expired {
|
||||
swap.Status = bep3.Expired // set open swaps to expired so they can be refunded after chain start
|
||||
swap.ExpireHeight = 1 // set expire on first block as well to be safe
|
||||
}
|
||||
newSwaps = append(newSwaps, swap)
|
||||
}
|
||||
var newAssetParams bep3.AssetParams
|
||||
for _, ap := range genesisState.Params.AssetParams {
|
||||
ap.MinBlockLock = uint64(24686)
|
||||
ap.MaxBlockLock = uint64(86400)
|
||||
newAssetParams = append(newAssetParams, ap)
|
||||
}
|
||||
newParams := bep3.NewParams(newAssetParams)
|
||||
return bep3.NewGenesisState(newParams, newSwaps, newSupplies, genesisState.PreviousBlockTime)
|
||||
}
|
||||
|
||||
// Committee migrates from a v0.11 (or v0.12) committee genesis state to a v0.13 committee genesis stat
|
||||
func Committee(genesisState v0_11committee.GenesisState) v0_13committee.GenesisState {
|
||||
committees := []v0_13committee.Committee{}
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/kava-labs/kava/x/bep3"
|
||||
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"
|
||||
@ -176,3 +177,35 @@ func TestCommittee(t *testing.T) {
|
||||
require.Equal(t, len(oldSPCP.AllowedCollateralParams), len(newSPCP.AllowedCollateralParams))
|
||||
require.Equal(t, len(oldSPCP.AllowedMarkets), len(newSPCP.AllowedMarkets))
|
||||
}
|
||||
|
||||
func TestBep3(t *testing.T) {
|
||||
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-4-bep3-state.json"))
|
||||
require.NoError(t, err)
|
||||
var oldGenState bep3.GenesisState
|
||||
cdc := app.MakeCodec()
|
||||
require.NotPanics(t, func() {
|
||||
cdc.MustUnmarshalJSON(bz, &oldGenState)
|
||||
})
|
||||
newGenState := Bep3(oldGenState)
|
||||
err = newGenState.Validate()
|
||||
require.NoError(t, err)
|
||||
|
||||
var oldBNBSupply bep3.AssetSupply
|
||||
var newBNBSupply bep3.AssetSupply
|
||||
|
||||
for _, supply := range oldGenState.Supplies {
|
||||
if supply.GetDenom() == "bnb" {
|
||||
oldBNBSupply = supply
|
||||
}
|
||||
}
|
||||
|
||||
for _, supply := range newGenState.Supplies {
|
||||
if supply.GetDenom() == "bnb" {
|
||||
newBNBSupply = supply
|
||||
}
|
||||
}
|
||||
|
||||
require.Equal(t, oldBNBSupply.CurrentSupply.Sub(sdk.NewCoin("bnb", sdk.NewInt(1000000000000))), newBNBSupply.CurrentSupply)
|
||||
require.Equal(t, uint64(24686), newGenState.Params.AssetParams[0].MinBlockLock)
|
||||
require.Equal(t, uint64(86400), newGenState.Params.AssetParams[0].MaxBlockLock)
|
||||
}
|
||||
|
1
migrate/v0_13/testdata/kava-4-bep3-state.json
vendored
Normal file
1
migrate/v0_13/testdata/kava-4-bep3-state.json
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user