Skip to content

Commit 4a83f8f

Browse files
committed
typechain artifacts
Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com>
1 parent 3147301 commit 4a83f8f

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

.github/actions/generate-evm-artifacts/action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ runs:
2727
- name: Build Foundry
2828
shell: bash
2929
run: forge build --skip test script
30+
- name: Generate Typechain artifacts
31+
shell: bash
32+
run: npx ts-node scripts/typechainArtifacts.ts
3033
- name: Generate Typechain
3134
shell: bash
32-
run: npx typechain --target ethers-v5 "out/!(build-info)/**/+([a-zA-Z0-9_]).json" --out-dir typechain
35+
run: npx typechain --target ethers-v5 "typechain-artifacts" --out-dir typechain
3336
- name: Archive EVM artifacts (for caching)
3437
shell: bash
3538
env:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ out
3131
zkout
3232
cache-foundry
3333

34+
# Typechain
35+
.typechain-artifacts
36+
3437
# Upgradeability files
3538
.openzeppelin
3639

scripts/typechainArtifacts.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import fg from "fast-glob";
4+
5+
type ArtifactJson = {
6+
contractName?: string;
7+
[key: string]: unknown;
8+
};
9+
10+
const OUT_DIR = "out";
11+
const STAGE_DIR = ".typechain-artifacts";
12+
13+
function main() {
14+
if (fs.existsSync(STAGE_DIR)) {
15+
fs.rmdirSync(STAGE_DIR, { recursive: true });
16+
}
17+
fs.mkdirSync(STAGE_DIR, { recursive: true });
18+
19+
const files = fg.sync([`${OUT_DIR}/**/*.json`, `!${OUT_DIR}/build-info/**`], {
20+
dot: false,
21+
onlyFiles: true,
22+
});
23+
24+
const seen = new Map<string, string>(); // contractName -> first file path kept
25+
const dups: Array<{ name: string; kept: string; dropped: string }> = [];
26+
27+
for (const file of files) {
28+
const name = file.split("/").pop()?.split(".")[0];
29+
if (!name) continue;
30+
31+
const already = seen.get(name);
32+
if (already) {
33+
dups.push({ name, kept: already, dropped: file });
34+
continue;
35+
}
36+
37+
seen.set(name, file);
38+
39+
// One artifact per name => stable TypeChain inputs
40+
const dest = path.join(STAGE_DIR, `${name}.json`);
41+
fs.copyFileSync(file, dest);
42+
}
43+
44+
if (dups.length > 0) {
45+
console.warn(`\nTypeChain dedupe: dropped ${dups.length} duplicate contract names:\n`);
46+
}
47+
48+
console.log(`Staged ${seen.size} unique artifacts into ${STAGE_DIR}/`);
49+
}
50+
51+
main();

0 commit comments

Comments
 (0)