import type { PrefixedHexString } from "./hex.js"; /** * A parameter of an ABI fragment. */ export interface AbiParameter { readonly name?: string; readonly type: string; readonly components?: readonly AbiParameter[]; readonly indexed?: boolean; } /** * An entry of a contract's ABI. Only the fields needed to encode values are * modeled. */ export interface AbiFragment { readonly type?: string; readonly name?: string; readonly inputs?: readonly AbiParameter[]; } /** * A parsed human-readable signature of a function, event or error. */ export interface AbiSignature { /** The keyword the signature starts with, if any. */ readonly kind?: "function" | "event" | "error" | "constructor"; /** * The name, or "" for a constructor or a bare parameter list, like * `(uint256,bool)`. */ readonly name: string; readonly inputs: readonly AbiParameter[]; /** * The return types, written as `f(uint256)(bool)` or * `f(uint256) returns (bool)`. They can hold custom types, like `IPool`, kept * as written, which aren't ABI types and must be resolved before decoding. */ readonly outputs: readonly AbiParameter[]; /** Set to true if the signature has the `anonymous` modifier of events. */ readonly anonymous?: boolean; } /** * A parsed human-readable signature of a function or error. */ export interface AbiFunctionSignature { /** The keyword the signature starts with, if any. */ readonly kind?: "function" | "error"; readonly name: string; readonly inputs: readonly AbiParameter[]; /** The return types. See `AbiSignature#outputs`. */ readonly outputs: readonly AbiParameter[]; } /** * A parsed human-readable signature of an event. */ export interface AbiEventSignature { /** The keyword the signature starts with, if any. */ readonly kind?: "event"; readonly name: string; readonly inputs: readonly AbiParameter[]; /** Whether the event is anonymous, so it doesn't log its topic. */ readonly anonymous: boolean; } /** * The signedness and size of a Solidity integer type. */ export interface IntType { readonly signed: boolean; readonly bits: number; } /** * The inclusive range of values that a Solidity integer type can hold. */ export interface IntTypeRange { readonly min: bigint; readonly max: bigint; } /** * Parses a Solidity integer type name, like `uint256` or `int128`, into its * signedness and size in bits. As in Solidity, `uint` and `int` are accepted as * aliases of the 256-bit types. * * @param type The type name to parse. * @returns The parsed type, or `undefined` if it isn't a Solidity integer type. */ export declare function parseIntType(type: string): IntType | undefined; /** * Returns the inclusive range of values that a Solidity integer type can hold. * * @param intType The integer type, as returned by {@link parseIntType}. * @returns The minimum and maximum values of the type. */ export declare function getIntTypeRange({ signed, bits }: IntType): IntTypeRange; /** * Returns the parameters of the constructor declared in an ABI. * * An ABI that declares no constructor yields an empty array, matching the * Solidity semantics of an implicit parameterless constructor. * * @param abi The ABI to read the constructor from. * @returns The constructor's parameters. */ export declare function getAbiConstructorParameters(abi: readonly AbiFragment[]): readonly AbiParameter[]; /** * ABI-encodes a list of values, as Solidity encodes a constructor's arguments * (i.e. without a function selector). * * Values are accepted in the same shapes that most Ethereum libraries accept: * integers as bigints, safe numbers, or decimal or hex strings; `bytes` as hex * strings or `Uint8Array`s; tuples as arrays or as objects keyed by component * name; and addresses with or without the "0x" prefix. * * @param parameters The ABI parameters to encode the values as. * @param values The values to encode, in the order of the parameters. * @returns The encoded values as a prefixed hex string, or "0x" if there are none. * @throws AbiParametersLengthMismatchError If the counts don't match. * @throws InvalidAbiValueError If a value can't be encoded as its type. * @throws AbiValueOutOfBoundsError If a numeric value is out of its type's range. * @throws UnsupportedAbiTypeError If a parameter's type can't be encoded. * @throws AbiEncodingFailedError If the encoder fails for any other reason. */ export declare function encodeAbiParameters(parameters: readonly AbiParameter[], values: readonly unknown[]): Promise; /** * Parses a human-readable signature, like `transfer(address,uint256)`. * * It also accepts parameter names, the `indexed` and data location keywords, * tuples written as `(...)` or `tuple(...)`, and whole Solidity declarations, * like `function balanceOf(address owner) external view returns (uint256);`. * Type aliases are normalized, so `uint` becomes `uint256` and `byte` becomes * `bytes1`, and function types must be written as `function`. Custom types, * like structs or contracts, are only accepted as return types, as resolving * them to ABI types needs their definitions. * * @param signature The signature to parse. * @returns The parsed signature. * @throws InvalidAbiSignatureError If the signature is invalid. */ export declare function parseAbiSignature(signature: string): AbiSignature; /** * Parses a human-readable signature of a function or error, like * `transfer(address,uint256)` or `error Unauthorized(address)`, accepting the * same syntax as `parseAbiSignature`. * * @param signature The signature to parse. * @returns The parsed signature. * @throws InvalidAbiSignatureError If the signature is invalid, has no name, or * is of an event or a constructor. */ export declare function parseAbiFunctionSignature(signature: string): AbiFunctionSignature; /** * Parses a human-readable signature of an event, like * `Transfer(address,address,uint256)`, accepting the same syntax as * `parseAbiSignature`. * * @param signature The signature to parse. * @returns The parsed signature. * @throws InvalidAbiSignatureError If the signature is invalid, has no name, has * return types, or is of a function, error or constructor. */ export declare function parseAbiEventSignature(signature: string): AbiEventSignature; /** * Parses a single human-readable parameter, like `uint256`, `address payable` * or `(address to, uint256 amount)[]`, accepting the same syntax as the * parameters of `parseAbiSignature`. * * @param parameter The parameter to parse. * @returns The parsed parameter. * @throws InvalidAbiSignatureError If the parameter is invalid, or isn't a * single one. */ export declare function parseAbiParameter(parameter: string): AbiParameter; /** * Returns the selector of a function or error: the first 4 bytes of the * keccak256 hash of its canonical signature. * * @param signature The parsed signature. * @returns The 4-byte selector, like `0xa9059cbb`. */ export declare function getAbiSelector(signature: AbiFunctionSignature): Promise; /** * Returns the topic of an event: the keccak256 hash of its canonical * signature, which non-anonymous events log as their first topic. * * @param signature The parsed signature. * @returns The 32-byte topic. */ export declare function getAbiEventTopic(signature: AbiEventSignature): Promise; export { AbiEncodingError, AbiEncodingFailedError, AbiParametersLengthMismatchError, AbiValueOutOfBoundsError, DuplicateAbiParameterNameError, InvalidAbiSignatureError, InvalidAbiValueError, UnsupportedAbiTypeError, isAbiEncodingError, isInvalidAbiSignatureError, type AbiEncodingErrorKind, type AnyAbiEncodingError, } from "./errors/abi.js"; //# sourceMappingURL=abi.d.ts.map