@@ -27,33 +27,55 @@ type EIP1559FeeEstimator struct {
27
27
// Access to the Ethereum client is needed to get the fee information from the chain
28
28
client EIP1159FeeEthClient
29
29
30
+ options eip1559FeeEstimatorOptions
31
+ }
32
+
33
+ type eip1559FeeEstimatorOptions struct {
30
34
// The base multiplier is used to increase the maxFeePerGas (GasFeeCap) by a factor
31
35
baseMultiplier float64
32
36
33
37
// The tip multiplier is used to increase the maxPriorityFeePerGas (GasTipCap) by a factor
34
38
tipMultiplier float64
35
39
}
36
40
37
- func NewEIP1559FeeEstimator (client EIP1159FeeEthClient ) * EIP1559FeeEstimator {
38
- return & EIP1559FeeEstimator {
39
- client : client ,
40
- baseMultiplier : 1.0 ,
41
- tipMultiplier : 1.0 ,
42
- }
41
+ type EIP1559FeeEstimatorOption interface {
42
+ apply (* eip1559FeeEstimatorOptions )
43
+ }
44
+
45
+ type eip1559FeeEstimatorOptionBaseMultiplier float64
46
+
47
+ func (o eip1559FeeEstimatorOptionBaseMultiplier ) apply (opts * eip1559FeeEstimatorOptions ) {
48
+ opts .baseMultiplier = float64 (o )
49
+ }
50
+
51
+ func WithEIP1559BaseMultiplier (multiplier float64 ) EIP1559FeeEstimatorOption {
52
+ return eip1559FeeEstimatorOptionBaseMultiplier (multiplier )
43
53
}
44
54
45
- func (f * EIP1559FeeEstimator ) WithBaseMultiplier (multiplier float64 ) * EIP1559FeeEstimator {
46
- newF := * f
47
- newF .baseMultiplier = multiplier
55
+ type eip1559FeeEstimatorOptionTipMultiplier float64
56
+
57
+ func (o eip1559FeeEstimatorOptionTipMultiplier ) apply (opts * eip1559FeeEstimatorOptions ) {
58
+ opts .tipMultiplier = float64 (o )
59
+ }
48
60
49
- return & newF
61
+ func WithEIP1559TipMultiplier (multiplier float64 ) EIP1559FeeEstimatorOption {
62
+ return eip1559FeeEstimatorOptionTipMultiplier (multiplier )
50
63
}
51
64
52
- func (f * EIP1559FeeEstimator ) WithTipMultiplier (multiplier float64 ) * EIP1559FeeEstimator {
53
- newF := * f
54
- newF .tipMultiplier = multiplier
65
+ func NewEIP1559FeeEstimator (client EIP1159FeeEthClient , opts ... EIP1559FeeEstimatorOption ) * EIP1559FeeEstimator {
66
+ options := eip1559FeeEstimatorOptions {
67
+ baseMultiplier : 1.0 ,
68
+ tipMultiplier : 1.0 ,
69
+ }
70
+
71
+ for _ , o := range opts {
72
+ o .apply (& options )
73
+ }
55
74
56
- return & newF
75
+ return & EIP1559FeeEstimator {
76
+ client : client ,
77
+ options : options ,
78
+ }
57
79
}
58
80
59
81
func (f * EIP1559FeeEstimator ) EstimateFees (ctx context.Context , opts * bind.TransactOpts ) (* bind.TransactOpts , error ) {
@@ -68,7 +90,7 @@ func (f *EIP1559FeeEstimator) EstimateFees(ctx context.Context, opts *bind.Trans
68
90
}
69
91
70
92
// GasTipCap represents the maxPriorityFeePerGas
71
- newOpts .GasTipCap = multiplyBigInt (tipCap , f .tipMultiplier )
93
+ newOpts .GasTipCap = multiplyBigInt (tipCap , f .options . tipMultiplier )
72
94
}
73
95
74
96
// Add a gas fee cap if needed
@@ -81,7 +103,7 @@ func (f *EIP1559FeeEstimator) EstimateFees(ctx context.Context, opts *bind.Trans
81
103
baseFee := block .BaseFee ()
82
104
if baseFee != nil {
83
105
// The adjusted base fee takes the multiplier into account
84
- adjustedBaseFee := multiplyBigInt (baseFee , f .baseMultiplier )
106
+ adjustedBaseFee := multiplyBigInt (baseFee , f .options . baseMultiplier )
85
107
86
108
// The total fee (maxFeePerGas) is the sum of the base fee and the tip
87
109
newOpts .GasFeeCap = big .NewInt (0 ).Add (adjustedBaseFee , newOpts .GasTipCap )
0 commit comments