Files
2024-01-03 09:44:09 +01:00

83 lines
2.6 KiB
Go

// (c) 2021-2024, Lux Partners Limited. All rights reserved.
// See the file LICENSE for licensing terms.
package feemanager
import (
"github.com/luxdefi/evm/commontype"
"github.com/luxdefi/evm/precompile/allowlist"
"github.com/luxdefi/evm/precompile/precompileconfig"
"github.com/ethereum/go-ethereum/common"
)
var _ precompileconfig.Config = &Config{}
// Config implements the StatefulPrecompileConfig interface while adding in the
// FeeManager specific precompile config.
type Config struct {
allowlist.AllowListConfig // Config for the fee config manager allow list
precompileconfig.Upgrade
InitialFeeConfig *commontype.FeeConfig `json:"initialFeeConfig,omitempty"` // initial fee config to be immediately activated
}
// NewConfig returns a config for a network upgrade at [blockTimestamp] that enables
// FeeManager with the given [admins], [enableds] and [managers] as members of the
// allowlist with [initialConfig] as initial fee config if specified.
func NewConfig(blockTimestamp *uint64, admins []common.Address, enableds []common.Address, managers []common.Address, initialConfig *commontype.FeeConfig) *Config {
return &Config{
AllowListConfig: allowlist.AllowListConfig{
AdminAddresses: admins,
EnabledAddresses: enableds,
ManagerAddresses: managers,
},
Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp},
InitialFeeConfig: initialConfig,
}
}
// NewDisableConfig returns config for a network upgrade at [blockTimestamp]
// that disables FeeManager.
func NewDisableConfig(blockTimestamp *uint64) *Config {
return &Config{
Upgrade: precompileconfig.Upgrade{
BlockTimestamp: blockTimestamp,
Disable: true,
},
}
}
// Key returns the key for the FeeManager precompileconfig.
// This should be the same key as used in the precompile module.
func (*Config) Key() string { return ConfigKey }
// Equal returns true if [cfg] is a [*FeeManagerConfig] and it has been configured identical to [c].
func (c *Config) Equal(cfg precompileconfig.Config) bool {
// typecast before comparison
other, ok := (cfg).(*Config)
if !ok {
return false
}
eq := c.Upgrade.Equal(&other.Upgrade) && c.AllowListConfig.Equal(&other.AllowListConfig)
if !eq {
return false
}
if c.InitialFeeConfig == nil {
return other.InitialFeeConfig == nil
}
return c.InitialFeeConfig.Equal(other.InitialFeeConfig)
}
// Verify tries to verify Config and returns an error accordingly.
func (c *Config) Verify(chainConfig precompileconfig.ChainConfig) error {
if err := c.AllowListConfig.Verify(chainConfig, c.Upgrade); err != nil {
return err
}
if c.InitialFeeConfig == nil {
return nil
}
return c.InitialFeeConfig.Verify()
}