-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathProxyOwner.sol
56 lines (47 loc) · 2.25 KB
/
ProxyOwner.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
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;
import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
/**
* @title ProxyOwner
* @notice ProxyAdmin with 2-step ownership transfer
* @dev Adds 2-step ownership transfer to the OpenZeppelin ProxyAdmin contract, both for the owner of the ProxyAdmin
* and to the proxy ownership transfer.
*/
contract ProxyOwner is ProxyAdmin, Ownable2Step {
// sig: 0xd8921f35
/// @custom:error Caller is not the pending admin
error ProxyOwnerNotPendingAdminError();
/// @dev Mapping of the pending admin for each proxy
mapping(TransparentUpgradeableProxy => address) public pendingAdmins;
/// @dev Only allows calls from the pending admin of `proxy`
modifier onlyPendingOwner(TransparentUpgradeableProxy proxy) {
if(pendingAdmins[proxy] != msg.sender) revert ProxyOwnerNotPendingAdminError();
_;
}
/// @notice Sets the pending admin for `proxy` to `newAdmin`
/// @param proxy The proxy to change the pending admin for
/// @param newAdmin The address of the new pending admin
function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public override onlyOwner {
pendingAdmins[proxy] = newAdmin;
}
/// @notice Processes the admin change for `proxy`
/// @dev Callback used by the new proxy owner
/// @param proxy The proxy to accept the pending admin for
function acceptProxyAdminCallback(TransparentUpgradeableProxy proxy) external onlyPendingOwner(proxy) {
proxy.changeAdmin(msg.sender);
delete pendingAdmins[proxy];
}
/// @notice Accepts ownership of `proxy`
/// @param previousOwner The previous owner of the proxy
/// @param proxy The proxy to accept ownership of
function acceptProxyAdmin(ProxyOwner previousOwner, TransparentUpgradeableProxy proxy) external onlyOwner {
previousOwner.acceptProxyAdminCallback(proxy);
}
function transferOwnership(address newOwner) public override(Ownable, Ownable2Step) {
super.transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal override(Ownable, Ownable2Step) {
super._transferOwnership(newOwner);
}
}