@@ -26,13 +26,15 @@ import { AddressArrayUtils } from "./lib/AddressArrayUtils.sol";
26
26
* @title ManagerCore
27
27
* @author Set Protocol
28
28
*
29
- * Registry for governance approved DelegatedManagerFactories and DelegatedManagers.
29
+ * Registry for governance approved GlobalExtensions, DelegatedManagerFactories, and DelegatedManagers.
30
30
*/
31
31
contract ManagerCore is Ownable {
32
32
using AddressArrayUtils for address [];
33
33
34
34
/* ============ Events ============ */
35
35
36
+ event ExtensionAdded (address indexed _extension );
37
+ event ExtensionRemoved (address indexed _extension );
36
38
event FactoryAdded (address indexed _factory );
37
39
event FactoryRemoved (address indexed _factory );
38
40
event ManagerAdded (address indexed _manager , address indexed _factory );
@@ -55,14 +57,18 @@ contract ManagerCore is Ownable {
55
57
56
58
/* ============ State Variables ============ */
57
59
58
- // List of enabled managers
59
- address [] public managers ;
60
+ // List of enabled extensions
61
+ address [] public extensions ;
60
62
// List of enabled factories of managers
61
63
address [] public factories;
64
+ // List of enabled managers
65
+ address [] public managers;
62
66
63
- // Mapping to check whether address is valid Manager or Factory
64
- mapping (address => bool ) public isManager ;
67
+ // Mapping to check whether address is valid Extension, Factory, or Manager
68
+ mapping (address => bool ) public isExtension ;
65
69
mapping (address => bool ) public isFactory;
70
+ mapping (address => bool ) public isManager;
71
+
66
72
67
73
// Return true if the ManagerCore is initialized
68
74
bool public isInitialized;
@@ -73,57 +79,59 @@ contract ManagerCore is Ownable {
73
79
* Initializes any predeployed factories. Note: This function can only be called by
74
80
* the owner once to batch initialize the initial system contracts.
75
81
*
82
+ * @param _extensions List of extensions to add
76
83
* @param _factories List of factories to add
77
84
*/
78
85
function initialize (
86
+ address [] memory _extensions ,
79
87
address [] memory _factories
80
88
)
81
89
external
82
90
onlyOwner
83
91
{
84
92
require (! isInitialized, "ManagerCore is already initialized " );
85
93
94
+ extensions = _extensions;
86
95
factories = _factories;
87
96
88
- // Loop through and initialize isFactory mapping
97
+ // Loop through and initialize isExtension and isFactory mapping
98
+ for (uint256 i = 0 ; i < _extensions.length ; i++ ) {
99
+ _addExtension (_extensions[i]);
100
+ }
89
101
for (uint256 i = 0 ; i < _factories.length ; i++ ) {
90
- address factory = _factories[i];
91
- require (factory != address (0 ), "Zero address submitted. " );
92
- isFactory[factory] = true ;
102
+ _addFactory (_factories[i]);
93
103
}
94
104
95
105
// Set to true to only allow initialization once
96
106
isInitialized = true ;
97
107
}
98
108
99
109
/**
100
- * PRIVILEGED FACTORY FUNCTION. Adds a newly deployed manager as an enabled manager.
110
+ * PRIVILEGED GOVERNANCE FUNCTION. Allows governance to add an extension
101
111
*
102
- * @param _manager Address of the manager contract to add
112
+ * @param _extension Address of the extension contract to add
103
113
*/
104
- function addManager (address _manager ) external onlyInitialized onlyFactory {
105
- require (! isManager[_manager ], "Manager already exists " );
114
+ function addExtension (address _extension ) external onlyInitialized onlyOwner {
115
+ require (! isExtension[_extension ], "Extension already exists " );
106
116
107
- isManager[_manager] = true ;
108
-
109
- managers.push (_manager);
117
+ _addExtension (_extension);
110
118
111
- emit ManagerAdded (_manager, msg . sender );
119
+ extensions. push (_extension );
112
120
}
113
121
114
122
/**
115
- * PRIVILEGED GOVERNANCE FUNCTION. Allows governance to remove a manager
123
+ * PRIVILEGED GOVERNANCE FUNCTION. Allows governance to remove an extension
116
124
*
117
- * @param _manager Address of the manager contract to remove
125
+ * @param _extension Address of the extension contract to remove
118
126
*/
119
- function removeManager (address _manager ) external onlyInitialized onlyOwner {
120
- require (isManager[_manager ], "Manager does not exist " );
127
+ function removeExtension (address _extension ) external onlyInitialized onlyOwner {
128
+ require (isExtension[_extension ], "Extension does not exist " );
121
129
122
- managers .removeStorage (_manager );
130
+ extensions .removeStorage (_extension );
123
131
124
- isManager[_manager ] = false ;
132
+ isExtension[_extension ] = false ;
125
133
126
- emit ManagerRemoved (_manager );
134
+ emit ExtensionRemoved (_extension );
127
135
}
128
136
129
137
/**
@@ -134,11 +142,9 @@ contract ManagerCore is Ownable {
134
142
function addFactory (address _factory ) external onlyInitialized onlyOwner {
135
143
require (! isFactory[_factory], "Factory already exists " );
136
144
137
- isFactory[ _factory] = true ;
145
+ _addFactory ( _factory) ;
138
146
139
147
factories.push (_factory);
140
-
141
- emit FactoryAdded (_factory);
142
148
}
143
149
144
150
/**
@@ -156,13 +162,75 @@ contract ManagerCore is Ownable {
156
162
emit FactoryRemoved (_factory);
157
163
}
158
164
165
+ /**
166
+ * PRIVILEGED FACTORY FUNCTION. Adds a newly deployed manager as an enabled manager.
167
+ *
168
+ * @param _manager Address of the manager contract to add
169
+ */
170
+ function addManager (address _manager ) external onlyInitialized onlyFactory {
171
+ require (! isManager[_manager], "Manager already exists " );
172
+
173
+ isManager[_manager] = true ;
174
+
175
+ managers.push (_manager);
176
+
177
+ emit ManagerAdded (_manager, msg .sender );
178
+ }
179
+
180
+ /**
181
+ * PRIVILEGED GOVERNANCE FUNCTION. Allows governance to remove a manager
182
+ *
183
+ * @param _manager Address of the manager contract to remove
184
+ */
185
+ function removeManager (address _manager ) external onlyInitialized onlyOwner {
186
+ require (isManager[_manager], "Manager does not exist " );
187
+
188
+ managers.removeStorage (_manager);
189
+
190
+ isManager[_manager] = false ;
191
+
192
+ emit ManagerRemoved (_manager);
193
+ }
194
+
159
195
/* ============ External Getter Functions ============ */
160
196
161
- function getManagers () external view returns (address [] memory ) {
162
- return managers ;
197
+ function getExtensions () external view returns (address [] memory ) {
198
+ return extensions ;
163
199
}
164
200
165
201
function getFactories () external view returns (address [] memory ) {
166
202
return factories;
167
203
}
204
+
205
+ function getManagers () external view returns (address [] memory ) {
206
+ return managers;
207
+ }
208
+
209
+ /* ============ Internal Functions ============ */
210
+
211
+ /**
212
+ * Add an extension tracked on the ManagerCore
213
+ *
214
+ * @param _extension Address of the extension contract to add
215
+ */
216
+ function _addExtension (address _extension ) internal {
217
+ require (_extension != address (0 ), "Zero address submitted. " );
218
+
219
+ isExtension[_extension] = true ;
220
+
221
+ emit ExtensionAdded (_extension);
222
+ }
223
+
224
+ /**
225
+ * Add a factory tracked on the ManagerCore
226
+ *
227
+ * @param _factory Address of the factory contract to add
228
+ */
229
+ function _addFactory (address _factory ) internal {
230
+ require (_factory != address (0 ), "Zero address submitted. " );
231
+
232
+ isFactory[_factory] = true ;
233
+
234
+ emit FactoryAdded (_factory);
235
+ }
168
236
}
0 commit comments