import {z} from 'zod' export type GetApiApiV1WalletsWalletIdTransfersArgs = {blockchain?: ('ethereum' | 'arbitrum' | 'avalanche' | 'polygon' | 'plasma' | 'sepolia' | 'tron' | 'ton' | 'bitcoin' | 'spark') | undefined, token?: ('usdt' | 'xaut' | 'usat' | 'btc') | undefined, type?: ('sent' | 'received') | undefined, from?: (number | string) | undefined, to?: (number | string) | undefined, limit?: number | undefined, skip?: number | undefined, sort?: ('asc' | 'desc') | undefined, walletId: string}; export type GetApiApiV1WalletsWalletIdTransfersOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1WalletsWalletIdTransfersResponse = z.object({transfers: z.array(z.object({walletId: z.string().optional(), blockchain: z.string().optional(), token: z.string().optional(), transactionHash: z.string().optional(), transferIndex: z.number().int().optional(), blockNumber: z.number().int().optional(), amount: z.string().optional(), from: z.string().optional(), to: z.string().optional(), ts: z.number().int().optional(), transactionIndex: z.number().int().optional(), logIndex: z.number().int().optional(), label: z.string().optional(), type: z.enum(["sent", "received"]).optional()})).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 synced transfers for a wallet * * GET /api/v1/wallets/{walletId}/transfers */ export const getApiApiV1WalletsWalletIdTransfers = async (args: GetApiApiV1WalletsWalletIdTransfersArgs, options: GetApiApiV1WalletsWalletIdTransfersOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.blockchain != null) query.append("blockchain", String(args.blockchain)) if (args.token != null) query.append("token", String(args.token)) if (args.type != null) query.append("type", String(args.type)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.skip != null) query.append("skip", String(args.skip)) if (args.sort != null) query.append("sort", String(args.sort)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/wallets/${encodeURIComponent(String(args.walletId))}/transfers${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(getApiApiV1WalletsWalletIdTransfersResponse, await res.json()) };