import {z} from 'zod' export type SmartMoneyChain = 'all' | 'arbitrum' | 'avalanche' | 'base' | 'bnb' | 'ethereum' | 'hyperevm' | 'iotaevm' | 'linea' | 'mantle' | 'monad' | 'optimism' | 'plasma' | 'polygon' | 'robinhood' | 'sei' | 'solana' | 'sonic'; export type SmartMoneyFilterType = 'Fund' | 'Smart Trader' | '30D Smart Trader' | '90D Smart Trader' | '180D Smart Trader' | 'Smart HL Perps Trader'; export type NumericRangeFilter = {min?: number | undefined, max?: number | undefined}; export type SmartMoneyDexTradesFilters = {include_smart_money_labels?: Array | undefined, exclude_smart_money_labels?: Array | undefined, chain?: (string | Array | null) | undefined, transaction_hash?: (string | Array | null) | undefined, trader_address?: (string | Array | null) | undefined, trader_address_label?: (string | Array | null) | undefined, token_bought_address?: (string | Array | null) | undefined, token_sold_address?: (string | Array | null) | undefined, token_bought_amount?: NumericRangeFilter | undefined, token_sold_amount?: NumericRangeFilter | undefined, token_bought_symbol?: (string | Array | null) | undefined, token_sold_symbol?: (string | Array | null) | undefined, token_bought_age_days?: NumericRangeFilter | undefined, token_sold_age_days?: NumericRangeFilter | undefined, token_bought_market_cap?: NumericRangeFilter | undefined, token_sold_market_cap?: NumericRangeFilter | undefined, token_bought_fdv?: NumericRangeFilter | undefined, token_sold_fdv?: NumericRangeFilter | undefined, trade_value_usd?: NumericRangeFilter | undefined}; export type PaginationRequest = {page?: number | undefined, per_page?: number | undefined}; export type SmartMoneyDexTradesSortField = 'chain' | 'block_timestamp' | 'transaction_hash' | 'trader_address' | 'trader_address_label' | 'token_bought_address' | 'token_sold_address' | 'token_bought_amount' | 'token_sold_amount' | 'token_bought_symbol' | 'token_sold_symbol' | 'token_bought_age_days' | 'token_sold_age_days' | 'token_bought_market_cap' | 'token_sold_market_cap' | 'token_bought_fdv' | 'token_sold_fdv' | 'trade_value_usd'; export type SortDirection = 'ASC' | 'DESC'; export type SortOrderSmartMoneyDexTradesSortField = {field: SmartMoneyDexTradesSortField, direction: SortDirection}; export type SmartMoneyDexTradesRequest = {chains: Array, filters?: SmartMoneyDexTradesFilters | undefined, pagination?: PaginationRequest | undefined, order_by?: Array | undefined}; export type CreateApiApiV1SmartMoneyDexTradesArgs = {body: SmartMoneyDexTradesRequest}; export type CreateApiApiV1SmartMoneyDexTradesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const smartMoneyDexTrade = z.object({chain: z.string(), block_timestamp: z.string(), transaction_hash: z.string(), trader_address: z.string(), trader_address_label: z.string(), token_bought_address: z.string(), token_sold_address: z.string(), token_bought_amount: z.number().optional(), token_sold_amount: z.number().optional(), token_bought_symbol: z.string(), token_sold_symbol: z.string(), token_bought_age_days: z.number().int(), token_sold_age_days: z.number().int(), token_bought_market_cap: z.number().optional(), token_sold_market_cap: z.number().optional(), token_bought_fdv: z.number().optional(), token_sold_fdv: z.number().optional(), trade_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 smartMoneyDexTradesResponse = z.object({data: z.array(smartMoneyDexTrade), 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 Smart Money DEX Trades Data * * POST /api/v1/smart-money/dex-trades */ export const createApiApiV1SmartMoneyDexTrades = async (args: CreateApiApiV1SmartMoneyDexTradesArgs, options?: CreateApiApiV1SmartMoneyDexTradesOptions) => { 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/smart-money/dex-trades${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(smartMoneyDexTradesResponse, await res.json()) };