@owlprotocol/contracts-account-abstraction
Version:
ERC4337 Account Abstraction support for deploying relevant smart contracts and interacting with UserOps.
36 lines (35 loc) • 1.91 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var calcDefaultPreVerificationGas_exports = {};
__export(calcDefaultPreVerificationGas_exports, {
calcDefaultPreVerificationGas: () => calcDefaultPreVerificationGas
});
module.exports = __toCommonJS(calcDefaultPreVerificationGas_exports);
var import_viem = require("viem");
var import_GasOverheads = require("../models/GasOverheads.js");
var import_PackedUserOperation2 = require("../models/PackedUserOperation.js");
function calcDefaultPreVerificationGas(packedUserOperation, overheads) {
const ov = { ...import_GasOverheads.DefaultGasOverheads, ...overheads ?? {} };
const p = { ...packedUserOperation };
p.signature = p.signature === "0x" ? (0, import_viem.toHex)(Buffer.alloc(ov.sigSize, 1)) : p.signature;
const packed = (0, import_viem.hexToBytes)((0, import_PackedUserOperation2.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);
}