From a7d577333f6500f790997423a65cfd8733c405ac Mon Sep 17 00:00:00 2001 From: Ramarti Date: Sun, 13 Oct 2024 19:05:54 -0300 Subject: [PATCH] Upgrade tooling scripts, fix in deploy script. (#204) * fix missing role in deploy script, versioning output files, helper upgrade scripts * removed empty deployment file --- deploy-out/deployment-1.json | 10 ---- script/foundry/deployment/Main.s.sol | 2 +- script/foundry/deployment/MockAssets.s.sol | 2 +- script/foundry/utils/DeployHelper.sol | 13 +++-- .../foundry/utils/JsonDeploymentHandler.s.sol | 4 +- .../foundry/utils/upgrades/DeployerUtils.sol | 32 ++++++++++++ .../utils/upgrades/StorageLayoutCheck.s.sol | 7 +-- .../utils/upgrades/UpgradeImplHelper.sol | 50 +++++++++++++++++++ test/foundry/utils/TestProxyHelper.sol | 2 +- 9 files changed, 97 insertions(+), 25 deletions(-) delete mode 100644 deploy-out/deployment-1.json create mode 100644 script/foundry/utils/upgrades/DeployerUtils.sol create mode 100644 script/foundry/utils/upgrades/UpgradeImplHelper.sol diff --git a/deploy-out/deployment-1.json b/deploy-out/deployment-1.json deleted file mode 100644 index 0d02fcb95..000000000 --- a/deploy-out/deployment-1.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "main": { - "AccessController": "0xE2307e3710d108ceC7a4722a020a050681c835b3", - "ERC6551Registry": "0xD28F3246f047Efd4059B24FA1fa587eD9fa3e77F", - "IPAccountImpl": "0x15F2ea83eB97ede71d84Bd04fFF29444f6b7cd52", - "IPAccountRegistry": "0x519b05b3655F4b89731B677d64CEcf761f4076f6", - "LicenseRegistry": "0x057cD3082EfED32d5C907801BF3628B27D88fD80", - "ModuleRegistry": "0x0B32a3F8f5b7E5d315b9E52E640a49A89d89c820" - } -} \ No newline at end of file diff --git a/script/foundry/deployment/Main.s.sol b/script/foundry/deployment/Main.s.sol index 5eedbd375..b7643dcfd 100644 --- a/script/foundry/deployment/Main.s.sol +++ b/script/foundry/deployment/Main.s.sol @@ -34,7 +34,7 @@ contract Main is DeployHelper { /// @dev To use, run the following command (e.g. for Sepolia): /// forge script script/foundry/deployment/Main.s.sol:Main --rpc-url $RPC_URL --broadcast --verify -vvvv - function run() public virtual override { + function run() public virtual { _run(CREATE3_DEFAULT_SEED); } diff --git a/script/foundry/deployment/MockAssets.s.sol b/script/foundry/deployment/MockAssets.s.sol index 901719a5d..79da8bbe9 100644 --- a/script/foundry/deployment/MockAssets.s.sol +++ b/script/foundry/deployment/MockAssets.s.sol @@ -45,7 +45,7 @@ contract MockAssets is Script, BroadcastManager, JsonDeploymentHandler { } function _postdeploy(string memory contractKey, address newAddress) private { - _writeAddress(contractKey, newAddress); console2.log(string.concat(contractKey, " deployed to:"), newAddress); + _writeAddress(contractKey, newAddress); } } diff --git a/script/foundry/utils/DeployHelper.sol b/script/foundry/utils/DeployHelper.sol index 6bfce899d..a82c40b8f 100644 --- a/script/foundry/utils/DeployHelper.sol +++ b/script/foundry/utils/DeployHelper.sol @@ -171,8 +171,8 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag } // This will run OZ storage layout check for all contracts. Requires --ffi flag. - if (runStorageLayoutCheck) super.run(); - + //if (runStorageLayoutCheck) _validate(); + _beginBroadcast(); // BroadcastManager.s.sol _deployProtocolContracts(); @@ -191,8 +191,11 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag revert RoleConfigError("RoyaltyModule is not owner of ipRoyaltyVaultBeacon"); } - if (!multisigAdmin || !multisigUpgrader) { - revert RoleConfigError("Multisig roles not granted"); + if (!multisigAdmin) { + revert RoleConfigError("Multisig admin role not granted"); + } + if (!multisigUpgrader) { + revert RoleConfigError("Multisig upgrader role not granted"); } if (writeDeploys) _writeDeployment(version); @@ -684,8 +687,8 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag function _postdeploy(string memory contractKey, address newAddress) private { if (writeDeploys) { - _writeAddress(contractKey, newAddress); console2.log(string.concat(contractKey, " deployed to:"), newAddress); + _writeAddress(contractKey, newAddress); } } diff --git a/script/foundry/utils/JsonDeploymentHandler.s.sol b/script/foundry/utils/JsonDeploymentHandler.s.sol index 52dfc056d..a12e71e55 100644 --- a/script/foundry/utils/JsonDeploymentHandler.s.sol +++ b/script/foundry/utils/JsonDeploymentHandler.s.sol @@ -5,7 +5,7 @@ import { Script } from "forge-std/Script.sol"; import { stdJson } from "forge-std/StdJson.sol"; import { console2 } from "forge-std/console2.sol"; -import { UpgradedImplHelper } from "../utils/upgrades/UpgradedImplHelper.sol"; +import { UpgradedImplHelper } from "./upgrades/UpgradedImplHelper.sol"; import { StringUtil } from "../../../script/foundry/utils/StringUtil.sol"; contract JsonDeploymentHandler is Script { @@ -81,4 +81,4 @@ contract JsonDeploymentHandler is Script { console2.log(output); vm.writeJson(output, string.concat(path, chainId, ".json"), string.concat(".", internalKey)); } -} +} \ No newline at end of file diff --git a/script/foundry/utils/upgrades/DeployerUtils.sol b/script/foundry/utils/upgrades/DeployerUtils.sol new file mode 100644 index 000000000..9346d8bc6 --- /dev/null +++ b/script/foundry/utils/upgrades/DeployerUtils.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.23; + +import { console2 } from "forge-std/console2.sol"; +import { ERC6551Registry } from "erc6551/ERC6551Registry.sol"; +import { ICreate3Deployer } from "@create3-deployer/contracts/ICreate3Deployer.sol"; + +contract DeployerUtils { + + ERC6551Registry internal immutable erc6551Registry; + ICreate3Deployer internal immutable create3Deployer; + // seed for CREATE3 salt + uint256 internal create3SaltSeed; + + constructor( + address _erc6551Registry, + address _create3Deployer, + uint256 _create3SaltSeed + ) { + erc6551Registry = ERC6551Registry(_erc6551Registry); + create3Deployer = ICreate3Deployer(_create3Deployer); + create3SaltSeed = _create3SaltSeed; + } + + function _getSalt(string memory name) internal virtual view returns (bytes32 salt) { + console2.log(name); + salt = keccak256(abi.encode(name, create3SaltSeed)); + console2.logBytes32(salt); + } + + +} \ No newline at end of file diff --git a/script/foundry/utils/upgrades/StorageLayoutCheck.s.sol b/script/foundry/utils/upgrades/StorageLayoutCheck.s.sol index 4b3df4ff6..271424fa3 100644 --- a/script/foundry/utils/upgrades/StorageLayoutCheck.s.sol +++ b/script/foundry/utils/upgrades/StorageLayoutCheck.s.sol @@ -20,14 +20,11 @@ contract StorageLayoutChecker is Script { using strings for *; - function run() virtual public { - _validate(); - } /// @notice Runs the storage layout check /// @dev For simplicity and efficiency, we check all the upgradeablecontracts in the project /// instead of going 1 by 1 using ffi. - function _validate() private { + function _validate() internal { string[] memory inputs = _buildValidateCommand(); Vm.FfiResult memory result = Utils.runAsBashCommand(inputs); string memory stdout = string(result.stdout); @@ -65,4 +62,4 @@ contract StorageLayoutChecker is Script { return inputs; } -} +} \ No newline at end of file diff --git a/script/foundry/utils/upgrades/UpgradeImplHelper.sol b/script/foundry/utils/upgrades/UpgradeImplHelper.sol new file mode 100644 index 000000000..6bc793707 --- /dev/null +++ b/script/foundry/utils/upgrades/UpgradeImplHelper.sol @@ -0,0 +1,50 @@ +/* solhint-disable no-console */ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.23; + +import { console2 } from "forge-std/console2.sol"; + +contract UpgradedImplHelper { + struct UpgradeProposal { + string key; + address proxy; + address newImpl; + // bytes initCall; TODO + } + + // Upgrade tracking + UpgradeProposal[] public upgradeProposals; + + function _addProposal( + string memory key, + address proxy, + address newImpl + ) internal { + require(proxy != address(0), "UpgradeImplHelper: Invalid proxy address"); + require(newImpl != address(0), "UpgradeImplHelper: Invalid new implementation address"); + upgradeProposals.push( + UpgradeProposal({ + key: key, + proxy: proxy, + newImpl: newImpl + }) + ); + } + + function _logUpgradeProposals() internal view { + console2.log("Upgrade Proposals"); + console2.log("Count", upgradeProposals.length); + for (uint256 i = 0; i < upgradeProposals.length; i++) { + console2.log("Proposal"); + console2.log(upgradeProposals[i].key); + if (keccak256(abi.encodePacked(upgradeProposals[i].key)) == keccak256(abi.encodePacked("IpRoyaltyVault"))) { + console2.log("BeaconProxy"); + } else { + console2.log("Proxy"); + } + console2.log(upgradeProposals[i].proxy); + console2.log("New Impl"); + console2.log(upgradeProposals[i].newImpl); + } + } +} \ No newline at end of file diff --git a/test/foundry/utils/TestProxyHelper.sol b/test/foundry/utils/TestProxyHelper.sol index 08ae62598..0cfbc90b2 100644 --- a/test/foundry/utils/TestProxyHelper.sol +++ b/test/foundry/utils/TestProxyHelper.sol @@ -5,7 +5,7 @@ import { ICreate3Deployer } from "@create3-deployer/contracts/ICreate3Deployer.s library TestProxyHelper { /// Deploys a new UUPS proxy with the provided implementation and data - /// @dev WARNING: DO NOT USE IN PRODUCTION, this doesn't check for storage layout compatibility + /// @dev WARNING: DO NOT USE IN PRODUCTION without checking storage layout compatibility /// @param impl address of the implementation contract /// @param data encoded initializer call function deployUUPSProxy(address impl, bytes memory data) internal returns (address) {