UNPKG

@owlprotocol/contracts-account-abstraction

Version:

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

78 lines (77 loc) 3.47 kB
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 getPaymasterData_exports = {}; __export(getPaymasterData_exports, { getPaymasterData: () => getPaymasterData }); module.exports = __toCommonJS(getPaymasterData_exports); var import_viem = require("viem"); var import_utils = require("viem/utils"); var import_actions = require("viem/actions"); var import_PackedUserOperation = require("../../models/PackedUserOperation.js"); var import_UserOperation = require("../../models/UserOperation.js"); var import_getSupportedEntryPoints = require("../bundler/getSupportedEntryPoints.js"); var import_VerifyingPaymaster = require("../../VerifyingPaymaster.js"); async function getPaymasterData(client, parameters) { const { entryPointAddress, ...userOperation } = parameters; const { paymaster } = client; const chainId = client.chain?.id ?? await (0, import_utils.getAction)(client, import_actions.getChainId, "getChainId")({}); const supportedEntryPoints = await (0, import_utils.getAction)( client, import_getSupportedEntryPoints.getSupportedEntryPoints, "getSupportedEntryPoints" )({}); if (!supportedEntryPoints.includes(entryPointAddress)) { throw new Error(`Unsupported entrypoint ${entryPointAddress}, expected one of ${supportedEntryPoints}`); } const validUntil = Date.now() + 3600; const validAfter = 0; const paymasterDataUnsigned = (0, import_utils.encodeAbiParameters)( [ { name: "validUntil", type: "uint48" }, { name: "validAfter", type: "uint48" } ], [validUntil, validAfter] ); const userOpPaymasterPacked = (0, import_PackedUserOperation.toPackedUserOperation)( (0, import_UserOperation.encodeUserOp)({ ...userOperation, preVerificationGas: userOperation.preVerificationGas ?? 0n, verificationGasLimit: userOperation.verificationGasLimit ?? 0n, callGasLimit: userOperation.callGasLimit ?? 0n, maxFeePerGas: userOperation.maxFeePerGas ?? 0n, maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas ?? 0n, signature: import_UserOperation.dummySignature, paymaster, paymasterData: (0, import_viem.concatHex)([paymasterDataUnsigned, import_UserOperation.dummySignature]) }) ); const userOpPaymasterHash = (0, import_VerifyingPaymaster.getVerifyingPaymasterHash)({ chainId, userOperation: userOpPaymasterPacked }); const paymasterSignature = await client.account.signMessage({ message: { raw: userOpPaymasterHash } }); const paymasterDataSigned = (0, import_viem.concatHex)([paymasterDataUnsigned, paymasterSignature]); return { paymaster, paymasterData: paymasterDataSigned, paymasterVerificationGasLimit: 100000n, paymasterPostOpGasLimit: 100000n }; }