UNPKG

@owlprotocol/contracts-account-abstraction

Version:

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

79 lines (78 loc) 3.07 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 getUserOperationReceipt_exports = {}; __export(getUserOperationReceipt_exports, { getUserOperationReceipt: () => getUserOperationReceipt }); module.exports = __toCommonJS(getUserOperationReceipt_exports); var import_account_abstraction = require("viem/account-abstraction"); var import_actions = require("viem/actions"); var import_utils = require("viem/utils"); var import_EntryPoint = require("../../artifacts/EntryPoint.js"); async function getUserOperationReceipt(client, parameters) { const { hash } = parameters; const blockNumber = await (0, import_actions.getBlockNumber)(client); const rpcMaxRange = 90000n; const fromBlock = rpcMaxRange < blockNumber ? blockNumber - rpcMaxRange : 0n; const filterResult = await (0, import_utils.getAction)( client, import_actions.getLogs, "getLogs" )({ address: import_account_abstraction.entryPoint07Address, event: import_EntryPoint.UserOperationEvent, args: { userOpHash: hash }, fromBlock, toBlock: "latest", strict: true }); const userOperationEvent = filterResult[0]; if (!userOperationEvent) throw new import_account_abstraction.UserOperationReceiptNotFoundError({ hash }); const transactionHash = userOperationEvent.transactionHash; const receipt = await (0, import_utils.getAction)(client, import_actions.getTransactionReceipt, "getTransactionReceipt")({ hash: transactionHash }); const logs = receipt.logs; let startIndex = -1; let endIndex = -1; logs.forEach((log, index) => { if (log.topics[0] === userOperationEvent.topics[0]) { if (log.topics[1] === userOperationEvent.topics[1]) { endIndex = index; } else if (endIndex === -1) { startIndex = index; } } }); if (endIndex === -1) { throw new Error("fatal: no UserOperationEvent in logs"); } const filteredLogs = logs.slice(startIndex + 1, endIndex); return { entryPoint: import_account_abstraction.entryPoint07Address, userOpHash: hash, sender: userOperationEvent.args.sender, nonce: userOperationEvent.args.nonce, actualGasUsed: userOperationEvent.args.actualGasUsed, actualGasCost: userOperationEvent.args.actualGasCost, success: userOperationEvent.args.success, receipt, logs: filteredLogs }; }