trUSD Calculations
Last updated
Last updated
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 is the trUSD balance for index as described in the trUSD section, is the discount rate, is the number of days until maturity, is the number of days until maturity for the th cash flow date, and is the cash flow payment determined as a fixed percentage of the trUSD balance, . 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 :
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 with .
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 , where is a fixed constant. For, cash flow payments, the total cost is:
Now this formula can be converted into a form to apply the simplification. Take, , , and the equation above becomes: