import {z} from 'zod' export type GetApiApiOrderEventsSolanaDepositsAndWithdrawalsArgs = {fromBlock?: number | undefined, toBlock?: number | undefined}; export type GetApiApiOrderEventsSolanaDepositsAndWithdrawalsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const solanaCreateOrderEventDTO = z.object({blockNumber: z.number().int().optional(), blockTimestamp: z.number().int().optional(), txHash: z.string().nullable().optional(), from: z.string().nullable().optional(), to: z.string().nullable().optional(), token: z.string().nullable().optional(), amount: z.string().nullable().optional(), isDeposit: z.boolean().optional(), giveAmountUSD: z.number().nullable().optional()}); export const getApiApiOrderEventsSolanaDepositsAndWithdrawalsResponse = z.array(solanaCreateOrderEventDTO); 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 }; /** * Returns information about Solana transactions in a given block range * * GET /api/OrderEvents/solanaDepositsAndWithdrawals */ export const getApiApiOrderEventsSolanaDepositsAndWithdrawals = async (args: GetApiApiOrderEventsSolanaDepositsAndWithdrawalsArgs, options?: GetApiApiOrderEventsSolanaDepositsAndWithdrawalsOptions) => { const {baseUrl = "https://dln.debridge.finance", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.fromBlock != null) query.append("fromBlock", String(args.fromBlock)) if (args.toBlock != null) query.append("toBlock", String(args.toBlock)) const url = `${baseUrl.replace(/\/+$/, '')}/api/OrderEvents/solanaDepositsAndWithdrawals${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(getApiApiOrderEventsSolanaDepositsAndWithdrawalsResponse, await res.json()) };