import {z} from 'zod' export type GetApiApiV1PickOfTheDayLedgerArgs = {'X-Query-Validation'?: 'strict' | undefined, 'If-None-Match'?: string | undefined}; export type GetApiApiV1PickOfTheDayLedgerOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const pickOfTheDayLedgerSealedEntry = z.object({state: z.literal("sealed"), pick_date: z.string(), pick_rank: z.number().int(), commitment_hash: z.string(), commitment_algo: z.literal("sha256(canonical_json(payload)||nonce)"), sealed_at: z.string(), kickoff: z.string(), permalink: z.string()}); export const pickOfTheDayCommitmentPayload = z.object({backed_price: z.string(), condition_id: z.string(), kickoff: z.string(), pick_date: z.string(), pick_outcome_index: z.union([z.literal(0), z.literal(1)]), pick_outcome_label: z.string(), pick_rank: z.number().int(), platform: z.string()}); export const pickOfTheDayLedgerOpenedEntry = z.object({state: z.literal("opened"), pick_date: z.string(), pick_rank: z.number().int(), commitment_hash: z.string(), commitment_nonce: z.string(), commitment_algo: z.literal("sha256(canonical_json(payload)||nonce)"), sealed_at: z.string(), resolved_at: z.string().nullable(), kickoff: z.string(), payload: pickOfTheDayCommitmentPayload, outcome: z.enum(["win", "loss", "void"]), matchup: z.string(), category: z.string(), permalink: z.string()}); export const pickOfTheDayUncommittedPayload = z.object({backed_price: z.string(), condition_id: z.string(), kickoff: z.string().nullable(), pick_date: z.string(), pick_outcome_index: z.union([z.literal(0), z.literal(1)]), pick_outcome_label: z.string(), pick_rank: z.number().int(), platform: z.string()}); export const pickOfTheDayLedgerUncommittedEntry = z.object({state: z.literal("uncommitted"), pick_date: z.string(), pick_rank: z.number().int(), pre_commitment: z.literal(true), outcome: z.enum(["pending", "win", "loss", "void"]), matchup: z.string(), category: z.string(), resolved_at: z.string().nullable(), payload: pickOfTheDayUncommittedPayload.nullable(), permalink: z.string()}); export const pickOfTheDayLedgerEntry = z.discriminatedUnion("state", [pickOfTheDayLedgerSealedEntry, pickOfTheDayLedgerOpenedEntry, pickOfTheDayLedgerUncommittedEntry]); export const pickOfTheDayLedger = z.object({entries: z.array(pickOfTheDayLedgerEntry), entry_count: z.number().int(), sealed_count: z.number().int(), opened_count: z.number().int(), uncommitted_count: z.number().int()}); export const responseMeta = z.object({request_id: z.string(), cached: z.boolean(), cache_age_s: z.number().int().optional(), cost: z.number().int(), ranking_generation: z.number().int().optional(), ranking_as_of: z.string().optional(), directional_source: z.enum(["live", "degraded"]).optional(), ranking_source: z.enum(["live", "db_only"]).optional(), category_skill_source: z.enum(["live", "partial", "degraded", "unavailable"]).optional(), category_skill_model_version: z.string().optional(), category_skill_taxonomy_version: z.string().optional(), category_skill_platform: z.literal("polymarket").optional(), category_skill_scope: z.literal("observed_goldsky_primary_taker_fill").optional(), category_skill_source_coverage: z.enum(["partial_whale_threshold_fills", "graded_wallet_fills"]).optional(), category_skill_observation_started_at: z.string().optional(), category_skill_model_operationally_degraded: z.boolean().optional(), category_skill_status_counts: z.object({live: z.number().int().gte(0), insufficient: z.number().int().gte(0), stale: z.number().int().gte(0), unknown: z.number().int().gte(0), degraded: z.number().int().gte(0)}).optional(), category_skill_base_payload_hash: z.string().optional(), category_skill_enriched_base_payload_hash: z.string().optional()}); export const getApiApiV1PickOfTheDayLedgerResponse = z.object({object: z.literal("pick_of_the_day_ledger"), data: pickOfTheDayLedger, meta: responseMeta}); 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 the Pick of the Day commitment ledger * * GET /api/v1/pick-of-the-day/ledger */ export const getApiApiV1PickOfTheDayLedger = async (args: GetApiApiV1PickOfTheDayLedgerArgs, options?: GetApiApiV1PickOfTheDayLedgerOptions) => { const {baseUrl = "https://api.0xinsider.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Query-Validation'] != null) headers.set("X-Query-Validation", String(args['X-Query-Validation'])) if (args['If-None-Match'] != null) headers.set("If-None-Match", String(args['If-None-Match'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/pick-of-the-day/ledger${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(getApiApiV1PickOfTheDayLedgerResponse, await res.json()) };