import {z} from 'zod' export type GetApiApiPublicV1PulseLifecycleIdArgs = {id: number}; export type GetApiApiPublicV1PulseLifecycleIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const lifecycleFill = z.object({attributedBuilderFee: z.number(), attributedFee: z.number(), attributedPnl: z.number(), attributedSize: z.number(), attributionAvailable: z.boolean(), builderFee: z.number(), fee: z.number(), hash: z.string().optional(), pnl: z.number(), px: z.number(), rawClosedPnl: z.number(), rawTime: z.number().int(), side: z.string(), sz: z.number(), tid: z.number().int(), tradeTime: z.string()}); export const lifecycleRow = z.object({builderFee: z.number(), closedAt: z.string().optional(), closedAtRaw: z.number().int().optional(), coin: z.string(), durationMs: z.number().int().optional(), entryVwap: z.number(), exitVwap: z.number().optional(), fees: z.number(), fillCount: z.number().int(), id: z.number().int(), isClosed: z.boolean(), lifecycleNum: z.number().int(), liquidationClosedPnl: z.number().optional(), liquidationMethod: z.string().optional(), liquidatorAddress: z.string().optional(), openedAt: z.string(), openedAtRaw: z.number().int(), openedBeforeWindow: z.boolean(), peakSize: z.number(), penaltyFeePaid: z.number().optional(), realizedPnl: z.number(), side: z.string(), status: z.string(), wasLiquidated: z.boolean()}); export const lifecycleDetailBody = z.object({$schema: z.string().optional(), address: z.string(), fillPnlBasis: z.string(), fills: z.array(lifecycleFill).nullable(), lifecycle: lifecycleRow}); 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 lifecycle by ID * * GET /api/public/v1/pulse/lifecycle/{id} */ export const getApiApiPublicV1PulseLifecycleId = async (args: GetApiApiPublicV1PulseLifecycleIdArgs, options?: GetApiApiPublicV1PulseLifecycleIdOptions) => { 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 (apiKey !== undefined) headers.set("X-API-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v1/pulse/lifecycle/${encodeURIComponent(String(args.id))}${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(lifecycleDetailBody, await res.json()) };