import {z} from 'zod' export type GetApiApiAccountLatestV1Args = {address?: string | undefined, network?: ('finney' | 'nakamoto' | 'kusanagi') | undefined, balance_free_min?: string | undefined, balance_free_max?: string | undefined, balance_staked_min?: string | undefined, balance_staked_max?: string | undefined, balance_total_min?: string | undefined, balance_total_max?: string | undefined, order?: ('balance_free_asc' | 'balance_free_desc' | 'balance_staked_asc' | 'balance_staked_desc' | 'balance_total_asc' | 'balance_total_desc') | undefined, page?: number | undefined, limit?: number | undefined}; export type GetApiApiAccountLatestV1Options = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiAccountLatestV1Response = z.object({pagination: z.object({current_page: z.number().int().optional(), per_page: z.number().int().optional(), total_items: z.number().int().optional(), total_pages: z.number().int().optional(), next_page: z.number().int().optional(), prev_page: z.unknown()}).optional(), data: z.array(z.object({address: z.object({ss58: z.string().optional(), hex: z.string().optional()}).optional(), network: z.string().optional(), block_number: z.number().int().optional(), timestamp: z.string().optional(), rank: z.number().int().optional(), balance_free: z.string().optional(), balance_staked: z.string().optional(), balance_staked_alpha_as_tao: z.string().optional(), balance_staked_root: z.string().optional(), balance_total: z.string().optional(), created_on_date: z.string().optional(), created_on_network: z.string().optional(), coldkey_swap: z.unknown()})).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 }; /** * Get Account * * GET /api/account/latest/v1 */ export const getApiApiAccountLatestV1 = async (args: GetApiApiAccountLatestV1Args, options?: GetApiApiAccountLatestV1Options) => { const {baseUrl = "https://api.taostats.io", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.address != null) query.append("address", String(args.address)) if (args.network != null) query.append("network", String(args.network)) if (args.balance_free_min != null) query.append("balance_free_min", String(args.balance_free_min)) if (args.balance_free_max != null) query.append("balance_free_max", String(args.balance_free_max)) if (args.balance_staked_min != null) query.append("balance_staked_min", String(args.balance_staked_min)) if (args.balance_staked_max != null) query.append("balance_staked_max", String(args.balance_staked_max)) if (args.balance_total_min != null) query.append("balance_total_min", String(args.balance_total_min)) if (args.balance_total_max != null) query.append("balance_total_max", String(args.balance_total_max)) if (args.order != null) query.append("order", String(args.order)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/api/account/latest/v1${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(getApiApiAccountLatestV1Response, await res.json()) };