mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
Updates dependencies: - github.com/luxfi/vm v1.0.22 → v1.0.23 (adds ZAP transport Serve) - github.com/luxfi/log v1.3.0 → v1.4.1 (fixes module path declaration) - github.com/luxfi/consensus v1.22.53 → v1.22.56 - github.com/luxfi/crypto v1.17.39 → v1.17.40 - github.com/luxfi/database v1.17.38 → v1.17.39 - github.com/luxfi/geth v1.16.69 → v1.16.73 - github.com/luxfi/p2p v1.18.7 → v1.18.8 - github.com/luxfi/warp v1.18.4 → v1.18.5 The vm package now provides a ZAP-based Serve function by default, eliminating the need for the grpc build tag for VM plugins. Also includes various improvements to validators, warp service, and precompile interfaces.
75 lines
2.7 KiB
Go
75 lines
2.7 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package feemanager
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/luxfi/evm/precompile/contract"
|
|
"github.com/luxfi/evm/precompile/modules"
|
|
"github.com/luxfi/evm/precompile/precompileconfig"
|
|
"github.com/luxfi/geth/common"
|
|
)
|
|
|
|
var _ contract.Configurator = (*configurator)(nil)
|
|
|
|
// ConfigKey is the key used in json config files to specify this precompile config.
|
|
// must be unique across all precompiles.
|
|
const ConfigKey = "feeManagerConfig"
|
|
|
|
// LP-aligned address: P=3 (LP-3xxx EVM), C=2 (C-Chain), II=F0 (LP-3511 Fee Manager)
|
|
var ContractAddress = common.HexToAddress("0x13F01")
|
|
|
|
// Module is the precompile module. It is used to register the precompile contract.
|
|
var Module = modules.Module{
|
|
ConfigKey: ConfigKey,
|
|
Address: ContractAddress,
|
|
Contract: FeeManagerPrecompile,
|
|
Configurator: &configurator{},
|
|
}
|
|
|
|
type configurator struct{}
|
|
|
|
func init() {
|
|
// Register the precompile module.
|
|
// Each precompile contract registers itself through [RegisterModule] function.
|
|
if err := modules.RegisterModule(Module); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// MakeConfig returns a new precompile config instance.
|
|
// This is required to Marshal/Unmarshal the precompile config.
|
|
func (*configurator) MakeConfig() precompileconfig.Config {
|
|
return new(Config)
|
|
}
|
|
|
|
// MakeGenesisConfig returns a precompile config for genesis activation (timestamp = 0).
|
|
func (*configurator) MakeGenesisConfig() precompileconfig.Config {
|
|
var zero uint64
|
|
return NewConfig(&zero, nil, nil, nil, nil)
|
|
}
|
|
|
|
// Configure configures [state] with the given [cfg] precompileconfig.
|
|
// This function is called by the EVM once per precompile contract activation.
|
|
func (*configurator) Configure(chainConfig precompileconfig.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, blockContext contract.ConfigurationBlockContext) error {
|
|
config, ok := cfg.(*Config)
|
|
if !ok {
|
|
return fmt.Errorf("expected config type %T, got %T: %v", &Config{}, cfg, cfg)
|
|
}
|
|
// Store the initial fee config into the state when the fee manager activates.
|
|
if config.InitialFeeConfig != nil {
|
|
if err := StoreFeeConfig(state, *config.InitialFeeConfig, blockContext); err != nil {
|
|
// This should not happen since we already checked this config with Verify()
|
|
return fmt.Errorf("cannot configure given initial fee config: %w", err)
|
|
}
|
|
} else {
|
|
if err := StoreFeeConfig(state, chainConfig.GetFeeConfig(), blockContext); err != nil {
|
|
// This should not happen since we already checked the chain config in the genesis creation.
|
|
return fmt.Errorf("cannot configure fee config in chain config: %w", err)
|
|
}
|
|
}
|
|
return config.Configure(chainConfig, ContractAddress, state, blockContext)
|
|
}
|