import type { SmartAccount } from "permissionless/accounts" import type { EntryPoint, Prettify } from "permissionless/types" import type { Chain, Client, PublicClientConfig, Transport } from "viem" import { type CABPaymasterActions, cabPaymasterActions } from "../cabPaymaster/clients/decorators/cabPaymasterActions" import type { CAB_VERSION, CabPaymasterRpcScheme } from "../types" import { type CABActions, cabActions } from "./decorators/cabActions" export type CABClient< TEntryPoint extends EntryPoint, TTransport extends Transport, TChain extends Chain, TSmartAccount extends | SmartAccount | undefined = | SmartAccount | undefined > = Client< TTransport, TChain, TSmartAccount, CabPaymasterRpcScheme, CABPaymasterActions & CABActions > export const createCABClient = < TEntryPoint extends EntryPoint, TTransport extends Transport, TChain extends Chain, TSmartAccount extends SmartAccount >( client: Prettify>, parameters: PublicClientConfig & { entryPoint: TEntryPoint cabVersion?: CAB_VERSION } ): CABClient => { const { transport, entryPoint: entryPoint_, cabVersion } = parameters const entryPoint = entryPoint_ ?? client.account.entryPoint return client .extend(cabPaymasterActions(entryPoint, transport, cabVersion)) .extend(cabActions(transport, cabVersion)) }