github.com/0xsequence/ethkit@v1.25.0/ethgas/readers.go (about) 1 package ethgas 2 3 import ( 4 "math/big" 5 6 "github.com/0xsequence/ethkit/ethmonitor" 7 "github.com/0xsequence/ethkit/go-ethereum/core/types" 8 ) 9 10 type GasPriceReader func(block *ethmonitor.Block) []*big.Int 11 12 var CustomGasPriceBidReaders = map[uint64]GasPriceReader{} 13 14 var CustomGasPricePaidReaders = map[uint64]GasPriceReader{ 15 42161: arbitrumGasPricePaidReader, // arbitrum one 16 42170: arbitrumGasPricePaidReader, // arbitrum nova 17 421611: arbitrumGasPricePaidReader, // arbitrum rinkeby 18 421613: arbitrumGasPricePaidReader, // arbitrum goerli 19 421614: arbitrumGasPricePaidReader, // arbitrum sepolia 20 200: arbitrumGasPricePaidReader, // arbitrum xdai 21 } 22 23 func DefaultGasPriceBidReader(block *ethmonitor.Block) []*big.Int { 24 transactions := block.Transactions() 25 prices := make([]*big.Int, 0, len(transactions)) 26 27 for _, transaction := range transactions { 28 prices = append(prices, transaction.GasFeeCap()) 29 } 30 31 return prices 32 } 33 34 func DefaultGasPricePaidReader(block *ethmonitor.Block) []*big.Int { 35 transactions := block.Transactions() 36 prices := make([]*big.Int, 0, len(transactions)) 37 38 for _, transaction := range transactions { 39 var price *big.Int 40 41 switch transaction.Type() { 42 case types.LegacyTxType: 43 price = transaction.GasPrice() 44 case types.AccessListTxType: 45 price = transaction.GasPrice() 46 case types.DynamicFeeTxType: 47 price = new(big.Int).Add(block.BaseFee(), transaction.GasTipCap()) 48 } 49 50 prices = append(prices, price) 51 } 52 53 return prices 54 } 55 56 func arbitrumGasPricePaidReader(block *ethmonitor.Block) []*big.Int { 57 transactions := block.Transactions() 58 prices := make([]*big.Int, 0, len(transactions)) 59 60 for range transactions { 61 prices = append(prices, block.BaseFee()) 62 } 63 64 return prices 65 }