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 TGMFlowIntelligenceTimeframe = '5m' | '1h' | '6h' | '12h' | '1d' | '7d'; export type TGMTokenInformationRequest = {chain: TGMChain, token_address: string, timeframe: TGMFlowIntelligenceTimeframe}; export type CreateApiApiV1TgmTokenInformationArgs = {body: TGMTokenInformationRequest}; export type CreateApiApiV1TgmTokenInformationOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const tokenDetails = z.object({token_deployment_date: z.string().optional(), website: z.string().optional(), x: z.string().optional(), telegram: z.string().optional(), market_cap_usd: z.number().optional(), fdv_usd: z.number().optional(), circulating_supply: z.number().optional(), total_supply: z.number().optional()}); export const spotMetrics = z.object({volume_total_usd: z.number().optional(), buy_volume_usd: z.number().optional(), sell_volume_usd: z.number().optional(), total_buys: z.number().int().optional(), total_sells: z.number().int().optional(), unique_buyers: z.number().int().optional(), unique_sellers: z.number().int().optional(), liquidity_usd: z.number().optional(), total_holders: z.number().int().optional()}); export const tGMTokenInformation = z.object({name: z.string().optional(), symbol: z.string().optional(), contract_address: z.string().optional(), logo: z.string().optional(), token_details: tokenDetails.optional(), spot_metrics: spotMetrics.optional()}); export const tGMTokenInformationResponse = z.object({data: tGMTokenInformation}); 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 "Token God Mode" (TGM) token information data * * POST /api/v1/tgm/token-information */ export const createApiApiV1TgmTokenInformation = async (args: CreateApiApiV1TgmTokenInformationArgs, options?: CreateApiApiV1TgmTokenInformationOptions) => { 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/v1/tgm/token-information${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(tGMTokenInformationResponse, await res.json()) };