PirexEthValidators.sol
General Overview
The PirexEthValidators.sol
contract is a central component in managing Ethereum validators for the Beacon Chain deposit contract. It facilitates a wide range of functions including setting contract addresses, managing validator queues, initiating deposits, and handling rewards and slashing operations. The contract also allows for validator management through various queues with capabilities to add, swap, remove, or clear validators.
Additionally, it addresses the redemption and rewarding of validators with upxEth tokens. The roles defined within the contract, such as GOVERNANCE_ROLE
, KEEPER_ROLE
, and DEFAULT_ADMIN_ROLE
, are important for these activities, ensuring a seamless and secure operation of validators within the protocol.
GOVERNANCE_ROLE
- manages the validator queue, sets fee parameters, and controls the pausing of deposits to the Beacon Chain deposit contract.KEEPER_ROLE
- responsible for harvesting rewards, updating the status of validators when they are slashed, and topping up the validator's stake if the active balance falls below the effective balance.DEFAULT_ADMIN_ROLE
- sets external contract addresses.
Technical Overview
Inherits: ReentrancyGuard, AccessControlDefaultAdminRules, IPirexEth
Author: redactedcartel.finance
State Variables
DENOMINATOR
KEEPER_ROLE
GOVERNANCE_ROLE
_NOT_PAUSED
_PAUSED
beaconChainDepositContract
preDepositAmount
DEPOSIT_SIZE
withdrawalCredentials
buffer
maxBufferSize
maxBufferSizePct
maxProcessedValidatorCount
upxEth
pxEth
autoPxEth
oracleAdapter
rewardRecipient
depositEtherPaused
pendingDeposit
_initializedValidators
_stakingValidators
pendingWithdrawal
outstandingRedemptions
batchId
endBlock
status
batchIdToValidator
burnerAccounts
Functions
onlyRewardRecipient
onlyWhenDepositEtherPaused
constructor
Parameters
Name | Type | Description |
---|---|---|
_pxEth | address | PxETH contract address |
_admin | address | Admin address |
_beaconChainDepositContract | address | The address of the deposit precompile |
_upxEth | address | UpxETH address |
_depositSize | uint256 | Amount of ETH to stake |
_preDepositAmount | uint256 | Amount of ETH for pre-deposit |
_initialDelay | uint48 | Delay required to schedule the acceptance of a access control transfer started |
getInitializedValidatorCount
Get the number of initialized validators
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Number of initialised validators |
getStakingValidatorCount
Get the number of staking validators
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Number of staking validators |
getInitializedValidatorAt
Get the initialized validator info at the specified index
Parameters
Name | Type | Description |
---|---|---|
_i | uint256 | Index |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | Public key |
<none> | bytes | Withdrawal credentials |
<none> | bytes | Signature |
<none> | bytes32 | Deposit data root hash |
<none> | address | pxETH receiver |
getStakingValidatorAt
Get the staking validator info at the specified index
Parameters
Name | Type | Description |
---|---|---|
_i | uint256 | Index |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | Public key |
<none> | bytes | Withdrawal credentials |
<none> | bytes | Signature |
<none> | bytes32 | Deposit data root hash |
<none> | address | pxETH receiver |
setContract
Set a contract address
Parameters
Name | Type | Description |
---|---|---|
c | DataTypes.Contract | Contract |
contractAddress | address | Contract address |
setMaxBufferSizePct
Set the percentage that will be applied to total supply of pxEth to determine maxBufferSize
Parameters
Name | Type | Description |
---|---|---|
_pct | uint256 | Max buffer size percentage |
setMaxProcessedValidatorCount
Set maximum count of processed validator in a _deposit call
Parameters
Name | Type | Description |
---|---|---|
_count | uint256 | Max processed count |
togglePauseDepositEther
Toggle allowing depositing ETH to validators
toggleBurnerAccounts
Approve/revoke addresses as burner accounts
Parameters
Name | Type | Description |
---|---|---|
_accounts | address[] | Addresses |
_state | bool | Burner acount state |
dissolveValidator
Update validator to Dissolve once Oracle updates on ETH being released
Parameters
Name | Type | Description |
---|---|---|
_pubKey | bytes | Public key of the validator |
slashValidator
Update validator state to be slashed
Parameters
Name | Type | Description |
---|---|---|
_pubKey | bytes | Public key of the validator |
_removeIndex | uint256 | Index of validator to be slashed |
_amount | uint256 | ETH amount released from Beacon chain |
_unordered | bool | Whether remove from staking validator queue in order or not |
_useBuffer | bool | whether to use buffer to compensate the loss |
_burnerAccounts | DataTypes.BurnerAccount[] | Burner accounts |
addInitializedValidators
Add multiple synced validators in the queue to be ready for staking
Parameters
Name | Type | Description |
---|---|---|
_validators | DataTypes.Validator[] | Validators details |
swapInitializedValidator
Swap initialized validators specified by the indexes
Parameters
Name | Type | Description |
---|---|---|
_fromIndex | uint256 | From index |
_toIndex | uint256 | To index |
popInitializedValidator
Pop initialized validators
Parameters
Name | Type | Description |
---|---|---|
_times | uint256 | Count of pop operations |
removeInitializedValidator
Remove initialized validators
Parameters
Name | Type | Description |
---|---|---|
_pubKey | bytes | |
_removeIndex | uint256 | Remove index |
_unordered | bool | Whether unordered or ordered |
clearInitializedValidator
Clear initialized validators
depositPrivileged
Trigger deposit to the ETH 2.0 deposit contract when allowed
topUpStake
Topup ETH to the validator if current balance drops below effective balance
Parameters
Name | Type | Description |
---|---|---|
_pubKey | bytes | Validator public key |
_signature | bytes | A BLS12-381 signature |
_depositDataRoot | bytes32 | The SHA-256 hash of the SSZ-encoded DepositData object. |
_topUpAmount | uint256 | Top-up amount |
_useBuffer | bool | Whether to use buffer |
_burnerAccounts | DataTypes.BurnerAccount[] | Burner accounts |
harvest
Harvest and mint staking rewards when available
Parameters
Name | Type | Description |
---|---|---|
_endBlock | uint256 | Block until which ETH rewards is computed |
_mintPxEth
Internal method for minting pxETH
Parameters
Name | Type | Description |
---|---|---|
_account | address | Account |
_amount | uint256 | Amount |
_burnPxEth
Internal method for burning pxETH
Parameters
Name | Type | Description |
---|---|---|
_account | address | Account |
_amount | uint256 | Amount |
_deposit
Spin up validator if sufficient ETH is available
_addPendingDeposit
Add pending deposit and spin up validator if required ETH available
Parameters
Name | Type | Description |
---|---|---|
_amount | uint256 | ETH asset amount |
_initiateRedemption
Internal handler for validator related logic on redemption
Parameters
Name | Type | Description |
---|---|---|
_pxEthAmount | uint256 | Amount of pxETH |
_receiver | address | Receiver for upxETH |
_shouldTriggerValidatorExit | bool | Whether initiate partial redemption with validator exit or not |