StakingDelegateRewards
Inherits: IStakingDelegateRewards, AccessControlEnumerable
Contract for managing staking rewards with functionality to update balances, notify new rewards, and recover tokens.
Inherits from IStakingDelegateRewards and AccessControlEnumerable.
State Variables
_DEFAULT_DURATION
Default duration of rewards period in seconds (7 days).
uint256 private constant _DEFAULT_DURATION = 7 days;
TIMELOCK_ROLE
Role identifier used for protecting functions with timelock access.
bytes32 public constant TIMELOCK_ROLE = keccak256("TIMELOCK_ROLE");
_REWARDS_TOKEN
Address of the token used for rewards, immutable.
address private immutable _REWARDS_TOKEN;
_STAKING_DELEGATE
Address of the staking delegate, immutable.
address private immutable _STAKING_DELEGATE;
periodFinish
Mapping of staking tokens to the period end timestamp.
mapping(address => uint256) public periodFinish;
rewardRate
Mapping of staking tokens to their respective reward rate.
mapping(address => uint256) public rewardRate;
rewardsDuration
Mapping of staking tokens to their rewards duration.
mapping(address => uint256) public rewardsDuration;
lastUpdateTime
Mapping of staking tokens to the last update time for rewards.
mapping(address => uint256) public lastUpdateTime;
rewardPerTokenStored
Mapping of staking tokens to the accumulated reward per token.
mapping(address => uint256) public rewardPerTokenStored;
leftOver
Mapping of staking tokens to the leftover rewards.
mapping(address => uint256) public leftOver;
userRewardPerTokenPaid
Mapping of staking tokens and users to the paid-out reward per token.
mapping(address => mapping(address => uint256)) public userRewardPerTokenPaid;
rewards
Mapping of staking tokens and users to their respective rewards.
mapping(address => mapping(address => uint256)) public rewards;
rewardDistributors
Mapping of staking tokens to their reward distributors.
mapping(address => address) public rewardDistributors;
rewardReceiver
Mapping of users to their designated reward receivers.
mapping(address => address) public rewardReceiver;
Functions
constructor
Constructor that sets the rewards token and staking delegate addresses.
constructor(address rewardsToken_, address stakingDelegate_, address admin, address timeLock) payable;
Parameters
Name | Type | Description |
---|---|---|
rewardsToken_ | address | The ERC20 token to be used as the rewards token. |
stakingDelegate_ | address | The address of the staking delegate contract. |
admin | address | |
timeLock | address |
getReward
Claims reward for a given staking token.
function getReward(address stakingToken) external;
Parameters
Name | Type | Description |
---|---|---|
stakingToken | address | The address of the staking token. |
getReward
Claims reward for a given user and staking token.
function getReward(address user, address stakingToken) external;
Parameters
Name | Type | Description |
---|---|---|
user | address | The address of the user to claim rewards for. |
stakingToken | address | The address of the staking token. |
setRewardReceiver
Sets the reward receiver who will receive your rewards instead.
This can be set to the zero address to receive rewards directly.
function setRewardReceiver(address receiver) external;
Parameters
Name | Type | Description |
---|---|---|
receiver | address | The address of the reward receiver. |
notifyRewardAmount
Notifies a new reward amount for a given staking token.
function notifyRewardAmount(address stakingToken, uint256 reward) external;
Parameters
Name | Type | Description |
---|---|---|
stakingToken | address | The address of the staking token to notify the reward for. |
reward | uint256 | The amount of the new reward. |
updateUserBalance
Updates the balance of a user for a given staking token.
function updateUserBalance(
address user,
address stakingToken,
uint256 currentUserBalance,
uint256 currentTotalDeposited
)
external;
Parameters
Name | Type | Description |
---|---|---|
user | address | The address of the user to update the balance for. |
stakingToken | address | The address of the staking token. |
currentUserBalance | uint256 | The current balance of staking token of the user. |
currentTotalDeposited | uint256 | The current total deposited amount of the staking token. |
addStakingToken
Adds a new staking token to the contract.
function addStakingToken(address stakingToken, address rewardDistributioner) external;
Parameters
Name | Type | Description |
---|---|---|
stakingToken | address | The address of the staking token to add. |
rewardDistributioner | address | The address allowed to notify new rewards for the staking token. |
setRewardsDuration
Sets the duration of the rewards period for a given staking token.
function setRewardsDuration(address stakingToken, uint256 rewardsDuration_) external onlyRole(TIMELOCK_ROLE);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | address | The address of the staking token to set the rewards duration for. |
rewardsDuration_ | uint256 | The new duration of the rewards period. |
recoverERC20
Allows recovery of ERC20 tokens other than the staking and rewards tokens.
Added to support recovering LP Rewards from other systems such as BAL to be distributed to holders
function recoverERC20(address tokenAddress, address to, uint256 tokenAmount) external onlyRole(DEFAULT_ADMIN_ROLE);
Parameters
Name | Type | Description |
---|---|---|
tokenAddress | address | The address of the token to recover. |
to | address | The address to send the recovered tokens to. |
tokenAmount | uint256 | The amount of tokens to recover. |
getRewardForDuration
Calculates the total reward for a given duration for a staking token.
function getRewardForDuration(address stakingToken) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | address | The address of the staking token. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The total reward for the given duration. |
rewardToken
Returns the address of the rewards token.
function rewardToken() external view returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the rewards token. |
stakingDelegate
Returns the address of the staking delegate.
function stakingDelegate() external view returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the staking delegate. |
lastTimeRewardApplicable
Calculates the last time a reward was applicable for the given staking token.
function lastTimeRewardApplicable(address stakingToken) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | address | The address of the staking token. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The last applicable timestamp for rewards. |
rewardPerToken
Calculates the accumulated reward per token stored.
function rewardPerToken(address stakingToken) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | address | The address of the staking token. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The accumulated reward per token. |
_rewardPerToken
function _rewardPerToken(address stakingToken, uint256 currentTotalDeposited) internal view returns (uint256);
earned
Calculates the amount of reward earned by an account for a given staking token.
function earned(address account, address stakingToken) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
account | address | The address of the user's account. |
stakingToken | address | The address of the staking token. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount of reward earned. |
_earned
function _earned(
address account,
address stakingToken,
uint256 userBalance,
uint256 rewardPerToken_
)
internal
view
returns (uint256);
_getReward
Updates the reward state for a given user and staking token. If there are any rewards to be paid out, they are sent to the receiver that was set by the user. (Defaults to the user's address if not set)
function _getReward(address user, address stakingToken) internal;
Parameters
Name | Type | Description |
---|---|---|
user | address | The address of the user to update rewards for. |
stakingToken | address | The address of the staking token. |
_updateReward
function _updateReward(address account, address stakingToken) internal;
_updateReward
Updates reward state for a given user and staking token.
function _updateReward(
address account,
address stakingToken,
uint256 currentUserBalance,
uint256 currentTotalDeposited
)
internal;
Parameters
Name | Type | Description |
---|---|---|
account | address | The address of the user to update rewards for. |
stakingToken | address | The address of the staking token. |
currentUserBalance | uint256 | |
currentTotalDeposited | uint256 |
Events
RewardAdded
Emitted when rewards are added for a staking token.
event RewardAdded(address indexed stakingToken, uint256 rewardAmount, uint256 rewardRate, uint256 start, uint256 end);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | address | The staking token for which rewards are added. |
rewardAmount | uint256 | The amount of rewards added. |
rewardRate | uint256 | The rate at which rewards will be distributed. |
start | uint256 | The start time of the reward period. |
end | uint256 | The end time of the reward period. |
StakingTokenAdded
Emitted when a staking token is added to the rewards program.
event StakingTokenAdded(address indexed stakingToken, address rewardDistributioner);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | address | The staking token that was added. |
rewardDistributioner | address | The address authorized to distribute rewards for the staking token. |
UserBalanceUpdated
Emitted when a user's balance is updated for a staking token.
event UserBalanceUpdated(address indexed user, address indexed stakingToken);
Parameters
Name | Type | Description |
---|---|---|
user | address | The user whose balance was updated. |
stakingToken | address | The staking token for which the balance was updated. |
RewardPaid
Emitted when rewards are paid out to a user for a staking token.
event RewardPaid(address indexed user, address indexed stakingToken, uint256 reward, address receiver);
Parameters
Name | Type | Description |
---|---|---|
user | address | The user who received the rewards. |
stakingToken | address | The staking token for which the rewards were paid. |
reward | uint256 | The amount of rewards paid. |
receiver | address | The address that received the rewards. |
RewardsDurationUpdated
Emitted when the rewards duration is updated for a staking token.
event RewardsDurationUpdated(address indexed stakingToken, uint256 newDuration);
Parameters
Name | Type | Description |
---|---|---|
stakingToken | address | The staking token for which the duration was updated. |
newDuration | uint256 | The new duration for rewards. |
Recovered
Emitted when tokens are recovered from the contract.
event Recovered(address token, uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
token | address | The address of the token that was recovered. |
amount | uint256 | The amount of the token that was recovered. |
RewardReceiverSet
Emitted when a user sets a reward receiver address.
event RewardReceiverSet(address indexed user, address receiver);
Parameters
Name | Type | Description |
---|---|---|
user | address | The user who set the reward receiver. |
receiver | address | The address set as the reward receiver. |