PulseUpgradeable.sol 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: Apache 2
  2. pragma solidity ^0.8.0;
  3. import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
  4. import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
  5. import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
  6. import "./Pulse.sol";
  7. contract PulseUpgradeable is
  8. Initializable,
  9. Ownable2StepUpgradeable,
  10. UUPSUpgradeable,
  11. Pulse
  12. {
  13. event ContractUpgraded(
  14. address oldImplementation,
  15. address newImplementation
  16. );
  17. function initialize(
  18. address owner,
  19. address admin,
  20. uint96 pythFeeInWei,
  21. address pythAddress,
  22. address defaultProvider,
  23. bool prefillRequestStorage,
  24. uint32 exclusivityPeriodSeconds
  25. ) external initializer {
  26. require(owner != address(0), "owner is zero address");
  27. require(admin != address(0), "admin is zero address");
  28. __Ownable_init();
  29. __UUPSUpgradeable_init();
  30. Pulse._initialize(
  31. admin,
  32. pythFeeInWei,
  33. pythAddress,
  34. defaultProvider,
  35. prefillRequestStorage,
  36. exclusivityPeriodSeconds
  37. );
  38. _transferOwnership(owner);
  39. }
  40. /// @custom:oz-upgrades-unsafe-allow constructor
  41. constructor() initializer {}
  42. function _authorizeUpgrade(address) internal override onlyOwner {}
  43. function upgradeTo(address newImplementation) external override onlyProxy {
  44. address oldImplementation = _getImplementation();
  45. _authorizeUpgrade(newImplementation);
  46. _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
  47. emit ContractUpgraded(oldImplementation, _getImplementation());
  48. }
  49. function upgradeToAndCall(
  50. address newImplementation,
  51. bytes memory data
  52. ) external payable override onlyProxy {
  53. address oldImplementation = _getImplementation();
  54. _authorizeUpgrade(newImplementation);
  55. _upgradeToAndCallUUPS(newImplementation, data, true);
  56. emit ContractUpgraded(oldImplementation, _getImplementation());
  57. }
  58. function version() public pure returns (string memory) {
  59. return "1.0.0";
  60. }
  61. }