import {z} from 'zod' export type GetApiApiPublicV1PulseCompareArgs = {wallets?: string | undefined}; export type GetApiApiPublicV1PulseCompareOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const lifecycleCoverage = z.object({reason: z.string().nullable(), tracked: z.boolean(), windowEnd: z.string(), windowStart: z.string()}); export const lifecycleSummaryWindow = z.object({days: z.number().int(), end: z.string(), includesCensored: z.boolean(), includesOpen: z.boolean(), start: z.string()}); export const walletLifecycleSummaryBody = z.object({$schema: z.string().optional(), address: z.string(), avgDurationMs: z.number(), avgPnl: z.number(), biggestLoss: z.number(), biggestWin: z.number(), closed: z.number().int(), coverage: lifecycleCoverage, firstOpenedAt: z.string().nullable(), lastActivityAt: z.string().nullable(), liquidations: z.number().int(), losses: z.number().int(), maxDurationMs: z.number().int().nullable(), minDurationMs: z.number().int().nullable(), open: z.number().int(), openRealizedPnl: z.number(), total: z.number().int(), totalBuilderFees: z.number(), totalFees: z.number(), totalPnl: z.number(), uniqueCoins: z.number().int(), winRate: z.number(), window: lifecycleSummaryWindow, wins: z.number().int()}); export const walletComparisonRow = z.object({address: z.string(), summary: walletLifecycleSummaryBody}); export const walletCompareBody = z.object({$schema: z.string().optional(), wallets: z.array(walletComparisonRow).nullable(), window: lifecycleSummaryWindow}); 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 API public v1 pulse compare * * GET /api/public/v1/pulse/compare */ export const getApiApiPublicV1PulseCompare = async (args: GetApiApiPublicV1PulseCompareArgs, options?: GetApiApiPublicV1PulseCompareOptions) => { const {baseUrl = "https://api.coinversa.ai", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.wallets != null) query.append("wallets", String(args.wallets)) if (apiKey !== undefined) headers.set("X-API-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v1/pulse/compare${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(walletCompareBody, await res.json()) };