import {z} from 'zod' export type GetApiAtomicmarketV1PricesAssetsArgs = {collection_name?: string | undefined, schema_name?: string | undefined, template_id?: number | undefined, burned?: boolean | undefined, owner?: string | undefined, match?: string | undefined, search?: string | undefined, match_immutable_name?: string | undefined, match_mutable_name?: string | undefined, is_transferable?: boolean | undefined, is_burnable?: boolean | undefined, minter?: string | undefined, burner?: string | undefined, initial_receiver?: string | undefined, collection_blacklist?: string | undefined, collection_whitelist?: string | undefined, authorized_account?: string | undefined, hide_offers?: boolean | undefined, asset_id?: string | undefined, ids?: string | undefined, lower_bound?: string | undefined, upper_bound?: string | undefined}; export type GetApiAtomicmarketV1PricesAssetsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAtomicmarketV1PricesAssetsResponse = z.object({success: z.boolean().optional(), data: z.array(z.object({token_symbol: z.string().optional(), token_precision: z.number().int().optional(), token_contract: z.string().optional(), median: z.string().optional(), average: z.string().optional(), suggested_average: z.string().optional(), suggested_median: z.string().optional(), min: z.string().optional(), max: z.string().optional()})).optional(), query_time: z.number().int().nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Gets price history for a template or schema * * GET /atomicmarket/v1/prices/assets */ export const getApiAtomicmarketV1PricesAssets = async (args: GetApiAtomicmarketV1PricesAssetsArgs, options?: GetApiAtomicmarketV1PricesAssetsOptions) => { const {baseUrl = "https://atomic.3dkrender.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.collection_name != null) query.append("collection_name", String(args.collection_name)) if (args.schema_name != null) query.append("schema_name", String(args.schema_name)) if (args.template_id != null) query.append("template_id", String(args.template_id)) if (args.burned != null) query.append("burned", String(args.burned)) if (args.owner != null) query.append("owner", String(args.owner)) if (args.match != null) query.append("match", String(args.match)) if (args.search != null) query.append("search", String(args.search)) if (args.match_immutable_name != null) query.append("match_immutable_name", String(args.match_immutable_name)) if (args.match_mutable_name != null) query.append("match_mutable_name", String(args.match_mutable_name)) if (args.is_transferable != null) query.append("is_transferable", String(args.is_transferable)) if (args.is_burnable != null) query.append("is_burnable", String(args.is_burnable)) if (args.minter != null) query.append("minter", String(args.minter)) if (args.burner != null) query.append("burner", String(args.burner)) if (args.initial_receiver != null) query.append("initial_receiver", String(args.initial_receiver)) if (args.collection_blacklist != null) query.append("collection_blacklist", String(args.collection_blacklist)) if (args.collection_whitelist != null) query.append("collection_whitelist", String(args.collection_whitelist)) if (args.authorized_account != null) query.append("authorized_account", String(args.authorized_account)) if (args.hide_offers != null) query.append("hide_offers", String(args.hide_offers)) if (args.collection_blacklist != null) query.append("collection_blacklist", String(args.collection_blacklist)) if (args.collection_whitelist != null) query.append("collection_whitelist", String(args.collection_whitelist)) if (args.asset_id != null) query.append("asset_id", String(args.asset_id)) if (args.ids != null) query.append("ids", String(args.ids)) if (args.lower_bound != null) query.append("lower_bound", String(args.lower_bound)) if (args.upper_bound != null) query.append("upper_bound", String(args.upper_bound)) const url = `${baseUrl.replace(/\/+$/, '')}/atomicmarket/v1/prices/assets${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 validateResponse(getApiAtomicmarketV1PricesAssetsResponse, await res.json()) };