|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Repository Overview |
| 6 | + |
| 7 | +This is The Graph Protocol's smart contracts monorepo - a decentralized network for querying and indexing blockchain data. It uses pnpm workspaces to manage multiple packages. |
| 8 | + |
| 9 | +## Key Commands |
| 10 | + |
| 11 | +### Build and Development |
| 12 | + |
| 13 | +```bash |
| 14 | +# Install dependencies (uses pnpm) |
| 15 | +pnpm install |
| 16 | + |
| 17 | +# Build all packages |
| 18 | +pnpm build |
| 19 | + |
| 20 | +# Clean build artifacts |
| 21 | +pnpm clean |
| 22 | + |
| 23 | +# Deep clean (including node_modules) |
| 24 | +pnpm clean:all |
| 25 | +``` |
| 26 | + |
| 27 | +### Testing |
| 28 | + |
| 29 | +```bash |
| 30 | +# Run all tests |
| 31 | +pnpm test |
| 32 | + |
| 33 | +# Run tests with coverage |
| 34 | +pnpm test:coverage |
| 35 | + |
| 36 | +# Test a specific package |
| 37 | +cd packages/<package-name> && pnpm test |
| 38 | + |
| 39 | +# Test a single file (in contracts package) |
| 40 | +cd packages/contracts && npx hardhat test test/<FILE_NAME>.ts |
| 41 | + |
| 42 | +# Run Foundry tests (in horizon/subgraph-service) |
| 43 | +cd packages/horizon && pnpm test |
| 44 | + |
| 45 | +# Run integration tests |
| 46 | +cd packages/horizon && pnpm test:integration |
| 47 | + |
| 48 | +# Run deployment tests |
| 49 | +cd packages/horizon && pnpm test:deployment |
| 50 | +``` |
| 51 | + |
| 52 | +### Linting and Formatting |
| 53 | + |
| 54 | +```bash |
| 55 | +# Run all linters |
| 56 | +pnpm lint |
| 57 | + |
| 58 | +# Format code |
| 59 | +pnpm format |
| 60 | + |
| 61 | +# Individual linters |
| 62 | +pnpm lint:ts # TypeScript/JavaScript |
| 63 | +pnpm lint:sol # Solidity |
| 64 | +pnpm lint:natspec # NatSpec comments |
| 65 | +pnpm lint:md # Markdown |
| 66 | +pnpm lint:json # JSON files |
| 67 | +pnpm lint:yaml # YAML files |
| 68 | +``` |
| 69 | + |
| 70 | +## Architecture Overview |
| 71 | + |
| 72 | +### Package Structure |
| 73 | + |
| 74 | +1. **contracts** - Original Graph Protocol contracts (staking, curation, disputes) |
| 75 | + - Uses Hardhat for development |
| 76 | + - Contains E2E testing framework for protocol validation |
| 77 | + |
| 78 | +2. **horizon** - Next iteration of The Graph protocol |
| 79 | + - Uses Hardhat + Foundry for testing |
| 80 | + - Deployment via Hardhat Ignition |
| 81 | + - Migration path from original protocol |
| 82 | + |
| 83 | +3. **subgraph-service** - Data service implementation for Graph Horizon |
| 84 | + - Manages disputes and allocations |
| 85 | + - Part of the Horizon ecosystem |
| 86 | + |
| 87 | +4. **interfaces** - Shared contract interfaces |
| 88 | + - Centralized repository for all Solidity contract interfaces |
| 89 | + - Used by multiple packages/programs for contract implementation and interaction |
| 90 | + - Generates TypeScript types for distribution via npm |
| 91 | + - Defaults to ethers v6 type generation |
| 92 | + - Includes Wagmi type generation support |
| 93 | + - Includes ethers v5 type generation |
| 94 | + - Published types can be imported by any TypeScript program |
| 95 | + |
| 96 | +5. **token-distribution** - Token locking and vesting contracts |
| 97 | + - GraphTokenLockWallet and GraphTokenLockManager |
| 98 | + - L2 token distribution functionality |
| 99 | + |
| 100 | +6. **toolshed** - Shared development utilities |
| 101 | + - Deployment helpers |
| 102 | + - Test fixtures |
| 103 | + - Hardhat extensions |
| 104 | + |
| 105 | +### Key Architectural Patterns |
| 106 | + |
| 107 | +- **Proxy Upgradeable Pattern**: Most contracts use OpenZeppelin's upgradeable proxy pattern |
| 108 | +- **Storage Separation**: Storage contracts are separate from logic contracts |
| 109 | +- **Governor/Controller Pattern**: Access control through Governor and Controller contracts |
| 110 | +- **Modular Design**: Clear separation between protocol layers and services |
| 111 | + |
| 112 | +### Testing Strategy |
| 113 | + |
| 114 | +- **Unit Tests**: TypeScript tests using Hardhat Test Environment |
| 115 | +- **Foundry Tests**: Solidity tests (`.t.sol` files) for horizon and subgraph-service |
| 116 | +- **Integration Tests**: Cross-contract interaction testing |
| 117 | +- **E2E Tests**: Full protocol deployment and operation validation |
| 118 | + |
| 119 | +### Deployment |
| 120 | + |
| 121 | +- Contract addresses stored in `addresses.json` files per package |
| 122 | +- Multi-network support (mainnet, testnets, Arbitrum chains) |
| 123 | +- Hardhat Ignition for deployment management |
| 124 | +- Migration scripts for upgrading from original protocol to Horizon |
| 125 | + |
| 126 | +## Development Tips |
| 127 | + |
| 128 | +### Working with Horizon |
| 129 | + |
| 130 | +Horizon packages use both Hardhat and Foundry. When developing: |
| 131 | + |
| 132 | +1. Use `forge test` for Foundry tests |
| 133 | +2. Use `pnpm test:integration` for integration tests |
| 134 | +3. Set required RPC URLs using `npx hardhat vars set <variable>` |
| 135 | + |
| 136 | +### Contract Verification |
| 137 | + |
| 138 | +For contract verification on block explorers: |
| 139 | + |
| 140 | +```bash |
| 141 | +npx hardhat vars set ARBISCAN_API_KEY <your-key> |
| 142 | +``` |
| 143 | + |
| 144 | +### Changesets for Versioning |
| 145 | + |
| 146 | +When making changes that should be published: |
| 147 | + |
| 148 | +```bash |
| 149 | +# Create a changeset |
| 150 | +pnpm changeset |
| 151 | + |
| 152 | +# Version packages (maintainer only) |
| 153 | +pnpm changeset version |
| 154 | + |
| 155 | +# Publish to npm (maintainer only) |
| 156 | +pnpm changeset publish |
| 157 | +``` |
| 158 | + |
| 159 | +### Security Considerations |
| 160 | + |
| 161 | +- Audit reports available in `audits/` directories |
| 162 | +- Use existing proxy patterns and access control mechanisms |
| 163 | +- Follow established upgrade procedures for contract modifications |
| 164 | +- Report security issues through Immunefi bounty program |
0 commit comments