import {z} from 'zod' export type GetApiV2WalletsBridgesArgs = {userId?: string | undefined, limit?: string | undefined, createdBefore?: string | undefined, createdAfter?: string | undefined}; export type GetApiV2WalletsBridgesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const bridgeAssetTransferObject = z.object({transferType: z.string().optional(), transferDetails: z.object({id: z.string().optional(), requestId: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), amount: z.number().optional(), status: z.enum(["NOT_INITIATED", "OPEN_QUOTE", "CREATED", "SOURCE_INITIATED", "SOURCE_PENDING", "SOURCE_PROCESSED", "SOURCE_FAILED", "DESTINATION_INITIATED", "DESTINATION_PENDING", "COMPLETED", "DESTINATION_FAILED", "QUOTE_FAILED", "UNKNOWN"]).optional(), source: z.object({userId: z.string().optional(), walletAddress: z.string().optional(), chain: z.string().optional(), currency: z.string().optional()}).optional(), destination: z.object({userId: z.string().optional(), walletAddress: z.string().optional(), chain: z.string().optional(), currency: z.string().optional()}).optional(), receipt: z.object({transactionHash: z.string().optional(), operations: z.object({mint: z.object({transactionHash: z.string().nullable().optional(), userOpHash: z.string().nullable().optional(), chain: z.string().nullable().optional()}).optional(), burn: z.object({transactionHash: z.string().nullable().optional(), userOpHash: z.string().nullable().optional(), chain: z.string().nullable().optional()}).optional(), approve: z.object({transactionHash: z.string().nullable().optional(), userOpHash: z.string().nullable().optional(), chain: z.string().nullable().optional()}).optional()}).optional()}).optional(), failedReason: z.string().nullable().optional(), fee: z.number().nullable().optional(), quoteInformation: z.object({sendGross: z.object({amount: z.string().optional(), currency: z.string().optional()}).optional(), sendNet: z.object({amount: z.string().optional(), currency: z.string().optional()}).optional(), railFee: z.object({amount: z.string().optional(), currency: z.string().optional()}).optional(), receiveGross: z.object({amount: z.string().optional(), currency: z.string().optional()}).optional(), receiveNet: z.object({amount: z.string().optional(), currency: z.string().optional()}).optional(), rate: z.string().optional(), expiresAt: z.string().optional()}).optional()}).optional()}); export const bridgeAssetTransferListObject = z.object({count: z.number().int().optional(), data: z.array(bridgeAssetTransferObject).optional(), nextCursor: z.string().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 }; /** * List all bridging requests * * GET /v2/wallets/bridges */ export const getApiV2WalletsBridges = async (args: GetApiV2WalletsBridgesArgs, options?: GetApiV2WalletsBridgesOptions) => { const {baseUrl = "https://production.hifibridge.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.userId != null) query.append("userId", String(args.userId)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.createdBefore != null) query.append("createdBefore", String(args.createdBefore)) if (args.createdAfter != null) query.append("createdAfter", String(args.createdAfter)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/wallets/bridges${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(bridgeAssetTransferListObject, await res.json()) };