1
2
pragma solidity ^0.4.24;
3
4
// File: zos-lib/contracts/upgradeability/Proxy.sol
5
6
/**
7
* @title Proxy
8
* @dev Implements delegation of calls to other contracts, with proper
9
* forwarding of return values and bubbling of failures.
10
* It defines a fallback function that delegates all calls to the address
11
* returned by the abstract _implementation() internal function.
12
*/
13
contract Proxy {
14
/**
15
* @dev Fallback function.
16
* Implemented entirely in `_fallback`.
17
*/
18
function () payable external {
19
_fallback();
20
}
21
22
/**
23
* @return The Address of the implementation.
24
*/
25
function _implementation() internal view returns (address);
26
27
/**
28
* @dev Delegates execution to an implementation contract.
29
* This is a low level function that doesn't return to its internal call site.
30
* It will return to the external caller whatever the implementation returns.
31
* @param implementation Address to delegate.
32
*/
33
function _delegate(address implementation) internal {
34
assembly {
35
// Copy msg.data. We take full control of memory in this inline assembly
36
// block because it will not return to Solidity code. We overwrite the
37
// Solidity scratch pad at memory position 0.
38
calldatacopy(0, 0, calldatasize)
39
40
// Call the implementation.
41
// out and outsize are 0 because we don't know the size yet.
42
let result := delegatecall(gas, implementation, 0, calldatasize, 0, 0)
43
44
// Copy the returned data.
45
returndatacopy(0, 0, returndatasize)
46
47
switch result
48
// delegatecall returns 0 on error.
49
case 0 { revert(0, returndatasize) }
50
default { return(0, returndatasize) }
51
}
52
}
53
54
/**
55
* @dev Function that is run as the first thing in the fallback function.
56
* Can be redefined in derived contracts to add functionality.
57
* Redefinitions must call super._willFallback().
58
*/
59
function _willFallback() internal {
60
}
61
62
/**
63
* @dev fallback implementation.
64
* Extracted to enable manual triggering.
65
*/
66
function _fallback() internal {
67
_willFallback();
68
_delegate(_implementation());
69
}
70
}
71
72
// File: openzeppelin-solidity/contracts/AddressUtils.sol
73
74
/**
75
* Utility library of inline functions on addresses
76
*/
77
library AddressUtils {
78
79
/**
80
* Returns whether the target address is a contract
81
* @dev This function will return false if invoked during the constructor of a contract,
82
* as the code is not actually created until after the constructor finishes.
83
* @param addr address to check
84
* @return whether the target address is a contract
85
*/
86
function isContract(address addr) internal view returns (bool) {
87
uint256 size;
88
// XXX Currently there is no better way to check if there is a contract in an address
89
// than to check the size of the code at that address.
90
// See https://ethereum.stackexchange.com/a/14016/36603
91
// for more details about how this works.
92
// TODO Check this again before the Serenity release, because all addresses will be
93
// contracts then.
94
// solium-disable-next-line security/no-inline-assembly
95
assembly { size := extcodesize(addr) }
96
return size > 0;
97
}
98
99
}
100
101
// File: zos-lib/contracts/upgradeability/UpgradeabilityProxy.sol
102
103
/**
104
* @title UpgradeabilityProxy
105
* @dev This contract implements a proxy that allows to change the
106
* implementation address to which it will delegate.
107
* Such a change is called an implementation upgrade.
108
*/
109
contract UpgradeabilityProxy is Proxy {
110
/**
111
* @dev Emitted when the implementation is upgraded.
112
* @param implementation Address of the new implementation.
113
*/
114
event Upgraded(address implementation);
115
116
/**
117
* @dev Storage slot with the address of the current implementation.
118
* This is the keccak-256 hash of "org.zeppelinos.proxy.implementation", and is
119
* validated in the constructor.
120
*/
121
bytes32 private constant IMPLEMENTATION_SLOT = 0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3;
122
123
/**
124
* @dev Contract constructor.
125
* @param _implementation Address of the initial implementation.
126
*/
127
constructor(address _implementation) public {
128
assert(IMPLEMENTATION_SLOT == keccak256("org.zeppelinos.proxy.implementation"));
129
130
_setImplementation(_implementation);
131
}
132
133
/**
134
* @dev Returns the current implementation.
135
* @return Address of the current implementation
136
*/
137
function _implementation() internal view returns (address impl) {
138
bytes32 slot = IMPLEMENTATION_SLOT;
139
assembly {
140
impl := sload(slot)
141
}
142
}
143
144
/**
145
* @dev Upgrades the proxy to a new implementation.
146
* @param newImplementation Address of the new implementation.
147
*/
148
function _upgradeTo(address newImplementation) internal {
149
_setImplementation(newImplementation);
150
emit Upgraded(newImplementation);
151
}
152
153
/**
154
* @dev Sets the implementation address of the proxy.
155
* @param newImplementation Address of the new implementation.
156
*/
157
function _setImplementation(address newImplementation) private {
158
require(AddressUtils.isContract(newImplementation), "Cannot set a proxy implementation to a non-contract address");
159
160
bytes32 slot = IMPLEMENTATION_SLOT;
161
162
assembly {
163
sstore(slot, newImplementation)
164
}
165
}
166
}
167
168
// File: zos-lib/contracts/upgradeability/AdminUpgradeabilityProxy.sol
169
170
/**
171
* @title AdminUpgradeabilityProxy
172
* @dev This contract combines an upgradeability proxy with an authorization
173
* mechanism for administrative tasks.
174
* All external functions in this contract must be guarded by the
175
* `ifAdmin` modifier. See ethereum/solidity#3864 for a Solidity
176
* feature proposal that would enable this to be done automatically.
177
*/
178
contract AdminUpgradeabilityProxy is UpgradeabilityProxy {
179
/**
180
* @dev Emitted when the administration has been transferred.
181
* @param previousAdmin Address of the previous admin.
182
* @param newAdmin Address of the new admin.
183
*/
184
event AdminChanged(address previousAdmin, address newAdmin);
185
186
/**
187
* @dev Storage slot with the admin of the contract.
188
* This is the keccak-256 hash of "org.zeppelinos.proxy.admin", and is
189
* validated in the constructor.
190
*/
191
bytes32 private constant ADMIN_SLOT = 0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b;
192
193
/**
194
* @dev Modifier to check whether the `msg.sender` is the admin.
195
* If it is, it will run the function. Otherwise, it will delegate the call
196
* to the implementation.
197
*/
198
modifier ifAdmin() {
199
if (msg.sender == _admin()) {
200
_;
201
} else {
202
_fallback();
203
}
204
}
205
206
/**
207
* Contract constructor.
208
* It sets the `msg.sender` as the proxy administrator.
209
* @param _implementation address of the initial implementation.
210
*/
211
constructor(address _implementation) UpgradeabilityProxy(_implementation) public {
212
assert(ADMIN_SLOT == keccak256("org.zeppelinos.proxy.admin"));
213
214
_setAdmin(msg.sender);
215
}
216
217
/**
218
* @return The address of the proxy admin.
219
*/
220
function admin() external view ifAdmin returns (address) {
221
return _admin();
222
}
223
224
/**
225
* @return The address of the implementation.
226
*/
227
function implementation() external view ifAdmin returns (address) {
228
return _implementation();
229
}
230
231
/**
232
* @dev Changes the admin of the proxy.
233
* Only the current admin can call this function.
234
* @param newAdmin Address to transfer proxy administration to.
235
*/
236
function changeAdmin(address newAdmin) external ifAdmin {
237
require(newAdmin != address(0), "Cannot change the admin of a proxy to the zero address");
238
emit AdminChanged(_admin(), newAdmin);
239
_setAdmin(newAdmin);
240
}
241
242
/**
243
* @dev Upgrade the backing implementation of the proxy.
244
* Only the admin can call this function.
245
* @param newImplementation Address of the new implementation.
246
*/
247
function upgradeTo(address newImplementation) external ifAdmin {
248
_upgradeTo(newImplementation);
249
}
250
251
/**
252
* @dev Upgrade the backing implementation of the proxy and call a function
253
* on the new implementation.
254
* This is useful to initialize the proxied contract.
255
* @param newImplementation Address of the new implementation.
256
* @param data Data to send as msg.data in the low level call.
257
* It should include the signature and the parameters of the function to be
258
* called, as described in
259
* https://solidity.readthedocs.io/en/develop/abi-spec.html#function-selector-and-argument-encoding.
260
*/
261
function upgradeToAndCall(address newImplementation, bytes data) payable external ifAdmin {
262
_upgradeTo(newImplementation);
263
require(address(this).call.value(msg.value)(data));
264
}
265
266
/**
267
* @return The admin slot.
268
*/
269
function _admin() internal view returns (address adm) {
270
bytes32 slot = ADMIN_SLOT;
271
assembly {
272
adm := sload(slot)
273
}
274
}
275
276
/**
277
* @dev Sets the address of the proxy admin.
278
* @param newAdmin Address of the new proxy admin.
279
*/
280
function _setAdmin(address newAdmin) internal {
281
bytes32 slot = ADMIN_SLOT;
282
283
assembly {
284
sstore(slot, newAdmin)
285
}
286
}
287
288
/**
289
* @dev Only fall back when the sender is not the admin.
290
*/
291
function _willFallback() internal {
292
require(msg.sender != _admin(), "Cannot call fallback function from the proxy admin");
293
super._willFallback();
294
}
295
}
296
297
// File: contracts/FiatTokenProxy.sol
298
299
/**
300
* Copyright CENTRE SECZ 2018
301
*
302
* Permission is hereby granted, free of charge, to any person obtaining a copy
303
* of this software and associated documentation files (the "Software"), to deal
304
* in the Software without restriction, including without limitation the rights
305
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
306
* copies of the Software, and to permit persons to whom the Software is furnished to
307
* do so, subject to the following conditions:
308
*
309
* The above copyright notice and this permission notice shall be included in all
310
* copies or substantial portions of the Software.
311
*
312
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
313
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
314
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
315
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
316
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
317
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
318
*/
319
320
pragma solidity ^0.4.24;
321
322
323
/**
324
* @title FiatTokenProxy
325
* @dev This contract proxies FiatToken calls and enables FiatToken upgrades
326
*/
327
contract FiatTokenProxy is AdminUpgradeabilityProxy {
328
constructor(address _implementation) public AdminUpgradeabilityProxy(_implementation) {
329
}
330
}