/** * Account Adapter * * Adapts ZeroDev's account objects to work with our service layer. * Normalizes the interface to match KernelAccountInstance. */ import { Chain, Hex } from 'viem'; import { entryPoint07Address } from 'viem/account-abstraction'; import { KernelAccountInstance } from './kernel-account'; /** * Adapt a ZeroDev account to our KernelAccountInstance interface * * ZeroDev's createKernelAccount returns a different structure than what * our service expects. This adapter normalizes it. * * @param account - The account from createKernelAccount * @param chain - The chain the account is on * @returns Normalized account that works with our service */ export function adaptZeroDevAccount( account: any, chain: Chain ): KernelAccountInstance { return { ...account, chain, entryPoint: account.entryPoint || { address: entryPoint07Address, version: '0.7' } } as KernelAccountInstance; } /** * Adapt a session key account specifically * * Session key accounts need special handling to ensure all properties * are properly set for transaction execution. */ export function adaptSessionKeyAccount( sessionKeyAccount: any, masterAccount: KernelAccountInstance ): KernelAccountInstance { // Ensure entryPoint is properly defined const entryPoint = sessionKeyAccount.entryPoint || masterAccount.entryPoint || { address: entryPoint07Address, version: '0.7' }; return { ...sessionKeyAccount, chain: masterAccount.chain, entryPoint: { address: entryPoint.address || entryPoint07Address, version: entryPoint.version || '0.7' } } as KernelAccountInstance; }