Skip to content

Commit b762037

Browse files
committed
feat: add ethers v5 type generation to interfaces package
Signed-off-by: Tomás Migone <[email protected]>
1 parent 59154fb commit b762037

File tree

10 files changed

+857
-526
lines changed

10 files changed

+857
-526
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ packages/*/.eslintcache
2828

2929
# Build artifacts
3030
dist/
31+
dist-v5/
3132
build/
3233
typechain/
3334
typechain-types/

CLAUDE.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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

packages/interfaces/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @graphprotocol/interfaces
22

3+
## 0.4.0
4+
5+
### Minor Changes
6+
7+
- Add ethers v5 type generation to interfaces package
8+
39
## 0.3.0
410

511
### Minor Changes

packages/interfaces/package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphprotocol/interfaces",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"publishConfig": {
55
"access": "public"
66
},
@@ -12,13 +12,13 @@
1212
"default": "./dist/src/index.js",
1313
"types": "./dist/src/index.d.ts"
1414
},
15-
"./wagmi": {
16-
"default": "./dist/wagmi/generated.js",
17-
"types": "./dist/wagmi/generated.d.ts"
18-
},
1915
"./types-v5": {
2016
"default": "./dist/types-v5/index.js",
2117
"types": "./dist/types-v5/index.d.ts"
18+
},
19+
"./wagmi": {
20+
"default": "./dist/wagmi/generated.js",
21+
"types": "./dist/wagmi/generated.d.ts"
2222
}
2323
},
2424
"files": [
@@ -33,14 +33,13 @@
3333
"author": "The Graph Team",
3434
"license": "GPL-2.0-or-later",
3535
"scripts": {
36-
"clean": "rm -rf dist cache artifacts types wagmi",
36+
"clean": "rm -rf dist dist-v5 cache artifacts types types-v5 wagmi",
3737
"lint": "pnpm lint:ts; pnpm lint:sol; pnpm lint:json",
3838
"lint:ts": "eslint --fix --cache '**/*.{js,ts,cjs,mjs,jsx,tsx}'; prettier -w --cache --log-level warn '**/*.{js,ts,cjs,mjs,jsx,tsx}'",
3939
"lint:sol": "solhint --fix --noPrompt --noPoster 'contracts/**/*.sol'; prettier -w --cache --log-level warn 'contracts/**/*.sol'",
4040
"lint:json": "prettier -w --cache --log-level warn '**/*.json'",
4141
"format": "prettier -w --cache --log-level warn '**/*.{js,ts,cjs,mjs,jsx,tsx,json,md,yaml,yml}'",
42-
"build": "hardhat compile && pnpm build:types && tsc",
43-
"build:types": "scripts/build-types.sh",
42+
"build": "scripts/build.sh",
4443
"build:clean": "pnpm clean && pnpm build",
4544
"watch": "tsc --watch",
4645
"prepublishOnly": "pnpm run build"
@@ -53,6 +52,9 @@
5352
"@typechain/ethers-v5": "^10.2.1",
5453
"@wagmi/cli": "^2.3.1",
5554
"ethers": "6.13.7",
55+
"ethers-v5": "npm:[email protected]",
56+
"@ethersproject/abi": "5.7.0",
57+
"@ethersproject/providers": "5.7.2",
5658
"hardhat": "^2.24.0",
5759
"markdownlint-cli": "^0.45.0",
5860
"prettier": "^3.5.3",

packages/interfaces/scripts/build-types.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# Complete build script for the interfaces package
4+
# This script handles:
5+
# 1. Hardhat compilation (generates artifacts and ethers-v6 types)
6+
# 2. Type generation (WAGMI and ethers-v5 types)
7+
# 3. TypeScript compilation (both v6 and v5 types)
8+
9+
set -e # Exit on any error
10+
11+
echo "🔨 Starting complete build process..."
12+
13+
# Step 1: Hardhat compilation
14+
echo "📦 Compiling contracts with Hardhat..."
15+
hardhat compile
16+
17+
# Step 2: Generate types
18+
echo "🏗️ Generating type definitions..."
19+
20+
# Build wagmi types
21+
echo " - Generating WAGMI types..."
22+
pnpm wagmi generate
23+
24+
# Build ethers-v5 types
25+
echo " - Generating ethers-v5 types..."
26+
pnpm typechain \
27+
--target ethers-v5 \
28+
--out-dir types-v5 \
29+
'artifacts/contracts/**/!(*.dbg).json' \
30+
'artifacts/@openzeppelin/**/!(*.dbg).json'
31+
32+
# Step 3: TypeScript compilation
33+
echo "🔧 Compiling TypeScript..."
34+
35+
# Compile v6 types (default tsconfig)
36+
echo " - Compiling ethers-v6 types..."
37+
tsc
38+
39+
# Compile v5 types (separate tsconfig)
40+
echo " - Compiling ethers-v5 types..."
41+
tsc -p tsconfig.v5.json
42+
43+
# Step 4: Merge v5 types into dist directory
44+
echo "📁 Organizing compiled types..."
45+
mkdir -p dist/types-v5
46+
cp -r dist-v5/* dist/types-v5/
47+
48+
echo "✅ Build completed successfully!"
49+
echo "📄 Generated types:"
50+
echo " - ethers-v6: dist/types/"
51+
echo " - ethers-v5: dist/types-v5/"
52+
echo " - wagmi: dist/wagmi/"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist-v5",
5+
"baseUrl": ".",
6+
"paths": {
7+
"ethers": ["node_modules/ethers-v5"],
8+
"ethers/*": ["node_modules/ethers-v5/*"],
9+
"@ethersproject/abi": ["node_modules/@ethersproject/abi"],
10+
"@ethersproject/providers": ["node_modules/@ethersproject/providers"],
11+
"@ethersproject/*": ["node_modules/@ethersproject/*"]
12+
}
13+
},
14+
"include": ["types-v5/**/*.ts"]
15+
}

packages/toolshed/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# @graphprotocol/toolshed
22

3+
## 0.6.7
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- @graphprotocol/interfaces@0.4.0
9+
310
## 0.6.6
411

512
### Patch Changes

packages/toolshed/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphprotocol/toolshed",
3-
"version": "0.6.6",
3+
"version": "0.6.7",
44
"publishConfig": {
55
"access": "public"
66
},

0 commit comments

Comments
 (0)