import {z} from 'zod' export type GetApiUtxoManagementVaultAccountIdAssetIdUnspentOutputsArgs = {vaultAccountId: unknown, assetId: string, pageCursor?: string | undefined, pageSize?: number | undefined, sort?: ('AMOUNT' | 'CONFIRMATIONS') | undefined, order?: ('ASC' | 'DESC') | undefined, includeAllLabels?: Array | undefined, includeAnyLabels?: Array | undefined, excludeAnyLabels?: Array | undefined, includeStatuses?: Array | undefined, address?: string | undefined, txHash?: string | undefined, txId?: string | undefined, minAmount?: string | undefined, maxAmount?: string | undefined}; export type GetApiUtxoManagementVaultAccountIdAssetIdUnspentOutputsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const utxoInput2 = z.object({txHash: z.string().optional(), index: z.number().int().optional()}); export const utxoOutput = z.object({input: utxoInput2, utxoId: z.string(), address: z.string(), amount: z.string(), confirmations: z.number().int().optional(), status: z.enum(["PENDING", "AVAILABLE", "FROZEN", "SELECTED"]), isChange: z.boolean().optional(), isCoinbase: z.boolean().optional(), fbTxId: z.string().optional(), createdByHash: z.string().optional(), spentByFbTxId: z.array(z.string()).optional(), createdByHeight: z.number().int().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), labels: z.array(z.string()).optional(), hasNativeAssets: z.boolean().optional()}); export const listUtxosResponse = z.object({data: z.array(utxoOutput), next: z.string().nullable().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 unspent outputs (UTXOs) * * GET /utxo_management/{vaultAccountId}/{assetId}/unspent_outputs */ export const getApiUtxoManagementVaultAccountIdAssetIdUnspentOutputs = async (args: GetApiUtxoManagementVaultAccountIdAssetIdUnspentOutputsArgs, options?: GetApiUtxoManagementVaultAccountIdAssetIdUnspentOutputsOptions) => { const {baseUrl = "https://api.fireblocks.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageCursor != null) query.append("pageCursor", String(args.pageCursor)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.order != null) query.append("order", String(args.order)) for (const item of args.includeAllLabels ?? []) query.append("includeAllLabels", String(item)) for (const item of args.includeAnyLabels ?? []) query.append("includeAnyLabels", String(item)) for (const item of args.excludeAnyLabels ?? []) query.append("excludeAnyLabels", String(item)) for (const item of args.includeStatuses ?? []) query.append("includeStatuses", String(item)) if (args.address != null) query.append("address", String(args.address)) if (args.txHash != null) query.append("txHash", String(args.txHash)) if (args.txId != null) query.append("txId", String(args.txId)) if (args.minAmount != null) query.append("minAmount", String(args.minAmount)) if (args.maxAmount != null) query.append("maxAmount", String(args.maxAmount)) const url = `${baseUrl.replace(/\/+$/, '')}/utxo_management/${encodeURIComponent(String(args.vaultAccountId))}/${encodeURIComponent(String(args.assetId))}/unspent_outputs${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(listUtxosResponse, await res.json()) };