Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/graph-core-initial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@graphprotocol/graph-core': major
---

Publish the governance and proxy contracts (Controller, Governed, Managed, Pausable, GraphProxy, GraphProxyAdmin, GraphProxyStorage, GraphUpgradeable) as `@graphprotocol/graph-core`.
Publish the governance, proxy and epoch contracts (Controller, Governed, Managed, Pausable, GraphProxy, GraphProxyAdmin, GraphProxyStorage, GraphUpgradeable, EpochManager, EpochManagerStorage) as `@graphprotocol/graph-core`.
2 changes: 1 addition & 1 deletion .changeset/graph-token-initial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@graphprotocol/graph-token': major
---

Publish the token and bridge contracts (GraphToken, L2GraphToken, TokenUtils, the Arbitrum gateways and BridgeEscrow) as `@graphprotocol/graph-token`.
Publish the token, bridge, curation-token and subgraph NFT contracts (GraphToken, L2GraphToken, TokenUtils, the Arbitrum gateways, BridgeEscrow, GraphCurationToken, SubgraphNFT, SubgraphNFTDescriptor, HexStrings and Base58Encoder) as `@graphprotocol/graph-token`.
5 changes: 5 additions & 0 deletions .changeset/horizon-dependency-artifacts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/horizon': patch
---

The dependency artifacts and types for `TokenUtils` and `GraphUpgradeable` are now built from `@graphprotocol/graph-token` and `@graphprotocol/graph-core`, so they move from `build/contracts/@graphprotocol/contracts/...` to `build/contracts/@graphprotocol/graph-token/...` and `build/contracts/@graphprotocol/graph-core/...`. Contract bytecode is unchanged.
3 changes: 3 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
- name: Check bytecode equivalence
run: pnpm check:bytecode

- name: Check storage layouts of ported contracts
run: pnpm check:storage

- name: Test all packages
run: pnpm -r --sequential run test:self

Expand Down
7 changes: 6 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ pnpm lint:yaml # YAML files
1. **horizon** - Next iteration of The Graph protocol
- Uses Hardhat + Foundry for testing
- Deployment via Hardhat Ignition
- Migration path from original protocol

2. **subgraph-service** - Data service implementation for Graph Horizon
- Manages disputes and allocations
Expand All @@ -94,6 +93,12 @@ pnpm lint:yaml # YAML files

6. **billing** - Graph Studio billing contracts (Billing, BillingConnector, BanxaWrapper), private, Hardhat 2 with ethers v5

7. **graph-core** - Governance, proxy and epoch contracts (Controller, GraphProxy, GraphProxyAdmin, EpochManager), solc 0.7.6 with bytecode identical to the deployed protocol

8. **graph-token** - GraphToken, L2GraphToken, the Arbitrum gateways, GraphCurationToken and the SubgraphNFT contracts, solc 0.7.6 with bytecode identical to the deployed protocol

9. **legacy** - Archive of the verified source of the mainnet implementations, with addresses and audits (private)

### Key Architectural Patterns

- **Proxy Upgradeable Pattern**: Most contracts use OpenZeppelin's upgradeable proxy pattern
Expand Down
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@

This repository is a pnpm workspaces monorepo containing the following packages:

| Package | Latest version | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ |
| [billing](./packages/billing) | Private, not published | Graph Studio billing contracts: Billing, BillingConnector and BanxaWrapper. |
| [data-edge](./packages/data-edge) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Fdata-edge.svg)](https://badge.fury.io/js/@graphprotocol%2Fdata-edge) | Data edge testing and utilities for The Graph protocol. |
| [hardhat-graph-protocol](./packages/hardhat-graph-protocol) | [![npm version](https://badge.fury.io/js/hardhat-graph-protocol.svg)](https://badge.fury.io/js/hardhat-graph-protocol) | A Hardhat plugin that extends the runtime environment with functionality for The Graph protocol. |
| [horizon](./packages/horizon) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Fhorizon.svg)](https://badge.fury.io/js/@graphprotocol%2Fhorizon) | Contracts for Graph Horizon, the next iteration of The Graph protocol. |
| [interfaces](./packages/interfaces) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Finterfaces.svg)](https://badge.fury.io/js/@graphprotocol%2Finterfaces) | Contract interfaces for The Graph protocol contracts. |
| [issuance](./packages/issuance) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Fissuance.svg)](https://badge.fury.io/js/@graphprotocol%2Fissuance) | Smart contracts for The Graph's token issuance functionality |
| [subgraph-service](./packages/subgraph-service) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Fsubgraph-service.svg)](https://badge.fury.io/js/@graphprotocol%2Fsubgraph-service) | Contracts for the Subgraph data service in Graph Horizon. |
| [token-distribution](./packages/token-distribution) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Ftoken-distribution.svg)](https://badge.fury.io/js/@graphprotocol%2Ftoken-distribution) | Contracts managing token locks for network participants. |
| [toolshed](./packages/toolshed) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Ftoolshed.svg)](https://badge.fury.io/js/@graphprotocol%2Ftoolshed) | A collection of tools and utilities for the Graph Protocol TypeScript components. |
| Package | Latest version | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
| [billing](./packages/billing) | Private, not published | Graph Studio billing contracts: Billing, BillingConnector and BanxaWrapper. |
| [data-edge](./packages/data-edge) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Fdata-edge.svg)](https://badge.fury.io/js/@graphprotocol%2Fdata-edge) | Data edge testing and utilities for The Graph protocol. |
| [graph-core](./packages/graph-core) | Not yet published | Governance, proxy and epoch contracts: Controller, GraphProxy, GraphProxyAdmin, EpochManager (solc 0.7.6). |
| [graph-token](./packages/graph-token) | Not yet published | The Graph token, Arbitrum bridge, curation token and subgraph NFT contracts (solc 0.7.6). |
| [hardhat-graph-protocol](./packages/hardhat-graph-protocol) | [![npm version](https://badge.fury.io/js/hardhat-graph-protocol.svg)](https://badge.fury.io/js/hardhat-graph-protocol) | A Hardhat plugin that extends the runtime environment with functionality for The Graph protocol. |
| [horizon](./packages/horizon) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Fhorizon.svg)](https://badge.fury.io/js/@graphprotocol%2Fhorizon) | Contracts for Graph Horizon, the next iteration of The Graph protocol. |
| [interfaces](./packages/interfaces) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Finterfaces.svg)](https://badge.fury.io/js/@graphprotocol%2Finterfaces) | Contract interfaces for The Graph protocol contracts. |
| [issuance](./packages/issuance) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Fissuance.svg)](https://badge.fury.io/js/@graphprotocol%2Fissuance) | Smart contracts for The Graph's token issuance functionality |
| [legacy](./packages/legacy) | Private, not published | Archive of the verified source of the mainnet implementations, with their addresses and audits. |
| [subgraph-service](./packages/subgraph-service) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Fsubgraph-service.svg)](https://badge.fury.io/js/@graphprotocol%2Fsubgraph-service) | Contracts for the Subgraph data service in Graph Horizon. |
| [token-distribution](./packages/token-distribution) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Ftoken-distribution.svg)](https://badge.fury.io/js/@graphprotocol%2Ftoken-distribution) | Contracts managing token locks for network participants. |
| [toolshed](./packages/toolshed) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Ftoolshed.svg)](https://badge.fury.io/js/@graphprotocol%2Ftoolshed) | A collection of tools and utilities for the Graph Protocol TypeScript components. |

## Development

Expand Down Expand Up @@ -163,7 +166,7 @@ gh workflow run publish.yml -f package=interfaces -f tag=latest -f dry_run=false

Inputs:

- `package` — the workspace package to publish (one of `address-book`, `contracts`, `interfaces`, `toolshed`).
- `package` — the workspace package to publish (one of `address-book`, `graph-core`, `graph-token`, `interfaces`, `toolshed`).
- `tag` — npm dist-tag. Use `latest` for stable releases; use a custom tag (`dips`, `sepolia`, `next`, …) for pre-releases so the stable channel isn't overwritten.
- `dry_run` — when `true`, validates the workflow without consuming a version or pushing a git tag.

Expand Down
2 changes: 1 addition & 1 deletion docs/IGraphProxyAdminInterfaceFix.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function acceptProxyAndCall(address implementation, IGraphProxy proxy, bytes cal
**Notes on parameter type choice:**

- Used `address` instead of `GraphUpgradeable` for the implementation parameter
- This avoids creating a dependency from interfaces package to contracts package
- This avoids creating a dependency from the interfaces package to graph-core
- The actual contract uses `GraphUpgradeable`, but `address` is compatible (Solidity allows passing addresses for contract types)
- The ABI encoding is identical - both produce the same function selector and parameter encoding

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"test:prod": "FOUNDRY_PROFILE=prod pnpm test",
"test:scripts": "node --test 'scripts/**/*.test.mjs'",
"check:bytecode": "node scripts/contracts-migration/check-bytecode.mjs",
"check:storage": "node scripts/contracts-migration/check-storage.mjs",
"test:coverage": "pnpm build && pnpm -r run build:self:coverage && pnpm -r run test:coverage:self"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/deployment/tasks/verify-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function getFullyQualifiedContractName(artifactSource: ArtifactSource): s
switch (artifactSource.type) {
case 'graph-core':
case 'graph-token':
// e.g., contracts/rewards/RewardsManager.sol:RewardsManager
// e.g., contracts/governance/Controller.sol:Controller
return `contracts/${artifactSource.path}/${artifactSource.name}.sol:${artifactSource.name}`
case 'subgraph-service':
// e.g., contracts/SubgraphService.sol:SubgraphService, contracts/l2/curation/L2Curation.sol:L2Curation
Expand Down
2 changes: 1 addition & 1 deletion packages/graph-core/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Graph Core

Governance and proxy contracts shared by The Graph Protocol: `Controller`, `Governed`, `Managed`, `Pausable`, and the `GraphProxy` upgrade pattern (`GraphProxy`, `GraphProxyAdmin`, `GraphProxyStorage`, `GraphUpgradeable`).
Governance, proxy and epoch contracts shared by The Graph Protocol: `Controller`, `Governed`, `Managed`, `Pausable`, the `GraphProxy` upgrade pattern (`GraphProxy`, `GraphProxyAdmin`, `GraphProxyStorage`, `GraphUpgradeable`), and `EpochManager` with `EpochManagerStorage`.

The contracts compile with solc 0.7.6 (optimizer enabled, 200 runs) to keep their bytecode identical to the deployed protocol.

Expand Down
5 changes: 5 additions & 0 deletions packages/graph-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"version": "0.0.0",
"description": "The Graph governance and proxy contracts",
"license": "GPL-2.0-or-later",
"repository": {
"type": "git",
"url": "git+https://github.com/graphprotocol/contracts",
"directory": "packages/graph-core"
},
"scripts": {
"build": "pnpm build:dep && pnpm build:self",
"build:dep": "pnpm --filter '@graphprotocol/graph-core^...' run build:self",
Expand Down
2 changes: 1 addition & 1 deletion packages/graph-token/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Graph Token

The Graph token and the Arbitrum bridge contracts: `GraphToken`, `L2GraphToken`, `GraphTokenUpgradeable`, `TokenUtils`, `L1GraphTokenGateway`, `L2GraphTokenGateway`, `GraphTokenGateway`, `BridgeEscrow` and the Arbitrum messenger helpers.
The Graph token and the Arbitrum bridge contracts: `GraphToken`, `L2GraphToken`, `GraphTokenUpgradeable`, `TokenUtils`, `L1GraphTokenGateway`, `L2GraphTokenGateway`, `GraphTokenGateway`, `BridgeEscrow` and the Arbitrum messenger helpers, plus the curation share token `GraphCurationToken` and the subgraph NFT contracts `SubgraphNFT`, `SubgraphNFTDescriptor`, `HexStrings` and `Base58Encoder`.

`GraphToken`, `L1GraphTokenGateway` and `BridgeEscrow` here are not the code running on mainnet. The mainnet sources are held in `packages/legacy`.

Expand Down
5 changes: 5 additions & 0 deletions packages/graph-token/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"version": "0.0.0",
"description": "The Graph token and bridge escrow contracts",
"license": "GPL-2.0-or-later",
"repository": {
"type": "git",
"url": "git+https://github.com/graphprotocol/contracts",
"directory": "packages/graph-token"
},
"scripts": {
"build": "pnpm build:dep && pnpm build:self",
"build:dep": "pnpm --filter '@graphprotocol/graph-token^...' run build:self",
Expand Down
43 changes: 43 additions & 0 deletions scripts/contracts-migration/check-storage.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node
// Compares the storage layout of each ported contract with its committed pre-port (0.7.6) layout.
import { execFileSync } from 'node:child_process'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { compareLayouts } from './compare-storage-layout.mjs'

const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')

export const PORTED = [
{
pkg: 'packages/issuance',
id: 'contracts/rewards/RewardsManager.sol:RewardsManager',
fixture: 'test/fixtures/pre-port/RewardsManager.storage.json',
},
{
pkg: 'packages/subgraph-service',
id: 'contracts/l2/discovery/L2GNS.sol:L2GNS',
fixture: 'test/fixtures/pre-port/L2GNS.storage.json',
},
{
pkg: 'packages/subgraph-service',
id: 'contracts/l2/curation/L2Curation.sol:L2Curation',
fixture: 'test/fixtures/pre-port/L2Curation.storage.json',
},
]

let failed = false
for (const { pkg, id, fixture } of PORTED) {
const cwd = path.join(root, pkg)
const before = JSON.parse(fs.readFileSync(path.join(cwd, fixture), 'utf8'))
const after = JSON.parse(execFileSync('forge', ['inspect', id, 'storageLayout', '--json'], { cwd, encoding: 'utf8' }))
const diffs = compareLayouts(before, after)
if (diffs.length) {
failed = true
console.error(`${id}:`)
for (const d of diffs) console.error(` ${d}`)
}
}
if (failed) process.exit(1)
console.log(`OK: ${PORTED.length} storage layouts match`)
2 changes: 1 addition & 1 deletion scripts/contracts-migration/test-mapping/t4.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# T4 test mapping: EpochManager

New tests are in `packages/horizon`, deploying the EpochManager Hardhat artifact behind a GraphProxy via `ProtocolFixture`. The old fixture's `epochs.lengthInBlocks` default (60) is the initial epoch length; the lifecycle tests call `setEpochLength(3)` as the old `beforeEach` did.
New tests were added in `packages/horizon` and moved with EpochManager to `packages/graph-core` in Phase 1 (P4), deploying the EpochManager Hardhat artifact behind a GraphProxy via `ProtocolFixture`. The old fixture's `epochs.lengthInBlocks` default (60) is the initial epoch length; the lifecycle tests call `setEpochLength(3)` as the old `beforeEach` did.

| Old file | Old test (describe › it) | New test (file::function) | Note |
| ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ---- |
Expand Down
Loading