Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
Primata committed Sep 13, 2024
1 parent b0be4a5 commit 7710b45
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 42 deletions.
15 changes: 10 additions & 5 deletions protocol-units/settlement/mcr/contracts/script/CoreDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {TimelockController} from "@openzeppelin/contracts/governance/TimelockCon
contract CoreDeployer is MCRDeployer, StakingDeployer, StlMoveDeployer {

function run() external override(MCRDeployer, StakingDeployer, StlMoveDeployer) {

// load config data
_loadConfig();

Expand All @@ -23,26 +22,30 @@ contract CoreDeployer is MCRDeployer, StakingDeployer, StlMoveDeployer {
vm.startBroadcast(signer);

// timelock is required for all deployments
if (deployment.timelock == ZERO) {
timelock = new TimelockController(config.minDelay, config.proposers, config.executors, config.admin);
deployment.timelock = address(timelock);
}
_deployTimelock();

// Deploy or upgrade contracts conditionally
deployment.moveAdmin == ZERO && deployment.move == ZERO ?
_deployMove() : deployment.moveAdmin != ZERO && deployment.move != ZERO ?
// if move is already deployed, upgrade it
_upgradeMove() : revert("MOVE: both admin and proxy should be registered");

// requires move to be deployed
deployment.stakingAdmin == ZERO && deployment.staking == ZERO && deployment.move != ZERO ?
_deployStaking() : deployment.stakingAdmin != ZERO && deployment.staking != ZERO ?
// if staking is already deployed, upgrade it
_upgradeStaking() : revert("STAKING: both admin and proxy should be registered");

// requires move to be deployed
deployment.stlMoveAdmin == ZERO && deployment.stlMove == ZERO && deployment.move != ZERO ?
_deployStlMove() : deployment.stlMoveAdmin != ZERO && deployment.stlMove != ZERO ?
// if stlMove is already deployed, upgrade it
_upgradeStlMove() : revert("STL: both admin and proxy should be registered");

// requires staking and move to be deployed
deployment.mcrAdmin == ZERO && deployment.mcr == ZERO && deployment.move != ZERO && deployment.staking != ZERO ?
_deployMCR() : deployment.mcrAdmin != ZERO && deployment.mcr != ZERO ?
// if mcr is already deployed, upgrade it
_upgradeMCR() : revert("MCR: both admin and proxy should be registered");

// Only write to file if chainid is not running a foundry local chain
Expand All @@ -57,6 +60,8 @@ contract CoreDeployer is MCRDeployer, StakingDeployer, StlMoveDeployer {

vm.stopBroadcast();
}

// •☽────✧˖°˖DANGER ZONE˖°˖✧────☾•

function _deployMove() internal {
console.log("MOVE: deploying");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ contract MCRDeployer is Helper {
vm.startBroadcast(signer);

// timelock is required for all deployments
if (deployment.timelock == ZERO) {
timelock = new TimelockController(config.minDelay, config.proposers, config.executors, config.admin);
deployment.timelock = address(timelock);
}
_deployTimelock();

deployment.mcrAdmin == ZERO && deployment.mcr == ZERO && deployment.move != ZERO && deployment.staking != ZERO ?
_deployMCR() : deployment.mcrAdmin != ZERO && deployment.mcr != ZERO ?
Expand All @@ -41,6 +38,8 @@ contract MCRDeployer is Helper {
}
}

// •☽────✧˖°˖DANGER ZONE˖°˖✧────☾•

function _deployMCR() internal {
console.log("MCR: deploying");
MCR mcrImplementation = new MCR();
Expand Down Expand Up @@ -79,7 +78,7 @@ contract MCRDeployer is Helper {
),
bytes32(0),
bytes32(0),
block.timestamp + config.minDelay
config.minDelay
);
json.serialize("to", address(timelock));
string memory zero = "0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ contract StakingDeployer is Helper {
vm.startBroadcast(signer);

// timelock is required for all deployments
if (deployment.timelock == ZERO) {
timelock = new TimelockController(config.minDelay, config.proposers, config.executors, config.admin);
deployment.timelock = address(timelock);
}
_deployTimelock();

deployment.stakingAdmin == ZERO && deployment.staking == ZERO && deployment.move != ZERO ?
_deployStaking() : deployment.stakingAdmin != ZERO && deployment.staking != ZERO ?
Expand All @@ -38,6 +35,8 @@ contract StakingDeployer is Helper {
}
}

// •☽────✧˖°˖DANGER ZONE˖°˖✧────☾•

function _deployStaking() internal {
console.log("STAKING: deploying");
MovementStaking stakingImplementation = new MovementStaking();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ contract StlMoveDeployer is Helper {
vm.startBroadcast(signer);

// timelock is required for all deployments
if (deployment.timelock == ZERO) {
timelock = new TimelockController(config.minDelay, config.proposers, config.executors, config.admin);
deployment.timelock = address(timelock);
}
_deployTimelock();

deployment.stlMoveAdmin == ZERO && deployment.stlMove == ZERO && deployment.move != ZERO ?
_deployStlMove() : deployment.stlMoveAdmin != ZERO && deployment.stlMove != ZERO ?
Expand All @@ -38,6 +35,8 @@ contract StlMoveDeployer is Helper {
}
}

// •☽────✧˖°˖DANGER ZONE˖°˖✧────☾•

function _deployStlMove() internal {
console.log("STL: deploying");
stlMoveToken stlMoveImplementation = new stlMoveToken();
Expand Down
44 changes: 23 additions & 21 deletions protocol-units/settlement/mcr/contracts/script/helpers/Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ contract Helper is Script {
TransparentUpgradeableProxy public stlMoveProxy;
TransparentUpgradeableProxy public stakingProxy;
TransparentUpgradeableProxy public mcrProxy;

TimelockController public timelock;
string public mcrSignature = "initialize(address,uint256,uint256,uint256,address[])";
string public stakingSignature = "initialize(address)";
Expand Down Expand Up @@ -65,13 +64,21 @@ contract Helper is Script {

function _loadDeployments() internal {
// load deployments
// Inspo https://github.com/traderjoe-xyz/joe-v2/blob/main/script/deploy-core.s.sol
string memory path = string.concat(root, deploymentsPath);
string memory json = vm.readFile(path);
bytes memory rawDeploymentData = json.parseRaw(string(abi.encodePacked(".", chainId)));
deployment = abi.decode(rawDeploymentData, (Deployment));
storageJson = json;
}

function _deployTimelock() internal {
if (deployment.timelock == ZERO) {
timelock = new TimelockController(config.minDelay, config.proposers, config.executors, config.admin);
deployment.timelock = address(timelock);
}
}

function _storeAdminDeployment() internal returns (address admin) {
Vm.Log[] memory logs = vm.getRecordedLogs();
admin = logs[logs.length-2].emitter;
Expand All @@ -82,17 +89,7 @@ contract Helper is Script {
string memory path = string.concat(root, deploymentsPath);
string memory json = storageJson;
string memory base = "new";
json.serialize("move", deployment.move);
json.serialize("moveAdmin", deployment.moveAdmin);
json.serialize("staking", deployment.staking);
json.serialize("stakingAdmin", deployment.stakingAdmin);
json.serialize("stlMove", deployment.stlMove);
json.serialize("stlMoveAdmin", deployment.stlMoveAdmin);
json.serialize("mcr", deployment.mcr);
json.serialize("mcrAdmin", deployment.mcrAdmin);
json.serialize("timelock", deployment.timelock);
string memory newChainData = json.serialize("multisig", deployment.multisig);

string memory newChainData = _serializer(json, deployment);
// take values from storageJson that were not updated (e.g. 3771) and serialize them
uint256[] memory validChains = new uint256[](4);
validChains[0] = 1; // ethereum
Expand All @@ -113,18 +110,23 @@ contract Helper is Script {
bytes memory rawDeploymentData = sJson.parseRaw(string(abi.encodePacked(".", uint2str(chain))));
Deployment memory deploymentData = abi.decode(rawDeploymentData, (Deployment));
string memory json = uint2str(chain);
json.serialize("move", deploymentData.move);
json.serialize("moveAdmin", deploymentData.moveAdmin);
json.serialize("staking", deploymentData.staking);
json.serialize("stakingAdmin", deploymentData.stakingAdmin);
json.serialize("stlMove", deploymentData.stlMove);
json.serialize("stlMoveAdmin", deploymentData.stlMoveAdmin);
json.serialize("mcr", deploymentData.mcr);
json.serialize("mcrAdmin", deploymentData.mcrAdmin);
string memory chainData = json.serialize("timelock", deploymentData.timelock);
string memory chainData = _serializer(json, deploymentData);
base.serialize(uint2str(chain), chainData);
}

function _serializer(string memory json, Deployment memory deployment) internal returns (string memory) {
json.serialize("move", deployment.move);
json.serialize("moveAdmin", deployment.moveAdmin);
json.serialize("staking", deployment.staking);
json.serialize("stakingAdmin", deployment.stakingAdmin);
json.serialize("stlMove", deployment.stlMove);
json.serialize("stlMoveAdmin", deployment.stlMoveAdmin);
json.serialize("mcr", deployment.mcr);
json.serialize("mcrAdmin", deployment.mcrAdmin);
json.serialize("timelock", deployment.timelock);
return json.serialize("multisig", deployment.multisig);
}

// string to address
function s2a(bytes memory str) public returns (address addr) {
bytes32 data = keccak256(str);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"data":"0x01d5062a0000000000000000000000001d2fbd705240d438f00bc225643c0b342ed0ee35000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000849623609d000000000000000000000000e0d1c060c7fcd0b8024a6486a83f35d3262e430100000000000000000000000030133f993afe13cbeccc84b07e98f1101075919a0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","operation":"OperationType.Call","to":"0xF927E1Ab4b4Eb8D8811e4Ad224bF0eea7004F87c","value":0}
{"chainId":"31337","data":"0x01d5062a0000000000000000000000001d2fbd705240d438f00bc225643c0b342ed0ee35000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000849623609d000000000000000000000000e0d1c060c7fcd0b8024a6486a83f35d3262e430100000000000000000000000030133f993afe13cbeccc84b07e98f1101075919a0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","operation":"OperationType.Call","safeAddress":"0x4494435752a88a5458F436c8a2E6D382A02b3A73","to":"0xF927E1Ab4b4Eb8D8811e4Ad224bF0eea7004F87c","value":"0"}
11 changes: 9 additions & 2 deletions protocol-units/settlement/mcr/contracts/test/Deployer.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "forge-std/Test.sol";
import "../../src/token/MOVEToken.sol";

contract DeployerTest is Test {

}

function setUp() public {
// Set the sender address
}
}

0 comments on commit 7710b45

Please sign in to comment.