# trUSD Calculations

### 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:

Here $B_{i}$ is the trUSD balance for index $i$ as described in the trUSD section, $r$ is the discount rate, $n$ is the number of days until maturity, $p_{j}$ is the number of days until maturity for the $j$th cash flow date, and $c$ is the cash flow payment determined as a fixed percentage of the trUSD balance, $B_{i}$. 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 Taylor series:

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

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 $r$ with $(0.04 * 10^9) / 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 $p_{j} = \delta * j$, where $\delta$ is a fixed constant. For, $k$ cash flow payments, the total cost is:

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

Last updated