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 per second
the number of times the interest is compounded, compounding is once per second, so "n" is seconds past since last calculation
Nominal interest rate (5% would be 0.05)
Annual Percentage Rate (APR)
constant, seconds in a year:
The basic formula is:
Debt equals to Principal (or the previous debt amount) times rate to the power of seconds since last calculation.
Using the formula above, the Debt after half a year would result in .
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%.
The annual percentage rate could also be calculated directly from the percentage rate (using ):
To calculate the Debt, we initialize an interest rate in Tinlake with a variable called
ratePerSecond or . The ratePerSecond represents the interest accrued per second in Tinlake.
The debt can be calculated by multipling the principial with to the power of . The variable represents the time passed in seconds since the loan has been borrowed.
Continuing the example from above for annual interest:
The Tinlake User Interface uses an annual percentage rate (APR) as input. Tinlake transforms this annually compounded rate into the equivalent rate used for compounding per seconds . This is achieved by solving the equation:
Using the calculated compounding every second leads to the same amount of debt like using compounding annually over the course of a year. Thus, the calculated
rate can be used to achive an interest per year (APR) behaviour with the compounding per second implementation in Tinlake.
Continuing the example from above with an 5.00% annual interest rate (APR):
We use fixed precision decimals for any monetary amounts. Interest Rates are typically of type
ray with 27 digits precision and amounts are of type
wad which has 18 digits precision.
This is usually explicitally mentioned in throught the codebase.