import type { Abi, Address, Chain, ContractEventArgs, ContractEventName, ContractFunctionName, DecodeFunctionDataReturnType, EncodeFunctionDataParameters, GetContractEventsReturnType, GetContractReturnType, Hex, Log, PublicClient, Transport } from "viem"; import { BaseError } from "viem"; import type { BaseContractStateHuman, RawTx } from "../types/index.js"; import { Construct, type ConstructOptions } from "./Construct.js"; import type { IBaseContract, ParsedCall, ParsedCallArgs, ParsedCallV2 } from "./types.js"; /** * Arguments for constructing a {@link BaseContract}. **/ export interface BaseContractArgs { /** * Contract ABI used for encoding/decoding. **/ abi: abi; /** * On-chain address of the contract. **/ addr: Address; /** * Optional display name for the contract. **/ name?: string; /** * Contract version * @default 0 **/ version?: number | bigint; /** * Gearbox contract type identifier (hex bytes32 or parsed string). **/ contractType?: string; } /** * Options supplied to the {@link ContractParseError} constructor. **/ export interface ContractParseErrorOptions { /** * Address of the contract where parsing failed. **/ address: Address; /** * Raw calldata that could not be decoded. **/ callData: Hex; /** * Optional display name for the contract. **/ contractName?: string; } /** * Error thrown when calldata cannot be decoded against a contract's ABI. * Captures the target address and raw calldata for diagnostics. */ export declare class ContractParseError extends BaseError { readonly address: Address; readonly callData: Hex; readonly selector: Hex; constructor(cause: Error, options: ContractParseErrorOptions); } /** * Wrapper around a single on-chain contract, providing calldata decoding, * event fetching, and human-readable state output. * * @typeParam abi - Narrowed ABI type for this contract. **/ export declare class BaseContract extends Construct implements IBaseContract { /** * Viem contract instance for direct read calls **/ readonly contract: GetContractReturnType, Address>; /** * Contract ABI **/ readonly abi: abi; /** * Gearbox contract type identifier (e.g. `"CREDIT_MANAGER"`), or empty string if unknown. **/ readonly contractType: string; /** * Contract version number. * @default 0 **/ readonly version: number; /** * On-chain address of the contract. **/ readonly address: Address; /** * Display name for the contract. **/ readonly name: string; constructor(options: ConstructOptions, args: BaseContractArgs); /** {@inheritDoc IBaseContract.stateHuman} */ stateHuman(_?: boolean): BaseContractStateHuman; /** * Applies an on-chain event to update this contract's local state. * * @param _log - Decoded event log emitted by this contract. **/ processLog(_log: Log>): void; /** * Return parsed args and function name from calldata belonging to this contract * Target of the call is always this contract, but args can be parsed into calls to other contracts (de-facto recursive ParsedCall) * @param calldata * @returns */ parseFunctionData(calldata: Hex): ParsedCall; /** * Same as {@link parseFunctionData}, but throws {@link ContractParseError} if error occurs * @param callData * @returns */ mustParseFunctionData(callData: Hex): ParsedCall; /** * Parses viem-decoded contract function arguments to a map of named arguments * This default implementation uses abi-based parsing, you can override it, * but use this super implementation as fallback * @param params * @returns */ protected parseFunctionParams(params: DecodeFunctionDataReturnType): ParsedCallArgs; /** * Converts contract calldata to some human-friendly string * This is safe function which should not throw * @param calldata * @returns */ stringifyFunctionData(calldata: Hex): string; /** * Same as {@link stringifyFunctionData}, but throws if error occurs. * @param calldata - Raw ABI-encoded calldata. */ mustStringifyFunctionData(calldata: Hex): string; /** * Pretty-prints values of function arguments (do not include parameter names) * Can be overriden in classes, but use this super implementation as fallback * * @param decoded - Function arguments decoded by viem * @returns */ protected stringifyFunctionParams(decoded: DecodeFunctionDataReturnType): string[]; protected wrapParseCall(functionName: string, args: Record): ParsedCall; /** * Parses calldata into structured result with preserved original types. * When strict is true, throws {@link ContractParseError} on unknown selectors; * otherwise returns a fallback with the raw calldata. */ parseFunctionDataV2(calldata: Hex, strict?: boolean): ParsedCallV2; /** * Converts viem-decoded function arguments to a record preserving original types. * Override in subclasses to handle nesting (e.g., multicall inner calls). * @param strict - propagated from parseFunctionDataV2 for recursive parsing */ protected parseFunctionParamsV2(params: DecodeFunctionDataReturnType, _strict?: boolean): Record; protected wrapParseCallV2(functionName: string, rawArgs: Record): ParsedCallV2; /** * Creates a raw transaction for a function in this contract * @param parameters * @returns */ createRawTx | undefined = undefined>(parameters: Omit, "abi"> & { description?: string; }): RawTx; /** * Get events in safe manner, by bisecting block range if needed * * @deprecated TODO: this should be moved to viem transport * * @param eventName * @param fromBlock * @param toBlock * @param args * @param chunkSize * @returns */ getEvents>(eventName: EventName, fromBlock: bigint, toBlock: bigint, args?: ContractEventArgs ? EventName : ContractEventName> | undefined, chunkSize?: number): Promise>; }