Skip to content

Commit 43599f4

Browse files
authored
Add BaseManager (V1) (#6)
1 parent 9657380 commit 43599f4

File tree

4 files changed

+676
-1
lines changed

4 files changed

+676
-1
lines changed

contracts/manager/BaseManager.sol

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
/*
2+
Copyright 2021 Set Labs Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache License, Version 2.0
17+
*/
18+
19+
pragma solidity 0.6.10;
20+
21+
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
22+
23+
import { AddressArrayUtils } from "../lib/AddressArrayUtils.sol";
24+
import { IAdapter } from "../interfaces/IAdapter.sol";
25+
import { ISetToken } from "../interfaces/ISetToken.sol";
26+
27+
28+
/**
29+
* @title BaseManager
30+
* @author Set Protocol
31+
*
32+
* Smart contract manager that contains permissions and admin functionality
33+
*/
34+
contract BaseManager {
35+
using Address for address;
36+
using AddressArrayUtils for address[];
37+
38+
/* ============ Events ============ */
39+
40+
event AdapterAdded(
41+
address _adapter
42+
);
43+
44+
event AdapterRemoved(
45+
address _adapter
46+
);
47+
48+
event MethodologistChanged(
49+
address _oldMethodologist,
50+
address _newMethodologist
51+
);
52+
53+
event OperatorChanged(
54+
address _oldOperator,
55+
address _newOperator
56+
);
57+
58+
/* ============ Modifiers ============ */
59+
60+
/**
61+
* Throws if the sender is not the SetToken operator
62+
*/
63+
modifier onlyOperator() {
64+
require(msg.sender == operator, "Must be operator");
65+
_;
66+
}
67+
68+
/**
69+
* Throws if the sender is not the SetToken methodologist
70+
*/
71+
modifier onlyMethodologist() {
72+
require(msg.sender == methodologist, "Must be methodologist");
73+
_;
74+
}
75+
76+
/**
77+
* Throws if the sender is not a listed adapter
78+
*/
79+
modifier onlyAdapter() {
80+
require(isAdapter[msg.sender], "Must be adapter");
81+
_;
82+
}
83+
84+
/* ============ State Variables ============ */
85+
86+
// Instance of SetToken
87+
ISetToken public setToken;
88+
89+
// Array of listed adapters
90+
address[] internal adapters;
91+
92+
// Mapping to check if adapter is added
93+
mapping(address => bool) public isAdapter;
94+
95+
// Address of operator which typically executes manager only functions on Set Protocol modules
96+
address public operator;
97+
98+
// Address of methodologist which serves as providing methodology for the index
99+
address public methodologist;
100+
101+
/* ============ Constructor ============ */
102+
103+
constructor(
104+
ISetToken _setToken,
105+
address _operator,
106+
address _methodologist
107+
)
108+
public
109+
{
110+
setToken = _setToken;
111+
operator = _operator;
112+
methodologist = _methodologist;
113+
}
114+
115+
/* ============ External Functions ============ */
116+
117+
/**
118+
* MUTUAL UPGRADE: Update the SetToken manager address. Operator and Methodologist must each call
119+
* this function to execute the update.
120+
*
121+
* @param _newManager New manager address
122+
*/
123+
function setManager(address _newManager) external onlyOperator {
124+
require(_newManager != address(0), "Zero address not valid");
125+
setToken.setManager(_newManager);
126+
}
127+
128+
/**
129+
* MUTUAL UPGRADE: Add a new adapter that the BaseManager can call.
130+
*
131+
* @param _adapter New adapter to add
132+
*/
133+
function addAdapter(address _adapter) external onlyOperator {
134+
require(!isAdapter[_adapter], "Adapter already exists");
135+
require(address(IAdapter(_adapter).manager()) == address(this), "Adapter manager invalid");
136+
137+
adapters.push(_adapter);
138+
139+
isAdapter[_adapter] = true;
140+
141+
emit AdapterAdded(_adapter);
142+
}
143+
144+
/**
145+
* MUTUAL UPGRADE: Remove an existing adapter tracked by the BaseManager.
146+
*
147+
* @param _adapter Old adapter to remove
148+
*/
149+
function removeAdapter(address _adapter) external onlyOperator {
150+
require(isAdapter[_adapter], "Adapter does not exist");
151+
152+
adapters.removeStorage(_adapter);
153+
154+
isAdapter[_adapter] = false;
155+
156+
emit AdapterRemoved(_adapter);
157+
}
158+
159+
/**
160+
* ADAPTER ONLY: Interact with a module registered on the SetToken.
161+
*
162+
* @param _module Module to interact with
163+
* @param _data Byte data of function to call in module
164+
*/
165+
function interactManager(address _module, bytes calldata _data) external onlyAdapter {
166+
// Invoke call to module, assume value will always be 0
167+
_module.functionCallWithValue(_data, 0);
168+
}
169+
170+
/**
171+
* OPERATOR ONLY: Add a new module to the SetToken.
172+
*
173+
* @param _module New module to add
174+
*/
175+
function addModule(address _module) external onlyOperator {
176+
setToken.addModule(_module);
177+
}
178+
179+
/**
180+
* OPERATOR ONLY: Remove a new module from the SetToken.
181+
*
182+
* @param _module Module to remove
183+
*/
184+
function removeModule(address _module) external onlyOperator {
185+
setToken.removeModule(_module);
186+
}
187+
188+
/**
189+
* METHODOLOGIST ONLY: Update the methodologist address
190+
*
191+
* @param _newMethodologist New methodologist address
192+
*/
193+
function setMethodologist(address _newMethodologist) external onlyMethodologist {
194+
emit MethodologistChanged(methodologist, _newMethodologist);
195+
196+
methodologist = _newMethodologist;
197+
}
198+
199+
/**
200+
* OPERATOR ONLY: Update the operator address
201+
*
202+
* @param _newOperator New operator address
203+
*/
204+
function setOperator(address _newOperator) external onlyOperator {
205+
emit OperatorChanged(operator, _newOperator);
206+
207+
operator = _newOperator;
208+
}
209+
210+
/* ============ External Getters ============ */
211+
212+
function getAdapters() external view returns(address[] memory) {
213+
return adapters;
214+
}
215+
}

0 commit comments

Comments
 (0)