import { toHex, type Address, type IsUndefined, type Prettify, type UnionOmit, } from "viem"; import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc"; import type { InnerWalletApiClientBase } from "../../types.js"; import { AccountNotFoundError } from "@aa-sdk/core"; import { mergeClientCapabilities } from "../../internal/capabilities.js"; type RpcSchema = Extract< WalletServerRpcSchemaType, { Request: { method: "wallet_requestQuote_v0"; }; } >; export type RequestQuoteV0Params< TAccount extends Address | undefined = Address | undefined, > = Prettify> & (IsUndefined extends true ? { from: Address } : { from?: never }); export type RequestQuoteV0Result = Prettify; export async function requestQuoteV0< TAccount extends Address | undefined = Address | undefined, >( client: InnerWalletApiClientBase, params: RequestQuoteV0Params, ): Promise { const from = params.from ?? client.account?.address; if (!from) { throw new AccountNotFoundError(); } const capabilities = params.returnRawCalls ? undefined : mergeClientCapabilities(client, params.capabilities); return await client.request({ method: "wallet_requestQuote_v0", params: [ { ...params, chainId: toHex(client.chain.id), from, ...(capabilities && { capabilities }), }, ], }); }