StakingPoolsERC721
The StakingPoolsERC721
provides staking pools for ERC721 tokens, earning a ERC20 reward token while staked.
Implementation¶
The StakingPoolsERC721
contract requires the following variables to be passed into the constructor:
Name | Type | Description |
---|---|---|
_stakingToken | address | The address of the ERC721 token that can be staked in the contract. |
_rewardToken | address | The address of the ERC20 token to be rewarded for staking. |
Usage¶
setStakingToken
- Set the address of the ERC721 token that can be staked in the contract.
_stakingToken
: Address of the ERC721 token.
setRewardToken
- Set the address of the ERC20 token to be rewarded for staking.
_receiver
: Address of the ERC20 token.
setStakingRewardCalculator
- Set the address of the IStakingRewardCalculator contract.
_stakingRewardCalculator
: Address of the contract.
addStakingPool
function addStakingPool(
bool _rewardWhileLocked,
uint256 _lockPeriod,
uint256 _reward
) external onlyOwner returns (uint256)
- Add a staking pool. The pool starts disabled.
_rewardWhileLocked
: Reward tokens can be claimed during the lock period._lockPeriod
: The lock period in seconds that the token will be locked._reward
: The amount of the ERC20 token to give at the end of the lock period.- Returns the index of the staking pool.
_addStakingPool
function _addStakingPool(
bool _rewardWhileLocked,
uint256 _lockPeriod,
uint256 _reward
) internal returns (uint256)
- Add a staking pool. The pool starts disabled.
_rewardWhileLocked
: Reward tokens can be claimed during the lock period._lockPeriod
: The lock period in seconds that the token will be locked._reward
: The amount of the ERC20 token to give at the end of the lock period.- Returns the index of the staking pool.
activateStakingPool
- Activate the given staking pool. Cannot activate an invalidated pool.
_index
: The index of the staking pool.
_activateStakingPool
- Activate the given staking pool. Cannot activate an invalidated pool.
_index
: The index of the staking pool.
deactivateStakingPool
- Deactivate the given staking pool. No new tokens can be staked in the pool, but existing tokens in the pool will continue to earn until unlocked.
_index
: The index of the staking pool.
invalidateStakingPool
- Invalidate the staking pool. No new tokens can be staked in the pool, and all existing tokens will be immediately unlocked. Unclaimed tokens will be lost.
_index
: The index of the staking pool.
stake
- Stake the token Ids in the given staking pool.
_poolIndex
: The index of the staking pool._tokenIds
: The list of tokenIds to stake in the pool.
unstake
- Unstake all unlocked tokens for the caller, and pay out any unclaimed rewards.
claimRewards
- Claim any unclaimed rewards for the caller.
rewardsAvailable
- Get balance of reward token available to claim by user.
_owner
: The owner to check balance for.- Returns the users reward balance.
stakingPoolCount
- Get the number of staking pools available.
- Returns the number of staking pools.
getStakedTokenIds
- Get a list of all staked token Ids for an owner.
_owner
: The owners address.- Returns a list of token Ids.
getLockedTokenIds
function getLockedTokenIds(address _owner, uint256 _poolIndex) external view returns (uint256, uint256[] memory)
- Get a list of all locked token Ids for an owner in a staking pool.
_owner
: The owners address._poolIndex
: The index of the staking pool.- Returns the count of token Ids, and a list of token Ids.
getUnlockedTokenIds
- Get a list of all unlocked token Ids for an owner.
_owner
: The owners address.- Returns the count of token Ids, and a list of token Ids.
getStakedTokenBalance
- Get the number of staked tokens by owner.
_owner
: The owners address.- Returns the number of tokens staked.
rewardsRatePerTimeUnit
- Calculate the current rewards rate for a user over a given amount of time.
_owner
: The owner to calculate for._timeUnit
: The time in seconds to calculate rewards over. i.e. 86400 seconds to calculate rewards per day.- Returns the calculated rewards rate.
Example¶
pragma solidity ^0.8.19;
import "@wraith-works/contracts/tokens/ERC721/StakingPoolsERC721.sol";
contract MyStakingPools is StakingPoolsERC721 {
constructor(address _stakingToken, address _rewardToken) StakingPoolsERC721(_stakingToken, _rewardToken) {
_addStakingPool(true, 86400, 1 * 10**18);
_activateStakingPool(0);
_addStakingPool(true, 86400 * 7, 10 * 10**18);
_activateStakingPool(1);
_addStakingPool(true, 86400 * 30, 50 * 10**18);
_activateStakingPool(2);
}
}