Implementation of Compound Interest

Ethlizard's staking contract uses a unique method to calculate compound interest. Since it is impossible to store decimals in solidity, and there are overflow requirements, we are unable to calculate compound interest via a regular, simple means.

Instead, we use this formula to calculate continuous compound interest, using the ABDKMath64x64 library:

(1+r)t=2tā€‰ā‹…ā€‰logā”2(1+r)(1+r)^t = 2^{t\,\cdot\, \log_2(1+r)}

This is the result of converting a basic compound interest formula into the above via log laws.

(1+r)t=2logā”2((1+r)t)=2(tƗlogā”2(1+r))(1+r)^t = 2^{\log_2((1+r)^t)} = 2^{(t Ɨ \log_2(1+r))}

The value of (1+r)(1 + r) is stored in our contract in 64.64-bit binary fixed-point quadruple-precision binary floating-point numbers. This was an implementation allowed by the ABDKMaths64x64 library and allows the contract to calculate compound interest via calling the logarithm and exponent functions. We use an approximation of 1.0051.005 (the rebasing factor) in our contract.

The value of (1+r)(1 + r) in our contract is:

1.853897779407809941.85389777940780994

And this means our rebasing factor is:

1.00500000000000000140512601554121374647365882992744445800781251.0050000000000000014051260155412137464736588299274444580078125

The implementation of the above formulas is found within the function calculateRebasePercentage.

Last updated