Files
wax/packages/plugins/test/e2e/utils/sendUserOpAndWait.ts
2024-03-28 12:43:23 +00:00

37 lines
860 B
TypeScript

import { UserOperation } from "./userOpUtils";
import { ethers } from "ethers";
import sleep from "./sleep";
export default async function sendUserOpAndWait(
userOp: UserOperation,
entryPoint: string,
bundlerProvider: ethers.JsonRpcProvider,
pollingDelay = 100,
maxAttempts = 200,
) {
const userOpHash = (await bundlerProvider.send("eth_sendUserOperation", [
userOp,
entryPoint,
])) as string;
let receipt: { success: boolean } | null = null;
let attempts = 0;
while (attempts < maxAttempts && receipt === null) {
await sleep(pollingDelay);
receipt = (await bundlerProvider.send("eth_getUserOperationReceipt", [
userOpHash,
])) as { success: boolean } | null;
attempts++;
}
if (receipt === null) {
throw new Error(`Could not get receipt after ${maxAttempts} attempts`);
}
return receipt;
}