Skip to content

Commit c173ede

Browse files
authored
refactor(evm): scaffold 18 decimals (#239)
* refactor(evm): scaffold 18 decimal * cl * updates
1 parent 8fc47a1 commit c173ede

File tree

6 files changed

+67
-3
lines changed

6 files changed

+67
-3
lines changed

evm/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# EVM App Changelog
22

3+
## [`v0.1.2`](https://github.com/ignite/apps/releases/tag/evm/v0.1.2)
4+
5+
- [#239](https://github.com/ignite/apps/pull/239) Set default token decimal to 18 as recommended.
6+
- [#239](https://github.com/ignite/apps/pull/239) Fix export genesis for ibc transfer wrapped module.
7+
38
## [`v0.1.1`](https://github.com/ignite/apps/releases/tag/evm/v0.1.1)
49

510
- [#235](https://github.com/ignite/apps/pull/235) Wire EVM mempool and correct start command.

evm/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module github.com/ignite/apps/evm
33
go 1.24.1
44

55
require (
6+
cosmossdk.io/math v1.5.3
7+
github.com/cosmos/cosmos-sdk v0.53.4
68
github.com/gobuffalo/genny/v2 v2.1.0
79
github.com/gobuffalo/plush/v4 v4.1.22
810
github.com/hashicorp/go-plugin v1.6.3
@@ -17,7 +19,6 @@ require (
1719
cosmossdk.io/depinject v1.2.1 // indirect
1820
cosmossdk.io/errors v1.0.2 // indirect
1921
cosmossdk.io/log v1.6.1 // indirect
20-
cosmossdk.io/math v1.5.3 // indirect
2122
cosmossdk.io/schema v1.1.0 // indirect
2223
cosmossdk.io/store v1.1.2 // indirect
2324
cosmossdk.io/x/tx v0.14.0 // indirect
@@ -61,7 +62,6 @@ require (
6162
github.com/cosmos/btcutil v1.0.5 // indirect
6263
github.com/cosmos/cosmos-db v1.1.1 // indirect
6364
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
64-
github.com/cosmos/cosmos-sdk v0.53.4 // indirect
6565
github.com/cosmos/go-bip39 v1.0.0 // indirect
6666
github.com/cosmos/gogogateway v1.2.0 // indirect
6767
github.com/cosmos/gogoproto v1.7.0 // indirect

evm/template/generator.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ package template
33
import (
44
"embed"
55
"io/fs"
6+
"math"
67
"os"
78
"path/filepath"
89

910
"github.com/gobuffalo/genny/v2"
1011
"github.com/gobuffalo/plush/v4"
1112

13+
sdkmath "cosmossdk.io/math"
14+
sdk "github.com/cosmos/cosmos-sdk/types"
15+
16+
configchain "github.com/ignite/cli/v29/ignite/config/chain"
1217
"github.com/ignite/cli/v29/ignite/pkg/errors"
1318
"github.com/ignite/cli/v29/ignite/pkg/gomodule"
1419
"github.com/ignite/cli/v29/ignite/pkg/gomodulepath"
@@ -53,6 +58,10 @@ func NewEVMGenerator(chain *chain.Chain) (*genny.Generator, error) {
5358
return nil, errors.Errorf("failed to update go.mod: %w", err)
5459
}
5560

61+
if err := updateConfigYaml(chain); err != nil {
62+
return nil, errors.Errorf("failed to update config.yaml: %w", err)
63+
}
64+
5665
g.RunFn(commandsModify(appPath, binaryName))
5766
g.RunFn(rootModify(appPath, binaryName))
5867
g.RunFn(appModify(appPath, binaryName))
@@ -82,3 +91,28 @@ func updateDependencies(appPath string) error {
8291

8392
return os.WriteFile(filepath.Join(appPath, "go.mod"), data, 0o644)
8493
}
94+
95+
const defaultValPower = 1
96+
97+
// updateConfigYaml updates the default bond tokens.
98+
// this is required as the chain uses 18 decimals.
99+
func updateConfigYaml(c *chain.Chain) error {
100+
igniteConfig, err := c.Config()
101+
if err != nil {
102+
return err
103+
}
104+
105+
coins := sdk.NewCoin(igniteConfig.DefaultDenom, sdkmath.NewInt((defaultValPower * int64(math.Pow10(18)))))
106+
igniteConfig.Validators[0].Bonded = coins.String()
107+
for i, account := range igniteConfig.Accounts {
108+
if account.Name == igniteConfig.Validators[0].Name {
109+
igniteConfig.Accounts[i].Coins = []string{coins.String()}
110+
}
111+
}
112+
113+
if err := configchain.Save(*igniteConfig, c.ConfigPath()); err != nil {
114+
return err
115+
}
116+
117+
return nil
118+
}

evm/template/generator_app.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ func appModify(appPath, binaryName string) genny.RunFn {
2121
// change imports
2222
content, err := xast.AppendImports(
2323
f.String(),
24+
xast.WithImport("math/big"),
25+
xast.WithImport("cosmossdk.io/math"),
2426
xast.WithNamedImport("feegrantkeeper", "cosmossdk.io/x/feegrant/keeper"),
2527
xast.WithNamedImport("_", "github.com/ethereum/go-ethereum/eth/tracers/js"),
2628
xast.WithNamedImport("_", "github.com/ethereum/go-ethereum/eth/tracers/native"),
@@ -53,6 +55,22 @@ func appModify(appPath, binaryName string) genny.RunFn {
5355
1,
5456
)
5557

58+
// change decimal to 18
59+
content, err = xast.InsertGlobal(
60+
content,
61+
xast.GlobalTypeConst,
62+
xast.WithGlobal("BaseDenomUnit", "int64", "18"),
63+
)
64+
65+
content, err = xast.ModifyFunction(
66+
content,
67+
"init",
68+
xast.AppendFuncCode(`// Update power reduction for 18-decimal base unit
69+
sdk.DefaultPowerReduction = math.NewIntFromBigInt(
70+
new(big.Int).Exp(big.NewInt(10), big.NewInt(BaseDenomUnit), nil),
71+
)`),
72+
)
73+
5674
// append modules
5775
content, err = xast.ModifyStruct(
5876
content,

evm/template/generator_cmd.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ func rootModify(appPath, binaryName string) genny.RunFn {
7777
content, err := xast.AppendImports(
7878
f.String(),
7979
xast.WithNamedImport("cosmosevmkeyring", "github.com/cosmos/evm/crypto/keyring"),
80+
xast.WithNamedImport("ibctransferevm", "github.com/cosmos/evm/x/ibc/transfer"),
81+
xast.WithNamedImport("ibctransfer", "github.com/cosmos/ibc-go/v10/modules/apps/transfer"),
82+
xast.WithNamedImport("ibctransfertypes", "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"),
8083
)
8184
if err != nil {
8285
return err
@@ -97,6 +100,10 @@ func rootModify(appPath, binaryName string) genny.RunFn {
97100
for name, mod := range evmModules {
98101
moduleBasicManager[name] = module.CoreAppModuleBasicAdaptor(name, mod)
99102
autoCliOpts.Modules[name] = mod
103+
}
104+
// Fix basic manager transfer wrapping
105+
moduleBasicManager[ibctransfertypes.ModuleName] = ibctransferevm.AppModuleBasic{
106+
AppModuleBasic: &ibctransfer.AppModuleBasic{},
100107
}`,
101108
5),
102109
)

evolve/cmd/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func initEVABCI(
6363
return err
6464
}
6565

66-
coins := sdk.NewCoin("stake", sdkmath.NewInt((defaultValPower * int64(math.Pow10(6)))))
66+
coins := sdk.NewCoin(igniteConfig.DefaultDenom, sdkmath.NewInt((defaultValPower * int64(math.Pow10(6)))))
6767
igniteConfig.Validators[0].Bonded = coins.String()
6868
for i, account := range igniteConfig.Accounts {
6969
if account.Name == igniteConfig.Validators[0].Name {

0 commit comments

Comments
 (0)