import type { Chain, Transport } from "viem"; import type { GetAccountParameter, GetEntryPointFromAccount, SmartContractAccount, } from "../../../account/smartContractAccount"; import type { BaseSmartAccountClient } from "../../../client/smartAccountClient"; import type { SendUserOperationResult } from "../../../client/types"; import { AccountNotFoundError } from "../../../errors/account.js"; import { ChainNotFoundError } from "../../../errors/client.js"; import type { UserOperationOverrides, UserOperationStruct, } from "../../../types"; import { signUserOperation } from "../signUserOperation.js"; import type { GetContextParameter, UserOperationContext } from "../types"; import { getUserOperationError } from "../getUserOperationError.js"; export async function _sendUserOperation< TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends SmartContractAccount | undefined = | SmartContractAccount | undefined, TContext extends UserOperationContext | undefined = | UserOperationContext | undefined, TEntryPointVersion extends GetEntryPointFromAccount = GetEntryPointFromAccount, >( client: BaseSmartAccountClient, args: { uoStruct: UserOperationStruct; overrides?: UserOperationOverrides; } & GetAccountParameter & GetContextParameter, ): Promise> { const { account = client.account, uoStruct, context, overrides } = args; if (!account) { throw new AccountNotFoundError(); } if (!client.chain) { throw new ChainNotFoundError(); } const entryPoint = account.getEntryPoint(); const request = await signUserOperation(client, { uoStruct, account, context, overrides, }); try { return { hash: await client.sendRawUserOperation(request, entryPoint.address), request, }; } catch (err) { getUserOperationError(client, request, entryPoint); throw err; } }