Documentation ¶
Index ¶
- Constants
- Variables
- func BumpLegacyGasPriceOnly(cfg bumpConfig, lggr logger.SugaredLogger, ...) (gasPrice *assets.Wei, chainSpecificGasLimit uint32, err error)
- func HexToInt64(input interface{}) int64
- func Int64ToHex(n int64) string
- type ArbConfig
- type BlockHistoryConfig
- type BlockHistoryEstimator
- func (b *BlockHistoryEstimator) BumpDynamicFee(_ context.Context, originalFee DynamicFee, originalGasLimit uint32, ...) (bumped DynamicFee, chainSpecificGasLimit uint32, err error)
- func (b *BlockHistoryEstimator) BumpLegacyGas(_ context.Context, originalGasPrice *assets.Wei, gasLimit uint32, ...) (bumpedGasPrice *assets.Wei, chainSpecificGasLimit uint32, 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, gasLimit uint32, maxGasPriceWei *assets.Wei) (fee DynamicFee, chainSpecificGasLimit uint32, err error)
- func (b *BlockHistoryEstimator) GetLegacyGas(_ context.Context, _ []byte, gasLimit uint32, maxGasPriceWei *assets.Wei, ...) (gasPrice *assets.Wei, chainSpecificGasLimit uint32, err error)
- func (b *BlockHistoryEstimator) HealthReport() map[string]error
- func (b *BlockHistoryEstimator) IsUsable(tx evmtypes.Transaction, block evmtypes.Block, chainType config.ChainType, ...) bool
- 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 Config
- type DynamicFee
- type EvmEstimator
- func NewArbitrumEstimator(lggr logger.Logger, cfg ArbConfig, rpcClient rpcClient, ethClient ethClient) EvmEstimator
- func NewBlockHistoryEstimator(lggr logger.Logger, ethClient evmclient.Client, cfg chainConfig, ...) EvmEstimator
- func NewFixedPriceEstimator(cfg fixedPriceEstimatorConfig, bhCfg fixedPriceEstimatorBlockHistoryConfig, ...) EvmEstimator
- func NewSuggestedPriceEstimator(lggr logger.Logger, client rpcClient) EvmEstimator
- type EvmFee
- type EvmFeeEstimator
- type EvmPriorAttempt
- type GasEstimatorConfig
- type SuggestedPriceEstimator
- func (*SuggestedPriceEstimator) BumpDynamicFee(_ context.Context, _ DynamicFee, _ uint32, _ *assets.Wei, _ []EvmPriorAttempt) (bumped DynamicFee, chainSpecificGasLimit uint32, err error)
- func (o *SuggestedPriceEstimator) BumpLegacyGas(_ context.Context, _ *assets.Wei, _ uint32, _ *assets.Wei, _ []EvmPriorAttempt) (bumpedGasPrice *assets.Wei, chainSpecificGasLimit uint32, err error)
- func (o *SuggestedPriceEstimator) Close() error
- func (*SuggestedPriceEstimator) GetDynamicFee(_ context.Context, _ uint32, _ *assets.Wei) (fee DynamicFee, chainSpecificGasLimit uint32, err error)
- func (o *SuggestedPriceEstimator) GetLegacyGas(ctx context.Context, _ []byte, GasLimit uint32, maxGasPriceWei *assets.Wei, ...) (gasPrice *assets.Wei, chainSpecificGasLimit uint32, err error)
- func (o *SuggestedPriceEstimator) HealthReport() map[string]error
- func (o *SuggestedPriceEstimator) Name() string
- func (o *SuggestedPriceEstimator) OnNewLongestChain(context.Context, *evmtypes.Head)
- func (o *SuggestedPriceEstimator) Start(context.Context) error
- type WrappedEvmEstimator
- func (e *WrappedEvmEstimator) BumpFee(ctx context.Context, originalFee EvmFee, feeLimit uint32, ...) (bumpedFee EvmFee, chainSpecificFeeLimit uint32, err error)
- func (e *WrappedEvmEstimator) Close() error
- func (e *WrappedEvmEstimator) GetFee(ctx context.Context, calldata []byte, feeLimit uint32, maxFeePrice *assets.Wei, ...) (fee EvmFee, chainSpecificFeeLimit uint32, err error)
- func (e *WrappedEvmEstimator) GetMaxCost(ctx context.Context, amount assets.Eth, calldata []byte, feeLimit uint32, ...) (*big.Int, error)
- func (e *WrappedEvmEstimator) HealthReport() map[string]error
- func (e *WrappedEvmEstimator) L1Oracle() rollups.L1Oracle
- func (e *WrappedEvmEstimator) Name() string
- func (e *WrappedEvmEstimator) Ready() error
- func (e *WrappedEvmEstimator) Start(ctx context.Context) error
Constants ¶
const ( // ArbGasInfoAddress is the address of the "Precompiled contract that exists in every Arbitrum chain." // https://github.com/OffchainLabs/nitro/blob/f7645453cfc77bf3e3644ea1ac031eff629df325/contracts/src/precompiles/ArbGasInfo.sol ArbGasInfoAddress = "0x000000000000000000000000000000000000006C" // ArbGasInfo_getPricesInArbGas is the a hex encoded call to: // `function getPricesInArbGas() external view returns (uint256, uint256, uint256);` ArbGasInfo_getPricesInArbGas = "02199f34" )
const BumpingHaltedLabel = "" /* 230-byte string literal not displayed */
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, originalGasLimit uint32, maxGasPriceWei *assets.Wei) (gasPrice *assets.Wei, chainSpecificGasLimit uint32, err error)
BumpLegacyGasPriceOnly will increase the price and apply multiplier to the gas limit
func HexToInt64 ¶
func HexToInt64(input interface{}) int64
HexToInt64 performs the inverse of Int64ToHex Returns 0 on invalid input
func Int64ToHex ¶
Int64ToHex converts an int64 into go-ethereum's hex representation
Types ¶
type BlockHistoryConfig ¶
type BlockHistoryConfig interface { evmconfig.BlockHistory }
type BlockHistoryEstimator ¶
type BlockHistoryEstimator struct { services.StateMachine // contains filtered or unexported fields }
func (*BlockHistoryEstimator) BumpDynamicFee ¶
func (b *BlockHistoryEstimator) BumpDynamicFee(_ context.Context, originalFee DynamicFee, originalGasLimit uint32, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumped DynamicFee, chainSpecificGasLimit uint32, 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, gasLimit uint32, maxGasPriceWei *assets.Wei) (fee DynamicFee, chainSpecificGasLimit uint32, 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 config.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) 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 Config ¶
type Config interface { ChainType() config.ChainType FinalityDepth() uint32 FinalityTagEnabled() bool }
Config defines an interface for configuration in the gas package
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, originalGasLimit uint32, maxGasPriceWei *assets.Wei) (bumped DynamicFee, chainSpecificGasLimit uint32, err error)
BumpDynamicFeeOnly bumps the tip cap and max gas price if necessary
type EvmEstimator ¶
type EvmEstimator interface { commontypes.HeadTrackable[*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 uint32, maxGasPriceWei *assets.Wei, opts ...feetypes.Opt) (gasPrice *assets.Wei, chainSpecificGasLimit uint32, 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 uint32, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumpedGasPrice *assets.Wei, chainSpecificGasLimit uint32, 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, gasLimit uint32, maxGasPriceWei *assets.Wei) (fee DynamicFee, chainSpecificGasLimit uint32, 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, gasLimit uint32, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumped DynamicFee, chainSpecificGasLimit uint32, err error) }
Estimator provides an interface for estimating gas price and limit
func NewArbitrumEstimator ¶
func NewArbitrumEstimator(lggr logger.Logger, cfg ArbConfig, rpcClient rpcClient, ethClient ethClient) EvmEstimator
func NewBlockHistoryEstimator ¶
func NewBlockHistoryEstimator(lggr logger.Logger, ethClient evmclient.Client, cfg chainConfig, eCfg estimatorGasEstimatorConfig, bhCfg BlockHistoryConfig, chainID big.Int) 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, bhCfg fixedPriceEstimatorBlockHistoryConfig, lggr logger.Logger) 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 rpcClient) EvmEstimator
NewSuggestedPriceEstimator returns a new Estimator which uses the suggested gas price.
type EvmFee ¶
type EvmFee struct { // legacy fees Legacy *assets.Wei // dynamic/EIP1559 fees DynamicFeeCap *assets.Wei DynamicTipCap *assets.Wei }
func (EvmFee) ValidDynamic ¶
type EvmFeeEstimator ¶
type EvmFeeEstimator interface { services.Service commontypes.HeadTrackable[*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 uint32, maxFeePrice *assets.Wei, opts ...feetypes.Opt) (fee EvmFee, chainSpecificFeeLimit uint32, err error) BumpFee(ctx context.Context, originalFee EvmFee, feeLimit uint32, maxFeePrice *assets.Wei, attempts []EvmPriorAttempt) (bumpedFee EvmFee, chainSpecificFeeLimit uint32, err error) // GetMaxCost returns the total value = max price x fee units + transferred value GetMaxCost(ctx context.Context, amount assets.Eth, calldata []byte, feeLimit uint32, maxFeePrice *assets.Wei, opts ...feetypes.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 evmclient.Client, cfg Config, geCfg evmconfig.GasEstimator) EvmFeeEstimator
NewEstimator returns the estimator for a given config
func NewWrappedEvmEstimator ¶
func NewWrappedEvmEstimator(lggr logger.Logger, newEstimator func(logger.Logger) EvmEstimator, eip1559Enabled bool, l1Oracle rollups.L1Oracle) EvmFeeEstimator
type EvmPriorAttempt ¶
type GasEstimatorConfig ¶
type GasEstimatorConfig interface { EIP1559DynamicFees() bool BumpPercent() uint16 BumpThreshold() uint64 BumpMin() *assets.Wei FeeCapDefault() *assets.Wei LimitMax() uint32 LimitMultiplier() float32 PriceDefault() *assets.Wei TipCapDefault() *assets.Wei TipCapMin() *assets.Wei PriceMin() *assets.Wei PriceMax() *assets.Wei Mode() string }
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, _ uint32, _ *assets.Wei, _ []EvmPriorAttempt) (bumped DynamicFee, chainSpecificGasLimit uint32, err error)
func (*SuggestedPriceEstimator) BumpLegacyGas ¶
func (*SuggestedPriceEstimator) Close ¶
func (o *SuggestedPriceEstimator) Close() error
func (*SuggestedPriceEstimator) GetDynamicFee ¶
func (*SuggestedPriceEstimator) GetDynamicFee(_ context.Context, _ uint32, _ *assets.Wei) (fee DynamicFee, chainSpecificGasLimit uint32, err error)
func (*SuggestedPriceEstimator) GetLegacyGas ¶
func (*SuggestedPriceEstimator) HealthReport ¶
func (o *SuggestedPriceEstimator) HealthReport() map[string]error
func (*SuggestedPriceEstimator) Name ¶
func (o *SuggestedPriceEstimator) Name() string
func (*SuggestedPriceEstimator) OnNewLongestChain ¶
func (o *SuggestedPriceEstimator) OnNewLongestChain(context.Context, *evmtypes.Head)
type WrappedEvmEstimator ¶
type WrappedEvmEstimator struct { services.StateMachine EvmEstimator EIP1559Enabled bool // contains filtered or unexported fields }
WrappedEvmEstimator provides a struct that wraps the EVM specific dynamic and legacy estimators into one estimator that conforms to the generic FeeEstimator
func (*WrappedEvmEstimator) Close ¶
func (e *WrappedEvmEstimator) Close() error
func (*WrappedEvmEstimator) GetMaxCost ¶
func (*WrappedEvmEstimator) HealthReport ¶
func (e *WrappedEvmEstimator) HealthReport() map[string]error
func (*WrappedEvmEstimator) L1Oracle ¶
func (e *WrappedEvmEstimator) L1Oracle() rollups.L1Oracle
func (*WrappedEvmEstimator) Name ¶
func (e *WrappedEvmEstimator) Name() string
func (*WrappedEvmEstimator) Ready ¶
func (e *WrappedEvmEstimator) Ready() error