2024-09-10 01:47:59 +02:00
2024-09-09 22:23:01 +02:00
2024-09-10 00:03:33 +02:00
2024-09-10 01:08:53 +02:00
2024-09-10 01:47:59 +02:00
2024-09-10 01:08:53 +02:00
2024-09-09 22:23:01 +02:00
2024-09-09 22:23:01 +02:00
2024-09-10 01:47:59 +02:00
2024-09-10 01:37:37 +02:00

StakeManager

The rewardIndex is a crucial part of the reward distribution mechanism.

It represents the accumulated rewards per staked token since the beginning of the contract's operation.

Here's how it works:

1 - Initial state: When the contract starts, rewardIndex is 0. 2 - Whenever new rewards are added to the contract (detected in updateRewardIndex()), the rewardIndex increases. The increase is calculated as: rewardIndex += (newRewards * SCALE_FACTOR) / totalStaked This calculation distributes the new rewards evenly across all staked tokens. 3 - Each user has their own userRewardIndex, which represents the global rewardIndex at the time of their last interaction (stake, unstake, or reward claim). 4 - When a user wants to claim rewards, we calculate the difference between the current rewardIndex and the user's userRewardIndex, multiply it by their staked balance, and divide by SCALE_FACTOR 5 - After a user stakes, unstakes, or claims rewards, their userRewardIndex is updated to the current global rewardIndex. This "resets" their reward accumulation for the next period.

Instead of updating each user's rewards every time new rewards are added, we only need to update a single global variable (rewardIndex).

User-specific calculations are done only when a user interacts with the contract.

SCALE_FACTOR is used to maintain precision in calculations.

Description
No description provided
Readme 2.8 MiB
Languages
Ruby 96.8%
Shell 1.7%
Python 1.5%