Tinlake uses an interest rate mechanism that is typically implemented as compounding per second. The implementation can be found in github.com/centrifuge/tinlake-math.
Below we show abstract examples of how this is calculated:
interest rate (5% would be 0.05)
the number of times the interest is compounded, compounding is once per second
Example: Interest rate compounding per second
Using the formula above, the Debt after half a year would be .
After one year () the would be .
Thus a 5.00% interest rate compounded every second is equivalent to an annually compounded rate of 5.127%.
This rate could also be calculated directly (using ):
To calculate the Debt, we initialize an interest rate in Tinlake with a variable called
Fee represents the interest accrued per second in Tinlake.
The debt can be calculated by multipling the principial
fee to the power of
t. The variable
t represents the time passed in seconds since the loan has been borrowed.
1Continuing the example from above for annual interest (t = 31536000):23fee = (1 + 0.05 / 31536000) = 1,0000000015854900.4D = 100 * 1,0000000015854900 ^ 31536000 = 105.1271.
Using an annual percentage rate (APR) in Tinlake
The current Tinlake implementation uses an annual percentage rate (APR) as input. Tinlake transforms this annually compounded rate
i into the equivalent rate used for compounding per secondes
r. This is achieved by solving the equation:
1i = (1 + r/n)^n
1r = n * (i^(1/n)-1)
Using the calculated
r compounding every second leads to the same amount of debt like using
i compounding annually over the course of a year. Thus, the calculated
r can be used to achive an interest per year (APR) behaviour with the compounding per second implementation in Tinlake.`
1Continuing the example from above with an 5.00% annual interest rate (APR):23i = 1.054n = 600 * 24 * 365 (= 31536000 seconds per year)5t = 3153600067r = 31536000 * ((1.05^(1 / 31536000) - 1) = 0.04879028fee = (1 + 0.0487902 / 31536000) = 1,0000000015471300.9D = 100 * 1,0000000015471300 ^ 31536000 = 105.00
Note: Some values in our contract are fixed precision decimals with 27 digits (type ray) precision and others 18 digits (type wad).