import {z} from 'zod' export type TGMChain = 'arbitrum' | 'avalanche' | 'base' | 'bnb' | 'ethereum' | 'hyperevm' | 'hyperliquid' | 'injective' | 'iotaevm' | 'linea' | 'mantle' | 'mantra' | 'monad' | 'near' | 'optimism' | 'plasma' | 'polygon' | 'robinhood' | 'sei' | 'solana' | 'sonic' | 'starknet' | 'sui' | 'ton' | 'tron'; export type TgmHistoricalTokenQuantScoresRequest = {as_of_date: string, chain: TGMChain, token_address: string}; export type CreateApiApiV1beta1TgmHistoricalTokenQuantScoresArgs = {body: TgmHistoricalTokenQuantScoresRequest}; export type CreateApiApiV1beta1TgmHistoricalTokenQuantScoresOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const tgmHistoricalTokenQuantScore = z.object({indicator_type: z.string(), signal: z.number().optional(), signal_percentile: z.number().optional(), score: z.string().optional(), last_trigger_on: z.string().optional(), is_stablecoin: z.boolean().optional(), market_cap_usd: z.number().optional(), market_cap_group: z.string().optional(), model_type: z.string().optional()}); export const tgmHistoricalTokenQuantScoresResponse = z.object({data: z.array(tgmHistoricalTokenQuantScore)}); 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 Historical Token Quant Scores (Beta) * * POST /api/v1beta1/tgm/historical-token-quant-scores */ export const createApiApiV1beta1TgmHistoricalTokenQuantScores = async (args: CreateApiApiV1beta1TgmHistoricalTokenQuantScoresArgs, options?: CreateApiApiV1beta1TgmHistoricalTokenQuantScoresOptions) => { const {baseUrl = "https://api.nansen.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("apiKey", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1beta1/tgm/historical-token-quant-scores${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 validateResponse(tgmHistoricalTokenQuantScoresResponse, await res.json()) };