ERC1967Proxy.sol 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v5.2.0-rc.0) (proxy/ERC1967/ERC1967Proxy.sol)
  3. pragma solidity ^0.8.22;
  4. import {Proxy} from "../Proxy.sol";
  5. import {ERC1967Utils} from "./ERC1967Utils.sol";
  6. /**
  7. * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
  8. * implementation address that can be changed. This address is stored in storage in the location specified by
  9. * https://eips.ethereum.org/EIPS/eip-1967[ERC-1967], so that it doesn't conflict with the storage layout of the
  10. * implementation behind the proxy.
  11. */
  12. contract ERC1967Proxy is Proxy {
  13. /**
  14. * @dev Initializes the upgradeable proxy with an initial implementation specified by `implementation`.
  15. *
  16. * If `_data` is nonempty, it's used as data in a delegate call to `implementation`. This will typically be an
  17. * encoded function call, and allows initializing the storage of the proxy like a Solidity constructor.
  18. *
  19. * Requirements:
  20. *
  21. * - If `data` is empty, `msg.value` must be zero.
  22. */
  23. constructor(address implementation, bytes memory _data) payable {
  24. ERC1967Utils.upgradeToAndCall(implementation, _data);
  25. }
  26. /**
  27. * @dev Returns the current implementation address.
  28. *
  29. * TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
  30. * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
  31. * `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
  32. */
  33. function _implementation() internal view virtual override returns (address) {
  34. return ERC1967Utils.getImplementation();
  35. }
  36. }