Skip to content

Latest commit

 

History

History
416 lines (203 loc) · 6.61 KB

RewardsPoolBase.md

File metadata and controls

416 lines (203 loc) · 6.61 KB

RewardsPoolBase

Base pool contract used in all other pools. Users can stake tokens and get rewards based on the percentage of total staked tokens. After deployment, owner can send funds and then start the pool. When it's started a check is done to verify enough rewards are available. Users can claim their rewards at any point, as well as withdraw their stake. The owner can extend the pool by setting a new end time and sending more rewards if needed.

Rewards are kept track of using the accumulatedRewardMultiplier. This variable represents the accumulated reward per token staked from the start until now. Based on the difference between the accumulatedRewardMultiplier at the time of your stake and withdrawal, we calculate the amount of tokens you can claim.

For example, you enter when the accumulatedRewardMultiplier is 5 and exit at 20. You staked 100 tokens. Your reward is (20 - 5) * 100 = 1500 tokens.

Inheritance

RewardsPoolBase
Ownable
Context

Variables

uint256 PRECISION;
uint256 totalStaked;
uint256[] rewardPerSecond;
address[] rewardsTokens;
contract IERC20 stakingToken;
uint256 startTimestamp;
uint256 endTimestamp;
uint256 extensionDuration;
uint256[] extensionRewardPerSecond;
uint256[] accumulatedRewardMultiplier;
uint256 stakeLimit;
uint256 contractStakeLimit;
string name;
mapping(address => struct RewardsPoolBase.UserInfo) userInfo;
struct RewardsPoolBase.Campaign[] previousCampaigns;

Functions

constructor

contract IERC20 _stakingToken; // The token to stake

address[] _rewardsTokens; // The reward tokens

uint256 _stakeLimit; // Maximum amount of tokens that can be staked per user

uint256 _contractStakeLimit; // Maximum amount of tokens that can be staked in total

string _name; // Name of the pool

start

Start the pool. Funds for rewards will be checked and staking will be opened.

uint256 _startTimestamp; // The start time of the pool

uint256 _endTimestamp; // The end time of the pool

uint256[] _rewardPerSecond; // Amount of rewards given per second

cancel

Cancels the scheduled start. Can only be done before the start.

stake

Stake an amount of tokens

uint256 _tokenAmount; // The amount to be staked

claim

Claim all your rewards, this will not remove your stake

withdraw

Withdrawing a portion or all of staked tokens. This will not claim your rewards

uint256 _tokenAmount; // The amount to be withdrawn

exit

Claim all rewards and withdraw all staked tokens. Exits from the rewards pool

balanceOf → uint256

Returns the amount of tokens the user has staked

address _userAddress; // The user to get the balance of

updateRewardMultipliers

Updates the accumulated reward multipliers for everyone and each token

hasStakingStarted → bool

Checks if the staking has started

getUserRewardDebt → uint256

Returns the amount of reward debt of a specific token and user

address _userAddress; // the address of the updated user

uint256 _index; // index of the reward token to check

getUserOwedTokens → uint256

Returns the amount of reward owed of a specific token and user

address _userAddress; // the address of the updated user

uint256 _index; // index of the reward token to check

getUserAccumulatedReward → uint256

Calculates the reward at a specific time

address _userAddress; // the address of the user

uint256 _tokenIndex; // the index of the reward token you are interested

uint256 _time; // the time to check the reward at

getUserTokensOwedLength → uint256

Returns the length of the owed tokens in the user info

address _userAddress; 

getUserRewardDebtLength → uint256

Returns the length of the reward debt in the user info

address _userAddress; 

getRewardTokensCount → uint256

Returns the amount of reward tokens

getPreviousCampaignsCount → uint256

Returns the amount of previous campaigns

extend

Extends the rewards period and updates the rates. When the current campaign is still going on, the extension will be scheduled and started when the campaign ends. The extension can be cancelled until it starts. After it starts, the rewards are locked in and cannot be withdraw.

uint256 _durationTime; // duration of the campaign (how many seconds the campaign will have)

uint256[] _rewardPerSecond; // array with new rewards per second for each token

cancelExtension

Cancels the schedules extension

getAvailableBalance → uint256

Calculates the available amount of reward tokens that are not locked

uint256 _rewardTokenIndex; // the index of the reward token to check

withdrawTokens

Withdraw tokens other than the staking and reward token, for example rewards from liquidity mining

address _recipient; // The address to whom the rewards will be transferred

address _token; // The address of the rewards contract

withdrawExcessRewards

Withdraw excess rewards not needed for current campaign and extension

address _recipient; // The address to whom the rewards will be transferred

owner → address

Returns the address of the current owner.

renounceOwnership

Leaves the contract without owner. It will not be possible to call onlyOwner functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.

transferOwnership

Transfers ownership of the contract to a new account (newOwner). Can only be called by the current owner.

address newOwner; 

Events

Started

uint256 startTimestamp;
uint256 endTimestamp;
uint256[] rewardsPerSecond;

Staked

address user;
uint256 amount;

Claimed

address user;
uint256 amount;
address token;

Withdrawn

address user;
uint256 amount;

Exited

address user;
uint256 amount;

Extended

uint256 newStartTimestamp;
uint256 newEndTimestamp;
uint256[] newRewardsPerSecond;

OwnershipTransferred

address previousOwner;
address newOwner;

Structs

UserInfo

uint256 firstStakedTimestamp;
uint256 amountStaked;
uint256[] rewardDebt;
uint256[] tokensOwed;

Campaign

uint256 startTimestamp;
uint256 endTimestamp;
uint256[] rewardPerSecond;