ValidatorManagerLib

Git Source

Library for managing validator storage

*This library is used by the Infrared contract for:

  • Adding and removing validators (to the set of validators and distributor contract)
  • Queuing/Activating Boosts and Drop/Activate Boosts in BGT contract: https://github.com/berachain/contracts-monorepo/blob/main/src/pol/BGT.sol
  • Getting the number of validators
  • Checking if validator is an Infrared validator*

Ownership of Operator rewards is tied to the number of validators an operator has, which should be linear to their operating costs hence share of fees. ie if an operator has 10 validators and total validators is 100, they should receive 10% of the fees even if Effective Balances are not super equal.

Functions

isValidator

Checks if a validator is an Infrared validator, ie if the validator ID is in the set of validator IDs

function isValidator(ValidatorStorage storage $, bytes memory pubkey)
    external
    view
    returns (bool);

Parameters

NameTypeDescription
$ValidatorStorageStorage pinter for validator storage
pubkeybytesThe CL pubkey of validator

_getValidatorId

Gets the validator ID for associated CL pubkey

function _getValidatorId(bytes memory pubkey) internal pure returns (bytes32);

Parameters

NameTypeDescription
pubkeybytesThe CL pubkey of validator

addValidators

Adds validator to the set of validators, and maps the validator ID to the public key.

Also adds the validator to a public key set in the distributor contract, for receiving operator rewards. (ie Commissions for running nodeds).address

function addValidators(
    ValidatorStorage storage $,
    address distributor,
    ValidatorTypes.Validator[] memory _validators
) external;

Parameters

NameTypeDescription
$ValidatorStorageStorage pointer to the validator storage
distributoraddressaddress of the distributor contract
_validatorsValidatorTypes.Validator[]array of Validator structs containing the CL public key and address of the validator and their associated fee collecting address

removeValidators

Removes validators from the set of validators and also removes the validator from the distributor contract.

function removeValidators(
    ValidatorStorage storage $,
    address distributor,
    bytes[] memory _pubkeys
) external;

replaceValidator

Replaces a validator in the set of validators and also updates the validator in the distributor contract.

function replaceValidator(
    ValidatorStorage storage $,
    address distributor,
    bytes calldata _current,
    bytes calldata _new
) external;

Parameters

NameTypeDescription
$ValidatorStorageStorage pointer to the validator storage
distributoraddressaddress of the distributor contract
_currentbytesPublic key of the current validator
_newbytesPublic key of the new validator

queueBoosts

Queues boosts for validators in the BGT smart contract

The sum of the boosts must be less than or equal to the total supply of iBGT

function queueBoosts(
    ValidatorStorage storage $,
    address bgt,
    address ibgt,
    bytes[] memory _pubkeys,
    uint128[] memory _amts
) external;

Parameters

NameTypeDescription
$ValidatorStorageStorage pointer to the validator storage
bgtaddressaddress of the BGT contract
ibgtaddress
_pubkeysbytes[]array of public keys of validators
_amtsuint128[]array of amounts of boosts to queue

cancelBoosts

Cancels boosts for validators in the BGT smart contract before they are activated

function cancelBoosts(
    address bgt,
    bytes[] memory _pubkeys,
    uint128[] memory _amts
) external;

Parameters

NameTypeDescription
bgtaddressaddress of the BGT contract
_pubkeysbytes[]array of public keys of validators
_amtsuint128[]array of amounts of boosts to cancel

activateBoosts

Activates boosts for validators in the BGT smart contract

function activateBoosts(
    ValidatorStorage storage $,
    address bgt,
    bytes[] memory _pubkeys
) external;

Parameters

NameTypeDescription
$ValidatorStorageStorage pointer to the validator storage
bgtaddressaddress of the BGT contract
_pubkeysbytes[]array of public keys of validators

queueDropBoosts

Queues to drop the boosts for validators in the BGT smart contract

function queueDropBoosts(
    address bgt,
    bytes[] memory _pubkeys,
    uint128[] memory _amts
) external;

Parameters

NameTypeDescription
bgtaddressaddress of the BGT contract
_pubkeysbytes[]array of public keys of validators
_amtsuint128[]array of amounts of boosts to drop

cancelDropBoosts

Cancels drop boosts for validators in the BGT smart contract before they are activated

function cancelDropBoosts(
    ValidatorStorage storage $,
    address bgt,
    bytes[] memory _pubkeys,
    uint128[] memory _amts
) external;

Parameters

NameTypeDescription
$ValidatorStorageStorage pointer to the validator storage
bgtaddressaddress of the BGT contract
_pubkeysbytes[]array of public keys of validators
_amtsuint128[]array of amounts of boosts to cancel

dropBoosts

Activates drop boosts for validators in the BGT smart contract

function dropBoosts(address bgt, bytes[] memory _pubkeys) external;

Parameters

NameTypeDescription
bgtaddressaddress of the BGT contract
_pubkeysbytes[]array of public keys of validators

infraredValidators

Returns the list of validators in the validator storage

function infraredValidators(ValidatorStorage storage $, address distributor)
    external
    view
    returns (ValidatorTypes.Validator[] memory validators);

Parameters

NameTypeDescription
$ValidatorStorageStorage pointer to the validator storage
distributoraddressaddress of the distributor contract

Returns

NameTypeDescription
validatorsValidatorTypes.Validator[]array of Validator structs containing the CL public key and address of the validators fee collecting address

numInfraredValidators

Returns the number of validators in the validator storage

function numInfraredValidators(ValidatorStorage storage $)
    external
    view
    returns (uint256);

Parameters

NameTypeDescription
$ValidatorStorageStorage pointer to the validator storage

Returns

NameTypeDescription
<none>uint256number of validators

_getValidatorAddress

helper function to get the vlaidator fee collecting address via the CL pubkey

function _getValidatorAddress(address distributor, bytes memory pubkey)
    internal
    view
    returns (address);

Parameters

NameTypeDescription
distributoraddressaddress of the distributor contract
pubkeybytesCL pubkey of the validator

Returns

NameTypeDescription
<none>addressaddress of the validator fee collecting address

Structs

ValidatorStorage

Storage structure for validator storage

This structure is used to store validator IDs and public keys

struct ValidatorStorage {
    EnumerableSet.Bytes32Set validatorIds;
    mapping(bytes32 => bytes) validatorPubkeys;
}

Properties

NameTypeDescription
validatorIdsEnumerableSet.Bytes32SetSet of validator IDs which are keccak256 hashes of public keys.
validatorPubkeysmapping(bytes32 => bytes)Maps validator ID to public key