Skip to content

bcnmy/entry-point-gas-estimations

Repository files navigation

entry-point-gas-estimations

A package to estimate callGasLimit, verificationGasLimit and preVerificationGas for a given userOperation.

Installation

First, install the required packages for initializing the gas estimator client

npm i entry-point-gas-estimations
yarn add entry-point-gas-estimations

Integration

import { createGasEstimator } from "entry-point-gas-estimations";

// Creating a general gas estimator client
const gasEstimator = createGasEstimator({
  rpcUrl,
});

// L2s have a different way of calculating the preVerificationGas
// which requires creating network-specific gas estimator clients

// Optimism Stack Networks
const optimismGasEstimator = createOptimismGasEstimator({
  rpcUrl,
});

// Arbitrum Networks
const arbitrumGasEstimator = createArbitrumGasEstimator({
  rpcUrl,
});

// Mantle Networks
const mantleGasEstimator = createMantleGasEstimator({
  rpcUrl,
});

// Scroll Networks
const scrollGasEstimator = createScrollGasEstimator({
  rpcUrl,
});

// Morph Networks
const morphGasEstimator = createMorphGasEstimator({
  rpcUrl,
});

Parameters

  • rpcUrl(string, required): RPC Url of the network

returns

  • gasEstimator(Promise<GasEstimator>): gas estimator instance

Methods

This method is used to estimate gas for the userOp. It returns estimates for preVerificationGas, verificationGasLimit, and callGasLimit for a given UserOperation. It requires passing a semi-valid/ dummy signature in userOp (e.g. a signature of the correct length and format).

Usage

const estimateUserOperationGasResponse: EstimateUserOperationGas = await gasEstimator.estimateUserOperationGas({
  userOperation,
  supportsEthCallStateOverride,
  supportsEthCallByteCodeOverride,
  stateOverrideSet
  baseFeePerGas
});

Parameters

  • userOperation(UserOperation, required): userOperation to calculate gas estimates for.
  • stateOverrideSet(StateOverrideSet): optional state override set for estimating gas for a userOperation under different blockchain states.
  • supportsEthCallStateOverride (boolean): optional param, default set to true, set to false if eth_call does not support state overrides
  • supportsEthCallByteCodeOverride (boolean): optional param, default set to true, set to false if eth_call does not give correct response to bytecode overrides
  • baseFeePerGas (bigint): optional param, but required for Optimism based networks

returns

  • estimateUserOperationGasResponse(Promise<EstimateUserOperationGas>): It returns an object containing the following gas limits.

    type EstimateUserOperationGas = {
      callGasLimit: bigint;
      verificationGasLimit: bigint;
      preVerificationGas: bigint;
      validAfter: number;
      validUntil: number;
    };

This method is used to estimate the verificationGasLimit for a given userOperation.

Usage

const verificationGasLimitResponse: EstimateVerificationGasLimit =
  await gasEstimator.estimateVerificationGasLimit({
    userOperation,
    supportsEthCallStateOverride,
    supportsEthCallByteCodeOverride,
    stateOverrideSet,
  });

Parameters

  • userOperation(UserOperation, required): userOperation to calculate gas estimates for.
  • stateOverrideSet(StateOverrideSet): optional state override set for estimating gas for a userOperation under different blockchain states.
  • supportsEthCallStateOverride (boolean): optional param, default set to true, set to false if eth_call does not support state overrides
  • supportsEthCallByteCodeOverride (boolean): optional param, default set to true, set to false if eth_call does not give correct response to bytecode overrides

returns

  • verificationGasLimitResponse(Promise<EstimateVerificationGasLimit>): It returns an object containing the verificationGasLimit, validUntil and validAfter values

    type EstimateVerificationGasLimit = {
      verificationGasLimit: bigint;
      validAfter: number;
      validUntil: number;
    };

This method is used to estimate the callGasLimit for a given userOperation.

Usage

const callGasLimitResponse = await gasEstimator.estimateCallGasLimit({
  userOperation,
  supportsEthCallStateOverride,
  supportsEthCallByteCodeOverride,
  stateOverrideSet,
});

Parameters

  • userOperation(UserOperation, required): userOperation to calculate gas estimates for.
  • stateOverrideSet(StateOverrideSet): optional state override set for estimating gas for a userOperation under different blockchain states.
  • supportsEthCallStateOverride (boolean): optional param, default set to true, set to false if eth_call does not support state overrides
  • supportsEthCallByteCodeOverride (boolean): optional param, default set to true, set to false if eth_call does not give correct response to bytecode overrides

returns

  • callGasLimitResponse(Promise<EstimateCallGasLimit>): It returns an object containing the callGasLimit value

    type EstimateCallGasLimit = {
      callGasLimit: bigint;
    };

This method is used to estimate the preVerificationGas for a given userOperation. The exact implementation of this method is network dependent hence make sure to use network specefic gas estimator clients

Usage

const preVerficationGasResponse =
  await gasEstimator.calculatePreVerificationGas({
    userOperation,
    baseFeePerGas,
  });

Parameters

  • userOperation(UserOperation, required): userOperation to calculate gas estimates for.
  • baseFeePerGas (bigint): optional param, but required for Optimism based networks

returns

  • preVerificationGasResponse(Promise<CalculatePreVerificationGas>) : It returns an object containing the preVerficationGas value

    type CalculatePreVerificationGas = {
      preVerificationGas: bigint;
    };

Releases

No releases published

Packages

No packages published