/** * TypedContract type definitions for ethers v6 with abitype. * * This is a local copy of types from ethers-abitype to avoid the global * abitype module augmentation that pollutes AddressType with `string | Addressable`, * which breaks viem type compatibility. * * @see https://github.com/ethers-io/ethers.js/issues/4475 */ import type { BaseContract, ContractTransaction, ContractTransactionResponse, DeferredTopicFilter, EventFragment, FunctionFragment, Result, Overrides } from 'ethers'; import type { Abi, AbiParametersToPrimitiveTypes, ExtractAbiEvent, ExtractAbiEventNames, ExtractAbiEvents, ExtractAbiFunction, ExtractAbiFunctionNames, ExtractAbiFunctions } from 'abitype'; type AsArray = T extends readonly unknown[] ? T : never; export type TypedContractFunctionResult['outputs']>> = TOutputArgs extends readonly [] ? void : TOutputArgs extends readonly [infer Arg] ? Arg : TOutputArgs; export type TypedFragment = ExtractAbiFunction> = Omit & { name: TFunction['name']; type: TFunction['type']; inputs: TFunction['inputs']; outputs: TFunction['outputs']; stateMutability: TFunction['stateMutability']; }; export interface TypedContractFunction = ExtractAbiFunction, TInputArgs extends readonly unknown[] = AsArray>, TResult = TypedContractFunctionResult, TFragment = TypedFragment> { (...args: [...TInputArgs, overrides?: Overrides]): Promise; /** * The name of the Contract method. */ name: TFunctionName; /** * The fragment of the Contract method. This will throw on ambiguous * method names. */ fragment: TFragment; /** * Returns the fragment constrained by %%args%%. This can be used to * resolve ambiguous method names. */ getFragment(...args: [...TInputArgs]): TFragment; /** * Returns a populated transaction that can be used to perform the * contract method with %%args%%. */ populateTransaction(...args: [...TInputArgs, overrides?: Overrides]): Promise; /** * Call the contract method with %%args%% and return the value. * * If the return value is a single type, it will be dereferenced and * returned directly, otherwise the full Result will be returned. */ staticCall(...args: [...TInputArgs, overrides?: Overrides]): Promise; /** * Send a transaction for the contract method with %%args%%. */ send(...args: [...TInputArgs, overrides?: Overrides]): Promise; /** * Estimate the gas to send the contract method with %%args%%. */ estimateGas(...args: [...TInputArgs, overrides?: Overrides]): Promise; /** * Call the contract method with %%args%% and return the Result * without any dereferencing. */ staticCallResult(...args: [...TInputArgs, overrides?: Overrides]): Promise; } export interface TypedContractEvent = ExtractAbiEvent, TEventArgs extends readonly unknown[] = AsArray>>> { (...args: [...TEventArgs]): DeferredTopicFilter; /** * The name of the Contract event. */ name: TEventName; /** * The fragment of the Contract event. This will throw on ambiguous * method names. */ fragment: EventFragment; /** * Returns the fragment constrained by %%args%%. This can be used to * resolve ambiguous event names. */ getFragment(...args: [...TEventArgs]): EventFragment; } export type TypedContract = Omit & { [Method in ExtractAbiFunctionNames]: TypedContractFunction; } & { /** * Return the function for a given name. This is useful when a contract * method name conflicts with a JavaScript name such as ``prototype`` or * when using a Contract programatically. */ getFunction>(key: T | TypedFragment): TypedContractFunction; /** * Return the event for a given name. This is useful when a contract * event name conflicts with a JavaScript name such as ``prototype`` or * when using a Contract programatically. */ getEvent>(key: T | EventFragment): TypedContractEvent; /** * All the Events available on this contract. */ filters: { [EventName in ExtractAbiEventNames]: TypedContractEvent; }; }; export {};