diff --git a/packages/contracts/deploy/02_setup/10_setup.ts b/packages/contracts/deploy/02_setup/10_setup.ts index 54873fd..d633d47 100644 --- a/packages/contracts/deploy/02_setup/10_setup.ts +++ b/packages/contracts/deploy/02_setup/10_setup.ts @@ -3,26 +3,35 @@ import { PersonalSpaceAdminPluginSetupParams, SpacePluginSetupParams, } from '../../plugin-setup-params'; +import {activeContractsList} from '@aragon/osx-ethers'; import {DeployFunction} from 'hardhat-deploy/types'; import {HardhatRuntimeEnvironment} from 'hardhat/types'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - const {deployments, getNamedAccounts} = hre; + const {deployments, getNamedAccounts, network} = hre; const {deploy} = deployments; const {deployer} = await getNamedAccounts(); - // Space + const pspAddress = + activeContractsList[network.name as keyof typeof activeContractsList] + .PluginSetupProcessor; + + console.log( + `\nUsing the PluginSetupProcessor address ${pspAddress} on ${network.name}` + ); + + // Space Setup console.log( `\nDeploying ${SpacePluginSetupParams.PLUGIN_SETUP_CONTRACT_NAME}` ); await deploy(SpacePluginSetupParams.PLUGIN_SETUP_CONTRACT_NAME, { from: deployer, - args: [], + args: [pspAddress], log: true, }); - // Personal Space + // Personal Space Setup console.log( `\nDeploying ${PersonalSpaceAdminPluginSetupParams.PLUGIN_SETUP_CONTRACT_NAME}` ); @@ -33,14 +42,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { log: true, }); - // Governance + // Governance Setup console.log( `\nDeploying ${GovernancePluginsSetupParams.PLUGIN_SETUP_CONTRACT_NAME}` ); await deploy(GovernancePluginsSetupParams.PLUGIN_SETUP_CONTRACT_NAME, { from: deployer, - args: [], + args: [pspAddress], log: true, }); }; diff --git a/packages/contracts/src/GovernancePluginsSetup.sol b/packages/contracts/src/GovernancePluginsSetup.sol index 9a91165..025ca59 100644 --- a/packages/contracts/src/GovernancePluginsSetup.sol +++ b/packages/contracts/src/GovernancePluginsSetup.sol @@ -36,7 +36,7 @@ contract GovernancePluginsSetup is PluginSetup { function prepareInstallation( address _dao, bytes memory _data - ) external returns (address _mainVotingPlugin, PreparedSetupData memory _preparedSetupData) { + ) external returns (address mainVotingPlugin, PreparedSetupData memory preparedSetupData) { // Decode the custom installation parameters ( MajorityVotingBase.VotingSettings memory _votingSettings, @@ -46,7 +46,7 @@ contract GovernancePluginsSetup is PluginSetup { ) = decodeInstallationParams(_data); // Deploy the main voting plugin - _mainVotingPlugin = createERC1967Proxy( + mainVotingPlugin = createERC1967Proxy( mainVotingPluginImplementation, abi.encodeCall( MainVotingPlugin.initialize, @@ -57,7 +57,7 @@ contract GovernancePluginsSetup is PluginSetup { // Deploy the member access plugin MemberAccessPlugin.MultisigSettings memory _multisigSettings; _multisigSettings.proposalDuration = _memberAccessProposalDuration; - _multisigSettings.mainVotingPlugin = MainVotingPlugin(_mainVotingPlugin); + _multisigSettings.mainVotingPlugin = MainVotingPlugin(mainVotingPlugin); address _memberAccessPlugin = createERC1967Proxy( memberAccessPluginImplementation, @@ -66,7 +66,7 @@ contract GovernancePluginsSetup is PluginSetup { // Condition contract (member access plugin execute) address _memberAccessExecuteCondition = address( - new MemberAccessExecuteCondition(_mainVotingPlugin) + new MemberAccessExecuteCondition(mainVotingPlugin) ); // List the requested permissions @@ -79,14 +79,14 @@ contract GovernancePluginsSetup is PluginSetup { permissions[0] = PermissionLib.MultiTargetPermission({ operation: PermissionLib.Operation.Grant, where: _dao, - who: _mainVotingPlugin, + who: mainVotingPlugin, condition: PermissionLib.NO_CONDITION, permissionId: DAO(payable(_dao)).EXECUTE_PERMISSION_ID() }); // The DAO can update the main voting plugin settings permissions[1] = PermissionLib.MultiTargetPermission({ operation: PermissionLib.Operation.Grant, - where: _mainVotingPlugin, + where: mainVotingPlugin, who: _dao, condition: PermissionLib.NO_CONDITION, permissionId: MainVotingPlugin(mainVotingPluginImplementation) @@ -95,7 +95,7 @@ contract GovernancePluginsSetup is PluginSetup { // The DAO can manage the list of addresses permissions[2] = PermissionLib.MultiTargetPermission({ operation: PermissionLib.Operation.Grant, - where: _mainVotingPlugin, + where: mainVotingPlugin, who: _dao, condition: PermissionLib.NO_CONDITION, permissionId: MainVotingPlugin(mainVotingPluginImplementation) @@ -127,7 +127,7 @@ contract GovernancePluginsSetup is PluginSetup { // pluginUpgrader can make the DAO execute applyUpdate // pluginUpgrader can make the DAO execute grant/revoke address[] memory _targetPluginAddresses = new address[](2); - _targetPluginAddresses[0] = _mainVotingPlugin; + _targetPluginAddresses[0] = mainVotingPlugin; _targetPluginAddresses[1] = _memberAccessPlugin; OnlyPluginUpgraderCondition _onlyPluginUpgraderCondition = new OnlyPluginUpgraderCondition( DAO(payable(_dao)), @@ -143,9 +143,9 @@ contract GovernancePluginsSetup is PluginSetup { }); } - _preparedSetupData.permissions = permissions; - _preparedSetupData.helpers = new address[](1); - _preparedSetupData.helpers[0] = _memberAccessPlugin; + preparedSetupData.permissions = permissions; + preparedSetupData.helpers = new address[](1); + preparedSetupData.helpers[0] = _memberAccessPlugin; } /// @inheritdoc IPluginSetup diff --git a/packages/contracts/test/unit-testing/governance-plugins-setup.ts b/packages/contracts/test/unit-testing/governance-plugins-setup.ts index 1a1eb7e..79c6100 100644 --- a/packages/contracts/test/unit-testing/governance-plugins-setup.ts +++ b/packages/contracts/test/unit-testing/governance-plugins-setup.ts @@ -20,6 +20,7 @@ import { UPGRADE_PLUGIN_PERMISSION_ID, VotingMode, } from './common'; +import {activeContractsList} from '@aragon/osx-ethers'; import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'; import {expect} from 'chai'; import {ethers} from 'hardhat'; @@ -34,9 +35,14 @@ describe('Governance Plugins Setup', function () { [alice, bob] = await ethers.getSigners(); dao = await deployTestDao(alice); + const hardhatForkNetwork = (process.env.NETWORK_NAME ?? + 'mainnet') as keyof typeof activeContractsList; + const pspAddress = + activeContractsList[hardhatForkNetwork].PluginSetupProcessor; + governancePluginsSetup = await new GovernancePluginsSetup__factory( alice - ).deploy(); + ).deploy(pspAddress); }); describe('prepareInstallation', async () => { @@ -74,12 +80,11 @@ describe('Governance Plugins Setup', function () { from: governancePluginsSetup.address, nonce: nonce + 1, }); - const anticipatedConditionPluginAddress = ethers.utils.getContractAddress( - { + const anticipatedMemberAccessConditionAddress = + ethers.utils.getContractAddress({ from: governancePluginsSetup.address, nonce: nonce + 2, - } - ); + }); const { mainVotingPlugin, @@ -93,7 +98,7 @@ describe('Governance Plugins Setup', function () { const [memberAccessPlugin] = helpers; expect(memberAccessPlugin).to.eq(anticipatedMemberAccessPluginAddress); - expect(permissions.length).to.be.equal(7); + expect(permissions.length).to.be.equal(5); expect(permissions).to.deep.equal([ [ Operation.Grant, @@ -116,18 +121,11 @@ describe('Governance Plugins Setup', function () { NO_CONDITION, UPDATE_ADDRESSES_PERMISSION_ID, ], - [ - Operation.Grant, - mainVotingPlugin, - dao.address, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], [ Operation.Grant, dao.address, memberAccessPlugin, - anticipatedConditionPluginAddress, + anticipatedMemberAccessConditionAddress, EXECUTE_PERMISSION_ID, ], [ @@ -137,13 +135,6 @@ describe('Governance Plugins Setup', function () { NO_CONDITION, UPDATE_MULTISIG_SETTINGS_PERMISSION_ID, ], - [ - Operation.Grant, - memberAccessPlugin, - dao.address, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], ]); await governancePluginsSetup.prepareInstallation(dao.address, initData); @@ -190,12 +181,16 @@ describe('Governance Plugins Setup', function () { from: governancePluginsSetup.address, nonce: nonce + 1, }); - const anticipatedConditionPluginAddress = ethers.utils.getContractAddress( - { + const anticipatedMemberAccessConditionAddress = + ethers.utils.getContractAddress({ from: governancePluginsSetup.address, nonce: nonce + 2, - } - ); + }); + const anticipatedOnlyPluginUpgraderConditionAddress = + ethers.utils.getContractAddress({ + from: governancePluginsSetup.address, + nonce: nonce + 3, + }); const { mainVotingPlugin, @@ -209,7 +204,7 @@ describe('Governance Plugins Setup', function () { const [memberAccessPlugin] = helpers; expect(memberAccessPlugin).to.eq(anticipatedMemberAccessPluginAddress); - expect(permissions.length).to.be.equal(9); + expect(permissions.length).to.be.equal(6); expect(permissions).to.deep.equal([ [ Operation.Grant, @@ -232,18 +227,11 @@ describe('Governance Plugins Setup', function () { NO_CONDITION, UPDATE_ADDRESSES_PERMISSION_ID, ], - [ - Operation.Grant, - mainVotingPlugin, - dao.address, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], [ Operation.Grant, dao.address, memberAccessPlugin, - anticipatedConditionPluginAddress, + anticipatedMemberAccessConditionAddress, EXECUTE_PERMISSION_ID, ], [ @@ -255,24 +243,10 @@ describe('Governance Plugins Setup', function () { ], [ Operation.Grant, - memberAccessPlugin, dao.address, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], - [ - Operation.Grant, - mainVotingPlugin, pluginUpgrader, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], - [ - Operation.Grant, - memberAccessPlugin, - pluginUpgrader, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, + anticipatedOnlyPluginUpgraderConditionAddress, + EXECUTE_PERMISSION_ID, ], ]); @@ -313,7 +287,7 @@ describe('Governance Plugins Setup', function () { } ); - expect(permissions.length).to.be.equal(7); + expect(permissions.length).to.be.equal(5); expect(permissions).to.deep.equal([ [ Operation.Revoke, @@ -336,13 +310,6 @@ describe('Governance Plugins Setup', function () { NO_CONDITION, UPDATE_ADDRESSES_PERMISSION_ID, ], - [ - Operation.Revoke, - mainVotingPlugin.address, - dao.address, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], [ Operation.Revoke, dao.address, @@ -357,13 +324,6 @@ describe('Governance Plugins Setup', function () { NO_CONDITION, UPDATE_MULTISIG_SETTINGS_PERMISSION_ID, ], - [ - Operation.Revoke, - memberAccessPlugin.address, - dao.address, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], ]); }); @@ -392,7 +352,7 @@ describe('Governance Plugins Setup', function () { } ); - expect(permissions.length).to.be.equal(9); + expect(permissions.length).to.be.equal(6); expect(permissions).to.deep.equal([ [ Operation.Revoke, @@ -415,13 +375,6 @@ describe('Governance Plugins Setup', function () { NO_CONDITION, UPDATE_ADDRESSES_PERMISSION_ID, ], - [ - Operation.Revoke, - mainVotingPlugin.address, - dao.address, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], [ Operation.Revoke, dao.address, @@ -438,24 +391,10 @@ describe('Governance Plugins Setup', function () { ], [ Operation.Revoke, - memberAccessPlugin.address, dao.address, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], - [ - Operation.Revoke, - mainVotingPlugin.address, pluginUpgrader, NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], - [ - Operation.Revoke, - memberAccessPlugin.address, - pluginUpgrader, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, + EXECUTE_PERMISSION_ID, ], ]); }); diff --git a/packages/contracts/test/unit-testing/space-plugin-setup.ts b/packages/contracts/test/unit-testing/space-plugin-setup.ts index e4d5b0d..4739a5a 100644 --- a/packages/contracts/test/unit-testing/space-plugin-setup.ts +++ b/packages/contracts/test/unit-testing/space-plugin-setup.ts @@ -12,10 +12,11 @@ import { ADDRESS_ONE, ADDRESS_ZERO, CONTENT_PERMISSION_ID, + EXECUTE_PERMISSION_ID, NO_CONDITION, SUBSPACE_PERMISSION_ID, - UPGRADE_PLUGIN_PERMISSION_ID, } from './common'; +import {activeContractsList} from '@aragon/osx-ethers'; import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'; import {expect} from 'chai'; import {ethers} from 'hardhat'; @@ -32,8 +33,14 @@ describe('Space Plugin Setup', function () { [alice, bob] = await ethers.getSigners(); dao = await deployTestDao(alice); + const hardhatForkNetwork = (process.env.NETWORK_NAME ?? + 'mainnet') as keyof typeof activeContractsList; + + const pspAddress = + activeContractsList[hardhatForkNetwork].PluginSetupProcessor; + SpacePluginSetup = new SpacePluginSetup__factory(alice); - spacePluginSetup = await SpacePluginSetup.deploy(); + spacePluginSetup = await SpacePluginSetup.deploy(pspAddress); }); describe('prepareInstallation', async () => { @@ -62,7 +69,7 @@ describe('Space Plugin Setup', function () { expect(plugin).to.be.equal(anticipatedPluginAddress); expect(helpers.length).to.be.equal(0); - expect(permissions.length).to.be.equal(3); + expect(permissions.length).to.be.equal(2); expect(permissions).to.deep.equal([ [ Operation.Grant, @@ -78,13 +85,6 @@ describe('Space Plugin Setup', function () { NO_CONDITION, SUBSPACE_PERMISSION_ID, ], - [ - Operation.Grant, - plugin, - dao.address, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], ]); await spacePluginSetup.prepareInstallation(dao.address, initData); @@ -109,6 +109,10 @@ describe('Space Plugin Setup', function () { from: spacePluginSetup.address, nonce, }); + const anticipatedConditionAddress = ethers.utils.getContractAddress({ + from: spacePluginSetup.address, + nonce: nonce + 1, + }); const { plugin, @@ -120,7 +124,7 @@ describe('Space Plugin Setup', function () { expect(plugin).to.be.equal(anticipatedPluginAddress); expect(helpers.length).to.be.equal(0); - expect(permissions.length).to.be.equal(4); + expect(permissions.length).to.be.equal(3); expect(permissions).to.deep.equal([ [ Operation.Grant, @@ -138,17 +142,10 @@ describe('Space Plugin Setup', function () { ], [ Operation.Grant, - plugin, dao.address, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], - [ - Operation.Grant, - plugin, pluginUpgrader, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, + anticipatedConditionAddress, + EXECUTE_PERMISSION_ID, ], ]); @@ -178,7 +175,7 @@ describe('Space Plugin Setup', function () { data: uninstallData, }); - expect(permissions.length).to.be.equal(3); + expect(permissions.length).to.be.equal(2); expect(permissions).to.deep.equal([ [ Operation.Revoke, @@ -194,13 +191,6 @@ describe('Space Plugin Setup', function () { NO_CONDITION, SUBSPACE_PERMISSION_ID, ], - [ - Operation.Revoke, - plugin.address, - dao.address, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], ]); }); @@ -222,7 +212,7 @@ describe('Space Plugin Setup', function () { data: uninstallData, }); - expect(permissions.length).to.be.equal(4); + expect(permissions.length).to.be.equal(3); expect(permissions).to.deep.equal([ [ Operation.Revoke, @@ -240,17 +230,10 @@ describe('Space Plugin Setup', function () { ], [ Operation.Revoke, - plugin.address, dao.address, - NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, - ], - [ - Operation.Revoke, - plugin.address, pluginUpgrader, NO_CONDITION, - UPGRADE_PLUGIN_PERMISSION_ID, + EXECUTE_PERMISSION_ID, ], ]); });