import {z} from 'zod' export type GetApiApiDtaoValidatorYieldLatestV1Args = {hotkey?: string | undefined, netuid?: number | undefined, min_stake?: string | undefined, page?: number | undefined, limit?: number | undefined, order?: ('netuid_asc' | 'netuid_desc' | 'name_asc' | 'name_desc' | 'stake_asc' | 'stake_desc' | 'one_hour_apy_asc' | 'one_hour_apy_desc' | 'one_day_apy_asc' | 'one_day_apy_desc' | 'seven_day_apy_asc' | 'seven_day_apy_desc' | 'thirty_day_apy_asc' | 'thirty_day_apy_desc') | undefined}; export type GetApiApiDtaoValidatorYieldLatestV1Options = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiDtaoValidatorYieldLatestV1Response = 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({hotkey: z.object({ss58: z.string().optional(), hex: z.string().optional()}).optional(), name: z.string().optional(), netuid: z.number().int().optional(), block_number: z.number().int().optional(), timestamp: z.string().optional(), stake: z.string().optional(), one_hour_apy: z.string().optional(), one_day_apy: z.string().optional(), seven_day_apy: z.string().optional(), thirty_day_apy: z.string().optional(), one_day_epoch_participation: z.unknown(), seven_day_epoch_participation: z.unknown(), thirty_day_epoch_participation: 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 Validator Yield * * GET /api/dtao/validator/yield/latest/v1 */ export const getApiApiDtaoValidatorYieldLatestV1 = async (args: GetApiApiDtaoValidatorYieldLatestV1Args, options?: GetApiApiDtaoValidatorYieldLatestV1Options) => { 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.hotkey != null) query.append("hotkey", String(args.hotkey)) if (args.netuid != null) query.append("netuid", String(args.netuid)) if (args.min_stake != null) query.append("min_stake", String(args.min_stake)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.order != null) query.append("order", String(args.order)) if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/api/dtao/validator/yield/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(getApiApiDtaoValidatorYieldLatestV1Response, await res.json()) };