LastUpdateTime(can be any user)
TotalSupply(total staked amount)
Rewards[.](total reward added to the user so far)
PaidReward[.](Total rewards paid to all users so far)
RewardRate(reward to pay in return for a single token per second)
updateRewardsfunction is called before the staking action and the initial parameters are updated as follows.
rewards[A] and userRewardPerTokenPaid[A], are updated as follows.
totalSupply and balances[A].
totalSupply; let’s imagine a new user B staking 200 tokens assuming
t1is the current time.
rewards[B] and userRewardPerTokenPaid[B],are updated as follows.
totalSupply and balances[B].
rewardsPerTokenStored and lastUpdateTimeis updated as follows.
rewards[C] and userRewardPerTokenPaid[C],are updated as follows.
totalSupply and balances[C].
getRewardfunction also triggers the
updateRewardsfunction so the parameters are updated.
rewards[B], are updated as follows.
userRewardPerTokenPaid[B]is calculated as follows.
rewards[B]mapping that we just updated. The reward is sent to the user and is reset to 0 until they claim again at a later time. As seen from the calculations, the reward is calculated so that it does not account for the time period where B has not staked (There was only user A) but accounts for the time periods where there is
<A, B, C> separately. This algorithm handles every user’s rewards in the same way.
APR (Annual Percentage Rate)and
APY (Annual Percentage Yield)should be understood. Simply,
APRis simple and
APYis compound interest, reflecting the interest you make in your interest.
InterestReturnis the total interest paid over the life of the staking,
principalis the total deposit, and
nis the number of days in the total reward period. Hence, there is no rebasing or reinvesting included whereas, in the APY calculation, interest on the earned interest (reinvesting effect) is also considered.
Nis the compounding frequency (e.g., daily, weekly, monthly, quarterly, etc.) With every rebase, the returned interest reward is added to the stakers' balance automatically resulting in a higher compound rate in the next period.
APY, let's imagine that $OPN staking offers 100%
APRat a certain timeframe, and imagine this
APRcontinues to remain the same for over one year. Then, let
N = 365,i.e., if compounding frequency is daily, and let
Principal = $10,000then
71.4567%interest rate difference between
FutureValueof the user to
27,145.67which will be
20,000if compound interest wouldn't be considered, creating a
7,145.67extra interest. To compare the compound effect of the $OPN auto-compound staking pool with the simple staking pools, here is the graph representing the accumulated $OPN amount over time; the difference between auto-compounded capital and simple capital is increasing over time, reaching
7,145.67at the end of the first year and
43688.76at the end of the second year.
RealizedAPRis the actual
APRrate after subtracting protocol fees