Skip to content

BeraChef

0xdf960E8F3F19C481dDE769edEDD439ea1a63426a | ABI JSON

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%.

solidity
uint96 public constant MAX_COMMISSION_RATE = 0.2e4;

MAX_REWARD_ALLOCATION_BLOCK_DELAY

With 2 second block time, this is ~30 days.

solidity
uint64 public constant MAX_REWARD_ALLOCATION_BLOCK_DELAY = 1_315_000;

Structs

CommissionRate

The commission rate struct for validators.

solidity
struct CommissionRate {
    uint32 activationBlock;
    uint96 commissionRate;
}

Properties

NameTypeDescription
activationBlockuint32The block number in which the commission rate was activated
commissionRateuint96The commission rate to be used by the validator

QueuedCommissionRateChange

The queued commission rate change struct for validators.

solidity
struct QueuedCommissionRateChange {
    uint32 blockNumberLast;
    uint96 commissionRate;
}

Properties

NameTypeDescription
blockNumberLastuint32The last block number commission rate was queued
commissionRateuint96The queued commission rate to be used by the validator

RewardAllocation

The reward allocation struct containing start block and weights.

solidity
struct RewardAllocation {
    uint64 startBlock;
    Weight[] weights;
}

Properties

NameTypeDescription
startBlockuint64The block number when the allocation becomes active
weightsWeight[]Array of weights for reward distribution

Weight

The weight struct for reward allocation.

solidity
struct Weight {
    address receiver;
    uint96 percentageNumerator;
}

Properties

NameTypeDescription
receiveraddressThe address receiving the rewards
percentageNumeratoruint96The percentage numerator for the weight

State Variables

beaconDepositContract

solidity
IBeaconDeposit public beaconDepositContract;

commissionChangeDelay

The delay in blocks before a new commission rate can go into effect.

solidity
uint64 public commissionChangeDelay;

distributor

The address of the distributor contract.

solidity
address public distributor;

factory

The address of the reward vault factory contract.

solidity
address public factory;

isWhitelistedVault

Mapping of receiver address to whether they are white-listed or not.

solidity
mapping(address receiver => bool) public isWhitelistedVault;

maxNumWeightsPerRewardAllocation

The maximum number of weights per reward allocation.

solidity
uint8 public maxNumWeightsPerRewardAllocation;

maxWeightPerVault

The maximum weight a vault can assume in the reward allocation

solidity
uint96 public maxWeightPerVault;

rewardAllocationBlockDelay

The delay in blocks before a new reward allocation can go into effect.

solidity
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.

solidity
function getActiveRewardAllocation(bytes calldata valPubkey) external view returns (RewardAllocation memory);

Parameters

NameTypeDescription
valPubkeybytesThe validator's pubkey.

Returns

NameTypeDescription
<none>RewardAllocationrewardAllocation The active reward allocation.

getDefaultRewardAllocation

Returns the default reward allocation for validators that do not have a reward allocation.

solidity
function getDefaultRewardAllocation() external view returns (RewardAllocation memory);

Returns

NameTypeDescription
<none>RewardAllocationrewardAllocation The default reward allocation.

getQueuedRewardAllocation

Returns the queued reward allocation for a validator with given pubkey

solidity
function getQueuedRewardAllocation(bytes calldata valPubkey) external view returns (RewardAllocation memory);

Parameters

NameTypeDescription
valPubkeybytesThe validator's pubkey.

Returns

NameTypeDescription
<none>RewardAllocationrewardAllocation 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.

solidity
function getSetActiveRewardAllocation(bytes calldata valPubkey) external view returns (RewardAllocation memory);

Parameters

NameTypeDescription
valPubkeybytesThe validator's pubkey.

Returns

NameTypeDescription
<none>RewardAllocationrewardAllocation 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.

solidity
function getValCommissionOnIncentiveTokens(bytes calldata valPubkey) external view returns (uint96);

Parameters

NameTypeDescription
valPubkeybytesThe validator's pubkey.

Returns

NameTypeDescription
<none>uint96commissionRate The commission rate of the validator on the incentive tokens.

getValQueuedCommissionOnIncentiveTokens

Returns the queued commission struct of a validator on an incentive tokens.

solidity
function getValQueuedCommissionOnIncentiveTokens(bytes calldata valPubkey)
    external
    view
    returns (QueuedCommissionRateChange memory);

Parameters

NameTypeDescription
valPubkeybytesThe validator's pubkey.

Returns

NameTypeDescription
<none>QueuedCommissionRateChangequeuedCommissionRate 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.

solidity
function getValidatorIncentiveTokenShare(
    bytes calldata valPubkey,
    uint256 incentiveTokenAmount
)
    external
    view
    returns (uint256);

Parameters

NameTypeDescription
valPubkeybytesThe validator's pubkey.
incentiveTokenAmountuint256The amount of the incentive tokens.

Returns

NameTypeDescription
<none>uint256validatorShare The validator's share of the incentive tokens.

isQueuedRewardAllocationReady

Returns the status of whether a queued reward allocation is ready to be activated.

solidity
function isQueuedRewardAllocationReady(bytes calldata valPubkey, uint256 blockNumber) public view returns (bool);

Parameters

NameTypeDescription
valPubkeybytesThe validator's pubkey.
blockNumberuint256The block number to be queried.

Returns

NameTypeDescription
<none>boolisReady 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.

solidity
function isReady() external view returns (bool);

Returns

NameTypeDescription
<none>boolisReady 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:

solidity
function activateQueuedValCommission(bytes calldata valPubkey) external;

Parameters

NameTypeDescription
valPubkeybytesThe 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:

solidity
function activateReadyQueuedRewardAllocation(bytes calldata valPubkey) external onlyDistributor;

Parameters

NameTypeDescription
valPubkeybytesThe validator's pubkey.

initialize

Initializes the BeraChef contract with the required parameters.

solidity
function initialize(
    address _distributor,
    address _factory,
    address _governance,
    address _beaconDepositContract,
    uint8 _maxNumWeightsPerRewardAllocation
)
    external
    initializer;

Parameters

NameTypeDescription
_distributoraddressThe address of the distributor contract
_factoryaddressThe address of the reward vault factory
_governanceaddressThe address of the governance module
_beaconDepositContractaddressThe address of the beacon deposit contract
_maxNumWeightsPerRewardAllocationuint8The maximum number of weights per allocation

Emits:

_authorizeUpgrade

Authorizes an upgrade to a new implementation.

Only the owner can call this function.

solidity
function _authorizeUpgrade(address newImplementation) internal override onlyOwner;

Parameters

NameTypeDescription
newImplementationaddressThe 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:

solidity
function queueNewRewardAllocation(
    bytes calldata valPubkey,
    uint64 startBlock,
    Weight[] calldata weights
)
    external
    onlyOperator(valPubkey);

Parameters

NameTypeDescription
valPubkeybytesThe validator's pubkey.
startBlockuint64The block that the reward allocation goes into effect.
weightsWeight[]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:

solidity
function queueValCommission(bytes calldata valPubkey, uint96 commissionRate) external onlyOperator(valPubkey);

Parameters

NameTypeDescription
valPubkeybytesThe validator's pubkey.
commissionRateuint96The commission rate of the validator on the incentive tokens.

setCommissionChangeDelay

Sets the commission change delay.

Only owner can call this function.

Emits:

solidity
function setCommissionChangeDelay(uint64 _commissionChangeDelay) external onlyOwner;

Parameters

NameTypeDescription
_commissionChangeDelayuint64The 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:

solidity
function setDefaultRewardAllocation(RewardAllocation calldata ra) external onlyOwner;

Parameters

NameTypeDescription
raRewardAllocationThe default reward allocation to set

setMaxNumWeightsPerRewardAllocation

Sets the maximum number of weights per reward allocation.

Emits:

solidity
function setMaxNumWeightsPerRewardAllocation(uint8 _maxNumWeightsPerRewardAllocation) external onlyOwner;

setMaxWeightPerVault

Sets the maximum weight a vault can assume in a reward allocation.

Emits:

solidity
function setMaxWeightPerVault(uint96 _maxWeightPerVault) external onlyOwner;

setRewardAllocationBlockDelay

Sets the delay in blocks before a new reward allocation can be queued.

Emits:

solidity
function setRewardAllocationBlockDelay(uint64 _rewardAllocationBlockDelay) external onlyOwner;

setVaultWhitelistedStatus

Updates the vault's whitelisted status

Emits:

solidity
function setVaultWhitelistedStatus(address receiver, bool isWhitelisted, string memory metadata) external onlyOwner;

Parameters

NameTypeDescription
receiveraddressThe address to remove or add as whitelisted vault.
isWhitelistedboolThe whitelist status; true if the receiver is being whitelisted, false otherwise.
metadatastringThe metadata of the vault.

updateWhitelistedVaultMetadata

Updates the metadata of a whitelisted vault, reverts if vault is not whitelisted.

Emits:

solidity
function updateWhitelistedVaultMetadata(address vault, string memory metadata) external onlyOwner;

Parameters

NameTypeDescription
vaultaddress
metadatastringThe metadata of the vault, to associate info with the vault in the events log.

Events

CommissionChangeDelaySet

Emitted when the commission change delay is set.

solidity
event CommissionChangeDelaySet(uint64 oldDelay, uint64 newDelay);

Parameters

NameTypeDescription
oldDelayuint64The previous commission change delay
newDelayuint64The new commission change delay

SetDefaultRewardAllocation

Emitted when the default reward allocation is set.

solidity
event SetDefaultRewardAllocation(RewardAllocation rewardAllocation);

Parameters

NameTypeDescription
rewardAllocationRewardAllocationThe new default reward allocation

Initialized

Emitted when the contract is initialized.

solidity
event Initialized(uint64 version);

Parameters

NameTypeDescription
versionuint64The initialization version

MaxNumWeightsPerRewardAllocationSet

Emitted when the maximum number of weights per reward allocation is set.

solidity
event MaxNumWeightsPerRewardAllocationSet(uint8 oldMaxNumWeights, uint8 newMaxNumWeights);

Parameters

NameTypeDescription
oldMaxNumWeightsuint8The previous maximum number of weights
newMaxNumWeightsuint8The new maximum number of weights

MaxWeightPerVaultSet

Emitted when the maximum weight per vault is set.

solidity
event MaxWeightPerVaultSet(uint96 oldMaxWeight, uint96 newMaxWeight);

Parameters

NameTypeDescription
oldMaxWeightuint96The previous maximum weight per vault
newMaxWeightuint96The new maximum weight per vault

OwnershipTransferred

Emitted when ownership is transferred.

solidity
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

Parameters

NameTypeDescription
previousOwneraddressThe previous owner
newOwneraddressThe new owner

ActivateRewardAllocation

Emitted when a reward allocation is activated.

solidity
event ActivateRewardAllocation(bytes indexed valPubkey, uint64 startBlock, Weight[] weights);

Parameters

NameTypeDescription
valPubkeybytesThe validator's public key
startBlockuint64The block when allocation becomes active
weightsWeight[]The weights of the reward allocation

RewardAllocationBlockDelaySet

Emitted when the reward allocation block delay is set.

solidity
event RewardAllocationBlockDelaySet(uint64 oldDelay, uint64 newDelay);

Parameters

NameTypeDescription
oldDelayuint64The previous reward allocation block delay
newDelayuint64The new reward allocation block delay

QueueRewardAllocation

Emitted when a reward allocation is queued.

solidity
event QueueRewardAllocation(bytes indexed valPubkey, uint64 startBlock, Weight[] weights);

Parameters

NameTypeDescription
valPubkeybytesThe validator's public key
startBlockuint64The block when allocation becomes active
weightsWeight[]The weights of the reward allocation

Upgraded

Emitted when the implementation is upgraded.

solidity
event Upgraded(address indexed implementation);

Parameters

NameTypeDescription
implementationaddressThe new implementation address

ValCommissionSet

Emitted when a validator commission is set.

solidity
event ValCommissionSet(bytes indexed valPubkey, uint96 oldCommissionRate, uint96 newCommissionRate);

Parameters

NameTypeDescription
valPubkeybytesThe validator's public key
oldCommissionRateuint96The old commission rate
newCommissionRateuint96The new commission rate

QueuedValCommission

Emitted when a validator commission is queued.

solidity
event QueuedValCommission(bytes indexed valPubkey, uint96 queuedCommissionRate);

Parameters

NameTypeDescription
valPubkeybytesThe validator's public key
queuedCommissionRateuint96The queued commission rate

VaultWhitelistedStatusUpdated

Emitted when a vault's whitelisted status is updated.

solidity
event VaultWhitelistedStatusUpdated(address indexed vault, bool isWhitelisted, string metadata);

Parameters

NameTypeDescription
vaultaddressThe vault address
isWhitelistedboolThe new whitelisted status
metadatastringThe vault metadata

WhitelistedVaultMetadataUpdated

Emitted when whitelisted vault metadata is updated.

solidity
event WhitelistedVaultMetadataUpdated(address indexed vault, string metadata);

Parameters

NameTypeDescription
vaultaddressThe vault address
metadatastringThe updated metadata