From 41f5bd4e306f43ffdf14ef3454e057d874478599 Mon Sep 17 00:00:00 2001 From: Matt Yang Date: Wed, 13 Sep 2023 00:31:52 -0400 Subject: [PATCH] use chain type instead of modifying chain config --- .../evm/config/toml/defaults/Base_Goerli.toml | 1 - .../evm/config/toml/defaults/Base_Mainnet.toml | 1 - .../config/toml/defaults/Optimism_Goerli.toml | 1 - .../config/toml/defaults/Optimism_Mainnet.toml | 1 - .../gas/chainoracles/l1_gas_price_oracle.go | 18 +++++++----------- core/chains/evm/gas/models.go | 6 ++---- 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/core/chains/evm/config/toml/defaults/Base_Goerli.toml b/core/chains/evm/config/toml/defaults/Base_Goerli.toml index 092974b0aee..5ecfd036f46 100644 --- a/core/chains/evm/config/toml/defaults/Base_Goerli.toml +++ b/core/chains/evm/config/toml/defaults/Base_Goerli.toml @@ -6,7 +6,6 @@ NoNewHeadsThreshold = '40s' MinIncomingConfirmations = 1 [GasEstimator] -Mode = 'OPStack' EIP1559DynamicFees = true PriceMin = '1 wei' BumpMin = '100 wei' diff --git a/core/chains/evm/config/toml/defaults/Base_Mainnet.toml b/core/chains/evm/config/toml/defaults/Base_Mainnet.toml index b724b01db30..314c12f8c54 100644 --- a/core/chains/evm/config/toml/defaults/Base_Mainnet.toml +++ b/core/chains/evm/config/toml/defaults/Base_Mainnet.toml @@ -6,7 +6,6 @@ NoNewHeadsThreshold = '40s' MinIncomingConfirmations = 1 [GasEstimator] -Mode = 'OPStack' EIP1559DynamicFees = true PriceMin = '1 wei' BumpMin = '100 wei' diff --git a/core/chains/evm/config/toml/defaults/Optimism_Goerli.toml b/core/chains/evm/config/toml/defaults/Optimism_Goerli.toml index 21e488576fe..458b3b08123 100644 --- a/core/chains/evm/config/toml/defaults/Optimism_Goerli.toml +++ b/core/chains/evm/config/toml/defaults/Optimism_Goerli.toml @@ -7,7 +7,6 @@ NoNewHeadsThreshold = '40s' MinIncomingConfirmations = 1 [GasEstimator] -Mode = 'OPStack' EIP1559DynamicFees = true PriceMin = '1 wei' BumpMin = '100 wei' diff --git a/core/chains/evm/config/toml/defaults/Optimism_Mainnet.toml b/core/chains/evm/config/toml/defaults/Optimism_Mainnet.toml index bff70e35da1..fd4dd9f32f0 100644 --- a/core/chains/evm/config/toml/defaults/Optimism_Mainnet.toml +++ b/core/chains/evm/config/toml/defaults/Optimism_Mainnet.toml @@ -7,7 +7,6 @@ NoNewHeadsThreshold = '40s' MinIncomingConfirmations = 1 [GasEstimator] -Mode = 'OPStack' EIP1559DynamicFees = true PriceMin = '1 wei' BumpMin = '100 wei' diff --git a/core/chains/evm/gas/chainoracles/l1_gas_price_oracle.go b/core/chains/evm/gas/chainoracles/l1_gas_price_oracle.go index 0f924aa3617..b4378d6588e 100644 --- a/core/chains/evm/gas/chainoracles/l1_gas_price_oracle.go +++ b/core/chains/evm/gas/chainoracles/l1_gas_price_oracle.go @@ -12,17 +12,13 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/assets" evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" + "github.com/smartcontractkit/chainlink/v2/core/config" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/utils" ) type OracleType string -const ( - Arbitrum OracleType = "ARBITRUM" - OPStack OracleType = "OP_STACK" -) - // Reads L2-specific precompiles and caches the l1GasPrice set by the L2. type l1GasPriceOracle struct { client evmclient.Client @@ -58,23 +54,23 @@ const ( PollPeriod = 12 * time.Second ) -func NewL1GasPriceOracle(lggr logger.Logger, ethClient evmclient.Client, oracleType OracleType) L1Oracle { +func NewL1GasPriceOracle(lggr logger.Logger, ethClient evmclient.Client, chainType config.ChainType) L1Oracle { var address, selector string - switch oracleType { - case Arbitrum: + switch chainType { + case config.ChainArbitrum: address = ArbGasInfoAddress selector = ArbGasInfo_getL1BaseFeeEstimate - case OPStack: + case config.ChainOptimismBedrock: address = OPGasOracleAddress selector = OPGasOracle_l1BaseFee default: - panic(fmt.Errorf("unsupportd oracle type: %s", oracleType)) + return nil } return &l1GasPriceOracle{ client: ethClient, pollPeriod: PollPeriod, - logger: lggr.Named(fmt.Sprintf("%s L1GasPriceOracle", oracleType)), + logger: lggr.Named(fmt.Sprintf("%d L1GasPriceOracle", chainType)), address: address, selector: selector, } diff --git a/core/chains/evm/gas/models.go b/core/chains/evm/gas/models.go index d8118072e63..cf5e7d34e5a 100644 --- a/core/chains/evm/gas/models.go +++ b/core/chains/evm/gas/models.go @@ -67,12 +67,10 @@ func NewEstimator(lggr logger.Logger, ethClient evmclient.Client, cfg Config, ge df := geCfg.EIP1559DynamicFees() switch s { case "Arbitrum": - l1Oracle := chainoracles.NewL1GasPriceOracle(lggr, ethClient, chainoracles.Arbitrum) + l1Oracle := chainoracles.NewL1GasPriceOracle(lggr, ethClient, cfg.ChainType()) return NewWrappedEvmEstimatorWithL1Oracle(NewArbitrumEstimator(lggr, geCfg, ethClient, ethClient), df, l1Oracle) case "BlockHistory": - return NewWrappedEvmEstimator(NewBlockHistoryEstimator(lggr, ethClient, cfg, geCfg, bh, *ethClient.ConfiguredChainID()), df) - case "OPStack": - l1Oracle := chainoracles.NewL1GasPriceOracle(lggr, ethClient, chainoracles.OPStack) + l1Oracle := chainoracles.NewL1GasPriceOracle(lggr, ethClient, cfg.ChainType()) return NewWrappedEvmEstimatorWithL1Oracle(NewBlockHistoryEstimator(lggr, ethClient, cfg, geCfg, bh, *ethClient.ConfiguredChainID()), df, l1Oracle) case "FixedPrice": return NewWrappedEvmEstimator(NewFixedPriceEstimator(geCfg, bh, lggr), df)