import {z} from 'zod' export type AnyOfParameter = {eq?: (string | null) | undefined, in?: (Array | null) | undefined, null?: (boolean | null) | undefined}; export type AccountParameter = {eq?: (string | null) | undefined, ne?: (string | null) | undefined, in?: (Array | null) | undefined, ni?: (Array | null) | undefined, eqx?: (string | null) | undefined, nex?: (string | null) | undefined, null?: (boolean | null) | undefined}; export type SmartRollupParameter = {eq?: (string | null) | undefined, ne?: (string | null) | undefined, in?: (Array | null) | undefined, ni?: (Array | null) | undefined}; export type Int64Parameter = {eq?: (number | null) | undefined, ne?: (number | null) | undefined, gt?: (number | null) | undefined, ge?: (number | null) | undefined, lt?: (number | null) | undefined, le?: (number | null) | undefined, in?: (Array | null) | undefined, ni?: (Array | null) | undefined, empty?: boolean | undefined}; export type OpHashParameter = {eq?: (string | null) | undefined, ne?: (string | null) | undefined, in?: (Array | null) | undefined, ni?: (Array | null) | undefined}; export type Int32Parameter = {eq?: (number | null) | undefined, ne?: (number | null) | undefined, gt?: (number | null) | undefined, ge?: (number | null) | undefined, lt?: (number | null) | undefined, le?: (number | null) | undefined, in?: (Array | null) | undefined, ni?: (Array | null) | undefined}; export type TimestampParameter = {eq?: (string | null) | undefined, ne?: (string | null) | undefined, gt?: (string | null) | undefined, ge?: (string | null) | undefined, lt?: (string | null) | undefined, le?: (string | null) | undefined, in?: (Array | null) | undefined, ni?: (Array | null) | undefined}; export type OperationStatusParameter = {eq?: (string | null) | undefined, ne?: (string | null) | undefined}; export type SortParameter = {asc?: (string | null) | undefined, desc?: (string | null) | undefined}; export type OffsetParameter = {el?: (number | null) | undefined, pg?: (number | null) | undefined, cr?: (number | null) | undefined}; export type SelectionParameter = {fields?: (Array | null) | undefined, values?: (Array | null) | undefined}; export type Symbols = 'None' | 'Btc' | 'Eur' | 'Usd' | 'Cny' | 'Jpy' | 'Krw' | 'Eth' | 'Gbp'; export type GetApiV1OperationsSrRecoverBondArgs = {anyof?: (AnyOfParameter | null) | undefined, staker?: (AccountParameter | null) | undefined, rollup?: (SmartRollupParameter | null) | undefined, id?: (Int64Parameter | null) | undefined, hash?: (OpHashParameter | null) | undefined, counter?: (Int32Parameter | null) | undefined, level?: (Int32Parameter | null) | undefined, timestamp?: (TimestampParameter | null) | undefined, status?: (OperationStatusParameter | null) | undefined, sender?: (AccountParameter | null) | undefined, sort?: (SortParameter | null) | undefined, offset?: (OffsetParameter | null) | undefined, limit?: number | undefined, select?: (SelectionParameter | null) | undefined, quote?: Symbols | undefined}; export type GetApiV1OperationsSrRecoverBondOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const alias = z.object({alias: z.string().nullable().optional(), address: z.string()}); export const operationError = z.object({type: z.string()}); export const quoteShort = z.object({btc: z.number().nullable().optional(), eur: z.number().nullable().optional(), usd: z.number().nullable().optional(), cny: z.number().nullable().optional(), jpy: z.number().nullable().optional(), krw: z.number().nullable().optional(), eth: z.number().nullable().optional(), gbp: z.number().nullable().optional()}); export const smartRollupRecoverBondOperation = z.object({type: z.string().optional(), id: z.number().int().optional(), level: z.number().int().optional(), timestamp: z.string().optional(), hash: z.string(), sender: alias, counter: z.number().int().optional(), gasLimit: z.number().int().optional(), gasUsed: z.number().int().optional(), storageLimit: z.number().int().optional(), bakerFee: z.number().int().optional(), status: z.string(), rollup: alias.nullable().optional(), staker: alias.nullable().optional(), bond: z.number().int().optional(), errors: z.array(operationError).nullable().optional(), quote: quoteShort.nullable().optional()}); export const getApiV1OperationsSrRecoverBondResponse = z.array(smartRollupRecoverBondOperation); 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 smart rollup recover bond * * GET /v1/operations/sr_recover_bond */ export const getApiV1OperationsSrRecoverBond = async (args: GetApiV1OperationsSrRecoverBondArgs, options?: GetApiV1OperationsSrRecoverBondOptions) => { const {baseUrl = "https://api.tzkt.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.anyof != null) query.append("anyof", JSON.stringify(args.anyof)) if (args.staker != null) query.append("staker", JSON.stringify(args.staker)) if (args.rollup != null) query.append("rollup", JSON.stringify(args.rollup)) if (args.id != null) query.append("id", JSON.stringify(args.id)) if (args.hash != null) query.append("hash", JSON.stringify(args.hash)) if (args.counter != null) query.append("counter", JSON.stringify(args.counter)) if (args.level != null) query.append("level", JSON.stringify(args.level)) if (args.timestamp != null) query.append("timestamp", JSON.stringify(args.timestamp)) if (args.status != null) query.append("status", JSON.stringify(args.status)) if (args.sender != null) query.append("sender", JSON.stringify(args.sender)) if (args.sort != null) query.append("sort", JSON.stringify(args.sort)) if (args.offset != null) query.append("offset", JSON.stringify(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.select != null) query.append("select", JSON.stringify(args.select)) if (args.quote != null) query.append("quote", String(args.quote)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/operations/sr_recover_bond${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(getApiV1OperationsSrRecoverBondResponse, await res.json()) };