import {z} from 'zod' export type TGMFlowIntelligenceChain = 'arbitrum' | 'avalanche' | 'base' | 'bnb' | 'ethereum' | 'hyperevm' | 'injective' | '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 NumericRangeFilter = {min?: number | undefined, max?: number | undefined}; export type IntegerRangeFilter = {min?: number | undefined, max?: number | undefined}; export type TGMFlowIntelligenceFilters = {public_figure_net_flow_usd?: NumericRangeFilter | undefined, public_figure_avg_flow_usd?: NumericRangeFilter | undefined, public_figure_wallet_count?: IntegerRangeFilter | undefined, top_pnl_net_flow_usd?: NumericRangeFilter | undefined, top_pnl_avg_flow_usd?: NumericRangeFilter | undefined, top_pnl_wallet_count?: IntegerRangeFilter | undefined, whale_net_flow_usd?: NumericRangeFilter | undefined, whale_avg_flow_usd?: NumericRangeFilter | undefined, whale_wallet_count?: IntegerRangeFilter | undefined, smart_trader_net_flow_usd?: NumericRangeFilter | undefined, smart_trader_avg_flow_usd?: NumericRangeFilter | undefined, smart_trader_wallet_count?: IntegerRangeFilter | undefined, exchange_net_flow_usd?: NumericRangeFilter | undefined, exchange_avg_flow_usd?: NumericRangeFilter | undefined, exchange_wallet_count?: IntegerRangeFilter | undefined, fresh_wallets_net_flow_usd?: NumericRangeFilter | undefined, fresh_wallets_avg_flow_usd?: NumericRangeFilter | undefined, fresh_wallets_wallet_count?: IntegerRangeFilter | undefined}; export type TGMFlowIntelligenceRequest = {chain: TGMFlowIntelligenceChain, token_address: string, timeframe?: TGMFlowIntelligenceTimeframe | undefined, filters?: TGMFlowIntelligenceFilters | undefined}; export type CreateApiApiV1TgmFlowIntelligenceArgs = {body: TGMFlowIntelligenceRequest}; export type CreateApiApiV1TgmFlowIntelligenceOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const tGMFlowIntelligence = z.object({public_figure_net_flow_usd: z.number().optional(), public_figure_avg_flow_usd: z.number().optional(), public_figure_wallet_count: z.number().int().optional(), top_pnl_net_flow_usd: z.number().optional(), top_pnl_avg_flow_usd: z.number().optional(), top_pnl_wallet_count: z.number().int().optional(), whale_net_flow_usd: z.number().optional(), whale_avg_flow_usd: z.number().optional(), whale_wallet_count: z.number().int().optional(), smart_trader_net_flow_usd: z.number().optional(), smart_trader_avg_flow_usd: z.number().optional(), smart_trader_wallet_count: z.number().int().optional(), exchange_net_flow_usd: z.number().optional(), exchange_avg_flow_usd: z.number().optional(), exchange_wallet_count: z.number().int().optional(), fresh_wallets_net_flow_usd: z.number().optional(), fresh_wallets_avg_flow_usd: z.number().optional(), fresh_wallets_wallet_count: z.number().int().optional()}); export const tGMFlowIntelligenceResponse = z.object({data: z.array(tGMFlowIntelligence), warnings: z.array(z.string()).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 "Token God Mode" (TGM) flow intelligence data * * POST /api/v1/tgm/flow-intelligence */ export const createApiApiV1TgmFlowIntelligence = async (args: CreateApiApiV1TgmFlowIntelligenceArgs, options?: CreateApiApiV1TgmFlowIntelligenceOptions) => { 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/flow-intelligence${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(tGMFlowIntelligenceResponse, await res.json()) };