Repository navigation
feat(contracts): production DeployProtocol script (closes #694) - #700
Conversation
Add `script/DeployProtocol.s.sol` + abstract `BaseProtocolDeploy.s.sol` that deploys the v3 contract surface in ADR 016 § Deployment Order, wires cross-contract roles, and atomically hands off GOVERNANCE_ROLE + DEFAULT_ADMIN_ROLE from the deployer EOA to a fresh TimelockController. Post-deploy `_assertNoBackDoors` reverts the run if any step left the deployer holding a privileged role. The shared base is also consumed by `GovernanceLifecycleTest`, removing ~150 lines of duplicated deploy helpers; all 57 lifecycle tests pass unchanged. Design choices (confirmed up-front): - BuybackBurner is abstract; ship with bucket dormant (buybackBurner_=address(0), shares[1]=0). Governance activates later via setSharesAndDestinations once a concrete subclass lands. - ED25519_VERIFIER_ADDRESS is operator-supplied via env var (no production verifier in repo yet). 13 new tests across DeployProtocol.t.sol + DeployProtocolScript.t.sol: role-matrix invariants, 7 ZeroAddress fail-fast cases, manifest write/overwrite/contents, env-var defaults, run-guard against forge's default sender. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Gas snapshotGas changes vs baseRun: 26655289391 |
Contracts coverageLine coverage: 84.39% (1130/1339 lines) |
There was a problem hiding this comment.
Code Review
This pull request introduces a standardized, five-phase deployment pipeline for the v3 protocol contracts via BaseProtocolDeploy and its concrete script DeployProtocol. It handles contract deployment, cross-contract role wiring, and an atomic governance handoff to a TimelockController with post-deploy safety assertions to ensure no backdoors remain. Comprehensive unit and integration tests are added to verify the deployment topology, manifest writing, and script configurations, while existing lifecycle tests are refactored to utilize this new deployment logic. No review comments were provided, so there is no additional feedback to address.
solc W2018 (state mutability can be restricted to view) is fatal under FOUNDRY_PROFILE=ci --deny warnings. test_readConfig_appliesDefaultsForOptionalVars only calls the external-view wrapper and pure assertions, so solc flags it. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds a production-grade Foundry deploy pipeline for the v3 contract surface described in ADR 016. A shared abstract base (BaseProtocolDeploy) runs a five-phase deploy (targets → governance → cross-contract wiring → role handoff → no-back-door invariant) and is consumed by both the production DeployProtocol script (env-var driven, manifest writer) and the refactored GovernanceLifecycleTest, with new dedicated tests covering role topology, zero-address fail-fast, manifest IO, and the forge-default-sender guard.
Changes:
- New
BaseProtocolDeploy.s.sol+DeployProtocol.s.sol: typedDeployConfig/Deployment, five-phase deploy with_assertNoBackDoorsinvariant, env-var config reader, anddeployments/<chainId>.jsonmanifest writer with overwrite guard. - New
DeployProtocol.t.sol(13 in-process role/wiring/zero-address tests) andDeployProtocolScript.t.sol(6 script-shape tests for env defaults, manifest contents/overwrite, and forge-default-sender rejection). - Refactored
GovernanceLifecycleTestto inheritBaseProtocolDeploy, dropping ~150 lines of duplicated deploy helpers and using a new_postWiringHookto grant test-onlyROUTER_CALLER_ROLE;foundry.tomlgetsfs_permissionsscoped to./deployments.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| contracts/script/BaseProtocolDeploy.s.sol | New abstract base implementing the five-phase deploy pipeline and back-door invariant. |
| contracts/script/DeployProtocol.s.sol | New production script: env→config plumbing, run() with forge-default-sender guard, manifest writer. |
| contracts/test/DeployProtocol.t.sol | New in-process tests for role matrix, wiring, launch shares, zero-address checks, and back-door revert. |
| contracts/test/DeployProtocolScript.t.sol | New tests for _readConfig defaults, manifest contents/overwrite guard, and run() rejection of forge default sender. |
| contracts/test/GovernanceLifecycle.t.sol | Refactor onto BaseProtocolDeploy; replaces inline _deployTargets/_handOff… helpers with a _postWiringHook override. |
| contracts/foundry.toml | Adds fs_permissions for ./deployments so the manifest writer can run under Foundry's sandbox. |
| contracts/deployments/.gitkeep | Placeholder to keep the manifest output directory in tree. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address PR #700 review: - Deploy TimelockController before FeeRouter (new phase 1) and wire it as the treasury bucket destination, matching ADR 016 § Deployment Order step 7 (treasury is Timelock-custodied, disbursed only by governance proposal). Previously FeeRouter took an operator-supplied TREASURY_ADDRESS deployed before the timelock existed — so "treasury == the Timelock" was unreachable in a single run. Drop the TREASURY_ADDRESS env var and the treasury config field; the bucket is now always address(timelock). _deployGovernance splits into _deployTimelock (phase 1) + _deployGovernor (phase 3). Note: FeeRouter.treasury is a mutable GOVERNANCE_ROLE-gated setter, not immutable as the review stated, so a misconfig was always correctable via a 48h proposal — but Timelock-custody is the canonical ADR 016 model regardless. - gitignore deployments/3133769*.json so a failed/interrupted DeployProtocolScript test run can't leave a stray test manifest that gets accidentally committed. Real-chain manifests use other ids and remain committable with `git add -f`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Multi-agent review of PR #700 surfaced several gaps; all verified findings fixed: - Manifest writability is now checked in run() BEFORE vm.startBroadcast, not after. Previously a stale manifest with no FORCE_OVERWRITE_MANIFEST let the whole deploy + governance handoff broadcast on-chain, then reverted at the write — leaving deployed contracts with no recorded addresses. New _assertManifestWritable/_manifestPath helpers; _writeManifest keeps the guard so direct callers/tests still get it. - Grant GENESIS_GRANTOR_ROLE to the Timelock in phase 4 (ADR 016 § Post-Deploy Init step 7). The 30-day genesis window starts ticking at CapacityBond construction; without this, enabling credits needed a ~10-day proposal, burning a third of the window. - Drop FEE_ROUTER_EPOCH_LENGTH env var — it can only ever be 7 days (FeeRouter reverts EpochLengthMismatch otherwise), so it advertised false tunability and carried a silent uint256->uint64 truncation. Now a fixed uint64 constant; FEE_ROUTER_WINDOW_EPOCHS gets an explicit overflow guard. - Enforce a MIN_TIMELOCK_DELAY floor — TIMELOCK_DELAY=0 was silently accepted, constructing a zero-delay Timelock that defeats the governance-delay model. - Make _assertNoBackDoors symmetric: assert the Timelock HOLDS both roles on every target and self-administers, not just that the deployer is out. A handoff that revoked the deployer but skipped a Timelock grant would otherwise pass while leaving a contract ungoverned. New GovernanceNotHandedOff error; extract _governedTargets(d) as the single source of truth for the handoff loop and the guard. - Fix stale comments: "five-phase"->"six-phase", "§ Role Matrix"->"§ Access Control Matrix", "phases 1-5"->"phases 1-6", imprecise ADR step-7 custody citations, and the overstated "sorted alphabetically" manifest claim. Tests: add run() pre-broadcast manifest-guard test, GovernanceNotHandedOff negative test, genesis-grantor wiring test, and manifest deployer/deployBlock assertions. 297 pass; forge fmt, aderyn (0 high), slither (clean). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…col-script # Conflicts: # contracts/test/GovernanceLifecycle.t.sol
Two comment-only corrections surfaced by PR review after the #708 rebase: - GovernanceLifecycle.t.sol: buyback share in the fixture is 3000 bps, not the 2500 left over from the old 4-bucket split. - DeployProtocolScript.t.sol: the base-deploy pipeline is 6 phases (the _assertNoBackDoors guard at phase 6 is covered in DeployProtocol.t.sol), not "phases 1-5". Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
script/DeployProtocol.s.sol+ abstractscript/BaseProtocolDeploy.s.sol: deploys the v3 contract surface in ADR 016 § Deployment Order and Initialization Dependencies, wires cross-contract roles, and atomically hands offGOVERNANCE_ROLE+DEFAULT_ADMIN_ROLEfrom the deployer EOA to a freshTimelockController. Post-deploy_assertNoBackDoorsinvariant reverts the run if any step left the deployer holding a privileged role.GovernanceLifecycleTestto inherit the shared base (drops the duplicated_deployTargets/_wireCrossContractRoles/_handOffGovernanceToTimelockhelpers via a_postWiringHookoverride; all existing lifecycle tests pass unchanged).test/DeployProtocol.t.sol+test/DeployProtocolScript.t.sol: role-matrix invariants, 6ZeroAddressfail-fast cases, manifest write/overwrite-guard/contents, env-var defaults, run-guard against forge's default sender.Rebased onto the SafetyReserve removal (#708)
This PR was rebased on top of #708, which removed
SafetyReserve(escrow-on-slash insideCapacityBond; FeeRouter split → 60/30/10). The deploy surface was updated accordingly:SafetyReserve→SlashAppeal. The script deploysSlashAppeal(ADR 028) instead ofSafetyReserveand grants itSLASH_APPEAL_ROLEonCapacityBond.setChallengerIncentivePoolnow lives onSlashAppeal. Thebond.setSafetyReserve/SLASH_INFLOW_REPORTER_ROLE/APPEAL_REVERSAL_ROLEwiring is gone.uint256[3]operator/buyback/treasury). ThesafetyReserve_constructor arg and the 4thsafetybucket are gone.maxAppealRestitutionconfig/env var (no longer part of the appeal surface);SAFETY_APPEAL_BOND→SLASH_APPEAL_BOND.[FeeRouter, CapacityBond, ContentBlacklist, SlashAppeal, PublisherRegistry].Design choices
BuybackBurner.solisabstractpending a Balancer V3 Vault integration). Launch shares are[9000, 0, 1000](operator/buyback/treasury) withbuybackBurner_=address(0)—FeeRouter._setSharesexplicitly permits this. Operator is pinned at its 9000-bps ceiling so the dormant 30% buyback leg is temporarily routed to operators while treasury holds its 10% target. Governance activates the bucket viaFeeRouter.setSharesAndDestinationsonce a concrete subclass is deployed.ED25519_VERIFIER_ADDRESS.Test plan
forge fmt --checkFOUNDRY_PROFILE=ci forge build --sizes --deny warningsforge test— 289 tests pass (77 across the DeployProtocol/DeployProtocolScript/GovernanceLifecycle suites)npx solhint --config .solhint.json 'script/**/*.sol'— 0 errorsslither . --config-file slither.config.json— exit 0 (fail_on: mediumgate)aderyn -o /tmp/aderyn.md --no-snippets --skip-update-check— 0 High findings (fail-on: highgate)--sender)🤖 Generated with Claude Code