Rewarder

Git Source

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

REWARD_TOKEN

REWARD_TOKEN_DECIMALS

totalRewardRate

rewarderFactory

calibrationRestricted

farmRewardConfigs

_decimals

Functions

constructor

initialize

Initializer function of this contract.

Parameters

Name
Type
Description

_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

Name
Type
Description

_farm

address

Address of the farm for which the rewards are to be calibrated.

Returns

Name
Type
Description

rewardsToSend

uint256

Rewards which are sent to the farm.

updateTokenManagerOfFarm

Function to update the token manager's address in the farm.

Parameters

Name
Type
Description

_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

Name
Type
Description

_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

Name
Type
Description

_farm

address

Address of the farm.

_apr

uint256

APR in 1e8 precision.

toggleCalibrationRestriction

Function to toggle calibration restriction.

Parameters

Name
Type
Description

_farm

address

Address of farm for which calibration restriction is to be toggled.

recoverERC20

Function to recover ERC20 tokens from this contract.

Parameters

Name
Type
Description

_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

Name
Type
Description

_farm

address

Address of the farm.

Returns

Name
Type
Description

<none>

address[]

Array of token addresses.

<none>

uint256[]

getFarmRewardConfig

Function to get reward config for a farm.

Parameters

Name
Type
Description

_farm

address

Address of the farm.

Returns

Name
Type
Description

<none>

FarmRewardConfig

FarmRewardConfig Farm reward config.

rewardsEndTime

Function to calculate the time till which rewards are there for an LP.

Parameters

Name
Type
Description

_farm

address

Address of the farm for which the end time is to be calculated.

Returns

Name
Type
Description

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

Name
Type
Description

_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

Name
Type
Description

_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

Name
Type
Description

_farm

address

Address of the farm.

_getTokenAmounts

An internal function to get token amounts for the farm.

Parameters

Name
Type
Description

_farm

address

Address of the farm.

Returns

Name
Type
Description

<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

Name
Type
Description

_farm

address

Address of the farm.

Returns

Name
Type
Description

<none>

bool

If farm has one of the reward token as reward token of this contract.

_validateNonZeroAddr

Validate address.

Parameters

Name
Type
Description

_addr

address

Address to be validated.

_calibrateReward

_setRewardRate

Function to set reward rate in the farm.

Parameters

Name
Type
Description

_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

Name
Type
Description

_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

Name
Type
Description

_farm

address

Address of the farm to be validated.

_baseTokens

address[]

Array of base tokens.

Returns

Name
Type
Description

<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

Name
Type
Description

_farm

address

Address of the farm.

_baseTokens

address[]

Array of base token addresses to be considered for value calculation.

Returns

Name
Type
Description

<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

Name
Type
Description

_token

address

Address of the asset token.

_amount

uint256

Amount of the token.

Returns

Name
Type
Description

<none>

uint256

Normalized amount of the token in _desiredPrecision.

_getPrice

Function to fetch and get the price of a token.

Parameters

Name
Type
Description

_token

address

Token for which the the price is to be fetched.

_oracle

address

Address of the oracle contract.

Returns

Name
Type
Description

priceData

IOracle.PriceData

Price data of the token.

_validatePriceFeed

Function to validate price feed.

Parameters

Name
Type
Description

_token

address

Token to be validated.

_oracle

address

Address of the oracle.

_validateRewardPer

Function to validate the no lockup fund's reward percentage.

Parameters

Name
Type
Description

_percentage

uint256

No lockup fund's reward percentage to be validated.