• Calculates the required prefund amount for a user operation based on its gas parameters. The prefund amount is used to ensure the account has sufficient funds to cover the operation's gas costs. For operations using a paymaster, the gas requirements are multiplied by 3 to account for potential paymaster failures and refunds.

    Parameters

    • userOp: {
          callGasLimit: bigint;
          maxFeePerGas: bigint;
          paymasterAndData: string;
          preVerificationGas: bigint;
          verificationGasLimit: bigint;
      }

      The user operation to calculate prefund for

      • callGasLimit: bigint

        Gas limit for the main execution call

      • maxFeePerGas: bigint

        Maximum total fee per gas unit

      • paymasterAndData: string

        Paymaster contract address and data, "0x" if no paymaster is used

      • preVerificationGas: bigint

        Gas for pre-verification operations

      • verificationGasLimit: bigint

        Gas limit for the verification phase

    Returns bigint

    The required prefund amount in wei as a bigint

    const prefund = getRequiredPrefundV6({
    paymasterAndData: "0x", // No paymaster
    callGasLimit: 100000n,
    verificationGasLimit: 50000n,
    preVerificationGas: 21000n,
    maxFeePerGas: 1000000000n
    });

    const prefundWithPaymaster = getRequiredPrefundV6({
    paymasterAndData: "0x123...", // Using paymaster
    callGasLimit: 100000n,
    verificationGasLimit: 50000n,
    preVerificationGas: 21000n,
    maxFeePerGas: 1000000000n
    }); // Will be 3x higher due to paymaster multiplier