-
Notifications
You must be signed in to change notification settings - Fork 2
C4 mothership fixes #119
base: main
Are you sure you want to change the base?
C4 mothership fixes #119
Changes from all commits
e531e30
d902965
2aa7584
403e173
9f55e90
7b27e5c
2975956
06fe6e4
c68de85
834d485
6f700ff
0d26079
611f1e6
e395ca8
66fa1cf
f65c7bc
9d5cc51
d39c1c3
78d5330
491ce1f
e213ad2
9b86527
69ee4f5
bd78105
ff13d94
48ac18b
55da9bc
dbff53f
216dcba
9c7332a
7e4d760
513a198
886b8f0
178c7ce
44c955d
74e22d6
6d7bd76
eb826de
1dc9544
36e88c4
c51f56c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,51 +7,51 @@ import "../OverlayToken.sol"; | |
|
||
contract OverlayV1Mothership is AccessControlEnumerable { | ||
|
||
uint16 public constant MIN_FEE = 1; // 0.01% | ||
uint16 public constant MAX_FEE = 100; // 1.00% | ||
uint public constant MIN_FEE = 1e14; // 0.01% | ||
uint public constant MAX_FEE = 1e16; // 1.00% | ||
|
||
uint16 public constant MIN_MARGIN_MAINTENANCE = 100; // 1% maintenance | ||
uint16 public constant MAX_MARGIN_MAINTENANCE = 6000; // 60% maintenance | ||
uint public constant MAX_FEE_BURN = 1e18; // 100% | ||
uint public constant MAX_MARGIN_BURN = 1e18; // 100% | ||
|
||
bytes32 public constant ADMIN = 0x00; | ||
bytes32 public constant GOVERNOR = keccak256("GOVERNOR"); | ||
bytes32 public constant GUARDIAN = keccak256("GUARDIAN"); | ||
bytes32 public constant MINTER = keccak256("MINTER"); | ||
bytes32 public constant BURNER = keccak256("BURNER"); | ||
|
||
// ovl erc20 token | ||
address public ovl; | ||
|
||
// portion of liquidations to burn on update | ||
uint public marginBurnRate; | ||
address public immutable ovl; | ||
|
||
// global params adjustable by gov | ||
// address to send fees to | ||
address public feeTo; | ||
// build/unwind trading fee | ||
uint public fee; | ||
// portion of build/unwind fee burnt | ||
uint public feeBurnRate; | ||
// address to send fees to | ||
address public feeTo; | ||
// portion of liquidations to burn on update | ||
uint public marginBurnRate; | ||
|
||
mapping(address => bool) public marketActive; | ||
mapping(address => bool) public marketExists; | ||
address[] public allMarkets; | ||
|
||
mapping(address => bool) public collateralExists; | ||
mapping(address => bool) public collateralActive; | ||
address[] public allCollateral; | ||
address[] public allCollaterals; | ||
|
||
event UpdateCollateral(address collateral, bool active); | ||
event UpdateMarket(address market, bool active); | ||
|
||
event UpdateFeeTo(address feeTo); | ||
event UpdateFee(uint fee); | ||
event UpdateFeeBurnRate(uint feeBurnRate); | ||
event UpdateMarginBurnRate(uint marginBurnRate); | ||
|
||
modifier onlyGovernor () { | ||
require(hasRole(GOVERNOR, msg.sender), "OVLV1:!gov"); | ||
_; | ||
} | ||
|
||
modifier onlyGuardian () { | ||
require(hasRole(GUARDIAN, msg.sender), "OVLV1:!guard"); | ||
_; | ||
} | ||
|
||
constructor( | ||
address _ovl, | ||
address _feeTo, | ||
uint _fee, | ||
uint _feeBurnRate, | ||
|
@@ -60,65 +60,59 @@ contract OverlayV1Mothership is AccessControlEnumerable { | |
|
||
_setupRole(ADMIN, msg.sender); | ||
_setupRole(GOVERNOR, msg.sender); | ||
_setupRole(GUARDIAN, msg.sender); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we removing the guardian role? I don't have any strong opinions yet about the types of roles we need but it is likely more than just admin and governor. Governor would be something with a reasonable time lock for instance. Guardian would be something along the lines of emergency shutdown. Admin, that'd be to grant/remove various roles. Not sure though. I'd like to look at other protocol's thought processes. Fei in particular. We are in the realm of somewhat more permissioned operation so maybe protocols like Aave and Compound should also be taken into account. |
||
_setRoleAdmin(GOVERNOR, ADMIN); | ||
_setRoleAdmin(GUARDIAN, ADMIN); | ||
|
||
// global params | ||
fee = _fee; | ||
feeBurnRate = _feeBurnRate; | ||
feeTo = _feeTo; | ||
marginBurnRate = _marginBurnRate; | ||
|
||
} | ||
|
||
function setOVL (address _ovl) external onlyGovernor { | ||
|
||
// immutable params | ||
ovl = _ovl; | ||
|
||
// global params | ||
_setFeeTo(_feeTo); | ||
_setFee(_fee); | ||
_setFeeBurnRate(_feeBurnRate); | ||
_setMarginBurnRate(_marginBurnRate); | ||
} | ||
|
||
function totalMarkets () external view returns (uint) { | ||
return allMarkets.length; | ||
} | ||
|
||
function totalCollaterals () external view returns (uint) { | ||
return allCollaterals.length; | ||
} | ||
|
||
/** | ||
@notice Make this contract aware of a new market contract's existence | ||
@dev Should be called after contract deployment in specific market factory.createMarket | ||
@dev Only the Governor can initialize a market | ||
@dev Appends new market address to `allMarkets` array to track them | ||
@param market Overlay market contract address | ||
@param _market Overlay market contract address | ||
*/ | ||
function initializeMarket(address market) external onlyGovernor { | ||
|
||
require(!marketExists[market], "OVLV1:!!initialized"); | ||
|
||
marketExists[market] = true; | ||
marketActive[market] = true; | ||
function initializeMarket(address _market) external onlyGovernor { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't really initializing a market, that seems to say we are instantiating some state on the market. We are just adding it to the manifest here in the mothership. |
||
require(!marketExists[_market], "OVLV1: market exists"); | ||
|
||
allMarkets.push(market); | ||
marketExists[_market] = true; | ||
marketActive[_market] = true; | ||
allMarkets.push(_market); | ||
|
||
emit UpdateMarket(_market, true); | ||
} | ||
|
||
/// @notice Disables an existing market contract for a mirin market | ||
function disableMarket(address market) external onlyGovernor { | ||
function disableMarket(address _market) external onlyGovernor { | ||
require(marketExists[_market], "OVLV1: market !exists"); | ||
require(marketActive[_market], "OVLV1: market !enabled"); | ||
|
||
require(marketActive[market], "OVLV1: !enabled"); | ||
|
||
marketActive[market] = false; | ||
marketActive[_market] = false; | ||
|
||
emit UpdateMarket(_market, false); | ||
} | ||
|
||
/// @notice Enables an existing market contract for a mirin market | ||
function enableMarket(address market) external onlyGovernor { | ||
|
||
require(marketExists[market], "OVLV1: !exists"); | ||
function enableMarket(address _market) external onlyGovernor { | ||
require(marketExists[_market], "OVLV1: market !exists"); | ||
require(!marketActive[_market], "OVLV1: market !disabled"); | ||
|
||
require(!marketActive[market], "OVLV1: !disabled"); | ||
|
||
marketActive[market] = true; | ||
marketActive[_market] = true; | ||
|
||
emit UpdateMarket(_market, true); | ||
} | ||
|
||
/** | ||
|
@@ -128,65 +122,92 @@ contract OverlayV1Mothership is AccessControlEnumerable { | |
@param _collateral Overlay OVL collateral contract address | ||
*/ | ||
function initializeCollateral (address _collateral) external onlyGovernor { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, not really initializing here, just adding to the manifest and activating |
||
|
||
require(!collateralExists[_collateral], "OVLV1:!!iintialized"); | ||
require(!collateralExists[_collateral], "OVLV1: collateral exists"); | ||
|
||
collateralExists[_collateral] = true; | ||
collateralActive[_collateral] = true; | ||
|
||
allCollateral.push(_collateral); | ||
allCollaterals.push(_collateral); | ||
|
||
OverlayToken(ovl).grantRole(OverlayToken(ovl).MINTER_ROLE(), _collateral); | ||
|
||
OverlayToken(ovl).grantRole(OverlayToken(ovl).BURNER_ROLE(), _collateral); | ||
|
||
emit UpdateCollateral(_collateral, true); | ||
} | ||
|
||
function enableCollateral (address _collateral) external onlyGovernor { | ||
require(collateralExists[_collateral], "OVLV1: collateral !exists"); | ||
require(!collateralActive[_collateral], "OVLV1: collateral !disabled"); | ||
|
||
require(collateralExists[_collateral], "OVLV1:!exists"); | ||
|
||
require(!collateralActive[_collateral], "OVLV1:!disabled"); | ||
collateralActive[_collateral] = true; | ||
|
||
OverlayToken(ovl).grantRole(OverlayToken(ovl).MINTER_ROLE(), _collateral); | ||
|
||
OverlayToken(ovl).grantRole(OverlayToken(ovl).BURNER_ROLE(), _collateral); | ||
|
||
emit UpdateCollateral(_collateral, true); | ||
} | ||
|
||
function disableCollateral (address _collateral) external onlyGovernor { | ||
require(collateralExists[_collateral], "OVLV1: collateral !exists"); | ||
require(collateralActive[_collateral], "OVLV1: collateral !enabled"); | ||
|
||
require(collateralActive[_collateral], "OVLV1:!enabled"); | ||
collateralActive[_collateral] = false; | ||
|
||
OverlayToken(ovl).revokeRole(OverlayToken(ovl).MINTER_ROLE(), _collateral); | ||
|
||
OverlayToken(ovl).revokeRole(OverlayToken(ovl).BURNER_ROLE(), _collateral); | ||
|
||
emit UpdateCollateral(_collateral, false); | ||
} | ||
|
||
function setFeeTo(address _feeTo) external onlyGovernor { | ||
_setFeeTo(_feeTo); | ||
} | ||
|
||
function setFee(uint _fee) external onlyGovernor { | ||
_setFee(_fee); | ||
} | ||
|
||
function setFeeBurnRate(uint _feeBurnRate) external onlyGovernor { | ||
_setFeeBurnRate(_feeBurnRate); | ||
} | ||
|
||
/// @notice Allows gov to adjust per market params | ||
function setMarginBurnRate(uint _marginBurnRate) external onlyGovernor { | ||
_setMarginBurnRate(_marginBurnRate); | ||
} | ||
|
||
function _setFeeTo(address _feeTo) internal { | ||
require(_feeTo != address(0), "OVLV1: fees to the zero address"); | ||
feeTo = _feeTo; | ||
emit UpdateFeeTo(_feeTo); | ||
} | ||
|
||
/// @notice Allows gov to adjust global params | ||
function adjustGlobalParams( | ||
uint16 _fee, | ||
uint16 _feeBurnRate, | ||
address _feeTo | ||
) external onlyGovernor { | ||
function _setFee(uint _fee) internal { | ||
require(_fee >= MIN_FEE && _fee <= MAX_FEE, "OVLV1: fee rate out of bounds"); | ||
fee = _fee; | ||
emit UpdateFee(_fee); | ||
} | ||
|
||
function _setFeeBurnRate(uint _feeBurnRate) internal { | ||
require(_feeBurnRate <= MAX_FEE_BURN, "OVLV1: fee burn rate out of bounds"); | ||
feeBurnRate = _feeBurnRate; | ||
feeTo = _feeTo; | ||
emit UpdateFeeBurnRate(_feeBurnRate); | ||
} | ||
|
||
function _setMarginBurnRate(uint _marginBurnRate) internal { | ||
require(_marginBurnRate <= MAX_MARGIN_BURN, "OVLV1: margin burn rate out of bounds"); | ||
marginBurnRate = _marginBurnRate; | ||
emit UpdateMarginBurnRate(_marginBurnRate); | ||
} | ||
|
||
function getUpdateParams() external view returns ( | ||
uint, | ||
uint, | ||
address | ||
function getGlobalParams() external view returns ( | ||
address feeTo_, | ||
uint fee_, | ||
uint feeBurnRate_, | ||
uint marginBurnRate_ | ||
) { | ||
return ( | ||
marginBurnRate, | ||
feeBurnRate, | ||
feeTo | ||
); | ||
feeTo_ = feeTo; | ||
fee_ = fee; | ||
feeBurnRate_ = feeBurnRate; | ||
marginBurnRate_ = marginBurnRate; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we see scenarios on long tail markets where we want more?