Skip to content

Commit 9e56604

Browse files
committed
generate abi.ts files as const
1 parent 55609d9 commit 9e56604

75 files changed

Lines changed: 45719 additions & 8595 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"prettier-fix": "prettier --write src",
1313
"setup": "sqd down && sqd up && sleep 2 && sqd migration:apply",
1414
"serve": "sqd serve",
15-
"typegen": "sqd typegen",
15+
"typegen": "sqd typegen && ts-node scripts/generate-abi-exports.ts",
1616
"migration:apply": "sqd migration:apply",
1717
"process:arbitrum": "sqd process:arbitrum",
1818
"process:base": "sqd process:base",

scripts/generate-abi-exports.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Generate .abi.ts files from raw JSON ABIs in ./abi/.
3+
* Each generated file re-exports the ABI with `as const` for proper viem type inference.
4+
*
5+
* Usage: ts-node scripts/generate-abi-exports.ts
6+
* Or via: pnpm run typegen (if wired into the command chain)
7+
*/
8+
import fs from 'fs'
9+
import path from 'path'
10+
11+
const abiDir = path.resolve(__dirname, '../abi')
12+
const outDir = path.resolve(__dirname, '../src/abi')
13+
14+
const jsonFiles = fs.readdirSync(abiDir).filter((f) => f.endsWith('.json'))
15+
16+
for (const file of jsonFiles) {
17+
const basename = path.parse(file).name
18+
const json = fs.readFileSync(path.join(abiDir, file), 'utf-8')
19+
const abi = JSON.parse(json)
20+
const outFile = path.join(outDir, `${basename}.abi.ts`)
21+
const content = `export const ABI_JSON = ${JSON.stringify(abi, null, 4)} as const\n`
22+
fs.writeFileSync(outFile, content)
23+
}
24+
25+
console.log(`Generated ${jsonFiles.length} .abi.ts files`)

0 commit comments

Comments
 (0)