Skip to main content

Discounting

Discounting

Discounting contract without a state which defines the relevant formulas for the navfeed

calcDiscount

function calcDiscount(uint256 discountRate, uint256 fv, uint256 normalizedBlockTimestamp, uint256 maturityDate) internal pure returns (uint256 result)

calculates the discount for a given loan

Parameters

NameTypeDescription
discountRateuint256the discount rate
fvuint256the future value of the loan
normalizedBlockTimestampuint256the normalized block time (each day to midnight)
maturityDateuint256the maturity date of the loan

Return Values

NameTypeDescription
resultuint256discount for the loan

calcFutureValue

function calcFutureValue(uint256 loanInterestRate, uint256 amount, uint256 maturityDate, uint256 recoveryRatePD) internal view returns (uint256 fv)

calculate the future value based on the amount, maturityDate interestRate and recoveryRate

Parameters

NameTypeDescription
loanInterestRateuint256the interest rate of the loan
amountuint256of the loan (principal)
maturityDateuint256the maturity date of the loan
recoveryRatePDuint256the recovery rate together with the probability of default of the loan

Return Values

NameTypeDescription
fvuint256future value of the loan

secureSub

function secureSub(uint256 x, uint256 y) internal pure returns (uint256 result)

substracts to values if the result smaller than 0 it returns 0

Parameters

NameTypeDescription
xuint256the first value (minuend)
yuint256the second value (subtrahend)

Return Values

NameTypeDescription
resultuint256result of the subtraction

uniqueDayTimestamp

function uniqueDayTimestamp(uint256 timestamp) internal pure returns (uint256 nTimestamp)

normalizes a timestamp to round down to the nearest midnight (UTC)

Parameters

NameTypeDescription
timestampuint256the timestamp which should be normalized

Return Values

NameTypeDescription
nTimestampuint256normalized timestamp

rpow

function rpow(uint256 x, uint256 n, uint256 base) internal pure returns (uint256 z)

rpow peforms a math pow operation with fixed point number adopted from ds-math

Parameters

NameTypeDescription
xuint256the base for the pow operation
nuint256the exponent for the pow operation
baseuint256the base of the fixed point number

Return Values

NameTypeDescription
zuint256the result of the pow operation