ProxyAdmin.sol 1.8 KB

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