-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
fixed_price_estimator.go
65 lines (52 loc) · 2.64 KB
/
fixed_price_estimator.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 gas
import (
"context"
"math/big"
"github.com/pkg/errors"
evmtypes "github.com/smartcontractkit/chainlink/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/core/logger"
)
var _ Estimator = &fixedPriceEstimator{}
type fixedPriceEstimator struct {
config Config
lggr logger.SugaredLogger
}
// NewFixedPriceEstimator returns a new "FixedPrice" estimator which will
// always use the config default values for gas prices and limits
func NewFixedPriceEstimator(cfg Config, lggr logger.Logger) Estimator {
return &fixedPriceEstimator{cfg, logger.Sugared(lggr.Named("FixedPriceEstimator"))}
}
func (f *fixedPriceEstimator) Start(context.Context) error { return nil }
func (f *fixedPriceEstimator) Close() error { return nil }
func (f *fixedPriceEstimator) OnNewLongestChain(_ context.Context, _ *evmtypes.Head) {}
func (f *fixedPriceEstimator) GetLegacyGas(_ []byte, gasLimit uint32, maxGasPriceWei *big.Int, _ ...Opt) (gasPrice *big.Int, chainSpecificGasLimit uint32, err error) {
gasPrice = f.config.EvmGasPriceDefault()
chainSpecificGasLimit = applyMultiplier(gasLimit, f.config.EvmGasLimitMultiplier())
gasPrice = capGasPrice(gasPrice, maxGasPriceWei, f.config)
return
}
func (f *fixedPriceEstimator) BumpLegacyGas(originalGasPrice *big.Int, originalGasLimit uint32, maxGasPriceWei *big.Int) (gasPrice *big.Int, gasLimit uint32, err error) {
return BumpLegacyGasPriceOnly(f.config, f.lggr, f.config.EvmGasPriceDefault(), originalGasPrice, originalGasLimit, maxGasPriceWei)
}
func (f *fixedPriceEstimator) GetDynamicFee(originalGasLimit uint32, maxGasPriceWei *big.Int) (d DynamicFee, chainSpecificGasLimit uint32, err error) {
gasTipCap := f.config.EvmGasTipCapDefault()
if gasTipCap == nil {
return d, 0, errors.New("cannot calculate dynamic fee: EthGasTipCapDefault was not set")
}
chainSpecificGasLimit = applyMultiplier(originalGasLimit, f.config.EvmGasLimitMultiplier())
var feeCap *big.Int
if f.config.EvmGasBumpThreshold() == 0 {
// Gas bumping is disabled, just use the max fee cap
feeCap = getMaxGasPrice(maxGasPriceWei, f.config)
} else {
// Need to leave headroom for bumping so we fallback to the default value here
feeCap = f.config.EvmGasFeeCapDefault()
}
return DynamicFee{
FeeCap: feeCap,
TipCap: gasTipCap,
}, chainSpecificGasLimit, nil
}
func (f *fixedPriceEstimator) BumpDynamicFee(originalFee DynamicFee, originalGasLimit uint32, maxGasPriceWei *big.Int) (bumped DynamicFee, chainSpecificGasLimit uint32, err error) {
return BumpDynamicFeeOnly(f.config, f.lggr, f.config.EvmGasTipCapDefault(), nil, originalFee, originalGasLimit, maxGasPriceWei)
}