hardhat
Version:
Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
58 lines • 2.51 kB
TypeScript
/**
* A single field of a Solidity struct
*/
export interface StructMember {
name: string;
/**
* EIP-712 type string, or `undefined` if the type can't be encoded (e.g. mappings).
*/
type: string | undefined;
}
/**
* A Solidity struct extracted from a source AST (Abstract Syntax Tree).
*/
export interface CollectedStruct {
name: string;
members: StructMember[];
/**
* Project-relative source path. Used for diagnostics only.
*/
sourcePath: string;
}
/**
* A user-defined value type (`type Foo is bytes32;`) resolves to its
* underlying elementary type for EIP-712 encoding.
* The map is keyed by the user-defined value type definition's solc node id,
* which is what `referencedDeclaration` on a `UserDefinedTypeName` reference
* points to.
*/
export type UserDefinedValueTypeIndex = Map<number, Record<string, unknown>>;
/**
* Walks every AST in the build and indexes every `UserDefinedValueTypeDefinition`
* by its node `id`, mapping to its `underlyingType` (an `ElementaryTypeName`).
*
* User-defined value types can sit at file scope or inside a contract, and a
* struct in one source may reference a user-defined value type defined in
* another, so this must run across every AST in the build — not just the ones
* matched by the user's include globs.
*/
export declare function buildUserDefinedValueTypeIndex(asts: unknown[]): UserDefinedValueTypeIndex;
/**
* Returns every struct definition reachable from a solc source AST (Abstract Syntax Tree),
* including structs nested inside contracts.
*/
export declare function extractStructsFromAst(ast: unknown, sourcePath: string, userDefinedValueTypeI?: UserDefinedValueTypeIndex): CollectedStruct[];
/**
* Converts a solc `typeName` AST node into its EIP-712 type string, following
* the same conventions as `forge bind-json`:
*
* - elementary types pass through (`address`, `uint256`, `string`, ...)
* - enums → `uint8`
* - contracts / interfaces → `address`
* - structs → bare name (`Wallet.Person` → `Person`)
* - user-defined value types → underlying elementary type (`type Foo is bytes32` → `bytes32`)
* - arrays → `T[]` (dynamic) or `T[N]` (fixed)
* - mappings / functions → `undefined` (not EIP-712 encodable)
*/
export declare function encodeMemberType(typeName: unknown, userDefinedValueTypeI?: UserDefinedValueTypeIndex): string | undefined;
//# sourceMappingURL=ast-walker.d.ts.map