Skip to content

Commit

Permalink
feat(paymaster): allow second execution of service
Browse files Browse the repository at this point in the history
  • Loading branch information
tuler committed Jul 30, 2024
1 parent 3c48bbe commit 7755228
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
13 changes: 13 additions & 0 deletions packages/mock-verifying-paymaster/src/helpers/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ export const VERIFYING_PAYMASTER_V07_ABI = [
],
stateMutability: "nonpayable",
},
{
inputs: [],
name: "getDeposit",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
stateMutability: "view",
type: "function",
},
{
type: "function",
name: "getHash",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,38 @@ export const setupVerifyingPaymasterV07 = async (
chain: await getChain(),
});

await walletClient
.sendTransaction({
to: DETERMINISTIC_DEPLOYER,
data,
})
.then((hash) => publicClient.waitForTransactionReceipt({ hash }))
.then(() => console.log("deployed VerifyingPaymaster v0.7"));

const address = getContractAddress({
opcode: "CREATE2",
from: DETERMINISTIC_DEPLOYER,
salt: slice(data, 0, 32),
bytecode: slice(data, 32),
});

if ((await publicClient.getCode({ address })) === undefined) {
await walletClient
.sendTransaction({
to: DETERMINISTIC_DEPLOYER,
data,
})
.then((hash) => publicClient.waitForTransactionReceipt({ hash }))
.then(() => console.log("deployed VerifyingPaymaster v0.7"));
}

const verifyingPaymaster = getContract({
address,
abi: VERIFYING_PAYMASTER_V07_ABI,
client: walletClient,
});

await verifyingPaymaster.write
.deposit({
value: parseEther("50"),
})
.then(() => console.log("Funded VerifyingPaymaster V0.7"));
const requiredDeposit = parseEther("50");
const currentDeposit = await verifyingPaymaster.read.getDeposit();
if (currentDeposit < requiredDeposit) {
await verifyingPaymaster.write
.deposit({
value: requiredDeposit - currentDeposit,
})
.then(() => console.log("Funded VerifyingPaymaster V0.7"));
}

return verifyingPaymaster;
};
Expand All @@ -87,32 +93,38 @@ export const setupVerifyingPaymasterV06 = async (
chain: await getChain(),
});

await walletClient
.sendTransaction({
to: DETERMINISTIC_DEPLOYER,
data,
})
.then((hash) => publicClient.waitForTransactionReceipt({ hash }))
.then(() => console.log("deployed VerifyingPaymaster v0.6"));

const address = getContractAddress({
opcode: "CREATE2",
from: DETERMINISTIC_DEPLOYER,
salt: slice(data, 0, 32),
bytecode: slice(data, 32),
});

if ((await publicClient.getCode({ address })) === undefined) {
await walletClient
.sendTransaction({
to: DETERMINISTIC_DEPLOYER,
data,
})
.then((hash) => publicClient.waitForTransactionReceipt({ hash }))
.then(() => console.log("deployed VerifyingPaymaster v0.6"));
}

const verifyingPaymaster = getContract({
address,
abi: VERIFYING_PAYMASTER_V06_ABI,
client: walletClient,
});

await verifyingPaymaster.write
.deposit({
value: parseEther("50"),
})
.then(() => console.log("Funded VerifyingPaymaster V0.6"));
const requiredDeposit = parseEther("50");
const currentDeposit = await verifyingPaymaster.read.getDeposit();
if (currentDeposit < requiredDeposit) {
await verifyingPaymaster.write
.deposit({
value: requiredDeposit - currentDeposit,
})
.then(() => console.log("Funded VerifyingPaymaster V0.6"));
}

return verifyingPaymaster;
};
3 changes: 2 additions & 1 deletion packages/mock-verifying-paymaster/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ const main = async () => {
return reply.code(200).send({ message: "pong" });
});

await app.listen({ host: "0.0.0.0", port: 3000 });
const service = await app.listen({ host: "0.0.0.0", port: 3000 });
console.log(`Service ready: ${service}`);
};

main();

0 comments on commit 7755228

Please sign in to comment.