import {z} from 'zod' export type GetApiWalletsWalletIdArgs = {walletId: string, filterByIsArchived?: boolean | undefined}; export type GetApiWalletsWalletIdOptions = {baseUrl?: string | undefined, ApiAccessKey?: string | undefined, fetch?: typeof fetch | undefined}; export const amount = z.object({assetType: z.string(), currentPrice: z.string().optional(), currentUSDValue: z.string().optional(), quantity: z.string()}); export const assetDetailsForWallet = z.object({assetType: z.string(), availableBalance: amount, stakedBalance: amount.optional(), totalBalance: amount, unclaimedBalance: amount.optional(), unvestedBalance: amount.optional(), unvestedUnstakeableBalance: amount.optional()}); export const signedAddressForWallet = z.object({address: z.string(), addressId: z.string(), addressSignaturePayload: z.string(), certChain: z.string().optional(), signature: z.string(), signatureVersion: z.enum(["V1", "V2"]).optional()}); export const depositInstruction = z.object({bankAddress: z.string(), bankName: z.string(), bankRoutingNumber: z.string(), bankSwiftCode: z.string(), beneficiaryAccountNumber: z.string(), beneficiaryAddress: z.string(), beneficiaryName: z.string(), memoField: z.string().optional()}); export const resourceType = z.enum(["VAULT", "WALLET", "ADDRESS", "STANDING_INSTRUCTION"]); export const walletDetails = z.object({assets: z.array(assetDetailsForWallet), depositAddress: signedAddressForWallet.optional(), depositInstruction: depositInstruction.optional(), isArchived: z.boolean(), isDefault: z.boolean(), networkId: z.string(), subaccountId: z.string().optional(), type: resourceType, vaultId: z.string(), vaultName: z.string(), walletId: z.string(), walletName: z.string()}); export const vaultsWalletResponse = z.object({data: walletDetails}); 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 }; /** * Wallet details for a wallet * * GET /wallets/{walletId} */ export const getApiWalletsWalletId = async (args: GetApiWalletsWalletIdArgs, options?: GetApiWalletsWalletIdOptions) => { const {baseUrl = "https://api.anchorage-staging.com/v2", fetch: fetchFn = fetch, ApiAccessKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.filterByIsArchived != null) query.append("filterByIsArchived", String(args.filterByIsArchived)) if (ApiAccessKey !== undefined) headers.set("Api-Access-Key", ApiAccessKey) const url = `${baseUrl.replace(/\/+$/, '')}/wallets/${encodeURIComponent(String(args.walletId))}${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(vaultsWalletResponse, await res.json()) };