Feature/foundry platform deployments#35
Conversation
Mirrors hardhat/contracts/upgrade/ in foundry/src/upgrade/. Each stub inherits V1 and adds a version() sentinel used by upgrade tests to confirm the new implementation is live. No reinitializer needed — V2 introduces no new state variables.
…ript Mirrors hardhat/scripts/deploy-platform.ts. Deploys the four platform contracts behind Transparent Proxies in the same wiring order: DinToken → DinCoordinator (setCoordinator) → DinValidatorStake (updateValidatorStakeContract) → DINModelRegistry. Writes foundry/deployments/localhost.json in the exact same schema as hardhat/deployments/localhost.json so dincli import-deployments accepts it with --foundry or --file without any parsing changes. Also updates foundry/.gitignore to allow script/*.sol and adds @openzeppelin/upgrades-core to package.json (required by the OZ Foundry Upgrades library for upgrade-safety validation at test time).
Mirrors hardhat/scripts/upgrade-platform.ts. Reads the proxy address from foundry/deployments/localhost.json, resolves the V2 implementation by contract name (CONTRACT env var), and upgrades via the OZ Foundry Upgrades library. Rejects unknown contract names with a descriptive revert so misconfigurations surface at the script level rather than silently upgrading the wrong proxy.
Resolves to foundry/deployments/<network>.json with the same local->localhost mapping used by the hardhat default path. --file and --foundry together are rejected as mutually exclusive.
…flow - fs_permissions: allow read on out/ (OZ validation) and read-write on deployments/ (vm.writeJson / vm.readFile in deploy and upgrade scripts) - DeployPlatform.s.sol, UpgradePlatform.s.sol: vm.projectRoot() resolves to the foundry/ dir, so drop the extra /foundry/ prefix in the path - .gitignore: ignore local deployment artifacts (deployments/localhost.json) and anvil chain-1337 broadcast logs alongside the existing chain-31337 rule
|
Hi @umermjd11 Pls can you check this |
… (PR #35) Original work by Robert (@robertocarlous, PR #35, branch feature/foundry-platform-deployments, head 45dcda1), implementing issue #34: DeployPlatform.s.sol, UpgradePlatform.s.sol, four V2 upgrade stubs (DinTokenV2, DinCoordinatorV2, DinValidatorStakeV2, DINModelRegistryV2), the forge test suite (DeployPlatform.t.sol), dincli's `system import-deployments --foundry` flag, and the foundry.toml/package.json/.gitignore changes needed to run them. Three blocking bugs found in local verification, fixed here: - DeployPlatform.s.sol: vm.writeJson has no parent dir on a fresh clone (foundry/deployments/ is gitignored and not committed) — call vm.createDir before vm.writeJson. - All four V2 stubs: a plain `//` comment sat between the two `///` NatSpec lines, splitting the doc block so `@custom:oz-upgrades-from` never reached solc — UpgradePlatform.s.sol failed upgrades-core validation for every contract. Moved the `//` explanation above the NatSpec block so the `///` lines stay contiguous. - Both scripts' own documented "Usage (from repo root)" command didn't compile (foundry.toml/remappings.txt live in foundry/, not repo root) — changed the usage comments to `cd foundry && forge script ...`. Verified end-to-end: forge test (40/40 passing), and both scripts run against a local chain (deploy -> deployments JSON -> dincli system import-deployments --foundry -> upgrade, version() == 2 through the proxy for all four contracts). Co-Authored-By: umeradl <umermajeed.cto@gmail.com> Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
… harness tests/dincli/ can now deploy the platform contracts via either the new forge script from PR #35 or the existing hardhat script, selected by PLATFORM_DEPLOY_TOOLCHAIN (tests/dincli/constants.py; default "foundry", matching `dincli system import-deployments`'s own default). Overridable via env var / .env for anyone who wants to keep exercising the hardhat path. - constants.py: FOUNDRY_DIR, FORGE_BIN, PLATFORM_DEPLOY_TOOLCHAIN, HARDHAT_DEV_ACCOUNT_0; DEPLOYMENTS_FILE now resolves under whichever toolchain's deployments/ dir. - test_01_platform.py: test_deploy_platform_via_script branches on the toolchain (forge script vs hardhat run); test_import_deployments_into_din_info keeps passing an explicit --file since import-deployments' own --foundry/--hardhat default-path resolution is relative to cwd, and the harness's cwd is the isolated DIN_TEMP scratch dir, not the repo root. - conftest.py: managed_services now starts the matching chain backend (Anvil via foundry/anvil.sh for "foundry", the existing Hardhat node for "hardhat" — both on chain-id 1337) and runs `forge build` when the foundry toolchain is active; `npx hardhat compile` still always runs since task-level contract deploys and dump-abi tests need hardhat's ABIs/bytecode regardless of which toolchain deployed the platform. Verified: full tests/dincli/test_01_platform.py (8/8) under both toolchains, and test_01 through test_03 (35/35) end-to-end under the new foundry default. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Code review — Foundry platform deploy/upgrade parityReviewed at commit What's good
Bugs fixed (all three were blocking; fixed and re-verified, now landed on
|
Two follow-up fixes to files landed in b40fe2e (PR #35 foundry platform deploy/upgrade parity): - foundry/test/DeployPlatform.t.sol: the DinCoordinatorV2/ DinValidatorStakeV2/DINModelRegistryV2 imports sat mid-file, after the MockTaskContract definition — moved them up next to the DinTokenV2 import at the top, with the rest of the imports. - foundry/script/DeployPlatform.s.sol: added a `forge clean` step to the documented "Usage (from repo root)" comment, right after starting anvil. Without it, deploying then testing back-to-back after a recompile can hit upgrades-core's stale build-info bug ("Found multiple contracts with name ...") — reproduced again while re-verifying this change; `forge clean` resolves it. Also ran `forge fmt` over both files (line-wrapping only, no logic changes). Re-verified: forge clean && forge test — 40/40 passing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Merged manually to
|
|
Hi @umeradl Good catch on the proxyAdmin footgun — I agree it's worth fixing properly rather than just leaving a disclaimer. My preference is to record all four addresses explicitly (proxyAdminToken, proxyAdminCoordinator, proxyAdminStake, proxyAdminRegistry) rather than just renaming the single field. Since OZ v5 genuinely deploys four distinct ProxyAdmin contracts, the JSON should reflect that accurately a renamed single field still misleads anyone who reads it expecting to find the admin for a specific proxy. The fix needs to touch both the foundry deploy script and hardhat's deploy-platform.ts / helpers.ts together to keep the two schemas in sync, otherwise import-deployments would need to handle two different shapes. I can open a small follow-up issue and PR for that if useful it's a contained change. |
|
Yes please open an issue. Fix both hardhat and foundry for it, and fix dincli to import these into din_info.json — and the test harness if needed. If you can get to it, go ahead; otherwise I'll fix it myself and open the PR. |
|
Do not worry, i will do that from my end |
Summary
Implements issue #34 — Foundry Platform Deploy/Upgrade Parity
Adds Foundry equivalents of the Hardhat platform deploy/upgrade workflow so the four platform contracts (DinToken, DinCoordinator, DinValidatorStake, DINModelRegistry) can be deployed and upgraded via forge script on a local anvil chain.
What's included:
V2 upgrade stubs (foundry/src/upgrade/) — minimal V2 contracts for all four platform contracts, used to validate storage-layout safety in tests and the upgrade script
DeployPlatform.s.sol — deploys all four contracts behind TransparentUpgradeableProxy, wires them together in the correct order, and writes foundry/deployments/.json in the same address schema as the hardhat deploy script
UpgradePlatform.s.sol — upgrades a single proxy to its V2 implementation; contract selected via CONTRACT= env var, reads proxy address from the deployments JSON
Forge test suite (foundry/test/DeployPlatform.t.sol, 40 tests) — covers proxy wiring assertions, re-initializer protection on both proxy and implementation, and upgrade correctness (state preservation + access control) for all four contracts
dincli system import-deployments --foundry — new flag that auto-resolves to foundry/deployments/.json (with local → localhost mapping); --file and --foundry together are rejected as mutually exclusive; default hardhat behaviour is unchanged
E2e verified: anvil → forge script DeployPlatform.s.sol --broadcast → dincli system import-deployments --foundry → din_info.json updated with correct addresses