ERC1967Proxy.sol 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../Proxy.sol";
  4. import "./ERC1967Upgrade.sol";
  5. /**
  6. * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
  7. * implementation address that can be changed. This address is stored in storage in the location specified by
  8. * https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the
  9. * implementation behind the proxy.
  10. */
  11. contract ERC1967Proxy is Proxy, ERC1967Upgrade {
  12. /**
  13. * @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`.
  14. *
  15. * If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded
  16. * function call, and allows initializating the storage of the proxy like a Solidity constructor.
  17. */
  18. constructor(address _logic, bytes memory _data) payable {
  19. assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
  20. _upgradeToAndCall(_logic, _data, false);
  21. }
  22. /**
  23. * @dev Returns the current implementation address.
  24. */
  25. function _implementation() internal view virtual override returns (address impl) {
  26. return ERC1967Storage._getImplementation();
  27. }
  28. }