Skip to content

RewardVault

 | ABI JSON

Git Source

This contract is the vault for the Berachain rewards, it handles the staking and rewards accounting of BGT.

Inherits: PausableUpgradeable, ReentrancyGuardUpgradeable, FactoryOwnable, StakingRewards, IRewardVault

Constants

MAX_REWARD_DURATION

The maximum reward duration.

solidity
uint256 public constant MAX_REWARD_DURATION = 7 days;

MIN_REWARD_DURATION

The minimum reward duration.

solidity
uint256 public constant MIN_REWARD_DURATION = 3 days;

Structs

DelegateStake

Struct to hold delegate stake data.

solidity
struct DelegateStake {
    uint256 delegateTotalStaked;
    mapping(address delegate => uint256 amount) stakedByDelegate;
}

Properties

NameTypeDescription
delegateTotalStakeduint256The total amount staked by delegates
stakedByDelegatemapping(address delegate => uint256 amount)The mapping of the amount staked by each delegate

Incentive

Struct to hold an incentive data.

solidity
struct Incentive {
    uint256 minIncentiveRate;
    uint256 incentiveRate;
    uint256 amountRemaining;
    address manager;
}

Properties

NameTypeDescription
minIncentiveRateuint256The minimum amount of the token to incentivize per BGT emission
incentiveRateuint256The amount of the token to incentivize per BGT emission
amountRemaininguint256The amount of the token remaining to incentivize
manageraddressThe address of the manager that can addIncentive for this incentive token

State Variables

beaconDepositContract

The BeaconDeposit contract.

solidity
IBeaconDeposit public beaconDepositContract;

distributor

The address of the distributor contract.

solidity
address public distributor;

incentives

The mapping of incentive token to its incentive data.

solidity
mapping(address token => Incentive) public incentives;

maxIncentiveTokensCount

The maximum count of incentive tokens that can be stored.

solidity
uint8 public maxIncentiveTokensCount;

minRewardDurationForTargetRate

The reward duration in case targetRewardsPerSecond is not met.

Must be between MIN_REWARD_DURATION and MAX_REWARD_DURATION and can be set only by reward vault manager.

solidity
uint256 public minRewardDurationForTargetRate;

pendingRewardsDuration

The pending rewards duration.

Comes into effect during the next notifyRewardAmount call.

solidity
uint256 public pendingRewardsDuration;

rewardVaultManager

The address authorized to manage reward vault operations and configurations.

This role is typically assigned to dApp teams to enable them to configure reward distribution parameters.

solidity
address public rewardVaultManager;

targetRewardsPerSecond

The target rewards per second, scaled by PRECISION.

This acts as both a maximum and a target rate. When the calculated reward rate exceeds this value, the duration is dynamically adjusted to achieve this target rate, but never goes below MIN_REWARD_DURATION. This prevents the issue where a spike in rewards would permanently expand the duration, causing subsequent smaller rewards to be spread over longer periods with very low rates.

solidity
uint256 public targetRewardsPerSecond;

whitelistedTokens

The list of whitelisted tokens.

solidity
address[] public whitelistedTokens;

View Functions

getDelegateStake

Get the amount staked by a delegate on behalf of an account.

solidity
function getDelegateStake(address account, address delegate) external view returns (uint256);

Parameters

NameTypeDescription
accountaddressThe account to check
delegateaddressThe delegate to check

Returns

NameTypeDescription
<none>uint256The amount staked by a delegate

getTotalDelegateStaked

Get the total amount staked by delegates.

solidity
function getTotalDelegateStaked(address account) external view returns (uint256);

Parameters

NameTypeDescription
accountaddressThe account to check

Returns

NameTypeDescription
<none>uint256The total amount staked by delegates

getWhitelistedTokens

Get the list of whitelisted tokens.

solidity
function getWhitelistedTokens() public view returns (address[] memory);

Returns

NameTypeDescription
<none>address[]The list of whitelisted tokens

getWhitelistedTokensCount

Get the count of active incentive tokens.

solidity
function getWhitelistedTokensCount() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256The count of active incentive tokens

operator

Get the operator for an account.

solidity
function operator(address account) external view returns (address);

Parameters

NameTypeDescription
accountaddressThe account to get the operator for

Returns

NameTypeDescription
<none>addressThe operator for the account

Functions

accountIncentives

Process incentives added via IERC20.transfer, adding them to the incentive accounting.

Allows permissionless incentive addition, without dossing the manager possibility to let the incentive accounting go to 0 in order to be able to decrease the incentive rate.

Emits:

solidity
function accountIncentives(address token, uint256 amount) external nonReentrant onlyWhitelistedToken(token);

Parameters

NameTypeDescription
tokenaddressThe address of the token to process
amountuint256The amount of token to account as incentive

addIncentive

Add an incentive token to the vault.

The incentive token's transfer should not exceed a gas usage of 500k units. In case the transfer exceeds 500k gas units, your incentive will fail to be transferred to the validator and its delegates.

Emits:

solidity
function addIncentive(
    address token,
    uint256 amount,
    uint256 incentiveRate
) external nonReentrant onlyWhitelistedToken(token);

Parameters

NameTypeDescription
tokenaddressThe address of the token to add as an incentive
amountuint256The amount of the token to add as an incentive
incentiveRateuint256The amount of the token to incentivize per BGT emission

delegateStake

Stake tokens on behalf of another account.

Emits:

solidity
function delegateStake(address account, uint256 amount) external nonReentrant whenNotPaused;

Parameters

NameTypeDescription
accountaddressThe account to stake for
amountuint256The amount of tokens to stake

delegateWithdraw

Withdraw tokens staked on behalf of another account by the delegate (msg.sender).

Emits:

solidity
function delegateWithdraw(address account, uint256 amount) external nonReentrant whenNotPaused;

Parameters

NameTypeDescription
accountaddressThe account to withdraw for
amountuint256The amount of tokens to withdraw

exit

Exit the vault with the staked tokens and claim the reward.

Only the account holder can call this function, not the operator.

Emits:

solidity
function exit(address recipient) external nonReentrant whenNotPaused;

Parameters

NameTypeDescription
recipientaddressThe address to send the 'BGT' reward to

getPartialReward

Claim a partial reward.

Use getReward if you want to claim the full reward.

Emits:

solidity
function getPartialReward(
    address account,
    address recipient,
    uint256 amount
) external nonReentrant whenNotPaused onlyOperatorOrUser(account);

Parameters

NameTypeDescription
accountaddressThe account to get the reward for
recipientaddressThe address to send the reward to
amountuint256The amount of the reward to claim

getReward

Claim the reward.

The operator only handles BGT, not STAKING_TOKEN.

Emits:

solidity
function getReward(
    address account,
    address recipient
) external nonReentrant whenNotPaused onlyOperatorOrUser(account) returns (uint256);

Parameters

NameTypeDescription
accountaddressThe account to get the reward for
recipientaddressThe address to send the reward to

Returns

NameTypeDescription
<none>uint256The amount of the reward claimed

initialize

Initialize the vault, this is only callable once and by the factory since its the deployer.

Emits:

solidity
function initialize(
    address _beaconDepositContract,
    address _bgt,
    address _distributor,
    address _stakingToken
) external initializer;

Parameters

NameTypeDescription
_beaconDepositContractaddressThe BeaconDeposit contract address
_bgtaddressThe address of the BGT token
_distributoraddressThe address of the distributor
_stakingTokenaddressThe address of the staking token

notifyRewardAmount

Allows the distributor to notify the reward amount.

Emits:

solidity
function notifyRewardAmount(bytes calldata pubkey, uint256 reward) external onlyDistributor;

Parameters

NameTypeDescription
pubkeybytesThe pubkey of the validator
rewarduint256The amount of reward to notify

pause

Allows the factory vault pauser to pause the vault.

solidity
function pause() external onlyFactoryVaultPauser;

recoverERC20

Allows the factory owner to recover any ERC20 token from the vault.

Emits:

solidity
function recoverERC20(address tokenAddress, uint256 tokenAmount) external onlyFactoryOwner;

Parameters

NameTypeDescription
tokenAddressaddressThe address of the token to recover
tokenAmountuint256The amount of token to recover

removeIncentiveToken

Allows the factory vault manager to remove a whitelisted incentive token.

Emits:

solidity
function removeIncentiveToken(address token) external onlyFactoryVaultManager onlyWhitelistedToken(token);

Parameters

NameTypeDescription
tokenaddressThe address of the token to remove

setDistributor

Allows the factory owner to set the contract that is allowed to distribute rewards.

Emits:

solidity
function setDistributor(address _rewardDistribution) external onlyFactoryOwner;

Parameters

NameTypeDescription
_rewardDistributionaddressThe address that is allowed to distribute rewards

setMaxIncentiveTokensCount

Allows the factory owner to update the maxIncentiveTokensCount.

Emits:

solidity
function setMaxIncentiveTokensCount(uint8 _maxIncentiveTokensCount) external onlyFactoryOwner;

Parameters

NameTypeDescription
_maxIncentiveTokensCountuint8The new maxIncentiveTokens count

setMinRewardDurationForTargetRate

Allows the reward vault manager to set the min reward duration for target rate.

This duration is used in case target rewards per second is not met.

Emits:

solidity
function setMinRewardDurationForTargetRate(uint256 _minRewardDurationForTargetRate) external onlyRewardVaultManager;

Parameters

NameTypeDescription
_minRewardDurationForTargetRateuint256The new min reward duration for target rate

setOperator

Allows msg.sender to set another address to claim and manage their rewards.

Emits:

solidity
function setOperator(address _operator) external;

Parameters

NameTypeDescription
_operatoraddressThe address that will be allowed to claim and manage rewards

setRewardVaultManager

Allows the factory vault manager to set the address responsible for managing the reward vault.

Emits:

solidity
function setRewardVaultManager(address _rewardVaultManager) external onlyFactoryVaultManager;

Parameters

NameTypeDescription
_rewardVaultManageraddressThe address of the reward vault manager

setRewardsDuration

Allows the reward vault manager to update the duration of the rewards.

Only allowed if targetRewardsPerSecond is not set.

Emits:

solidity
function setRewardsDuration(uint256 _rewardsDuration) external onlyRewardVaultManager;

Parameters

NameTypeDescription
_rewardsDurationuint256The new duration of the rewards

setTargetRewardsPerSecond

Sets the target rewards per second rate.

This rate acts as both a maximum and a target. When rewards exceed this rate, the duration is dynamically adjusted to achieve this target rate while respecting MIN_REWARD_DURATION constraints. This prevents permanent duration expansion from reward spikes that would cause subsequent smaller rewards to be distributed at very low rates.

Emits:

solidity
function setTargetRewardsPerSecond(uint256 _targetRewardsPerSecond) external onlyRewardVaultManager;

Parameters

NameTypeDescription
_targetRewardsPerSeconduint256The new target rewards per second, scaled by PRECISION

stake

Stake tokens in the vault.

Emits:

solidity
function stake(uint256 amount) external nonReentrant whenNotPaused;

Parameters

NameTypeDescription
amountuint256The amount of tokens to stake

stakeOnBehalf

Stake tokens on behalf of another account.

solidity
function stakeOnBehalf(address account, uint256 amount) external nonReentrant whenNotPaused;

Parameters

NameTypeDescription
accountaddressThe account to stake for
amountuint256The amount of tokens to stake

unpause

Allows the factory vault manager to unpause the vault.

solidity
function unpause() external onlyFactoryVaultManager;

updateIncentiveManager

Update the manager of an incentive token.

Permissioned function, only allow factory owner to update the manager.

Emits:

solidity
function updateIncentiveManager(
    address token,
    address newManager
) external onlyFactoryOwner onlyWhitelistedToken(token);

Parameters

NameTypeDescription
tokenaddressThe address of the incentive token
newManageraddressThe new manager of the incentive token

whitelistIncentiveToken

Allows the factory owner to whitelist a token to incentivize with.

Emits:

solidity
function whitelistIncentiveToken(address token, uint256 minIncentiveRate, address manager) external onlyFactoryOwner;

Parameters

NameTypeDescription
tokenaddressThe address of the token to whitelist
minIncentiveRateuint256The minimum amount of the token to incentivize per BGT emission
manageraddressThe address of the manager that can addIncentive for this token

withdraw

Withdraw the staked tokens from the vault.

Emits:

solidity
function withdraw(uint256 amount) external nonReentrant checkSelfStakedBalance(msg.sender, amount) whenNotPaused;

Parameters

NameTypeDescription
amountuint256The amount of tokens to withdraw

Events

BGTBoosterIncentivesProcessed

Emitted when the BGT booster share of the incentive is processed.

solidity
event BGTBoosterIncentivesProcessed(bytes indexed pubkey, address indexed token, uint256 bgtEmitted, uint256 amount);

Parameters

NameTypeDescription
pubkeybytesThe pubkey of the validator
tokenaddressThe address of the incentive token
bgtEmitteduint256The amount of BGT emitted by the validator
amountuint256The amount of the incentive

BGTBoosterIncentivesProcessFailed

Emitted when the BGT booster share of the incentive fails to be processed.

solidity
event BGTBoosterIncentivesProcessFailed(bytes indexed pubkey, address indexed token, uint256 bgtEmitted, uint256 amount);

Parameters

NameTypeDescription
pubkeybytesThe pubkey of the validator
tokenaddressThe address of the incentive token
bgtEmitteduint256The amount of BGT emitted by the validator
amountuint256The amount of the incentive

DelegateStaked

Emitted when a delegate has staked on behalf of an account.

solidity
event DelegateStaked(address indexed account, address indexed delegate, uint256 amount);

Parameters

NameTypeDescription
accountaddressThe account whose delegate has staked
delegateaddressThe delegate that has staked
amountuint256The amount of staked tokens

DelegateWithdrawn

Emitted when a delegate has withdrawn on behalf of an account.

solidity
event DelegateWithdrawn(address indexed account, address indexed delegate, uint256 amount);

Parameters

NameTypeDescription
accountaddressThe account whose delegate has withdrawn
delegateaddressThe delegate that has withdrawn
amountuint256The amount of withdrawn tokens

DistributorSet

Emitted when the distributor is set.

solidity
event DistributorSet(address indexed distributor);

Parameters

NameTypeDescription
distributoraddressThe address of the distributor

IncentiveAdded

Emitted when incentives are added to the vault.

solidity
event IncentiveAdded(address indexed token, address sender, uint256 amount, uint256 incentiveRate);

Parameters

NameTypeDescription
tokenaddressThe incentive token
senderaddressThe address that added the incentive
amountuint256The amount of the incentive
incentiveRateuint256The amount of the token to incentivize per BGT emission

IncentiveFeeCollected

Emitted when the incentive fee is sent to the collector.

solidity
event IncentiveFeeCollected(address indexed token, uint256 amount);

Parameters

NameTypeDescription
tokenaddressThe address of the incentive token
amountuint256The amount of the incentive fee

IncentiveFeeCollectionFailed

Emitted when the incentive fee is failed to be sent to the collector.

solidity
event IncentiveFeeCollectionFailed(address indexed token, uint256 amount);

Parameters

NameTypeDescription
tokenaddressThe address of the incentive token
amountuint256The amount of the incentive fee

IncentiveManagerChanged

Emitted when the manager of an incentive token is changed.

solidity
event IncentiveManagerChanged(address indexed token, address newManager, address oldManager);

Parameters

NameTypeDescription
tokenaddressThe address of the incentive token
newManageraddressThe new manager of the incentive token
oldManageraddressThe old manager of the incentive token

IncentiveTokenRemoved

Emitted when an incentive token is removed.

solidity
event IncentiveTokenRemoved(address indexed token);

Parameters

NameTypeDescription
tokenaddressThe address of the token that has been removed

IncentiveTokenWhitelisted

Emitted when an incentive token is whitelisted.

solidity
event IncentiveTokenWhitelisted(address indexed token, uint256 minIncentiveRate, address manager);

Parameters

NameTypeDescription
tokenaddressThe address of the token that has been whitelisted
minIncentiveRateuint256The minimum amount of the token to incentivize per BGT emission
manageraddressThe address of the manager that can addIncentive for this token

IncentivesProcessed

Emitted when validator share of incentives are processed to the operator address of a validator.

solidity
event IncentivesProcessed(bytes indexed pubkey, address indexed token, uint256 bgtEmitted, uint256 amount);

Parameters

NameTypeDescription
pubkeybytesThe pubkey of the validator
tokenaddressThe address of the incentive token
bgtEmitteduint256The amount of BGT emitted by the validator
amountuint256The amount of the incentive

IncentivesProcessFailed

Emitted when validator share of incentives fail to be processed to the operator address of a validator.

solidity
event IncentivesProcessFailed(bytes indexed pubkey, address indexed token, uint256 bgtEmitted, uint256 amount);

Parameters

NameTypeDescription
pubkeybytesThe pubkey of the validator
tokenaddressThe address of the incentive token
bgtEmitteduint256The amount of BGT emitted by the validator
amountuint256The amount of the incentive

MaxIncentiveTokensCountUpdated

Emitted when maxIncentiveTokensCount is updated.

solidity
event MaxIncentiveTokensCountUpdated(uint8 maxIncentiveTokensCount);

Parameters

NameTypeDescription
maxIncentiveTokensCountuint8The max count of incentive tokens

MinRewardDurationForTargetRateUpdated

Emitted when the min reward duration for target rate is updated.

solidity
event MinRewardDurationForTargetRateUpdated(uint256 newMinRewardDurationForTargetRate, uint256 oldMinRewardDurationForTargetRate);

Parameters

NameTypeDescription
newMinRewardDurationForTargetRateuint256The new min reward duration for target rate
oldMinRewardDurationForTargetRateuint256The old min reward duration for target rate

OperatorSet

Emitted when the msg.sender has set an operator to handle its rewards.

solidity
event OperatorSet(address account, address operator);

Parameters

NameTypeDescription
accountaddressThe account that has set the operator
operatoraddressThe operator that has been set

Recovered

Emitted when a token has been recovered.

solidity
event Recovered(address token, uint256 amount);

Parameters

NameTypeDescription
tokenaddressThe token that has been recovered
amountuint256The amount of token recovered

Staked

Emitted when the staking balance of an account has increased.

solidity
event Staked(address indexed account, uint256 amount);

Parameters

NameTypeDescription
accountaddressThe account that has staked
amountuint256The amount of staked tokens

Withdrawn

Emitted when the staking balance of an account has decreased.

solidity
event Withdrawn(address indexed account, uint256 amount);

Parameters

NameTypeDescription
accountaddressThe account that has withdrawn
amountuint256The amount of withdrawn tokens

RewardAdded

Emitted when a reward has been added to the vault.

solidity
event RewardAdded(uint256 reward);

Parameters

NameTypeDescription
rewarduint256The amount of reward added, scaled by PRECISION

RewardPaid

Emitted when a reward is paid to an account.

solidity
event RewardPaid(address indexed account, address to, uint256 reward);

Parameters

NameTypeDescription
accountaddressThe account that earned the reward
toaddressThe address that received the reward
rewarduint256The amount of reward paid

RewardsDurationUpdated

Emitted when the reward duration has been updated.

solidity
event RewardsDurationUpdated(uint256 newDuration);

Parameters

NameTypeDescription
newDurationuint256The new duration of the reward

RewardVaultManagerSet

Emitted when the reward vault manager is set.

solidity
event RewardVaultManagerSet(address indexed newRewardVaultManager, address indexed oldRewardVaultManager);

Parameters

NameTypeDescription
newRewardVaultManageraddressThe address of the new reward vault manager
oldRewardVaultManageraddressThe address of the old reward vault manager

TargetRewardsPerSecondUpdated

Emitted when the target rewards per second is updated.

solidity
event TargetRewardsPerSecondUpdated(uint256 newTargetRewardsPerSecond, uint256 oldTargetRewardsPerSecond);

Parameters

NameTypeDescription
newTargetRewardsPerSeconduint256The new target rewards per second
oldTargetRewardsPerSeconduint256The old target rewards per second

Errors

AmountGreaterThanReward

Thrown when the amount to claim is greater than the available reward.

solidity
error AmountGreaterThanReward();

AmountLessThanMinIncentiveRate

Thrown when the incentive amount is less than the minimum incentive rate.

solidity
error AmountLessThanMinIncentiveRate();

CannotRecoverIncentiveToken

Thrown when attempting to recover an incentive token.

solidity
error CannotRecoverIncentiveToken();

DurationChangeNotAllowed

Thrown when duration change is not allowed.

solidity
error DurationChangeNotAllowed();

IncentiveRateTooHigh

Thrown when the incentive rate is too high.

solidity
error IncentiveRateTooHigh();

InsolventReward

Thrown when the reward is insolvent.

solidity
error InsolventReward();

InsufficientDelegateStake

Thrown when there is insufficient delegate stake.

solidity
error InsufficientDelegateStake();

InsufficientSelfStake

Thrown when there is insufficient self stake.

solidity
error InsufficientSelfStake();

InvalidIncentiveRate

Thrown when the incentive rate is invalid.

solidity
error InvalidIncentiveRate();

InvalidMaxIncentiveTokensCount

Thrown when the max incentive tokens count is invalid.

solidity
error InvalidMaxIncentiveTokensCount();

InvalidRewardDuration

Thrown when the reward duration is invalid.

solidity
error InvalidRewardDuration();

MinIncentiveRateIsZero

Thrown when the minimum incentive rate is zero.

solidity
error MinIncentiveRateIsZero();

NotDelegate

Thrown when the caller is not a delegate.

solidity
error NotDelegate();

NotDistributor

Thrown when the caller is not the distributor.

solidity
error NotDistributor();

NotEnoughBalance

Thrown when there is not enough balance.

solidity
error NotEnoughBalance();

NotIncentiveManager

Thrown when the caller is not the incentive manager.

solidity
error NotIncentiveManager();

NotOperator

Thrown when the caller is not the operator.

solidity
error NotOperator();

NotRewardVaultManager

Thrown when the caller is not the reward vault manager.

solidity
error NotRewardVaultManager();

TokenAlreadyWhitelistedOrLimitReached

Thrown when the token is already whitelisted or the limit is reached.

solidity
error TokenAlreadyWhitelistedOrLimitReached();

TokenNotWhitelisted

Thrown when the token is not whitelisted.

solidity
error TokenNotWhitelisted();

ZeroAddress

Thrown when a zero address is provided where a valid address is required.

solidity
error ZeroAddress();