import { type PublicRpcSchema, type Transport } from "viem"; /** Schema entry for `eth_getLogs` extracted from viem's {@link PublicRpcSchema}. */ type EthGetLogsSchema = Extract; /** * Filter parameter for `eth_getLogs` as defined by viem's {@link PublicRpcSchema}. * A discriminated union of block-range filters and block-hash filters. */ export type EthGetLogsFilter = EthGetLogsSchema["Parameters"][0]; /** Raw RPC return type for `eth_getLogs` (logs with hex-encoded quantities). */ export type EthGetLogsResult = EthGetLogsSchema["ReturnType"]; /** * Options controlling pagination behaviour of {@link logSplitterTransport}. */ export interface LogSplitterTransportOptions { /** * Acts as a min page size hint when there's no explit hint in rpc error message. * Has no effect once the page size is already below `softLimit`. */ softLimit?: number; /** * Initial page size. The block range is walked in `hardLimit`-sized pages * from the start without attempting the full range first. */ hardLimit?: number; } /** * @internal * Returns `true` when both `fromBlock` and `toBlock` are concrete hex-encoded * block numbers and `blockHash` is absent. Only fixed numeric ranges can be * split into sub-ranges for pagination. * * At the RPC transport level, block numbers are always `0x`-prefixed hex * strings, while named tags (`"latest"`, `"safe"`, etc.) are plain words. * The `0x` prefix check is sufficient to distinguish the two. * * @param filter - The `eth_getLogs` filter object. * @returns Whether the filter describes a fixed, splittable block range. */ export declare function isFixedBlockRange(filter: EthGetLogsFilter): boolean; /** * Returns `true` when the error message matches known RPC range/size limit * patterns. Transient errors (timeouts, rate limits, 5xx) are explicitly * excluded — they should be retried by the underlying transport. * * @param error - Any thrown value. * @returns Whether the error indicates a block-range or result-size limit. */ export declare function isRangeError(error: unknown): boolean; /** * @internal * Attempts to extract a concrete page-size hint from an error thrown by an * RPC provider. Two strategies are tried: * * 1. **Alchemy JSON details** — parses the `details` field of a * {@link HttpRequestError} for a suggested `[fromHex, toHex]` range and * computes the span as `toHex - fromHex + 1`. * 2. **DRPC decimal range** — matches `retry with the range -` and * computes the span as `to - from + 1`. * 3. **Generic N-blocks pattern** — matches `/ block(s)/i` in the * error message. * * @param error - Any thrown value. * @returns The suggested page size, or `null` if no hint could be extracted. */ export declare function parsePageSizeHint(error: unknown): number | null; /** * @internal * Callback that performs a single `eth_getLogs` RPC call for the given * inclusive block range `[from, to]`. */ export type CallRpcFn = (from: number, to: number) => Promise; /** * @internal * Fetches logs over `[from, to]` using a sequential linear walk with * dynamically adjustable page size. On range errors the page is bisected * (optionally capped by {@link LogSplitterTransportOptions.softLimit | softLimit}). * Reduced page sizes persist for all subsequent pages in the same call. * * @param callRpc - Callback that performs a single `eth_getLogs` RPC call. * @param from - Inclusive start block number. * @param to - Inclusive end block number. * @param options - Optional pagination limits. * @returns All logs in the requested range, concatenated in order. * * @throws {@link InvalidParamsRpcError} when `from > to`. * @throws The original error when a single-block request fails or the error * is not a recognised range error. */ export declare function fetchLogsWithPagination(callRpc: CallRpcFn, from: number, to: number, options?: LogSplitterTransportOptions): Promise; /** * Wraps a viem {@link Transport} to transparently split `eth_getLogs` requests * that exceed RPC provider block-range or result-size limits. * * Only requests with concrete numeric `fromBlock`/`toBlock` values (hex or * bigint) are intercepted. Calls using block tags (`"latest"`, `"earliest"`, * etc.) or `blockHash` are passed through unmodified. * * @param transport - The underlying viem transport to wrap. * @param options - Optional pagination configuration. * @returns A new transport that performs automatic log pagination. * * @example * ```ts * import { createPublicClient, http } from "viem"; * import { mainnet } from "viem/chains"; * import { logSplitterTransport } from "./logSplitterTransport.js"; * * const client = createPublicClient({ * chain: mainnet, * transport: logSplitterTransport(http("https://rpc.example.com"), { * hardLimit: 10_000, * softLimit: 2_000, * }), * }); * ``` */ export declare function logSplitterTransport(transport: Transport, logOptions?: LogSplitterTransportOptions): Transport; export {};