NodeOperatorsRegistry
The NodeOperatorRegistry contract is the core contract that allows node operators to participate in the Lido staking protocol. Node Operators participate on the protocol as validators and get rewarded for their work. A Node Operator gets added to the Registry by the DAO. Validator reward is distributed evenly amongst all active operators. The contract contains a list of operators, their public keys, and the logic for managing their state.
Roles
The NodeOperatoRegistry contract has the following roles
Name | Description |
---|---|
DAO_ROLE | DAO role |
PAUSE_ROLE | Allows to pasuse the contract |
UNPAUSE_ROLE | Allows to unpasuse the contract |
ADD_NODE_OPERATOR_ROLE | Allows to add new node operator the contract |
REMOVE_NODE_OPERATOR_ROLE | Allows to remove a node operator the contract |
Structs
NodeOperatorStatus
A node operator statuses
Name | Description |
---|---|
INACTIVE | When the node operator is INACTIVE |
ACTIVE | When the node operator is ACTIVE |
JAILED | When the node operator is JAILED |
EJECTED | When the node operator is EJECTED |
UNSTAKED | When the node operator is UNSTAKED |
enum NodeOperatorRegistryStatus {
INACTIVE,
ACTIVE,
JAILED,
EJECTED,
UNSTAKED
}
FullNodeOperatorRegistry
Name | Description |
---|---|
validatorId | Polygon validator id |
commissionRate | The commission rate applied by the validator on Polygon stake manager |
validatorShare | The validator share address |
rewardAddress | The validator reward address |
delegation | The validator delegation status on Polygon stake manager |
status | The validator status |
struct FullNodeOperatorRegistry {
uint256 validatorId;
uint256 commissionRate;
address validatorShare;
address rewardAddress;
bool delegation;
NodeOperatorRegistryStatus status;
}
ValidatorData
The node operator data
Name | Description |
---|---|
validatorShare | The validator share address of the validator |
rewardAddress | The validator reward address |
struct ValidatorData {
address validatorShare;
address rewardAddress;
}
View Methods
stakeManager
Polygon stake manager address.
function stakeManager() view returns (address)
version
Contract version.
function version() view returns (string memory)
stMATIC
stMATIC address.
function stMATIC() view returns (address)
DAO_ROLE
Role bytes.
function DAO_ROLE() view returns (bytes32)
PAUSE_ROLE
Role bytes.
function PAUSE_ROLE() view returns (bytes32)
UNPAUSE_ROLE()
Role bytes.
function UNPAUSE_ROLE() view returns (bytes32)
ADD_NODE_OPERATOR_ROLE()
Role bytes.
function ADD_NODE_OPERATOR_ROLE() view returns (bytes32)
REMOVE_NODE_OPERATOR_ROLE()
Role bytes.
function REMOVE_NODE_OPERATOR_ROLE() view returns (bytes32)
DISTANCE_THRESHOLD_PERCENTS()
The min percent to recognize the system as balanced.
function DISTANCE_THRESHOLD_PERCENTS() view returns (uint256)
MAX_WITHDRAW_PERCENTAGE_PER_REBALANCE()
The maximum percentage withdraw per system rebalance.
function MAX_WITHDRAW_PERCENTAGE_PER_REBALANCE() view returns (uint256)
MIN_REQUEST_WITHDRAW_RANGE_PERCENTS()
Allows to increse the number of validators to request withdraw from when the system is balanced.
function MIN_REQUEST_WITHDRAW_RANGE_PERCENTS() view returns (uint8)
validatorIds()
Get validator id.
Parameters:
Name | Type | Description |
---|---|---|
index | uint256 | array index |
function validatorIds(uint256 index) view returns (uint256)
Returns:
Name | Type | Description |
---|---|---|
validatorId | uint256 | validator id |
validatorIdToRewardAddress()
Mapping of all owners with node operator id. Mapping is used to be able to extend the struct.
Parameters:
Name | Type | Description |
---|---|---|
validatorId | uint256 | validator id |
function validatorIdToRewardAddress(uint256 validatorId) view returns (address)
Returns:
Name | Type | Description |
---|---|---|
rewardAddress | address | node operator reward address. |
validatorRewardAddressToId()
Mapping of validator reward address to validator Id. Mapping is used to be able to extend the struct.
Parameters:
Name | Type | Description |
---|---|---|
rewardAddress | address | node operator reward address. |
function validatorRewardAddressToId(address rewardAddress) view returns (uint256)
Returns:
Name | Type | Description |
---|---|---|
validatorId | uint256 | validator id |
getNodeOperator()
Returns the node operator based on the operator's reward address.
Parameters:
Name | Type | Description |
---|---|---|
_rewardAddress | address | Reward address of the node operator owner |
function getNodeOperator(address _rewardAddress)
external
view
returns (FullNodeOperatorRegistry memory)
Returns:
Name | Type | Description |
---|---|---|
nodeOperator | FullNodeOperatorRegistry | Node operator data. |
getNodeOperator()
Returns the node operator based on the operator's validator id.
Parameters:
Name | Type | Description |
---|---|---|
_operatorId | uint256 | Id of the operator |
function getNodeOperator(uint256 _validatorId)
external
view
returns (FullNodeOperatorRegistry memory)
Returns:
Name | Type | Description |
---|---|---|
nodeOperator | FullNodeOperatorRegistry | Node operator data. |
getStats()
Returns a list all the node operator statuses in the system.
function getStats()
external
view
override
returns (
uint256 inactiveNodeOperator,
uint256 activeNodeOperator,
uint256 jailedNodeOperator,
uint256 ejectedNodeOperator,
uint256 unstakedNodeOperator
)
Returns:
Name | Type | Description |
---|---|---|
inactiveNodeOperator | uint256 | the number of inactive operators. |
activeNodeOperator | uint256 | the number of active operators. |
jailedNodeOperator | uint256 | the number of jailed operators. |
ejectedNodeOperator | uint256 | the number of ejected operators. |
unstakedNodeOperator | uint256 | the number of unstaked operators. |
listDelegatedNodeOperators()
Returns a list all the ACTIVE operators
function listDelegatedNodeOperators()
external
view
override
returns (ValidatorData[] memory, uint256)
Returns:
Name | Type | Description |
---|---|---|
activeNodeOperators | ValidatorData[] | a list of ACTIVE node operator. |
totalActiveNodeOperators | uint256 | total number of ACTIVE node operators. |
listWithdrawNodeOperators()
Returns a list all the operators on the stakeManager that can be withdrawn from this includes ACTIVE, JAILED, ejected, and UNSTAKED operators.
function listWithdrawNodeOperators()
external
view
override
returns (ValidatorData[] memory nodeOperators, uint256 totalNodeOperators)
Returns:
Name | Type | Description |
---|---|---|
nodeOperators | ValidatorData[] | a list of ACTIVE, JAILED or UNSTAKED node operator. |
totalNodeOperators | uint256 | total number of node operators. |
getValidatorsDelegationAmount()
Calculate how total buffered should be delegated between the active validators, depending on if the system is balanced or not. If validators are in EJECTED or UNSTAKED status the function will revert.
Parameters:
Name | Type | Description |
---|---|---|
amountToDelegate | uint256 | The total that can be delegated. |
function getValidatorsDelegationAmount(uint256 amountToDelegate)
external
view
returns (
ValidatorData[] memory validators,
uint256 totalActiveNodeOperator,
uint256[] memory operatorRatios,
uint256 totalRatio
);
Returns:
Name | Type | Description |
---|---|---|
validators | ValidatorData[] | all active node operators. |
totalActiveNodeOperator | uint256 | total active node operators. |
operatorRatios | uint256[] | is a list of operator's ratio. |
totalRatio | uint256 | the total ratio. If ZERO that means the system is balanced. |
getValidatorsRebalanceAmount()
Calculate how the system could be rebalanced depending on the current buffered tokens. If validators are in EJECTED or UNSTAKED status the function will revert. If the system is balanced the function will revert.
Parameters:
Name | Type | Description |
---|---|---|
_totalBuffered | uint256 | totalBuffered MATIC amount in the StMatic contract |
function getValidatorsRebalanceAmount(uint256 totalBuffered)
external
view
returns (
ValidatorData[] memory validators,
uint256 totalActiveNodeOperator,
uint256[] memory operatorRatios,
uint256 totalRatio,
uint256 totalToWithdraw
);
Returns:
Name | Type | Description |
---|---|---|
validators | ValidatorData[] | all active node operators. |
totalActiveNodeOperator | uint256 | total active node operators. |
operatorRatios | uint256[] | is a list of operator's ratio. |
totalRatio | uint256 | the total ratio. If ZERO that means the system is balanced. |
totalToWithdraw | uint256 | the total amount to withdraw. |
getValidatorsRequestWithdraw()
Calculate the validators to request withdrawal from depending on whether the system is balanced or not.
Parameters:
Name | Type | Description |
---|---|---|
_withdrawAmount | uint256 | amount to withdraw from validator |
function getValidatorsRequestWithdraw(uint256 _withdrawAmount)
external
view
returns (
ValidatorData[] memory validators,
uint256 totalDelegated,
uint256 bigNodeOperatorLength,
uint256[] memory bigNodeOperatorIds,
uint256 smallNodeOperatorLength,
uint256[] memory smallNodeOperatorIds,
uint256[] memory operatorAmountCanBeRequested,
uint256 totalValidatorToWithdrawFrom
);
Returns:
Name | Type | Description |
---|---|---|
validators | ValidatorData[] | all node operators. |
totalDelegated | uint256 | total amount delegated. |
bigNodeOperatorLength | uint256 | number of ids bigNodeOperatorIds. |
bigNodeOperatorIds | uint256[] | stores the ids of node operators that amount delegated to it is greater than the average delegation. |
smallNodeOperatorLength | uint256 | number of ids smallNodeOperatorIds. |
smallNodeOperatorIds | uint256[] | stores the ids of node operators that amount delegated to it is less than the average delegation. |
operatorAmountCanBeRequested | uint256[] | amount that can be requested from a spécific validator when the system is not balanced. |
totalValidatorToWithdrawFrom | uint256 | the number of validator to withdraw from when the system is balanced. |
getNodeOperatorStatus()
Returns a node operator status.
Parameters:
Name | Type | Description |
---|---|---|
_validatorId | uint256 | validator id |
function getNodeOperatorStatus(uint256 _validatorId)
external
view
override
returns (NodeOperatorRegistryStatus operatorStatus)
Returns:
Name | Type | Description |
---|---|---|
operatorStatus | enum | The validator status |
getValidatorIds()
Returns a list of all validator ids in the system.
function getValidatorIds()
external
view
override
returns (uint256[] memory)
Returns:
Name | Type | Description |
---|---|---|
validatorIds | Array<uint256> | The list of all validator ids in the protocol |
getProtocolStats()
Returns the protocol stats.
function getProtocolStats()
external
view
returns (
bool isBalanced,
uint256 distanceThreshold,
uint256 minAmount,
uint256 maxAmount
);
Returns:
Name | Type | Description |
---|---|---|
isBalanced | boolean | if the system is balanced or not |
distanceThreshold | uint256 | the distance threshold between the big and small amount deposit in validators |
minAmount | uint256 | The min amount delegated to a validator |
maxAmount | uint256 | The max amount delegated to a validator |
Methods
exitNodeOperatorRegistry()
Allows the Node Operator to exit the Registry by itself
function exitNodeOperatorRegistry() external override
removeInvalidNodeOperator()
Remove a node operator from the system if it fails to meet certain conditions:
- If the commission of the Node Operator is less than the standard commission.
- If the Node Operator is either Unstaked or Ejected.
function removeInvalidNodeOperator(uint256 _validatorId)
external
override
whenNotPaused
Parameters:
Name | Type | Description |
---|---|---|
_validatorId | uint256 | validator id |
setRewardAddress()
Update the reward address of a Node Operator.
function setRewardAddress(address _newRewardAddress) external override
setOperatorRewardAddress()
Allows operator's owner to update reward address
function setOperatorRewardAddress(address _rewardAddress)
external
Parameters:
Name | Type | Description |
---|---|---|
_rewardAddress | address | New reward address |
pasue()
Allows an authorized user with PAUSE ROLE
to pause the contract.
function pause() external onlyRole(PAUSE_ROLE);
unpasue()
Allows an authorized user with UNPAUSE ROLE
to unpause the contract.
function unpause() external onlyRole(PAUSE_ROLE);
DAO Methods
These methods can be called by DAO-only roles.
addNodeOperator()
Allows the DAO to add a new node operator to the system.
function addNodeOperator(uint256 _validatorId, address _rewardAddress)
external
override
userHasRole(DAO_ROLE)
Parameters:
Name | Type | Description |
---|---|---|
_validatorId | uint256 | Validator Id |
_rewardAddress | address | Reward address which receives stMATIC rewards for this operator |
removeNodeOperator()
Allows the DAO to remove a node operator from the system and withdraw total delegated tokens to it.
function removeNodeOperator(uint256 _validatorId)
external
override
userHasRole(DAO_ROLE)
Parameters:
Name | Type | Description |
---|---|---|
_validatorId | uint256 | Validator Id |
setStMaticAddress()
Allows the DAO to set the StMATIC contract address.
function setStMaticAddress(address _newStMatic)
external
userHasRole(DAO_ROLE)
Parameters:
Name | Type | Description |
---|---|---|
_newStMatic | address | New stMATIC address |
setDistanceThreshold()
Allows the DAO to set the distance threshold for balancing the system.
function setDistanceThreshold(uint256 _newDistanceThreshold)
external
override
userHasRole(DAO_ROLE)
Parameters:
Name | Type | Description |
---|---|---|
_newDistanceThreshold | uint256 | New distance threshold |
setMinRequestWithdrawRange()
Allows the DAO to set the minimum request withdraw range to keep the system balanced
function setMinRequestWithdrawRange(uint8 _newMinRequestWithdrawRange)
external
override
userHasRole(DAO_ROLE)
Parameters:
Name | Type | Description |
---|---|---|
_newMinRequestWithdrawRange | uint8 | New min request withdraw range threshold |
setMaxWithdrawPercentagePerRebalance()
Allows the DAO to set the maximum withdraw percentage per balance of each validator
function setMaxWithdrawPercentagePerRebalance(uint256 _newMaxWithdrawPercentagePerRebalance)
external
override
userHasRole(DAO_ROLE)
Parameters:
Name | Type | Description |
---|---|---|
__newMaxWithdrawPercentagePerRebalance | uint8 | New max withdraw percentage per baalnce |
setVersion()
Allows the DAO to set the contract version
function setVersion(string memory _newVersion) external userHasRole(DAO_ROLE)
Parameters:
Name | Type | Description |
---|---|---|
_newVersion | string | New version |