Farm
Inherits: FarmStorage, OwnableUpgradeable, ReentrancyGuardUpgradeable, MulticallUpgradeable
Author: Sperax Foundation.
This contract contains the core logic for the Demeter farms.
Functions
constructor
withdraw
Function to be called to withdraw deposit.
Parameters
claimRewards
A function to be called by the depositor to claim rewards.
Parameters
initiateCooldown
Function to be called to initiate cooldown for a staked deposit.
_depositId is corresponding to the user's deposit.
Parameters
addRewards
Add rewards to the farm.
Parameters
updateCooldownPeriod
Update the cooldown period.
Parameters
farmPauseSwitch
Pause / UnPause the farm.
Parameters
closeFarm
A function to explicitly close the farm.
Recovers remaining non accrued rewards.
recoverERC20
Recover erc20 tokens other than the reward tokens.
Parameters
recoverRewardFunds
Get the remaining reward balance out of the farm.
Function recovers minOf(_amount, rewardsLeft).
Parameters
setRewardRate
Function to update reward params for a fund.
Parameters
updateRewardData
Transfer the tokenManagerRole to other user.
Only the existing tokenManager for a reward can call this function.
Parameters
computeRewards
Function to compute the total accrued rewards for a deposit for each subscription.
Parameters
Returns
getRewardFunds
Get the reward fund details.
Returns
getRewardData
Get the reward details for specified reward token.
Parameters
Returns
getDepositInfo
Get deposit info for a deposit id.
Parameters
Returns
getNumSubscriptions
Get number of subscriptions for an account.
Parameters
Returns
getSubscriptionInfo
Get subscription stats for a deposit.
Parameters
Returns
getRewardRates
Get reward rates for a rewardToken.
Parameters
Returns
getRewardFundInfo
Get farm reward fund info.
Parameters
Returns
getRewardTokens
Function to get the reward tokens added in the farm.
Returns
getTokenAmounts
Function to be called by Demeter Rewarder to get tokens and amounts associated with the farm's liquidity.
This function should be overridden to add the respective logic.
Returns
updateFarmRewardData
Function to update the FarmRewardData for all funds.
claimRewardsTo
Claim rewards and send it to another account.
Only the depositor can call this function.
Parameters
updateFarmStartTime
Update the farm start time.
Can be updated only before the farm start. New start time should be in future.
Parameters
isFarmOpen
Returns if farm is open. Farm is open if it is not closed.
This function can be overridden to add any new/additional logic.
Returns
isFarmActive
Returns if farm is active. Farm is active if it is not paused and not closed.
This function can be overridden to add any new/additional logic.
Returns
getRewardBalance
Get the reward balance for specified reward token.
This function calculates the available reward balance by considering the accrued rewards and the token supply.
Parameters
Returns
_recoverERC20
_deposit
Common logic for deposit in the demeter farm.
Parameters
Returns
_initiateCooldown
Common logic for initiating cooldown.
Parameters
_withdraw
Common logic for withdraw.
Parameters
_updateAndClaimFarmRewards
Claim rewards for the user.
NOTE: any function calling this private function should be marked as non-reentrant.
Parameters
_updateAndClaimFarmRewardsTo
Claim rewards for the user and send it to another account.
NOTE: any function calling this private function should be marked as non-reentrant.
Parameters
_recoverRewardFunds
Get the remaining reward balance out of the farm.
Function recovers minOf(_amount, rewardsLeft).
In case of partial withdraw of funds, the reward rate has to be set manually again.
Parameters
_setRewardRate
Function to update reward params for a fund.
Parameters
_setupFarm
Function to setup the reward funds and initialize the farm global params during construction.
Parameters
_addRewardData
Adds new reward token to the farm.
Parameters
_updateLastRewardAccrualTime
Update the last reward accrual time.
_getAccRewards
Computes the accrued reward for a given fund id and time interval.
_alreadyAccRewardBal
is useful when this function called from computeRewards
function. As computeReward
is a view function and it doesn't update the accRewardBal
in the rewardData
.
Parameters
Returns
_validateDeposit
Validate the deposit for account.
Parameters
_validateNotRecentDeposit
A function to validate deposit ts to prevent flash loan vulnerabilities
Reverts when deposit made in the same transaction.
Parameters
_validateFarmOpen
Validate if farm is open. Revert otherwise.
This function can be overridden to add any new/additional logic.
_validateFarmActive
Validate if farm is active. Revert otherwise. Farm is active if it is not paused and not closed.
This function can be overridden to add any new/additional logic.
_validateTokenManager
Validate the caller is the token Manager. Revert otherwise.
Parameters
_validateRewardToken
Validate the reward token is valid.
Parameters
_getRewardAccrualTimeElapsed
Get the time elapsed since the last reward accrual.
Returns
_validateCooldownPeriod
An internal function to validate cooldown period.
Parameters
_validateNonZeroAddr
Validate address.
Parameters
_subscribeRewardFund
Add subscription to the reward fund for a deposit.
Parameters
_unsubscribeRewardFund
Unsubscribe a reward fund from a deposit.
The rewards claimed from the reward fund is persisted in the event.
Parameters