import type { Address } from "viem"; import { type PublicClient, type Transport } from "viem"; import type { HttpRpcClientOptions } from "viem/utils"; import { type ICreditAccountsService } from "./accounts/index.js"; import type { BaseState, IBaseContract } from "./base/index.js"; import { ChainContractsRegister } from "./base/index.js"; import type { GearboxChain, NetworkType } from "./chain/chains.js"; import type { VersionRange } from "./constants/index.js"; import type { IAddressProviderContract } from "./core/index.js"; import { RWARegistry } from "./market/index.js"; import { MarketRegister } from "./market/MarketRegister.js"; import { PriceFeedRegister } from "./market/pricefeeds/index.js"; import type { PythOptions, RedstoneOptions } from "./market/pricefeeds/updates/index.js"; import type { PluginsMap } from "./plugins/index.js"; import { type IPoolsService } from "./pools/index.js"; import { type IRouterContract } from "./router/index.js"; import type { GearboxState, GearboxStateHuman, ILogger } from "./types/index.js"; /** * Serialised state format version, checked during hydration to detect * incompatible snapshots. **/ export declare const STATE_VERSION = 1; /** * Connection options for the underlying JSON-RPC provider. * * Supply **one** of the three variants: * - `rpcURLs` — the SDK creates a viem transport internally (with optional * fallback when multiple URLs are given). * - `transport` — bring your own viem `Transport`. * - `client` — bring your own fully-configured viem `PublicClient`. **/ export type ClientOptions = { /** * One or more JSON-RPC endpoint URLs. **/ rpcURLs: string[]; /** * Per-request timeout in milliseconds. **/ timeout?: number; /** * Number of automatic retries per RPC call. **/ retryCount?: number; /** * Low-level options forwarded to the viem HTTP transport. **/ httpTransportOptions?: HttpRpcClientOptions | undefined; } | { /** * Pre-built viem transport. **/ transport: Transport; } | { /** * Pre-built viem public client. **/ client: PublicClient; }; /** * Options for creating an {@link OnchainSDK} instance. * * @typeParam Plugins - Map of plugin names to plugin instances. **/ export interface OnchainSDKOptions { /** * Custom logger implementation. **/ logger?: ILogger; /** * When `true`, throw on unrecognised contract types instead of falling back to a generic contract wrapper. **/ strictContractTypes?: boolean; /** * Explicit gas limit for read-only `eth_call` requests. * `null` disables the gas limit entirely; `undefined` uses the SDK default (550M). */ gasLimit?: bigint | null; /** * Plugins that extend SDK functionality. **/ plugins?: Plugins; } /** * Options accepted by {@link OnchainSDK.attach}. **/ export interface AttachOptions { /** * Override address of the Gearbox AddressProvider contract. **/ addressProvider?: Address; /** * Addresses of market configurator contracts to load. **/ marketConfigurators?: Address[]; /** * Addresses of RWA factory contracts to load. **/ rwaFactories?: Address[]; /** * Pin SDK to a specific block number during attach. **/ blockNumber?: bigint | number; /** * Skip fetching updatable price feeds on attach and sync. **/ ignoreUpdateablePrices?: boolean; /** * Pool addresses whose markets should be skipped. **/ ignoreMarkets?: Address[]; /** * Options for Redstone price-feed updates. **/ redstone?: RedstoneOptions; /** * Options for Pyth price-feed updates. **/ pyth?: PythOptions; } /** * Options accepted by {@link OnchainSDK.hydrate}. **/ export interface HydrateOptions { /** * Pool addresses whose markets should be skipped. **/ ignoreMarkets?: Address[]; /** * Options for Redstone price-feed updates. **/ redstone?: RedstoneOptions; /** * Options for Pyth price-feed updates. **/ pyth?: PythOptions; } /** * Options for {@link OnchainSDK.syncState}, controlling which block to * sync to and whether updatable price feeds should be refreshed. **/ export interface SyncStateOptions { /** * Target block number to sync to. **/ blockNumber: bigint; /** * Block timestamp corresponding to `blockNumber`. **/ timestamp: bigint; /** * When `true`, skip refreshing updatable price feeds during this sync. **/ ignoreUpdateablePrices?: boolean; } /** * Single-chain entry point for the Gearbox SDK. * * `OnchainSDK` aggregates on-chain state for the Gearbox protocol — markets, * credit managers, pools, price oracles, and price feeds — into a single * queryable object that can be kept up-to-date via {@link syncState} or * serialised/restored via {@link state}/{@link hydrate}. * * Create an instance with `new OnchainSDK(network, clientOptions, options)`, * then call {@link attach} (live chain data) or {@link hydrate} (saved snapshot). * * @typeParam Plugins - Map of plugin names to plugin instances that extend * the SDK with additional domain-specific functionality. **/ export declare class OnchainSDK extends ChainContractsRegister { #private; /** Registered plugin instances, keyed by plugin name. */ readonly plugins: Plugins; /** * Gas limit applied to read-only `eth_call` requests. **/ readonly gasLimit: bigint | undefined; /** * When `true`, the SDK throws on unrecognised contract types. **/ readonly strictContractTypes: boolean; /** * Namespace for credit accounts operations. */ readonly accounts: ICreditAccountsService; /** * Namespace for pool operations. */ readonly pools: IPoolsService; /** * @param network - Gearbox network type (e.g. `"Mainnet"`, `"Monad"`). * @param clientOptions - Connection options (RPC URLs, transport, or client). * @param options - SDK configuration options. */ constructor(network: NetworkType, clientOptions: ClientOptions, options?: OnchainSDKOptions); /** * Initialises the SDK by reading live on-chain state. * * @param options - Attach configuration. * @throws {@link SdkAlreadyAttachedError} if already attached. */ attach(options?: AttachOptions): Promise; /** * Restores SDK state from a previously serialised {@link GearboxState} * snapshot, without making any on-chain calls. * * @param state - Serialised state obtained from {@link OnchainSDK.state}. * @param options - Hydrate configuration. * @throws {@link SdkAlreadyAttachedError} if already attached. * @throws {@link SdkStateVersionMismatchError} if snapshot version doesn't match. * @throws {@link SdkChainMismatchError} if snapshot network doesn't match. */ hydrate(state: GearboxState, options?: HydrateOptions): void; /** * Gearbox network type the SDK is connected to (e.g. `"Mainnet"`, `"Arbitrum"`). **/ get networkType(): NetworkType; /** * Whether the SDK has been initialised via {@link attach} or {@link hydrate}. **/ get attached(): boolean; /** * Returns a human-readable snapshot of the entire SDK state. * @param raw - When `true`, include raw numeric values alongside formatted ones. */ stateHuman(raw?: boolean): GearboxStateHuman; /** Serialisable snapshot of the current SDK state. */ get state(): GearboxState; /** * Incrementally updates SDK state by replaying on-chain events. * * @param opts - Target block and sync behaviour. * @returns `true` if the sync completed successfully. */ syncState(opts?: SyncStateOptions): Promise; /** * Block number that the SDK state corresponds to. * @throws {@link SdkNotAttachedError} if not attached. */ get currentBlock(): bigint; /** * Block timestamp (Unix epoch seconds) corresponding to {@link currentBlock}. * @throws {@link SdkNotAttachedError} if not attached. */ get timestamp(): bigint; /** * Global registry of all price feeds known to the SDK. * @throws {@link SdkNotAttachedError} if not attached. */ get priceFeeds(): PriceFeedRegister; /** GEAR governance token address, or `undefined` if not listed. */ get gear(): Address | undefined; /** * The chain's address provider contract. * @throws {@link SdkNotAttachedError} if not attached. */ get addressProvider(): IAddressProviderContract; /** * Registry of all loaded markets. * @throws {@link SdkNotAttachedError} if not attached. */ get marketRegister(): MarketRegister; /** * RWA register for RWA-wrapped underlying tokens and factories. * * @throws If the SDK has not been attached or hydrated yet. **/ get rwa(): RWARegistry; /** * @internal * Resolves the appropriate router contract for a given credit manager, * credit facade, or explicit version range. * * @param params - Identifies the context: a credit manager address/state, * a credit facade address/state, or a {@link VersionRange}. * @returns The matching router contract instance. * @throws If the credit facade version is unsupported or no router is * registered for the resolved version range. **/ routerFor(params: { creditManager: Address | BaseState | IBaseContract; } | { creditFacade: Address | BaseState | IBaseContract; } | VersionRange): IRouterContract; }