Skip to content

Commit

Permalink
deployment: update prep-upgrade.js to take in an init contract address
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-fruitful committed Oct 2, 2023
1 parent 4540da1 commit bde9637
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
32 changes: 29 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ facetAction=1 # 0 - all, 1 - changed, 2 - listed
deploymentSalt=0xdeffffffff
ownerAddress=0x931c3aC09202650148Edb2316e97815f904CF4fa
systemAdminAddress=0x2dF0a6dB2F0eF1269bE777C856A7665eeC00649f
initDiamondAddress=
updateStateAddress=

.DEFAULT_GOAL := help

Expand Down Expand Up @@ -256,6 +256,32 @@ deploy-mainnet-sim: ## simulate deploy to mainnet
-vv \
--ffi

deploy-mainnet-init: ## upgrade to mainnet with a state update via a state updating (init) contract
@forge script SmartDeploy \
-s "smartDeploy(bool, address, address, address, uint8, string[] memory, bytes32)" ${newDiamond} ${ownerAddress} ${systemAdminAddress} ${updateStateAddress} ${facetAction} ${facetsToCutIn} ${deploymentSalt} \
-f ${ETH_MAINNET_RPC_URL} \
--chain-id 1 \
--etherscan-api-key ${ETHERSCAN_API_KEY} \
--sender ${ownerAddress} \
--mnemonic-paths ./nayms_mnemonic.txt \
--mnemonic-indexes 19 \
-vv \
--ffi \
--broadcast \
--slow \
--verify --delay 30 --retries 10 \
; node cli-tools/postproc-broadcasts.js

deploy-mainnet-init-sim: ## simulate upgrade to mainnet with a state update via a state updating (init) contract
@forge script SmartDeploy \
-s "smartDeploy(bool, address, address, address, uint8, string[] memory, bytes32)" ${newDiamond} ${ownerAddress} ${systemAdminAddress} ${updateStateAddress} ${facetAction} ${facetsToCutIn} ${deploymentSalt} \
-f ${ETH_MAINNET_RPC_URL} \
--chain-id 1 \
--etherscan-api-key ${ETHERSCAN_API_KEY} \
--sender ${ownerAddress} \
-vv \
--ffi

deploy-mainnet-fork: ## smart deploy to local mainnet fork
@cast rpc anvil_impersonateAccount ${mainnetSysAdmin} && \
cast send ${diamondAddress} "transferOwnership(address)" \
Expand Down Expand Up @@ -491,7 +517,7 @@ anvil-upgrade-init: ## Anvil - upgrading a diamond WITH InitDiamond

anvil-upgrade-init-addr: ## Anvil - upgrading a diamond WITH InitDiamond AND pass in init diamond address
forge script SmartDeploy \
-s "smartDeploy(bool, address, address, address, uint8, string[] memory, bytes32)" false ${ownerAddress} ${systemAdminAddress} ${initDiamondAddress} 1 ${facetsToCutIn} ${deploymentSalt} \
-s "smartDeploy(bool, address, address, address, uint8, string[] memory, bytes32)" false ${ownerAddress} ${systemAdminAddress} ${updateStateAddress} 1 ${facetsToCutIn} ${deploymentSalt} \
-f http:\\127.0.0.1:8545 \
--chain-id 31337 \
--sender ${ownerAddress} \
Expand All @@ -503,7 +529,7 @@ anvil-upgrade-init-addr: ## Anvil - upgrading a diamond WITH InitDiamond AND pas

anvil-upgrade-init-addr-sim: ## Anvil - simulate upgrading a diamond WITH InitDiamond AND pass in init diamond address. Use this to get the upgrade hash.
forge script SmartDeploy \
-s "smartDeploy(bool, address, address, address, uint8, string[] memory, bytes32)" false ${ownerAddress} ${systemAdminAddress} ${initDiamondAddress} 1 ${facetsToCutIn} ${deploymentSalt} \
-s "smartDeploy(bool, address, address, address, uint8, string[] memory, bytes32)" false ${ownerAddress} ${systemAdminAddress} ${updateStateAddress} 1 ${facetsToCutIn} ${deploymentSalt} \
-f http:\\127.0.0.1:8545 \
--chain-id 31337 \
--sender ${ownerAddress} \
Expand Down
27 changes: 18 additions & 9 deletions cli-tools/prep-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const path = require("path");
const ethers = require("ethers");
// Define the FacetCutAction enum
const facetCutActionEnum = {
0: "Add",
1: "Replace",
2: "Remove",
0: "Add",
1: "Replace",
2: "Remove",
};

const filePath = process.argv[2]; // get the file path from CLI argument

const generateS03UpgradeDiamond = (facetCuts) => {
const generateS03UpgradeDiamond = (facetCuts, updateStateAddress) => {
let script = `// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
Expand Down Expand Up @@ -47,7 +47,7 @@ contract S03UpgradeDiamond is DeploymentHelpers {
if (i === 0) {
script += ` bytes4[] memory f = new bytes4[](${facetCut.functionSelectors.length});\n`;
} else {
script += ` f = new bytes4[](${facetCut.functionSelectors.length});\n`;
script += ` f = new bytes4[](${facetCut.functionSelectors.length});\n`;
}

facetCut.functionSelectors.forEach((selector, j) => {
Expand All @@ -59,9 +59,17 @@ contract S03UpgradeDiamond is DeploymentHelpers {
});

script += `
vm.startBroadcast(_ownerAddress);
nayms.diamondCut(cut, address(0), new bytes(0));
vm.stopBroadcast();
vm.startBroadcast(_ownerAddress);`;

if (updateStateAddress) {
script += `
nayms.diamondCut(cut, address(${updateStateAddress}), abi.encodeWithSignature("initialize()"));\n`;
} else {
script += `
nayms.diamondCut(cut, address(0), new bytes(0));\n`;
}

script += ` vm.stopBroadcast();
}
}
`;
Expand Down Expand Up @@ -101,8 +109,9 @@ fs.readFile(filePath, "utf8", (err, data) => {
return { facetAddress, action, functionSelectors };
});

const updateStateAddress = process.argv[3];
// Write the script to the S03UpgradeDiamond.s.sol file
fs.writeFile(path.join(__dirname, "../script/deployment/S03UpgradeDiamond.s.sol"), generateS03UpgradeDiamond(facetCuts), (err) => {
fs.writeFile(path.join(__dirname, "../script/deployment/S03UpgradeDiamond.s.sol"), generateS03UpgradeDiamond(facetCuts, updateStateAddress), (err) => {
if (err) {
console.error(`Error writing file to disk: ${err}`);
} else {
Expand Down

0 comments on commit bde9637

Please sign in to comment.