UNPKG

@owlprotocol/contracts-account-abstraction

Version:

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

57 lines (56 loc) 2.74 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 sendUserOperation_exports = {}; __export(sendUserOperation_exports, { sendUserOperation: () => sendUserOperation }); module.exports = __toCommonJS(sendUserOperation_exports); var import_utils = require("viem/utils"); var import_actions = require("viem/actions"); var import_account_abstraction = require("viem/account-abstraction"); var import_getSupportedEntryPoints = require("./getSupportedEntryPoints.js"); var import_IEntryPoint = require("../../artifacts/IEntryPoint.js"); var import_PackedUserOperation = require("../../models/PackedUserOperation.js"); var import_UserOperation = require("../../models/UserOperation.js"); async function sendUserOperation(client, parameters) { 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")({}); const entryPointAddress = supportedEntryPoints[0]; const userOperation = parameters; const userOpPacked = (0, import_PackedUserOperation.toPackedUserOperation)((0, import_UserOperation.encodeUserOp)(userOperation)); const handleOpsArgs = [[userOpPacked], client.account.address]; const { request } = await (0, import_utils.getAction)( client, import_actions.simulateContract, "simulateContract" )({ account: client.account, address: entryPointAddress, abi: [import_IEntryPoint.handleOps, ...import_IEntryPoint.errors], functionName: "handleOps", args: handleOpsArgs }); (0, import_utils.getAction)(client, import_actions.writeContract, "writeContract")({ ...request, abi: [import_IEntryPoint.handleOps, ...import_IEntryPoint.errors] }); const userOpHash = (0, import_account_abstraction.getUserOperationHash)({ userOperation, entryPointAddress, entryPointVersion: "0.7", chainId }); return userOpHash; }