Reservoir
  • Introduction
    • Reservoir Overview
    • The Next-Gen Stablecoin
  • Products
    • Products Overview
    • Stablecoin - rUSD
    • Savings - srUSD
      • srUSD Calculations
    • Term - trUSD
      • trUSD Calculations
    • Lending Market
    • Proof of Reserves
  • Protocol Architecture
    • Architecture Overview
    • Credit Enforcer
    • Peg Stability Module
    • Term Issuer
    • Savings Module
    • Asset Adapters
  • Risk Management
    • Overview
  • Security & Compliance
    • FAQ
    • Smart Contract Addresses
    • Audit
    • Terms of Service
    • Risk Factors
  • Branding
    • Media Kit
Powered by GitBook
On this page
  • Term Discount
  • Term Cash Flows
  1. Products
  2. Term - trUSD

trUSD Calculations

PreviousTerm - trUSDNextLending Market

Last updated 12 months ago

Term Discount

Each term token (trUSD) comes with a cash flow rate, as well as a yield (discount rate), the protocol defines for newly issued trUSD. For a rUSD holder the cost for purchasing a term is:

c(1+r)n−p1+c(1+r)n−p2+...+Bi(1+r)n\frac{c}{(1 + r)^{n - p_{1}}} + \frac{c}{(1 + r)^{n - p_{2}}} + . . . + \frac{B_{i}}{(1 + r)^{n}}(1+r)n−p1​c​+(1+r)n−p2​c​+...+(1+r)nBi​​

Here BiB_{i}Bi​ is the trUSD balance for index iii as described in the trUSD section, rrr is the discount rate, nnn is the number of days until maturity, pjp_{j}pj​ is the number of days until maturity for the jjjth cash flow date, and ccc is the cash flow payment determined as a fixed percentage of the trUSD balance, BiB_{i}Bi​. We discount the balance daily, which makes for a large exponent. To calculate this in Solidity it helps to convert the discount formula into a :

(1+r)n≈1+nr+n(n−1)2r2(1 + r)^{n} \approx 1 + n r + \frac{n (n - 1)}{2} r^{2}(1+r)n≈1+nr+2n(n−1)​r2

Then standardizing to 18 decimals, the formula is converted to:

1∗1018+nr∗1018+n(n−1)2r2∗1018=1∗1018+n∗(r∗1018)+n(n−1)2∗(r365∗109)2\begin{align*}1 * 10^{18} & + n r * 10^{18} + \frac{n (n - 1)}{2} r^{2} * 10^{18} \\ & = 1 * 10^{18} + n * \left( r * 10^{18} \right) + \frac{n (n - 1)}{2} * \left(\frac{r}{365} * 10^{9} \right)^{2} \end{align*}1∗1018​+nr∗1018+2n(n−1)​r2∗1018=1∗1018+n∗(r∗1018)+2n(n−1)​∗(365r​∗109)2​

This enables an easy way to set a discount rate in a normal form as an APR such as 0.04 and have the Solidity math work out, replacing rrr with (0.04∗109)/365(0.04 * 10^9) / 365(0.04∗109)/365.

Term Cash Flows

The calculation for the total cash flow discount value can be converted into a closed formula. This avoids a loop, so the smart contract can support an arbitrary number of cash payments for any date of a maturing term, as well as minimizes gas costs overall. Since the time gap between coupon payments is fixed, each pj=δ∗jp_{j} = \delta * jpj​=δ∗j, where δ\deltaδ is a fixed constant. For, kkk cash flow payments, the total cost is:

c(1+r)n−p1+c(1+r)n−p2+...+c(1+r)n−pk=c(1+r)n−δ∗1+c(1+r)n−δ∗2+...+c(1+r)n−δ∗k=((1+r)δ∗1+(1+r)δ∗2+...(1+r)δ∗k)c(1+r)n\begin{align*} \frac{c}{(1 + r)^{n - p_{1}}} + \frac{c}{(1 + r)^{n - p_{2}}} + & . . . + \frac{c}{(1 + r)^{n - p_{k}}} \\ & = \frac{c}{(1 + r)^{n - \delta * 1}} + \frac{c}{(1 + r)^{n - \delta * 2}} + . . . + \frac{c}{(1 + r)^{n - \delta * k}} \\ & = \left((1 + r)^{\delta * 1} + (1 + r)^{\delta * 2} + . . . (1 + r)^{\delta * k} \right) \frac{c}{(1 + r)^{n}} \end{align*}(1+r)n−p1​c​+(1+r)n−p2​c​+​...+(1+r)n−pk​c​=(1+r)n−δ∗1c​+(1+r)n−δ∗2c​+...+(1+r)n−δ∗kc​=((1+r)δ∗1+(1+r)δ∗2+...(1+r)δ∗k)(1+r)nc​​
a−∑i=1k+1xi−1=a−a(1−xk+1)(1−x)=axk+1−x1−xa - \sum_{i = 1}^{k + 1} x^{i - 1} = a - \frac{a (1 - x^{k + 1})}{(1 - x)} = a \frac{x^{k + 1} - x}{1 - x}a−i=1∑k+1​xi−1=a−(1−x)a(1−xk+1)​=a1−xxk+1−x​

Now this formula can be converted into a form to apply the simplification. Take, x=(1+r)δx = (1 + r)^{\delta}x=(1+r)δ, a=c/(1+r)na = c / (1 + r)^{n}a=c/(1+r)n, and the equation above becomes:

Taylor series
geometric series