export type GetApiApiV2SwapQuoteArgs = {from_chain: string, from_address: string, to_chain: string, to_address: string, quantity: string, address: string, slippage?: number | undefined, recipient?: string | undefined}; export type GetApiApiV2SwapQuoteOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get swap quote * * GET /api/v2/swap/quote */ export const getApiApiV2SwapQuote = async (args: GetApiApiV2SwapQuoteArgs, options?: GetApiApiV2SwapQuoteOptions) => { const {baseUrl = "https://api.opensea.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "*/*") if (args.from_chain != null) query.append("from_chain", String(args.from_chain)) if (args.from_address != null) query.append("from_address", String(args.from_address)) if (args.to_chain != null) query.append("to_chain", String(args.to_chain)) if (args.to_address != null) query.append("to_address", String(args.to_address)) if (args.quantity != null) query.append("quantity", String(args.quantity)) if (args.address != null) query.append("address", String(args.address)) if (args.slippage != null) query.append("slippage", String(args.slippage)) if (args.recipient != null) query.append("recipient", String(args.recipient)) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/swap/quote${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };