import {z} from 'zod' export type GetApiV1TreasuryDepositsIdArgs = {id: string}; export type GetApiV1TreasuryDepositsIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const depositDesiredFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const depositDesiredToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const depositDesiredOverlay = z.object({from: depositDesiredFromLeg, to: depositDesiredToLeg}); export const depositEstimatedFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const depositEstimatedToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const depositEstimatedOverlay = z.object({from: depositEstimatedFromLeg, to: depositEstimatedToLeg}); export const depositActualFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const depositActualToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const depositActualOverlay = z.object({from: depositActualFromLeg, to: depositActualToLeg}); export const stepEstimatedFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const stepEstimatedToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const stepEstimatedOverlay = z.object({from: stepEstimatedFromLeg, to: stepEstimatedToLeg}); export const stepActualFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const stepActualToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const stepActualOverlay = z.object({from: stepActualFromLeg, to: stepActualToLeg}); 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 depositStep = z.object({id: z.string(), deposit_id: z.string(), step_sequence: z.number().int(), step_type: z.enum(["transfer", "swap"]), estimated: stepEstimatedOverlay, actual: stepActualOverlay, transaction_hash: z.string().nullable().optional(), fees: z.array(stepFee), provider_key: z.enum(["circle_mint", "kraken", "openfx", "turnkey", "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 deposit = z.object({id: z.string(), workspace_id: z.string(), organization_reference_id: z.string().nullable().optional(), direction: z.literal("inbound"), desired: depositDesiredOverlay, estimated: depositEstimatedOverlay, actual: depositActualOverlay, steps: z.array(depositStep).optional(), created_at: z.string(), updated_at: z.string(), expires_at: z.string().nullable().optional()}); export const createDepositResponse = z.object({data: deposit}); 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 deposit by ID * * GET /v1/treasury/deposits/{id} */ export const getApiV1TreasuryDepositsId = async (args: GetApiV1TreasuryDepositsIdArgs, options?: GetApiV1TreasuryDepositsIdOptions) => { 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/deposits/${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(createDepositResponse, await res.json()) };