github.com/smartcontractkit/chainlink-testing-framework/libs@v0.0.0-20240227141906-ec710b4eb1a3/blockchain/kroma.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 // Kroma Gas Oracle Address https://docs.kroma.network/testnet/contract-addresses 16 const kromaGasOracleAddress string = "0x4200000000000000000000000000000000000005" 17 18 // KromaMultinodeClient represents a multi-node, EVM compatible client for the Kroma network 19 type KromaMultinodeClient struct { 20 *EthereumMultinodeClient 21 } 22 23 // KromaClient represents a single node, EVM compatible client for the Kroma network 24 type KromaClient struct { 25 *EthereumClient 26 } 27 28 func (o *KromaClient) EstimateGas(callData ethereum.CallMsg) (GasEstimations, error) { 29 // Kroma is based on Optimism and uses the same gas machanism. The L1 fee needs to be added on top of the regular gas costs. 30 gasOracle, err := ethcontracts.NewOptimismGas(common.HexToAddress(kromaGasOracleAddress), 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 Kroma L1 Fee") 53 return gasEstimations, err 54 }