gas

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2023 License: GPL-3.0 Imports: 16 Imported by: 6

Documentation

Overview

Package gas implements helper functions for calculating gas parameters based on Ethereum protocol values.

Index

Constants

This section is empty.

Variables

View Source
var (
	// The maximum value to start a binary search from. A lower value reduces the upper limit of RPC calls to
	// the debug_traceCall method. This value is the current gas limit of a block.
	MaxGasLimit = 30000000
)

Functions

func EstimateGas added in v0.6.0

func EstimateGas(
	rpc *rpc.Client,
	from common.Address,
	op *userop.UserOperation,
	ov *Overhead,
	chainID *big.Int,
	tracer string,
) (verificationGas uint64, callGas uint64, err error)

EstimateGas uses the simulateHandleOp method on the EntryPoint to derive an estimate for verificationGasLimit and callGasLimit.

Types

type CalcPreVerificationGasFunc added in v0.6.0

type CalcPreVerificationGasFunc = func(op *userop.UserOperation, static *big.Int) (*big.Int, error)

CalcPreVerificationGasFunc defines an interface for a function to calculate PVG given a userOp and a static value. The static input is the value derived from the default overheads.

func CalcArbitrumPVGWithEthClient added in v0.6.0

func CalcArbitrumPVGWithEthClient(
	rpc *rpc.Client,
	entryPoint common.Address,
) CalcPreVerificationGasFunc

CalcArbitrumPVGWithEthClient uses Arbitrum's NodeInterface precompile to get an estimate for preVerificationGas that takes into account the L1 gas component. see https://medium.com/offchainlabs/understanding-arbitrum-2-dimensional-fees-fd1d582596c9.

type GasEstimates added in v0.2.0

type GasEstimates struct {
	PreVerificationGas *big.Int `json:"preVerificationGas"`
	VerificationGas    *big.Int `json:"verificationGas"`
	CallGasLimit       *big.Int `json:"callGasLimit"`
}

GasEstimates provides estimate values for all gas fields in a UserOperation.

type Overhead

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

Overhead provides helper methods for calculating gas limits based on pre-defined parameters.

func NewDefaultOverhead

func NewDefaultOverhead() *Overhead

NewDefaultOverhead returns an instance of Overhead using parameters defined by the Ethereum protocol.

func (*Overhead) CalcPreVerificationGas

func (ov *Overhead) CalcPreVerificationGas(op *userop.UserOperation) (*big.Int, error)

CalcPreVerificationGas returns an expected gas cost for processing a UserOperation from a batch.

func (*Overhead) NonZeroValueCall

func (ov *Overhead) NonZeroValueCall() *big.Int

NonZeroValueCall returns an expected gas cost of using the CALL opcode in the context of EIP-4337. See https://github.com/wolflo/evm-opcodes/blob/main/gas.md#aa-1-call.

func (*Overhead) SetCalcPreVerificationGasFunc added in v0.6.0

func (ov *Overhead) SetCalcPreVerificationGasFunc(fn CalcPreVerificationGasFunc)

SetCalcPreVerificationGasFunc allows a custom function to be defined that can control how it calculates PVG. This is useful for networks that have different models for gas.

Jump to

Keyboard shortcuts

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