gasestimate

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: LGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxGasLimit   = uint64(6400000)
	MaxBinarySearchDepth = 10000
)
View Source
const (
	SafeBufferLimit     = 0.1
	SimulateTxnAccessor = "SimulateTxnAccessor"
)

Variables

View Source
var (
	ErrEstimateTransactionLimitFailed = errors.New("failed to estimate safe transaction gas")
)
View Source
var (
	ErrInvalidChainID = errors.New("invalid chainID")
)

Functions

func EstimateSafeTransactionGasLimit

func EstimateSafeTransactionGasLimit(
	ctx context.Context,
	client EstimateSafeTransactionClient,
	request EstimateSafeTransactionGasRequest,
) (uint64, error)

EstimateSafeTransactionGasLimit estimates the gas limit for a safe transaction. It uses a binary search algorithm to find the optimal gas limit for the transaction. And finds the optimal gas at which the transaction succeeds by checking the return of the eth_call if encoded callData is execTransactionFromModule or execTransaction and call is successful safe returns (true) boolean as return https://github.com/safe-global/safe-contracts/blob/1cfa95710057e33832600e6b9ad5ececca8f7839/contracts/SafeL2.sol#L12-L13

Types

type EstimateSafeTransactionClient

type EstimateSafeTransactionClient interface {
	EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
	CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
}

type EstimateSafeTransactionGasRequest

type EstimateSafeTransactionGasRequest struct {
	From        common.Address
	To          common.Address
	CallData    []byte
	Value       *big.Int
	MaxGasLimit uint64
}

type Estimation

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

func NewGasEstimation

func NewGasEstimation(
	clientFactory gasEstimatorFactory,
	addRegistry types.AddressRegistry,
	safeAbi *abi.ABI,
	accessorAbi *abi.ABI,
	clientURLs map[int64]string,
	logger logger.Logger,
) *Estimation

func (*Estimation) EstimateSafeGas

func (g *Estimation) EstimateSafeGas(ctx context.Context, safeTxn *types.SafeTx) (uint64, error)

EstimateSafeGas this estimates the max gas limit that should be given in form of safeTxGas it selects the appropriate function according to the safe version

func (*Estimation) EstimateSafeGasv1_3_0

func (g *Estimation) EstimateSafeGasv1_3_0(ctx context.Context, safeTxn *types.SafeTx) (uint64, error)

EstimateSafeGasv1_3_0 this estimates the max gas limit that should be given in form of safeTxGas and is compatible with safe version 1.3.0 see https://github.com/safe-global/safe-core-sdk/blob/7959821ab08c96cf3babb9ed906c01d644ac49f4/packages/protocol-kit/src/utils/transactions/gas.ts#L17

func (*Estimation) EstimateSafeGasv1_4_0

func (g *Estimation) EstimateSafeGasv1_4_0(_ context.Context, safeTxn *types.SafeTx) (uint64, error)

EstimateSafeGasv1_4_0 this estimates the max gas limit that should be given in form of safeTxGas and is compatible with safe version 1.4.0

Jump to

Keyboard shortcuts

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