/
Controller.sol
161 lines (127 loc) · 4.33 KB
/
Controller.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
pragma solidity 0.4.17;
import 'IController.sol';
import 'IControlled.sol';
import 'libraries/token/ERC20Basic.sol';
import 'libraries/Extractable.sol';
contract Controller is IController {
address public owner;
mapping(address => bool) public whitelist;
mapping(bytes32 => address) public registry;
bool public stopped = false;
modifier onlyWhitelistedCallers {
assertIsWhitelisted(msg.sender);
_;
}
modifier devModeOwnerOnly {
require(msg.sender == owner);
require(whitelist[owner]);
_;
}
modifier onlyOwnerCaller {
require(msg.sender == owner);
_;
}
modifier onlyInBadTimes {
require(stopped);
_;
}
modifier onlyInGoodTimes {
require(!stopped);
_;
}
function Controller() public {
owner = msg.sender;
whitelist[owner] = true;
}
/*
* Whitelisting [whitelisted augur contracts and dev mode can use it]
*/
function addToWhitelist(address _target) public onlyWhitelistedCallers returns(bool) {
whitelist[_target] = true;
return true;
}
function removeFromWhitelist(address _target) public onlyWhitelistedCallers returns(bool) {
whitelist[_target] = false;
return true;
}
function assertIsWhitelisted(address _target) public view returns(bool) {
require(whitelist[_target]);
return true;
}
/*
* Registry for lookups [whitelisted augur contracts and dev mode can use it]
*/
function setValue(bytes32 _key, address _value) public onlyWhitelistedCallers returns(bool) {
registry[_key] = _value;
return true;
}
function removeValue(bytes32 _key) public onlyWhitelistedCallers returns(bool) {
registry[_key] = address(0);
return true;
}
function lookup(bytes32 _key) public view returns(address) {
return registry[_key];
}
function assertOnlySpecifiedCaller(address _caller, bytes32 _allowedCaller) public view returns(bool) {
require(registry[_allowedCaller] == _caller || (msg.sender == owner && whitelist[owner]));
return true;
}
/*
* Contract Administration [dev mode can use it]
*/
function suicideFunds(IControlled _target, address _destination, ERC20Basic[] _tokens) public devModeOwnerOnly returns(bool) {
_target.suicideFunds(_destination, _tokens);
return true;
}
function extractEther(Extractable _target, address _destination) public devModeOwnerOnly returns(bool) {
_target.extractEther(_destination);
return true;
}
function extractTokens(Extractable _target, address _destination, ERC20Basic _token) public devModeOwnerOnly returns(bool) {
_target.extractTokens(_destination, _token);
return true;
}
function updateController(IControlled _target, Controller _newController) public devModeOwnerOnly returns(bool) {
_target.setController(_newController);
return true;
}
/*
* Controller Administration [dev can transfer ownership anytime, mode can only switched from dev mode -> decentralized]
*/
function transferOwnership(address _newOwner) public onlyOwnerCaller returns(bool) {
// if in dev mode, blacklist old owner and whitelist new owner
if (whitelist[owner]) {
whitelist[owner] = false;
whitelist[_newOwner] = true;
}
owner = _newOwner;
return true;
}
function switchModeSoOnlyEmergencyStopsAndEscapeHatchesCanBeUsed() public devModeOwnerOnly returns(bool) {
whitelist[owner] = false;
return true;
}
/*
* Emergency Stop Functions [dev can use it anytime in or out of dev mode]
*/
function emergencyStop() public onlyOwnerCaller onlyInGoodTimes returns(bool) {
stopped = true;
return true;
}
function release() public onlyOwnerCaller onlyInBadTimes returns(bool) {
stopped = false;
return true;
}
function stopInEmergency() public constant onlyInGoodTimes returns(bool) {
return true;
}
function onlyInEmergency() public constant onlyInBadTimes returns(bool) {
return true;
}
/*
* Helper functions
*/
function getAugur() public view returns (Augur) {
return Augur(lookup("Augur"));
}
}