UNPKG

@owlprotocol/contracts-account-abstraction

Version:

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

63 lines (62 loc) 1.99 kB
import { entryPoint07Address, UserOperationReceiptNotFoundError } from "viem/account-abstraction"; import { getBlockNumber, getLogs, getTransactionReceipt } from "viem/actions"; import { getAction } from "viem/utils"; import { UserOperationEvent } from "../../artifacts/EntryPoint.js"; async function getUserOperationReceipt(client, parameters) { const { hash } = parameters; const blockNumber = await getBlockNumber(client); const rpcMaxRange = 90000n; const fromBlock = rpcMaxRange < blockNumber ? blockNumber - rpcMaxRange : 0n; const filterResult = await getAction( client, getLogs, "getLogs" )({ address: entryPoint07Address, event: UserOperationEvent, args: { userOpHash: hash }, fromBlock, toBlock: "latest", strict: true }); const userOperationEvent = filterResult[0]; if (!userOperationEvent) throw new UserOperationReceiptNotFoundError({ hash }); const transactionHash = userOperationEvent.transactionHash; const receipt = await getAction(client, 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: 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 }; } export { getUserOperationReceipt };