Badger Finance
Searchโ€ฆ
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.
1
NUMBER_OF_SNAPSHOTS = 3
2
user_balance_in_vault = 100
3
totals = 10000
Copied!
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.
1
user_balance = user_balance_in_vault * NUMBER_OF_SNAPSHOTS * 1000 == 300000
Copied!
Now, totals will also change, as user balance was boosted
1
totals = (totals - user_balance_in_vault) * NUMBER_OF_SNAPSHOTS + user_balance
Copied!
After that same action is done to identify what is user's share of the vault total balance:
1
twap_user_share = user_balance / totals == 0.91
Copied!
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.
1
NUMBER_OF_SNAPSHOTS = 3
2
user_balance_in_vault = 100 # User just deposited 100 tokens
3
totals = 9900 # As user didn't deposit their funds yet
Copied!
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.
1
user_balance = (0 + 0 + user_balance_in_vault) * 1000 == 100000
2
totals = totals + totals + totals + user_balance
Copied!
Let's calculate user's share in pool and make sure it's less than in the Example 1:
1
twap_user_share = user_balance / totals == 0.77
Copied!
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
Contents