Skip to content

Commit

Permalink
use chain type instead of modifying chain config
Browse files Browse the repository at this point in the history
  • Loading branch information
matYang committed Sep 13, 2023
1 parent 56efe1d commit 41f5bd4
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 19 deletions.
1 change: 0 additions & 1 deletion core/chains/evm/config/toml/defaults/Base_Goerli.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ NoNewHeadsThreshold = '40s'
MinIncomingConfirmations = 1

[GasEstimator]
Mode = 'OPStack'
EIP1559DynamicFees = true
PriceMin = '1 wei'
BumpMin = '100 wei'
Expand Down
1 change: 0 additions & 1 deletion core/chains/evm/config/toml/defaults/Base_Mainnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ NoNewHeadsThreshold = '40s'
MinIncomingConfirmations = 1

[GasEstimator]
Mode = 'OPStack'
EIP1559DynamicFees = true
PriceMin = '1 wei'
BumpMin = '100 wei'
Expand Down
1 change: 0 additions & 1 deletion core/chains/evm/config/toml/defaults/Optimism_Goerli.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ NoNewHeadsThreshold = '40s'
MinIncomingConfirmations = 1

[GasEstimator]
Mode = 'OPStack'
EIP1559DynamicFees = true
PriceMin = '1 wei'
BumpMin = '100 wei'
Expand Down
1 change: 0 additions & 1 deletion core/chains/evm/config/toml/defaults/Optimism_Mainnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ NoNewHeadsThreshold = '40s'
MinIncomingConfirmations = 1

[GasEstimator]
Mode = 'OPStack'
EIP1559DynamicFees = true
PriceMin = '1 wei'
BumpMin = '100 wei'
Expand Down
18 changes: 7 additions & 11 deletions core/chains/evm/gas/chainoracles/l1_gas_price_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down
6 changes: 2 additions & 4 deletions core/chains/evm/gas/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 41f5bd4

Please sign in to comment.