import {z} from 'zod' export type GetApiDepositsIdArgs = {id: string, 'x-api-key'?: string | undefined}; export type GetApiDepositsIdOptions = {baseUrl?: string | undefined, tenantApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const depositTimingEstimate = z.object({expectedSeconds: z.number().int().gte(0), softDelaySeconds: z.number().int().gte(0), escalatedDelaySeconds: z.number().int().gte(0)}); export const depositListItem = z.object({id: z.string(), chain: z.string(), txHash: z.string(), token: z.string(), tokenSymbol: z.string().nullable(), tokenDecimals: z.number().int().nullable(), targetTokenSymbol: z.string().nullable(), targetTokenDecimals: z.number().int().nullable(), amount: z.string(), sender: z.string(), recipient: z.string(), depositAddress: z.string(), targetChain: z.string(), targetToken: z.string(), status: z.enum(["pending", "processing", "completed", "failed", "rejected", "ignored", "expecting_refund", "refunded", "delayed", "reconciliation_required"]), sourceTxHash: z.string().nullable(), destinationTxHash: z.string().nullable(), sourceAmount: z.string().nullable(), destinationAmount: z.string().nullable(), sponsoredGasUsd: z.string().optional(), sponsoredBridgeFeeUsd: z.string().optional(), createdAt: z.string(), completedAt: z.string().nullable(), errorCode: z.string().nullable(), creditKind: z.enum(["deposit", "collector_return"]), retryable: z.boolean(), refundAttributions: z.array(z.object({submissionKey: z.string(), intentId: z.string(), state: z.string(), reason: z.string().nullable(), references: z.array(z.object({chain: z.string(), txHash: z.string(), vm: z.string().optional()})).optional(), credit: z.object({chain: z.string(), txHash: z.string(), account: z.string(), token: z.string(), amount: z.string()}).optional(), successorDepositId: z.string().optional()})).optional(), refundOf: z.array(z.object({depositId: z.string(), submissionKey: z.string()})).optional(), delivery: z.object({outcome: z.enum(["pending", "delivered", "returned", "failed", "unresolved"]), depositId: z.string().nullable(), reason: z.string().optional(), chain: z.string().optional(), token: z.string().optional(), recipient: z.string().optional(), amount: z.string().optional(), txHash: z.string().optional(), completedAt: z.string().optional()}).optional(), isSpam: z.boolean(), timing: depositTimingEstimate.optional()}); 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 a deposit * * GET /deposits/{id} * * Also accepts auth: internalProjectBearer */ export const getApiDepositsId = async (args: GetApiDepositsIdArgs, options?: GetApiDepositsIdOptions) => { const {baseUrl = "https://v1.orchestrator.rhinestone.dev/deposit-processor", fetch: fetchFn = fetch, tenantApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-api-key'] != null) headers.set("x-api-key", String(args['x-api-key'])) if (tenantApiKey !== undefined) headers.set("x-api-key", tenantApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/deposits/${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(depositListItem, await res.json()) };