forked from wighawag/hardhat-deploy
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProxied.sol
executable file
·42 lines (39 loc) · 1.73 KB
/
Proxied.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
abstract contract Proxied {
/// @notice to be used by initialisation / postUpgrade function so that only the proxy's admin can execute them
/// It also allows these functions to be called inside a contructor
/// even if the contract is meant to be used without proxy
modifier proxied() {
address proxyAdminAddress = _proxyAdmin();
// With hardhat-deploy proxies
// the proxyAdminAddress is zero only for the implementation contract
// if the implementation contract want to be used as a standalone/immutable contract
// it simply has to execute the `proxied` function
// This ensure the proxyAdminAddress is never zero post deployment
// And allow you to keep the same code for both proxied contract and immutable contract
if (proxyAdminAddress == address(0)) {
// ensure can not be called twice when used outside of proxy : no admin
// solhint-disable-next-line security/no-inline-assembly
assembly {
sstore(
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
)
}
} else {
require(msg.sender == proxyAdminAddress);
}
_;
}
modifier onlyProxyAdmin() {
require(msg.sender == _proxyAdmin(), "NOT_AUTHORIZED");
_;
}
function _proxyAdmin() internal view returns (address ownerAddress) {
// solhint-disable-next-line security/no-inline-assembly
assembly {
ownerAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103)
}
}
}