|
2 | 2 | /** |
3 | 3 | * Build precompile contracts (excluding testdata, testutil) in OpenZeppelin style: |
4 | 4 | * - dist/precompiles/ : .sol sources |
5 | | - * - dist/abi/ : ABI-only JSON per contract |
| 5 | + * - dist/abi/ : ABI-only JSON + .ts (as const); tsc emits .js + .d.ts |
6 | 6 | * |
7 | 7 | * Run from contracts directory: pnpm run build:precompiles |
8 | 8 | */ |
@@ -80,14 +80,22 @@ function buildPrecompiles() { |
80 | 80 | if (!sourceName || !sourceName.startsWith("solidity/precompiles/")) continue; |
81 | 81 |
|
82 | 82 | const relFromSolidity = sourceName.replace(/^solidity\//, ""); // precompiles/bank/IBank.sol |
| 83 | + const contractName = relFromSolidity.replace(/\.sol$/, "").split("/").pop(); // e.g. IBank |
83 | 84 | const solPath = join(SOLIDITY_SOURCE, relFromSolidity); |
84 | 85 | const abiOutPath = join(DIST_ABI, relFromSolidity.replace(".sol", ".json")); |
| 86 | + const abiTsOutPath = join(DIST_ABI, relFromSolidity.replace(".sol", ".ts")); |
85 | 87 | const solOutPath = join(DIST, relFromSolidity); |
86 | 88 |
|
87 | 89 | ensureDir(dirname(abiOutPath)); |
88 | 90 | ensureDir(dirname(solOutPath)); |
89 | 91 |
|
90 | | - writeFileSync(abiOutPath, JSON.stringify(artifact.abi ?? [], null, 2), "utf8"); |
| 92 | + const abi = artifact.abi ?? []; |
| 93 | + writeFileSync(abiOutPath, JSON.stringify(abi, null, 2), "utf8"); |
| 94 | + writeFileSync( |
| 95 | + abiTsOutPath, |
| 96 | + `export const ${contractName}_ABI = ${JSON.stringify(abi, null, 2)} as const;\n`, |
| 97 | + "utf8" |
| 98 | + ); |
91 | 99 | if (existsSync(solPath)) { |
92 | 100 | cpSync(solPath, solOutPath); |
93 | 101 | copiedSol.add(relFromSolidity); |
|
0 commit comments