|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This is a monorepo for the **Gnosis Bridge Monitor** — a real-time bridge transaction explorer for Gnosis Chain. It includes: |
| 8 | +- `/app` — Next.js frontend (bridge explorer UI) |
| 9 | +- `/envio-indexer` — Envio blockchain indexer (real-time event indexing via GraphQL) |
| 10 | +- `/alerts` — Slack alert system for validator balances and bridge limits |
| 11 | +- `/tests` — Test plans and records |
| 12 | + |
| 13 | +## Common Commands |
| 14 | + |
| 15 | +All commands run from the repo root using pnpm workspaces, or from within the package directory. |
| 16 | + |
| 17 | +### Frontend (`/app`) |
| 18 | +```bash |
| 19 | +pnpm app:dev # Start Next.js dev server |
| 20 | +pnpm app:build # Production build |
| 21 | +pnpm app:lint # Lint (ESLint + Prettier) |
| 22 | +pnpm app:lint:fix # Auto-fix lint issues |
| 23 | +cd app && pnpm typechain # Regenerate TypeChain types from ABIs |
| 24 | +``` |
| 25 | + |
| 26 | +### Indexer (`/envio-indexer`) |
| 27 | +```bash |
| 28 | +pnpm indexer:dev # Start indexer in dev mode |
| 29 | +pnpm indexer:codegen # Regenerate types from config.yaml |
| 30 | +cd envio-indexer && pnpm mocha # Run indexer tests |
| 31 | +``` |
| 32 | + |
| 33 | +### Alerts (`/alerts`) |
| 34 | +```bash |
| 35 | +cd alerts && pnpm dev # Run alerts service with ts-node |
| 36 | +cd alerts && pnpm build # Compile TypeScript |
| 37 | +``` |
| 38 | + |
| 39 | +## Architecture |
| 40 | + |
| 41 | +### Frontend (`/app/src/`) |
| 42 | + |
| 43 | +**Tech stack:** Next.js 15 + React 18, Ethers.js v5 (legacy) + Viem v2 (modern), Web3Onboard v2 (wallet), Styled Components, SWR (data fetching), TypeChain (contract types). |
| 44 | + |
| 45 | +**Key structural patterns:** |
| 46 | +- Pages in `/app/pages/bridge-explorer/` — each route has a corresponding `pagePartials/` folder for page-specific components |
| 47 | +- `NextPageWithLayout` pattern for per-page layouts; `SingleColumnLayout` is the default |
| 48 | +- Provider tree in `_app.tsx`: `Web3ConnectionProvider` (dynamic/no-SSR) → `ThemeProvider` → `TransactionNotificationProvider` → `TokenListProvider` → `ValidatorsProvider` |
| 49 | +- Contract ABIs live in `src/abis/` and generate TypeChain types via `pnpm typechain` |
| 50 | +- Bridge and chain configuration is centralized in `src/constants/` (bridges, validators, chains, contracts) |
| 51 | + |
| 52 | +**Bridge types supported:** |
| 53 | +- XDAI Bridge: native token bridge (DAI/USDS) |
| 54 | +- OmniBridge (AMB): multi-token bridge (USDC, USDT, ERC-20s) |
| 55 | +- USDC Transmuter: handles USDC variant bridging |
| 56 | + |
| 57 | +### Indexer (`/envio-indexer/`) |
| 58 | + |
| 59 | +**Tech stack:** Envio v2, Viem, TypeScript, Mocha/Chai for tests. |
| 60 | + |
| 61 | +The indexer tracks bridge transaction lifecycle via on-chain events: |
| 62 | +1. `UserRequestForSignature` — bridge initiated |
| 63 | +2. `SignedForUserRequest` — validator signed |
| 64 | +3. `CollectedSignatures` — threshold reached |
| 65 | +4. `AffirmationCompleted` — executed on destination |
| 66 | + |
| 67 | +Configuration is in `config.yaml` (networks, contract addresses, event signatures, start blocks). The `schema.graphql` defines the GraphQL API consumed by the frontend. Run `pnpm indexer:codegen` after changing either file. |
| 68 | + |
| 69 | +Generated code lives in `generated/` — do not edit manually. |
| 70 | + |
| 71 | +### Data Flow |
| 72 | + |
| 73 | +Frontend (`SWR` hooks) → Envio GraphQL API (`NEXT_PUBLIC_ENVIO_INDEXER_URL`) → Indexed on-chain events → Bridge contracts on Ethereum (chain 1) and Gnosis Chain (chain 100). |
| 74 | + |
| 75 | +## Environment Setup |
| 76 | + |
| 77 | +Copy and fill `.env.example` files: |
| 78 | +- `app/.env.local` — requires RPC URLs, WalletConnect project ID, Envio indexer GraphQL URL |
| 79 | +- `alerts/.env` — requires Slack token/channel, RPC URLs, subgraph URLs |
| 80 | + |
| 81 | +Node version is pinned in `.nvmrc` (v22.11.0). Use `nvm use` before installing. |
| 82 | + |
| 83 | +## Git Workflow |
| 84 | + |
| 85 | +- Feature branches are created from `develop` |
| 86 | +- PRs target `develop` → promoted to `staging` → `main` (production) |
| 87 | +- Conventional Commits are enforced via commitlint (pre-commit hook) |
| 88 | +- Pre-commit hooks (Husky + lint-staged) run ESLint fix, Prettier, and `tsc` on staged files |
0 commit comments