Badger Finance
Calculation of Vault Scheduled Rewards
The logic of calculating scheduled rewards was similar to tree rewards calculation, when only one snapshot was taken per user in the end of the cycle.
That caused problems, as there is a high chance that some of users will deposit their funds at the end of the cycle and still get full reward amount. This results in reduced rewards for other users who had balances deposited during the entire cycle.
We solved this by taking multiple snapshots for different blocks during cycle, averaging each user balance.

Example 1:

User deposits funds at the beginning of the cycle and their balance doesn't change during the rewards cycle. Other user's balances also remain unchanged.
user_balance_in_vault = 100
totals = 10000
For vault scheduled rewards we take only 3 snapshots, at the start, end and somewhere in the middle of cycle.
Let's assume this user had 1000 boost since they are holding some amount of Badger tokens. Other users have no boost.
user_balance = user_balance_in_vault * NUMBER_OF_SNAPSHOTS * 1000 == 300000
Now, totals will also change, as user balance was boosted
totals = (totals - user_balance_in_vault) * NUMBER_OF_SNAPSHOTS + user_balance
After that same action is done to identify what is user's share of the vault total balance:
twap_user_share = user_balance / totals == 0.91
User reward percentage will be 91**%** as ****their balance was boosted

Example 2 (more complex):

User with boost deposit funds at the end of the current rewards cycle.
user_balance_in_vault = 100 # User just deposited 100 tokens
totals = 9900 # As user didn't deposit their funds yet
Taking multiple snapshots again, user didn't have any balance at any snapshot taken during cycle except the latest one. Also, user has a boost of 1000.
user_balance = (0 + 0 + user_balance_in_vault) * 1000 == 100000
totals = totals + totals + totals + user_balance
Let's calculate user's share in pool and make sure it's less than in the Example 1:
twap_user_share = user_balance / totals == 0.77
As we can see from the number of 77% user's rewards will decrease. So even if user deposited a large amount of tokens and gets boosted by the end of cycle, they will still get less rewards than previously, giving more rewards to users who had their balance unchanged since the beginning of cycle.
Copy link
On this page