github.com/smartcontractkit/chainlink-testing-framework/libs@v0.0.0-20240227141906-ec710b4eb1a3/blockchain/optimism.go (about) 1 package blockchain 2 3 import ( 4 "context" 5 6 "github.com/ethereum/go-ethereum" 7 "github.com/ethereum/go-ethereum/accounts/abi/bind" 8 "github.com/ethereum/go-ethereum/common" 9 "github.com/ethereum/go-ethereum/core/types" 10 "github.com/rs/zerolog/log" 11 12 ethcontracts "github.com/smartcontractkit/chainlink-testing-framework/libs/contracts/ethereum" 13 ) 14 15 const optimismGasOracleAddress string = "0x420000000000000000000000000000000000000F" 16 17 // OptimismMultinodeClient represents a multi-node, EVM compatible client for the Optimism network 18 type OptimismMultinodeClient struct { 19 *EthereumMultinodeClient 20 } 21 22 // OptimismClient represents a single node, EVM compatible client for the Optimism network 23 type OptimismClient struct { 24 *EthereumClient 25 } 26 27 func (o *OptimismClient) EstimateGas(callData ethereum.CallMsg) (GasEstimations, error) { 28 // Optimism is unique in its usage of an L1 data fee on top of regular gas costs. Need to call their oracle 29 // https://community.optimism.io/docs/developers/build/transaction-fees/#the-l1-data-fee 30 gasOracle, err := ethcontracts.NewOptimismGas(common.HexToAddress(optimismGasOracleAddress), o.Client) 31 if err != nil { 32 return GasEstimations{}, err 33 } 34 opts := &bind.CallOpts{ 35 From: common.HexToAddress(o.GetDefaultWallet().Address()), 36 Context: context.Background(), 37 } 38 l1Fee, err := gasOracle.GetL1Fee(opts, types.DynamicFeeTx{}.Data) 39 if err != nil { 40 return GasEstimations{}, err 41 } 42 gasEstimations, err := o.EthereumClient.EstimateGas(callData) 43 if err != nil { 44 return GasEstimations{}, err 45 } 46 initialEstimate := gasEstimations.TotalGasCost 47 gasEstimations.TotalGasCost.Add(initialEstimate, l1Fee) 48 log.Debug(). 49 Uint64("New Total Cost", gasEstimations.TotalGasCost.Uint64()). 50 Uint64("Initial Estimate", initialEstimate.Uint64()). 51 Uint64("L1 Fee", l1Fee.Uint64()). 52 Msg("Adding Optimism L1 Fee") 53 return gasEstimations, err 54 }