ProxyAdmin.sol 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v5.1.0-rc.0) (proxy/transparent/ProxyAdmin.sol)
  3. pragma solidity ^0.8.20;
  4. import {ITransparentUpgradeableProxy} from "./TransparentUpgradeableProxy.sol";
  5. import {Ownable} from "../../access/Ownable.sol";
  6. /**
  7. * @dev This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an
  8. * explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}.
  9. */
  10. contract ProxyAdmin is Ownable {
  11. /**
  12. * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgrade(address,address)`
  13. * and `upgradeAndCall(address,address,bytes)` are present, and `upgrade` must be used if no function should be called,
  14. * while `upgradeAndCall` will invoke the `receive` function if the third argument is the empty byte string.
  15. * If the getter returns `"5.0.0"`, only `upgradeAndCall(address,address,bytes)` is present, and the third argument must
  16. * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
  17. * during an upgrade.
  18. */
  19. string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
  20. /**
  21. * @dev Sets the initial owner who can perform upgrades.
  22. */
  23. constructor(address initialOwner) Ownable(initialOwner) {}
  24. /**
  25. * @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation.
  26. * See {TransparentUpgradeableProxy-_dispatchUpgradeToAndCall}.
  27. *
  28. * Requirements:
  29. *
  30. * - This contract must be the admin of `proxy`.
  31. * - If `data` is empty, `msg.value` must be zero.
  32. */
  33. function upgradeAndCall(
  34. ITransparentUpgradeableProxy proxy,
  35. address implementation,
  36. bytes memory data
  37. ) public payable virtual onlyOwner {
  38. proxy.upgradeToAndCall{value: msg.value}(implementation, data);
  39. }
  40. }