|
@@ -28,30 +28,18 @@ import "../ERC1967/ERC1967Proxy.sol";
|
|
contract TransparentUpgradeableProxy is ERC1967Proxy {
|
|
contract TransparentUpgradeableProxy is ERC1967Proxy {
|
|
/**
|
|
/**
|
|
* @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and
|
|
* @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and
|
|
- * optionally initialized with `_data` as explained in {UpgradeableProxy-constructor}.
|
|
|
|
|
|
+ * optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}.
|
|
*/
|
|
*/
|
|
constructor(address _logic, address admin_, bytes memory _data) payable ERC1967Proxy(_logic, _data) {
|
|
constructor(address _logic, address admin_, bytes memory _data) payable ERC1967Proxy(_logic, _data) {
|
|
assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
|
|
assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
|
|
- _setAdmin(admin_);
|
|
|
|
|
|
+ _changeAdmin(admin_);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * @dev Emitted when the admin account has changed.
|
|
|
|
- */
|
|
|
|
- event AdminChanged(address previousAdmin, address newAdmin);
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @dev Storage slot with the admin of the contract.
|
|
|
|
- * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
|
|
|
|
- * validated in the constructor.
|
|
|
|
- */
|
|
|
|
- bytes32 private constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin.
|
|
* @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin.
|
|
*/
|
|
*/
|
|
modifier ifAdmin() {
|
|
modifier ifAdmin() {
|
|
- if (msg.sender == _admin()) {
|
|
|
|
|
|
+ if (msg.sender == _getAdmin()) {
|
|
_;
|
|
_;
|
|
} else {
|
|
} else {
|
|
_fallback();
|
|
_fallback();
|
|
@@ -68,7 +56,7 @@ contract TransparentUpgradeableProxy is ERC1967Proxy {
|
|
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
|
|
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
|
|
*/
|
|
*/
|
|
function admin() external ifAdmin returns (address admin_) {
|
|
function admin() external ifAdmin returns (address admin_) {
|
|
- admin_ = _admin();
|
|
|
|
|
|
+ admin_ = _getAdmin();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -92,9 +80,7 @@ contract TransparentUpgradeableProxy is ERC1967Proxy {
|
|
* NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.
|
|
* NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.
|
|
*/
|
|
*/
|
|
function changeAdmin(address newAdmin) external virtual ifAdmin {
|
|
function changeAdmin(address newAdmin) external virtual ifAdmin {
|
|
- require(newAdmin != address(0), "TransparentUpgradeableProxy: new admin is the zero address");
|
|
|
|
- emit AdminChanged(_admin(), newAdmin);
|
|
|
|
- _setAdmin(newAdmin);
|
|
|
|
|
|
+ _changeAdmin(newAdmin);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -102,8 +88,8 @@ contract TransparentUpgradeableProxy is ERC1967Proxy {
|
|
*
|
|
*
|
|
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}.
|
|
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}.
|
|
*/
|
|
*/
|
|
- function upgradeTo(address newImplementation) external virtual ifAdmin {
|
|
|
|
- _upgradeTo(newImplementation);
|
|
|
|
|
|
+ function upgradeTo(address newImplementation) external ifAdmin {
|
|
|
|
+ _upgradeToAndCall(newImplementation, bytes(""), false);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -113,39 +99,22 @@ contract TransparentUpgradeableProxy is ERC1967Proxy {
|
|
*
|
|
*
|
|
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}.
|
|
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}.
|
|
*/
|
|
*/
|
|
- function upgradeToAndCall(address newImplementation, bytes calldata data) external payable virtual ifAdmin {
|
|
|
|
- _upgradeTo(newImplementation);
|
|
|
|
- Address.functionDelegateCall(newImplementation, data);
|
|
|
|
|
|
+ function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin {
|
|
|
|
+ _upgradeToAndCall(newImplementation, data, true);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* @dev Returns the current admin.
|
|
* @dev Returns the current admin.
|
|
*/
|
|
*/
|
|
- function _admin() internal view virtual returns (address adm) {
|
|
|
|
- bytes32 slot = _ADMIN_SLOT;
|
|
|
|
- // solhint-disable-next-line no-inline-assembly
|
|
|
|
- assembly {
|
|
|
|
- adm := sload(slot)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @dev Stores a new address in the EIP1967 admin slot.
|
|
|
|
- */
|
|
|
|
- function _setAdmin(address newAdmin) private {
|
|
|
|
- bytes32 slot = _ADMIN_SLOT;
|
|
|
|
-
|
|
|
|
- // solhint-disable-next-line no-inline-assembly
|
|
|
|
- assembly {
|
|
|
|
- sstore(slot, newAdmin)
|
|
|
|
- }
|
|
|
|
|
|
+ function _admin() internal view virtual returns (address) {
|
|
|
|
+ return _getAdmin();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.
|
|
* @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.
|
|
*/
|
|
*/
|
|
function _beforeFallback() internal virtual override {
|
|
function _beforeFallback() internal virtual override {
|
|
- require(msg.sender != _admin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target");
|
|
|
|
|
|
+ require(msg.sender != _getAdmin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target");
|
|
super._beforeFallback();
|
|
super._beforeFallback();
|
|
}
|
|
}
|
|
}
|
|
}
|