Skip to content

Commit

Permalink
refactor: migrate erc20 module's bridge and ibc token to crosschain m…
Browse files Browse the repository at this point in the history
…odule (#768)

Co-authored-by: nulnut <[email protected]>
  • Loading branch information
zakir-code and nulnut authored Oct 22, 2024
1 parent dffb21a commit 9c6341a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/upgrades/v8/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/functionx/fx-core/v8/app/upgrades/store"
fxtypes "github.com/functionx/fx-core/v8/types"
crosschaintypes "github.com/functionx/fx-core/v8/x/crosschain/types"
erc20keeper "github.com/functionx/fx-core/v8/x/erc20/keeper"
erc20v8 "github.com/functionx/fx-core/v8/x/erc20/migrations/v8"
erc20types "github.com/functionx/fx-core/v8/x/erc20/types"
"github.com/functionx/fx-core/v8/x/gov/keeper"
Expand Down Expand Up @@ -52,6 +53,10 @@ func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator,
return fromVM, err
}

if err = migrateERC20TokenToCrosschain(cacheCtx, app.BankKeeper, app.Erc20Keeper); err != nil {
return fromVM, err
}

updateMetadata(cacheCtx, app.BankKeeper)

store.RemoveStoreKeys(cacheCtx, app.GetKey(erc20types.StoreKey), erc20v8.GetRemovedStoreKeys())
Expand Down Expand Up @@ -152,6 +157,23 @@ func migrateAccountBalance(ctx sdk.Context, bankKeeper bankkeeper.Keeper, accoun
return nil
}

func migrateERC20TokenToCrosschain(ctx sdk.Context, bankKeeper bankkeeper.Keeper, erc20Keeper erc20keeper.Keeper) error {
balances := bankKeeper.GetAllBalances(ctx, types.NewModuleAddress(erc20types.ModuleName))
migrateCoins := sdk.NewCoins()
for _, bal := range balances {
has, err := erc20Keeper.HasToken(ctx, bal.Denom)
if err != nil {
return err
}
if !has {
continue
}
migrateCoins = migrateCoins.Add(bal)
}
ctx.Logger().Info("migrate erc20 bridge/ibc token to crosschain", "coins", migrateCoins.String())
return bankKeeper.SendCoinsFromModuleToModule(ctx, erc20types.ModuleName, crosschaintypes.ModuleName, migrateCoins)
}

func updateMetadata(ctx sdk.Context, bankKeeper bankkeeper.Keeper) {
mds := bankKeeper.GetAllDenomMetaData(ctx)
for _, md := range mds {
Expand Down

0 comments on commit 9c6341a

Please sign in to comment.