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