import {z} from 'zod' export type PaginationRequest = {page?: number | undefined, per_page?: number | undefined}; export type LabelType = '30D Smart Trader' | '90D Smart Trader' | '180D Smart Trader' | 'Fund' | 'Smart 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 NumericRangeFilter = {min?: number | undefined, max?: number | undefined}; export type TGMJupDcaStatus = 'Active' | 'Closed'; export type TGMJupDcaFilters = {include_smart_money_labels?: Array | undefined, exclude_smart_money_labels?: Array | undefined, trader_address?: (string | Array | null) | undefined, trader_label?: (string | Array | null) | undefined, creation_hash?: (string | Array | null) | undefined, dca_vault_address?: (string | Array | null) | undefined, input_mint_address?: (string | Array | null) | undefined, output_mint_address?: (string | Array | null) | undefined, deposit_amount?: NumericRangeFilter | undefined, deposit_spent?: NumericRangeFilter | undefined, other_token_redeemed?: NumericRangeFilter | undefined, status?: TGMJupDcaStatus | undefined, token_input?: string | undefined, token_output?: string | undefined, deposit_usd_value?: NumericRangeFilter | undefined}; export type TGMJupDcaRequest = {token_address: string, pagination?: PaginationRequest | undefined, filters?: TGMJupDcaFilters | undefined}; export type CreateApiApiV1TgmJupDcaArgs = {body: TGMJupDcaRequest}; export type CreateApiApiV1TgmJupDcaOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const tGMJupDcaStatus = z.enum(["Active", "Closed"]); export const tGMJupDca = z.object({since_timestamp: z.string().optional(), last_timestamp: z.string().optional(), trader_address: z.string(), creation_hash: z.string().optional(), trader_label: z.string().optional(), dca_vault_address: z.string().optional(), input_mint_address: z.string().optional(), output_mint_address: z.string().optional(), deposit_amount: z.number().optional(), deposit_spent: z.number().optional(), other_token_redeemed: z.number().optional(), status: tGMJupDcaStatus.optional(), token_input: z.string().optional(), token_output: z.string().optional(), deposit_usd_value: 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 tGMJupDcaResponse = z.object({data: z.array(tGMJupDca), 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 "Token God Mode" (TGM) Jupiter DCA data * * POST /api/v1/tgm/jup-dca */ export const createApiApiV1TgmJupDca = async (args: CreateApiApiV1TgmJupDcaArgs, options?: CreateApiApiV1TgmJupDcaOptions) => { 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/jup-dca${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(tGMJupDcaResponse, await res.json()) };