Skip to content

Commit

Permalink
Merge pull request #8 from aragon/f/mgmt-dao-setup
Browse files Browse the repository at this point in the history
Management DAO post install script
  • Loading branch information
brickpop authored Apr 15, 2024
2 parents 6d5a0ee + 28e6b52 commit ed99aad
Show file tree
Hide file tree
Showing 13 changed files with 597 additions and 132 deletions.
21 changes: 16 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
# GENERAL

## The network used for testing purposes
## The network used
NETWORK_NAME="sepolia" # ["mainnet", "sepolia", "polygon", "polygonMumbai"]

# PROTOCOL CONTRACTS
## DEPLOYMENT
DEPLOYMENT_RPC_ENDPOINT="https://host/path"

## Hex encoded private keys separated by a comma `,`
## The first item will be the deployment wallet
PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"

# OSx protocol contracts
PLUGIN_REPO_FACTORY_ADDRESS="0xA69347F49dD618cb4577670D0728684AfAa01197"
PLUGIN_SETUP_PROCESSOR_ADDRESS="0xAc7e4fB4a2f58b7EA5516f47b6f804956Faf0134"

## Hex encoded private keys separated by a comma `,`a
PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" # Default hardhat account 0 private key. DON'T USE FOR DEPLOYMENTS
MANAGING_DAO_ADDRESS="0x617e4fB3a2358b7EA5a16f47b6f1f4956Faf0162"

# Management DAO governance plugin settings
GOVERNANCE_PLUGIN_REPO_ADDRESS="0xf956Fa58b7EB3a2347b6f1f4f0A5a16f162617e4"
MGMT_DAO_PROPOSAL_DURATION="604800" # 60 * 60 * 24 * 7 seconds
MGMT_DAO_MIN_PROPOSAL_PARTICIPATION="500000" # 50%
MGMT_DAO_PROPOSAL_SUPPORT_THRESHOLD="500000" # 50%
MGMT_DAO_INITIAL_EDITORS="0x1234,0x2345,0x3456,0x4567..." # Comma separated addresses

## API keys
INFURA_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
Expand Down
111 changes: 1 addition & 110 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ yarn build
yarn test
```

See [Deployment](#deployment) below
See the [deployment checklist](./README_DEPLOYMENT.md)

## Overview

Expand Down Expand Up @@ -774,112 +774,3 @@ The plugins from this repo are built on top of many contract primitives from Ara
- `minProposerVotingPower` wasn't used

The rest of dependencies are imported directly from Aragon or from OpenZeppelin.

## Deployment

### On a blockchain supported by Aragon

If the current contracts are meant to be deployed on a blockchain like Mainnet, Sepolia, Polygon, Base, etc, the only step needed is to define the relevant env vars on `.env` and run the following command:

```sh
cd packages/contracts
npx hardhat deploy --network <replace-the-name>
```

### On a custom blockchain

In the case of specific blockchains where OSx support is not officially available, you will need to deploy it first. The high level process looks like:

0. Prepare a wallet for the whole deployment process
1. Deploy OSx
1. This will create a Managing DAO, where the deployer wallet can `execute()` actions
2. Deploy the plugins of this project
3. Install the plugin that will control the Managing DAO
4. Revoke the `ROOT_PERMISSION` from the deployment wallet on the DAO

#### 1) Deploy OSx

Clone [https://github.com/aragon/osx](the OSx repo) into a separate folder.

```sh
yarn
cd packages/contracts
yarn build
yarn test
```

- Edit the `packages/contracts/hardhat.config.ts` to include the details of your target network.
- Edit the `.env` file to make use of the deployment wallet's private key.

```sh
npx hardhat deploy --network <replace-the-name>
```

Write down the address of the deployed contracts. The result should look similar to this:

```json
{
"managingDAOImplementation": "0x731b7F3d74C9dc25A90af73B960ad51f42481d6c",
"managingDAO": "0x1C57A251B1902656693f689aA69389f2a6f2a432",
"ENSRegistry": "0xE847017f1e18F7bF35b180fD45b4dAC18E81d568",
"PublicResolver": "0xE3B1288048f898A28a78FCf9942E14Cc853fFEF2",
"DAO_ENSSubdomainRegistrar_Implementation": "0xd92C33f309D6e795DCe1980aBc42D3431b0af0e7",
"DAO_ENSSubdomainRegistrar": "0xcf9D94Ddd248694B66D1D445b85ccbE385634Cc8",
"Plugin_ENSSubdomainRegistrar_Implementation": "0x7BC82fCba3521B15792423ac4E6076582235263B",
"Plugin_ENSSubdomainRegistrar": "0xd14C706586c6177d54D201df009b75FB14E8AB5E",
"DAORegistry_Implementation": "0x66a19CC345dAB31dfb6295017819d54dB594DE56",
"DAORegistry": "0x11d3B1B24C19B5672b92CD535d2F1F35C53AC543",
"PluginRepoRegistry_Implementation": "0x38b112318cfd563Fa5de538E7c219bf72F1CcA6a",
"PluginRepoRegistry": "0x9b51505f7bf3A45BC92F6bE269324096abEC0A73",
"PluginRepoFactory": "0xA69347F49dD615cb4577670D0728684AfAa01197",
"PluginSetupProcessor": "0xAc7e4fB4a2158b7EA5516f47b6f804956Faf0134",
"DAOFactory": "0x2d11E9413264e3814C2a21160cBCcb9Dc3C96890"
}
```

You are going to need the `PluginRepoFactory`, the `PluginSetupProcessor` and the `managingDAO`.

#### 2) Deploy your plugins

On this repository:

- Edit the `packages/contracts/hardhat.config.ts` to include the details of your target network.
- Edit the `packages/contracts/plugin-setup-params.ts` to define the details of your new plugins
- Make sure that you don't deploy the same plugin repo twice, since this will cause an ENS collision
- In such case, either define a new ENS subdomain or consider running the step 1 again
- Edit the `.env` file
- Define the deployment wallet's private key
- Define the `PLUGIN_REPO_FACTORY_ADDRESS` and the `PLUGIN_SETUP_PROCESSOR_ADDRESS` from the contracts [deployed above](#1-deploy-osx)

```sh
cd packages/contracts
yarn build
npx hardhat deploy --network <replace-the-name>
```

With this step, the deployment would be technically done.

However, as the maintainer of the deployment, you are strongly encouraged to configure the Managing DAO such in a way that updates are approved by a group of people.

#### 3) Install a governance plugin to the Managing DAO

The Managing DAO is the contract that has the role of managing certain protocol modules, like the Plugin Registry, the DAO registry, etc. In case a new OSx version is available, only that DAO is be able to push upgrades and perform certain management tasks, which makes it a key component.

The Managing DAO will be created with the following permissions:

- The Managing DAO holds `ROOT_PERMISSION` on itself
- The deployer address holds `EXECUTE_PERMISSION` on the Managing DAO

Among the plugins deployed [in the step above](#2-deploy-your-plugins), one of them should be installed to the Managing DAO.

In your custom script make sure to:

1. Use the same deployment wallet as before
2. Call `prepareInstallation()` on the Plugin Setup Processor deployed during the [Deploy OSX](#1-deploy-osx) step
3. Call `execute()` on the Managing DAO, with an action that calls `applyInstallation()` on the Plugin Setup Processor

#### 4) Drop the ROOT permission of the deployer

In the same custom script as before:

1. Call `execute()` on the Managing DAO, with an action that calls `revoke(dao, deploymentWalletAddr, ROOT_PERMISSION_ID)` on the DAO itself
120 changes: 120 additions & 0 deletions README_DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Geo Browser - Aragon OSx

## Deployment

### On a blockchain supported by Aragon

If the current contracts are meant to be deployed on a blockchain like Mainnet, Sepolia, Polygon, Base, etc, the only step needed is to define the relevant env vars on `.env` and run the following command:

```sh
cd packages/contracts
npx hardhat deploy --network <the-network-name>
```

### On a custom blockchain

In the case of specific blockchains where OSx support is not officially available, you will need to deploy it first. The high level process looks like:

0. Prepare a wallet for the whole deployment process
1. Deploy OSx
1. This will create a Managing DAO, where the deployer wallet can `execute()` actions
2. Deploy the plugins of this project
3. Install the plugin that will control the Managing DAO and revoke the `ROOT_PERMISSION` from the deployment wallet

#### 1) Deploy OSx

Clone [the OSx repo](https://github.com/aragon/osx) into a separate folder.

```sh
git checkout deployments/simpler-deployment
yarn
cd packages/contracts
cp .env.example .env
nano .env # Update the values
yarn build
# yarn test (optional)
```

- Open the [DEPLOYMENT_CHECKLIST.md](https://github.com/aragon/osx/blob/deployments/simpler-deployment/DEPLOYMENT_CHECKLIST.md) file and follow the instructions

Write down the address of the deployed contracts. The result should look similar to this:

```json
{
"managingDAOImplementation": "0x731b7F3d74C9dc25A90af73B960ad51f42481d6c",
"managingDAO": "0x1C57A251B1902656693f689aA69389f2a6f2a432",
"ENSRegistry": "0xE847017f1e18F7bF35b180fD45b4dAC18E81d568",
"PublicResolver": "0xE3B1288048f898A28a78FCf9942E14Cc853fFEF2",
"DAO_ENSSubdomainRegistrar_Implementation": "0xd92C33f309D6e795DCe1980aBc42D3431b0af0e7",
"DAO_ENSSubdomainRegistrar": "0xcf9D94Ddd248694B66D1D445b85ccbE385634Cc8",
"Plugin_ENSSubdomainRegistrar_Implementation": "0x7BC82fCba3521B15792423ac4E6076582235263B",
"Plugin_ENSSubdomainRegistrar": "0xd14C706586c6177d54D201df009b75FB14E8AB5E",
"DAORegistry_Implementation": "0x66a19CC345dAB31dfb6295017819d54dB594DE56",
"DAORegistry": "0x11d3B1B24C19B5672b92CD535d2F1F35C53AC543",
"PluginRepoRegistry_Implementation": "0x38b112318cfd563Fa5de538E7c219bf72F1CcA6a",
"PluginRepoRegistry": "0x9b51505f7bf3A45BC92F6bE269324096abEC0A73",
"PluginRepoFactory": "0xA69347F49dD615cb4577670D0728684AfAa01197",
"PluginSetupProcessor": "0xAc7e4fB4a2158b7EA5516f47b6f804956Faf0134",
"DAOFactory": "0x2d11E9413264e3814C2a21160cBCcb9Dc3C96890"
}
```

Copy the `PluginRepoFactory`, the `PluginSetupProcessor` and the `managingDAO` addresses for the next step.

#### 2) Run the plugin deployment script

Back to this repository:

- Update the `.env` file with the values that correspond to your target blockchain
- `NETWORK_NAME` and `DEPLOYMENT_RPC_ENDPOINT`
- Alternatively, edit the `packages/contracts/hardhat.config.ts` to manually customize the HardHat client
- Define the deployment wallet's `PRIVATE_KEY`
- Define the protocol addresses [you copied before](#1-deploy-osx):
- `PLUGIN_REPO_FACTORY_ADDRESS`, `PLUGIN_SETUP_PROCESSOR_ADDRESS` and `MANAGING_DAO_ADDRESS`
- Edit the `packages/contracts/plugin-setup-params.ts` to define the details of the plugins to depoy
- If you try to deploy the same plugin repo twice, you will encounter an ENS collision
- In such case, either define a new unique ENS subdomain or consider rerunning the step 1 and trying again
- Review the Management DAO's plugin settings under `.env`

```sh
cd packages/contracts
yarn build
yarn deploy --network <the-network-name>
```

#### 3) Install a governance plugin to the Managing DAO

The Managing DAO is the contract that has the role of managing certain protocol modules, like the Plugin Registry, the DAO registry, etc. In case a new OSx version is available, only that DAO is be able to push upgrades and perform certain management tasks, which makes it a key component.

The Managing DAO will be created with the following permissions:

- The Managing DAO holds `ROOT_PERMISSION` on itself
- The deployer address also holds `ROOT_PERMISSION` on the Managing DAO

Among the plugins deployed [in the step above](#2-deploy-your-plugins), one of them should be installed to the Managing DAO.

When the script from step 2 finishes, you should see a message like this:

```
If you wish to configure the Managing DAO:
1) Update the .env file with this value:
GOVERNANCE_PLUGIN_REPO_ADDRESS="0xeC91F7Fa3BcFB208c679d2d7de18E7bd9d7cC40B"
2) Define the following values:
MGMT_DAO_PROPOSAL_DURATION="604800" # 60 * 60 * 24 * 7 (seconds)
MGMT_DAO_MIN_PROPOSAL_PARTICIPATION="500000" # 50%
MGMT_DAO_PROPOSAL_SUPPORT_THRESHOLD="500000" # 50%
MGMT_DAO_INITIAL_EDITORS="0x1234,0x2345,0x3456,0x4567..." # Comma separated addresses
3) Run the following command:
$ yarn managing-dao-setup
```

By running the `managing-dao-setup.ts` script, you will be:

1. Asking the [PSP from OSx](#1-deploy-osx) to run `prepareInstallation()` and deploy a new Governance plugin instance
2. Ask the Managing DAO to call `applyInstallation()` on the PSP for the deployed plugin
3. Make the Managing DAO revoke the remaining deployment wallet permissions
4. Checking that the Managing DAO's permissions are correctly configured
15 changes: 11 additions & 4 deletions packages/contracts/deploy/01_repo/10_create_repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
PersonalSpaceAdminPluginSetupParams,
SpacePluginSetupParams,
} from '../../plugin-setup-params';
import {isLocalChain} from '../../utils/hardhat';
import {
findEventTopicLog,
getPluginRepoFactoryAddress,
Expand Down Expand Up @@ -33,19 +34,25 @@ async function deployRepo(
const {network} = hre;
let pluginRepoFactoryAddr: string;

if (!process.env.PLUGIN_REPO_FACTORY_ADDRESS) {
if (
process.env.PLUGIN_REPO_FACTORY_ADDRESS &&
!isLocalChain(hre.network.name)
) {
// Use the given value when deploying to a live network
pluginRepoFactoryAddr = process.env.PLUGIN_REPO_FACTORY_ADDRESS;
} else {
// Use the well-known OSx addresses when in test/fork mode
pluginRepoFactoryAddr = getPluginRepoFactoryAddress(network.name);
if (!pluginRepoFactoryAddr)
if (!pluginRepoFactoryAddr) {
throw new Error(
'PLUGIN_REPO_FACTORY_ADDRESS is empty and no default value is available for ' +
network.name
);
}

console.log(
'Using the default Plugin Repo Factory address (PLUGIN_REPO_FACTORY_ADDRESS is empty)'
);
} else {
pluginRepoFactoryAddr = process.env.PLUGIN_REPO_FACTORY_ADDRESS;
}

console.log(`\nDeploying the "${ensSubdomain}" plugin repo`);
Expand Down
10 changes: 7 additions & 3 deletions packages/contracts/deploy/02_setup/10_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
PersonalSpaceAdminPluginSetupParams,
SpacePluginSetupParams,
} from '../../plugin-setup-params';
import {isLocalChain} from '../../utils/hardhat';
import {getPluginSetupProcessorAddress} from '../../utils/helpers';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
Expand All @@ -13,7 +14,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deployer} = await getNamedAccounts();

let pspAddress: string;
if (!process.env.PLUGIN_SETUP_PROCESSOR_ADDRESS) {
if (
process.env.PLUGIN_SETUP_PROCESSOR_ADDRESS &&
!isLocalChain(hre.network.name)
) {
pspAddress = process.env.PLUGIN_SETUP_PROCESSOR_ADDRESS;
} else {
pspAddress = getPluginSetupProcessorAddress(network.name);
if (!pspAddress)
throw new Error(
Expand All @@ -24,8 +30,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(
'Using the default Plugin Setup Processor address (PLUGIN_SETUP_PROCESSOR_ADDRESS is empty)'
);
} else {
pspAddress = process.env.PLUGIN_SETUP_PROCESSOR_ADDRESS;
}

// Space Setup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {verifyContract} from '../../utils/etherscan';
import {isLocalChain} from '../../utils/hardhat';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

Expand Down Expand Up @@ -31,8 +32,4 @@ export default func;
func.tags = ['Verification'];
func.runAtTheEnd = true;
func.skip = (hre: HardhatRuntimeEnvironment) =>
Promise.resolve(
hre.network.name === 'localhost' ||
hre.network.name === 'hardhat' ||
hre.network.name === 'coverage'
);
Promise.resolve(isLocalChain(hre.network.name));
38 changes: 38 additions & 0 deletions packages/contracts/deploy/99_verification/20_summary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {GovernancePluginsSetupParams} from '../../plugin-setup-params';
import {isLocalChain} from '../../utils/hardhat';
import {getPluginRepoInfo} from '../../utils/plugin-repo-info';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const pluginRepoInfo = getPluginRepoInfo(
GovernancePluginsSetupParams.PLUGIN_REPO_ENS_NAME,
hre.network.name
);
if (!pluginRepoInfo)
throw new Error('Could not read the address of the deployed contract');

console.log(`
If you wish to configure the Managing DAO:
1) Update the .env file with this value:
GOVERNANCE_PLUGIN_REPO_ADDRESS="${pluginRepoInfo.address}"
2) Define the following values:
MGMT_DAO_PROPOSAL_DURATION="604800" # 60 * 60 * 24 * 7 (seconds)
MGMT_DAO_MIN_PROPOSAL_PARTICIPATION="500000" # 50%
MGMT_DAO_PROPOSAL_SUPPORT_THRESHOLD="500000" # 50%
MGMT_DAO_INITIAL_EDITORS="0x1234,0x2345,0x3456,0x4567..." # Comma separated addresses
3) Run the following command:
$ npx ts-node scripts/managing-dao-setup.ts
`);
};

export default func;

func.tags = ['Verification'];
func.runAtTheEnd = true;
func.skip = (hre: HardhatRuntimeEnvironment) =>
Promise.resolve(isLocalChain(hre.network.name));
Loading

0 comments on commit ed99aad

Please sign in to comment.