Skip to content

Commit

Permalink
Upgrade tooling scripts, fix in deploy script. (storyprotocol#204)
Browse files Browse the repository at this point in the history
* fix missing role in deploy script, versioning output files, helper upgrade scripts

* removed empty deployment file
  • Loading branch information
Ramarti authored Oct 13, 2024
1 parent 71d9dd0 commit a7d5773
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 25 deletions.
10 changes: 0 additions & 10 deletions deploy-out/deployment-1.json

This file was deleted.

2 changes: 1 addition & 1 deletion script/foundry/deployment/Main.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion script/foundry/deployment/MockAssets.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
13 changes: 8 additions & 5 deletions script/foundry/utils/DeployHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions script/foundry/utils/JsonDeploymentHandler.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -81,4 +81,4 @@ contract JsonDeploymentHandler is Script {
console2.log(output);
vm.writeJson(output, string.concat(path, chainId, ".json"), string.concat(".", internalKey));
}
}
}
32 changes: 32 additions & 0 deletions script/foundry/utils/upgrades/DeployerUtils.sol
Original file line number Diff line number Diff line change
@@ -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);
}


}
7 changes: 2 additions & 5 deletions script/foundry/utils/upgrades/StorageLayoutCheck.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -65,4 +62,4 @@ contract StorageLayoutChecker is Script {

return inputs;
}
}
}
50 changes: 50 additions & 0 deletions script/foundry/utils/upgrades/UpgradeImplHelper.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
2 changes: 1 addition & 1 deletion test/foundry/utils/TestProxyHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a7d5773

Please sign in to comment.