Skip to content

Commit

Permalink
WIP memberAccess plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Sep 1, 2023
1 parent f8d2e30 commit 5324a74
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 74 deletions.
17 changes: 13 additions & 4 deletions packages/contracts/src/MainVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@ pragma solidity ^0.8.8;

import {IDAO, PluginUUPSUpgradeable} from "@aragon/osx/core/plugin/PluginUUPSUpgradeable.sol";

bytes4 constant MAIN_SPACE_VOTING_INTERFACE_ID = MainVotingPlugin.initialize.selector ^
MainVotingPlugin.editorCount.selector;

/// @title MainVotingPlugin
/// @dev Release 1, Build 1
contract MainVotingPlugin is PluginUUPSUpgradeable {
constructor() {
_disableInitializers();
}

/// @notice Initializes the plugin when build 1 is installed.
/// @param _dao The address of the DAO to read the permissions from.
function initialize(IDAO _dao) external initializer {
__PluginUUPSUpgradeable_init(_dao);
}

/// @notice Checks if this or the parent contract supports an interface by its ID.
/// @param _interfaceId The ID of the interface.
/// @return Returns `true` if the interface is supported.
function supportsInterface(
bytes4 _interfaceId
) public view override(PluginUUPSUpgradeable) returns (bool) {
return
_interfaceId == MAIN_SPACE_VOTING_INTERFACE_ID || super.supportsInterface(_interfaceId);
}

function editorCount() public pure returns (uint32) {
return 1;
}
Expand Down
29 changes: 20 additions & 9 deletions packages/contracts/src/MemberAccessVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {IMembership} from "@aragon/osx/core/plugin/membership/IMembership.sol";
import {PluginUUPSUpgradeable} from "@aragon/osx/core/plugin/PluginUUPSUpgradeable.sol";
import {ProposalUpgradeable} from "@aragon/osx/core/plugin/proposal/ProposalUpgradeable.sol";
import {IMultisig} from "@aragon/osx/plugins/governance/multisig/IMultisig.sol";
import {MainVotingPlugin} from "./MainVotingPlugin.sol";
import {MainVotingPlugin, MAIN_SPACE_VOTING_INTERFACE_ID} from "./MainVotingPlugin.sol";

bytes4 constant MULTISIG_INTERFACE_ID = MemberAccessVotingPlugin.initialize.selector ^
MemberAccessVotingPlugin.updateMultisigSettings.selector ^
MemberAccessVotingPlugin.getProposal.selector;

/// @title Multisig - Release 1, Build 1
/// @author Aragon Association - 2022-2023
Expand Down Expand Up @@ -78,10 +82,6 @@ contract MemberAccessVotingPlugin is
MainVotingPlugin mainVotingPlugin;
}

/// @notice The [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface ID of the contract.
bytes4 internal constant MULTISIG_INTERFACE_ID =
this.initialize.selector ^ this.updateMultisigSettings.selector ^ this.getProposal.selector;

/// @notice A mapping between proposal IDs and proposal information.
mapping(uint256 => Proposal) internal proposals;

Expand Down Expand Up @@ -111,6 +111,9 @@ contract MemberAccessVotingPlugin is
/// @notice Thrown when attempting to use addAddresses and removeAddresses.
error AddresslistDisabled();

/// @notice Thrown when attempting to use an invalid contract.
error InvalidContract();

/// @notice Emitted when a proposal is approved by an editor.
/// @param proposalId The ID of the proposal.
/// @param editor The editor casting the approve.
Expand All @@ -124,7 +127,7 @@ contract MemberAccessVotingPlugin is
/// @notice Emitted when the plugin settings are set.
/// @param proposalDuration The amount of time before a non-approved proposal expires.
/// @param mainVotingPlugin The address of the main voting plugin for the space. Used to apply permissions for it.
event MultisigSettingsUpdated(uint64 proposalDuration, MainVotingPlugin mainVotingPlugin);
event MultisigSettingsUpdated(uint64 proposalDuration, address mainVotingPlugin);

/// @notice Initializes Release 1, Build 1.
/// @dev This method is required to support [ERC-1822](https://eips.ethereum.org/EIPS/eip-1822).
Expand Down Expand Up @@ -254,7 +257,7 @@ contract MemberAccessVotingPlugin is
value: 0,
data: abi.encodeWithSelector(
PermissionManager.grant.selector, // grant()
multisigSettings.mainVotingPlugin, // where
address(multisigSettings.mainVotingPlugin), // where
_proposedMember, // who
MEMBER_PERMISSION_ID // permission ID
)
Expand Down Expand Up @@ -286,7 +289,7 @@ contract MemberAccessVotingPlugin is
value: 0,
data: abi.encodeWithSelector(
PermissionManager.revoke.selector, // revoke()
multisigSettings.mainVotingPlugin, // where
address(multisigSettings.mainVotingPlugin), // where
_proposedMember, // who
MEMBER_PERMISSION_ID // permission ID
)
Expand Down Expand Up @@ -468,12 +471,20 @@ contract MemberAccessVotingPlugin is
/// @notice Internal function to update the plugin settings.
/// @param _multisigSettings The new settings.
function _updateMultisigSettings(MultisigSettings calldata _multisigSettings) internal {
if (
!MainVotingPlugin(_multisigSettings.mainVotingPlugin).supportsInterface(
MAIN_SPACE_VOTING_INTERFACE_ID
)
) {
revert InvalidContract();
}

multisigSettings = _multisigSettings;
lastMultisigSettingsChange = block.number.toUint64();

emit MultisigSettingsUpdated({
proposalDuration: _multisigSettings.proposalDuration,
mainVotingPlugin: _multisigSettings.mainVotingPlugin
mainVotingPlugin: address(_multisigSettings.mainVotingPlugin)
});
}

Expand Down
14 changes: 14 additions & 0 deletions packages/contracts/src/SpacePlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ pragma solidity ^0.8.8;

import {IDAO, PluginUUPSUpgradeable} from "@aragon/osx/core/plugin/PluginUUPSUpgradeable.sol";

bytes4 constant SPACE_INTERFACE_ID = SpacePlugin.initialize.selector ^
SpacePlugin.setContent.selector ^
SpacePlugin.acceptSubspace.selector ^
SpacePlugin.removeSubspace.selector;

/// @title SpacePlugin
/// @dev Release 1, Build 1
contract SpacePlugin is PluginUUPSUpgradeable {
Expand Down Expand Up @@ -32,6 +37,15 @@ contract SpacePlugin is PluginUUPSUpgradeable {
emit ContentChanged({blockIndex: 0, itemIndex: 0, contentUri: _firstBlockContentUri});
}

/// @notice Checks if this or the parent contract supports an interface by its ID.
/// @param _interfaceId The ID of the interface.
/// @return Returns `true` if the interface is supported.
function supportsInterface(
bytes4 _interfaceId
) public view override(PluginUUPSUpgradeable) returns (bool) {
return _interfaceId == SPACE_INTERFACE_ID || super.supportsInterface(_interfaceId);
}

/// @notice Emits an event with new contents for the given block index. Caller needs CONTENT_PERMISSION.
/// @param _blockIndex The index of the block whose items have new contents.
/// @param _itemIndex The index of the item that has new contents.
Expand Down
4 changes: 4 additions & 0 deletions packages/contracts/test/unit-testing/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export const CONTENT_PERMISSION_ID = ethers.utils.id("CONTENT_PERMISSION");
export const SUBSPACE_PERMISSION_ID = ethers.utils.id("SUBSPACE_PERMISSION");

export const EXECUTE_PERMISSION_ID = ethers.utils.id("EXECUTE_PERMISSION");
export const UPDATE_MULTISIG_SETTINGS_PERMISSION_ID = ethers.utils.id(
"UPDATE_MULTISIG_SETTINGS_PERMISSION",
);
export const ROOT_PERMISSION_ID = ethers.utils.id("ROOT_PERMISSION");

export const ADDRESS_ZERO = ethers.constants.AddressZero;
export const ADDRESS_ONE = `0x${"0".repeat(39)}1`;
Expand Down
2 changes: 0 additions & 2 deletions packages/contracts/test/unit-testing/main-voting-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe("Default Main Voting plugin", function () {
);

await memberAccessPlugin.initialize(dao.address, {
minApprovals: 0,
proposalDuration: 60 * 60 * 24 * 5,
mainVotingPlugin: spaceVotingPlugin.address,
});
Expand Down Expand Up @@ -89,7 +88,6 @@ describe("Default Main Voting plugin", function () {
it("reverts if trying to re-initialize", async () => {
await expect(
memberAccessPlugin.initialize(dao.address, {
minApprovals: 0,
proposalDuration: 60 * 60 * 24 * 5,
mainVotingPlugin: spaceVotingPlugin.address,
}),
Expand Down
Loading

0 comments on commit 5324a74

Please sign in to comment.