-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathBaseV2GaugeManager.sol
164 lines (125 loc) · 5.6 KB
/
BaseV2GaugeManager.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Ownable} from "solady/auth/Ownable.sol";
import {bHermes, bHermesBoost, bHermesGauges} from "@hermes/bHermes.sol";
import {BaseV2GaugeFactory} from "./BaseV2GaugeFactory.sol";
import {IBaseV2GaugeManager} from "../interfaces/IBaseV2GaugeManager.sol";
/// @title Base V2 Gauge Factory Manager - Manages addition/removal of Gauge Factories to bHermes.
contract BaseV2GaugeManager is Ownable, IBaseV2GaugeManager {
/*///////////////////////////////////////////////////////////////
GAUGE MANAGER STATE
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IBaseV2GaugeManager
address public admin;
/// @inheritdoc IBaseV2GaugeManager
bHermesGauges public immutable bHermesGaugeWeight;
/// @inheritdoc IBaseV2GaugeManager
bHermesBoost public immutable bHermesGaugeBoost;
/// @inheritdoc IBaseV2GaugeManager
BaseV2GaugeFactory[] public gaugeFactories;
/// @inheritdoc IBaseV2GaugeManager
mapping(BaseV2GaugeFactory => uint256) public gaugeFactoryIds;
/// @inheritdoc IBaseV2GaugeManager
mapping(BaseV2GaugeFactory => bool) public activeGaugeFactories;
/**
* @notice Initializes Base V2 Gauge Factory Manager contract.
* @param _bHermes bHermes contract
* @param _owner can add BaseV2GaugeFactories.
* @param _admin can transfer ownership of bHermesWeight and bHermesBoost.
*/
constructor(bHermes _bHermes, address _owner, address _admin) {
admin = _admin;
_initializeOwner(_owner);
bHermesGaugeWeight = _bHermes.gaugeWeight();
bHermesGaugeBoost = _bHermes.gaugeBoost();
}
/// @inheritdoc IBaseV2GaugeManager
function getGaugeFactories() external view returns (BaseV2GaugeFactory[] memory) {
return gaugeFactories;
}
/*//////////////////////////////////////////////////////////////
EPOCH LOGIC
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IBaseV2GaugeManager
function newEpoch() external {
BaseV2GaugeFactory[] storage _gaugeFactories = gaugeFactories;
uint256 length = _gaugeFactories.length;
for (uint256 i = 0; i < length;) {
if (activeGaugeFactories[_gaugeFactories[i]]) _gaugeFactories[i].newEpoch();
unchecked {
i++;
}
}
}
/// @inheritdoc IBaseV2GaugeManager
function newEpoch(uint256 start, uint256 end) external {
BaseV2GaugeFactory[] storage _gaugeFactories = gaugeFactories;
uint256 length = _gaugeFactories.length;
if (end > length) end = length;
for (uint256 i = start; i < end;) {
if (activeGaugeFactories[_gaugeFactories[i]]) _gaugeFactories[i].newEpoch();
unchecked {
i++;
}
}
}
/*//////////////////////////////////////////////////////////////
GAUGE LOGIC
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IBaseV2GaugeManager
function addGauge(address gauge) external onlyActiveGaugeFactory {
bHermesGaugeWeight.addGauge(gauge);
bHermesGaugeBoost.addGauge(gauge);
}
/// @inheritdoc IBaseV2GaugeManager
function removeGauge(address gauge) external onlyActiveGaugeFactory {
bHermesGaugeWeight.removeGauge(gauge);
bHermesGaugeBoost.removeGauge(gauge);
}
/*//////////////////////////////////////////////////////////////
OWNER LOGIC
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IBaseV2GaugeManager
function addGaugeFactory(BaseV2GaugeFactory gaugeFactory) external onlyOwner {
if (activeGaugeFactories[gaugeFactory]) revert GaugeFactoryAlreadyExists();
gaugeFactoryIds[gaugeFactory] = gaugeFactories.length;
gaugeFactories.push(gaugeFactory);
activeGaugeFactories[gaugeFactory] = true;
emit AddedGaugeFactory(address(gaugeFactory));
}
/// @inheritdoc IBaseV2GaugeManager
function removeGaugeFactory(BaseV2GaugeFactory gaugeFactory) external onlyOwner {
if (!activeGaugeFactories[gaugeFactory] || gaugeFactories[gaugeFactoryIds[gaugeFactory]] != gaugeFactory) {
revert NotActiveGaugeFactory();
}
delete gaugeFactories[gaugeFactoryIds[gaugeFactory]];
delete gaugeFactoryIds[gaugeFactory];
delete activeGaugeFactories[gaugeFactory];
emit RemovedGaugeFactory(address(gaugeFactory));
}
/*//////////////////////////////////////////////////////////////
ADMIN LOGIC
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IBaseV2GaugeManager
function changebHermesGaugeOwner(address newOwner) external onlyAdmin {
bHermesGaugeWeight.transferOwnership(newOwner);
bHermesGaugeBoost.transferOwnership(newOwner);
emit ChangedbHermesGaugeOwner(newOwner);
}
/// @inheritdoc IBaseV2GaugeManager
function changeAdmin(address newAdmin) external onlyAdmin {
admin = newAdmin;
emit ChangedAdmin(newAdmin);
}
/*//////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////*/
modifier onlyActiveGaugeFactory() {
if (!activeGaugeFactories[BaseV2GaugeFactory(msg.sender)]) revert NotActiveGaugeFactory();
_;
}
modifier onlyAdmin() {
if (msg.sender != admin) revert NotAdmin();
_;
}
}