UUPSUpgradeable.sol 1.0 KB

12345678910111213141516171819202122232425262728
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../ERC1967/ERC1967Upgrade.sol";
  4. /**
  5. * @dev Base contract for building openzeppelin-upgrades compatible implementations for the {ERC1967Proxy}. It includes
  6. * publicly available upgrade functions that are called by the plugin and by the secure upgrade mechanism to verify
  7. * continuation of the upgradability.
  8. *
  9. * The {_authorizeUpgrade} function MUST be overridden to include access restriction to the upgrade mechanism.
  10. *
  11. * _Available since v4.1._
  12. */
  13. abstract contract UUPSUpgradeable is ERC1967Upgrade {
  14. function upgradeTo(address newImplementation) external virtual {
  15. _authorizeUpgrade(newImplementation);
  16. _upgradeToAndCallSecure(newImplementation, bytes(""), false);
  17. }
  18. function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual {
  19. _authorizeUpgrade(newImplementation);
  20. _upgradeToAndCallSecure(newImplementation, data, true);
  21. }
  22. function _authorizeUpgrade(address newImplementation) internal virtual;
  23. }