Skip to content

Commit

Permalink
Merge pull request #157 from pimlicolabs/fix/prepareUserOperation
Browse files Browse the repository at this point in the history
Fix prepareUserOperation in 0.7
  • Loading branch information
plusminushalf authored Apr 5, 2024
2 parents 74a25a4 + 18c925d commit aac3585
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
1 change: 0 additions & 1 deletion packages/permissionless-test/ep-0.6/bundlerActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ describe("BUNDLER ACTIONS", () => {
to: zeroAddress,
value: 0n
})
console.log(`Transaction hash: ${response}`)
}, 100000)

test("Sending user operation", async () => {
Expand Down
7 changes: 3 additions & 4 deletions packages/permissionless-test/ep-0.7/bundlerActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe("BUNDLER ACTIONS", () => {
index: 3n
})

// const paymasterClient = getPimlicoPaymasterClient()
const paymasterClient = getPimlicoPaymasterClient()
const pimlicoBundlerClient = getPimlicoBundlerClient()

const smartAccountClient = createSmartAccountClient({
Expand All @@ -114,8 +114,8 @@ describe("BUNDLER ACTIONS", () => {
const gasPrices =
await pimlicoBundlerClient.getUserOperationGasPrice()
return gasPrices.fast
}
// sponsorUserOperation: paymasterClient.sponsorUserOperation
},
sponsorUserOperation: paymasterClient.sponsorUserOperation
}
})

Expand All @@ -128,7 +128,6 @@ describe("BUNDLER ACTIONS", () => {
to: zeroAddress,
value: 0n
})
console.log(`Transaction hash: ${response}`)
}, 100000)

test("Sending user operation", async () => {
Expand Down
33 changes: 28 additions & 5 deletions packages/permissionless-test/ep-0.7/safeSmartAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,41 @@ describe("Safe Account", () => {
}, 1000000)

test("safe Smart account client send transaction", async () => {
const bundlerClient = getBundlerClient()
const erc20PaymasterAddress =
"0x000000000041F3aFe8892B48D88b6862efe0ec8d"

const smartAccountClient = await getSmartAccountClient({
account: await getSignerToSafeSmartAccount()
account: await getSignerToSafeSmartAccount(),
middleware: {
sponsorUserOperation: async (args) => {
const gasEstimates =
await bundlerClient.estimateUserOperationGas({
userOperation: {
...args.userOperation,
paymaster: erc20PaymasterAddress
}
})

return {
...gasEstimates,
paymaster: erc20PaymasterAddress
}
}
}
})
await refillSmartAccount(
walletClient,
smartAccountClient.account.address
)
// await refillSmartAccount(
// walletClient,
// smartAccountClient.account.address
// )
const response = await smartAccountClient.sendTransaction({
to: zeroAddress,
value: 0n,
data: "0x"
})

console.log(`Transaction hash: ${response}`)

expectTypeOf(response).toBeString()
expect(response).toHaveLength(66)
expect(response).toMatch(/^0x[0-9a-fA-F]{64}$/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ async function prepareUserOperationRequestForEntryPointV06<
}

if (typeof middleware === "function") {
return (await middleware({
return middleware({
userOperation,
entryPoint: account.entryPoint
} as {
userOperation: UserOperation<GetEntryPointVersion<entryPoint>>
entryPoint: entryPoint
})) as PrepareUserOperationRequestReturnType<entryPoint>
}) as Promise<PrepareUserOperationRequestReturnType<entryPoint>>
}

if (middleware && typeof middleware !== "function" && middleware.gasPrice) {
Expand Down Expand Up @@ -201,6 +201,7 @@ async function prepareUserOperationRequestForEntryPointV06<
sponsorUserOperationData.preVerificationGas
userOperation.paymasterAndData =
sponsorUserOperationData.paymasterAndData
return userOperation as PrepareUserOperationRequestReturnType<entryPoint>
}

if (
Expand Down Expand Up @@ -291,13 +292,13 @@ async function prepareUserOperationRequestEntryPointV07<
}

if (typeof middleware === "function") {
return (await middleware({
return middleware({
userOperation,
entryPoint: account.entryPoint
} as {
userOperation: UserOperation<GetEntryPointVersion<entryPoint>>
entryPoint: entryPoint
})) as PrepareUserOperationRequestReturnType<entryPoint>
}) as Promise<PrepareUserOperationRequestReturnType<entryPoint>>
}

if (middleware && typeof middleware !== "function" && middleware.gasPrice) {
Expand Down Expand Up @@ -349,20 +350,22 @@ async function prepareUserOperationRequestEntryPointV07<
userOperation.paymasterPostOpGasLimit =
sponsorUserOperationData.paymasterPostOpGasLimit
userOperation.paymasterData = sponsorUserOperationData.paymasterData

return userOperation as PrepareUserOperationRequestReturnType<entryPoint>
}

if (
!userOperation.callGasLimit ||
!userOperation.verificationGasLimit ||
!userOperation.preVerificationGas
) {
const gasParameters = await getAction(client, estimateUserOperationGas)(
const gasParameters = await getAction(
client,
estimateUserOperationGas<ENTRYPOINT_ADDRESS_V07_TYPE>
)(
{
userOperation,
entryPoint: account.entryPoint
} as {
userOperation: UserOperation<GetEntryPointVersion<entryPoint>>
entryPoint: entryPoint
},
stateOverrides
)
Expand All @@ -373,6 +376,13 @@ async function prepareUserOperationRequestEntryPointV07<
gasParameters.verificationGasLimit
userOperation.preVerificationGas =
userOperation.preVerificationGas || gasParameters.preVerificationGas

userOperation.paymasterPostOpGasLimit =
userOperation.paymasterPostOpGasLimit ||
gasParameters.paymasterPostOpGasLimit
userOperation.paymasterPostOpGasLimit =
userOperation.paymasterPostOpGasLimit ||
gasParameters.paymasterPostOpGasLimit
}

return userOperation as PrepareUserOperationRequestReturnType<entryPoint>
Expand Down

0 comments on commit aac3585

Please sign in to comment.