export type GetApiAssetRegistryPriceArgs = {assetKey?: string | undefined, chainId?: number | undefined, address?: string | undefined}; export type GetApiAssetRegistryPriceOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Current USD price for one active registry asset * * GET /asset-registry/price */ export const getApiAssetRegistryPrice = async (args: GetApiAssetRegistryPriceArgs, options: GetApiAssetRegistryPriceOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.assetKey != null) query.append("assetKey", String(args.assetKey)) if (args.chainId != null) query.append("chainId", String(args.chainId)) if (args.address != null) query.append("address", String(args.address)) const url = `${baseUrl.replace(/\/+$/, '')}/asset-registry/price${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 undefined };