Rewarder
Inherits: IRewarder, OwnableUpgradeable, ReentrancyGuardUpgradeable
Author: Sperax Foundation.
This contract tracks farms, their APR and other data for a specific reward token.
Farms for UniV3 pools using Rewarder contract must have a minimum observationCardinality of 20. It can be updated by calling increaseObservationCardinalityNext function on the pool.
State Variables
MAX_PERCENTAGE
uint256 public constant MAX_PERCENTAGE = 1e4;
APR_PRECISION
uint256 public constant APR_PRECISION = 1e8;
REWARD_PERIOD
uint256 public constant REWARD_PERIOD = 1 weeks;
DENOMINATOR
uint256 public constant DENOMINATOR = 100;
ONE_YEAR
uint256 public constant ONE_YEAR = 365 days;
REWARD_TOKEN
address public REWARD_TOKEN;
REWARD_TOKEN_DECIMALS
uint8 public REWARD_TOKEN_DECIMALS;
totalRewardRate
uint256 public totalRewardRate;
rewarderFactory
address public rewarderFactory;
calibrationRestricted
mapping(address => bool) public calibrationRestricted;
farmRewardConfigs
mapping(address => FarmRewardConfig) internal farmRewardConfigs;
_decimals
mapping(address => uint8) private _decimals;
Functions
constructor
constructor();
initialize
Initializer function of this contract.
function initialize(address _rwdToken, address _oracle, address _admin) external initializer;
Parameters
_rwdToken
address
Address of the reward token.
_oracle
address
Address of the USDs Master Price Oracle.
_admin
address
Admin/ deployer of this contract.
calibrateReward
Function to calibrate rewards for this rewarder's reward token for a farm.
Calculates based on APR, caps based on maxRewardPerSec or balance rewards, sends and sets the rewardRate in the farm.
function calibrateReward(address _farm) external nonReentrant returns (uint256 rewardsToSend);
Parameters
_farm
address
Address of the farm for which the rewards are to be calibrated.
Returns
rewardsToSend
uint256
Rewards which are sent to the farm.
updateTokenManagerOfFarm
Function to update the token manager's address in the farm.
function updateTokenManagerOfFarm(address _farm, address _newManager) external onlyOwner;
Parameters
_farm
address
Farm's address in which the token manager is to be updated.
_newManager
address
Address of the new token manager.
recoverRewardFundsOfFarm
Function to recover reward funds from the farm.
function recoverRewardFundsOfFarm(address _farm, uint256 _amount) external onlyOwner;
Parameters
_farm
address
Farm's address from which reward funds is to be recovered.
_amount
uint256
Amount which is to be recovered.
updateAPR
Function to update APR.
function updateAPR(address _farm, uint256 _apr) external onlyOwner nonReentrant;
Parameters
_farm
address
Address of the farm.
_apr
uint256
APR in 1e8 precision.
toggleCalibrationRestriction
Function to toggle calibration restriction.
function toggleCalibrationRestriction(address _farm) external onlyOwner;
Parameters
_farm
address
Address of farm for which calibration restriction is to be toggled.
recoverERC20
Function to recover ERC20 tokens from this contract.
function recoverERC20(address _token, uint256 _amount) external onlyOwner;
Parameters
_token
address
Address of the token.
_amount
uint256
Amount of the tokens.
getTokenAmounts
Function to get token amounts value of underlying pool of the farm.
function getTokenAmounts(address _farm) external view returns (address[] memory, uint256[] memory);
Parameters
_farm
address
Address of the farm.
Returns
<none>
address[]
Array of token addresses.
<none>
uint256[]
getFarmRewardConfig
Function to get reward config for a farm.
function getFarmRewardConfig(address _farm) external view returns (FarmRewardConfig memory);
Parameters
_farm
address
Address of the farm.
Returns
<none>
FarmRewardConfig
FarmRewardConfig Farm reward config.
rewardsEndTime
Function to calculate the time till which rewards are there for an LP.
function rewardsEndTime(address _farm) external view returns (uint256 rewardsEndingOn);
Parameters
_farm
address
Address of the farm for which the end time is to be calculated.
Returns
rewardsEndingOn
uint256
Timestamp in seconds till which the rewards are there in farm and in rewarder.
updateRewardConfig
Function to update the REWARD_TOKEN configuration. This function calibrates reward so token manager must be updated to address of this contract in the farm.
function updateRewardConfig(address _farm, FarmRewardConfigInput memory _rewardConfig) public onlyOwner nonReentrant;
Parameters
_farm
address
Address of the farm for which the config is to be updated.
_rewardConfig
FarmRewardConfigInput
The config which is to be set.
_initialize
Internal initialize function.
function _initialize(address _rwdToken, address _oracle, address _admin, address _rewarderFactory) internal;
Parameters
_rwdToken
address
Address of the reward token.
_oracle
address
Address of the USDs Master Price Oracle.
_admin
address
Admin/ deployer of this contract.
_rewarderFactory
address
Address of Rewarder factory contract.
_isConfigured
Function to check if the farm's reward is configured.
function _isConfigured(address _farm) internal view;
Parameters
_farm
address
Address of the farm.
_getTokenAmounts
An internal function to get token amounts for the farm.
function _getTokenAmounts(address _farm) internal view virtual returns (address[] memory, uint256[] memory);
Parameters
_farm
address
Address of the farm.
Returns
<none>
address[]
Array of token addresses.
<none>
uint256[]
Array of token amounts.
_hasRewardToken
Function to check if the reward token of this contract is one of farm's reward token.
function _hasRewardToken(address _farm) internal view virtual returns (bool);
Parameters
_farm
address
Address of the farm.
Returns
<none>
bool
If farm has one of the reward token as reward token of this contract.
_validateNonZeroAddr
Validate address.
function _validateNonZeroAddr(address _addr) internal pure;
Parameters
_addr
address
Address to be validated.
_calibrateReward
function _calibrateReward(address _farm) private returns (uint256 rewardsToSend);
_setRewardRate
Function to set reward rate in the farm.
function _setRewardRate(address _farm, uint128 _rwdRate, uint256 _nonLockupRewardPer) private;
Parameters
_farm
address
Address of the farm.
_rwdRate
uint128
Reward per second to be emitted.
_nonLockupRewardPer
uint256
Reward percentage to be allocated to no lockup fund.
_adjustGlobalRewardRate
Function to adjust global rewards per second emitted for a reward token.
function _adjustGlobalRewardRate(uint256 _oldRewardRate, uint256 _newRewardRate) private;
Parameters
_oldRewardRate
uint256
Old emission rate.
_newRewardRate
uint256
New emission rate.
_isValidFarm
Function to validate farm.
It checks that the farm should implement getTokenAmounts and have REWARD_TOKEN. as one of the reward tokens.
function _isValidFarm(address _farm, address[] memory _baseTokens) private returns (bool);
Parameters
_farm
address
Address of the farm to be validated.
_baseTokens
address[]
Array of base tokens.
Returns
<none>
bool
bool True if farm is valid.
_hasBaseTokens
Function to check whether the base tokens are a subset of farm's assets.
It handles repeated base tokens as well and pushes indexed in farmRewardConfigs.
function _hasBaseTokens(address _farm, address[] memory _baseTokens) private returns (bool);
Parameters
_farm
address
Address of the farm.
_baseTokens
address[]
Array of base token addresses to be considered for value calculation.
Returns
<none>
bool
hasBaseTokens True if baseTokens are non redundant and are a subset of assets.
_normalizeAmount
Function to normalize asset amounts to be of precision REWARD_TOKEN_DECIMALS.
function _normalizeAmount(address _token, uint256 _amount) private view returns (uint256);
Parameters
_token
address
Address of the asset token.
_amount
uint256
Amount of the token.
Returns
<none>
uint256
Normalized amount of the token in _desiredPrecision.
_getPrice
Function to fetch and get the price of a token.
function _getPrice(address _token, address _oracle) private view returns (IOracle.PriceData memory priceData);
Parameters
_token
address
Token for which the the price is to be fetched.
_oracle
address
Address of the oracle contract.
Returns
priceData
IOracle.PriceData
Price data of the token.
_validatePriceFeed
Function to validate price feed.
function _validatePriceFeed(address _token, address _oracle) private view;
Parameters
_token
address
Token to be validated.
_oracle
address
Address of the oracle.
_validateRewardPer
Function to validate the no lockup fund's reward percentage.
function _validateRewardPer(uint256 _percentage) private pure;
Parameters
_percentage
uint256
No lockup fund's reward percentage to be validated.
Was this helpful?