Skip to content

Commit

Permalink
modified daofactory
Browse files Browse the repository at this point in the history
  • Loading branch information
novaknole committed Sep 30, 2024
1 parent c5d8db6 commit 4bb5752
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 21 deletions.
10 changes: 8 additions & 2 deletions packages/contracts/deploy/update/to_v1.3.0/90_ManagingDAO.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {DAOFactory__factory, DAO__factory} from '../../../typechain';
import {getContractAddress} from '../../helpers';
import {IMPLICIT_INITIAL_PROTOCOL_VERSION} from '@aragon/osx-commons-sdk';
import {
getProtocolVersion,
IMPLICIT_INITIAL_PROTOCOL_VERSION,
} from '@aragon/osx-commons-sdk';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

Expand All @@ -24,7 +27,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const upgradeTX = await managementDAO.populateTransaction.upgradeToAndCall(
newDaoImplementation,
managementDAO.interface.encodeFunctionData('initializeFrom', [
IMPLICIT_INITIAL_PROTOCOL_VERSION,
// Get the managing dao's protocol version from which upgrade will happen.
await getProtocolVersion(managementDAO),
[],
])
);
Expand All @@ -38,6 +42,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
value: 0,
description: `Upgrade the <strong>management DAO</strong> (<code>${managementDAOAddress}</code>) to the new <strong>implementation</strong> (<code>${newDaoImplementation}</code>).`,
});

console.log(hre.managementDAOActions);
};
export default func;
func.tags = ['ManagementDAO', 'v1.3.0'];
53 changes: 35 additions & 18 deletions packages/contracts/src/framework/dao/DAOFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@ import {PermissionLib} from "@aragon/osx-commons-contracts/src/permission/Permis
import {ProxyLib} from "@aragon/osx-commons-contracts/src/utils/deployment/ProxyLib.sol";

import {DAO} from "../../core/dao/DAO.sol";
import {PluginRepo} from "../plugin/repo/PluginRepo.sol";
import {PluginSetupProcessor} from "../plugin/setup/PluginSetupProcessor.sol";
import {hashHelpers, PluginSetupRef} from "../plugin/setup/PluginSetupProcessorHelpers.sol";
import {DAORegistry} from "./DAORegistry.sol";

// Permission Identifiers necessary to create and set up the dao.
bytes32 constant ROOT_PERMISSION_ID = keccak256("ROOT_PERMISSION");
bytes32 constant APPLY_INSTALLATION_PERMISSION_ID = keccak256("APPLY_INSTALLATION_PERMISSION");
bytes32 constant APPLY_TARGET_PERMISSION_ID = keccak256("APPLY_TARGET_PERMISSION");
bytes32 constant UPGRADE_DAO_PERMISSION_ID = keccak256("UPGRADE_DAO_PERMISSION");
bytes32 constant SET_METADATA_PERMISSION_ID = keccak256("SET_METADATA_PERMISSION");
bytes32 constant REGISTER_STANDARD_CALLBACK_PERMISSION_ID = keccak256(
"REGISTER_STANDARD_CALLBACK_PERMISSION"
);
bytes32 constant SET_TRUSTED_FORWARDER_PERMISSION_ID = keccak256(
"SET_TRUSTED_FORWARDER_PERMISSION"
);

/// @title DAOFactory
/// @author Aragon X - 2022-2023
/// @notice This contract is used to create a DAO.
Expand Down Expand Up @@ -93,20 +105,21 @@ contract DAOFactory is ERC165, ProtocolVersion {
// Register DAO.
daoRegistry.register(createdDao, msg.sender, _daoSettings.subdomain);

// Get Permission IDs
bytes32 rootPermissionID = createdDao.ROOT_PERMISSION_ID();
bytes32 applyInstallationPermissionID = pluginSetupProcessor
.APPLY_INSTALLATION_PERMISSION_ID();
// Set the psp to be the allowed grantee for `APPLY_TARGET_PERMISSION_ID`.
createdDao.setApplyTargetMethodGrantee(address(pluginSetupProcessor));

// Grant the temporary permissions.
// Grant Temporarily `ROOT_PERMISSION` to `pluginSetupProcessor`.
createdDao.grant(address(createdDao), address(pluginSetupProcessor), rootPermissionID);
// Grant Temporarily `APPLY_TARGET_PERMISSION_ID` to `pluginSetupProcessor`.
createdDao.grant(
address(createdDao),
address(pluginSetupProcessor),
APPLY_TARGET_PERMISSION_ID
);

// Grant Temporarily `APPLY_INSTALLATION_PERMISSION` on `pluginSetupProcessor` to this `DAOFactory`.
createdDao.grant(
address(pluginSetupProcessor),
address(this),
applyInstallationPermissionID
APPLY_INSTALLATION_PERMISSION_ID
);

// Install plugins on the newly created DAO.
Expand Down Expand Up @@ -139,19 +152,23 @@ contract DAOFactory is ERC165, ProtocolVersion {
_setDAOPermissions(createdDao);

// Revoke the temporarily granted permissions.
// Revoke Temporarily `ROOT_PERMISSION` from `pluginSetupProcessor`.
createdDao.revoke(address(createdDao), address(pluginSetupProcessor), rootPermissionID);
// Revoke Temporarily `APPLY_TARGET_PERMISSION_ID` from `pluginSetupProcessor`.
createdDao.revoke(
address(createdDao),
address(pluginSetupProcessor),
APPLY_TARGET_PERMISSION_ID
);

// Revoke `APPLY_INSTALLATION_PERMISSION` on `pluginSetupProcessor` from this `DAOFactory` .
createdDao.revoke(
address(pluginSetupProcessor),
address(this),
applyInstallationPermissionID
APPLY_INSTALLATION_PERMISSION_ID
);

// Revoke Temporarily `ROOT_PERMISSION_ID` from `pluginSetupProcessor` that implicitly granted to this `DaoFactory`
// at the create dao step `address(this)` being the initial owner of the new created DAO.
createdDao.revoke(address(createdDao), address(this), rootPermissionID);
createdDao.revoke(address(createdDao), address(this), ROOT_PERMISSION_ID);
}

/// @notice Deploys a new DAO `ERC1967` proxy, and initialize it with this contract as the initial owner.
Expand Down Expand Up @@ -187,27 +204,27 @@ contract DAOFactory is ERC165, ProtocolVersion {
items[0] = PermissionLib.SingleTargetPermission(
PermissionLib.Operation.Grant,
address(_dao),
_dao.ROOT_PERMISSION_ID()
ROOT_PERMISSION_ID
);
items[1] = PermissionLib.SingleTargetPermission(
PermissionLib.Operation.Grant,
address(_dao),
_dao.UPGRADE_DAO_PERMISSION_ID()
UPGRADE_DAO_PERMISSION_ID
);
items[2] = PermissionLib.SingleTargetPermission(
PermissionLib.Operation.Grant,
address(_dao),
_dao.SET_TRUSTED_FORWARDER_PERMISSION_ID()
SET_TRUSTED_FORWARDER_PERMISSION_ID
);
items[3] = PermissionLib.SingleTargetPermission(
PermissionLib.Operation.Grant,
address(_dao),
_dao.SET_METADATA_PERMISSION_ID()
SET_METADATA_PERMISSION_ID
);
items[4] = PermissionLib.SingleTargetPermission(
PermissionLib.Operation.Grant,
address(_dao),
_dao.REGISTER_STANDARD_CALLBACK_PERMISSION_ID()
REGISTER_STANDARD_CALLBACK_PERMISSION_ID
);

_dao.applySingleTargetPermissions(address(_dao), items);
Expand Down
18 changes: 17 additions & 1 deletion packages/contracts/test/framework/dao/dao-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import {expect} from 'chai';
import {defaultAbiCoder} from 'ethers/lib/utils';
import {ethers} from 'hardhat';

const APPLY_TARGET_PERMISSION_ID = ethers.utils.id('APPLY_TARGET_PERMISSION');

const EVENTS = {
PluginRepoRegistered: 'PluginRepoRegistered',
DAORegistered: 'DAORegistered',
Expand All @@ -60,6 +62,7 @@ const EVENTS = {
NewURI: 'NewURI',
Revoked: 'Revoked',
Granted: 'Granted',
ApplyMethodGranteeSet: 'ApplyTargetMethodGranteeSet',
};

const ALLOW_FLAG = '0x0000000000000000000000000000000000000002';
Expand Down Expand Up @@ -434,10 +437,14 @@ describe('DAOFactory: ', function () {
const daoContract = factory.attach(dao);

// Check that events were emitted.
await expect(tx)
.to.emit(daoContract, EVENTS.ApplyMethodGranteeSet)
.withArgs(psp.address);

await expect(tx)
.to.emit(daoContract, EVENTS.Revoked)
.withArgs(
DAO_PERMISSIONS.ROOT_PERMISSION_ID,
APPLY_TARGET_PERMISSION_ID,
daoFactory.address,
dao,
psp.address
Expand Down Expand Up @@ -479,6 +486,15 @@ describe('DAOFactory: ', function () {
)
).to.be.false;

expect(
await daoContract.hasPermission(
dao,
psp.address,
APPLY_TARGET_PERMISSION_ID,
'0x'
)
).to.be.false;

expect(
await daoContract.hasPermission(
psp.address,
Expand Down

0 comments on commit 4bb5752

Please sign in to comment.