export type SwapAssetInput = {amount: string, chain: string, contract: string}; export type SwapExecuteRequest = {address: string, from_assets: Array, recipient?: (string | null) | undefined, slippage_tolerance?: (number | null) | undefined, to_assets: Array}; export type CreateApiApiV2SwapExecuteArgs = {body: SwapExecuteRequest}; export type CreateApiApiV2SwapExecuteOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Execute a token swap * * POST /api/v2/swap/execute */ export const createApiApiV2SwapExecute = async (args: CreateApiApiV2SwapExecuteArgs, options?: CreateApiApiV2SwapExecuteOptions) => { const {baseUrl = "https://api.opensea.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/swap/execute${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };