diff --git a/.changeset/graph-core-initial.md b/.changeset/graph-core-initial.md index 554aac1f4..af9257a6e 100644 --- a/.changeset/graph-core-initial.md +++ b/.changeset/graph-core-initial.md @@ -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`. diff --git a/.changeset/graph-token-initial.md b/.changeset/graph-token-initial.md index b3225a634..747267bd5 100644 --- a/.changeset/graph-token-initial.md +++ b/.changeset/graph-token-initial.md @@ -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`. diff --git a/.changeset/horizon-dependency-artifacts.md b/.changeset/horizon-dependency-artifacts.md new file mode 100644 index 000000000..e5199a17c --- /dev/null +++ b/.changeset/horizon-dependency-artifacts.md @@ -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. diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 7f4f813d0..c89f811bc 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -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 diff --git a/CLAUDE.md b/CLAUDE.md index 691030abd..792387605 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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 @@ -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 diff --git a/README.md b/README.md index 779c1d964..e152df763 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/docs/IGraphProxyAdminInterfaceFix.md b/docs/IGraphProxyAdminInterfaceFix.md index a7ec3a86a..193b6de98 100644 --- a/docs/IGraphProxyAdminInterfaceFix.md +++ b/docs/IGraphProxyAdminInterfaceFix.md @@ -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 diff --git a/package.json b/package.json index a1743c57c..121b721c9 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/packages/deployment/tasks/verify-contract.ts b/packages/deployment/tasks/verify-contract.ts index 1532cf950..9af0b424e 100644 --- a/packages/deployment/tasks/verify-contract.ts +++ b/packages/deployment/tasks/verify-contract.ts @@ -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 diff --git a/packages/graph-core/README.md b/packages/graph-core/README.md index 52fde6c19..72e323f91 100644 --- a/packages/graph-core/README.md +++ b/packages/graph-core/README.md @@ -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. diff --git a/packages/graph-core/package.json b/packages/graph-core/package.json index 2adfb95d0..36812ed0d 100644 --- a/packages/graph-core/package.json +++ b/packages/graph-core/package.json @@ -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", diff --git a/packages/graph-token/README.md b/packages/graph-token/README.md index bdd85eda4..d558166f0 100644 --- a/packages/graph-token/README.md +++ b/packages/graph-token/README.md @@ -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`. diff --git a/packages/graph-token/package.json b/packages/graph-token/package.json index 5a5c1b464..f35bb5c90 100644 --- a/packages/graph-token/package.json +++ b/packages/graph-token/package.json @@ -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", diff --git a/scripts/contracts-migration/check-storage.mjs b/scripts/contracts-migration/check-storage.mjs new file mode 100644 index 000000000..49229aa9f --- /dev/null +++ b/scripts/contracts-migration/check-storage.mjs @@ -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`) diff --git a/scripts/contracts-migration/test-mapping/t4.md b/scripts/contracts-migration/test-mapping/t4.md index f9fa7eab1..df661d5a4 100644 --- a/scripts/contracts-migration/test-mapping/t4.md +++ b/scripts/contracts-migration/test-mapping/t4.md @@ -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 | | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ---- |