gas

package
v0.6.47 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: GPL-3.0 Imports: 20 Imported by: 1

Documentation

Overview

Package gas implements helper functions for calculating EIP-4337 gas parameters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateGas added in v0.6.0

func EstimateGas(in *EstimateInput) (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.

func CalcOptimismPVGWithEthClient added in v0.6.2

func CalcOptimismPVGWithEthClient(
	rpc *rpc.Client,
	chainID *big.Int,
	entryPoint common.Address,
) CalcPreVerificationGasFunc

CalcOptimismPVGWithEthClient uses Optimism's Gas Price Oracle precompile to get an estimate for preVerificationGas that takes into account the L1 gas component.

type EstimateInput added in v0.6.9

type EstimateInput struct {
	Rpc         *rpc.Client
	EntryPoint  common.Address
	Op          *userop.UserOperation
	Sos         state.OverrideSet
	Ov          *Overhead
	ChainID     *big.Int
	MaxGasLimit *big.Int
	Tracer      string
	// contains filtered or unexported fields
}

type GasEstimates added in v0.2.0

type GasEstimates struct {
	PreVerificationGas   *big.Int `json:"preVerificationGas"`
	VerificationGasLimit *big.Int `json:"verificationGasLimit"`
	CallGasLimit         *big.Int `json:"callGasLimit"`

	// TODO: Deprecate in v0.7
	VerificationGas *big.Int `json:"verificationGas"`
}

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) CalcCallDataCost added in v0.6.5

func (ov *Overhead) CalcCallDataCost(op *userop.UserOperation) float64

CalcCallDataCost calculates the additional gas cost required to serialize the userOp when making the transaction to submit the entire batch.

func (*Overhead) CalcPerUserOpCost added in v0.6.5

func (ov *Overhead) CalcPerUserOpCost(op *userop.UserOperation) float64

CalcPerUserOpCost calculates the gas overhead from processing a UserOperation's validation and execution phase. This overhead is not constant and is correlated to the number of 32 byte words in the UserOperation. It can be summarized in the equation perUserOpMultiplier * lenInWord + perUserOpFixed.

Note: The constant values have been derived empirically by plotting the relationship between per userOp overhead vs length in words with a sample size of 30.

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) CalcPreVerificationGasWithBuffer added in v0.6.3

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

CalcPreVerificationGasWithBuffer returns CalcPreVerificationGas increased by the set PVG buffer factor.

func (*Overhead) NonZeroValueCall

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

NonZeroValueCall returns an expected gas cost of using the CALL opcode with non-zero value. 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.

func (*Overhead) SetPreVerificationGasBufferFactor added in v0.6.3

func (ov *Overhead) SetPreVerificationGasBufferFactor(factor int64)

SetPreVerificationGasBufferFactor defines the percentage to increase the preVerificationGas by during an estimation. This is useful for rollups that use 2D gas values where the L1 gas component is non-deterministic. This buffer accounts for any variability in-between eth_estimateUserOperationGas and eth_sendUserOperation. Defaults to 0.

Jump to

Keyboard shortcuts

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