-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGraphProxyAdmin.sol
103 lines (92 loc) · 3.85 KB
/
GraphProxyAdmin.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.7.6;
import "../governance/Governed.sol";
import "./IGraphProxy.sol";
import "./GraphUpgradeable.sol";
/**
* @title GraphProxyAdmin
* @dev This is the owner of upgradeable proxy contracts.
* Proxy contracts use a TransparentProxy pattern, any admin related call
* like upgrading a contract or changing the admin needs to be send through
* this contract.
*/
contract GraphProxyAdmin is Governed {
/**
* @dev Contract constructor.
*/
constructor() {
Governed._initialize(msg.sender);
}
/**
* @dev Returns the current implementation of a proxy.
* This is needed because only the proxy admin can query it.
* @return The address of the current implementation of the proxy.
*/
function getProxyImplementation(IGraphProxy _proxy) public view returns (address) {
// We need to manually run the static call since the getter cannot be flagged as view
// bytes4(keccak256("implementation()")) == 0x5c60da1b
(bool success, bytes memory returndata) = address(_proxy).staticcall(hex"5c60da1b");
require(success);
return abi.decode(returndata, (address));
}
/**
* @dev Returns the pending implementation of a proxy.
* This is needed because only the proxy admin can query it.
* @return The address of the pending implementation of the proxy.
*/
function getProxyPendingImplementation(IGraphProxy _proxy) public view returns (address) {
// We need to manually run the static call since the getter cannot be flagged as view
// bytes4(keccak256("pendingImplementation()")) == 0x396f7b23
(bool success, bytes memory returndata) = address(_proxy).staticcall(hex"396f7b23");
require(success);
return abi.decode(returndata, (address));
}
/**
* @dev Returns the admin of a proxy. Only the admin can query it.
* @return The address of the current admin of the proxy.
*/
function getProxyAdmin(IGraphProxy _proxy) public view returns (address) {
// We need to manually run the static call since the getter cannot be flagged as view
// bytes4(keccak256("admin()")) == 0xf851a440
(bool success, bytes memory returndata) = address(_proxy).staticcall(hex"f851a440");
require(success);
return abi.decode(returndata, (address));
}
/**
* @dev Changes the admin of a proxy.
* @param _proxy Proxy to change admin.
* @param _newAdmin Address to transfer proxy administration to.
*/
function changeProxyAdmin(IGraphProxy _proxy, address _newAdmin) public onlyGovernor {
_proxy.setAdmin(_newAdmin);
}
/**
* @dev Upgrades a proxy to the newest implementation of a contract.
* @param _proxy Proxy to be upgraded.
* @param _implementation the address of the Implementation.
*/
function upgrade(IGraphProxy _proxy, address _implementation) public onlyGovernor {
_proxy.upgradeTo(_implementation);
}
/**
* @dev Accepts a proxy.
* @param _implementation Address of the implementation accepting the proxy.
* @param _proxy Address of the proxy being accepted.
*/
function acceptProxy(GraphUpgradeable _implementation, IGraphProxy _proxy) public onlyGovernor {
_implementation.acceptProxy(_proxy);
}
/**
* @dev Accepts a proxy and call a function on the implementation.
* @param _implementation Address of the implementation accepting the proxy.
* @param _proxy Address of the proxy being accepted.
* @param _data Encoded function to call on the implementation after accepting the proxy.
*/
function acceptProxyAndCall(
GraphUpgradeable _implementation,
IGraphProxy _proxy,
bytes calldata _data
) external onlyGovernor {
_implementation.acceptProxyAndCall(_proxy, _data);
}
}