import {z} from 'zod' export type FundWalletAmountDTO = {amount: number, token: 'usdxm', chain: 'arbitrum-sepolia' | 'avalanche-fuji' | 'base-sepolia' | 'ethereum-sepolia' | 'optimism-sepolia' | 'polygon-amoy' | 'sei-atlantic-2-testnet' | 'skale-nebula-testnet' | 'soneium-minato-testnet' | 'viction-testnet' | 'solana' | 'stellar'}; export type CreateApiV1Alpha2WalletsWalletLocatorBalancesArgs = {'X-API-KEY': string, walletLocator: string, body: FundWalletAmountDTO}; export type CreateApiV1Alpha2WalletsWalletLocatorBalancesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const walletBalanceResponseDTO = z.array(z.object({token: z.enum(["ape", "bnb", "coti", "eth", "pathusd", "matic", "mnt", "pol", "plume", "sei", "chz", "avax", "xai", "fuel", "hbar", "vic", "ip", "zcx", "u2u", "flow", "usdc", "usdce", "busd", "usdxm", "usdt", "credit", "usdf", "pyusd0", "eurc", "usdg", "weth", "degen", "superverse", "pirate", "wld", "xmeme", "alphausd", "betausd", "thetausd", "wirex-usdc", "bonk", "phantom-cash", "xlm", "usdm0", "usdm1", "mgusd", "wirex-usdc", "sol", "sui", "apt", "sfuel", "xion"]), decimals: z.number(), balances: z.record(z.string(), z.string())})); 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 }; /** * Fund Wallet * * POST /v1-alpha2/wallets/{walletLocator}/balances */ export const createApiV1Alpha2WalletsWalletLocatorBalances = async (args: CreateApiV1Alpha2WalletsWalletLocatorBalancesArgs, options?: CreateApiV1Alpha2WalletsWalletLocatorBalancesOptions) => { const {baseUrl = "https://staging.crossmint.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-API-KEY'] != null) headers.set("X-API-KEY", String(args['X-API-KEY'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1-alpha2/wallets/${encodeURIComponent(String(args.walletLocator))}/balances${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(walletBalanceResponseDTO, await res.json()) };