SchedulerGovernance.sol 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: Apache 2
  2. pragma solidity ^0.8.0;
  3. import "./SchedulerState.sol";
  4. import "./SchedulerErrors.sol";
  5. /**
  6. * @dev `SchedulerGovernance` defines governance capabilities for the Pulse contract.
  7. */
  8. abstract contract SchedulerGovernance is SchedulerState {
  9. event NewAdminProposed(address oldAdmin, address newAdmin);
  10. event NewAdminAccepted(address oldAdmin, address newAdmin);
  11. event SingleUpdateKeeperFeeSet(uint oldFee, uint newFee);
  12. event MinimumBalancePerFeedSet(uint oldBalance, uint newBalance);
  13. /**
  14. * @dev Returns the address of the proposed admin.
  15. */
  16. function proposedAdmin() public view virtual returns (address) {
  17. return _state.proposedAdmin;
  18. }
  19. /**
  20. * @dev Returns the address of the current admin.
  21. */
  22. function getAdmin() external view returns (address) {
  23. return _state.admin;
  24. }
  25. /**
  26. * @dev Proposes a new admin for the contract. Replaces the proposed admin if there is one.
  27. * Can only be called by either admin or owner.
  28. */
  29. function proposeAdmin(address newAdmin) public virtual {
  30. require(newAdmin != address(0), "newAdmin is zero address");
  31. _authorizeAdminAction();
  32. _state.proposedAdmin = newAdmin;
  33. emit NewAdminProposed(_state.admin, newAdmin);
  34. }
  35. /**
  36. * @dev The proposed admin accepts the admin transfer.
  37. */
  38. function acceptAdmin() external {
  39. if (msg.sender != _state.proposedAdmin) revert Unauthorized();
  40. address oldAdmin = _state.admin;
  41. _state.admin = msg.sender;
  42. _state.proposedAdmin = address(0);
  43. emit NewAdminAccepted(oldAdmin, msg.sender);
  44. }
  45. /**
  46. * @dev Authorization check for admin actions
  47. * Must be implemented by the inheriting contract.
  48. */
  49. function _authorizeAdminAction() internal virtual;
  50. /**
  51. * @dev Set the keeper fee for single updates in Wei.
  52. * Calls {_authorizeAdminAction}.
  53. * Emits a {SingleUpdateKeeperFeeSet} event.
  54. */
  55. function setSingleUpdateKeeperFeeInWei(uint128 newFee) external {
  56. _authorizeAdminAction();
  57. uint oldFee = _state.singleUpdateKeeperFeeInWei;
  58. _state.singleUpdateKeeperFeeInWei = newFee;
  59. emit SingleUpdateKeeperFeeSet(oldFee, newFee);
  60. }
  61. /**
  62. * @dev Set the minimum balance required per feed in a subscription.
  63. * Calls {_authorizeAdminAction}.
  64. * Emits a {MinimumBalancePerFeedSet} event.
  65. */
  66. function setMinimumBalancePerFeed(uint128 newMinimumBalance) external {
  67. _authorizeAdminAction();
  68. uint oldBalance = _state.minimumBalancePerFeed;
  69. _state.minimumBalancePerFeed = newMinimumBalance;
  70. emit MinimumBalancePerFeedSet(oldBalance, newMinimumBalance);
  71. }
  72. }