gasprice

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPercentile = errors.New("invalid percentile")
	ErrBlockCount        = errors.New("blockCount must be greater than 0")
	ErrBlockNotFound     = errors.New("could not find block")
)
View Source
var DefaultGasHelperConfig = &Config{
	NumOfBlocksToCheck: 20,
	PricePercentile:    60,
	SampleNumber:       3,
	MaxPrice:           ethgo.Gwei(500),
	LastPrice:          ethgo.Gwei(1),
	IgnorePrice:        big.NewInt(2),
}

DefaultGasHelperConfig is the default config for gas helper (as per ethereum)

Functions

This section is empty.

Types

type Blockchain

type Blockchain interface {
	GetBlockByNumber(number uint64, full bool) (*types.Block, bool)
	GetBlockByHash(hash types.Hash, full bool) (*types.Block, bool)
	Header() *types.Header
	Config() *chain.Params
}

Blockchain is the interface representing blockchain

type Config

type Config struct {
	// NumOfBlocksToCheck is the number of blocks to sample
	NumOfBlocksToCheck uint64
	// PricePercentile is the sample percentile of transactions in a block
	PricePercentile uint64
	// SampleNumber is number of transactions sampled in a block
	SampleNumber uint64
	// MaxPrice is the tip max price
	MaxPrice *big.Int
	// LastPrice is the last price returned for maxPriorityFeePerGas
	// when starting node it will be some default value
	LastPrice *big.Int
	// IgnorePrice is the lowest price to take into consideration
	// when collecting transactions
	IgnorePrice *big.Int
}

Config is a struct that holds configuration of GasHelper

type FeeHistoryReturn added in v1.0.1

type FeeHistoryReturn struct {
	OldestBlock   uint64
	BaseFeePerGas []uint64
	GasUsedRatio  []float64
	Reward        [][]uint64
}

type GasHelper

type GasHelper struct {
	// contains filtered or unexported fields
}

GasHelper struct implements functions from the GasStore interface

func NewGasHelper

func NewGasHelper(config *Config, backend Blockchain) (*GasHelper, error)

NewGasHelper is the constructor function for GasHelper struct

func (*GasHelper) FeeHistory added in v1.0.1

func (g *GasHelper) FeeHistory(blockCount uint64, newestBlock uint64, rewardPercentiles []float64) (
	*FeeHistoryReturn, error)

func (*GasHelper) MaxPriorityFeePerGas

func (g *GasHelper) MaxPriorityFeePerGas() (*big.Int, error)

MaxPriorityFeePerGas calculates the priority fee needed for transaction to be included in a block The function does following:

  • takes chain header
  • iterates for numOfBlocksToCheck from chain header to previous blocks
  • collects at most the sample number of sorted transactions in block
  • if not enough transactions were collected and their tips, go through some more blocks to get more accurate calculation
  • when enough transactions and their tips are collected, take the one that is in pricePercentile
  • if given price is larger then maxPrice then return the maxPrice

type GasStore

type GasStore interface {
	// MaxPriorityFeePerGas calculates the priority fee needed for transaction to be included in a block
	MaxPriorityFeePerGas() (*big.Int, error)
	// FeeHistory returns the collection of historical gas information
	FeeHistory(uint64, uint64, []float64) (*FeeHistoryReturn, error)
}

GasStore interface is providing functions regarding gas and fees

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL