Skip to content

Commit

Permalink
Merge pull request #170 from zerodevapp/feat/gas-fees-sponsorUserOper…
Browse files Browse the repository at this point in the history
…ation

feat: include maxFeePerGas and maxPriorityFeePerGas as part of sponsorUserOperation action response
  • Loading branch information
plusminushalf authored Apr 17, 2024
2 parents 4ade690 + ace8a11 commit 698d42c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-drinks-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"permissionless": patch
---

Changed sponsorUserOperation action return type to include maxFeePerGas and maxPriorityFeePerGas if returned by paymaster and return it as part of userOperation from prepareUserOperationRequest action
2 changes: 2 additions & 0 deletions packages/permissionless/actions/smartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type Middleware,
type PrepareUserOperationRequestParameters,
type PrepareUserOperationRequestReturnType,
type SponsorUserOperationReturnType,
prepareUserOperationRequest
} from "./smartAccount/prepareUserOperationRequest"

Expand Down Expand Up @@ -40,6 +41,7 @@ export {
prepareUserOperationRequest,
type PrepareUserOperationRequestParameters,
type PrepareUserOperationRequestReturnType,
type SponsorUserOperationReturnType,
sendTransaction,
sendUserOperation,
type SendUserOperationParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Chain, Client, Transport } from "viem"
import { estimateFeesPerGas } from "viem/actions"
import { getAction } from "viem/utils"
import type { SmartAccount } from "../../accounts/types"
import type { PartialPick } from "../../types"
import type {
GetAccountParameter,
PartialBy,
Expand All @@ -19,6 +20,38 @@ import { AccountOrClientNotFoundError, parseAccount } from "../../utils/"
import { getEntryPointVersion } from "../../utils/getEntryPointVersion"
import { estimateUserOperationGas } from "../bundler/estimateUserOperationGas"

export type SponsorUserOperationReturnType<entryPoint extends EntryPoint> =
entryPoint extends ENTRYPOINT_ADDRESS_V06_TYPE
? Prettify<
Pick<
UserOperation<"v0.6">,
| "callGasLimit"
| "verificationGasLimit"
| "preVerificationGas"
| "paymasterAndData"
> &
PartialPick<
UserOperation<"v0.6">,
"maxFeePerGas" | "maxPriorityFeePerGas"
>
>
: Prettify<
Pick<
UserOperation<"v0.7">,
| "callGasLimit"
| "verificationGasLimit"
| "preVerificationGas"
| "paymaster"
| "paymasterVerificationGasLimit"
| "paymasterPostOpGasLimit"
| "paymasterData"
> &
PartialPick<
UserOperation<"v0.7">,
"maxFeePerGas" | "maxPriorityFeePerGas"
>
>

export type Middleware<entryPoint extends EntryPoint> = {
middleware?:
| ((args: {
Expand All @@ -33,26 +66,7 @@ export type Middleware<entryPoint extends EntryPoint> = {
sponsorUserOperation?: (args: {
userOperation: UserOperation<GetEntryPointVersion<entryPoint>>
entryPoint: entryPoint
}) => Promise<
entryPoint extends ENTRYPOINT_ADDRESS_V06_TYPE
? Pick<
UserOperation<"v0.6">,
| "callGasLimit"
| "verificationGasLimit"
| "preVerificationGas"
| "paymasterAndData"
>
: Pick<
UserOperation<"v0.7">,
| "callGasLimit"
| "verificationGasLimit"
| "preVerificationGas"
| "paymaster"
| "paymasterVerificationGasLimit"
| "paymasterPostOpGasLimit"
| "paymasterData"
>
>
}) => Promise<SponsorUserOperationReturnType<entryPoint>>
}
}

Expand Down Expand Up @@ -188,13 +202,7 @@ async function prepareUserOperationRequestForEntryPointV06<
userOperation: UserOperation<GetEntryPointVersion<entryPoint>>
entryPoint: entryPoint
}
)) as Pick<
UserOperation<"v0.6">,
| "callGasLimit"
| "verificationGasLimit"
| "preVerificationGas"
| "paymasterAndData"
>
)) as SponsorUserOperationReturnType<ENTRYPOINT_ADDRESS_V06_TYPE>

userOperation.callGasLimit = sponsorUserOperationData.callGasLimit
userOperation.verificationGasLimit =
Expand All @@ -203,6 +211,11 @@ async function prepareUserOperationRequestForEntryPointV06<
sponsorUserOperationData.preVerificationGas
userOperation.paymasterAndData =
sponsorUserOperationData.paymasterAndData
userOperation.maxFeePerGas =
sponsorUserOperationData.maxFeePerGas || userOperation.maxFeePerGas
userOperation.maxPriorityFeePerGas =
sponsorUserOperationData.maxPriorityFeePerGas ||
userOperation.maxPriorityFeePerGas
return userOperation as PrepareUserOperationRequestReturnType<entryPoint>
}

Expand Down Expand Up @@ -338,16 +351,8 @@ async function prepareUserOperationRequestEntryPointV07<
userOperation: UserOperation<GetEntryPointVersion<entryPoint>>
entryPoint: entryPoint
}
)) as Pick<
UserOperation<"v0.7">,
| "callGasLimit"
| "verificationGasLimit"
| "preVerificationGas"
| "paymaster"
| "paymasterVerificationGasLimit"
| "paymasterPostOpGasLimit"
| "paymasterData"
>
)) as SponsorUserOperationReturnType<ENTRYPOINT_ADDRESS_V07_TYPE>

userOperation.callGasLimit = sponsorUserOperationData.callGasLimit
userOperation.verificationGasLimit =
sponsorUserOperationData.verificationGasLimit
Expand All @@ -359,6 +364,11 @@ async function prepareUserOperationRequestEntryPointV07<
userOperation.paymasterPostOpGasLimit =
sponsorUserOperationData.paymasterPostOpGasLimit
userOperation.paymasterData = sponsorUserOperationData.paymasterData
userOperation.maxFeePerGas =
sponsorUserOperationData.maxFeePerGas || userOperation.maxFeePerGas
userOperation.maxPriorityFeePerGas =
sponsorUserOperationData.maxPriorityFeePerGas ||
userOperation.maxPriorityFeePerGas

return userOperation as PrepareUserOperationRequestReturnType<entryPoint>
}
Expand Down
2 changes: 2 additions & 0 deletions packages/permissionless/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export type Prettify<T> = {

export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>

export type PartialPick<T, K extends keyof T> = Partial<Pick<T, K>>

// biome-ignore lint/suspicious/noExplicitAny: generic type
export type UnionOmit<T, K extends keyof any> = T extends any
? Omit<T, K>
Expand Down

0 comments on commit 698d42c

Please sign in to comment.