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
APR_PRECISION
REWARD_PERIOD
DENOMINATOR
ONE_YEAR
REWARD_TOKEN
REWARD_TOKEN_DECIMALS
totalRewardRate
rewarderFactory
calibrationRestricted
farmRewardConfigs
_decimals
Functions
constructor
initialize
Initializer function of this contract.
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.
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.
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.
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.
Parameters
_farm
address
Address of the farm.
_apr
uint256
APR in 1e8 precision.
toggleCalibrationRestriction
Function to toggle calibration restriction.
Parameters
_farm
address
Address of farm for which calibration restriction is to be toggled.
recoverERC20
Function to recover ERC20 tokens from this contract.
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.
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.
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.
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.
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.
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.
Parameters
_farm
address
Address of the farm.
_getTokenAmounts
An internal function to get token amounts for the farm.
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.
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.
Parameters
_addr
address
Address to be validated.
_calibrateReward
_setRewardRate
Function to set reward rate in the farm.
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.
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.
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.
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.
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.
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.
Parameters
_token
address
Token to be validated.
_oracle
address
Address of the oracle.
_validateRewardPer
Function to validate the no lockup fund's reward percentage.
Parameters
_percentage
uint256
No lockup fund's reward percentage to be validated.