Skip to content

Commit

Permalink
Deploy script for the protocol and plugin upgrades (#384)
Browse files Browse the repository at this point in the history
* feat: protect the DAO executor against reentrancy

* fix: remove console.log

* fix: prevent storage corruption

* feat: refactored reentrancy guard into a modifier

* feat: added tests and preliminary versioning

* chore: cleaning

* fix: remove empty comment

* fix: refactor findEventTopicLog function

* fix: moved implementation slot and renamed file

* fix: remove redundant includes

* prepare package

* remember the branch

* only artifact src

* correct the paths

* correct root path

* update hashes

* add logs

* only copy typechain

* generate typechain

* setup rollup

* update npm packages

* update rollup index

* add esm cjs

* add readme

* remove gitIgnore

* update typechain

* update typescript

* convert script to typescript

* change commit hash json

* rename types to typechain

* add test

* add json to rollup and export types

* update usage test

* generate index.ts dynamically

* update readme

* add empty line

* update commit hashes

* fix index.ts

* chore: update test

* fix: removed redundant imports

* chore: remove legacy version files of DAO

* fix: adapt contracts-version tests

* fix: remove version in title as contracts will get a constant

* fix: compile legacy contracts for regression testing

* Revert "fix: compile legacy contracts for regression testing "

This reverts commit 403436c.

* revert versioning changes

* adapt tests

* test with creating symbolic link

* correct path

* feat: added tests for proposal start and end date handling

* fix: corrected wrong validation order

* Revert "chore: remove legacy version files of DAO"

This reverts commit 57f755c.

* add legacy versions

* fix: renaming of the versions

* chore: remove old CI task

* chore: maintained changelog

* fix: version numbers

* fix: imports

* WIP

* doc: clarified the origin of the implementation slot

* fix: versioning

* fix: move files

* Apply suggestions from code review

Co-authored-by: Jør∂¡ <4456749+brickpop@users.noreply.github.com>

* chore: formatting

* chore: remove NatSpec version number from osx files

* feat: added more tests

* Applied review suggestion

Co-authored-by: Rekard0 <5880388+Rekard0@users.noreply.github.com>

* feat: added test checking that execution is still possible after the upgrade

* Improved comments

* feat: initialize _rentrancyStatus

* doc: clarify comments

* fix: change version number

* fix: use upgradeToAndCall and correct versions

* feat: added initializeUpgradeFrom function and tests

* feat: improved function and added more tests

* WIP

* fix: tests

* fix: finalize tests

* fix typechain and add a script

* fix: typo

* feat: improve initializeUpgradeFrom

* feat: added _initData parameter

* feat: added test

* fix: wrong version number

* WIP

* fix remaining tests

* fix subgraph

* add ref depth

* fix: replacing getContractFactory and getContractAt by typechain factory calls  and added missing awaits

* fix: test timings

* fix: re-introduced yarn postinstall

* fix: remove redundant includes

* fix: adapt upgrade tests

* feat: optimize if statements

* fix: tests

* feat: rename initializeUpgradeFrom to initializeFrom

* fix: correct test description

* fix: removed duplicate file

* fix: typo

* fix: delete legacy files

* revert: metadata changes as they will happen in #375

* fix: merge conflicts

* fix: re-order changelog entries

* fix: remove wrong/redundant import originating from merge

* feat: improve upgrade version checks

* fix: remove redundant ROOT_PERMISSION grant call

* feat: added more checks to the upgrade tests

* feat: more explicit variable naming

* fix: reworked initializeFrom logic

* feat: improved changelog entry

* feat: improved comment

* fix: use factories

* feat: added deploy scripts

* fix: use the correct deployment method

* chore: remove the old, unused script for the v1.2.0 update

* fix: use deploy method


fix: use deploy method

* fix: file name

* feat: improve scripts by adding a TARGET_RELEASE variable

* fix: file name

* fix: wrong interface

* fix: import order

---------

Co-authored-by: Rekard0 <5880388+Rekard0@users.noreply.github.com>
Co-authored-by: Jør∂¡ <4456749+brickpop@users.noreply.github.com>
  • Loading branch information
3 people committed May 24, 2023
1 parent 14d5fe6 commit 43a5f39
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {DAO__factory} from '../../../typechain';
import {Operation} from '../../../utils/types';
import {getContractAddress} from '../../helpers';
import {DAO__factory} from '../../../typechain';

import daoFactoryArtifact from '../../../artifacts/src/framework/dao/DAOFactory.sol/DAOFactory.json';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('Updating DAOFactory');
Expand All @@ -23,6 +25,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`Using PreviousDAOFactory ${previousDAOFactoryAddress}`);

const deployResult = await deploy('DAOFactory', {
contract: daoFactoryArtifact,
from: deployer.address,
args: [daoRegistryAddress, pluginSetupProcessorAddress],
log: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {PluginRepo__factory} from '../../../typechain';
import {getContractAddress, uploadToIPFS} from '../../helpers';

import multisigSetupArtifact from '../../../artifacts/src/plugins/governance/multisig/MultisigSetup.sol/MultisigSetup.json';

import multisigReleaseMetadata from '../../../src/plugins/governance/multisig/release-metadata.json';
import multisigBuildMetadata from '../../../src/plugins/governance/multisig/build-metadata.json';

const TARGET_RELEASE = 1;

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nUpdate Multisig Plugin');
const {deployments, ethers, network} = hre;
const {deploy} = deployments;
const [deployer] = await ethers.getSigners();

const deployResult = await deploy('MultisigSetup', {
contract: multisigSetupArtifact,
from: deployer.address,
args: [],
log: true,
Expand Down Expand Up @@ -44,7 +49,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const tx = await multisigRepo
.connect(deployer)
.createVersion(
1,
TARGET_RELEASE,
deployResult.address,
ethers.utils.toUtf8Bytes(`ipfs://${multisigBuildCIDPath}`),
ethers.utils.toUtf8Bytes(`ipfs://${multisigReleaseCIDPath}`)
Expand All @@ -57,7 +62,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const tx = await multisigRepo
.connect(deployer)
.populateTransaction.createVersion(
1,
TARGET_RELEASE,
deployResult.address,
ethers.utils.toUtf8Bytes(`ipfs://${multisigBuildCIDPath}`),
ethers.utils.toUtf8Bytes(`ipfs://${multisigReleaseCIDPath}`)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {PluginRepo__factory} from '../../../typechain';
import {getContractAddress, uploadToIPFS} from '../../helpers';

import tokenVotingSetupArtifact from '../../../artifacts/src/plugins/governance/majority-voting/token/TokenVotingSetup.sol/TokenVotingSetup.json';
import tokenVotingReleaseMetadata from '../../../src/plugins/governance/majority-voting/token/release-metadata.json';
import tokenVotingBuildMetadata from '../../../src/plugins/governance/majority-voting/token/build-metadata.json';

const TARGET_RELEASE = 1;

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nUpdate TokenVoting Plugin');
const {deployments, ethers, network} = hre;
const {deploy} = deployments;
const [deployer] = await ethers.getSigners();

const deployResult = await deploy('TokenVotingSetup', {
contract: tokenVotingSetupArtifact,
from: deployer.address,
args: [],
log: true,
});

const tokenVotingReleaseCIDPath = await uploadToIPFS(
JSON.stringify(tokenVotingReleaseMetadata),
network.name
);
const tokenVotingBuildCIDPath = await uploadToIPFS(
JSON.stringify(tokenVotingBuildMetadata),
network.name
);

const tokenVotingRepoAddress = await getContractAddress(
'token-voting-repo',
hre
);
const tokenVotingRepo = PluginRepo__factory.connect(
tokenVotingRepoAddress,
ethers.provider
);
if (
await tokenVotingRepo.callStatic.isGranted(
tokenVotingRepoAddress,
deployer.address,
await tokenVotingRepo.MAINTAINER_PERMISSION_ID(),
'0x00'
)
) {
console.log(`Deployer has permission to install new TokenVoting version`);
const tx = await tokenVotingRepo
.connect(deployer)
.createVersion(
TARGET_RELEASE,
deployResult.address,
ethers.utils.toUtf8Bytes(`ipfs://${tokenVotingBuildCIDPath}`),
ethers.utils.toUtf8Bytes(`ipfs://${tokenVotingReleaseCIDPath}`)
);
console.log(`Creating new TokenVoting build version with ${tx.hash}`);
await tx.wait();
return;
}

const tx = await tokenVotingRepo
.connect(deployer)
.populateTransaction.createVersion(
TARGET_RELEASE,
deployResult.address,
ethers.utils.toUtf8Bytes(`ipfs://${tokenVotingBuildCIDPath}`),
ethers.utils.toUtf8Bytes(`ipfs://${tokenVotingReleaseCIDPath}`)
);

if (!tx.to || !tx.data) {
throw new Error(
`Failed to populate TokenVoting Repo createVersion transaction`
);
}

console.log(
`Deployer has no permission to create a new version. Adding managingDAO action`
);
hre.managingDAOActions.push({
to: tx.to,
data: tx.data,
value: 0,
description: `Creates a new build for release 1 in the TokenVotingRepo (${tokenVotingRepoAddress}) with TokenVotingSetup (${deployResult.address})`,
});
};
export default func;
func.tags = ['Update', 'TokenVotingPlugin'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nConcluding TokenVoting Plugin Update');

hre.aragonToVerifyContracts.push(
await hre.deployments.get('TokenVotingSetup')
);
};
export default func;
func.tags = ['TokenVotingPlugin', 'Verify'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {PluginRepo__factory} from '../../../typechain';
import {getContractAddress, uploadToIPFS} from '../../helpers';

import addresslistVotingSetupArtifact from '../../../artifacts/src/plugins/governance/majority-voting/addresslist/AddresslistVotingSetup.sol/AddresslistVotingSetup.json';
import addresslistVotingReleaseMetadata from '../../../src/plugins/governance/majority-voting/addresslist/release-metadata.json';
import addresslistVotingBuildMetadata from '../../../src/plugins/governance/majority-voting/addresslist/build-metadata.json';

const TARGET_RELEASE = 1;

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nUpdate AddresslistVoting Plugin');
const {deployments, ethers, network} = hre;
const {deploy} = deployments;
const [deployer] = await ethers.getSigners();

const deployResult = await deploy('AddresslistVotingSetup', {
contract: addresslistVotingSetupArtifact,
from: deployer.address,
args: [],
log: true,
});

const addresslistVotingReleaseCIDPath = await uploadToIPFS(
JSON.stringify(addresslistVotingReleaseMetadata),
network.name
);
const addresslistVotingBuildCIDPath = await uploadToIPFS(
JSON.stringify(addresslistVotingBuildMetadata),
network.name
);

const addresslistVotingRepoAddress = await getContractAddress(
'address-list-voting-repo',
hre
);
const addresslistVotingRepo = PluginRepo__factory.connect(
addresslistVotingRepoAddress,
ethers.provider
);
if (
await addresslistVotingRepo.callStatic.isGranted(
addresslistVotingRepoAddress,
deployer.address,
await addresslistVotingRepo.MAINTAINER_PERMISSION_ID(),
'0x00'
)
) {
console.log(
`Deployer has permission to install new AddresslistVoting version`
);
const tx = await addresslistVotingRepo
.connect(deployer)
.createVersion(
TARGET_RELEASE,
deployResult.address,
ethers.utils.toUtf8Bytes(`ipfs://${addresslistVotingBuildCIDPath}`),
ethers.utils.toUtf8Bytes(`ipfs://${addresslistVotingReleaseCIDPath}`)
);
console.log(`Creating new AddresslistVoting build version with ${tx.hash}`);
await tx.wait();
return;
}

const tx = await addresslistVotingRepo
.connect(deployer)
.populateTransaction.createVersion(
TARGET_RELEASE,
deployResult.address,
ethers.utils.toUtf8Bytes(`ipfs://${addresslistVotingBuildCIDPath}`),
ethers.utils.toUtf8Bytes(`ipfs://${addresslistVotingReleaseCIDPath}`)
);

if (!tx.to || !tx.data) {
throw new Error(
`Failed to populate AddresslistVoting Repo createVersion transaction`
);
}

console.log(
`Deployer has no permission to create a new version. Adding managingDAO action`
);
hre.managingDAOActions.push({
to: tx.to,
data: tx.data,
value: 0,
description: `Creates a new build for release 1 in the AddresslistVotingRepo (${addresslistVotingRepoAddress}) with AddresslistVotingSetup (${deployResult.address})`,
});
};
export default func;
func.tags = ['Update', 'AddresslistVotingPlugin'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nConcluding AddresslistVoting Plugin Update');

hre.aragonToVerifyContracts.push(
await hre.deployments.get('AddresslistVotingSetup')
);
};
export default func;
func.tags = ['AddresslistVotingPlugin', 'Verify'];

0 comments on commit 43a5f39

Please sign in to comment.