import type { Abi, Address, Chain, Hex, PublicClient, Transport } from "viem"; import type { MultiCall } from "../types/index.js"; import type { ILogger } from "../types/logger.js"; import type { BaseContract } from "./BaseContract.js"; import { TokensMeta } from "./TokensMeta.js"; import type { ParsedCall, ParsedCallV2 } from "./types.js"; /** * @internal * Conditional type that resolves to `BaseContract` when `T` is an ABI type, * or returns `T` unchanged otherwise. Used by register lookup methods to * provide strongly-typed contract references. */ export type ContractOrInterface = T extends Abi | readonly unknown[] ? BaseContract : T; /** * Central registry of all known contracts on a single chain. * * Used to share information between contracts, enables instances of {@link BaseContract} to discover each other * This is critical for parsing of calls that involve multiple contracts */ export declare class ChainContractsRegister { private readonly contracts; private readonly labels; readonly client: PublicClient; /** * Shared token metadata (symbol, decimals) for all tokens known on this chain. **/ readonly tokensMeta: TokensMeta; readonly logger?: ILogger; constructor(client: PublicClient, logger?: ILogger); /** * Clears all registered contracts, address labels, and token metadata. **/ resetContracts(): void; /** * Looks up a contract by address. * @param address - On-chain address. * @returns The contract wrapper, or `undefined` if not registered. */ getContract(address: Address): ContractOrInterface | undefined; /** * Looks up a contract by address, throwing if not found. * @param address - On-chain address. * @throws If no contract is registered at this address. */ mustGetContract(address: Address): ContractOrInterface; /** * Registers (or replaces) a contract at the given address. * @param address - On-chain address. * @param contract - Contract wrapper instance. */ setContract(address: Address, contract: BaseContract): void; /** * Assigns a human-readable label to an address for use in logging and * parsed call output. * @param address - On-chain address. * @param label - Static label string, or a function that receives the * current label and returns a new one. */ setAddressLabel(address: Address, label: string | ((oldLabel?: string) => string)): void; /** * Returns a display string for an address, incorporating its label if one exists. * @param address - On-chain address. * @param omitAddress - When `true`, returns only the label (no address prefix). * Falls back to the raw address when no label is set. */ labelAddress(address: Address, omitAddress?: boolean): string; /** * The viem {@link Chain} object for this register's connected client. **/ get chain(): Chain; /** * Numeric chain ID (e.g. `1` for Ethereum mainnet). **/ get chainId(): number; /** * Converts contract call into some human-friendly string * This method is safe and should not throw * @param address * @param calldata * @returns */ stringifyFunctionData(address: Address, calldata: Hex): string; /** * Converts multicalls into some human-friendly strings * This method is safe and should not throw * @param address * @param calldata * @returns */ stringifyMultiCall(calls: MultiCall[]): string[]; /** * Return args, function, type and address name from contract call * @param address * @param calldata * @returns */ parseFunctionData(address: Address, calldata: Hex): ParsedCall; /** * Converts multicalls into call info * @param address * @param calldata * @returns */ parseMultiCall(calls: MultiCall[]): ParsedCall[]; /** * Parses calldata for a contract at the given address, preserving original types. * When strict is true, throws on unknown address or selector; otherwise returns a fallback. */ parseFunctionDataV2(address: Address, calldata: Hex, strict?: boolean): ParsedCallV2; /** * Parses multicalls preserving original types. * When strict is true, throws on unknown targets or selectors. */ parseMultiCallV2(calls: MultiCall[], strict?: boolean): ParsedCallV2[]; }