totalSupply() :
This function returns the total supply of a token. It works by accessing the _totalSupply variable, which stores the total amount of tokens that have been created. (autogenerated documentation)
balanceOf(address) :
This function returns the balance of a given account. It works by accessing the _balances mapping, which stores the balances of all accounts, and returning the balance associated with the given account address. (autogenerated documentation)
lastTimeRewardApplicable() :
This function returns the timestamp of the last time a reward was applicable. It works by comparing the current block timestamp to the periodFinish timestamp. If the current block timestamp is less than the periodFinish timestamp, then the current block timestamp is returned, otherwise the periodFinish timestamp is returned. (autogenerated documentation)
rewardPerToken() :
This function calculates the reward per token for a given token contract. It does this by taking the stored reward per token, adding the amount of time since the last reward was applicable, multiplied by the reward rate, multiplied by 1e18, and then divided by the total supply of the token. This gives the amount of reward per token that is currently applicable. (autogenerated documentation)
earned(address) :
This function calculates the total rewards earned by a given account. It does this by multiplying the account's balance by the difference between the reward per token and the user reward per token paid, then dividing by 1e18 and adding the rewards for the account. (autogenerated documentation)
getRewardForDuration() :
This function returns the reward for a given duration. It works by multiplying the reward rate (which is set by the owner) by the rewards duration (which is also set by the owner). This allows the owner to set the reward rate and duration, and then use this function to calculate the total reward for that duration. (autogenerated documentation)
stake(uint256) :
This function allows a user to stake a certain amount of tokens. It requires that the amount is greater than 0, and then adds the amount to the total supply and the user's balance. It then transfers the amount from the user to the contract address, and emits an event to indicate that the user has staked the amount. (autogenerated documentation)
withdraw(uint256) :
This function allows a user to withdraw a specified amount of tokens from their account. It first checks that the amount is greater than 0, then subtracts the amount from the total supply and the user's balance. It then transfers the amount to the user's account using the safeTransfer function from the stakingToken contract. Finally, it emits an event to indicate that the withdrawal has been successful. (autogenerated documentation)
getReward() :
This function allows a user to claim a reward from the contract. It takes the sender's address as an argument and checks if there is a reward associated with it. If there is, it sets the reward to 0 and sends the reward to the sender using the rewardsToken contract. Finally, it emits an event to notify that the reward has been paid. (autogenerated documentation)
exit() :
This function allows a user to withdraw their balance from the contract and receive a reward. It works by first withdrawing the user's balance from the contract, then calling the getReward() function to give the user their reward. (autogenerated documentation)
notifyRewardAmount(uint256) :
This function is used to notify the reward amount for a given period. It takes in a uint256 reward as an argument and updates the reward rate accordingly. It first checks if the current block timestamp is greater than the period finish, and if so, sets the reward rate to the reward divided by the rewards duration. If not, it calculates the remaining time until the period finish, multiplies it by the reward rate, and then sets the reward rate to the reward plus the leftover amount divided by the rewards duration. It then checks if the provided reward is too high by comparing it to the balance of the rewards token divided by the rewards duration. Finally, it updates the last update time, period finish, and emits a RewardAdded event. (autogenerated documentation)
recoverERC20(address,uint256) :
This function allows the owner of the contract to recover a specified amount of ERC20 tokens from a given address. It first checks that the address is not the same as the address of the staking token, and then uses the IERC20 interface to safely transfer the specified amount of tokens from the given address to the owner's address. Finally, it emits an event to indicate that the tokens have been recovered. (autogenerated documentation)
setRewardsDuration(uint256) :
This function allows the owner of the contract to set the duration of the rewards period. It requires that the previous rewards period has been completed before the duration can be changed. Once the duration is set, an event is emitted to notify the users of the new rewards duration. (autogenerated documentation)