diff --git a/evm/CHANGELOG.md b/evm/CHANGELOG.md index 735a3635..21e96dbb 100644 --- a/evm/CHANGELOG.md +++ b/evm/CHANGELOG.md @@ -1,5 +1,10 @@ # EVM App Changelog +## [`v0.1.2`](https://github.com/ignite/apps/releases/tag/evm/v0.1.2) + +- [#239](https://github.com/ignite/apps/pull/239) Set default token decimal to 18 as recommended. +- [#239](https://github.com/ignite/apps/pull/239) Fix export genesis for ibc transfer wrapped module. + ## [`v0.1.1`](https://github.com/ignite/apps/releases/tag/evm/v0.1.1) - [#235](https://github.com/ignite/apps/pull/235) Wire EVM mempool and correct start command. diff --git a/evm/go.mod b/evm/go.mod index 8b2525a3..d7ada838 100644 --- a/evm/go.mod +++ b/evm/go.mod @@ -3,6 +3,8 @@ module github.com/ignite/apps/evm go 1.24.1 require ( + cosmossdk.io/math v1.5.3 + github.com/cosmos/cosmos-sdk v0.53.4 github.com/gobuffalo/genny/v2 v2.1.0 github.com/gobuffalo/plush/v4 v4.1.22 github.com/hashicorp/go-plugin v1.6.3 @@ -17,7 +19,6 @@ require ( cosmossdk.io/depinject v1.2.1 // indirect cosmossdk.io/errors v1.0.2 // indirect cosmossdk.io/log v1.6.1 // indirect - cosmossdk.io/math v1.5.3 // indirect cosmossdk.io/schema v1.1.0 // indirect cosmossdk.io/store v1.1.2 // indirect cosmossdk.io/x/tx v0.14.0 // indirect @@ -61,7 +62,6 @@ require ( github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.1.1 // indirect github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect - github.com/cosmos/cosmos-sdk v0.53.4 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/gogoproto v1.7.0 // indirect diff --git a/evm/template/generator.go b/evm/template/generator.go index af34a27a..8861eeaa 100644 --- a/evm/template/generator.go +++ b/evm/template/generator.go @@ -3,12 +3,17 @@ package template import ( "embed" "io/fs" + "math" "os" "path/filepath" "github.com/gobuffalo/genny/v2" "github.com/gobuffalo/plush/v4" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + configchain "github.com/ignite/cli/v29/ignite/config/chain" "github.com/ignite/cli/v29/ignite/pkg/errors" "github.com/ignite/cli/v29/ignite/pkg/gomodule" "github.com/ignite/cli/v29/ignite/pkg/gomodulepath" @@ -53,6 +58,10 @@ func NewEVMGenerator(chain *chain.Chain) (*genny.Generator, error) { return nil, errors.Errorf("failed to update go.mod: %w", err) } + if err := updateConfigYaml(chain); err != nil { + return nil, errors.Errorf("failed to update config.yaml: %w", err) + } + g.RunFn(commandsModify(appPath, binaryName)) g.RunFn(rootModify(appPath, binaryName)) g.RunFn(appModify(appPath, binaryName)) @@ -82,3 +91,28 @@ func updateDependencies(appPath string) error { return os.WriteFile(filepath.Join(appPath, "go.mod"), data, 0o644) } + +const defaultValPower = 1 + +// updateConfigYaml updates the default bond tokens. +// this is required as the chain uses 18 decimals. +func updateConfigYaml(c *chain.Chain) error { + igniteConfig, err := c.Config() + if err != nil { + return err + } + + coins := sdk.NewCoin(igniteConfig.DefaultDenom, sdkmath.NewInt((defaultValPower * int64(math.Pow10(18))))) + igniteConfig.Validators[0].Bonded = coins.String() + for i, account := range igniteConfig.Accounts { + if account.Name == igniteConfig.Validators[0].Name { + igniteConfig.Accounts[i].Coins = []string{coins.String()} + } + } + + if err := configchain.Save(*igniteConfig, c.ConfigPath()); err != nil { + return err + } + + return nil +} diff --git a/evm/template/generator_app.go b/evm/template/generator_app.go index 3d05b952..6f76b2b7 100644 --- a/evm/template/generator_app.go +++ b/evm/template/generator_app.go @@ -21,6 +21,8 @@ func appModify(appPath, binaryName string) genny.RunFn { // change imports content, err := xast.AppendImports( f.String(), + xast.WithImport("math/big"), + xast.WithImport("cosmossdk.io/math"), xast.WithNamedImport("feegrantkeeper", "cosmossdk.io/x/feegrant/keeper"), xast.WithNamedImport("_", "github.com/ethereum/go-ethereum/eth/tracers/js"), xast.WithNamedImport("_", "github.com/ethereum/go-ethereum/eth/tracers/native"), @@ -53,6 +55,22 @@ func appModify(appPath, binaryName string) genny.RunFn { 1, ) + // change decimal to 18 + content, err = xast.InsertGlobal( + content, + xast.GlobalTypeConst, + xast.WithGlobal("BaseDenomUnit", "int64", "18"), + ) + + content, err = xast.ModifyFunction( + content, + "init", + xast.AppendFuncCode(`// Update power reduction for 18-decimal base unit + sdk.DefaultPowerReduction = math.NewIntFromBigInt( + new(big.Int).Exp(big.NewInt(10), big.NewInt(BaseDenomUnit), nil), + )`), + ) + // append modules content, err = xast.ModifyStruct( content, diff --git a/evm/template/generator_cmd.go b/evm/template/generator_cmd.go index dc5d7823..280805f6 100644 --- a/evm/template/generator_cmd.go +++ b/evm/template/generator_cmd.go @@ -77,6 +77,9 @@ func rootModify(appPath, binaryName string) genny.RunFn { content, err := xast.AppendImports( f.String(), xast.WithNamedImport("cosmosevmkeyring", "github.com/cosmos/evm/crypto/keyring"), + xast.WithNamedImport("ibctransferevm", "github.com/cosmos/evm/x/ibc/transfer"), + xast.WithNamedImport("ibctransfer", "github.com/cosmos/ibc-go/v10/modules/apps/transfer"), + xast.WithNamedImport("ibctransfertypes", "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"), ) if err != nil { return err @@ -97,6 +100,10 @@ func rootModify(appPath, binaryName string) genny.RunFn { for name, mod := range evmModules { moduleBasicManager[name] = module.CoreAppModuleBasicAdaptor(name, mod) autoCliOpts.Modules[name] = mod + } + // Fix basic manager transfer wrapping + moduleBasicManager[ibctransfertypes.ModuleName] = ibctransferevm.AppModuleBasic{ + AppModuleBasic: &ibctransfer.AppModuleBasic{}, }`, 5), ) diff --git a/evolve/cmd/init.go b/evolve/cmd/init.go index b6999a37..bbeb64ff 100644 --- a/evolve/cmd/init.go +++ b/evolve/cmd/init.go @@ -63,7 +63,7 @@ func initEVABCI( return err } - coins := sdk.NewCoin("stake", sdkmath.NewInt((defaultValPower * int64(math.Pow10(6))))) + coins := sdk.NewCoin(igniteConfig.DefaultDenom, sdkmath.NewInt((defaultValPower * int64(math.Pow10(6))))) igniteConfig.Validators[0].Bonded = coins.String() for i, account := range igniteConfig.Accounts { if account.Name == igniteConfig.Validators[0].Name {