Skip to content

BerachainRewardsVault

ABI JSON

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

This contract is taken from the stable and tested Synthetix StakingRewards Contract. We are using this model instead of 4626 because we want to incentivize staying in the vault for x period of time to be considered a miner and not a trader.

State Variables

maxIncentiveTokensCount

The maximum count of incentive tokens that can be stored.

solidity
uint8 public maxIncentiveTokensCount;

distributor

The address of the distributor contract.

solidity
address public distributor;

beraChef

The Berachef contract.

solidity
IBeraChef public beraChef;

_delegateStake

solidity
mapping(address account => DelegateStake) internal _delegateStake;

_operators

The mapping of accounts to their operators.

solidity
mapping(address account => address operator) internal _operators;

incentives

the mapping of incentive token to its incentive data.

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

whitelistedTokens

The list of whitelisted tokens.

solidity
address[] public whitelistedTokens;

Functions

constructor

solidity
constructor();

initialize

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

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

Parameters

NameTypeDescription
_bgtaddressThe address of the BGT token.
_distributoraddressThe address of the distributor.
_berachefaddressThe address of the berachef.
_governanceaddressThe address of the governance.
_stakingTokenaddressThe address of the staking token.

onlyDistributor

solidity
modifier onlyDistributor();

onlyOperatorOrUser

solidity
modifier onlyOperatorOrUser(address account);

checkSelfStakedBalance

solidity
modifier checkSelfStakedBalance(address account, uint256 amount);

onlyWhitelistedToken

solidity
modifier onlyWhitelistedToken(address token);

setDistributor

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

solidity
function setDistributor(address _rewardDistribution) external onlyOwner;

Parameters

NameTypeDescription
_rewardDistributionaddressThe address that is allowed to distribute rewards.

notifyRewardAmount

Allows the distributor to notify the reward amount.

solidity
function notifyRewardAmount(address coinbase, uint256 reward) external onlyDistributor;

Parameters

NameTypeDescription
coinbaseaddressThe address of the coinbase.
rewarduint256The amount of reward to notify.

recoverERC20

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

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

Parameters

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

setRewardsDuration

Allows the owner to update the duration of the rewards.

solidity
function setRewardsDuration(uint256 _rewardsDuration) external onlyOwner;

Parameters

NameTypeDescription
_rewardsDurationuint256The new duration of the rewards.

whitelistIncentiveToken

Allows the owner to whitelist a token to incentivize with.

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

Parameters

NameTypeDescription
tokenaddressThe address of the token to whitelist.
minIncentiveRateuint256The minimum amount of the token to incentivize per BGT emission.

removeIncentiveToken

Allows the owner to remove a whitelisted incentive token.

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

Parameters

NameTypeDescription
tokenaddressThe address of the token to remove.

setMaxIncentiveTokensCount

Allows the owner to update the maxIncentiveTokensCount.

solidity
function setMaxIncentiveTokensCount(uint8 _maxIncentiveTokensCount) external onlyOwner;

Parameters

NameTypeDescription
_maxIncentiveTokensCountuint8The new maxIncentiveTokens count.

pause

Allows the owner to update the pause state of the vault.

solidity
function pause(bool _paused) external onlyOwner;

Parameters

NameTypeDescription
_pausedboolThe new pause state of the vault.

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.

getWhitelistedTokensCount

Get the count of active incentive tokens.

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

Returns

NameTypeDescription
<none>uint256The count of active incentive tokens.

getWhitelistedTokens

Get the list of whitelisted tokens.

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

Returns

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

getTotalDelegateStaked

Get the total amount staked by delegates.

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

Returns

NameTypeDescription
<none>uint256The total amount staked by delegates.

getDelegateStake

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

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

Returns

NameTypeDescription
<none>uint256The amount staked by a delegate.

stake

Stake tokens in the vault.

solidity
function stake(uint256 amount) external nonReentrant whenNotPaused;

Parameters

NameTypeDescription
amountuint256The amount of tokens to stake.

delegateStake

Stake tokens on behalf of another account.

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

Parameters

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

withdraw

Withdraw the staked tokens from the vault.

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

Parameters

NameTypeDescription
amountuint256The amount of tokens to withdraw.

delegateWithdraw

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

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

Parameters

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

getReward

Claim the reward.

The operator only handles BGT, not STAKING_TOKEN.

If the operator is the one calling this method, the reward will be credited to their address.

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

Parameters

NameTypeDescription
accountaddressThe account to claim the reward for.

Returns

NameTypeDescription
<none>uint256The amount of the reward claimed.

exit

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

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

solidity
function exit() external nonReentrant;

setOperator

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

solidity
function setOperator(address _operator) external;

Parameters

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

addIncentive

Add an incentive to the vault.

solidity
function addIncentive(address token, uint256 amount, uint256 incentiveRate) external 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.

_checkSelfStakedBalance

Check if the account has enough self-staked balance.

solidity
function _checkSelfStakedBalance(address account, uint256 amount) internal view;

Parameters

NameTypeDescription
accountaddressThe account to check the self-staked balance for.
amountuint256The amount being withdrawn.

_safeTransferRewardToken

The Distributor grants this contract the allowance to transfer the BGT in its balance.

solidity
function _safeTransferRewardToken(address to, uint256 amount) internal override;

_checkRewardSolvency

solidity
function _checkRewardSolvency() internal view override;

_processIncentives

process the incentives for a coinbase.

solidity
function _processIncentives(address coinbase, uint256 bgtEmitted) internal;

Parameters

NameTypeDescription
coinbaseaddressThe coinbase to process the incentives for.
bgtEmitteduint256The amount of BGT emitted by the validator.

_deleteWhitelistedTokenFromList

solidity
function _deleteWhitelistedTokenFromList(address token) internal;

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;
}

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.