import {z} from 'zod' export type SmartMoneyFilterType = 'Fund' | 'Smart Trader' | '30D Smart Trader' | '90D Smart Trader' | '180D Smart Trader' | 'Smart HL Perps Trader'; export type DateRangeFilter = {from?: (string | string | null) | undefined, to?: (string | string | null) | undefined}; export type NumericRangeFilter = {min?: number | undefined, max?: number | undefined}; export type SmartMoneyDcasFilters = {include_smart_money_labels?: Array | undefined, exclude_smart_money_labels?: Array | undefined, dca_created_at?: DateRangeFilter | undefined, transaction_hash?: (string | Array | null) | undefined, trader_address?: (string | Array | null) | undefined, trader_address_label?: (string | Array | null) | undefined, input_token_symbol?: (string | Array | null) | undefined, output_token_symbol?: (string | Array | null) | undefined, deposit_token_amount?: NumericRangeFilter | undefined, token_spent_amount?: NumericRangeFilter | undefined, output_token_redeemed_amount?: NumericRangeFilter | undefined}; export type PaginationRequest = {page?: number | undefined, per_page?: number | undefined}; export type SmartMoneyDcasSortField = 'dca_created_at' | 'dca_updated_at' | 'input_token_symbol' | 'output_token_symbol' | 'deposit_token_amount' | 'token_spent_amount' | 'deposit_value_usd' | 'output_token_redeemed_amount'; export type SortDirection = 'ASC' | 'DESC'; export type SortOrderSmartMoneyDcasSortField = {field: SmartMoneyDcasSortField, direction: SortDirection}; export type SmartMoneyDcasRequest = {filters?: SmartMoneyDcasFilters | undefined, pagination?: PaginationRequest | undefined, order_by?: Array | undefined}; export type CreateApiApiV1SmartMoneyDcasArgs = {body: SmartMoneyDcasRequest}; export type CreateApiApiV1SmartMoneyDcasOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const smartMoneyDca = z.object({dca_created_at: z.string(), dca_updated_at: z.string(), trader_address: z.string(), transaction_hash: z.string(), trader_address_label: z.string(), dca_vault_address: z.string(), input_token_address: z.string(), output_token_address: z.string(), deposit_token_amount: z.number().optional(), token_spent_amount: z.number().optional(), output_token_redeemed_amount: z.number().optional(), dca_status: z.string(), input_token_symbol: z.string(), output_token_symbol: z.string(), deposit_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 smartMoneyDcasResponse = z.object({data: z.array(smartMoneyDca), 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 DCAs Data * * POST /api/v1/smart-money/dcas */ export const createApiApiV1SmartMoneyDcas = async (args: CreateApiApiV1SmartMoneyDcasArgs, options?: CreateApiApiV1SmartMoneyDcasOptions) => { 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/dcas${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(smartMoneyDcasResponse, await res.json()) };