Skip to content

Commit

Permalink
CCIP-3552 refactor OP oracle to accept generic DA oracle config (#14599)
Browse files Browse the repository at this point in the history
* Add DA oracle interface

* run mockery

* changeset

* Comment out DA oracle validations for now

* adding tag to changeset

* fix tests

* fix tests and some more refactoring

* add tests for custom gas API

* Rebase

* feedback

* Fall back to check chainType when creating the L1 oracle

* update default tomls with DA config

* renamings

* remove custom calldata option from op oracle

* update namings again

* change OP oracle type to opstack

* feedback

* use random address for tests
  • Loading branch information
ogtownsend authored Oct 11, 2024
1 parent a330bf9 commit 4ac405a
Show file tree
Hide file tree
Showing 31 changed files with 456 additions and 101 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-pillows-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Refactor OP oracle to accept generic DA oracle config #wip
20 changes: 20 additions & 0 deletions core/capabilities/ccip/ocrimpls/contract_transmitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ocrimpls"
cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
Expand Down Expand Up @@ -588,6 +590,24 @@ type TestGasEstimatorConfig struct {
bumpThreshold uint64
}

func (g *TestGasEstimatorConfig) DAOracle() evmconfig.DAOracle {
return &TestDAOracleConfig{}
}

type TestDAOracleConfig struct {
evmconfig.DAOracle
}

func (d *TestDAOracleConfig) OracleType() toml.OracleType { return toml.OPStack }
func (d *TestDAOracleConfig) OracleAddress() *types.EIP55Address {
a, err := types.NewEIP55Address("0x420000000000000000000000000000000000000F")
if err != nil {
panic(err)
}
return &a
}
func (d *TestDAOracleConfig) CustomGasPriceCalldata() string { return "" }

func (g *TestGasEstimatorConfig) BlockHistory() evmconfig.BlockHistory {
return &TestBlockHistoryConfig{}
}
Expand Down
24 changes: 24 additions & 0 deletions core/chains/evm/config/chain_scoped_gas_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
)

type gasEstimatorConfig struct {
Expand Down Expand Up @@ -42,6 +43,10 @@ func (g *gasEstimatorConfig) FeeHistory() FeeHistory {
return &feeHistoryConfig{c: g.c.FeeHistory}
}

func (g *gasEstimatorConfig) DAOracle() DAOracle {
return &daOracleConfig{c: g.c.DAOracle}
}

func (g *gasEstimatorConfig) EIP1559DynamicFees() bool {
return *g.c.EIP1559DynamicFees
}
Expand Down Expand Up @@ -118,6 +123,25 @@ func (g *gasEstimatorConfig) EstimateLimit() bool {
return *g.c.EstimateLimit
}

type daOracleConfig struct {
c toml.DAOracle
}

func (d *daOracleConfig) OracleType() toml.OracleType {
return d.c.OracleType
}

// OracleAddress returns the address of the oracle contract and is only supported on the OP stack for now.
func (d *daOracleConfig) OracleAddress() *types.EIP55Address {
return d.c.OracleAddress
}

// CustomGasPriceCalldata returns the calldata for a custom gas price API.
func (d *daOracleConfig) CustomGasPriceCalldata() string {
// TODO: CCIP-3710 update once custom calldata oracle is added
return ""
}

type limitJobTypeConfig struct {
c toml.GasLimitJobType
}
Expand Down
8 changes: 8 additions & 0 deletions core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
)

Expand Down Expand Up @@ -141,6 +142,7 @@ type GasEstimator interface {
Mode() string
PriceMaxKey(gethcommon.Address) *assets.Wei
EstimateLimit() bool
DAOracle() DAOracle
}

type LimitJobType interface {
Expand All @@ -162,6 +164,12 @@ type BlockHistory interface {
TransactionPercentile() uint16
}

type DAOracle interface {
OracleType() toml.OracleType
OracleAddress() *types.EIP55Address
CustomGasPriceCalldata() string
}

type FeeHistory interface {
CacheTimeout() time.Duration
}
Expand Down
47 changes: 47 additions & 0 deletions core/chains/evm/config/mocks/gas_estimator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ type GasEstimator struct {

BlockHistory BlockHistoryEstimator `toml:",omitempty"`
FeeHistory FeeHistoryEstimator `toml:",omitempty"`
DAOracle DAOracle `toml:",omitempty"`
}

func (e *GasEstimator) ValidateConfig() (err error) {
Expand Down Expand Up @@ -683,6 +684,7 @@ func (e *GasEstimator) setFrom(f *GasEstimator) {
e.LimitJobType.setFrom(&f.LimitJobType)
e.BlockHistory.setFrom(&f.BlockHistory)
e.FeeHistory.setFrom(&f.FeeHistory)
e.DAOracle.setFrom(&f.DAOracle)
}

type GasLimitJobType struct {
Expand Down Expand Up @@ -755,6 +757,28 @@ func (u *FeeHistoryEstimator) setFrom(f *FeeHistoryEstimator) {
}
}

type DAOracle struct {
OracleType OracleType
OracleAddress *types.EIP55Address
CustomGasPriceCalldata string
}

type OracleType string

const (
OPStack = OracleType("opstack")
Arbitrum = OracleType("arbitrum")
ZKSync = OracleType("zksync")
)

func (d *DAOracle) setFrom(f *DAOracle) {
d.OracleType = f.OracleType
if v := f.OracleAddress; v != nil {
d.OracleAddress = v
}
d.CustomGasPriceCalldata = f.CustomGasPriceCalldata
}

type KeySpecificConfig []KeySpecific

func (ks KeySpecificConfig) ValidateConfig() (err error) {
Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Base_Goerli.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ BumpMin = '100 wei'
[GasEstimator.BlockHistory]
BlockHistorySize = 60

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x420000000000000000000000000000000000000F'

[Transactions]
ResendAfterThreshold = '30s'

Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Base_Mainnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ BumpMin = '100 wei'
[GasEstimator.BlockHistory]
BlockHistorySize = 24

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x420000000000000000000000000000000000000F'

[Transactions]
ResendAfterThreshold = '30s'

Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Base_Sepolia.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ BumpMin = '100 wei'
[GasEstimator.BlockHistory]
BlockHistorySize = 60

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x420000000000000000000000000000000000000F'

[Transactions]
ResendAfterThreshold = '30s'

Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Kroma_Mainnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ BumpMin = '100 wei'
[GasEstimator.BlockHistory]
BlockHistorySize = 24

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x4200000000000000000000000000000000000005'

[Transactions]
ResendAfterThreshold = '30s'

Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Kroma_Sepolia.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ BumpMin = '100 wei'
[GasEstimator.BlockHistory]
BlockHistorySize = 24

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x4200000000000000000000000000000000000005'

[Transactions]
ResendAfterThreshold = '30s'

Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Optimism_Goerli.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ BumpMin = '100 wei'
[GasEstimator.BlockHistory]
BlockHistorySize = 60

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x420000000000000000000000000000000000000F'

[Transactions]
ResendAfterThreshold = '30s'

Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Optimism_Mainnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ BumpMin = '100 wei'
[GasEstimator.BlockHistory]
BlockHistorySize = 24

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x420000000000000000000000000000000000000F'

[Transactions]
ResendAfterThreshold = '30s'

Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Optimism_Sepolia.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ BumpMin = '100 wei'
[GasEstimator.BlockHistory]
BlockHistorySize = 60

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x420000000000000000000000000000000000000F'

[Transactions]
ResendAfterThreshold = '30s'

Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Scroll_Mainnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ BumpMin = '1 gwei'
[GasEstimator.BlockHistory]
BlockHistorySize = 24

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x5300000000000000000000000000000000000002'

[HeadTracker]
HistoryDepth = 50

Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Scroll_Sepolia.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ BumpMin = '1 gwei'
[GasEstimator.BlockHistory]
BlockHistorySize = 24

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x5300000000000000000000000000000000000002'

[HeadTracker]
HistoryDepth = 50

Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Soneium_Sepolia.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ BumpMin = '1 mwei'
[GasEstimator.BlockHistory]
BlockHistorySize = 60

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x420000000000000000000000000000000000000F'

[Transactions]
ResendAfterThreshold = '30s'

Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Zircuit_Mainnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ BumpMin = '100 wei'
[GasEstimator.BlockHistory]
BlockHistorySize = 24

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x420000000000000000000000000000000000000F'

[Transactions]
ResendAfterThreshold = '30s'

Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/config/toml/defaults/Zircuit_Sepolia.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ BumpMin = '100 wei'
[GasEstimator.BlockHistory]
BlockHistorySize = 60

[GasEstimator.DAOracle]
OracleType = 'opstack'
OracleAddress = '0x420000000000000000000000000000000000000F'

[Transactions]
ResendAfterThreshold = '30s'

Expand Down
3 changes: 2 additions & 1 deletion core/chains/evm/gas/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ func NewEstimator(lggr logger.Logger, ethClient feeEstimatorClient, chaintype ch
"priceMax", geCfg.PriceMax(),
"priceMin", geCfg.PriceMin(),
"estimateLimit", geCfg.EstimateLimit(),
"daOracleAddress", geCfg.DAOracle().OracleAddress(),
)
df := geCfg.EIP1559DynamicFees()

// create l1Oracle only if it is supported for the chain
var l1Oracle rollups.L1Oracle
if rollups.IsRollupWithL1Support(chaintype) {
var err error
l1Oracle, err = rollups.NewL1GasOracle(lggr, ethClient, chaintype)
l1Oracle, err = rollups.NewL1GasOracle(lggr, ethClient, chaintype, geCfg.DAOracle())
if err != nil {
return nil, fmt.Errorf("failed to initialize L1 oracle: %w", err)
}
Expand Down
4 changes: 3 additions & 1 deletion core/chains/evm/gas/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
commonfee "github.com/smartcontractkit/chainlink/v2/common/fee"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/mocks"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/rollups"
Expand Down Expand Up @@ -71,7 +72,8 @@ func TestWrappedEvmEstimator(t *testing.T) {
assert.Nil(t, l1Oracle)

// expect l1Oracle
oracle, err := rollups.NewL1GasOracle(lggr, nil, chaintype.ChainOptimismBedrock)
daOracle := rollups.CreateTestDAOracle(t, toml.OPStack, "0x420000000000000000000000000000000000000F", "")
oracle, err := rollups.NewL1GasOracle(lggr, nil, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
// cast oracle to L1Oracle interface
estimator = gas.NewEvmFeeEstimator(lggr, getEst, false, geCfg, nil)
Expand Down
Loading

0 comments on commit 4ac405a

Please sign in to comment.