Add documentation for proxies (#2344)
This commit is contained in:
committed by
GitHub
parent
885b76f66f
commit
6bc2ae3731
@ -6,16 +6,17 @@ import "../access/Ownable.sol";
|
||||
import "./TransparentUpgradeableProxy.sol";
|
||||
|
||||
/**
|
||||
* @title ProxyAdmin
|
||||
* @dev This contract is the admin of a proxy, and is in charge
|
||||
* of upgrading it as well as transferring it to another admin.
|
||||
* @dev This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an
|
||||
* explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}.
|
||||
*/
|
||||
contract ProxyAdmin is Ownable {
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @dev Returns the current implementation of `proxy`.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - This contract must be the admin of `proxy`.
|
||||
*/
|
||||
function getProxyImplementation(TransparentUpgradeableProxy proxy) public view returns (address) {
|
||||
// We need to manually run the static call since the getter cannot be flagged as view
|
||||
@ -26,8 +27,11 @@ contract ProxyAdmin is Ownable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the admin of a proxy. Only the admin can query it.
|
||||
* @return The address of the current admin of the proxy.
|
||||
* @dev Returns the current admin of `proxy`.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - This contract must be the admin of `proxy`.
|
||||
*/
|
||||
function getProxyAdmin(TransparentUpgradeableProxy proxy) public view returns (address) {
|
||||
// We need to manually run the static call since the getter cannot be flagged as view
|
||||
@ -38,31 +42,34 @@ contract ProxyAdmin is Ownable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Changes the admin of a proxy.
|
||||
* @param proxy Proxy to change admin.
|
||||
* @param newAdmin Address to transfer proxy administration to.
|
||||
* @dev Changes the admin of `proxy` to `newAdmin`.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - This contract must be the current admin of `proxy`.
|
||||
*/
|
||||
function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public onlyOwner {
|
||||
proxy.changeAdmin(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.
|
||||
* @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - This contract must be the admin of `proxy`.
|
||||
*/
|
||||
function upgrade(TransparentUpgradeableProxy proxy, address implementation) public onlyOwner {
|
||||
proxy.upgradeTo(implementation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Upgrades a proxy to the newest implementation of a contract and forwards a function call to it.
|
||||
* This is useful to initialize the proxied contract.
|
||||
* @param proxy Proxy to be upgraded.
|
||||
* @param implementation Address of the Implementation.
|
||||
* @param data Data to send as msg.data in the low level call.
|
||||
* It should include the signature and the parameters of the function to be called, as described in
|
||||
* https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding.
|
||||
* @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See
|
||||
* {TransparentUpgradeableProxy-upgradeToAndCall}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - This contract must be the admin of `proxy`.
|
||||
*/
|
||||
function upgradeAndCall(TransparentUpgradeableProxy proxy, address implementation, bytes memory data) public payable onlyOwner {
|
||||
proxy.upgradeToAndCall{value: msg.value}(implementation, data);
|
||||
|
||||
Reference in New Issue
Block a user