From 9b9fccf3fea6e7295d3b4de4f0be977a1691b03a Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Wed, 2 Oct 2024 12:04:36 +0100 Subject: [PATCH 1/4] Improve 7579 functions --- .../actions/erc7579/installModule.test.ts | 2 +- .../actions/erc7579/installModule.ts | 91 +++++++++---------- .../actions/erc7579/installModules.test.ts | 7 ++ .../actions/erc7579/installModules.ts | 89 ++++++++---------- .../actions/erc7579/isModuleInstalled.ts | 22 ++++- .../actions/erc7579/uninstallModule.ts | 67 ++++---------- .../actions/erc7579/uninstallModules.ts | 64 +++---------- .../utils/encodeInstallModule.ts | 85 +++++++++++++++++ .../utils/encodeUninstallModule.ts | 85 +++++++++++++++++ packages/permissionless/utils/index.ts | 12 ++- 10 files changed, 320 insertions(+), 204 deletions(-) create mode 100644 packages/permissionless/utils/encodeInstallModule.ts create mode 100644 packages/permissionless/utils/encodeUninstallModule.ts diff --git a/packages/permissionless/actions/erc7579/installModule.test.ts b/packages/permissionless/actions/erc7579/installModule.test.ts index 39599afe..7a308b55 100644 --- a/packages/permissionless/actions/erc7579/installModule.test.ts +++ b/packages/permissionless/actions/erc7579/installModule.test.ts @@ -36,7 +36,7 @@ describe.each(getCoreSmartAccounts())( account: smartClient.account, type: "executor", address: "0xc98B026383885F41d9a995f85FC480E9bb8bB891", - context: name.startsWith("Kernel 7579") + initData: name.startsWith("Kernel 7579") ? encodePacked( ["address", "bytes"], [ diff --git a/packages/permissionless/actions/erc7579/installModule.ts b/packages/permissionless/actions/erc7579/installModule.ts index d2b95441..a4c09a80 100644 --- a/packages/permissionless/actions/erc7579/installModule.ts +++ b/packages/permissionless/actions/erc7579/installModule.ts @@ -1,29 +1,50 @@ -import { - type Address, - type Client, - type Hex, - encodeFunctionData, - getAddress -} from "viem" +import type { Address, Client, Hex, Narrow, OneOf } from "viem" import { type GetSmartAccountParameter, + type PaymasterActions, type SmartAccount, + type UserOperationCalls, sendUserOperation } from "viem/account-abstraction" import { getAction, parseAccount } from "viem/utils" import { AccountNotFoundError } from "../../errors" -import { type ModuleType, parseModuleTypeId } from "./supportsModule" +import { encodeInstallModule } from "../../utils" +import type { ModuleType } from "./supportsModule" export type InstallModuleParameters< - TSmartAccount extends SmartAccount | undefined + TSmartAccount extends SmartAccount | undefined, + calls extends readonly unknown[] = readonly unknown[] > = GetSmartAccountParameter & { type: ModuleType address: Address - context: Hex maxFeePerGas?: bigint maxPriorityFeePerGas?: bigint nonce?: bigint -} + calls?: UserOperationCalls> + paymaster?: + | Address + | true + | { + /** Retrieves paymaster-related User Operation properties to be used for sending the User Operation. */ + getPaymasterData?: + | PaymasterActions["getPaymasterData"] + | undefined + /** Retrieves paymaster-related User Operation properties to be used for gas estimation. */ + getPaymasterStubData?: + | PaymasterActions["getPaymasterStubData"] + | undefined + } + | undefined + /** Paymaster context to pass to `getPaymasterData` and `getPaymasterStubData` calls. */ + paymasterContext?: unknown | undefined +} & OneOf< + | { + context: Hex + } + | { + initData: Hex + } + > export async function installModule< TSmartAccount extends SmartAccount | undefined @@ -37,7 +58,12 @@ export async function installModule< maxPriorityFeePerGas, nonce, address, - context + context, + initData, + type, + calls, + paymaster, + paymasterContext } = parameters if (!account_) { @@ -54,41 +80,14 @@ export async function installModule< "sendUserOperation" )({ calls: [ - { - to: account.address, - value: BigInt(0), - data: encodeFunctionData({ - abi: [ - { - name: "installModule", - type: "function", - stateMutability: "nonpayable", - inputs: [ - { - type: "uint256", - name: "moduleTypeId" - }, - { - type: "address", - name: "module" - }, - { - type: "bytes", - name: "initData" - } - ], - outputs: [] - } - ], - functionName: "installModule", - args: [ - parseModuleTypeId(parameters.type), - getAddress(address), - context - ] - }) - } + ...encodeInstallModule({ + account, + modules: [{ address, context: context ?? initData, type }] + }), + ...(calls ?? []) ], + paymaster, + paymasterContext, maxFeePerGas, maxPriorityFeePerGas, nonce, diff --git a/packages/permissionless/actions/erc7579/installModules.test.ts b/packages/permissionless/actions/erc7579/installModules.test.ts index 4500bea6..c8e50be1 100644 --- a/packages/permissionless/actions/erc7579/installModules.test.ts +++ b/packages/permissionless/actions/erc7579/installModules.test.ts @@ -34,6 +34,13 @@ describe.each(getCoreSmartAccounts())( const opHash = await installModules(smartClient, { account: smartClient.account, + calls: [ + { + to: smartClient.account.address, + value: 0n, + data: "0x" + } + ], modules: [ { type: "executor", diff --git a/packages/permissionless/actions/erc7579/installModules.ts b/packages/permissionless/actions/erc7579/installModules.ts index ff628bd0..2a8bdf74 100644 --- a/packages/permissionless/actions/erc7579/installModules.ts +++ b/packages/permissionless/actions/erc7579/installModules.ts @@ -1,32 +1,41 @@ +import type { Address, Chain, Client, Hex, Narrow, Transport } from "viem" import { - type Address, - type Chain, - type Client, - type Hex, - type Transport, - encodeFunctionData, - getAddress -} from "viem" -import { - type GetSmartAccountParameter, + type PaymasterActions, type SmartAccount, + type UserOperationCalls, sendUserOperation } from "viem/account-abstraction" import { getAction, parseAccount } from "viem/utils" import { AccountNotFoundError } from "../../errors" -import { type ModuleType, parseModuleTypeId } from "./supportsModule" +import { + type EncodeInstallModuleParameters, + encodeInstallModule +} from "../../utils/encodeInstallModule" export type InstallModulesParameters< - TSmartAccount extends SmartAccount | undefined -> = GetSmartAccountParameter & { - modules: { - type: ModuleType - address: Address - context: Hex - }[] + TSmartAccount extends SmartAccount | undefined, + calls extends readonly unknown[] = readonly unknown[] +> = EncodeInstallModuleParameters & { maxFeePerGas?: bigint maxPriorityFeePerGas?: bigint nonce?: bigint + calls?: UserOperationCalls> + paymaster?: + | Address + | true + | { + /** Retrieves paymaster-related User Operation properties to be used for sending the User Operation. */ + getPaymasterData?: + | PaymasterActions["getPaymasterData"] + | undefined + /** Retrieves paymaster-related User Operation properties to be used for gas estimation. */ + getPaymasterStubData?: + | PaymasterActions["getPaymasterStubData"] + | undefined + } + | undefined + /** Paymaster context to pass to `getPaymasterData` and `getPaymasterStubData` calls. */ + paymasterContext?: unknown | undefined } export async function installModules< @@ -40,7 +49,10 @@ export async function installModules< maxFeePerGas, maxPriorityFeePerGas, nonce, - modules + modules, + paymaster, + paymasterContext, + calls } = parameters if (!account_) { @@ -55,36 +67,15 @@ export async function installModules< sendUserOperation, "sendUserOperation" )({ - calls: modules.map(({ type, address, context }) => ({ - to: account.address, - value: BigInt(0), - data: encodeFunctionData({ - abi: [ - { - name: "installModule", - type: "function", - stateMutability: "nonpayable", - inputs: [ - { - type: "uint256", - name: "moduleTypeId" - }, - { - type: "address", - name: "module" - }, - { - type: "bytes", - name: "initData" - } - ], - outputs: [] - } - ], - functionName: "installModule", - args: [parseModuleTypeId(type), getAddress(address), context] - }) - })), + calls: [ + ...encodeInstallModule({ + account, + modules + }), + ...(calls ?? []) + ], + paymaster, + paymasterContext, maxFeePerGas, maxPriorityFeePerGas, nonce, diff --git a/packages/permissionless/actions/erc7579/isModuleInstalled.ts b/packages/permissionless/actions/erc7579/isModuleInstalled.ts index 6454fa0a..dbe01140 100644 --- a/packages/permissionless/actions/erc7579/isModuleInstalled.ts +++ b/packages/permissionless/actions/erc7579/isModuleInstalled.ts @@ -4,6 +4,7 @@ import { type Client, ContractFunctionExecutionError, type Hex, + type OneOf, type Transport, decodeFunctionResult, encodeFunctionData, @@ -23,8 +24,14 @@ export type IsModuleInstalledParameters< > = GetSmartAccountParameter & { type: ModuleType address: Address - context: Hex -} +} & OneOf< + | { + additionalContext: Hex + } + | { + context: Hex + } + > export async function isModuleInstalled< TSmartAccount extends SmartAccount | undefined @@ -32,7 +39,12 @@ export async function isModuleInstalled< client: Client, parameters: IsModuleInstalledParameters ): Promise { - const { account: account_ = client.account, address, context } = parameters + const { + account: account_ = client.account, + address, + context, + additionalContext + } = parameters if (!account_) { throw new AccountNotFoundError({ @@ -82,7 +94,7 @@ export async function isModuleInstalled< args: [ parseModuleTypeId(parameters.type), getAddress(address), - context + context ?? additionalContext ], address: account.address }) @@ -104,7 +116,7 @@ export async function isModuleInstalled< args: [ parseModuleTypeId(parameters.type), getAddress(address), - context + context ?? additionalContext ] }) }) diff --git a/packages/permissionless/actions/erc7579/uninstallModule.ts b/packages/permissionless/actions/erc7579/uninstallModule.ts index d4032607..833d8be3 100644 --- a/packages/permissionless/actions/erc7579/uninstallModule.ts +++ b/packages/permissionless/actions/erc7579/uninstallModule.ts @@ -1,12 +1,4 @@ -import { - type Address, - type Chain, - type Client, - type Hex, - type Transport, - encodeFunctionData, - getAddress -} from "viem" +import type { Address, Chain, Client, Hex, OneOf, Transport } from "viem" import { type GetSmartAccountParameter, type SmartAccount, @@ -15,18 +7,25 @@ import { import { getAction } from "viem/utils" import { parseAccount } from "viem/utils" import { AccountNotFoundError } from "../../errors" -import { type ModuleType, parseModuleTypeId } from "./supportsModule" +import { encodeUninstallModule } from "../../utils/encodeUninstallModule" +import type { ModuleType } from "./supportsModule" export type UninstallModuleParameters< TSmartAccount extends SmartAccount | undefined > = GetSmartAccountParameter & { type: ModuleType address: Address - context: Hex maxFeePerGas?: bigint maxPriorityFeePerGas?: bigint nonce?: bigint -} +} & OneOf< + | { + deInitData: Hex + } + | { + context: Hex + } + > export async function uninstallModule< TSmartAccount extends SmartAccount | undefined @@ -40,7 +39,9 @@ export async function uninstallModule< maxPriorityFeePerGas, nonce, address, - context + context, + deInitData, + type } = parameters if (!account_) { @@ -56,42 +57,10 @@ export async function uninstallModule< sendUserOperation, "sendUserOperation" )({ - calls: [ - { - to: account.address, - value: BigInt(0), - data: encodeFunctionData({ - abi: [ - { - name: "uninstallModule", - type: "function", - stateMutability: "nonpayable", - inputs: [ - { - type: "uint256", - name: "moduleTypeId" - }, - { - type: "address", - name: "module" - }, - { - type: "bytes", - name: "deInitData" - } - ], - outputs: [] - } - ], - functionName: "uninstallModule", - args: [ - parseModuleTypeId(parameters.type), - getAddress(address), - context - ] - }) - } - ], + calls: encodeUninstallModule({ + account, + modules: [{ type, address, context: context ?? deInitData }] + }), maxFeePerGas, maxPriorityFeePerGas, nonce, diff --git a/packages/permissionless/actions/erc7579/uninstallModules.ts b/packages/permissionless/actions/erc7579/uninstallModules.ts index 5e25736a..fe22b614 100644 --- a/packages/permissionless/actions/erc7579/uninstallModules.ts +++ b/packages/permissionless/actions/erc7579/uninstallModules.ts @@ -1,32 +1,16 @@ -import { - type Address, - type Chain, - type Client, - type Hex, - type Transport, - encodeFunctionData, - getAddress -} from "viem" -import { - type GetSmartAccountParameter, - type SmartAccount, - sendUserOperation -} from "viem/account-abstraction" +import type { Chain, Client, Hex, Transport } from "viem" +import { type SmartAccount, sendUserOperation } from "viem/account-abstraction" import { getAction } from "viem/utils" import { parseAccount } from "viem/utils" import { AccountNotFoundError } from "../../errors" -import { type ModuleType, parseModuleTypeId } from "./supportsModule" +import { + type EncodeUninstallModuleParameters, + encodeUninstallModule +} from "../../utils/encodeUninstallModule" export type UninstallModulesParameters< TSmartAccount extends SmartAccount | undefined -> = GetSmartAccountParameter & { - modules: [ - { - type: ModuleType - address: Address - context: Hex - } - ] +> = EncodeUninstallModuleParameters & { maxFeePerGas?: bigint maxPriorityFeePerGas?: bigint nonce?: bigint @@ -59,36 +43,10 @@ export async function uninstallModules< sendUserOperation, "sendUserOperation" )({ - calls: modules.map(({ type, address, context }) => ({ - to: account.address, - value: BigInt(0), - data: encodeFunctionData({ - abi: [ - { - name: "uninstallModule", - type: "function", - stateMutability: "nonpayable", - inputs: [ - { - type: "uint256", - name: "moduleTypeId" - }, - { - type: "address", - name: "module" - }, - { - type: "bytes", - name: "deInitData" - } - ], - outputs: [] - } - ], - functionName: "uninstallModule", - args: [parseModuleTypeId(type), getAddress(address), context] - }) - })), + calls: encodeUninstallModule({ + account, + modules + }), maxFeePerGas, maxPriorityFeePerGas, nonce, diff --git a/packages/permissionless/utils/encodeInstallModule.ts b/packages/permissionless/utils/encodeInstallModule.ts new file mode 100644 index 00000000..f10275d8 --- /dev/null +++ b/packages/permissionless/utils/encodeInstallModule.ts @@ -0,0 +1,85 @@ +import { + type Address, + type Hex, + type OneOf, + encodeFunctionData, + getAddress +} from "viem" +import type { + GetSmartAccountParameter, + SmartAccount +} from "viem/account-abstraction" +import { + type ModuleType, + parseModuleTypeId +} from "../actions/erc7579/supportsModule" +import { AccountNotFoundError } from "../errors" + +export type EncodeInstallModuleParameter = { + type: ModuleType + address: Address +} & OneOf< + | { + context: Hex + } + | { + initData: Hex + } +> + +export type EncodeInstallModuleParameters< + TSmartAccount extends SmartAccount | undefined +> = GetSmartAccountParameter & { + modules: EncodeInstallModuleParameter[] | EncodeInstallModuleParameter +} + +export function encodeInstallModule< + TSmartAccount extends SmartAccount | undefined +>(parameters: EncodeInstallModuleParameters) { + const account = parameters.account as SmartAccount + + if (!account) { + throw new AccountNotFoundError({ + docsPath: "/docs/actions/wallet/sendTransaction" + }) + } + + const modules = Array.isArray(parameters.modules) + ? parameters.modules + : [parameters.modules] + + return modules.map(({ type, address, context, initData }) => ({ + to: account.address, + value: BigInt(0), + data: encodeFunctionData({ + abi: [ + { + name: "installModule", + type: "function", + stateMutability: "nonpayable", + inputs: [ + { + type: "uint256", + name: "moduleTypeId" + }, + { + type: "address", + name: "module" + }, + { + type: "bytes", + name: "initData" + } + ], + outputs: [] + } + ], + functionName: "installModule", + args: [ + parseModuleTypeId(type), + getAddress(address), + context ?? initData + ] + }) + })) +} diff --git a/packages/permissionless/utils/encodeUninstallModule.ts b/packages/permissionless/utils/encodeUninstallModule.ts new file mode 100644 index 00000000..bd4b5185 --- /dev/null +++ b/packages/permissionless/utils/encodeUninstallModule.ts @@ -0,0 +1,85 @@ +import { + type Address, + type Hex, + type OneOf, + encodeFunctionData, + getAddress +} from "viem" +import type { + GetSmartAccountParameter, + SmartAccount +} from "viem/account-abstraction" +import { + type ModuleType, + parseModuleTypeId +} from "../actions/erc7579/supportsModule" +import { AccountNotFoundError } from "../errors" + +export type EncodeUninstallModuleParameter = { + type: ModuleType + address: Address +} & OneOf< + | { + context: Hex + } + | { + deInitData: Hex + } +> + +export type EncodeUninstallModuleParameters< + TSmartAccount extends SmartAccount | undefined +> = GetSmartAccountParameter & { + modules: EncodeUninstallModuleParameter[] | EncodeUninstallModuleParameter +} + +export function encodeUninstallModule< + TSmartAccount extends SmartAccount | undefined +>(parameters: EncodeUninstallModuleParameters) { + const account = parameters.account as SmartAccount + + if (!account) { + throw new AccountNotFoundError({ + docsPath: "/docs/actions/wallet/sendTransaction" + }) + } + + const modules = Array.isArray(parameters.modules) + ? parameters.modules + : [parameters.modules] + + return modules.map(({ type, address, context, deInitData }) => ({ + to: account.address, + value: BigInt(0), + data: encodeFunctionData({ + abi: [ + { + name: "uninstallModule", + type: "function", + stateMutability: "nonpayable", + inputs: [ + { + type: "uint256", + name: "moduleTypeId" + }, + { + type: "address", + name: "module" + }, + { + type: "bytes", + name: "deInitData" + } + ], + outputs: [] + } + ], + functionName: "uninstallModule", + args: [ + parseModuleTypeId(type), + getAddress(address), + context ?? deInitData + ] + }) + })) +} diff --git a/packages/permissionless/utils/index.ts b/packages/permissionless/utils/index.ts index c65af699..8469d094 100644 --- a/packages/permissionless/utils/index.ts +++ b/packages/permissionless/utils/index.ts @@ -10,8 +10,14 @@ import { toOwner } from "./toOwner" import { decodeNonce } from "./decodeNonce" import { encodeNonce } from "./encodeNonce" +import { + type EncodeInstallModuleParameters, + encodeInstallModule +} from "./encodeInstallModule" import { getPackedUserOperation } from "./getPackedUserOperation" +import { type EncodeCallDataParams, encode7579Calls } from "./encode7579Calls" + export { transactionReceiptStatus, deepHexlify, @@ -22,5 +28,9 @@ export { getAddressFromInitCodeOrPaymasterAndData, getPackedUserOperation, encodeNonce, - decodeNonce + decodeNonce, + type EncodeInstallModuleParameters, + encodeInstallModule, + type EncodeCallDataParams, + encode7579Calls } From d23ee0d5b530134756ea098f6233910f79cba83e Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Wed, 2 Oct 2024 12:06:33 +0100 Subject: [PATCH 2/4] Added changeset --- .changeset/proud-rings-march.md | 5 +++++ .changeset/stale-roses-compare.md | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/proud-rings-march.md create mode 100644 .changeset/stale-roses-compare.md diff --git a/.changeset/proud-rings-march.md b/.changeset/proud-rings-march.md new file mode 100644 index 00000000..bddf6ce9 --- /dev/null +++ b/.changeset/proud-rings-march.md @@ -0,0 +1,5 @@ +--- +"permissionless": patch +--- + +Added support to send calls with 7579 functions and override paymaster props diff --git a/.changeset/stale-roses-compare.md b/.changeset/stale-roses-compare.md new file mode 100644 index 00000000..8fe8c9b0 --- /dev/null +++ b/.changeset/stale-roses-compare.md @@ -0,0 +1,5 @@ +--- +"permissionless": patch +--- + +Added support for initData & deInitData From 7d4602c831430744916dda33983be0583d9b0662 Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Wed, 2 Oct 2024 12:07:18 +0100 Subject: [PATCH 3/4] Add more changeset --- .changeset/metal-ravens-mate.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/metal-ravens-mate.md diff --git a/.changeset/metal-ravens-mate.md b/.changeset/metal-ravens-mate.md new file mode 100644 index 00000000..31c4bc4d --- /dev/null +++ b/.changeset/metal-ravens-mate.md @@ -0,0 +1,5 @@ +--- +"permissionless": patch +--- + +Added utility functions to encode 7579 function calldata From 6154359a4fb29d4a4e90e92530428cf725c07bff Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Wed, 2 Oct 2024 12:55:27 +0100 Subject: [PATCH 4/4] Add calls in uninstallModule as well --- .../actions/erc7579/uninstallModule.ts | 50 ++++++++++++++++--- .../actions/erc7579/uninstallModules.ts | 47 ++++++++++++++--- 2 files changed, 82 insertions(+), 15 deletions(-) diff --git a/packages/permissionless/actions/erc7579/uninstallModule.ts b/packages/permissionless/actions/erc7579/uninstallModule.ts index 833d8be3..5817c97e 100644 --- a/packages/permissionless/actions/erc7579/uninstallModule.ts +++ b/packages/permissionless/actions/erc7579/uninstallModule.ts @@ -1,7 +1,17 @@ -import type { Address, Chain, Client, Hex, OneOf, Transport } from "viem" +import type { + Address, + Chain, + Client, + Hex, + Narrow, + OneOf, + Transport +} from "viem" import { type GetSmartAccountParameter, + type PaymasterActions, type SmartAccount, + type UserOperationCalls, sendUserOperation } from "viem/account-abstraction" import { getAction } from "viem/utils" @@ -11,13 +21,31 @@ import { encodeUninstallModule } from "../../utils/encodeUninstallModule" import type { ModuleType } from "./supportsModule" export type UninstallModuleParameters< - TSmartAccount extends SmartAccount | undefined + TSmartAccount extends SmartAccount | undefined, + calls extends readonly unknown[] = readonly unknown[] > = GetSmartAccountParameter & { type: ModuleType address: Address maxFeePerGas?: bigint maxPriorityFeePerGas?: bigint nonce?: bigint + calls?: UserOperationCalls> + paymaster?: + | Address + | true + | { + /** Retrieves paymaster-related User Operation properties to be used for sending the User Operation. */ + getPaymasterData?: + | PaymasterActions["getPaymasterData"] + | undefined + /** Retrieves paymaster-related User Operation properties to be used for gas estimation. */ + getPaymasterStubData?: + | PaymasterActions["getPaymasterStubData"] + | undefined + } + | undefined + /** Paymaster context to pass to `getPaymasterData` and `getPaymasterStubData` calls. */ + paymasterContext?: unknown | undefined } & OneOf< | { deInitData: Hex @@ -41,7 +69,10 @@ export async function uninstallModule< address, context, deInitData, - type + type, + calls, + paymaster, + paymasterContext } = parameters if (!account_) { @@ -57,10 +88,15 @@ export async function uninstallModule< sendUserOperation, "sendUserOperation" )({ - calls: encodeUninstallModule({ - account, - modules: [{ type, address, context: context ?? deInitData }] - }), + calls: [ + ...encodeUninstallModule({ + account, + modules: [{ type, address, context: context ?? deInitData }] + }), + ...(calls ?? []) + ], + paymaster, + paymasterContext, maxFeePerGas, maxPriorityFeePerGas, nonce, diff --git a/packages/permissionless/actions/erc7579/uninstallModules.ts b/packages/permissionless/actions/erc7579/uninstallModules.ts index fe22b614..885bf6bb 100644 --- a/packages/permissionless/actions/erc7579/uninstallModules.ts +++ b/packages/permissionless/actions/erc7579/uninstallModules.ts @@ -1,5 +1,10 @@ -import type { Chain, Client, Hex, Transport } from "viem" -import { type SmartAccount, sendUserOperation } from "viem/account-abstraction" +import type { Address, Chain, Client, Hex, Narrow, Transport } from "viem" +import { + type PaymasterActions, + type SmartAccount, + type UserOperationCalls, + sendUserOperation +} from "viem/account-abstraction" import { getAction } from "viem/utils" import { parseAccount } from "viem/utils" import { AccountNotFoundError } from "../../errors" @@ -9,11 +14,29 @@ import { } from "../../utils/encodeUninstallModule" export type UninstallModulesParameters< - TSmartAccount extends SmartAccount | undefined + TSmartAccount extends SmartAccount | undefined, + calls extends readonly unknown[] = readonly unknown[] > = EncodeUninstallModuleParameters & { maxFeePerGas?: bigint maxPriorityFeePerGas?: bigint nonce?: bigint + calls?: UserOperationCalls> + paymaster?: + | Address + | true + | { + /** Retrieves paymaster-related User Operation properties to be used for sending the User Operation. */ + getPaymasterData?: + | PaymasterActions["getPaymasterData"] + | undefined + /** Retrieves paymaster-related User Operation properties to be used for gas estimation. */ + getPaymasterStubData?: + | PaymasterActions["getPaymasterStubData"] + | undefined + } + | undefined + /** Paymaster context to pass to `getPaymasterData` and `getPaymasterStubData` calls. */ + paymasterContext?: unknown | undefined } export async function uninstallModules< @@ -27,7 +50,10 @@ export async function uninstallModules< maxFeePerGas, maxPriorityFeePerGas, nonce, - modules + modules, + calls, + paymaster, + paymasterContext } = parameters if (!account_) { @@ -43,10 +69,15 @@ export async function uninstallModules< sendUserOperation, "sendUserOperation" )({ - calls: encodeUninstallModule({ - account, - modules - }), + calls: [ + ...encodeUninstallModule({ + account, + modules + }), + ...(calls ?? []) + ], + paymaster, + paymasterContext, maxFeePerGas, maxPriorityFeePerGas, nonce,