ProxyAdmin.sol 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 {ITransparentUpgradeableProxy, TransparentUpgradeableProxy} 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 Sets the initial owner who can perform upgrades.
  13. */
  14. constructor(address initialOwner) Ownable(initialOwner) {}
  15. /**
  16. * @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}.
  17. *
  18. * Requirements:
  19. *
  20. * - This contract must be the admin of `proxy`.
  21. */
  22. function upgrade(ITransparentUpgradeableProxy proxy, address implementation) public virtual onlyOwner {
  23. proxy.upgradeTo(implementation);
  24. }
  25. /**
  26. * @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See
  27. * {TransparentUpgradeableProxy-upgradeToAndCall}.
  28. *
  29. * Requirements:
  30. *
  31. * - This contract must be the admin of `proxy`.
  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. }