import fs from "node:fs" import path from "node:path" import { getChain } from "@biconomy/abstractjs-canary" import { http, type Address, type Hex, createPublicClient } from "viem" import { ALL_ADDRESSES } from "../src/addresses" import { BYTECODES } from "../src/bytecodes" const main = async () => { let fetched = false const bytecodes = await Promise.all( Object.values(ALL_ADDRESSES).map( async ({ address, chainId }, i: number) => { const publicClient = createPublicClient({ // @ts-ignore chain: getChain(chainId), transport: http() }) const name = Object.keys(ALL_ADDRESSES)[i] if (BYTECODES[address]) { return { address, bytecode: BYTECODES[address].bytecode as Hex, name } } const bytecode = await publicClient.getCode({ address }) fetched = true return { address, bytecode, name } } ) ) const bytecodesAsObject = bytecodes.reduce( (acc, { name, address, bytecode }) => { acc[address] = { name, address, bytecode: (bytecode ?? "0x") as Hex } return acc }, {} as Record ) if (fetched) { const fileContent = `import type { Hex, Address } from "viem"; \n\nexport const BYTECODES: Record = ${JSON.stringify(bytecodesAsObject, null, 2)};` fs.writeFileSync(path.join(__dirname, "../src/bytecodes.ts"), fileContent) } } main() .then(() => { console.log("done") }) .catch((error) => { console.error(error) })