Skip to content

BGTStaker

0x44F07Ce5AfeCbCC406e6beFD40cc2998eEb8c7C6 | ABI JSON

Git Source

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.

solidity
address public FEE_COLLECTOR;

State Variables

lastUpdateTime

The last time the rewards were updated.

solidity
uint256 public lastUpdateTime;

periodFinish

The end of the current reward period.

solidity
uint256 public periodFinish;

rewardPerTokenStored

The last updated reward per token scaled by PRECISION.

solidity
uint256 public rewardPerTokenStored;

rewardRate

The reward rate for the current reward period scaled by PRECISION.

solidity
uint256 public rewardRate;

rewardToken

The ERC20 token in which rewards are denominated and distributed.

solidity
IERC20 public rewardToken;

rewardsDuration

The time over which the rewards will be distributed.

solidity
uint256 public rewardsDuration;

stakeToken

The ERC20 token which users stake to earn rewards.

solidity
IERC20 public stakeToken;

totalSupply

The total supply of the staked tokens.

solidity
uint256 public totalSupply;

undistributedRewards

The amount of undistributed rewards scaled by PRECISION.

solidity
uint256 public undistributedRewards;

View Functions

balanceOf

Get the balance of the staked tokens for an account.

solidity
function balanceOf(address account) public view virtual returns (uint256);

Parameters

NameTypeDescription
accountaddressThe account to get the balance for

Returns

NameTypeDescription
<none>uint256The balance of the staked tokens

earned

Retrieves the amount of reward earned by a specific account.

solidity
function earned(address account) public view virtual returns (uint256);

Parameters

NameTypeDescription
accountaddressThe account to calculate the reward for

Returns

NameTypeDescription
<none>uint256The amount of reward earned by the account

getRewardForDuration

Retrieves the total reward vested over the specified duration.

solidity
function getRewardForDuration() public view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The 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).

solidity
function lastTimeRewardApplicable() public view virtual returns (uint256);

Returns

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

solidity
function rewardPerToken() public view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The current value of the global reward per token accumulator scaled by 1e18

rewards

Get the reward balance for a specific account.

solidity
function rewards(address account) public view virtual returns (uint256);

Parameters

NameTypeDescription
accountaddressThe account to retrieve the reward balance for

Returns

NameTypeDescription
<none>uint256The current reward balance of the specified account

userRewardPerTokenPaid

Get the user reward per token paid.

solidity
function userRewardPerTokenPaid(address account) public view virtual returns (uint256);

Parameters

NameTypeDescription
accountaddressThe account to retrieve the reward for

Returns

NameTypeDescription
<none>uint256The current reward balance of the specified account

Functions

initialize

Initializes the contract.

Emits:

solidity
function initialize(
    address _bgt,
    address _feeCollector,
    address _governance,
    address _rewardToken
) external initializer;

Parameters

NameTypeDescription
_bgtaddressThe BGT token address
_feeCollectoraddressThe fee collector address
_governanceaddressThe governance address
_rewardTokenaddressThe reward token address

notifyRewardAmount

Notify the staker of a new reward amount.

Can only be called by the fee collector.

Emits:

solidity
function notifyRewardAmount(uint256 reward) external onlyFeeCollector;

Parameters

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

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

Set the rewards duration.

Revert if the reward cycle has started.

Can only be called by the owner.

Emits:

solidity
function setRewardsDuration(uint256 _rewardsDuration) external onlyOwner;

Parameters

NameTypeDescription
_rewardsDurationuint256The rewards duration

stake

Stake BGT tokens.

Can only be called by the BGT contract.

Emits:

solidity
function stake(address account, uint256 amount) external onlyBGT;

Parameters

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

withdraw

Withdraw BGT tokens.

Can only be called by the BGT contract.

Emits:

solidity
function withdraw(address account, uint256 amount) external onlyBGT;

Parameters

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

getReward

Get the reward.

Get the reward for the caller.

Emits:

solidity
function getReward() external returns (uint256);

Returns

NameTypeDescription
<none>uint256The reward amount

upgradeToAndCall

solidity
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual override onlyOwner;

Events

Initialized

Emitted when the contract is initialized.

solidity
event Initialized(uint64 version);

Parameters

NameTypeDescription
versionuint64The initialization version

OwnershipTransferred

Emitted when ownership is transferred.

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

Parameters

NameTypeDescription
previousOwneraddressThe previous owner
newOwneraddressThe new owner

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

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 has been claimed.

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

Parameters

NameTypeDescription
accountaddressThe account whose reward has been claimed
toaddressThe address that the reward was sent to (user or operator)
rewarduint256The amount of reward claimed

RewardsDurationUpdated

Emitted when the reward duration has been updated.

solidity
event RewardsDurationUpdated(uint256 newDuration);

Parameters

NameTypeDescription
newDurationuint256The new duration of the reward

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

Upgraded

Emitted when the implementation is upgraded.

solidity
event Upgraded(address indexed implementation);

Parameters

NameTypeDescription
implementationaddressThe new implementation address

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