Skip to content

Commit

Permalink
CCIP-4420 Mantle gas interceptor (#15900)
Browse files Browse the repository at this point in the history
* Fixing gas estimator interceptor for Mantle

* Adding extra check for the address presence
  • Loading branch information
mateusz-sekara authored Jan 13, 2025
1 parent 1251ee3 commit cf7b1b0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 189 deletions.

This file was deleted.

This file was deleted.

8 changes: 5 additions & 3 deletions core/services/relay/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/ccipexec"
ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/estimatorconfig"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/estimatorconfig/interceptors/mantle"
cciptransmitter "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/transmitter"
lloconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/llo/config"
mercuryconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/mercury/config"
"github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/codec"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/functions"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/interceptors/mantle"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury"
mercuryutils "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/utils"
reportcodecv1 "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/v1/reportcodec"
Expand Down Expand Up @@ -541,7 +541,8 @@ func (r *Relayer) NewCCIPCommitProvider(ctx context.Context, rargs commontypes.R
// to minimize misconfigure risk, might make sense to wire Mantle only when Commit + Mantle + IsSourceProvider
if r.chain.Config().EVM().ChainID().Uint64() == 5003 || r.chain.Config().EVM().ChainID().Uint64() == 5000 {
if commitPluginConfig.IsSourceProvider {
mantleInterceptor, iErr := mantle.NewInterceptor(ctx, r.chain.Client())
oracleAddress := r.chain.Config().EVM().GasEstimator().DAOracle().OracleAddress()
mantleInterceptor, iErr := mantle.NewInterceptor(ctx, r.chain.Client(), oracleAddress)
if iErr != nil {
return nil, iErr
}
Expand Down Expand Up @@ -619,7 +620,8 @@ func (r *Relayer) NewCCIPExecProvider(ctx context.Context, rargs commontypes.Rel
// to minimize misconfigure risk, make sense to wire Mantle only when Exec + Mantle + !IsSourceProvider
if r.chain.Config().EVM().ChainID().Uint64() == 5003 || r.chain.Config().EVM().ChainID().Uint64() == 5000 {
if !execPluginConfig.IsSourceProvider {
mantleInterceptor, iErr := mantle.NewInterceptor(ctx, r.chain.Client())
oracleAddress := r.chain.Config().EVM().GasEstimator().DAOracle().OracleAddress()
mantleInterceptor, iErr := mantle.NewInterceptor(ctx, r.chain.Client(), oracleAddress)
if iErr != nil {
return nil, iErr
}
Expand Down
16 changes: 10 additions & 6 deletions core/services/relay/evm/interceptors/mantle/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package mantle

import (
"context"
"errors"
"fmt"
"math/big"
"strings"
"time"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"

evmClient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
)

const (
Expand All @@ -27,9 +29,13 @@ type Interceptor struct {
tokenRatioCallData []byte
tokenRatio *big.Int
tokenRatioLastUpdate time.Time
oracleAddress common.Address
}

func NewInterceptor(_ context.Context, client evmClient.Client) (*Interceptor, error) {
func NewInterceptor(_ context.Context, client evmClient.Client, address *evmtypes.EIP55Address) (*Interceptor, error) {
if address == nil {
return nil, errors.New("oracle address is missing")
}
// Encode calldata for tokenRatio method
tokenRatioMethodAbi, err := abi.JSON(strings.NewReader(mantleTokenRatioAbiString))
if err != nil {
Expand All @@ -43,6 +49,7 @@ func NewInterceptor(_ context.Context, client evmClient.Client) (*Interceptor, e
return &Interceptor{
client: client,
tokenRatioCallData: tokenRatioCallData,
oracleAddress: address.Address(),
}, nil
}

Expand All @@ -65,11 +72,8 @@ func (i *Interceptor) ModifyGasPriceComponents(ctx context.Context, execGasPrice

// getMantleTokenRatio Requests and returns a token ratio value for the Mantle chain.
func (i *Interceptor) getMantleTokenRatio(ctx context.Context) (*big.Int, error) {
// FIXME it's removed from chainlink repo
// precompile := common.HexToAddress(rollups.OPGasOracleAddress)
precompile := utils.RandomAddress()
tokenRatio, err := i.client.CallContract(ctx, ethereum.CallMsg{
To: &precompile,
To: &i.oracleAddress,
Data: i.tokenRatioCallData,
}, nil)

Expand Down
11 changes: 9 additions & 2 deletions core/services/relay/evm/interceptors/mantle/interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ import (
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
)

var randomAddress = types.MustEIP55Address(utils.RandomAddress().String())

func TestInterceptor(t *testing.T) {
ethClient := mocks.NewClient(t)
ctx := context.Background()

_, err := NewInterceptor(ctx, ethClient, nil)
require.Error(t, err)

tokenRatio := big.NewInt(10)
interceptor, err := NewInterceptor(ctx, ethClient)
interceptor, err := NewInterceptor(ctx, ethClient, &randomAddress)
require.NoError(t, err)

// request token ratio
Expand Down Expand Up @@ -80,7 +87,7 @@ func TestModifyGasPriceComponents(t *testing.T) {
ethClient := mocks.NewClient(t)
ctx := context.Background()

interceptor, err := NewInterceptor(ctx, ethClient)
interceptor, err := NewInterceptor(ctx, ethClient, &randomAddress)
require.NoError(t, err)

// request token ratio
Expand Down

0 comments on commit cf7b1b0

Please sign in to comment.