BeraChef
The BeraChef contract is responsible for managing the reward allocations and the whitelisted vaults. Reward allocation is a list of weights that determine the percentage of rewards that goes to each reward vault. Each validator could have a custom reward allocation, if not, the default reward allocation is used.
Inherits: IBeraChef, OwnableUpgradeable, UUPSUpgradeable
Constants
MAX_COMMISSION_RATE
Represents the maximum commission rate per validator, set to 20%.
uint96 public constant MAX_COMMISSION_RATE = 0.2e4;
MAX_REWARD_ALLOCATION_BLOCK_DELAY
With 2 second block time, this is ~30 days.
uint64 public constant MAX_REWARD_ALLOCATION_BLOCK_DELAY = 1_315_000;
Structs
CommissionRate
The commission rate struct for validators.
struct CommissionRate {
uint32 activationBlock;
uint96 commissionRate;
}
Properties
Name | Type | Description |
---|---|---|
activationBlock | uint32 | The block number in which the commission rate was activated |
commissionRate | uint96 | The commission rate to be used by the validator |
QueuedCommissionRateChange
The queued commission rate change struct for validators.
struct QueuedCommissionRateChange {
uint32 blockNumberLast;
uint96 commissionRate;
}
Properties
Name | Type | Description |
---|---|---|
blockNumberLast | uint32 | The last block number commission rate was queued |
commissionRate | uint96 | The queued commission rate to be used by the validator |
RewardAllocation
The reward allocation struct containing start block and weights.
struct RewardAllocation {
uint64 startBlock;
Weight[] weights;
}
Properties
Name | Type | Description |
---|---|---|
startBlock | uint64 | The block number when the allocation becomes active |
weights | Weight[] | Array of weights for reward distribution |
Weight
The weight struct for reward allocation.
struct Weight {
address receiver;
uint96 percentageNumerator;
}
Properties
Name | Type | Description |
---|---|---|
receiver | address | The address receiving the rewards |
percentageNumerator | uint96 | The percentage numerator for the weight |
State Variables
beaconDepositContract
IBeaconDeposit public beaconDepositContract;
commissionChangeDelay
The delay in blocks before a new commission rate can go into effect.
uint64 public commissionChangeDelay;
distributor
The address of the distributor contract.
address public distributor;
factory
The address of the reward vault factory contract.
address public factory;
isWhitelistedVault
Mapping of receiver address to whether they are white-listed or not.
mapping(address receiver => bool) public isWhitelistedVault;
maxNumWeightsPerRewardAllocation
The maximum number of weights per reward allocation.
uint8 public maxNumWeightsPerRewardAllocation;
maxWeightPerVault
The maximum weight a vault can assume in the reward allocation
uint96 public maxWeightPerVault;
rewardAllocationBlockDelay
The delay in blocks before a new reward allocation can go into effect.
uint64 public rewardAllocationBlockDelay;
View Functions
getActiveRewardAllocation
Returns the active reward allocation for validator with given pubkey
Returns the active reward allocation if validator has a reward allocation and the weights are still valid, otherwise the default reward allocation.
function getActiveRewardAllocation(bytes calldata valPubkey) external view returns (RewardAllocation memory);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's pubkey. |
Returns
Name | Type | Description |
---|---|---|
<none> | RewardAllocation | rewardAllocation The active reward allocation. |
getDefaultRewardAllocation
Returns the default reward allocation for validators that do not have a reward allocation.
function getDefaultRewardAllocation() external view returns (RewardAllocation memory);
Returns
Name | Type | Description |
---|---|---|
<none> | RewardAllocation | rewardAllocation The default reward allocation. |
getQueuedRewardAllocation
Returns the queued reward allocation for a validator with given pubkey
function getQueuedRewardAllocation(bytes calldata valPubkey) external view returns (RewardAllocation memory);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's pubkey. |
Returns
Name | Type | Description |
---|---|---|
<none> | RewardAllocation | rewardAllocation The queued reward allocation. |
getSetActiveRewardAllocation
Returns the active reward allocation set by the validator with given pubkey.
This will return active reward allocation set by validators even if its not valid.
function getSetActiveRewardAllocation(bytes calldata valPubkey) external view returns (RewardAllocation memory);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's pubkey. |
Returns
Name | Type | Description |
---|---|---|
<none> | RewardAllocation | rewardAllocation The reward allocation. |
getValCommissionOnIncentiveTokens
Returns the commission rate of a validator on an incentive tokens.
Default commission rate is 5% if the commission was never set.
function getValCommissionOnIncentiveTokens(bytes calldata valPubkey) external view returns (uint96);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's pubkey. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint96 | commissionRate The commission rate of the validator on the incentive tokens. |
getValQueuedCommissionOnIncentiveTokens
Returns the queued commission struct of a validator on an incentive tokens.
function getValQueuedCommissionOnIncentiveTokens(bytes calldata valPubkey)
external
view
returns (QueuedCommissionRateChange memory);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's pubkey. |
Returns
Name | Type | Description |
---|---|---|
<none> | QueuedCommissionRateChange | queuedCommissionRate The queued commission struct of the validator on the incentive tokens. |
getValidatorIncentiveTokenShare
Returns the validator's share of the incentive tokens based on the validator's commission rate.
function getValidatorIncentiveTokenShare(
bytes calldata valPubkey,
uint256 incentiveTokenAmount
)
external
view
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's pubkey. |
incentiveTokenAmount | uint256 | The amount of the incentive tokens. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | validatorShare The validator's share of the incentive tokens. |
isQueuedRewardAllocationReady
Returns the status of whether a queued reward allocation is ready to be activated.
function isQueuedRewardAllocationReady(bytes calldata valPubkey, uint256 blockNumber) public view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's pubkey. |
blockNumber | uint256 | The block number to be queried. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | isReady True if the queued reward allocation is ready to be activated, false otherwise. |
isReady
Returns the status of whether the BeraChef contract is ready to be used.
This function should be used by all contracts that depend on a system call.
function isReady() external view returns (bool);
Returns
Name | Type | Description |
---|---|---|
<none> | bool | isReady True if the BeraChef is ready to be used, false otherwise. |
Functions
activateQueuedValCommission
Activates the queued commission rate of a validator on incentive tokens.
Emits:
function activateQueuedValCommission(bytes calldata valPubkey) external;
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's pubkey. |
activateReadyQueuedRewardAllocation
Activates the queued reward allocation for a validator if its ready for the current block.
Should be called by the distribution contract.
Emits:
function activateReadyQueuedRewardAllocation(bytes calldata valPubkey) external onlyDistributor;
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's pubkey. |
initialize
Initializes the BeraChef contract with the required parameters.
function initialize(
address _distributor,
address _factory,
address _governance,
address _beaconDepositContract,
uint8 _maxNumWeightsPerRewardAllocation
)
external
initializer;
Parameters
Name | Type | Description |
---|---|---|
_distributor | address | The address of the distributor contract |
_factory | address | The address of the reward vault factory |
_governance | address | The address of the governance module |
_beaconDepositContract | address | The address of the beacon deposit contract |
_maxNumWeightsPerRewardAllocation | uint8 | The maximum number of weights per allocation |
Emits:
_authorizeUpgrade
Authorizes an upgrade to a new implementation.
Only the owner can call this function.
function _authorizeUpgrade(address newImplementation) internal override onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
newImplementation | address | The new implementation address |
queueNewRewardAllocation
Add a new reward allocation to the queue for validator with given pubkey. Does not allow overwriting of existing queued reward allocation.
The weights of the reward allocation must add up to 100% or 1e4. Only whitelisted pools may be used as well.
Emits:
function queueNewRewardAllocation(
bytes calldata valPubkey,
uint64 startBlock,
Weight[] calldata weights
)
external
onlyOperator(valPubkey);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's pubkey. |
startBlock | uint64 | The block that the reward allocation goes into effect. |
weights | Weight[] | The weights of the reward allocation. |
queueValCommission
Queues a commission rate change for a validator on incentive tokens.
The caller of this function must be the validator operator address.
Emits:
function queueValCommission(bytes calldata valPubkey, uint96 commissionRate) external onlyOperator(valPubkey);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's pubkey. |
commissionRate | uint96 | The commission rate of the validator on the incentive tokens. |
setCommissionChangeDelay
Sets the commission change delay.
Only owner can call this function.
Emits:
function setCommissionChangeDelay(uint64 _commissionChangeDelay) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_commissionChangeDelay | uint64 | The delay in blocks to activate a queued commission change. |
setDefaultRewardAllocation
Sets the default reward allocation for validators that do not have a reward allocation.
The caller of this function must be the governance module account.
Emits:
function setDefaultRewardAllocation(RewardAllocation calldata ra) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
ra | RewardAllocation | The default reward allocation to set |
setMaxNumWeightsPerRewardAllocation
Sets the maximum number of weights per reward allocation.
Emits:
function setMaxNumWeightsPerRewardAllocation(uint8 _maxNumWeightsPerRewardAllocation) external onlyOwner;
setMaxWeightPerVault
Sets the maximum weight a vault can assume in a reward allocation.
Emits:
function setMaxWeightPerVault(uint96 _maxWeightPerVault) external onlyOwner;
setRewardAllocationBlockDelay
Sets the delay in blocks before a new reward allocation can be queued.
Emits:
function setRewardAllocationBlockDelay(uint64 _rewardAllocationBlockDelay) external onlyOwner;
setVaultWhitelistedStatus
Updates the vault's whitelisted status
Emits:
function setVaultWhitelistedStatus(address receiver, bool isWhitelisted, string memory metadata) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
receiver | address | The address to remove or add as whitelisted vault. |
isWhitelisted | bool | The whitelist status; true if the receiver is being whitelisted, false otherwise. |
metadata | string | The metadata of the vault. |
updateWhitelistedVaultMetadata
Updates the metadata of a whitelisted vault, reverts if vault is not whitelisted.
Emits:
function updateWhitelistedVaultMetadata(address vault, string memory metadata) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
vault | address | |
metadata | string | The metadata of the vault, to associate info with the vault in the events log. |
Events
CommissionChangeDelaySet
Emitted when the commission change delay is set.
event CommissionChangeDelaySet(uint64 oldDelay, uint64 newDelay);
Parameters
Name | Type | Description |
---|---|---|
oldDelay | uint64 | The previous commission change delay |
newDelay | uint64 | The new commission change delay |
SetDefaultRewardAllocation
Emitted when the default reward allocation is set.
event SetDefaultRewardAllocation(RewardAllocation rewardAllocation);
Parameters
Name | Type | Description |
---|---|---|
rewardAllocation | RewardAllocation | The new default reward allocation |
Initialized
Emitted when the contract is initialized.
event Initialized(uint64 version);
Parameters
Name | Type | Description |
---|---|---|
version | uint64 | The initialization version |
MaxNumWeightsPerRewardAllocationSet
Emitted when the maximum number of weights per reward allocation is set.
event MaxNumWeightsPerRewardAllocationSet(uint8 oldMaxNumWeights, uint8 newMaxNumWeights);
Parameters
Name | Type | Description |
---|---|---|
oldMaxNumWeights | uint8 | The previous maximum number of weights |
newMaxNumWeights | uint8 | The new maximum number of weights |
MaxWeightPerVaultSet
Emitted when the maximum weight per vault is set.
event MaxWeightPerVaultSet(uint96 oldMaxWeight, uint96 newMaxWeight);
Parameters
Name | Type | Description |
---|---|---|
oldMaxWeight | uint96 | The previous maximum weight per vault |
newMaxWeight | uint96 | The new maximum weight per vault |
OwnershipTransferred
Emitted when ownership is transferred.
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
Parameters
Name | Type | Description |
---|---|---|
previousOwner | address | The previous owner |
newOwner | address | The new owner |
ActivateRewardAllocation
Emitted when a reward allocation is activated.
event ActivateRewardAllocation(bytes indexed valPubkey, uint64 startBlock, Weight[] weights);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's public key |
startBlock | uint64 | The block when allocation becomes active |
weights | Weight[] | The weights of the reward allocation |
RewardAllocationBlockDelaySet
Emitted when the reward allocation block delay is set.
event RewardAllocationBlockDelaySet(uint64 oldDelay, uint64 newDelay);
Parameters
Name | Type | Description |
---|---|---|
oldDelay | uint64 | The previous reward allocation block delay |
newDelay | uint64 | The new reward allocation block delay |
QueueRewardAllocation
Emitted when a reward allocation is queued.
event QueueRewardAllocation(bytes indexed valPubkey, uint64 startBlock, Weight[] weights);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's public key |
startBlock | uint64 | The block when allocation becomes active |
weights | Weight[] | The weights of the reward allocation |
Upgraded
Emitted when the implementation is upgraded.
event Upgraded(address indexed implementation);
Parameters
Name | Type | Description |
---|---|---|
implementation | address | The new implementation address |
ValCommissionSet
Emitted when a validator commission is set.
event ValCommissionSet(bytes indexed valPubkey, uint96 oldCommissionRate, uint96 newCommissionRate);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's public key |
oldCommissionRate | uint96 | The old commission rate |
newCommissionRate | uint96 | The new commission rate |
QueuedValCommission
Emitted when a validator commission is queued.
event QueuedValCommission(bytes indexed valPubkey, uint96 queuedCommissionRate);
Parameters
Name | Type | Description |
---|---|---|
valPubkey | bytes | The validator's public key |
queuedCommissionRate | uint96 | The queued commission rate |
VaultWhitelistedStatusUpdated
Emitted when a vault's whitelisted status is updated.
event VaultWhitelistedStatusUpdated(address indexed vault, bool isWhitelisted, string metadata);
Parameters
Name | Type | Description |
---|---|---|
vault | address | The vault address |
isWhitelisted | bool | The new whitelisted status |
metadata | string | The vault metadata |
WhitelistedVaultMetadataUpdated
Emitted when whitelisted vault metadata is updated.
event WhitelistedVaultMetadataUpdated(address indexed vault, string metadata);
Parameters
Name | Type | Description |
---|---|---|
vault | address | The vault address |
metadata | string | The updated metadata |