-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exported genesis validation fix (#934)
* update expected keeper * add methods to expose other keepers from bankKeeper * fix amm module to support exported genesis validation * Add amm module v7 migration * update amm module module.go for v7 migration * update amm migration, return error --------- Co-authored-by: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com>
- Loading branch information
1 parent
0b231d2
commit 07bdc9d
Showing
7 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/elys-network/elys/x/amm/types" | ||
) | ||
|
||
// To be used in migration | ||
|
||
func (k Keeper) GetAccountKeeper() types.AccountKeeper { | ||
return k.accountKeeper | ||
} | ||
|
||
func (k Keeper) GetAssetProfileKeeper() types.AssetProfileKeeper { | ||
return k.assetProfileKeeper | ||
} | ||
|
||
func (k Keeper) GetBankKeeper() types.BankKeeper { | ||
return k.bankKeeper | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package migrations | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/elys-network/elys/x/amm/types" | ||
"github.com/elys-network/elys/x/amm/utils" | ||
) | ||
|
||
func (m Migrator) V7Migration(ctx sdk.Context) error { | ||
pools := m.keeper.GetAllPool(ctx) | ||
for _, pool := range pools { | ||
newPoolAddress := types.NewPoolAddress(pool.PoolId) | ||
poolAccountModuleName := types.GetPoolIdModuleName(pool.PoolId) | ||
if err := utils.CreateModuleAccount(ctx, m.keeper.GetAccountKeeper(), newPoolAddress, poolAccountModuleName); err != nil { | ||
return fmt.Errorf("error creating new pool account for %d: %w", pool.PoolId, err) | ||
} | ||
poolAccAddress := sdk.MustAccAddressFromBech32(pool.Address) | ||
// Bank: Transfer funds from prevPoolAddress to new newPoolAddress | ||
prevPoolAddressBalances := m.keeper.GetBankKeeper().GetAllBalances(ctx, poolAccAddress) | ||
m.keeper.GetBankKeeper().SendCoins(ctx, poolAccAddress, newPoolAddress, prevPoolAddressBalances) | ||
|
||
// AssetProfile: Update authority in assetprofile entry | ||
poolBaseDenom := types.GetPoolShareDenom(pool.PoolId) | ||
|
||
entry, found := m.keeper.GetAssetProfileKeeper().GetEntry(ctx, poolBaseDenom) | ||
// Should not happen | ||
if !found { | ||
return fmt.Errorf("assetprofile not found for basedenom: %s", poolBaseDenom) | ||
} | ||
|
||
entry.Authority = newPoolAddress.String() | ||
m.keeper.GetAssetProfileKeeper().SetEntry(ctx, entry) | ||
|
||
pool.Address = newPoolAddress.String() | ||
|
||
m.keeper.SetPool(ctx, pool) | ||
|
||
// Update the name and Symbol of pool share token metadata | ||
metadata, found := m.keeper.GetBankKeeper().GetDenomMetaData(ctx, poolBaseDenom) | ||
// Should not happen | ||
if !found { | ||
return fmt.Errorf("denom metadata for poolshare denom not found in bank denom metadata: %s", poolBaseDenom) | ||
} | ||
metadata.Name = metadata.Base | ||
metadata.Symbol = metadata.Display | ||
|
||
m.keeper.GetBankKeeper().SetDenomMetaData(ctx, metadata) | ||
} | ||
ctx.Logger().Info("Bank Module Migration Finished") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters