BGTStaker
A contract that enables BGT token holders to stake their tokens and earn dApp fees without transferring their tokens. This contract acts as a non-custodial staking solution where BGT tokens remain in the holder's wallet while still allowing them to participate in fee distribution. The contract integrates with the FeeCollector to distribute protocol fees to BGT delegators.
Inherits: IBGTStaker, OwnableUpgradeable, UUPSUpgradeable, StakingRewards
Constants
FEE_COLLECTOR
The fee collector contract that is allowed to notify rewards.
address public FEE_COLLECTOR;
State Variables
lastUpdateTime
The last time the rewards were updated.
uint256 public lastUpdateTime;
periodFinish
The end of the current reward period.
uint256 public periodFinish;
rewardPerTokenStored
The last updated reward per token scaled by PRECISION.
uint256 public rewardPerTokenStored;
rewardRate
The reward rate for the current reward period scaled by PRECISION.
uint256 public rewardRate;
rewardToken
The ERC20 token in which rewards are denominated and distributed.
IERC20 public rewardToken;
rewardsDuration
The time over which the rewards will be distributed.
uint256 public rewardsDuration;
stakeToken
The ERC20 token which users stake to earn rewards.
IERC20 public stakeToken;
totalSupply
The total supply of the staked tokens.
uint256 public totalSupply;
undistributedRewards
The amount of undistributed rewards scaled by PRECISION.
uint256 public undistributedRewards;
View Functions
balanceOf
Get the balance of the staked tokens for an account.
function balanceOf(address account) public view virtual returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
account | address | The account to get the balance for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The balance of the staked tokens |
earned
Retrieves the amount of reward earned by a specific account.
function earned(address account) public view virtual returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
account | address | The account to calculate the reward for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount of reward earned by the account |
getRewardForDuration
Retrieves the total reward vested over the specified duration.
function getRewardForDuration() public view virtual returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The total reward vested over the duration |
lastTimeRewardApplicable
Returns the timestamp of the last reward distribution. This is either the current timestamp (if rewards are still being actively distributed) or the timestamp when the reward duration ended (if all rewards have already been distributed).
function lastTimeRewardApplicable() public view virtual returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The timestamp of the last reward distribution |
rewardPerToken
Retrieves the current value of the global reward per token accumulator. This value is the sum of the last checkpoint value and the accumulated value since the last checkpoint. It should increase monotonically over time as more rewards are distributed.
function rewardPerToken() public view virtual returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The current value of the global reward per token accumulator scaled by 1e18 |
rewards
Get the reward balance for a specific account.
function rewards(address account) public view virtual returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
account | address | The account to retrieve the reward balance for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The current reward balance of the specified account |
userRewardPerTokenPaid
Get the user reward per token paid.
function userRewardPerTokenPaid(address account) public view virtual returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
account | address | The account to retrieve the reward for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The current reward balance of the specified account |
Functions
initialize
Initializes the contract.
Emits:
function initialize(
address _bgt,
address _feeCollector,
address _governance,
address _rewardToken
) external initializer;
Parameters
Name | Type | Description |
---|---|---|
_bgt | address | The BGT token address |
_feeCollector | address | The fee collector address |
_governance | address | The governance address |
_rewardToken | address | The reward token address |
notifyRewardAmount
Notify the staker of a new reward amount.
Can only be called by the fee collector.
Emits:
function notifyRewardAmount(uint256 reward) external onlyFeeCollector;
Parameters
Name | Type | Description |
---|---|---|
reward | uint256 | The amount of reward to notify |
recoverERC20
Recover ERC20 tokens.
Revert if the tokenAddress is the reward token.
Can only be called by the owner.
Emits:
function recoverERC20(address tokenAddress, uint256 tokenAmount) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
tokenAddress | address | The address of the token to recover |
tokenAmount | uint256 | The amount of token to recover |
setRewardsDuration
Set the rewards duration.
Revert if the reward cycle has started.
Can only be called by the owner.
Emits:
function setRewardsDuration(uint256 _rewardsDuration) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_rewardsDuration | uint256 | The rewards duration |
stake
Stake BGT tokens.
Can only be called by the BGT contract.
Emits:
function stake(address account, uint256 amount) external onlyBGT;
Parameters
Name | Type | Description |
---|---|---|
account | address | The account to stake for |
amount | uint256 | The amount of BGT to stake |
withdraw
Withdraw BGT tokens.
Can only be called by the BGT contract.
Emits:
function withdraw(address account, uint256 amount) external onlyBGT;
Parameters
Name | Type | Description |
---|---|---|
account | address | The account to withdraw for |
amount | uint256 | The amount of BGT to withdraw |
getReward
Get the reward.
Get the reward for the caller.
Emits:
function getReward() external returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The reward amount |
upgradeToAndCall
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual override onlyOwner;
Events
Initialized
Emitted when the contract is initialized.
event Initialized(uint64 version);
Parameters
Name | Type | Description |
---|---|---|
version | uint64 | The initialization version |
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 |
Recovered
Emitted when a token has been recovered.
event Recovered(address token, uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
token | address | The token that has been recovered |
amount | uint256 | The amount of token recovered |
RewardAdded
Emitted when a reward has been added to the vault.
event RewardAdded(uint256 reward);
Parameters
Name | Type | Description |
---|---|---|
reward | uint256 | The amount of reward added, scaled by PRECISION |
RewardPaid
Emitted when a reward has been claimed.
event RewardPaid(address indexed account, address to, uint256 reward);
Parameters
Name | Type | Description |
---|---|---|
account | address | The account whose reward has been claimed |
to | address | The address that the reward was sent to (user or operator) |
reward | uint256 | The amount of reward claimed |
RewardsDurationUpdated
Emitted when the reward duration has been updated.
event RewardsDurationUpdated(uint256 newDuration);
Parameters
Name | Type | Description |
---|---|---|
newDuration | uint256 | The new duration of the reward |
Staked
Emitted when the staking balance of an account has increased.
event Staked(address indexed account, uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
account | address | The account that has staked |
amount | uint256 | The amount of staked tokens |
Upgraded
Emitted when the implementation is upgraded.
event Upgraded(address indexed implementation);
Parameters
Name | Type | Description |
---|---|---|
implementation | address | The new implementation address |
Withdrawn
Emitted when the staking balance of an account has decreased.
event Withdrawn(address indexed account, uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
account | address | The account that has withdrawn |
amount | uint256 | The amount of withdrawn tokens |