import {z} from 'zod' export type GetApiApiV1WhaleTradesIdCounterpartiesExecutionsExecutionIdMakersArgs = {id: string, execution_id: string, snapshot_id: string, cursor?: string | undefined, limit?: number | undefined}; export type GetApiApiV1WhaleTradesIdCounterpartiesExecutionsExecutionIdMakersOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const counterpartyMatchBreakdown = z.object({match_type: z.enum(["COMPLEMENTARY", "MINT", "MERGE"]), maker_fill_count: z.number().int(), filled_shares: z.string()}); export const counterpartyParticipant = z.object({counterparty_key: z.string(), execution_wallet: z.string(), identity_status: z.enum(["resolved", "infrastructure", "unavailable"]), resolved_user_id: z.string().optional(), wallet_family: z.string().optional(), resolution_block: z.number().int().optional(), resolution_source: z.string().optional(), display_name: z.string().optional(), grade: z.string().optional(), last_traded_at: z.string().optional(), profile_segment: z.string().optional(), maker_fill_count: z.number().int(), filled_shares: z.string(), filled_usdc: z.string(), share_pct: z.string(), match_breakdown: z.array(counterpartyMatchBreakdown)}); export const counterpartyMakerPage = z.object({analysis_id: z.string(), snapshot_id: z.string(), execution_id: z.string(), items: z.array(counterpartyParticipant), next_cursor: z.string().optional()}); 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 getApiApiV1WhaleTradesIdCounterpartiesExecutionsExecutionIdMakersResponse = z.object({object: z.literal("counterparty_maker_page"), data: counterpartyMakerPage, 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 }; /** * Page maker counterparties * * GET /api/v1/whale-trades/{id}/counterparties/executions/{execution_id}/makers * * Also accepts auth: oauth2 */ export const getApiApiV1WhaleTradesIdCounterpartiesExecutionsExecutionIdMakers = async (args: GetApiApiV1WhaleTradesIdCounterpartiesExecutionsExecutionIdMakersArgs, options?: GetApiApiV1WhaleTradesIdCounterpartiesExecutionsExecutionIdMakersOptions) => { const {baseUrl = "https://api.0xinsider.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.snapshot_id != null) query.append("snapshot_id", String(args.snapshot_id)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/whale-trades/${encodeURIComponent(String(args.id))}/counterparties/executions/${encodeURIComponent(String(args.execution_id))}/makers${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(getApiApiV1WhaleTradesIdCounterpartiesExecutionsExecutionIdMakersResponse, await res.json()) };