ProxyAdmin.sol 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts v4.4.1 (proxy/transparent/ProxyAdmin.sol)
  3. pragma solidity ^0.8.0;
  4. import "./TransparentUpgradeableProxy.sol";
  5. import "../../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 Changes the admin of `proxy` to `newAdmin`.
  13. *
  14. * Requirements:
  15. *
  16. * - This contract must be the current admin of `proxy`.
  17. */
  18. function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public virtual onlyOwner {
  19. proxy.changeAdmin(newAdmin);
  20. }
  21. /**
  22. * @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}.
  23. *
  24. * Requirements:
  25. *
  26. * - This contract must be the admin of `proxy`.
  27. */
  28. function upgrade(TransparentUpgradeableProxy proxy, address implementation) public virtual onlyOwner {
  29. proxy.upgradeTo(implementation);
  30. }
  31. /**
  32. * @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See
  33. * {TransparentUpgradeableProxy-upgradeToAndCall}.
  34. *
  35. * Requirements:
  36. *
  37. * - This contract must be the admin of `proxy`.
  38. */
  39. function upgradeAndCall(
  40. TransparentUpgradeableProxy proxy,
  41. address implementation,
  42. bytes memory data
  43. ) public payable virtual onlyOwner {
  44. proxy.upgradeToAndCall{value: msg.value}(implementation, data);
  45. }
  46. }