Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Commit 75aefbe

Browse files
authored
SimpleAccount Preset: accept PM gas values rather then own estimates (#11)
1 parent 3adc548 commit 75aefbe

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "userop",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "A simple JS library for building ERC-4337 UserOperations.",
55
"types": "./dist/index.d.ts",
66
"main": "./dist/index.js",

src/preset/builder/simpleAccount.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,11 @@ export class SimpleAccount extends UserOperationBuilder {
8989
),
9090
})
9191
.useMiddleware(instance.resolveAccount)
92-
.useMiddleware(getGasPrice(instance.provider))
93-
.useMiddleware(estimateUserOperationGas(instance.provider));
92+
.useMiddleware(getGasPrice(instance.provider));
9493

9594
const withPM = paymasterMiddleware
9695
? base.useMiddleware(paymasterMiddleware)
97-
: base;
96+
: base.useMiddleware(estimateUserOperationGas(instance.provider));
9897

9998
return withPM.useMiddleware(EOASignature(instance.signer));
10099
}

src/preset/middleware/paymaster.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ interface VerifyingPaymasterResult {
66
paymasterAndData: string;
77
preVerificationGas: string;
88
verificationGasLimit: string;
9+
callGasLimit: string;
910
}
1011

1112
// Assumes the paymaster interface in https://hackmd.io/@stackup/H1oIvV-qi
1213
export const verifyingPaymaster =
1314
(paymasterRpc: string, context: any): UserOperationMiddlewareFn =>
1415
async (ctx) => {
16+
ctx.op.verificationGasLimit = ethers.BigNumber.from(
17+
ctx.op.verificationGasLimit
18+
).mul(3);
19+
1520
const provider = new ethers.providers.JsonRpcProvider(paymasterRpc);
1621
const pm = (await provider.send("pm_sponsorUserOperation", [
1722
OpToJSON(ctx.op),
@@ -23,4 +28,5 @@ export const verifyingPaymaster =
2328
ctx.op.paymasterAndData = pm.paymasterAndData;
2429
ctx.op.preVerificationGas = pm.preVerificationGas;
2530
ctx.op.verificationGasLimit = pm.verificationGasLimit;
31+
ctx.op.callGasLimit = pm.callGasLimit;
2632
};

0 commit comments

Comments
 (0)