-
Notifications
You must be signed in to change notification settings - Fork 5
Algorithm
Each farm instance has its own pool, that keeps track of vital data such as accumulatedRewardPerShare
. Each
pool can be updated only once per block - this is ensured by keeping track of lastBlockUpdate
.
Entrypoints %deposit
, %claim
, %withdraw
all call an updatePool()
function, causing the
pool to update with every first operation that 'arrives' to the farm in each block.
If there are no tokens delegated to the farm, which means if farmLpTokenBalance = 0n
then pool updates are skipped. Resulting
in no rewards being distributed, and only the lastBlockUpdate
being increased. If this behavior was not part of the implementation, then rewards would be lost for blocks when no-one is delegating to the farm.
If the calculated reward from the formula below exceeds the plannedRewards
, then a rewardRemainder
is returned instead.
Calculation of
plannedRewards
andrewardRemainder
can be found inupdatePool.religo
(Tezos.level - lastBlockUpdate) * rewardPerBlock
accumulatedRewardPerShare + reward / farmTokenBalance
delegatorReward = (accumulatedRewardPerShareEnd - accumulatedRewardPerShareStart) * delegatorBalance
accumulatedRewardPerShareEnd = current accumulatedRewardPerShare
accumulatedRewardPerShareStart = stakingStart