Adapt proxies to Contracts conventions (#2345)

pull/2347/head
Francisco Giordano 4 years ago committed by GitHub
parent 6bc2ae3731
commit 91f16a7e47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      contracts/proxy/Initializable.sol
  2. 6
      contracts/proxy/Proxy.sol
  3. 8
      contracts/proxy/TransparentUpgradeableProxy.sol
  4. 2
      contracts/proxy/UpgradeableProxy.sol

@ -15,7 +15,7 @@ pragma solidity >=0.4.24 <0.7.0;
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*/ */
contract Initializable { abstract contract Initializable {
/** /**
* @dev Indicates that the contract has been initialized. * @dev Indicates that the contract has been initialized.

@ -52,7 +52,7 @@ abstract contract Proxy {
* This function does not return to its internall call site, it will return directly to the external caller. * This function does not return to its internall call site, it will return directly to the external caller.
*/ */
function _fallback() internal { function _fallback() internal {
_willFallback(); _beforeFallback();
_delegate(_implementation()); _delegate(_implementation());
} }
@ -76,8 +76,8 @@ abstract contract Proxy {
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions. * call, or as part of the Solidity `fallback` or `receive` functions.
* *
* If overriden should call `super._willFallback()`. * If overriden should call `super._beforeFallback()`.
*/ */
function _willFallback() internal virtual { function _beforeFallback() internal virtual {
} }
} }

@ -134,7 +134,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy {
/** /**
* @dev Stores a new address in the EIP1967 admin slot. * @dev Stores a new address in the EIP1967 admin slot.
*/ */
function _setAdmin(address newAdmin) internal { function _setAdmin(address newAdmin) private {
bytes32 slot = _ADMIN_SLOT; bytes32 slot = _ADMIN_SLOT;
// solhint-disable-next-line no-inline-assembly // solhint-disable-next-line no-inline-assembly
@ -144,10 +144,10 @@ contract TransparentUpgradeableProxy is UpgradeableProxy {
} }
/** /**
* @dev Makes sure the admin cannot access the fallback function. See {Proxy-_willFallback}. * @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.
*/ */
function _willFallback() internal override virtual { function _beforeFallback() internal override virtual {
require(msg.sender != _admin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target"); require(msg.sender != _admin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target");
super._willFallback(); super._beforeFallback();
} }
} }

@ -67,7 +67,7 @@ contract UpgradeableProxy is Proxy {
/** /**
* @dev Stores a new address in the EIP1967 implementation slot. * @dev Stores a new address in the EIP1967 implementation slot.
*/ */
function _setImplementation(address newImplementation) internal { function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "UpgradeableProxy: new implementation is not a contract"); require(Address.isContract(newImplementation), "UpgradeableProxy: new implementation is not a contract");
bytes32 slot = _IMPLEMENTATION_SLOT; bytes32 slot = _IMPLEMENTATION_SLOT;

Loading…
Cancel
Save