import { AccountNotFoundError, IncompatibleClientError, isSmartAccountClient, type GetAccountParameter, type GetContextParameter, type GetEntryPointFromAccount, type SmartContractAccount, type UserOperationContext, type UserOperationOverridesParameter, } from "@aa-sdk/core"; import { encodeFunctionData, type Address, type Chain, type Client, type Hash, type Transport, } from "viem"; import { IPluginManagerAbi } from "../abis/IPluginManager.js"; export type UninstallPluginParams< TAccount extends SmartContractAccount | undefined = | SmartContractAccount | undefined, TContext extends UserOperationContext | undefined = | UserOperationContext | undefined, TEntryPointVersion extends GetEntryPointFromAccount = GetEntryPointFromAccount, > = { pluginAddress: Address; config?: Hash; pluginUninstallData?: Hash; } & UserOperationOverridesParameter & GetAccountParameter & GetContextParameter; export async function uninstallPlugin< TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends SmartContractAccount | undefined = | SmartContractAccount | undefined, TContext extends UserOperationContext | undefined = | UserOperationContext | undefined, >( client: Client, { overrides, account = client.account, context, ...params }: UninstallPluginParams, ) { if (!account) { throw new AccountNotFoundError(); } if (!isSmartAccountClient(client)) { throw new IncompatibleClientError( "SmartAccountClient", "uninstallPlugin", client, ); } const callData = await encodeUninstallPluginUserOperation(params); return client.sendUserOperation({ uo: callData, overrides, account, context, }); } export async function encodeUninstallPluginUserOperation( params: Omit, ) { return encodeFunctionData({ abi: IPluginManagerAbi, functionName: "uninstallPlugin", args: [ params.pluginAddress, params.config ?? "0x", params.pluginUninstallData ?? "0x", ], }); }