import {z} from 'zod' export type GetApiAtomicmarketV1StatsGraphArgs = {symbol: string, collection_blacklist?: string | undefined, collection_whitelist?: string | undefined}; export type GetApiAtomicmarketV1StatsGraphOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAtomicmarketV1StatsGraphResponse = z.object({success: z.boolean().optional(), data: z.object({symbol: z.object({token_contract: z.string().optional(), token_symbol: z.string().optional(), token_precision: z.number().int().optional()}).optional(), results: z.array(z.object({time: z.string().optional(), volume: z.string().optional(), sales: z.string().optional(), max: z.string().optional()})).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 }; /** * Get history of volume and * * GET /atomicmarket/v1/stats/graph */ export const getApiAtomicmarketV1StatsGraph = async (args: GetApiAtomicmarketV1StatsGraphArgs, options?: GetApiAtomicmarketV1StatsGraphOptions) => { 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.symbol != null) query.append("symbol", String(args.symbol)) 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)) const url = `${baseUrl.replace(/\/+$/, '')}/atomicmarket/v1/stats/graph${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(getApiAtomicmarketV1StatsGraphResponse, await res.json()) };