generated from aragon/osx-plugin-template-hardhat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GovernancePluginsSetup.sol
312 lines (282 loc) · 12.7 KB
/
GovernancePluginsSetup.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.8;
import {PermissionLib} from "@aragon/osx/core/permission/PermissionLib.sol";
import {DAO} from "@aragon/osx/core/dao/DAO.sol";
import {IDAO} from "@aragon/osx/core/dao/IDAO.sol";
import {PluginSetup, IPluginSetup} from "@aragon/osx/framework/plugin/setup/PluginSetup.sol";
import {PluginSetupProcessor} from "@aragon/osx/framework/plugin/setup/PluginSetupProcessor.sol";
import {MemberAccessPlugin} from "./MemberAccessPlugin.sol";
import {MemberAccessExecuteCondition} from "../conditions/MemberAccessExecuteCondition.sol";
import {OnlyPluginUpgraderCondition} from "../conditions/OnlyPluginUpgraderCondition.sol";
import {MainVotingPlugin} from "./MainVotingPlugin.sol";
import {MajorityVotingBase} from "./base/MajorityVotingBase.sol";
/// @title GovernancePluginsSetup
/// @dev Release 1, Build 1
contract GovernancePluginsSetup is PluginSetup {
address private immutable mainVotingPluginImplementation;
address public immutable memberAccessPluginImplementation;
address private immutable pluginSetupProcessor;
/// @notice Thrown when the array of helpers does not have the correct size
error InvalidHelpers(uint256 actualLength);
/// @notice Initializes the setup contract
/// @param pluginSetupProcessorAddress The address of the PluginSetupProcessor contract deployed by Aragon on that chain
constructor(PluginSetupProcessor pluginSetupProcessorAddress) {
pluginSetupProcessor = address(pluginSetupProcessorAddress);
mainVotingPluginImplementation = address(new MainVotingPlugin());
memberAccessPluginImplementation = address(new MemberAccessPlugin());
}
/// @inheritdoc IPluginSetup
/// @notice Prepares the installation of the two governance plugins in one go
function prepareInstallation(
address _dao,
bytes memory _data
) external returns (address mainVotingPlugin, PreparedSetupData memory preparedSetupData) {
// Decode the custom installation parameters
(
MajorityVotingBase.VotingSettings memory _votingSettings,
address[] memory _initialEditors,
uint64 _memberAccessProposalDuration,
address _pluginUpgrader
) = decodeInstallationParams(_data);
// Deploy the member access plugin
address _memberAccessPlugin = createERC1967Proxy(
memberAccessPluginImplementation,
abi.encodeCall(
MemberAccessPlugin.initialize,
(
IDAO(_dao),
MemberAccessPlugin.MultisigSettings({
proposalDuration: _memberAccessProposalDuration
})
)
)
);
// Deploy the main voting plugin
mainVotingPlugin = createERC1967Proxy(
mainVotingPluginImplementation,
abi.encodeCall(
MainVotingPlugin.initialize,
(
IDAO(_dao),
_votingSettings,
_initialEditors,
MemberAccessPlugin(_memberAccessPlugin)
)
)
);
// Condition contract (member access plugin execute)
address _memberAccessExecuteCondition = address(
new MemberAccessExecuteCondition(mainVotingPlugin)
);
// List the requested permissions
PermissionLib.MultiTargetPermission[]
memory permissions = new PermissionLib.MultiTargetPermission[](
_pluginUpgrader == address(0x0) ? 6 : 7
);
// The main voting plugin can execute on the DAO
permissions[0] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Grant,
where: _dao,
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,
who: _dao,
condition: PermissionLib.NO_CONDITION,
permissionId: MainVotingPlugin(mainVotingPluginImplementation)
.UPDATE_VOTING_SETTINGS_PERMISSION_ID()
});
// The DAO can manage the list of addresses
permissions[2] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Grant,
where: mainVotingPlugin,
who: _dao,
condition: PermissionLib.NO_CONDITION,
permissionId: MainVotingPlugin(mainVotingPluginImplementation)
.UPDATE_ADDRESSES_PERMISSION_ID()
});
// The MainVotingPlugin can create membership proposals on the MemberAccessPlugin
permissions[3] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Grant,
where: _memberAccessPlugin,
who: mainVotingPlugin,
condition: PermissionLib.NO_CONDITION,
permissionId: MemberAccessPlugin(_memberAccessPlugin).PROPOSER_PERMISSION_ID()
});
// The member access plugin needs to execute on the DAO
permissions[4] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.GrantWithCondition,
where: _dao,
who: _memberAccessPlugin,
// Conditional execution
condition: _memberAccessExecuteCondition,
permissionId: DAO(payable(_dao)).EXECUTE_PERMISSION_ID()
});
// The DAO needs to be able to update the member access plugin settings
permissions[5] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Grant,
where: _memberAccessPlugin,
who: _dao,
condition: PermissionLib.NO_CONDITION,
permissionId: MemberAccessPlugin(memberAccessPluginImplementation)
.UPDATE_MULTISIG_SETTINGS_PERMISSION_ID()
});
// The DAO doesn't need APPLY_UPDATE_PERMISSION_ID on the PSP
// pluginUpgrader permissions
if (_pluginUpgrader != address(0x0)) {
// 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[1] = _memberAccessPlugin;
OnlyPluginUpgraderCondition _onlyPluginUpgraderCondition = new OnlyPluginUpgraderCondition(
DAO(payable(_dao)),
PluginSetupProcessor(pluginSetupProcessor),
_targetPluginAddresses
);
permissions[6] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.GrantWithCondition,
where: _dao,
who: _pluginUpgrader,
condition: address(_onlyPluginUpgraderCondition),
permissionId: DAO(payable(_dao)).EXECUTE_PERMISSION_ID()
});
}
preparedSetupData.permissions = permissions;
preparedSetupData.helpers = new address[](1);
preparedSetupData.helpers[0] = _memberAccessPlugin;
}
/// @inheritdoc IPluginSetup
function prepareUninstallation(
address _dao,
SetupPayload calldata _payload
) external view returns (PermissionLib.MultiTargetPermission[] memory permissionChanges) {
if (_payload.currentHelpers.length != 1) {
revert InvalidHelpers(_payload.currentHelpers.length);
}
// Decode incoming params
address _pluginUpgrader = decodeUninstallationParams(_payload.data);
address _memberAccessPlugin = _payload.currentHelpers[0];
permissionChanges = new PermissionLib.MultiTargetPermission[](
_pluginUpgrader == address(0x0) ? 6 : 7
);
// Main voting plugin permissions
// The plugin can no longer execute on the DAO
permissionChanges[0] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Revoke,
where: _dao,
who: _payload.plugin,
condition: address(0),
permissionId: DAO(payable(_dao)).EXECUTE_PERMISSION_ID()
});
// The DAO can no longer update the plugin settings
permissionChanges[1] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Revoke,
where: _payload.plugin,
who: _dao,
condition: address(0),
permissionId: MainVotingPlugin(mainVotingPluginImplementation)
.UPDATE_VOTING_SETTINGS_PERMISSION_ID()
});
// The DAO can no longer manage the list of addresses
permissionChanges[2] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Revoke,
where: _payload.plugin,
who: _dao,
condition: address(0),
permissionId: MainVotingPlugin(mainVotingPluginImplementation)
.UPDATE_ADDRESSES_PERMISSION_ID()
});
// Plugin permissions
// The MainVotingPlugin can no longer propose on the MemberAccessPlugin
permissionChanges[3] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Revoke,
where: _memberAccessPlugin,
who: _payload.plugin,
condition: address(0),
permissionId: MemberAccessPlugin(memberAccessPluginImplementation)
.PROPOSER_PERMISSION_ID()
});
// The plugin can no longer execute on the DAO
permissionChanges[4] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Revoke,
where: _dao,
who: _memberAccessPlugin,
condition: address(0),
permissionId: DAO(payable(_dao)).EXECUTE_PERMISSION_ID()
});
// The DAO can no longer update the plugin settings
permissionChanges[5] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Revoke,
where: _memberAccessPlugin,
who: _dao,
condition: address(0),
permissionId: MemberAccessPlugin(memberAccessPluginImplementation)
.UPDATE_MULTISIG_SETTINGS_PERMISSION_ID()
});
if (_pluginUpgrader != address(0x0)) {
// pluginUpgrader can no longer make the DAO execute applyUpdate
// pluginUpgrader can no longer make the DAO execute grant/revoke
permissionChanges[6] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Revoke,
where: _dao,
who: _pluginUpgrader,
condition: address(0),
permissionId: DAO(payable(_dao)).EXECUTE_PERMISSION_ID()
});
}
}
/// @inheritdoc IPluginSetup
function implementation() external view returns (address) {
return mainVotingPluginImplementation;
}
/// @notice Encodes the given installation parameters into a byte array
function encodeInstallationParams(
MajorityVotingBase.VotingSettings calldata _votingSettings,
address[] calldata _initialEditors,
uint64 _memberAccessProposalDuration,
address _pluginUpgrader
) public pure returns (bytes memory) {
return
abi.encode(
_votingSettings,
_initialEditors,
_memberAccessProposalDuration,
_pluginUpgrader
);
}
/// @notice Decodes the given byte array into the original installation parameters
function decodeInstallationParams(
bytes memory _data
)
public
pure
returns (
MajorityVotingBase.VotingSettings memory votingSettings,
address[] memory initialEditors,
uint64 memberAccessProposalDuration,
address pluginUpgrader
)
{
(votingSettings, initialEditors, memberAccessProposalDuration, pluginUpgrader) = abi.decode(
_data,
(MajorityVotingBase.VotingSettings, address[], uint64, address)
);
}
/// @notice Encodes the given uninstallation parameters into a byte array
function encodeUninstallationParams(
address _pluginUpgrader
) public pure returns (bytes memory) {
return abi.encode(_pluginUpgrader);
}
/// @notice Decodes the given byte array into the original uninstallation parameters
function decodeUninstallationParams(
bytes memory _data
) public pure returns (address pluginUpgrader) {
(pluginUpgrader) = abi.decode(_data, (address));
}
}