Skip to content

Commit

Permalink
typechain packages from npm
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherDedominici committed Jan 10, 2025
1 parent 22389d6 commit dcaee30
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
2 changes: 2 additions & 0 deletions v-next/example-project/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@

# Hardhat compilation (v2) support directory
/cache

/types
4 changes: 4 additions & 0 deletions v-next/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -28,6 +30,11 @@ const compileAction: NewTaskActionFunction<CompileActionArguments> = 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,
Expand Down Expand Up @@ -62,6 +69,91 @@ const compileAction: NewTaskActionFunction<CompileActionArguments> = 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<string, SuccessfulFileBuildResult>,
);

// console.log(artifactsPaths);

console.log("=========================================== BEFORE");

const { runTypeChain } = await import("typechain");

const cwd = process.cwd();

// console.log(cwd);

console.log(artifactsPaths);

const typechainOptions: Omit<RunTypeChainConfig, "filesToProcess"> = {
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, SuccessfulFileBuildResult>,
): string[] {
const artifactSet = new Set<string>();

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;

0 comments on commit dcaee30

Please sign in to comment.