-
Notifications
You must be signed in to change notification settings - Fork 96
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
add admin only functions #2512
add admin only functions #2512
Changes from 1 commit
5d44764
dbcfeb3
9edcc69
2feda04
5dcb697
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,15 @@ contract StakeTable is AbstractStakeTable { | |
// Error raised when zero point keys are provided | ||
error NoKeyChange(); | ||
|
||
/// Error raised when the caller is not the admin | ||
error Unauthorized(); | ||
|
||
/// Error raised when the light client address is invalid | ||
error InvalidAddress(); | ||
|
||
/// Error raised when the value is invalid | ||
error InvalidValue(); | ||
|
||
/// Mapping from a hash of a BLS key to a node struct defined in the abstract contract. | ||
mapping(address account => Node node) public nodes; | ||
|
||
|
@@ -92,7 +101,17 @@ contract StakeTable is AbstractStakeTable { | |
|
||
uint64 public maxChurnRate; | ||
|
||
constructor(address _tokenAddress, address _lightClientAddress, uint64 churnRate) { | ||
uint256 public minStakeAmount; | ||
|
||
address public admin; | ||
|
||
/// TODO change constructor to initialize function when we make the contract upgradeable | ||
constructor( | ||
address _tokenAddress, | ||
address _lightClientAddress, | ||
uint64 churnRate, | ||
uint256 _minStakeAmount | ||
) { | ||
tokenAddress = _tokenAddress; | ||
lightClient = LightClient(_lightClientAddress); | ||
|
||
|
@@ -105,6 +124,10 @@ contract StakeTable is AbstractStakeTable { | |
// It is not possible to exit during the first epoch. | ||
firstAvailableExitEpoch = 1; | ||
_numPendingExits = 0; | ||
|
||
minStakeAmount = _minStakeAmount; | ||
|
||
admin = msg.sender; | ||
} | ||
|
||
/// @dev Computes a hash value of some G2 point. | ||
|
@@ -269,7 +292,7 @@ contract StakeTable is AbstractStakeTable { | |
BN254.G1Point memory blsSig, | ||
uint64 validUntilEpoch | ||
) external override { | ||
uint256 fixedStakeAmount = minStakeAmount(); | ||
uint256 fixedStakeAmount = minStakeAmount; | ||
|
||
// Verify that the sender amount is the minStakeAmount | ||
if (amount < fixedStakeAmount) { | ||
|
@@ -392,6 +415,8 @@ contract StakeTable is AbstractStakeTable { | |
/// @notice Request to exit from the stake table, not immediately withdrawable! | ||
/// | ||
/// @dev TODO modify this according to the current spec | ||
/// @dev TODO add a function to check if the node is eligible to exit | ||
/// @dev TODO discuss if we want an admin administered emergency exit | ||
function requestExit() external override { | ||
Node memory node = nodes[msg.sender]; | ||
|
||
|
@@ -524,10 +549,43 @@ contract StakeTable is AbstractStakeTable { | |
emit UpdatedConsensusKeys(msg.sender, node.blsVK, node.schnorrVK); | ||
} | ||
|
||
/// @notice Minimum stake amount | ||
/// @return Minimum stake amount | ||
/// TODO: This value should be a variable modifiable by admin | ||
function minStakeAmount() public pure returns (uint256) { | ||
return 10 ether; | ||
/// @notice Update the admin | ||
/// @dev The admin cannot be set to the zero address | ||
/// @param _admin The new admin | ||
function updateAdmin(address _admin) external { | ||
if (msg.sender != admin) revert Unauthorized(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it a conscientious decision not to inherit from an existing contract with access control? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you know what, i was thinking through it, wondered if this was more gas efficient There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. switched to Ownable here dbcfeb3 |
||
if (_admin == address(0)) revert InvalidAddress(); | ||
admin = _admin; | ||
emit AdminUpdated(admin); | ||
} | ||
|
||
/// @notice Update the min stake amount | ||
/// @dev The min stake amount cannot be set to zero | ||
/// @param _minStakeAmount The new min stake amount | ||
function updateMinStakeAmount(uint256 _minStakeAmount) external { | ||
if (msg.sender != admin) revert Unauthorized(); | ||
if (_minStakeAmount == 0) revert InvalidValue(); | ||
minStakeAmount = _minStakeAmount; | ||
emit MinStakeAmountUpdated(minStakeAmount); | ||
} | ||
|
||
/// @notice Update the max churn rate | ||
/// @dev The max churn rate cannot be set to zero | ||
/// @param _maxChurnRate The new max churn rate | ||
function updateMaxChurnRate(uint64 _maxChurnRate) external { | ||
if (msg.sender != admin) revert Unauthorized(); | ||
if (_maxChurnRate == 0) revert InvalidValue(); | ||
maxChurnRate = _maxChurnRate; | ||
emit MaxChurnRateUpdated(maxChurnRate); | ||
} | ||
|
||
/// @notice Update the light client address | ||
/// @dev The light client address cannot be set to the zero address | ||
/// @param _lightClientAddress The new light client address | ||
function updateLightClientAddress(address _lightClientAddress) external { | ||
if (msg.sender != admin) revert Unauthorized(); | ||
if (_lightClientAddress == address(0)) revert InvalidAddress(); | ||
lightClient = LightClient(_lightClientAddress); | ||
emit LightClientAddressUpdated(_lightClientAddress); | ||
} | ||
} |
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.
Why do we have this
amount
variable if we are not using it? Everyone puts in the same amount (minStakeAmount
) when callingregister()
.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.
thanks for pointing this out, confirming with @veilgets. Are we doing a fixedAmount and thus the amount they stake has to be that fixedAmount or are we doing a variable amount that must be >= some minAmount?
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.
we're choosing to go with a variable stake, so updated here 2feda04