Skip to content

Commit

Permalink
Move daoracle config into own package
Browse files Browse the repository at this point in the history
  • Loading branch information
ogtownsend committed Oct 11, 2024
1 parent 770d2bc commit 746d01d
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 61 deletions.
4 changes: 2 additions & 2 deletions core/capabilities/ccip/ocrimpls/contract_transmitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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/config/toml/daoracle"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -598,7 +598,7 @@ type TestDAOracleConfig struct {
evmconfig.DAOracle
}

func (d *TestDAOracleConfig) OracleType() toml.OracleType { return toml.OPStack }
func (d *TestDAOracleConfig) OracleType() daoracle.OracleType { return daoracle.OPStack }
func (d *TestDAOracleConfig) OracleAddress() *types.EIP55Address {
a, err := types.NewEIP55Address("0x420000000000000000000000000000000000000F")
if err != nil {
Expand Down
5 changes: 3 additions & 2 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/config/toml/daoracle"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
)

Expand Down Expand Up @@ -124,10 +125,10 @@ func (g *gasEstimatorConfig) EstimateLimit() bool {
}

type daOracleConfig struct {
c toml.DAOracle
c daoracle.DAOracle
}

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

Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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/config/toml/daoracle"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
)

Expand Down Expand Up @@ -165,7 +165,7 @@ type BlockHistory interface {
}

type DAOracle interface {
OracleType() toml.OracleType
OracleType() daoracle.OracleType
OracleAddress() *types.EIP55Address
CustomGasPriceCalldata() string
}
Expand Down
27 changes: 3 additions & 24 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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/daoracle"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
)
Expand Down Expand Up @@ -588,7 +589,7 @@ type GasEstimator struct {

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

func (e *GasEstimator) ValidateConfig() (err error) {
Expand Down Expand Up @@ -684,7 +685,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)
e.DAOracle.SetFrom(&f.DAOracle)
}

type GasLimitJobType struct {
Expand Down Expand Up @@ -757,28 +758,6 @@ 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
25 changes: 25 additions & 0 deletions core/chains/evm/config/toml/daoracle/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package daoracle

import "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"

type OracleType string

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

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

func (d *DAOracle) SetFrom(f *DAOracle) {
d.OracleType = f.OracleType
if v := f.OracleAddress; v != nil {
d.OracleAddress = v
}
d.CustomGasPriceCalldata = f.CustomGasPriceCalldata
}
4 changes: 2 additions & 2 deletions core/chains/evm/gas/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +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/config/toml/daoracle"
"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 @@ -72,7 +72,7 @@ func TestWrappedEvmEstimator(t *testing.T) {
assert.Nil(t, l1Oracle)

// expect l1Oracle
daOracle := rollups.CreateTestDAOracle(t, toml.OPStack, "0x420000000000000000000000000000000000000F", "")
daOracle := rollups.CreateTestDAOracle(t, daoracle.OPStack, "0x420000000000000000000000000000000000000F", "")
oracle, err := rollups.NewL1GasOracle(lggr, nil, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
// cast oracle to L1Oracle interface
Expand Down
10 changes: 5 additions & 5 deletions core/chains/evm/gas/rollups/da_oracle_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (

"github.com/stretchr/testify/require"

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

type TestDAOracle struct {
toml.DAOracle
daoracle.DAOracle
}

func (d *TestDAOracle) OracleType() toml.OracleType {
func (d *TestDAOracle) OracleType() daoracle.OracleType {
return d.DAOracle.OracleType
}

Expand All @@ -25,12 +25,12 @@ func (d *TestDAOracle) CustomGasPriceCalldata() string {
return d.DAOracle.CustomGasPriceCalldata
}

func CreateTestDAOracle(t *testing.T, oracleType toml.OracleType, oracleAddress string, customGasPriceCalldata string) *TestDAOracle {
func CreateTestDAOracle(t *testing.T, oracleType daoracle.OracleType, oracleAddress string, customGasPriceCalldata string) *TestDAOracle {
oracleAddr, err := types.NewEIP55Address(oracleAddress)
require.NoError(t, err)

return &TestDAOracle{
DAOracle: toml.DAOracle{
DAOracle: daoracle.DAOracle{
OracleType: oracleType,
OracleAddress: &oracleAddr,
CustomGasPriceCalldata: customGasPriceCalldata,
Expand Down
8 changes: 4 additions & 4 deletions core/chains/evm/gas/rollups/l1_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"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/config/toml/daoracle"
)

// L1Oracle provides interface for fetching L1-specific fee components if the chain is an L2.
Expand Down Expand Up @@ -57,11 +57,11 @@ func NewL1GasOracle(lggr logger.Logger, ethClient l1OracleClient, chainType chai
var err error
if daOracle != nil {
switch daOracle.OracleType() {
case toml.OPStack:
case daoracle.OPStack:
l1Oracle, err = NewOpStackL1GasOracle(lggr, ethClient, chainType, daOracle)
case toml.Arbitrum:
case daoracle.Arbitrum:
l1Oracle, err = NewArbitrumL1GasOracle(lggr, ethClient)
case toml.ZKSync:
case daoracle.ZKSync:
l1Oracle = NewZkSyncL1GasOracle(lggr, ethClient)
default:
err = fmt.Errorf("unsupported DA oracle type %s. Going forward all chain configs should specify an oracle type", daOracle.OracleType())
Expand Down
16 changes: 8 additions & 8 deletions core/chains/evm/gas/rollups/l1_oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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/config/toml/daoracle"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/rollups/mocks"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
)
Expand All @@ -30,7 +30,7 @@ func TestL1Oracle(t *testing.T) {
t.Run("Unsupported ChainType returns nil", func(t *testing.T) {
ethClient := mocks.NewL1OracleClient(t)

daOracle := CreateTestDAOracle(t, toml.OPStack, utils.RandomAddress().String(), "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, utils.RandomAddress().String(), "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainCelo, daOracle)
require.NoError(t, err)
assert.Nil(t, oracle)
Expand All @@ -43,7 +43,7 @@ func TestL1Oracle_GasPrice(t *testing.T) {
t.Run("Calling GasPrice on unstarted L1Oracle returns error", func(t *testing.T) {
ethClient := mocks.NewL1OracleClient(t)

daOracle := CreateTestDAOracle(t, toml.OPStack, utils.RandomAddress().String(), "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, utils.RandomAddress().String(), "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)

Expand All @@ -67,7 +67,7 @@ func TestL1Oracle_GasPrice(t *testing.T) {
assert.Nil(t, blockNumber)
}).Return(common.BigToHash(l1BaseFee).Bytes(), nil)

daOracle := CreateTestDAOracle(t, toml.Arbitrum, "0x0000000000000000000000000000000000000000", "")
daOracle := CreateTestDAOracle(t, daoracle.Arbitrum, "0x0000000000000000000000000000000000000000", "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainArbitrum, daOracle)
require.NoError(t, err)
servicetest.RunHealthy(t, oracle)
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestL1Oracle_GasPrice(t *testing.T) {
assert.Nil(t, blockNumber)
}).Return(common.BigToHash(l1BaseFee).Bytes(), nil)

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, oracleAddress, "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainKroma, daOracle)
require.NoError(t, err)
servicetest.RunHealthy(t, oracle)
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestL1Oracle_GasPrice(t *testing.T) {
assert.Nil(t, blockNumber)
}).Return(common.BigToHash(l1BaseFee).Bytes(), nil)

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, oracleAddress, "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
servicetest.RunHealthy(t, oracle)
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestL1Oracle_GasPrice(t *testing.T) {
assert.Nil(t, blockNumber)
}).Return(common.BigToHash(l1BaseFee).Bytes(), nil)

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, oracleAddress, "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainScroll, daOracle)
require.NoError(t, err)
servicetest.RunHealthy(t, oracle)
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestL1Oracle_GasPrice(t *testing.T) {
assert.Nil(t, blockNumber)
}).Return(common.BigToHash(gasPerPubByteL2).Bytes(), nil)

daOracle := CreateTestDAOracle(t, toml.ZKSync, "0x0000000000000000000000000000000000000000", "")
daOracle := CreateTestDAOracle(t, daoracle.ZKSync, "0x0000000000000000000000000000000000000000", "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainZkSync, daOracle)
require.NoError(t, err)
servicetest.RunHealthy(t, oracle)
Expand Down
20 changes: 10 additions & 10 deletions core/chains/evm/gas/rollups/op_l1_oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"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/config/toml/daoracle"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/rollups/mocks"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
)
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestOPL1Oracle_ReadV1GasPrice(t *testing.T) {
assert.Nil(t, blockNumber)
}).Return(common.BigToHash(l1BaseFee).Bytes(), nil).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, "0x0000000000000000000000000000000000001234", "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, "0x0000000000000000000000000000000000001234", "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
gasPrice, err := oracle.GetDAGasPrice(tests.Context(t))
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestOPL1Oracle_CalculateEcotoneGasPrice(t *testing.T) {
ethClient := setupUpgradeCheck(t, oracleAddress, false, true)
mockBatchContractCall(t, ethClient, oracleAddress, baseFee, baseFeeScalar, blobBaseFee, blobBaseFeeScalar, decimals)

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
gasPrice, err := oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -246,7 +246,7 @@ func TestOPL1Oracle_CalculateEcotoneGasPrice(t *testing.T) {
rpcElements[1].Result = &badData
}).Return(nil).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
_, err = oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -257,7 +257,7 @@ func TestOPL1Oracle_CalculateEcotoneGasPrice(t *testing.T) {
ethClient := setupUpgradeCheck(t, oracleAddress, false, true)
ethClient.On("BatchCallContext", mock.Anything, mock.IsType([]rpc.BatchElem{})).Return(fmt.Errorf("revert")).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
_, err = oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -273,7 +273,7 @@ func TestOPL1Oracle_CalculateEcotoneGasPrice(t *testing.T) {
rpcElements[1].Error = fmt.Errorf("revert")
}).Return(nil).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
_, err = oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -295,7 +295,7 @@ func TestOPL1Oracle_CalculateFjordGasPrice(t *testing.T) {
ethClient := setupUpgradeCheck(t, oracleAddress, true, true)
mockBatchContractCall(t, ethClient, oracleAddress, baseFee, baseFeeScalar, blobBaseFee, blobBaseFeeScalar, decimals)

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
gasPrice, err := oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -315,7 +315,7 @@ func TestOPL1Oracle_CalculateFjordGasPrice(t *testing.T) {
rpcElements[1].Result = &badData
}).Return(nil).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
_, err = oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -326,7 +326,7 @@ func TestOPL1Oracle_CalculateFjordGasPrice(t *testing.T) {
ethClient := setupUpgradeCheck(t, oracleAddress, true, true)
ethClient.On("BatchCallContext", mock.Anything, mock.IsType([]rpc.BatchElem{})).Return(fmt.Errorf("revert")).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
_, err = oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -342,7 +342,7 @@ func TestOPL1Oracle_CalculateFjordGasPrice(t *testing.T) {
rpcElements[1].Error = fmt.Errorf("revert")
}).Return(nil).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, daoracle.OPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
_, err = oracle.GetDAGasPrice(tests.Context(t))
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/txmgr/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"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/config/toml/daoracle"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
"github.com/smartcontractkit/chainlink/v2/core/config"
Expand Down Expand Up @@ -82,7 +82,7 @@ type TestDAOracleConfig struct {
evmconfig.DAOracle
}

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

0 comments on commit 746d01d

Please sign in to comment.