UNPKG

@owlprotocol/contracts-account-abstraction

Version:

ERC4337 Account Abstraction support for deploying relevant smart contracts and interacting with UserOps.

17 lines (16 loc) 835 B
import { hexToBytes, toHex } from "viem"; import { DefaultGasOverheads } from "../models/GasOverheads.js"; import { packUserOperation } from "../models/PackedUserOperation.js"; function calcDefaultPreVerificationGas(packedUserOperation, overheads) { const ov = { ...DefaultGasOverheads, ...overheads ?? {} }; const p = { ...packedUserOperation }; p.signature = p.signature === "0x" ? toHex(Buffer.alloc(ov.sigSize, 1)) : p.signature; const packed = hexToBytes(packUserOperation(p)); const lengthInWord = (packed.length + 31) / 32; const callDataCost = packed.map((x) => x === 0 ? ov.zeroByte : ov.nonZeroByte).reduce((sum, x) => sum + x); const ret = Math.round(callDataCost + ov.fixed / ov.bundleSize + ov.perUserOp + ov.perUserOpWord * lengthInWord); return BigInt(ret); } export { calcDefaultPreVerificationGas };