From 7c17e940da0b6bb296b76d14632708fe53861427 Mon Sep 17 00:00:00 2001 From: Arthur Abeilice Date: Mon, 4 May 2026 21:13:31 -0300 Subject: [PATCH] chore(codegen): wire wagmi ABI codegen against smart-contracts submodule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - wagmi.config.ts: read ABIs from p2pix-smart-contracts/artifacts/contracts (P2Pix, Reputation, MockToken) and emit src/generated.ts with the @wagmi/cli actions plugin - package.json: add scripts * contracts:compile — installs submodule deps + runs `hardhat compile` * wagmi:gen — runs @wagmi/cli to (re)generate src/generated.ts * prewagmi:gen — chains contracts:compile before wagmi:gen * prestart — runs wagmi:gen, so `bun start` always has fresh ABIs - .gitignore: ignore src/generated.ts (regenerated on every prestart) Note: GraphQL/subgraph codegen is intentionally out of scope here — it will land in its own branch. --- .gitignore | 5 ++++- package.json | 6 +++++- wagmi.config.ts | 34 +++++++++++++++++++++++++++------- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index a5e73f8..1174f22 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,7 @@ vendor/ *.sw? .vercel -.env \ No newline at end of file +.env + +# Codegen output (regenerated by `bun run wagmi:gen`, runs on prestart) +src/generated.ts \ No newline at end of file diff --git a/package.json b/package.json index 1260b95..83007fa 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.2.0", "type": "module", "scripts": { + "prestart": "bun run wagmi:gen", "start": "vite --host=0.0.0.0 --port 3000", "build": "bun run type-check && bun run build-only", "preview": "vite preview", @@ -11,7 +12,10 @@ "lint": "eslint .", "lint:fix": "eslint . --fix", "format": "prettier --write \"src/**/*.{ts,vue,json}\"", - "format:check": "prettier --check \"src/**/*.{ts,vue,json}\"" + "format:check": "prettier --check \"src/**/*.{ts,vue,json}\"", + "contracts:compile": "cd p2pix-smart-contracts && bun install && bunx hardhat compile", + "prewagmi:gen": "bun run contracts:compile", + "wagmi:gen": "bun ./node_modules/@wagmi/cli/dist/esm/cli.js generate" }, "dependencies": { "@floating-ui/vue": "^1.1.11", diff --git a/wagmi.config.ts b/wagmi.config.ts index bf1f610..4afd535 100644 --- a/wagmi.config.ts +++ b/wagmi.config.ts @@ -1,12 +1,32 @@ import { defineConfig } from '@wagmi/cli'; -import { hardhat } from '@wagmi/cli/plugins'; +import { actions } from '@wagmi/cli/plugins'; +import { readFileSync } from 'node:fs'; +import { resolve } from 'node:path'; + +const artifactsRoot = resolve( + __dirname, + 'p2pix-smart-contracts/artifacts/contracts', +); + +const loadAbi = (relPath: string) => { + const json = JSON.parse( + readFileSync(resolve(artifactsRoot, relPath), 'utf8'), + ); + return json.abi as readonly unknown[]; +}; export default defineConfig({ - out: 'src/blockchain/abi.ts', - contracts: [], - plugins: [ - hardhat({ - project: 'p2pix-smart-contracts', - }), + out: 'src/generated.ts', + contracts: [ + { name: 'P2Pix', abi: loadAbi('p2pix.sol/P2PIX.json') as never }, + { + name: 'Reputation', + abi: loadAbi('Reputation.sol/Reputation.json') as never, + }, + { + name: 'MockToken', + abi: loadAbi('lib/mock/mockToken.sol/MockToken.json') as never, + }, ], + plugins: [actions()], });