diff --git a/v-next/example-project/.gitignore b/v-next/example-project/.gitignore index b7b6eb4950..c54bf0021d 100644 --- a/v-next/example-project/.gitignore +++ b/v-next/example-project/.gitignore @@ -12,3 +12,5 @@ # Hardhat compilation (v2) support directory /cache + +/types diff --git a/v-next/hardhat/package.json b/v-next/hardhat/package.json index 7de30ed8aa..2862574c95 100644 --- a/v-next/hardhat/package.json +++ b/v-next/hardhat/package.json @@ -86,19 +86,23 @@ "@ignored/edr": "0.6.4-alpha.2", "@ignored/edr-optimism": "0.6.5-alpha.0", "@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.15", + "@ignored/hardhat-vnext-ethers": "workspace:^3.0.0-next.12", "@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.15", "@ignored/hardhat-vnext-zod-utils": "workspace:^3.0.0-next.15", "@nomicfoundation/solidity-analyzer": "^0.1.0", "@sentry/node": "^5.18.1", + "@typechain/ethers-v6": "^0.5.0", "adm-zip": "^0.4.16", "chalk": "^5.3.0", "debug": "^4.1.1", "enquirer": "^2.3.0", "ethereum-cryptography": "^2.2.1", + "ethers": "^6.13.5", "micro-eth-signer": "^0.13.0", "p-map": "^7.0.2", "semver": "^7.6.3", "tsx": "^4.11.0", + "typechain": "^8.3.1", "ws": "^8.18.0", "zod": "^3.23.8" } diff --git a/v-next/hardhat/src/internal/builtin-plugins/solidity/tasks/compile.ts b/v-next/hardhat/src/internal/builtin-plugins/solidity/tasks/compile.ts index 0bb657db05..9e957da6e3 100644 --- a/v-next/hardhat/src/internal/builtin-plugins/solidity/tasks/compile.ts +++ b/v-next/hardhat/src/internal/builtin-plugins/solidity/tasks/compile.ts @@ -1,4 +1,6 @@ +import type { SuccessfulFileBuildResult } from "../../../../types/solidity.js"; import type { NewTaskActionFunction } from "../../../../types/tasks.js"; +import type { PublicConfig as RunTypeChainConfig } from "typechain"; import { HardhatError } from "@ignored/hardhat-vnext-errors"; import { resolveFromRoot } from "@ignored/hardhat-vnext-utils/path"; @@ -28,6 +30,11 @@ const compileAction: NewTaskActionFunction = async ( return resolveFromRoot(process.cwd(), file); }); + // ---- + // solidity compilation here + // const compileSolOutput = await runSuper(taskArgs) + // await run(TASK_TYPECHAIN_GENERATE_TYPES, { compileSolOutput, quiet: taskArgs.quiet }) + // ---- const results = await solidity.build(rootPaths, { force, buildProfile: globalOptions.buildProfile, @@ -62,6 +69,91 @@ const compileAction: NewTaskActionFunction = async ( if (files.length === 0) { await solidity.cleanupArtifacts(rootPaths); } + + // --------------------------------------------------------- + // --------------------------------------------------------- + + const artifactsPaths = extractArtifactsPaths( + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- TMP + results as Map, + ); + + // console.log(artifactsPaths); + + console.log("=========================================== BEFORE"); + + const { runTypeChain } = await import("typechain"); + + const cwd = process.cwd(); + + // console.log(cwd); + + console.log(artifactsPaths); + + const typechainOptions: Omit = { + cwd, + allFiles: artifactsPaths, + // outDir: `${cwd}/typechain/types`, + target: "ethers-v6", + flags: { + alwaysGenerateOverloads: false, + discriminateTypes: false, // typechainCfg.discriminateTypes, + + tsNocheck: false, // typechainCfg.tsNocheck, + environment: "hardhat", + node16Modules: true, // typechainCfg.node16Modules, + }, + }; + + const result = await runTypeChain({ + ...typechainOptions, + filesToProcess: artifactsPaths, + }); + + console.log(`Successfully generated ${result.filesGenerated} typings!`); + + console.log("=========================================== AFTER"); + + // --------------------------------------------------------- + // --------------------------------------------------------- }; +function extractArtifactsPaths( + results: Map, +): string[] { + const artifactSet = new Set(); + + results.forEach((r) => { + r.contractArtifactsGenerated.forEach((artifactPath) => + artifactSet.add(artifactPath), + ); + }); + + return Array.from(artifactSet); +} + +// function getFQNamesFromCompilationOutput(compileSolOutput: any): string[] { +// const allFQNNamesNested = compileSolOutput.artifactsEmittedPerJob.map( +// (a: any) => { +// return a.artifactsEmittedPerFile.map((artifactPerFile: any) => { +// return artifactPerFile.artifactsEmitted.map((artifactName: any) => { +// return getFullyQualifiedName( +// artifactPerFile.file.sourceName, +// artifactName, +// ); +// }); +// }); +// }, +// ); + +// return allFQNNamesNested.flat(2); +// } + +// function getFullyQualifiedName( +// sourceName: string, +// contractName: string, +// ): string { +// return `${sourceName}:${contractName}`; +// } + export default compileAction;