This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
SubQuery Network Contracts - A comprehensive smart contract suite powering the decentralized SubQuery Network indexing infrastructure. Built with Solidity 0.8.15, Hardhat, and TypeScript.
yarn install # Install dependencies
yarn build # Build contracts + TypeScript SDK
yarn test # Run full test suite
yarn test:coverage # Run tests with coverage analysis
yarn lint # Lint all code (Solidity + TypeScript)
yarn format # Format all code (Prettier)yarn build:contract # Compile Solidity contracts only
yarn build:ts # Build TypeScript SDK only
yarn build:abi # Generate ABI filesyarn test:single <file> # Run specific test file
yarn coverage # Generate test coverage report
yarn test:fuzz # Run Echidna fuzz testingyarn deploy --testnet # Deploy to testnet (Polygon Mumbai + Sepolia)
yarn deploy --kepler # Deploy to Kepler network (staging)
yarn deploy --mainnet # Deploy to mainnet (Ethereum + Base)
yarn upgrade --testnet # Upgrade contracts with proxy pattern
yarn verify --testnet # Verify contracts on block explorersyarn docs:generate # Generate contract documentation
yarn docs:build # Build VuePress documentation site
yarn docs:dev # Serve docs locally- Layer 1 (Root): Ethereum mainnet/Sepolia - token contracts, governance
- Layer 2 (Child): Polygon/Base - main protocol contracts
- Bridge Integration: L1↔L2 token transfers via standard bridges
/contracts/
├── [Root contracts] - 35+ core contracts (Settings, Staking, IndexerRegistry, etc.)
├── /interfaces/ - 24 interface definitions
├── /l2/ - Layer 2 specific implementations
├── /root/ - Layer 1 (root chain) contracts
├── /utils/ - Utility and helper contracts
└── /archive/ - Legacy contract versions
- Settings.sol - Central configuration registry for all protocol parameters
- Staking.sol - Core delegation and staking mechanism
- IndexerRegistry.sol - Indexer registration and management
- ProjectRegistry.sol - Project registration system
- RewardsDistributor.sol - Automated reward distribution logic
- ConsumerHost.sol - Consumer interaction and payment layer
- PlanManager.sol - Service plan management
All main contracts use OpenZeppelin's upgradeable proxy pattern. When modifying contracts:
- Ensure storage layout compatibility
- Test upgrade scripts thoroughly
- Use upgrade helpers in
/scripts/upgrade.ts
- TypeScript SDK:
/src/- Auto-generated TypeChain bindings + wrapper SDK - Rust SDK:
/rust/- ethers-rs based SDK for Rust applications - Contract Types: Auto-generated in
/src/typechain/
- 32 comprehensive test files using Hardhat + Waffle + Chai
- Helper utilities:
/test/setup.ts,/test/helper.tsfor common test patterns - Mock contracts:
/contracts/mocks/for isolated testing - E2E tests: Full workflow validation across contract interactions
- Node Environment: CommonJS with ES2020 target
- Package Manager: Yarn 3.6.4 (use
yarnnotnpm) - TypeScript: Strict mode enabled with comprehensive type checking
- Pre-commit hooks: Husky + lint-staged for code quality
Networks are configured in hardhat.config.ts:
- testnet: Polygon Mumbai + Sepolia
- kepler: Polygon Mainnet (staging environment)
- mainnet: Ethereum + Base
- local: Hardhat network for development
- Published contracts:
/publish/*.jsonfiles track deployed addresses - Network configs:
/scripts/config/contains network-specific settings - Deployment verification: Automated Etherscan/Polygonscan verification
- Solidity: Uses Solhint with custom rules (
.solhint.json) - TypeScript: ESLint with TypeScript rules
- Formatting: Prettier for both Solidity and TypeScript
- Coverage: Aim for high test coverage, check with
yarn test:coverage
- Access Control: Most contracts use Ownable pattern with multi-sig governance
- Proxy Safety: Be careful with storage layout when upgrading contracts
- Audit Integration: Security audits stored in
/audits/directory - Fuzz Testing: Echidna configuration for property-based testing
- Contract Initialization: Use
__contractName_init()pattern for upgradeable contracts - Event Emission: All state changes should emit appropriate events
- Error Handling: Use custom errors (introduced in Solidity 0.8.4) for gas efficiency
- Interface Compliance: Always implement corresponding interfaces from
/contracts/interfaces/