From 9fd3c046f44e5e137fb804040d270ed1ce03a27a Mon Sep 17 00:00:00 2001 From: Sahil Vasava Date: Sat, 13 Apr 2024 04:09:16 +0530 Subject: [PATCH 1/2] feat: change sponsorUserOperation return type to include gas fee values and return it as part of userOp in prepareUserOperationRequest --- .../permissionless/actions/smartAccount.ts | 2 + .../prepareUserOperationRequest.ts | 84 +++++++++++-------- packages/permissionless/types/index.ts | 2 + 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/packages/permissionless/actions/smartAccount.ts b/packages/permissionless/actions/smartAccount.ts index 85ceda03..856c15d5 100644 --- a/packages/permissionless/actions/smartAccount.ts +++ b/packages/permissionless/actions/smartAccount.ts @@ -7,6 +7,7 @@ import { type Middleware, type PrepareUserOperationRequestParameters, type PrepareUserOperationRequestReturnType, + type SponsorUserOperationReturnType, prepareUserOperationRequest } from "./smartAccount/prepareUserOperationRequest" @@ -40,6 +41,7 @@ export { prepareUserOperationRequest, type PrepareUserOperationRequestParameters, type PrepareUserOperationRequestReturnType, + type SponsorUserOperationReturnType, sendTransaction, sendUserOperation, type SendUserOperationParameters, diff --git a/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts b/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts index a370ec1c..01de621e 100644 --- a/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts +++ b/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts @@ -1,6 +1,7 @@ import type { Chain, Client, Transport } from "viem" import { estimateFeesPerGas } from "viem/actions" import type { SmartAccount } from "../../accounts/types" +import type { PartialPick } from "../../types" import type { GetAccountParameter, PartialBy, @@ -19,6 +20,38 @@ import { getAction } from "../../utils/getAction" import { getEntryPointVersion } from "../../utils/getEntryPointVersion" import { estimateUserOperationGas } from "../bundler/estimateUserOperationGas" +export type SponsorUserOperationReturnType = + 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 = { middleware?: | ((args: { @@ -33,26 +66,7 @@ export type Middleware = { sponsorUserOperation?: (args: { userOperation: UserOperation> 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> } } @@ -188,13 +202,7 @@ async function prepareUserOperationRequestForEntryPointV06< userOperation: UserOperation> entryPoint: entryPoint } - )) as Pick< - UserOperation<"v0.6">, - | "callGasLimit" - | "verificationGasLimit" - | "preVerificationGas" - | "paymasterAndData" - > + )) as SponsorUserOperationReturnType userOperation.callGasLimit = sponsorUserOperationData.callGasLimit userOperation.verificationGasLimit = @@ -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 } @@ -333,16 +346,8 @@ async function prepareUserOperationRequestEntryPointV07< userOperation: UserOperation> entryPoint: entryPoint } - )) as Pick< - UserOperation<"v0.7">, - | "callGasLimit" - | "verificationGasLimit" - | "preVerificationGas" - | "paymaster" - | "paymasterVerificationGasLimit" - | "paymasterPostOpGasLimit" - | "paymasterData" - > + )) as SponsorUserOperationReturnType + userOperation.callGasLimit = sponsorUserOperationData.callGasLimit userOperation.verificationGasLimit = sponsorUserOperationData.verificationGasLimit @@ -354,6 +359,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 } diff --git a/packages/permissionless/types/index.ts b/packages/permissionless/types/index.ts index af9ac9a4..06a01060 100644 --- a/packages/permissionless/types/index.ts +++ b/packages/permissionless/types/index.ts @@ -37,6 +37,8 @@ export type Prettify = { export type PartialBy = Omit & Partial> +export type PartialPick = Partial> + // biome-ignore lint/suspicious/noExplicitAny: generic type export type UnionOmit = T extends any ? Omit From ace8a11af38488a305419e4ea8245eb7890fd5f3 Mon Sep 17 00:00:00 2001 From: Sahil Vasava Date: Sat, 13 Apr 2024 04:18:42 +0530 Subject: [PATCH 2/2] chore: add changeset --- .changeset/serious-drinks-burn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/serious-drinks-burn.md diff --git a/.changeset/serious-drinks-burn.md b/.changeset/serious-drinks-burn.md new file mode 100644 index 00000000..f779271f --- /dev/null +++ b/.changeset/serious-drinks-burn.md @@ -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