Skip to content

Commit

Permalink
Add option to encode old diamond-cut upgrade data
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbochok committed Jan 16, 2023
1 parent f7f76aa commit 892f36b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,39 @@ pragma solidity ^0.8.0;
import "../libraries/Diamond.sol";
import "../facets/Base.sol";

interface IOldDiamondCut {
function proposeDiamondCut(Diamond.FacetCut[] calldata _facetCuts, address _initAddress) external;

function cancelDiamondCutProposal() external;

function executeDiamondCutProposal(Diamond.DiamondCutData calldata _diamondCut) external;

function emergencyFreezeDiamond() external;

function unfreezeDiamond() external;

function approveEmergencyDiamondCutAsSecurityCouncilMember(bytes32 _diamondCutHash) external;

// FIXME: token holders should have the ability to cancel the upgrade

event DiamondCutProposal(Diamond.FacetCut[] _facetCuts, address _initAddress);

event DiamondCutProposalCancelation(uint256 currentProposalId, bytes32 indexed proposedDiamondCutHash);

event DiamondCutProposalExecution(Diamond.DiamondCutData _diamondCut);

event EmergencyFreeze();

event Unfreeze(uint256 lastDiamondFreezeTimestamp);

event EmergencyDiamondCutApproved(
address indexed _address,
uint256 currentProposalId,
uint256 securityCouncilEmergencyApprovals,
bytes32 indexed proposedDiamondCutHash
);
}

/// @author Matter Labs
contract DiamondUpgradeInit3 is Base {
function upgrade(
Expand Down
30 changes: 30 additions & 0 deletions ethereum/scripts/diamond-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ async function main() {
print('Facets', facets);
});

program.command('legacy-prepare-upgrade-calldata <facetCuts>')
.option('--init-address <init-address>')
.option('--init-data <init-data>')
.action(async (facetCutsData: string, cmd) => {
const diamondCutFacet = await hardhat.ethers.getContractAt('IOldDiamondCut', ZERO_ADDRESS);

// Encode data for the upgrade call
const facetCuts: Array<FacetCut> = JSON.parse(facetCutsData);

const initAddress = cmd.initAddress ? cmd.initAddress : ZERO_ADDRESS;
const initData = cmd.initData ? cmd.initData : '0x';

const upgradeParam = diamondCut(facetCuts, initAddress, initData);
print('DiamondCutData', upgradeParam);

// Get transaction data of the `proposeDiamondCut`
const proposeUpgrade = await diamondCutFacet.interface.encodeFunctionData('proposeDiamondCut', [
upgradeParam.facetCuts,
upgradeParam.initAddress
]);

// Get transaction data of the `executeDiamondCutProposal`
const executeUpgrade = await diamondCutFacet.interface.encodeFunctionData('executeDiamondCutProposal', [
upgradeParam
]);

print('proposeUpgrade', proposeUpgrade);
print('executeUpgrade', executeUpgrade);
});

program
.command('prepare-upgrade-calldata <facetCuts>')
.option('--init-address <init-address>')
Expand Down
13 changes: 7 additions & 6 deletions ethereum/scripts/upgrades/upgrade-3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { web3Provider } from '../utils';
import { Deployer } from '../../src.ts/deploy';
import * as fs from 'fs';
import * as path from 'path';
import { IOldDiamondCutFactory } from '../../typechain/IOldDiamondCutFactory';

function sleep(millis: number) {
return new Promise((resolve) => setTimeout(resolve, millis));
Expand Down Expand Up @@ -84,7 +85,8 @@ async function main() {
governorAddress: ZERO_ADDRESS,
verbose: true
});
const zkSyncContract = deployer.zkSyncContract(deployWallet);

const zkSyncContract = IOldDiamondCutFactory.connect(deployer.addresses.ZkSync.DiamondProxy, deployWallet);

// Get address of the diamond init contract
const diamondUpgradeAddress = cmd.diamondUpgradeAddress;
Expand All @@ -97,14 +99,13 @@ async function main() {
// Get diamond cut data
const upgradeParam = await prepareCalldata(diamondUpgradeAddress, allowlist, verifier, prioirityTxMaxErgsLimit);

const proposalId = cmd.proposalId ? cmd.proposalId : await zkSyncContract.getCurrentProposalId();
const proposeUpgradeTx = await zkSyncContract.proposeTransparentUpgrade(
upgradeParam,
proposalId
const proposeUpgradeTx = await zkSyncContract.proposeDiamondCut(
upgradeParam.facetCuts,
upgradeParam.initAddress
);
await proposeUpgradeTx.wait();

const executeUpgradeTx = await zkSyncContract.executeUpgrade(upgradeParam, ethers.constants.HashZero);
const executeUpgradeTx = await zkSyncContract.executeDiamondCutProposal(upgradeParam);
const executeUpgradeRec = await executeUpgradeTx.wait();
const deployL2TxHashes = executeUpgradeRec.events
.filter((event) => event.event === 'NewPriorityRequest')
Expand Down

0 comments on commit 892f36b

Please sign in to comment.