forked from wighawag/hardhat-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransparentProxy.sol
87 lines (73 loc) · 2.8 KB
/
TransparentProxy.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "./Proxy.sol";
contract TransparentProxy is Proxy {
// /////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////////////
constructor(
address implementationAddress,
bytes memory data,
address adminAddress
) public {
_setImplementation(implementationAddress, data);
_setAdmin(adminAddress);
}
// ///////////////////// EXTERNAL ///////////////////////////////////////////////////////////////////////////
function changeImplementation(
address newImplementation,
bytes calldata data
) external ifAdmin {
_setImplementation(newImplementation, data);
}
function proxyAdmin() external ifAdmin returns (address) {
return _admin();
}
// Transfer of adminship on the other hand is only visible to the admin of the Proxy
function changeProxyAdmin(address newAdmin) external ifAdmin {
uint256 disabled;
// solhint-disable-next-line security/no-inline-assembly
assembly {
disabled := sload(
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6102
)
}
require(disabled == 0, "changeAdmin has been disabled");
_setAdmin(newAdmin);
}
// to be used if EIP-173 needs to be implemented in the implementation contract so that change of admin can be constrained
// in a way that OwnershipTransfered is trigger all the time
function disableChangeProxyAdmin() external ifAdmin {
// solhint-disable-next-line security/no-inline-assembly
assembly {
sstore(
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6102,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
)
}
}
// /////////////////////// MODIFIERS ////////////////////////////////////////////////////////////////////////
modifier ifAdmin() {
if (msg.sender == _admin()) {
_;
} else {
_fallback();
}
}
// ///////////////////////// INTERNAL //////////////////////////////////////////////////////////////////////
function _admin() internal view returns (address adminAddress) {
// solhint-disable-next-line security/no-inline-assembly
assembly {
adminAddress := sload(
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103
)
}
}
function _setAdmin(address newAdmin) internal {
// solhint-disable-next-line security/no-inline-assembly
assembly {
sstore(
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103,
newAdmin
)
}
}
}