import { BaseError, type EIP1193RequestFn, type Transport, type TransportConfig } from "viem"; import type { HttpRpcClientOptions } from "viem/utils"; import { z } from "zod/v4"; import type { ILogger } from "../sdk/index.js"; export declare const providerConfigSchema: z.ZodObject<{ name: z.ZodString; url: z.ZodURL; cooldown: z.ZodOptional; httpTransportOptions: z.ZodOptional; wait: z.ZodOptional; }, z.core.$strip>]>>; fetchOptions: z.ZodOptional>; methods: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ exclude: z.ZodOptional>; }, z.core.$strip>]>>; retryCount: z.ZodOptional; retryDelay: z.ZodOptional; timeout: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>; export type ProviderConfig = z.infer; export interface ProviderStatus { id: string; status: "active" | "cooldown" | "standby"; } type OnRequestFn = (providerName: string, ...args: Parameters["onRequest"]>) => ReturnType["onRequest"]>; type OnResponseFn = (providerName: string, ...args: Parameters["onResponse"]>) => ReturnType["onResponse"]>; export declare const SelectionStrategy: z.ZodEnum<{ ordered: "ordered"; simple: "simple"; }>; /** * How to select the next transport * - simple: selects next transport after current that is not in cooldown by checking all transports in cyclic order * - ordered: will select first available transport that is not in cooldown */ export type SelectionStrategy = z.infer; /** * Schema without underlying transport configs */ export declare const revolverTransportConfigBaseSchema: z.ZodObject<{ selectionStrategy: z.ZodOptional>; key: z.ZodOptional; name: z.ZodOptional; defaultHTTPOptions: z.ZodOptional; wait: z.ZodOptional; }, z.core.$strip>]>>; fetchOptions: z.ZodOptional>; methods: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ exclude: z.ZodOptional>; }, z.core.$strip>]>>; retryCount: z.ZodOptional; retryDelay: z.ZodOptional; timeout: z.ZodOptional; }, z.core.$strip>>; defaultCooldown: z.ZodOptional; }, z.core.$strip>; export declare const revolverTransportConfigSchema: z.ZodUnion>; key: z.ZodOptional; name: z.ZodOptional; defaultHTTPOptions: z.ZodOptional; wait: z.ZodOptional; }, z.core.$strip>]>>; fetchOptions: z.ZodOptional>; methods: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ exclude: z.ZodOptional>; }, z.core.$strip>]>>; retryCount: z.ZodOptional; retryDelay: z.ZodOptional; timeout: z.ZodOptional; }, z.core.$strip>>; defaultCooldown: z.ZodOptional; providers: z.ZodArray; httpTransportOptions: z.ZodOptional; wait: z.ZodOptional; }, z.core.$strip>]>>; fetchOptions: z.ZodOptional>; methods: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ exclude: z.ZodOptional>; }, z.core.$strip>]>>; retryCount: z.ZodOptional; retryDelay: z.ZodOptional; timeout: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ selectionStrategy: z.ZodOptional>; key: z.ZodOptional; name: z.ZodOptional; defaultHTTPOptions: z.ZodOptional; wait: z.ZodOptional; }, z.core.$strip>]>>; fetchOptions: z.ZodOptional>; methods: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ exclude: z.ZodOptional>; }, z.core.$strip>]>>; retryCount: z.ZodOptional; retryDelay: z.ZodOptional; timeout: z.ZodOptional; }, z.core.$strip>>; defaultCooldown: z.ZodOptional; transports: z.ZodArray>; }, z.core.$strip>]>; export type RevolverTransportConfig = { logger?: ILogger; /** * When single http transport should retry? * Defaults to some less strict criteria, so it'll retry "blockNumber from the future" errors * * By viem's default, simple http transport retries LimitExceededRpcError.code, InternalRpcError.code and HTTP errors * so for things like ResourceNotFoundRpcError (eth_call with block number from other rps, which is yet in the future for current rpc) * it'll fail and not retry * https://github.com/wevm/viem/blob/3bc5e6f3c4a317441063342dd9ec2aaa7eb56b01/src/utils/buildRequest.ts#L269 */ shouldRetry?: ((iter: { count: number; error: Error; }) => Promise | boolean) | undefined; /** * Spying function that also returns provider name in additional to the request */ onRequest?: OnRequestFn; /** * Spying function that also returns provider name in additional to the response */ onResponse?: OnResponseFn; /** * Callback that is called when the transport is rotated */ onRotateSuccess?: (oldTransportName: string, newTransportName: string, reason?: BaseError) => void | Promise; /** * Callback that is called when the transport cannot be rotated */ onRotateFailed?: (oldTransportName: string, reason?: BaseError) => void | Promise; } & z.infer; export declare class NoAvailableTransportsError extends BaseError { statuses: ProviderStatus[]; constructor(statuses: ProviderStatus[], cause?: Error); } export interface RevolverTransportValue { /** * Manually try to rotate the transport * @param reason */ rotate: (reason?: BaseError) => Promise; /** * Returns the name of the current transport */ currentTransportName: () => string; /** * Returns statuses of all providers */ statuses: () => ProviderStatus[]; } export declare class RevolverTransport implements ReturnType> { #private; private overrides?; /** * Create a new RevolverTransport * RevolverTransport usues several RPC providers and rotates between them when requests fail * Failed transport goes into temporary cooldown, after which it can be tried again * When all transports are on cooldown, the transport will throw a NoAvailableTransportsError * @param config * @returns */ static create(config: RevolverTransportConfig): Transport<"revolver", RevolverTransportValue>; constructor(config: RevolverTransportConfig); get value(): RevolverTransportValue; request: EIP1193RequestFn; get config(): TransportConfig<"revolver">; /** * Manually rotate the transport * @param reason * @returns true if rotation was successful */ rotate(reason?: BaseError): Promise; } export {};