Skip to content

Commit

Permalink
Merge pull request #123 from pimlicolabs/feat/introduce-middleware
Browse files Browse the repository at this point in the history
fetch gas prices before paymaster signs the data
  • Loading branch information
plusminushalf authored Feb 25, 2024
2 parents 207c475 + 2b2c290 commit fd3411f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-knives-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"permissionless": patch
---

fix prepareUserOperationRequest for entryPoint 0.7
1 change: 0 additions & 1 deletion packages/permissionless-test/ep-0.6/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
getSenderAddress,
getUserOperationHash
} from "permissionless"
import { ENTRYPOINT_ADDRESS_V06_TYPE } from "permissionless/_types/types"
import {
getRequiredPrefund,
signUserOperationHashWithECDSA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,21 @@ async function prepareUserOperationRequestEntryPointV07<
})) as PrepareUserOperationRequestReturnType<entryPoint>
}

if (middleware && typeof middleware !== "function" && middleware.gasPrice) {
const gasPrice = await middleware.gasPrice()
userOperation.maxFeePerGas = gasPrice.maxFeePerGas
userOperation.maxPriorityFeePerGas = gasPrice.maxPriorityFeePerGas
}

if (!userOperation.maxFeePerGas || !userOperation.maxPriorityFeePerGas) {
const estimateGas = await estimateFeesPerGas(account.client)
userOperation.maxFeePerGas =
userOperation.maxFeePerGas || estimateGas.maxFeePerGas
userOperation.maxPriorityFeePerGas =
userOperation.maxPriorityFeePerGas ||
estimateGas.maxPriorityFeePerGas
}

if (
middleware &&
typeof middleware !== "function" &&
Expand Down Expand Up @@ -340,21 +355,6 @@ async function prepareUserOperationRequestEntryPointV07<
userOperation.paymasterData = sponsorUserOperationData.paymasterData
}

if (middleware && typeof middleware !== "function" && middleware.gasPrice) {
const gasPrice = await middleware.gasPrice()
userOperation.maxFeePerGas = gasPrice.maxFeePerGas
userOperation.maxPriorityFeePerGas = gasPrice.maxPriorityFeePerGas
}

if (!userOperation.maxFeePerGas || !userOperation.maxPriorityFeePerGas) {
const estimateGas = await estimateFeesPerGas(account.client)
userOperation.maxFeePerGas =
userOperation.maxFeePerGas || estimateGas.maxFeePerGas
userOperation.maxPriorityFeePerGas =
userOperation.maxPriorityFeePerGas ||
estimateGas.maxPriorityFeePerGas
}

if (
!userOperation.callGasLimit ||
!userOperation.verificationGasLimit ||
Expand Down

0 comments on commit fd3411f

Please sign in to comment.