import type { KernelSmartAccount } from "@zerodev/sdk" import type { EntryPoint } from "permissionless/types" import type { Chain, Client, Hash, Transport } from "viem" import { type EnableCABParameters, type GetEnabledChainsParameters, type GetEnabledChainsResult, type PrepareUserOperationRequestCABParameters, type PrepareUserOperationRequestCABReturnType, type SendUserOperationCABParameters, type SponsorUserOperationParameters, type SponsorUserOperationReturnType, enableCAB, getEnabledChains, prepareUserOperationRequestCAB, sendUserOperationCAB, sponsorUserOperation } from "../../actions/kernel" import type { CAB_VERSION } from "../../types" import { getCabPaymasterAddress } from "../../utils" import { getInvoiceManagerAddress } from "../../utils/getInvoiceManagerAddress" import type { KernelCABClient } from "../createKernelCABClient" export type KernelCABActions< TEntryPoint extends EntryPoint, TTransport extends Transport, TChain extends Chain | undefined, TSmartAccount extends | KernelSmartAccount | undefined = | KernelSmartAccount | undefined > = { enableCAB: (args: EnableCABParameters) => Promise sponsorUserOperation: ( args: SponsorUserOperationParameters ) => Promise> prepareUserOperationRequestCAB: ( args: PrepareUserOperationRequestCABParameters< TEntryPoint, TTransport, TChain, TSmartAccount > ) => Promise> sendUserOperationCAB: ( args: SendUserOperationCABParameters ) => Promise getEnabledChains: ( args?: GetEnabledChainsParameters ) => Promise } export const kernelCABActions = < TEntryPoint extends EntryPoint, TTransport extends Transport, TChain extends Chain | undefined, TSmartAccount extends | KernelSmartAccount | undefined = | KernelSmartAccount | undefined >( transport: Transport, cabVersion?: CAB_VERSION ) => ( client: Client ): KernelCABActions => ({ enableCAB: async (args) => enableCAB( client, { ...args, cabPaymasterAddress: getCabPaymasterAddress(cabVersion) }, transport ), sponsorUserOperation: async (args) => sponsorUserOperation< TEntryPoint, TTransport, TChain, TSmartAccount >( client as KernelCABClient< TEntryPoint, TTransport, TChain, TSmartAccount >, { ...args, cabPaymasterAddress: getCabPaymasterAddress(cabVersion) } ), prepareUserOperationRequestCAB: async (args) => prepareUserOperationRequestCAB< TEntryPoint, TChain, TTransport, TSmartAccount >( client, { ...args, cabPaymasterAddress: getCabPaymasterAddress(cabVersion) } as PrepareUserOperationRequestCABParameters< TEntryPoint, TTransport, TChain, TSmartAccount >, transport ), sendUserOperationCAB: async (args) => sendUserOperationCAB< TEntryPoint, TChain, TTransport, TSmartAccount >( client, { ...args, cabPaymasterAddress: getCabPaymasterAddress(cabVersion) }, transport ), getEnabledChains: async (args = {}) => getEnabledChains( client, { ...args, invoiceManagerAddress: getInvoiceManagerAddress(cabVersion) }, transport ) })