import {z} from 'zod' export type GetApiDepositsArgs = {account?: string | undefined, recipient?: string | undefined, address?: string | undefined, status?: (Array<'pending' | 'processing' | 'completed' | 'failed' | 'rejected' | 'ignored' | 'expecting_refund' | 'refunded' | 'delayed' | 'reconciliation_required'>) | undefined, excludeStatus?: (Array<'pending' | 'processing' | 'completed' | 'failed' | 'rejected' | 'ignored' | 'expecting_refund' | 'refunded' | 'delayed' | 'reconciliation_required'>) | undefined, chain?: Array | undefined, excludeChain?: Array | undefined, asset?: Array | undefined, excludeAsset?: Array | undefined, sender?: Array | undefined, excludeSender?: Array | undefined, txHash?: string | undefined, limit?: number | undefined, cursor?: string | undefined, includeSpam?: boolean | undefined, 'x-api-key'?: string | undefined}; export type GetApiDepositsOptions = {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 listDepositsResponse = z.object({deposits: z.array(depositListItem), nextCursor: z.string().nullable()}); 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 }; /** * List deposits * * GET /deposits * * Also accepts auth: internalProjectBearer */ export const getApiDeposits = async (args: GetApiDepositsArgs, options?: GetApiDepositsOptions) => { 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.account != null) query.append("account", String(args.account)) if (args.recipient != null) query.append("recipient", String(args.recipient)) if (args.address != null) query.append("address", String(args.address)) for (const item of args.status ?? []) query.append("status", String(item)) for (const item of args.excludeStatus ?? []) query.append("excludeStatus", String(item)) for (const item of args.chain ?? []) query.append("chain", String(item)) for (const item of args.excludeChain ?? []) query.append("excludeChain", String(item)) for (const item of args.asset ?? []) query.append("asset", String(item)) for (const item of args.excludeAsset ?? []) query.append("excludeAsset", String(item)) for (const item of args.sender ?? []) query.append("sender", String(item)) for (const item of args.excludeSender ?? []) query.append("excludeSender", String(item)) if (args.txHash != null) query.append("txHash", String(args.txHash)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.includeSpam != null) query.append("includeSpam", String(args.includeSpam)) 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${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(listDepositsResponse, await res.json()) };