Rewards program for the Algofi protocol.
The rewards methodology is in part inspired by AIP-16. Rewards are allocated pro-rata across the markets based on the weighted dollar value of the TVL in the underlying market. Consider the following market:
The ALGO, goBTC, and goETH weighted dollarized TVL are (600+50) * 1.8 * 1 = 1170mm, (0.002 + 0.001) * 61000 * 2 = 366mm, and (0.01 + 0.002) * 4200 * 2 = 100.8mm, respectively. The total weighted dollarized TVL is 1170 + 366 + 100.8 = 1636.8mm.
For example, if the protocol were issuing 100,000 ALGO tokens in rewards, then it would allocate 1170 / 1636.8 ~ 71% (71480 ALGOs), 366/1636.8 ~ 23% (22360 ALGOs), and 100.8/1636.8 ~ 6% (6160 ALGOs) of the rewards to the ALGO, goBTC, and goETH markets, respectively.
Then, within a given market, the protocol distributes the tokens on a pro-rata basis according to user supply TVL + borrow TVL. For example, within the ALGO market, the 71,480 tokens would be distributed evenly among the 600 + 50 = 650mm, resulting in ~109 ALGO tokens per 1mm of TVL.
To calculate rewards for a given market, a cumulative sum construction is used where every time the manager contract updates, the amount of rewards paid out / market TVL is saved down. This quantity is the market rewards coefficient:
where rewards paid to market m at time t is
- is rewards paid per second to the protocol
- is the time in seconds since the last manager update
- is the dollarized weighted TVL for market m at time t where a given market's TVL is scaled by its weight parameter:
- is the token TVL for market m at time t, the sum of the supply and borrow TVLs
To calculate the rewards accrued by a supplier or borrower of K tokens in market m between times t1 and t2, the difference between the two cumsum coefficients is calculated and scaled by the user's TVL: