Documentation
¶
Index ¶
- Constants
- Variables
- func BumpLegacyGasPriceOnly(cfg bumpConfig, lggr logger.SugaredLogger, ...) (gasPrice *assets.Wei, err error)
- func HexToInt64(input interface{}) int64
- func Int64ToHex(n int64) string
- func LimitBumpedFee(originalFee *assets.Wei, currentFee *assets.Wei, bumpedFee *assets.Wei, ...) (*assets.Wei, error)
- type ArbConfig
- type BlockHistoryEstimator
- func (b *BlockHistoryEstimator) BumpDynamicFee(_ context.Context, originalFee DynamicFee, maxGasPriceWei *assets.Wei, ...) (bumped DynamicFee, err error)
- func (b *BlockHistoryEstimator) BumpLegacyGas(_ context.Context, originalGasPrice *assets.Wei, gasLimit uint64, ...) (bumpedGasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)
- func (b *BlockHistoryEstimator) Close() error
- func (b *BlockHistoryEstimator) EffectiveGasPrice(block evmtypes.Block, tx evmtypes.Transaction) *assets.Wei
- func (b *BlockHistoryEstimator) EffectiveTipCap(block evmtypes.Block, tx evmtypes.Transaction) *assets.Wei
- func (b *BlockHistoryEstimator) FetchBlocks(ctx context.Context, head *evmtypes.Head) error
- func (b *BlockHistoryEstimator) FetchBlocksAndRecalculate(ctx context.Context, head *evmtypes.Head)
- func (b *BlockHistoryEstimator) GetDynamicFee(_ context.Context, maxGasPriceWei *assets.Wei) (fee DynamicFee, err error)
- func (b *BlockHistoryEstimator) GetLegacyGas(_ context.Context, _ []byte, gasLimit uint64, maxGasPriceWei *assets.Wei, ...) (gasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)
- func (b *BlockHistoryEstimator) HealthReport() map[string]error
- func (b *BlockHistoryEstimator) IsUsable(tx evmtypes.Transaction, block evmtypes.Block, chainType chaintype.ChainType, ...) bool
- func (b *BlockHistoryEstimator) L1Oracle() rollups.L1Oracle
- func (b *BlockHistoryEstimator) Name() string
- func (b *BlockHistoryEstimator) OnNewLongestChain(_ context.Context, head *evmtypes.Head)
- func (b *BlockHistoryEstimator) Recalculate(head *evmtypes.Head)
- func (b *BlockHistoryEstimator) Start(ctx context.Context) error
- type DynamicFee
- type EvmEstimator
- func NewArbitrumEstimator(lggr logger.Logger, cfg ArbConfig, ethClient feeEstimatorClient, ...) EvmEstimator
- func NewBlockHistoryEstimator(lggr logger.Logger, ethClient feeEstimatorClient, ...) EvmEstimator
- func NewFixedPriceEstimator(cfg fixedPriceEstimatorConfig, ethClient feeEstimatorClient, ...) EvmEstimator
- func NewSuggestedPriceEstimator(lggr logger.Logger, client feeEstimatorClient, cfg suggestedPriceConfig, ...) EvmEstimator
- type EvmFee
- type EvmFeeEstimator
- type EvmPriorAttempt
- type FeeHistoryEstimator
- func (f *FeeHistoryEstimator) BumpDynamicFee(ctx context.Context, originalFee DynamicFee, maxPrice *assets.Wei, ...) (bumped DynamicFee, err error)
- func (f *FeeHistoryEstimator) BumpLegacyGas(ctx context.Context, originalGasPrice *assets.Wei, gasLimit uint64, ...) (*assets.Wei, uint64, error)
- func (f *FeeHistoryEstimator) Close() error
- func (f *FeeHistoryEstimator) GetDynamicFee(ctx context.Context, maxPrice *assets.Wei) (fee DynamicFee, err error)
- func (f *FeeHistoryEstimator) GetLegacyGas(ctx context.Context, _ []byte, gasLimit uint64, maxPrice *assets.Wei, ...) (gasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)
- func (f *FeeHistoryEstimator) HealthReport() map[string]error
- func (f *FeeHistoryEstimator) L1Oracle() rollups.L1Oracle
- func (f *FeeHistoryEstimator) Name() string
- func (f *FeeHistoryEstimator) OnNewLongestChain(context.Context, *evmtypes.Head)
- func (f *FeeHistoryEstimator) RefreshDynamicPrice() error
- func (f *FeeHistoryEstimator) RefreshGasPrice() (*assets.Wei, error)
- func (f *FeeHistoryEstimator) Start(context.Context) error
- type FeeHistoryEstimatorConfig
- type GasEstimatorConfig
- type SuggestedPriceEstimator
- func (*SuggestedPriceEstimator) BumpDynamicFee(_ context.Context, _ DynamicFee, _ *assets.Wei, _ []EvmPriorAttempt) (bumped DynamicFee, err error)
- func (o *SuggestedPriceEstimator) BumpLegacyGas(ctx context.Context, originalFee *assets.Wei, feeLimit uint64, ...) (newGasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)
- func (o *SuggestedPriceEstimator) Close() error
- func (*SuggestedPriceEstimator) GetDynamicFee(_ context.Context, _ *assets.Wei) (fee DynamicFee, err error)
- func (o *SuggestedPriceEstimator) GetLegacyGas(ctx context.Context, _ []byte, gasLimit uint64, maxGasPriceWei *assets.Wei, ...) (gasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)
- func (o *SuggestedPriceEstimator) HealthReport() map[string]error
- func (o *SuggestedPriceEstimator) L1Oracle() rollups.L1Oracle
- func (o *SuggestedPriceEstimator) Name() string
- func (o *SuggestedPriceEstimator) OnNewLongestChain(context.Context, *types.Head)
- func (o *SuggestedPriceEstimator) Start(context.Context) error
Constants ¶
const ( MinimumBumpPercentage = 10 // based on geth's spec ConnectivityPercentile = 85 BaseFeeBufferPercentage = 40 )
const BumpingHaltedLabel = "" /* 230-byte string literal not displayed */
const EstimateGasBuffer = float32(1.15)
EstimateGasBuffer is a multiplier applied to estimated gas when the EstimateLimit feature is enabled
Variables ¶
var (
ErrNoSuitableTransactions = errors.New("no suitable transactions")
)
var MaxStartTime = 10 * time.Second
MaxStartTime is the maximum amount of time we are allowed to spend trying to fill initial data on start. This must be capped because it can block the application from starting.
Functions ¶
func BumpLegacyGasPriceOnly ¶
func BumpLegacyGasPriceOnly(cfg bumpConfig, lggr logger.SugaredLogger, currentGasPrice, originalGasPrice *assets.Wei, maxGasPriceWei *assets.Wei) (gasPrice *assets.Wei, err error)
BumpLegacyGasPriceOnly will increase the price
func HexToInt64 ¶
func HexToInt64(input interface{}) int64
HexToInt64 performs the inverse of Int64ToHex Returns 0 on invalid input
func Int64ToHex ¶
Int64ToHex formats an int64 as a hex string with 0x prefix.
func LimitBumpedFee ¶
func LimitBumpedFee(originalFee *assets.Wei, currentFee *assets.Wei, bumpedFee *assets.Wei, maxPrice *assets.Wei) (*assets.Wei, error)
LimitBumpedFee selects the maximum value between the bumped attempt and the current fee, if there is one. If the result is higher than the max price it gets capped. Geth's implementation has a hard 10% minimum limit for the bumped values, otherwise it rejects the transaction with an error. See: https://github.com/ethereum/go-ethereum/blob/bff330335b94af3643ac2fb809793f77de3069d4/core/tx_list.go#L298
Note: for chains that support EIP-1559 but we still choose to send Legacy transactions to them, the limit is still enforcable due to the fact that Legacy transactions are treated the same way as Dynamic transactions under the hood. For chains that don't support EIP-1559 at all, the limit isn't enforcable but a 10% minimum bump percentage makes sense anyway.
Types ¶
type BlockHistoryEstimator ¶
type BlockHistoryEstimator struct {
services.StateMachine
// contains filtered or unexported fields
}
func (*BlockHistoryEstimator) BumpDynamicFee ¶
func (b *BlockHistoryEstimator) BumpDynamicFee(_ context.Context, originalFee DynamicFee, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumped DynamicFee, err error)
func (*BlockHistoryEstimator) BumpLegacyGas ¶
func (*BlockHistoryEstimator) Close ¶
func (b *BlockHistoryEstimator) Close() error
func (*BlockHistoryEstimator) EffectiveGasPrice ¶
func (b *BlockHistoryEstimator) EffectiveGasPrice(block evmtypes.Block, tx evmtypes.Transaction) *assets.Wei
func (*BlockHistoryEstimator) EffectiveTipCap ¶
func (b *BlockHistoryEstimator) EffectiveTipCap(block evmtypes.Block, tx evmtypes.Transaction) *assets.Wei
func (*BlockHistoryEstimator) FetchBlocks ¶
FetchBlocks fetches block history leading up to the given head.
func (*BlockHistoryEstimator) FetchBlocksAndRecalculate ¶
func (b *BlockHistoryEstimator) FetchBlocksAndRecalculate(ctx context.Context, head *evmtypes.Head)
FetchBlocksAndRecalculate fetches block history leading up to head and recalculates gas price.
func (*BlockHistoryEstimator) GetDynamicFee ¶
func (b *BlockHistoryEstimator) GetDynamicFee(_ context.Context, maxGasPriceWei *assets.Wei) (fee DynamicFee, err error)
func (*BlockHistoryEstimator) GetLegacyGas ¶
func (*BlockHistoryEstimator) HealthReport ¶
func (b *BlockHistoryEstimator) HealthReport() map[string]error
func (*BlockHistoryEstimator) IsUsable ¶
func (b *BlockHistoryEstimator) IsUsable(tx evmtypes.Transaction, block evmtypes.Block, chainType chaintype.ChainType, minGasPrice *assets.Wei, lggr logger.Logger) bool
isUsable returns true if the tx is usable both generally and specifically for this Config.
func (*BlockHistoryEstimator) L1Oracle ¶
func (b *BlockHistoryEstimator) L1Oracle() rollups.L1Oracle
func (*BlockHistoryEstimator) Name ¶
func (b *BlockHistoryEstimator) Name() string
func (*BlockHistoryEstimator) OnNewLongestChain ¶
func (b *BlockHistoryEstimator) OnNewLongestChain(_ context.Context, head *evmtypes.Head)
OnNewLongestChain recalculates and sets global gas price if a sampled new head comes in and we are not currently fetching
func (*BlockHistoryEstimator) Recalculate ¶
func (b *BlockHistoryEstimator) Recalculate(head *evmtypes.Head)
Recalculate adds the given heads to the history and recalculates gas price.
type DynamicFee ¶
DynamicFee encompasses both FeeCap and TipCap for EIP1559 transactions
func BumpDynamicFeeOnly ¶
func BumpDynamicFeeOnly(config bumpConfig, feeCapBufferBlocks uint16, lggr logger.SugaredLogger, currentTipCap, currentBaseFee *assets.Wei, originalFee DynamicFee, maxGasPriceWei *assets.Wei) (bumped DynamicFee, err error)
BumpDynamicFeeOnly bumps the tip cap and max gas price if necessary
type EvmEstimator ¶
type EvmEstimator interface {
heads.Trackable[*evmtypes.Head, common.Hash]
services.Service
// GetLegacyGas Calculates initial gas fee for non-EIP1559 transaction
// maxGasPriceWei parameter is the highest possible gas fee cap that the function will return
GetLegacyGas(ctx context.Context, calldata []byte, gasLimit uint64, maxGasPriceWei *assets.Wei, opts ...fees.Opt) (gasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)
// BumpLegacyGas Increases gas price and/or limit for non-EIP1559 transactions
// if the bumped gas fee is greater than maxGasPriceWei, the method returns an error
// attempts must:
// - be sorted in order from highest price to lowest price
// - all be of transaction type 0x0 or 0x1
BumpLegacyGas(ctx context.Context, originalGasPrice *assets.Wei, gasLimit uint64, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumpedGasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)
// GetDynamicFee Calculates initial gas fee for gas for EIP1559 transactions
// maxGasPriceWei parameter is the highest possible gas fee cap that the function will return
GetDynamicFee(ctx context.Context, maxGasPriceWei *assets.Wei) (fee DynamicFee, err error)
// BumpDynamicFee Increases gas price and/or limit for non-EIP1559 transactions
// if the bumped gas fee or tip caps are greater than maxGasPriceWei, the method returns an error
// attempts must:
// - be sorted in order from highest price to lowest price
// - all be of transaction type 0x2
BumpDynamicFee(ctx context.Context, original DynamicFee, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumped DynamicFee, err error)
L1Oracle() rollups.L1Oracle
}
Estimator provides an interface for estimating gas price and limit
func NewArbitrumEstimator ¶
func NewArbitrumEstimator(lggr logger.Logger, cfg ArbConfig, ethClient feeEstimatorClient, l1Oracle rollups.ArbL1GasOracle) EvmEstimator
func NewBlockHistoryEstimator ¶
func NewBlockHistoryEstimator(lggr logger.Logger, ethClient feeEstimatorClient, chaintype chaintype.ChainType, eCfg estimatorGasEstimatorConfig, bhCfg evmconfig.BlockHistory, chainID *big.Int, l1Oracle rollups.L1Oracle) EvmEstimator
NewBlockHistoryEstimator returns a new BlockHistoryEstimator that listens for new heads and updates the base gas price dynamically based on the configured percentile of gas prices in that block
func NewFixedPriceEstimator ¶
func NewFixedPriceEstimator(cfg fixedPriceEstimatorConfig, ethClient feeEstimatorClient, bhCfg fixedPriceEstimatorBlockHistoryConfig, lggr logger.Logger, l1Oracle rollups.L1Oracle) EvmEstimator
NewFixedPriceEstimator returns a new "FixedPrice" estimator which will always use the config default values for gas prices and limits
func NewSuggestedPriceEstimator ¶
func NewSuggestedPriceEstimator(lggr logger.Logger, client feeEstimatorClient, cfg suggestedPriceConfig, l1Oracle rollups.L1Oracle) EvmEstimator
NewSuggestedPriceEstimator returns a new Estimator which uses the suggested gas price.
type EvmFeeEstimator ¶
type EvmFeeEstimator interface {
services.Service
heads.Trackable[*evmtypes.Head, common.Hash]
// L1Oracle returns the L1 gas price oracle only if the chain has one, e.g. OP stack L2s and Arbitrum.
L1Oracle() rollups.L1Oracle
GetFee(ctx context.Context, calldata []byte, feeLimit uint64, maxFeePrice *assets.Wei, fromAddress, toAddress *common.Address, opts ...fees.Opt) (fee EvmFee, estimatedFeeLimit uint64, err error)
BumpFee(ctx context.Context, originalFee EvmFee, feeLimit uint64, maxFeePrice *assets.Wei, attempts []EvmPriorAttempt) (bumpedFee EvmFee, chainSpecificFeeLimit uint64, err error)
// GetMaxCost returns the total value = max price x fee units + transferred value
GetMaxCost(ctx context.Context, amount assets.Eth, calldata []byte, feeLimit uint64, maxFeePrice *assets.Wei, fromAddress, toAddress *common.Address, opts ...fees.Opt) (*big.Int, error)
}
EvmFeeEstimator provides a unified interface that wraps EvmEstimator and can determine if legacy or dynamic fee estimation should be used
func NewEstimator ¶
func NewEstimator(lggr logger.Logger, ethClient feeEstimatorClient, chaintype chaintype.ChainType, chainID *big.Int, geCfg evmconfig.GasEstimator, clientsByChainID map[string]rollups.DAClient) (EvmFeeEstimator, error)
NewEstimator returns the estimator for a given config
func NewEvmFeeEstimator ¶
func NewEvmFeeEstimator(lggr logger.Logger, newEstimator func(logger.Logger) EvmEstimator, eip1559Enabled bool, geCfg GasEstimatorConfig, ethClient feeEstimatorClient) EvmFeeEstimator
type EvmPriorAttempt ¶
type FeeHistoryEstimator ¶
type FeeHistoryEstimator struct {
services.StateMachine
// contains filtered or unexported fields
}
func NewFeeHistoryEstimator ¶
func NewFeeHistoryEstimator(lggr logger.Logger, client feeHistoryEstimatorClient, cfg FeeHistoryEstimatorConfig, chainID *big.Int, l1Oracle rollups.L1Oracle) *FeeHistoryEstimator
func (*FeeHistoryEstimator) BumpDynamicFee ¶
func (f *FeeHistoryEstimator) BumpDynamicFee(ctx context.Context, originalFee DynamicFee, maxPrice *assets.Wei, _ []EvmPriorAttempt) (bumped DynamicFee, err error)
BumpDynamicFee provides a bumped dynamic fee by bumping the previous one by BumpPercent. If the original values are higher than the max price it returns an error as there is no room for bumping. If maxPriorityFeePerGas is bumped above the priority fee threshold then there is a good chance there is a connectivity issue and we shouldn't bump. Both maxFeePerGas as well as maxPriorityFeePerGas need to be bumped otherwise the RPC won't accept the transaction and throw an error. See: https://github.com/ethereum/go-ethereum/issues/24284 It aggregates the market, bumped, and max price to provide a correct value, for both maxFeePerGas as well as maxPriorityFerPergas.
func (*FeeHistoryEstimator) BumpLegacyGas ¶
func (f *FeeHistoryEstimator) BumpLegacyGas(ctx context.Context, originalGasPrice *assets.Wei, gasLimit uint64, maxPrice *assets.Wei, _ []EvmPriorAttempt) (*assets.Wei, uint64, error)
BumpLegacyGas provides a bumped gas price value by bumping the previous one by BumpPercent. If the original value is higher than the max price it returns an error as there is no room for bumping. It aggregates the market, bumped, and max gas price to provide a correct value.
func (*FeeHistoryEstimator) Close ¶
func (f *FeeHistoryEstimator) Close() error
func (*FeeHistoryEstimator) GetDynamicFee ¶
func (f *FeeHistoryEstimator) GetDynamicFee(ctx context.Context, maxPrice *assets.Wei) (fee DynamicFee, err error)
GetDynamicFee will fetch the cached dynamic prices.
func (*FeeHistoryEstimator) GetLegacyGas ¶
func (f *FeeHistoryEstimator) GetLegacyGas(ctx context.Context, _ []byte, gasLimit uint64, maxPrice *assets.Wei, opts ...fees.Opt) (gasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)
GetLegacyGas will fetch the cached gas price value.
func (*FeeHistoryEstimator) HealthReport ¶
func (f *FeeHistoryEstimator) HealthReport() map[string]error
func (*FeeHistoryEstimator) L1Oracle ¶
func (f *FeeHistoryEstimator) L1Oracle() rollups.L1Oracle
func (*FeeHistoryEstimator) Name ¶
func (f *FeeHistoryEstimator) Name() string
func (*FeeHistoryEstimator) OnNewLongestChain ¶
func (f *FeeHistoryEstimator) OnNewLongestChain(context.Context, *evmtypes.Head)
func (*FeeHistoryEstimator) RefreshDynamicPrice ¶
func (f *FeeHistoryEstimator) RefreshDynamicPrice() error
RefreshDynamicPrice uses eth_feeHistory to fetch the baseFee of the next block and the Nth maxPriorityFeePerGas percentiles of the past X blocks. It also fetches the highest 85th maxPriorityFeePerGas percentile of the past X blocks, which represents the highest percentile we're willing to pay. A buffer is added on top of the latest baseFee to catch fluctuations in the next blocks. On Ethereum the increase is baseFee * 1.125 per block, however in some chains that may vary.
func (*FeeHistoryEstimator) RefreshGasPrice ¶
func (f *FeeHistoryEstimator) RefreshGasPrice() (*assets.Wei, error)
RefreshGasPrice will use eth_gasPrice to fetch and cache the latest gas price from the RPC.
type GasEstimatorConfig ¶
type GasEstimatorConfig interface {
EIP1559DynamicFees() bool
BumpPercent() uint16
BumpThreshold() uint64
BumpMin() *assets.Wei
FeeCapDefault() *assets.Wei
LimitMax() uint64
LimitMultiplier() float32
PriceDefault() *assets.Wei
TipCapDefault() *assets.Wei
TipCapMin() *assets.Wei
PriceMin() *assets.Wei
PriceMax() *assets.Wei
Mode() string
EstimateLimit() bool
SenderAddress() *evmtypes.EIP55Address
}
type SuggestedPriceEstimator ¶
type SuggestedPriceEstimator struct {
services.StateMachine
GasPrice *assets.Wei
// contains filtered or unexported fields
}
SuggestedPriceEstimator is an Estimator which uses the suggested gas price from eth_gasPrice.
func (*SuggestedPriceEstimator) BumpDynamicFee ¶
func (*SuggestedPriceEstimator) BumpDynamicFee(_ context.Context, _ DynamicFee, _ *assets.Wei, _ []EvmPriorAttempt) (bumped DynamicFee, err error)
func (*SuggestedPriceEstimator) BumpLegacyGas ¶
func (o *SuggestedPriceEstimator) BumpLegacyGas(ctx context.Context, originalFee *assets.Wei, feeLimit uint64, maxGasPriceWei *assets.Wei, _ []EvmPriorAttempt) (newGasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)
Refreshes the gas price by making a call to the RPC in case the current one has gone stale. Adds the larger of BumpPercent and BumpMin configs as a buffer on top of the price returned from the RPC. The only reason bumping logic would be called on the SuggestedPriceEstimator is if there was a significant price spike between the last price update and when the tx was submitted. Refreshing the price helps ensure the latest market changes are accounted for.
func (*SuggestedPriceEstimator) Close ¶
func (o *SuggestedPriceEstimator) Close() error
func (*SuggestedPriceEstimator) GetDynamicFee ¶
func (*SuggestedPriceEstimator) GetDynamicFee(_ context.Context, _ *assets.Wei) (fee DynamicFee, err error)
func (*SuggestedPriceEstimator) GetLegacyGas ¶
func (*SuggestedPriceEstimator) HealthReport ¶
func (o *SuggestedPriceEstimator) HealthReport() map[string]error
func (*SuggestedPriceEstimator) L1Oracle ¶
func (o *SuggestedPriceEstimator) L1Oracle() rollups.L1Oracle
func (*SuggestedPriceEstimator) Name ¶
func (o *SuggestedPriceEstimator) Name() string
func (*SuggestedPriceEstimator) OnNewLongestChain ¶
func (o *SuggestedPriceEstimator) OnNewLongestChain(context.Context, *types.Head)