2020-10-13 08:28:52 +00:00
|
|
|
// SPDX-License-Identifier: agpl-3.0
|
|
|
|
pragma solidity ^0.6.8;
|
|
|
|
|
2020-10-15 13:25:27 +00:00
|
|
|
import '../../dependencies/openzeppelin/upgradeability/BaseUpgradeabilityProxy.sol';
|
2020-10-13 08:28:52 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-13 11:21:11 +00:00
|
|
|
* @title BaseImmutableAdminUpgradeabilityProxy
|
|
|
|
* @author Aave, inspired by the OpenZeppelin upgradeability proxy pattern
|
2020-10-13 08:28:52 +00:00
|
|
|
* @dev This contract combines an upgradeability proxy with an authorization
|
2020-10-13 11:21:11 +00:00
|
|
|
* mechanism for administrative tasks. The admin role is stored in an immutable, which
|
|
|
|
* helps saving transactions costs
|
2020-10-13 08:28:52 +00:00
|
|
|
* All external functions in this contract must be guarded by the
|
|
|
|
* `ifAdmin` modifier. See ethereum/solidity#3864 for a Solidity
|
|
|
|
* feature proposal that would enable this to be done automatically.
|
|
|
|
*/
|
|
|
|
contract BaseImmutableAdminUpgradeabilityProxy is BaseUpgradeabilityProxy {
|
|
|
|
address immutable ADMIN;
|
|
|
|
|
|
|
|
constructor(address admin) public {
|
2020-10-15 13:16:05 +00:00
|
|
|
ADMIN = admin;
|
2020-10-13 08:28:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
modifier ifAdmin() {
|
|
|
|
if (msg.sender == ADMIN) {
|
|
|
|
_;
|
|
|
|
} else {
|
|
|
|
_fallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The address of the proxy admin.
|
|
|
|
*/
|
|
|
|
function admin() external ifAdmin returns (address) {
|
|
|
|
return ADMIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The address of the implementation.
|
|
|
|
*/
|
|
|
|
function implementation() external ifAdmin returns (address) {
|
|
|
|
return _implementation();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Upgrade the backing implementation of the proxy.
|
|
|
|
* Only the admin can call this function.
|
|
|
|
* @param newImplementation Address of the new implementation.
|
|
|
|
*/
|
|
|
|
function upgradeTo(address newImplementation) external ifAdmin {
|
|
|
|
_upgradeTo(newImplementation);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Upgrade the backing implementation of the proxy and call a function
|
|
|
|
* on the new implementation.
|
|
|
|
* This is useful to initialize the proxied contract.
|
|
|
|
* @param newImplementation Address of the new 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.
|
|
|
|
*/
|
|
|
|
function upgradeToAndCall(address newImplementation, bytes calldata data)
|
|
|
|
external
|
|
|
|
payable
|
|
|
|
ifAdmin
|
|
|
|
{
|
|
|
|
_upgradeTo(newImplementation);
|
|
|
|
(bool success, ) = newImplementation.delegatecall(data);
|
|
|
|
require(success);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Only fall back when the sender is not the admin.
|
|
|
|
*/
|
|
|
|
function _willFallback() internal virtual override {
|
|
|
|
require(msg.sender != ADMIN, 'Cannot call fallback function from the proxy admin');
|
|
|
|
super._willFallback();
|
|
|
|
}
|
|
|
|
}
|