-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathImmutableModule.sol
72 lines (62 loc) · 2.38 KB
/
ImmutableModule.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
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.17;
import { ModuleKeys } from "./ModuleKeys.sol";
import { INexus } from "../interfaces/INexus.sol";
/**
* @notice Provides modifiers and internal functions to check modules and roles in the `Nexus` registry.
* For example, the `onlyGovernor` modifier validates the caller is the `Governor` in the `Nexus`.
* @author mStable
* @dev Subscribes to module updates from a given publisher and reads from its registry.
* Contract is used for upgradable proxy contracts.
*/
abstract contract ImmutableModule is ModuleKeys {
/// @notice `Nexus` contract that resolves protocol modules and roles.
INexus public immutable nexus;
/**
* @dev Initialization function for upgradable proxy contracts
* @param _nexus Address of the Nexus contract that resolves protocol modules and roles.
*/
constructor(address _nexus) {
require(_nexus != address(0), "Nexus address is zero");
nexus = INexus(_nexus);
}
/// @dev Modifier to allow function calls only from the Governor.
modifier onlyGovernor() {
_onlyGovernor();
_;
}
function _onlyGovernor() internal view {
require(msg.sender == _governor(), "Only governor can execute");
}
/// @dev Modifier to allow function calls only from the Governor or the Keeper EOA.
modifier onlyKeeperOrGovernor() {
_keeperOrGovernor();
_;
}
function _keeperOrGovernor() internal view {
require(msg.sender == _keeper() || msg.sender == _governor(), "Only keeper or governor");
}
/**
* @dev Returns Governor address from the Nexus
* @return Address of Governor Contract
*/
function _governor() internal view returns (address) {
return nexus.governor();
}
/**
* @dev Return Keeper address from the Nexus.
* This account is used for operational transactions that
* don't need multiple signatures.
* @return Address of the Keeper externally owned account.
*/
function _keeper() internal view returns (address) {
return nexus.getModule(KEY_KEEPER);
}
/**
* @dev Return Liquidator V2 module address from the Nexus
* @return Address of the Liquidator V2 contract
*/
function _liquidatorV2() internal view returns (address) {
return nexus.getModule(KEY_LIQUIDATOR_V2);
}
}