• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IndexCoop / index-coop-smart-contracts / 5be55ea0-6126-44e3-8993-1d8cecdfa204

23 Nov 2023 03:47AM UTC coverage: 46.877% (-30.4%) from 77.323%
5be55ea0-6126-44e3-8993-1d8cecdfa204

push

circleci

web-flow
Global optimistic auction rebalance extension (#154)

* feat: GlobalAuctionRebalanceExtension contract, tests & utils

* test: adds cases that increase coverage to 100%

* feat: prevent intialization when not ready.

* chore(deps): add @uma/core as devDep

* ref(AuctionRebalance): startRebalance overridable

* ref(OptimisticAuction): adds Initial contract.

* feat: setProductSettings, proposeRebalance, override startRebalance.

* chore(deps): remove @uma/core dev dep.

* test: derive unit test template for GlobalOptimisticAuctionRebalanceExtension from GlobalAuctionRebalanceExtension.

* test: update deployment helper and barrel.

* refactor: remove unused param from constructor.

* chore(deps): add base58 encode/decode lib.

* feat: add OOV3 mock.

* test: extends to cover propose rebalance path.

* refactor: add events, update docstrings.

 fix assertedProducts update.

* feat: emit events, simplify tracking assertion id relationships, refactor out bonds.

* docs: update contract natspec description.

* fix: add virtual keyword back and removed extra imports in utils.

* ref: refactor and doc updates.

580 of 1354 branches covered (0.0%)

Branch coverage included in aggregate %.

59 of 80 new or added lines in 2 files covered. (73.75%)

1087 existing lines in 25 files now uncovered.

1724 of 3561 relevant lines covered (48.41%)

16.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.73
/contracts/ManagerCore.sol
1
/*
2
    Copyright 2022 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 { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
22

23
import { AddressArrayUtils } from "./lib/AddressArrayUtils.sol";
24

25
/**
26
 * @title ManagerCore
27
 * @author Set Protocol
28
 *
29
 *  Registry for governance approved GlobalExtensions, DelegatedManagerFactories, and DelegatedManagers.
30
 */
31
contract ManagerCore is Ownable {
32
    using AddressArrayUtils for address[];
33

34
    /* ============ Events ============ */
35

36
    event ExtensionAdded(address indexed _extension);
37
    event ExtensionRemoved(address indexed _extension);
38
    event FactoryAdded(address indexed _factory);
39
    event FactoryRemoved(address indexed _factory);
40
    event ManagerAdded(address indexed _manager, address indexed _factory);
41
    event ManagerRemoved(address indexed _manager);
42

43
    /* ============ Modifiers ============ */
44

45
    /**
46
     * Throws if function is called by any address other than a valid factory.
47
     */
48
    modifier onlyFactory() {
49
        require(isFactory[msg.sender], "Only valid factories can call");
32✔
50
        _;
51
    }
52

53
    modifier onlyInitialized() {
54
        require(isInitialized, "Contract must be initialized.");
47!
55
        _;
56
    }
57

58
    /* ============ State Variables ============ */
59

60
    // List of enabled extensions
61
    address[] public extensions;
62
    // List of enabled factories of managers
63
    address[] public factories;
64
    // List of enabled managers
65
    address[] public managers;
66

67
    // Mapping to check whether address is valid Extension, Factory, or Manager
68
    mapping(address => bool) public isExtension;
69
    mapping(address => bool) public isFactory;
70
    mapping(address => bool) public isManager;
71

72

73
    // Return true if the ManagerCore is initialized
74
    bool public isInitialized;
75

76
    /* ============ External Functions ============ */
77

78
    /**
79
     * Initializes any predeployed factories. Note: This function can only be called by
80
     * the owner once to batch initialize the initial system contracts.
81
     *
82
     * @param _extensions            List of extensions to add
83
     * @param _factories             List of factories to add
84
     */
85
    function initialize(
86
        address[] memory _extensions,
87
        address[] memory _factories
88
    )
89
        external
90
        onlyOwner
91
    {
92
        require(!isInitialized, "ManagerCore is already initialized");
6!
93

94
        extensions = _extensions;
6✔
95
        factories = _factories;
6✔
96

97
        // Loop through and initialize isExtension and isFactory mapping
98
        for (uint256 i = 0; i < _extensions.length; i++) {
6✔
99
            _addExtension(_extensions[i]);
7✔
100
        }
101
        for (uint256 i = 0; i < _factories.length; i++) {
6✔
102
            _addFactory(_factories[i]);
6✔
103
        }
104

105
        // Set to true to only allow initialization once
106
        isInitialized = true;
6✔
107
    }
108

109
    /**
110
     * PRIVILEGED GOVERNANCE FUNCTION. Allows governance to add an extension
111
     *
112
     * @param _extension               Address of the extension contract to add
113
     */
114
    function addExtension(address _extension) external onlyInitialized onlyOwner {
UNCOV
115
        require(!isExtension[_extension], "Extension already exists");
×
116

UNCOV
117
        _addExtension(_extension);
×
118

UNCOV
119
        extensions.push(_extension);
×
120
    }
121

122
    /**
123
     * PRIVILEGED GOVERNANCE FUNCTION. Allows governance to remove an extension
124
     *
125
     * @param _extension               Address of the extension contract to remove
126
     */
127
    function removeExtension(address _extension) external onlyInitialized onlyOwner {
UNCOV
128
        require(isExtension[_extension], "Extension does not exist");
×
129

UNCOV
130
        extensions.removeStorage(_extension);
×
131

UNCOV
132
        isExtension[_extension] = false;
×
133

UNCOV
134
        emit ExtensionRemoved(_extension);
×
135
    }
136

137
    /**
138
     * PRIVILEGED GOVERNANCE FUNCTION. Allows governance to add a factory
139
     *
140
     * @param _factory               Address of the factory contract to add
141
     */
142
    function addFactory(address _factory) external onlyInitialized onlyOwner {
UNCOV
143
        require(!isFactory[_factory], "Factory already exists");
×
144

UNCOV
145
        _addFactory(_factory);
×
146

UNCOV
147
        factories.push(_factory);
×
148
    }
149

150
    /**
151
     * PRIVILEGED GOVERNANCE FUNCTION. Allows governance to remove a factory
152
     *
153
     * @param _factory               Address of the factory contract to remove
154
     */
155
    function removeFactory(address _factory) external onlyInitialized onlyOwner {
156
        require(isFactory[_factory], "Factory does not exist");
2!
157

158
        factories.removeStorage(_factory);
2✔
159

160
        isFactory[_factory] = false;
2✔
161

162
        emit FactoryRemoved(_factory);
2✔
163
    }
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");
30!
172

173
        isManager[_manager] = true;
30✔
174

175
        managers.push(_manager);
30✔
176

177
        emit ManagerAdded(_manager, msg.sender);
30✔
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");
13!
187

188
        managers.removeStorage(_manager);
13✔
189

190
        isManager[_manager] = false;
13✔
191

192
        emit ManagerRemoved(_manager);
13✔
193
    }
194

195
    /* ============ External Getter Functions ============ */
196

197
    function getExtensions() external view returns (address[] memory) {
UNCOV
198
        return extensions;
×
199
    }
200

201
    function getFactories() external view returns (address[] memory) {
UNCOV
202
        return factories;
×
203
    }
204

205
    function getManagers() external view returns (address[] memory) {
UNCOV
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.");
7!
218

219
        isExtension[_extension] = true;
7✔
220

221
        emit ExtensionAdded(_extension);
7✔
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.");
6!
231

232
        isFactory[_factory] = true;
6✔
233

234
        emit FactoryAdded(_factory);
6✔
235
    }
236
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc