Gas estimator implementation for Mantle networks. Extends EVMGasEstimator to handle Mantle's specific L1/L2 fee calculations.

const estimator = new MantleGasEstimator(rpcClient, {
[EntryPointVersion.v060]: entryPointV6,
[EntryPointVersion.v070]: entryPointV7
});

const gas = await estimator.estimatePreVerificationGas(userOperation, 1000000000n);

Hierarchy (View Summary)

Constructors

  • Creates a new EVMGasEstimator instance

    Parameters

    • chain: {
          chainId: number;
          eip1559: boolean;
          entryPoints?: {
              v060?: { address: string };
              v070?: {
                  address: string;
                  state?: { deposits: Record<string, { stateKey: string }> };
              };
          };
          isTestnet: boolean;
          name: string;
          nativeCurrency?: string;
          paymasters: {
              v060?: Record<string, { dummyPaymasterAndData: string; type: string }>;
              v070?: Record<
                  string,
                  { dummyPaymasterData: string; postOpGasLimit: bigint; type: string },
              >;
          };
          simulation?: {
              callGasLimit: bigint;
              preVerificationGas: bigint;
              verificationGasLimit: bigint;
          };
          smartAccountSupport: { nexus: boolean; smartAccountsV2: boolean };
          stack: ChainStack;
          stateOverrideSupport: {
              balance: boolean;
              bytecode: boolean;
              stateDiff: boolean;
          };
      }

      The SupportedChain to estimate gas for

    • rpcClient: GasEstimatorRpcClient

      The RPC client for making blockchain requests

    • entryPoints: EntryPoints

      Map of EntryPointVersion to their contract instances

    • simulationLimits: SimulationLimits = ...

      Optional gas limits for simulation, defaults to predefined constants

    Returns MantleGasEstimator

Properties

chain: {
    chainId: number;
    eip1559: boolean;
    entryPoints?: {
        v060?: { address: string };
        v070?: {
            address: string;
            state?: { deposits: Record<string, { stateKey: string }> };
        };
    };
    isTestnet: boolean;
    name: string;
    nativeCurrency?: string;
    paymasters: {
        v060?: Record<string, { dummyPaymasterAndData: string; type: string }>;
        v070?: Record<
            string,
            { dummyPaymasterData: string; postOpGasLimit: bigint; type: string },
        >;
    };
    simulation?: {
        callGasLimit: bigint;
        preVerificationGas: bigint;
        verificationGasLimit: bigint;
    };
    smartAccountSupport: { nexus: boolean; smartAccountsV2: boolean };
    stack: ChainStack;
    stateOverrideSupport: {
        balance: boolean;
        bytecode: boolean;
        stateDiff: boolean;
    };
}

The SupportedChain to estimate gas for

entryPoints: EntryPoints

Map of EntryPointVersion to their contract instances

The RPC client for making blockchain requests

simulationLimits: SimulationLimits = ...

Optional gas limits for simulation, defaults to predefined constants

Methods

  • Estimates the pre-verification gas for a user operation on Mantle. Includes both L2 execution gas and L1 data posting costs, adjusted by the L2 max fee.

    Parameters

    • userOperation: UserOperation

      The UserOperation to estimate gas for

    • baseFeePerGas: bigint

      Optional base fee per gas to use for estimation

    Returns Promise<bigint>

    The total pre-verification gas estimate as a bigint

    Error if the L1 fee estimation fails

    const gas = await estimator.estimatePreVerificationGas({
    sender: "0x123...",
    nonce: 1n,
    maxFeePerGas: 1000000000n,
    // ... other UserOperation fields
    });
  • Internal

    Estimates verification and call gas limits from execution results.

    Parameters

    Returns {
        callGasLimit: bigint;
        validAfter: number;
        validUntil: number;
        verificationGasLimit: bigint;
    }

    Object containing gas limits and validity window

  • Internal

    Uses binary search to estimate gas limits for deployed accounts.

    Parameters

    • userOperation: {
          callData: `0x${string}`;
          callGasLimit: bigint;
          initCode: `0x${string}`;
          maxFeePerGas: bigint;
          maxPriorityFeePerGas: bigint;
          nonce: bigint;
          paymasterAndData: `0x${string}`;
          preVerificationGas: bigint;
          sender: `0x${string}`;
          signature: `0x${string}`;
          verificationGasLimit: bigint;
      }

      The user operation to estimate for

      • callData: `0x${string}`
      • callGasLimit: bigint

        Gas limit for the main execution call

      • initCode: `0x${string}`
      • maxFeePerGas: bigint

        Maximum total fee per gas unit

      • maxPriorityFeePerGas: bigint

        Maximum priority fee per gas unit

      • nonce: bigint

        Account nonce

      • paymasterAndData: `0x${string}`
      • preVerificationGas: bigint

        Gas overhead for pre-verification operations

      • sender: `0x${string}`
      • signature: `0x${string}`
      • verificationGasLimit: bigint

        Gas limit for the verification phase

    • baseFeePerGas: bigint

      Current base fee per gas

    • options: EstimateUserOperationGasOptions

      Estimation options

    • OptionalstateOverrides: StateOverrideSet

      Optional state overrides

    Returns Promise<EstimateUserOperationGasResult>

    Gas estimation results

    Error if binary search fails