import {z} from 'zod' export type GetApiV1TreasuryWithdrawalsIdArgs = {id: string}; export type GetApiV1TreasuryWithdrawalsIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const withdrawalDesiredFromLegResponse = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const withdrawalDesiredToLegResponse = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const withdrawalDesiredOverlay = z.object({from: withdrawalDesiredFromLegResponse, to: withdrawalDesiredToLegResponse}); export const withdrawalEstimatedFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const withdrawalEstimatedToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const withdrawalEstimatedOverlay = z.object({from: withdrawalEstimatedFromLeg, to: withdrawalEstimatedToLeg}); export const withdrawalActualFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const withdrawalActualToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const withdrawalActualOverlay = z.object({from: withdrawalActualFromLeg, to: withdrawalActualToLeg}); export const withdrawalStepEstimatedFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const withdrawalStepEstimatedToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const withdrawalStepEstimatedOverlay = z.object({from: withdrawalStepEstimatedFromLeg, to: withdrawalStepEstimatedToLeg}); export const withdrawalStepActualFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const withdrawalStepActualToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const withdrawalStepActualOverlay = z.object({from: withdrawalStepActualFromLeg, to: withdrawalStepActualToLeg}); export const stepFee = z.object({fee_amount: z.string(), fee_currency: z.string(), fee_type: z.string(), fee_metadata: z.record(z.string(), z.unknown()).optional()}); export const statusReason = z.object({error_code: z.string(), error_message: z.string()}); export const withdrawalStep = z.object({id: z.string(), withdrawal_id: z.string(), step_sequence: z.number().int(), step_type: z.enum(["transfer", "swap"]), estimated: withdrawalStepEstimatedOverlay, actual: withdrawalStepActualOverlay, transaction_hash: z.string().nullable().optional(), unsigned_transaction: z.string().nullable().optional(), fees: z.array(stepFee), provider_key: z.enum(["circle_mint", "kraken", "turnkey", "openfx", "zuba"]).nullable().optional(), status: z.enum(["created", "signature_requested", "signed", "submitted", "confirmed", "completed", "failed"]), status_reasons: z.array(statusReason).nullable().optional(), created_at: z.string(), updated_at: z.string(), signature_requested_at: z.string().nullable().optional(), signed_at: z.string().nullable().optional(), submitted_at: z.string().nullable().optional(), confirmed_at: z.string().nullable().optional(), completed_at: z.string().nullable().optional(), failed_at: z.string().nullable().optional()}); export const withdrawal = z.object({id: z.string(), workspace_id: z.string(), organization_reference_id: z.string().nullable().optional(), direction: z.literal("outbound"), desired: withdrawalDesiredOverlay, estimated: withdrawalEstimatedOverlay, actual: withdrawalActualOverlay, balance_status: z.enum(["unreserved", "awaiting_funds", "reserved"]).nullable(), balance_reserved_at: z.string().nullable(), steps: z.array(withdrawalStep), created_at: z.string(), updated_at: z.string(), expires_at: z.string().nullable()}); export const withdrawalResponse = z.object({data: withdrawal}); 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 withdrawal by ID * * GET /v1/treasury/withdrawals/{id} */ export const getApiV1TreasuryWithdrawalsId = async (args: GetApiV1TreasuryWithdrawalsIdArgs, options?: GetApiV1TreasuryWithdrawalsIdOptions) => { const {baseUrl = "https://api.tesser.xyz", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/treasury/withdrawals/${encodeURIComponent(String(args.id))}${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(withdrawalResponse, await res.json()) };