import {z} from 'zod' export type GetApiV1Brc20SwapWithdrawProcessArgs = {id: string}; export type GetApiV1Brc20SwapWithdrawProcessOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1Brc20SwapWithdrawProcessResponse = z.object({code: z.number(), msg: z.string(), data: z.object({id: z.string().optional(), tick: z.string().optional(), amount: z.string().optional(), ts: z.number().optional(), status: z.string().optional(), totalConfirmedNum: z.number().optional(), totalNum: z.number().optional(), rollUpConfirmNum: z.number().optional(), rollUpTotalNum: z.number().optional(), approveConfirmNum: z.number().optional(), approveTotalNum: z.number().optional(), cancelConfirmedNum: z.number().optional(), cancelTotalNum: z.number().optional(), rollUpTxid: z.string().optional(), paymentTxid: z.string().optional(), inscribeTxid: z.string().optional(), approveTxid: z.string().optional(), completedAmount: z.string().optional(), matchHistory: z.array(z.object({approveInscriptionId: z.string().optional(), transferInscriptionId: z.string().optional(), tick: z.string().optional(), consumeAmount: z.string().optional(), remainAmount: z.string().optional(), approveAddress: z.string().optional(), transferAddress: z.string().optional(), txid: z.string().optional(), ts: z.number().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 }; /** * Gets the withdrawal progress for the specified ID. * * GET /v1/brc20-swap/withdraw_process */ export const getApiV1Brc20SwapWithdrawProcess = async (args: GetApiV1Brc20SwapWithdrawProcessArgs, options?: GetApiV1Brc20SwapWithdrawProcessOptions) => { const {baseUrl = "https://open-api.unisat.io", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.id != null) query.append("id", String(args.id)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/brc20-swap/withdraw_process${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(getApiV1Brc20SwapWithdrawProcessResponse, await res.json()) };