-
Notifications
You must be signed in to change notification settings - Fork 300
feat(pulse): add governance instructions, admin transfer capability #2608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
target_chains/ethereum/contracts/contracts/pulse/SchedulerGovernance.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// SPDX-License-Identifier: Apache 2 | ||
pragma solidity ^0.8.0; | ||
|
||
import "./SchedulerState.sol"; | ||
import "./SchedulerErrors.sol"; | ||
|
||
/** | ||
* @dev `SchedulerGovernance` defines governance capabilities for the Pulse contract. | ||
*/ | ||
abstract contract SchedulerGovernance is SchedulerState { | ||
event NewAdminProposed(address oldAdmin, address newAdmin); | ||
event NewAdminAccepted(address oldAdmin, address newAdmin); | ||
event SingleUpdateKeeperFeeSet(uint oldFee, uint newFee); | ||
event MinimumBalancePerFeedSet(uint oldBalance, uint newBalance); | ||
|
||
/** | ||
* @dev Returns the address of the proposed admin. | ||
*/ | ||
function proposedAdmin() public view virtual returns (address) { | ||
return _state.proposedAdmin; | ||
} | ||
|
||
/** | ||
* @dev Returns the address of the current admin. | ||
*/ | ||
function getAdmin() external view returns (address) { | ||
return _state.admin; | ||
} | ||
|
||
/** | ||
* @dev Proposes a new admin for the contract. Replaces the proposed admin if there is one. | ||
* Can only be called by either admin or owner. | ||
*/ | ||
function proposeAdmin(address newAdmin) public virtual { | ||
require(newAdmin != address(0), "newAdmin is zero address"); | ||
|
||
_authorizeAdminAction(); | ||
|
||
_state.proposedAdmin = newAdmin; | ||
emit NewAdminProposed(_state.admin, newAdmin); | ||
} | ||
|
||
/** | ||
* @dev The proposed admin accepts the admin transfer. | ||
*/ | ||
function acceptAdmin() external { | ||
if (msg.sender != _state.proposedAdmin) revert Unauthorized(); | ||
|
||
address oldAdmin = _state.admin; | ||
_state.admin = msg.sender; | ||
|
||
_state.proposedAdmin = address(0); | ||
emit NewAdminAccepted(oldAdmin, msg.sender); | ||
} | ||
|
||
/** | ||
* @dev Authorization check for admin actions | ||
* Must be implemented by the inheriting contract. | ||
*/ | ||
function _authorizeAdminAction() internal virtual; | ||
|
||
/** | ||
* @dev Set the keeper fee for single updates in Wei. | ||
* Calls {_authorizeAdminAction}. | ||
* Emits a {SingleUpdateKeeperFeeSet} event. | ||
*/ | ||
function setSingleUpdateKeeperFeeInWei(uint128 newFee) external { | ||
_authorizeAdminAction(); | ||
|
||
uint oldFee = _state.singleUpdateKeeperFeeInWei; | ||
_state.singleUpdateKeeperFeeInWei = newFee; | ||
|
||
emit SingleUpdateKeeperFeeSet(oldFee, newFee); | ||
} | ||
|
||
/** | ||
* @dev Set the minimum balance required per feed in a subscription. | ||
* Calls {_authorizeAdminAction}. | ||
* Emits a {MinimumBalancePerFeedSet} event. | ||
*/ | ||
function setMinimumBalancePerFeed(uint128 newMinimumBalance) external { | ||
_authorizeAdminAction(); | ||
|
||
uint oldBalance = _state.minimumBalancePerFeed; | ||
_state.minimumBalancePerFeed = newMinimumBalance; | ||
|
||
emit MinimumBalancePerFeedSet(oldBalance, newMinimumBalance); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better if you do this check regardless. Otherwise I can increase feeds and deactivate, and then later activate it to bypass it right?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeahh was debating this, but one thing i was thinking was we shouldn't enforce this for people trying to deactivate or reduce their feeds. maybe they are low on balance and trying to reduce their burn rate. ultimately the minimum balance thing serves 2 purposes: disincentivize the attack vector of flooding the system with subscriptions, and help the user maintain enough balance in their account to ensure uninterrupted operation.
also, we do enforce the check when activating, so the scenario you mentioned wouldn't be a problem.