import {z} from 'zod' export type GetApiApiV1GovernorEnqueuedVaasChainArgs = {page?: number | undefined, pageSize?: number | undefined, sortOrder?: ('ASC' | 'DESC') | undefined}; export type GetApiApiV1GovernorEnqueuedVaasChainOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const vaaChainID = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(4), z.literal(5), z.literal(6), z.literal(8), z.literal(13), z.literal(14), z.literal(15), z.literal(16), z.literal(18), z.literal(19), z.literal(20), z.literal(21), z.literal(22), z.literal(23), z.literal(24), z.literal(25), z.literal(26), z.literal(29), z.literal(30), z.literal(31), z.literal(32), z.literal(33), z.literal(38), z.literal(39), z.literal(40), z.literal(41), z.literal(42), z.literal(44), z.literal(45), z.literal(46), z.literal(47), z.literal(48), z.literal(49), z.literal(50), z.literal(51), z.literal(52), z.literal(53), z.literal(54), z.literal(55), z.literal(56), z.literal(57), z.literal(58), z.literal(59), z.literal(60), z.literal(61), z.literal(62), z.literal(63), z.literal(64), z.literal(65), z.literal(66), z.literal(67), z.literal(68), z.literal(69), z.literal(70), z.literal(71), z.literal(72), z.literal(73), z.literal(3104), z.literal(4000), z.literal(4001), z.literal(4002), z.literal(4003), z.literal(4004), z.literal(4005), z.literal(4006), z.literal(4007), z.literal(4008), z.literal(4009), z.literal(10002), z.literal(10003), z.literal(10004), z.literal(10005), z.literal(10006), z.literal(10007), z.literal(10009), z.literal(65000)]); export const governorEnqueuedVaaDetail = z.object({chainId: vaaChainID.optional(), emitterAddress: z.string().optional(), notionalValue: z.number().int().optional(), releaseTime: z.number().int().optional(), sequence: z.string().optional(), txHash: z.string().optional()}); export const responseResponsePagination = z.object({next: z.string().optional()}); export const responseResponseArrayGovernorEnqueuedVaaDetail = z.object({data: z.array(governorEnqueuedVaaDetail).optional(), pagination: responseResponsePagination.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 }; /** * Returns all enqueued VAAs for a given blockchain. * * GET /api/v1/governor/enqueued_vaas/:chain */ export const getApiApiV1GovernorEnqueuedVaasChain = async (args: GetApiApiV1GovernorEnqueuedVaasChainArgs, options: GetApiApiV1GovernorEnqueuedVaasChainOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/governor/enqueued_vaas/:chain${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(responseResponseArrayGovernorEnqueuedVaaDetail, await res.json()) };