@@ -10,6 +10,8 @@ import (
10
10
11
11
"github.com/cometbft/cometbft/libs/strings"
12
12
13
+ evmtypes "github.com/cosmos/evm/x/vm/types"
14
+
13
15
errorsmod "cosmossdk.io/errors"
14
16
15
17
"github.com/cosmos/cosmos-sdk/server/config"
@@ -130,6 +132,7 @@ type Config struct {
130
132
EVM EVMConfig `mapstructure:"evm"`
131
133
JSONRPC JSONRPCConfig `mapstructure:"json-rpc"`
132
134
TLS TLSConfig `mapstructure:"tls"`
135
+ Chain ChainConfig `mapstructure:"chain"`
133
136
}
134
137
135
138
// EVMConfig defines the application configuration values for the EVM.
@@ -205,6 +208,18 @@ type TLSConfig struct {
205
208
KeyPath string `mapstructure:"key-path"`
206
209
}
207
210
211
+ // ChainConfig defines the chain-specific configuration values.
212
+ type ChainConfig struct {
213
+ // Denom defines the base denomination used in the chain
214
+ Denom string `mapstructure:"denom"`
215
+ // ExtendedDenom defines the extended denomination (typically atto-denom for 18 decimals)
216
+ ExtendedDenom string `mapstructure:"extended-denom"`
217
+ // DisplayDenom defines the display denomination shown to users
218
+ DisplayDenom string `mapstructure:"display-denom"`
219
+ // Decimals defines the precision/decimals for the base denomination (1-18)
220
+ Decimals uint8 `mapstructure:"decimals"`
221
+ }
222
+
208
223
// DefaultEVMConfig returns the default EVM configuration
209
224
func DefaultEVMConfig () * EVMConfig {
210
225
return & EVMConfig {
@@ -335,6 +350,16 @@ func DefaultTLSConfig() *TLSConfig {
335
350
}
336
351
}
337
352
353
+ // DefaultChainConfig returns the default chain configuration
354
+ func DefaultChainConfig () * ChainConfig {
355
+ return & ChainConfig {
356
+ Denom : "aatom" ,
357
+ ExtendedDenom : "aatom" ,
358
+ DisplayDenom : "atom" ,
359
+ Decimals : 18 ,
360
+ }
361
+ }
362
+
338
363
// Validate returns an error if the TLS certificate and key file extensions are invalid.
339
364
func (c TLSConfig ) Validate () error {
340
365
certExt := path .Ext (c .CertificatePath )
@@ -352,6 +377,39 @@ func (c TLSConfig) Validate() error {
352
377
return nil
353
378
}
354
379
380
+ // Validate returns an error if the chain configuration fields are invalid.
381
+ func (c ChainConfig ) Validate () error {
382
+ if c .Denom == "" {
383
+ return errors .New ("chain denom cannot be empty" )
384
+ }
385
+ if c .ExtendedDenom == "" {
386
+ return errors .New ("chain extended-denom cannot be empty" )
387
+ }
388
+ if c .DisplayDenom == "" {
389
+ return errors .New ("chain display-denom cannot be empty" )
390
+ }
391
+ if c .Decimals == 0 || c .Decimals > 18 {
392
+ return errors .New ("chain decimals must be between 1 and 18" )
393
+ }
394
+
395
+ // For 18 decimals, denom and extended denom should be the same
396
+ if c .Decimals == 18 && c .Denom != c .ExtendedDenom {
397
+ return errors .New ("denom and extended-denom must be the same for 18 decimals" )
398
+ }
399
+
400
+ return nil
401
+ }
402
+
403
+ // ToEvmCoinInfo converts ChainConfig to evmtypes.EvmCoinInfo
404
+ func (c ChainConfig ) ToEvmCoinInfo () evmtypes.EvmCoinInfo {
405
+ return evmtypes.EvmCoinInfo {
406
+ Denom : c .Denom ,
407
+ ExtendedDenom : c .ExtendedDenom ,
408
+ DisplayDenom : c .DisplayDenom ,
409
+ Decimals : evmtypes .Decimals (c .Decimals ),
410
+ }
411
+ }
412
+
355
413
// DefaultConfig returns server's default configuration.
356
414
func DefaultConfig () * Config {
357
415
defaultSDKConfig := config .DefaultConfig ()
@@ -365,6 +423,7 @@ func DefaultConfig() *Config {
365
423
EVM : * DefaultEVMConfig (),
366
424
JSONRPC : * DefaultJSONRPCConfig (),
367
425
TLS : * DefaultTLSConfig (),
426
+ Chain : * DefaultChainConfig (),
368
427
}
369
428
}
370
429
@@ -391,5 +450,9 @@ func (c Config) ValidateBasic() error {
391
450
return errorsmod .Wrapf (errortypes .ErrAppConfig , "invalid tls config value: %s" , err .Error ())
392
451
}
393
452
453
+ if err := c .Chain .Validate (); err != nil {
454
+ return errorsmod .Wrapf (errortypes .ErrAppConfig , "invalid chain config value: %s" , err .Error ())
455
+ }
456
+
394
457
return c .Config .ValidateBasic ()
395
458
}
0 commit comments