ContinuousIndexingMath
Author: M^0 Labs
State Variables
SECONDS_PER_YEAR
The number of seconds in a year.
BPS_SCALED_ONE
100% in basis points.
EXP_SCALED_ONE
The scaling of rates in for exponent math.
Functions
divideDown
Helper function to calculate (x * EXP_SCALED_ONE) / index
, rounded down.
Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
divideUp
Helper function to calculate (x * EXP_SCALED_ONE) / index
, rounded up.
Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
multiplyDown
Helper function to calculate (x * index) / EXP_SCALED_ONE
, rounded down.
Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
multiplyUp
Helper function to calculate (x * index) / EXP_SCALED_ONE
, rounded up.
Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
multiplyIndicesDown
Helper function to calculate (index * deltaIndex) / EXP_SCALED_ONE
, rounded down.
Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
multiplyIndicesUp
Helper function to calculate (index * deltaIndex) / EXP_SCALED_ONE
, rounded up.
Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
getContinuousIndex
Helper function to calculate e^rt (continuous compounding formula).
uint64 yearlyRate
can accommodate 1000% interest per year.
uint32 time
can accommodate 100 years.
type(uint64).max * type(uint32).max / SECONDS_PER_YEAR
fits in a uint72
.
exponent
Helper function to calculate y = e^x using R(4,4) Padé approximation: e(x) = (1 + x/2 + 3(x^2)/28 + x^3/84 + x^4/1680) / (1 - x/2 + 3(x^2)/28 - x^3/84 + x^4/1680) See: https://en.wikipedia.org/wiki/Pad%C3%A9_table See: https://www.wolframalpha.com/input?i=PadeApproximant%5Bexp%5Bx%5D%2C%7Bx%2C0%2C%7B4%2C+4%7D%7D%5D Despite itself being a whole number, x
represents a real number scaled by EXP_SCALED_ONE
, thus allowing for y = e^x where x is a real number.
Output y
for a uint72
input x
will fit in uint48
convertToBasisPoints
Helper function to convert 12-decimal representation to basis points.
Parameters
input
uint64
The input in 12-decimal representation.
Returns
<none>
uint40
The output in basis points.
convertFromBasisPoints
Helper function to convert basis points to 12-decimal representation.
Parameters
input
uint32
The input in basis points.
Returns
<none>
uint64
The output in 12-decimal representation.
Errors
DivisionByZero
Emitted when a division by zero occurs.