import {z} from 'zod' export type TGMHistoricalChain = 'base' | 'bnb' | 'ethereum' | 'solana'; export type TGMHistoricalTopHoldersLabel = 'all_holders' | 'whale' | 'public_figure' | 'exchange' | 'smart_money'; export type PaginationRequest = {page?: number | undefined, per_page?: number | undefined}; export type HistoricalLabelType = '30D Smart Trader' | '90D Smart Trader' | '180D Smart Trader' | 'Fund' | 'Smart Trader' | 'Smart Dex Trader' | '30D Smart Dex Trader' | '90D Smart Dex Trader' | '180D Smart Dex Trader' | 'Public Figure' | 'Exchange' | 'Whale' | 'BananaGun Bot User' | 'Top Maestro Bot User' | 'Top BananaGun Bot User' | 'Maestro Bot User' | 'Early MAGIC Miner' | 'First Mover LP' | 'First Mover Staking' | 'Profitable LP' | 'Smart HL Perps Trader'; export type TGMHistoricalTopHoldersFilters = {include_sm_labels?: Array | undefined}; export type TGMHistoricalTopHoldersSortField = 'token_amount' | 'value_usd' | 'total_outflow' | 'total_inflow' | 'balance_change_24h' | 'balance_change_7d' | 'balance_change_30d' | 'ownership_percentage'; export type SortDirection = 'ASC' | 'DESC'; export type SortOrderTGMHistoricalTopHoldersSortField = {field: TGMHistoricalTopHoldersSortField, direction: SortDirection}; export type TGMHistoricalTopHoldersRequest = {chain: TGMHistoricalChain, token_address: string, as_of_date: string, label_type?: TGMHistoricalTopHoldersLabel | undefined, pagination?: PaginationRequest | undefined, filters?: TGMHistoricalTopHoldersFilters | undefined, order_by?: Array | undefined, apply_blacklist_filter?: boolean | undefined}; export type CreateApiApiV1beta1TgmHistoricalTopHoldersArgs = {body: TGMHistoricalTopHoldersRequest}; export type CreateApiApiV1beta1TgmHistoricalTopHoldersOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const tGMHistoricalTopHolder = z.object({token_symbol: z.string().optional(), address: z.string().optional(), address_label: z.string().optional(), token_amount: z.number().optional(), total_outflow: z.number().optional(), total_inflow: z.number().optional(), balance_change_24h: z.number().optional(), balance_change_7d: z.number().optional(), balance_change_30d: z.number().optional(), ownership_percentage: z.number().optional(), value_usd: z.number().optional()}); export const paginationInfo = z.object({page: z.number().int().gte(1).optional(), per_page: z.number().int().gte(1).lte(1000).optional(), is_last_page: z.boolean().optional()}); export const tGMHistoricalTopHoldersResponse = z.object({data: z.array(tGMHistoricalTopHolder), pagination: paginationInfo}); 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 God Mode" (TGM) top holders (Beta) * * POST /api/v1beta1/tgm/historical-top-holders */ export const createApiApiV1beta1TgmHistoricalTopHolders = async (args: CreateApiApiV1beta1TgmHistoricalTopHoldersArgs, options?: CreateApiApiV1beta1TgmHistoricalTopHoldersOptions) => { 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-top-holders${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(tGMHistoricalTopHoldersResponse, await res.json()) };