@@ -26,13 +26,15 @@ import { AddressArrayUtils } from "./lib/AddressArrayUtils.sol";
2626 * @title ManagerCore
2727 * @author Set Protocol
2828 *
29- * Registry for governance approved DelegatedManagerFactories and DelegatedManagers.
29+ * Registry for governance approved GlobalExtensions, DelegatedManagerFactories, and DelegatedManagers.
3030 */
3131contract ManagerCore is Ownable {
3232 using AddressArrayUtils for address [];
3333
3434 /* ============ Events ============ */
3535
36+ event ExtensionAdded (address indexed _extension );
37+ event ExtensionRemoved (address indexed _extension );
3638 event FactoryAdded (address indexed _factory );
3739 event FactoryRemoved (address indexed _factory );
3840 event ManagerAdded (address indexed _manager , address indexed _factory );
@@ -55,14 +57,18 @@ contract ManagerCore is Ownable {
5557
5658 /* ============ State Variables ============ */
5759
58- // List of enabled managers
59- address [] public managers ;
60+ // List of enabled extensions
61+ address [] public extensions ;
6062 // List of enabled factories of managers
6163 address [] public factories;
64+ // List of enabled managers
65+ address [] public managers;
6266
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 ;
6569 mapping (address => bool ) public isFactory;
70+ mapping (address => bool ) public isManager;
71+
6672
6773 // Return true if the ManagerCore is initialized
6874 bool public isInitialized;
@@ -73,57 +79,59 @@ contract ManagerCore is Ownable {
7379 * Initializes any predeployed factories. Note: This function can only be called by
7480 * the owner once to batch initialize the initial system contracts.
7581 *
82+ * @param _extensions List of extensions to add
7683 * @param _factories List of factories to add
7784 */
7885 function initialize (
86+ address [] memory _extensions ,
7987 address [] memory _factories
8088 )
8189 external
8290 onlyOwner
8391 {
8492 require (! isInitialized, "ManagerCore is already initialized " );
8593
94+ extensions = _extensions;
8695 factories = _factories;
8796
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+ }
89101 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]);
93103 }
94104
95105 // Set to true to only allow initialization once
96106 isInitialized = true ;
97107 }
98108
99109 /**
100- * PRIVILEGED FACTORY FUNCTION. Adds a newly deployed manager as an enabled manager.
110+ * PRIVILEGED GOVERNANCE FUNCTION. Allows governance to add an extension
101111 *
102- * @param _manager Address of the manager contract to add
112+ * @param _extension Address of the extension contract to add
103113 */
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 " );
106116
107- isManager[_manager] = true ;
108-
109- managers.push (_manager);
117+ _addExtension (_extension);
110118
111- emit ManagerAdded (_manager, msg . sender );
119+ extensions. push (_extension );
112120 }
113121
114122 /**
115- * PRIVILEGED GOVERNANCE FUNCTION. Allows governance to remove a manager
123+ * PRIVILEGED GOVERNANCE FUNCTION. Allows governance to remove an extension
116124 *
117- * @param _manager Address of the manager contract to remove
125+ * @param _extension Address of the extension contract to remove
118126 */
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 " );
121129
122- managers .removeStorage (_manager );
130+ extensions .removeStorage (_extension );
123131
124- isManager[_manager ] = false ;
132+ isExtension[_extension ] = false ;
125133
126- emit ManagerRemoved (_manager );
134+ emit ExtensionRemoved (_extension );
127135 }
128136
129137 /**
@@ -134,11 +142,9 @@ contract ManagerCore is Ownable {
134142 function addFactory (address _factory ) external onlyInitialized onlyOwner {
135143 require (! isFactory[_factory], "Factory already exists " );
136144
137- isFactory[ _factory] = true ;
145+ _addFactory ( _factory) ;
138146
139147 factories.push (_factory);
140-
141- emit FactoryAdded (_factory);
142148 }
143149
144150 /**
@@ -156,13 +162,75 @@ contract ManagerCore is Ownable {
156162 emit FactoryRemoved (_factory);
157163 }
158164
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+
159195 /* ============ External Getter Functions ============ */
160196
161- function getManagers () external view returns (address [] memory ) {
162- return managers ;
197+ function getExtensions () external view returns (address [] memory ) {
198+ return extensions ;
163199 }
164200
165201 function getFactories () external view returns (address [] memory ) {
166202 return factories;
167203 }
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+ }
168236}
0 commit comments