generated from aragon/osx-plugin-template-hardhat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpacePluginSetup.sol
180 lines (161 loc) · 6.88 KB
/
SpacePluginSetup.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
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.8;
import {DAO} from "@aragon/osx/core/dao/DAO.sol";
import {IDAO} from "@aragon/osx/core/dao/IDAO.sol";
import {PermissionLib} from "@aragon/osx/core/permission/PermissionLib.sol";
import {PluginSetup, IPluginSetup} from "@aragon/osx/framework/plugin/setup/PluginSetup.sol";
import {PluginSetupProcessor} from "@aragon/osx/framework/plugin/setup/PluginSetupProcessor.sol";
import {SpacePlugin} from "./SpacePlugin.sol";
import {OnlyPluginUpgraderCondition} from "../conditions/OnlyPluginUpgraderCondition.sol";
import {CONTENT_PERMISSION_ID, SUBSPACE_PERMISSION_ID} from "../constants.sol";
/// @title SpacePluginSetup
/// @dev Release 1, Build 1
contract SpacePluginSetup is PluginSetup {
address private immutable pluginImplementation;
address private immutable pluginSetupProcessor;
/// @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);
pluginImplementation = address(new SpacePlugin());
}
/// @inheritdoc IPluginSetup
function prepareInstallation(
address _dao,
bytes memory _data
) external returns (address plugin, PreparedSetupData memory preparedSetupData) {
// Decode incoming params
(
string memory _firstBlockContentUri,
address _predecessorAddress,
address _pluginUpgrader
) = decodeInstallationParams(_data);
// Deploy new plugin instance
plugin = createERC1967Proxy(
pluginImplementation,
abi.encodeCall(
SpacePlugin.initialize,
(IDAO(_dao), _firstBlockContentUri, _predecessorAddress)
)
);
PermissionLib.MultiTargetPermission[]
memory permissions = new PermissionLib.MultiTargetPermission[](
_pluginUpgrader == address(0x0) ? 2 : 3
);
// The DAO can emit content
permissions[0] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Grant,
where: plugin,
who: _dao,
condition: PermissionLib.NO_CONDITION,
permissionId: CONTENT_PERMISSION_ID
});
// The DAO can accept a subspace
permissions[1] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Grant,
where: plugin,
who: _dao,
condition: PermissionLib.NO_CONDITION,
permissionId: SUBSPACE_PERMISSION_ID
});
// 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] = plugin;
OnlyPluginUpgraderCondition _onlyPluginUpgraderCondition = new OnlyPluginUpgraderCondition(
DAO(payable(_dao)),
PluginSetupProcessor(pluginSetupProcessor),
_targetPluginAddresses
);
permissions[2] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.GrantWithCondition,
where: _dao,
who: _pluginUpgrader,
condition: address(_onlyPluginUpgraderCondition),
permissionId: DAO(payable(_dao)).EXECUTE_PERMISSION_ID()
});
}
preparedSetupData.permissions = permissions;
}
/// @inheritdoc IPluginSetup
function prepareUninstallation(
address _dao,
SetupPayload calldata _payload
) external view returns (PermissionLib.MultiTargetPermission[] memory permissionChanges) {
// Decode incoming params
address _pluginUpgrader = decodeUninstallationParams(_payload.data);
permissionChanges = new PermissionLib.MultiTargetPermission[](
_pluginUpgrader == address(0x0) ? 2 : 3
);
// The DAO can make it emit content
permissionChanges[0] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Revoke,
where: _payload.plugin,
who: _dao,
condition: PermissionLib.NO_CONDITION,
permissionId: CONTENT_PERMISSION_ID
});
// The DAO can make it accept/reject a subspace
permissionChanges[1] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Revoke,
where: _payload.plugin,
who: _dao,
condition: PermissionLib.NO_CONDITION,
permissionId: SUBSPACE_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[2] = 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 pluginImplementation;
}
/// @notice Encodes the given installation parameters into a byte array
function encodeInstallationParams(
string memory _firstBlockContentUri,
address _predecessorAddress,
address _pluginUpgrader
) public pure returns (bytes memory) {
return abi.encode(_firstBlockContentUri, _predecessorAddress, _pluginUpgrader);
}
/// @notice Decodes the given byte array into the original installation parameters
function decodeInstallationParams(
bytes memory _data
)
public
pure
returns (
string memory firstBlockContentUri,
address predecessorAddress,
address pluginUpgrader
)
{
(firstBlockContentUri, predecessorAddress, pluginUpgrader) = abi.decode(
_data,
(string, address, 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));
}
}