## Overview RAI Dollar(RD) is an immutable, $1 stablecoin backed only by ETH. RD uses features from Reflexer's RAI and Liquity's LUSD to achieve resilient stability around $1 under all market conditions. RD uses a floating par and variants of Liquity's Stability Pool. RD is redeemable for ETH, but swap liquidity is used for redemptions instead of vault collateral. **Collateralized Debt Position(CDP) stablecoin** Users lock ETH as collateral and mint RD as a loan with a minimum collateral ratio of 110%. The base loan interest rate is 0.5%, but the total loan rate can rise under certain market conditions. **Immutable** Upon launch, there is no dev or DAO control over the core protocol. The *only* modifiable attribute of RAI Dollar is the % of fees to share with the DAO and is bounded to the range of $[0, 30]$. **Floating Par** Par, the redemption value of RD, can float in order to create market price stability around $1. This is similar to RAI's floating peg, but unlike RAI, RAI Dollar uses the floating peg to target a $1 market price. **Redeemable for ETH** Each RD is redeemable for its par value of ETH minus a fee. The RAI Dollar protocol does not use borrower collateral for redemption, but uses swap liquidity. RD->ETH redemptions help enforce the price floor of RD. In some cases, the system can also support ETH->RD redemptions. These also use the par value of RD and contribute to market price stability. **System Liquidity Pool(SLP)** The protocol manages LP positions in an RD/ETH pool that is also used for redemptions and liquidations. This allows the protocol to use swap liquidity for redemption and avoid redemptions from vaults. Users add/remove RD/ETH liquidity through a manager contract in order to receive swap fees, loan fees, redemption fees, liquidation fees and governance rewards. RD->ETH redemptions are available only when the SLP RD balance is > 1% of supply. **System Surplus Pool(SSP)** An automated overflow pool for the SLP that uses surplus RD liquidity. Surplus RD liquidity results from removing 2-sided RD->ETH liquidity from the SLP for redemptions. This surplus RD is re-staked and earns ETH rewards from ETH->RD redemptions and liquidations. **Stability Pool(SP)** The protocol incorporates a Liquity-style Stability Pool to quickly process liquidations during ETH collateral shocks. RD only is locked in the SP and receives loan fees, liquidation profits and governance rewards. In cases where the amount of RD staked in the SP is greater than 20% of the supply, the SP will also support ETH->RD redemptions. **Loan Fees** RAI Dollar loans have a base interest rate of 0.5%. The system also controls an additive dynamic interest rate that can be raised in some market conditions, but it is expected the total interest rate will stay near 0.5%. An autonomous interest rate helps achieve sustainable market stability around $1. Fees from the autonomous rate are distributed to SLP and SP RD stakers. ## Protocol Operations ### Adding RD/ETH Liquidity ```mermaid sequenceDiagram Title Add RD/ETH Liquidity User->>Pool Manager: Add RD/ETH Liquidity Pool Manager->>Pair: Add RD/ETH Liquidity Pair->>Pool Manager: LP Tokens Pool Manager->>SLP: Stake LP Tokens Pair->>SLP: Swap fees ``` ### RD to ETH Redemptions When redeeming RD for ETH from the SLP, the protocol uses the par value of RD to determine the exchange rate. Redemptions do not decrease the outstanding supply of RD. The amount of ether received when redeeming $n$ tokens of RD is calculated as follows: $\displaystyle n_{eth} = \frac{n_{rd}\ p_{par}}{p_{eth/usd}}(1 - fee_{r})$ Where: $n_{eth}$: amount of ether received $n_{rd}$: number of RD redeemed $p_{par}$: current $par$ value of RD $p_{eth/usd}$: oracle value of ETH/USD $fee_r$: dynamic redemption fee(below) Let: $p_{market}$: market price of RD RD->ETH redemption arbitrage will be profitable when: $p_{market} < p_{par} - fee_{r}$ ```mermaid sequenceDiagram Title RD->ETH Redemption User->>Pool Manager: redeemRD() Pool Manager->>Pair: get RD balance alt if Pair RD balance > 1% supply User->>Pool Manager: Transfer RD Pool Manager->>SLP: Unstake LP Tokens SLP->>Pool Manager: Transfer LP Tokens Pool Manager->>Pair: Transfer LP Tokens Pair->>Pool Manager: Withdraw RD/ETH liquidity Pool Manager->>User: Transfer ETH Pool Manager->>SLP: Transfer ETH fee reward Pool Manager->>SSP: Stake surplus RD end ``` #### Dynamic RD->ETH Redemption Fee The purpose of the dynamic redemption fee this is to control short-term liquidity reduction in the SLP during periods of high redemption demand. RD->ETH Redemption fee is defined as: $fee_{r} = fee_{base} + fee_{dynamic}$ where: $fee_{base} = 0.5\%$ $fee_{dynamic}$: calculated as a decayed version of the existing dynamic fee plus a proportion of the % of RD liquidity that is being removed from the SLP. $fee_{dynamic_{t}} = \alpha^{\Delta t}fee_{dynamic_{t-1}} + c\frac{n_{rd}}{SLP_{rd}}$ where: $fee_{{dynamic}_{t}}$: $fee_{dynamic}$ at time $t$ $\alpha \approx 0.99998395506$, decay coefficient representing a half-life of 12 hours $c = 0.1$, constant $n_{rd}$: number of RD being redeemed $SLP_{nd}$: RD balance of the SLP #### Maintaining RD/ETH Liquidity during RD to ETH Redemptions As the system uses swap liquidity for redemptions, the protocol must ensure liquidity levels are maintained during long period of market conditions that favor redemption. eg: high risk-free US rates. The protocol addresses this in multiple ways: 1. Par mechanism As the $p_{market}$ rises to $p_{par}$ during redemptions, $p_{par}$ will respond and decrease. It will eventually reach $p_{par} < p_{market} + fee_r$, making RD->ETH redemptions unprofitable. This naturally throttles the rate of redemptions. Details of the floating par are below. 2. Interest rate mechanism As $p_{par}$ stays > $1, the total loan interest rate rises. This fee is directed to RD stakers in the SLP, SSP and SP, creating market demand for RD. This RD market demand helps increases the price alongside redemption demand. The increased $p_{market}$ eventually lowers $p_{par}$ and makes redemptions unprofitable, throttling the rate of redemptions. Details of the interest rate mechanism are below. 3. Dynamic redemption fee While the par and interest rate mechanisms help control SLP liquidity levels over longer trends, $fee_{r}$ helps control instantaneuous SLP liquidity reductions. Redemption amounts that severely reduce liquidity in the SLP incur a much large redemption fee and are deterred by the dynamic fee. 4. Increasing APY for RD/ETH Stakers As the System Liquidity Pool shrinks, the yield for RD/ETH stakers will increase and attract more RD/ETH liquidity. ### ETH to RD Redemptions If there is RD available in the SSP, a user can redeem ETH for it at $p_{par}$ with a fixed fee. The amount of RD received when redeeming is calculated as follows: $\displaystyle n_{rd} = \frac{n_{eth}\ p_{eth/usd}}{p_{par}}(1 - fee_{e})$ Where: $n_{rd}$: RD received $n_{eth}$: amount of ETH redeemed $p_{par}$: $par$ value of RD $p_{eth/usd}$: oracle value of ETH/USD $fee_e$: fixed redemption fee of 0.5% It follows that ETH->RD redemption arbitrage will be profitable when: $p_{market} > p_{par} + fee_{r}$ As ETH is redeemed for RD in the SSP, RD balance in the SSP drops and ETH rewards increase. ```mermaid sequenceDiagram Title ETH->RD Redemption User->>Pool Manager: redeemETH() Pool Manager->>SP: get RD balance Pool Manager->>SSP: get RD balance alt if SP RD balance > 20% RD supply User->>SP: Transfer ETH SP->>User: Transfer RD - fee else if SSP RD balance > 0 User->>SSP: Transfer ETH SSP->>User: Transfer RD -fee end ``` ### Liquidations Liquidations will be processed proportionately with RD in the SP and SSP. The ETH from the liquidated vault will be rewarded proportionately to the SP and SSP RD stakers. If there is not enough RD in the SP and SSP to fully liquidate the vault, the system will accept one of two actions. - Direct transfer of RD by liquidator to cover the liquidated troves debt. The liquidator receives all the vault's collateral. or - Redistribution of the liquidated vault's debt and collateral to all active vaults. ```mermaid sequenceDiagram Title Liquidation User->>Pool Manager: liquidateVault() Pool Manager->>SP: Get RD balance Pool Manager->>SSP: Get RD balance alt SP RD balance > 0 SP->>VaultManager: Transfer RD VaultManager->>SP: Transfer ETH else SSP RD balance > 0 SSP->>VaultManager: Transfer RD VaultManager->>SSP: Transfer ETH else SSP RD balance = 0 and SP RD balance = 0 VaultManager->>VaultManager: Redistribute Debt and Collateral end ``` ```mermaid sequenceDiagram Title Direct Liquidation with RD User->>VaultManager: liquidateVault() User->>VaultManager: Transfer RD VaultManager->>User: Transfer ETH ``` ## Par Mechanism $p_{par}$ is autonomously controlled by the protocol, adapting to $p_{market}$ and driving $p_{market}$ towards $1. $p_{par}$ is the redemption value of RD and also the value at which the system prices RD debt to determine collateralization ratio. While RAI also uses a floating par, the RAI market price is unbounded. RAI Dollar continuously attempts to target a constant $p_{market} =$ $1, providing a better value prop to many stablecoin holders and borrowers. ### Overview * If $p_{market}$ > $1, $p_{par}$ is lowered. * If $p_{market}$ < $1, $p_{par}$ is raised. * $p_{par}$ slowly decays towards $1 over time. ### $p_{market}$ Oracle As the protocol already retrieves $p_{eth\_usd}$ ETH/USD oracle for collateral pricing, it can leverage this existing price feed along with the SLP RD/ETH pool to provide an RD/USD oracle. $p_{market} = \left(\prod _{i=1}^{n}p_{{eth\_usd}_{i}}p_{{rd\_eth}_{i}}\right)^{\frac {1}{n}}$ *Unlike RAI, which sets the rate of $par$, RAI Dollar uses the $p_{market}$ oracle to directly set $par$.* To reduce incentive for manipulation, there will be a strict bound on how fast the $p_{market}$ value is allowed to change. Details on the $p_{market}$ oracle design and the SLP RD/ETH pool will be provided in a separate paper. ### Par Mechanism: Formal Definition Formally, the $p_{par}$ mechanism is a [PI](https://en.wikipedia.org/wiki/Proportional%E2%80%93integral%E2%80%93derivative_controller) controller with integral decay. It measures the error between $p_{market}$ and $1 and controls the value of $p_{par}$ Discrete PI w/ decay: $u_t = K_pe_{t} + K_i( \alpha^{\Delta t} \sum_{i=0}^{t-1}e_i \Delta t + e_{t}\Delta t) + u_0$ | Variable | Formal Name | System Value | | -------- | -------- | -------- | | $u_t$ | control variable | $p_{par}$| | $u_0$ | bias term, starting $p_{par}$ | $1| | $e_t$ | error, $r_t - y_t$ | $1 - $p_{market}$ | | $r_t$ | target | $1, constant | | $y_t$ | process output | $p_{market}$| | $\alpha$ | decay coefficent | decay coefficent | | $\sum_{i=0}^{t-1}e_i$ | integral | integral of error | | $K_p$ | proportional gain | weight of current error | | $K_i$ | integral gain | weight of historical error | ### Example: $p_{market}$ > $1 Consider $p_{market}$ above $1. In this case, the system **lowers** $p_{par}$ until $p_{market}$ responds and lowers to $1. ![image](https://hackmd.io/_uploads/rkWSpr7H1g.png) #### Why does $p_{market}$ drop in response to a lower $p_{par}$? ##### 1) Arbitrage Because of the minimum collateral ratio(CR) of 110%, there will be an immediate lock+mint+sell arbitrage when $p_{par} < 1/1.10$. The total market value of debt will be greater than the value of collateral locked, so arbitragers will lock collateral, sell the debt and "walk away". As long as $p_{market} >$ $ $1$, the system keeps lowering $p_{par}$. Market participants understand that eventually this will lead to the above abitrage and the market will inevitably go to $1. This threat of future arbitrage invokes market actors to sell before this happens. This arbitrage is the same mechanism used by Liquity and other CDP protocols to provide an upper bound on market price. *However, in RD's case the market price is driven to $1,* instead of an equilibrium between $1 and the upper bound. ##### 2) Higher Collateralization Ratio(CR) Lowering $p_{par}$ raises all vault CRs, making them safer from liquidation. This lowers $p_{market}$ by a) reducing demand for RD to re-pay debt and avoid liquidation b) increasing RD supply due to more room for debt to be drawn and sold ### Example: $p_{market}$ < $1 Consider a $p_{market}$ below $1. In this case, the system will raise $p_{par}$ until the market trades at $1. ![image](https://hackmd.io/_uploads/r1O6TrmHyx.png) #### Why does $p_{market}$ rise in response to a higher $p_{par}$? ##### 1) Redemption Arbitrage RD is directly redeemable at $p_{par}$ value in ETH for a small fee. Therefore, increasing $p_{par}$ will make buy+redeem arbitrarage more attractive, increasing $p_{market}$. Once this arbitrage makes $p_{market} >$ $ $1$ , $p_{par}$ will start to fall. Redemptions will eventually become unprofitable, and the $p_{market}$ will return to $1. ##### 2) Lower Collateral Ratio Raising $p_{par}$ lowers all vault collateral ratios, increasing the risk of liquidation and make lending less attractive. This raises $p_{market}$ due to a) increasing demand for RD to pay back debt and avoid liquidation b) decreased supply of RD due to less minting of new debt ## Par Simulations ### Simulation: $p_{market}$ > $1 This is a simulation of the RAI Dollar protocol during a $p_{market}$ price shock. The primary chart to consider is the $p_{par}$ and $p_{market}$ chart(top middle). #### Simulation Parameters: Simluation time: 7 days control period: 1 hour, how often $p_{par}$ is adjusted $K_p = 0.2$ $K_i = 9e^{-6}$ #### Simulation Actors: -Vault owners: repay and mint debt based on c-ratio -Redemption Arbitrageurs: RD to ETH and ETH to RD redemption arbitrage when it's profitable ![image](https://hackmd.io/_uploads/HkR51DA4Jg.png) #### Observations: **Timestep 1000-1500**: $p_{market}$ spikes to $1.05. $par$ decreases, making debt cheaper and ETH->RD arbitrage more profitable **Timestep 1900**: $p_{market}$ drops < $1 and converges to $p_{par}$. Since $p_{market}$ < $$1$, $p_{par} slowly starts to increase **Timestep 7700**: $p_{market}$ has converged back to $1. Remaining fluctuations are due to $p_{eth/usd}$ fluctuations as the simulation doesn't include strict arbitrageuers with other $1 stablecoins. ### Simulation: $p_{market}$ < $1 This is a simulation of the RAI Dollar protocol during a $p_{market}$ price shock. The simulation actors are vault owners and redemption arbitrageurs. The primary chart to consider is the $p_{par}$ and $p_{market}$ chart(top middle). #### Simulation Parameters: Simluation time: 7 days control period: 1 hour, how often $p_{par}$ is adjusted $K_p = 0.2$ $K_i = 9e^{-6}$ #### Simulation Actors: -Vault owners: repay and mint debt based on c-ratio -Redemption Arbitrageurs: RD to ETH and ETH to RD redemption arbitrage when it's profitable ![image](https://hackmd.io/_uploads/HkOmHPAN1l.png) #### Observations **Timestep 1000-1500**: $p_{market}$ drops to $0.95. $p_{par}$ increases, making debt more expensive and RD->ETH arbitrage more profitable **Timestep 1900**: $p_{market}$ rise > $1 and converges to $p_{par}$. Since $p_{market}$ > $$1$, $p_{par}$ slowly starts to decrease **Timestep 8200**: $p_{market}$ has converged back to $1. Remaining fluctuations are due to $p_{eth/usd}$ fluctuations as the simulation doesn't include strict arbitrageuers with other $1 stablecoins. ## Price Bounds **Upper Bound of $p_{market}$** The upper bound is re-inforced by lock-mint-sell arbitrage with a minimum c-ratio of 110%. Any market value above this price allows an immediate profit to abitrageurs and will be immediately corrected. $p_{market} <= 1.1 * p_{par}$ This is the practical upper bound of $p_{market}$ price for any $p_{par}$. Practically, $p_{market} <=$ $ $1.10$ Since the market price upper bound is dependent on par, it's *theoretically* possible to see $p_{market}>$ $$1.10$ For example: Let: $p_{par} =$ $$1.05$ then: $p_{market} <=$ $ $1.1 * 1.05 =$ $ $1.155$ However, in order for $p_{par}$ to reach $1.05 in the first place, $p_{market}$ price must have been previously depegged *down* below $1. So only immediately after a depegging < $1, can the market achieve a price > $1.10. This is unlikey but possible in volatile market conditions. However, it would still be immediately corrected by the system. As $p_{market}$ reaches $1.15 in the above scenario, $p_{par}$ will start to fall, eventually reaching $1. As $p_{par}$ reaches $1, $p_{market}$ will fall back to $1.10 due to arbitrage. **Lower Bound of $p_{market}$** The lower bound of $p_{market}$ is supported by redemptions, which are profitable when $p_{market} < p_{par} - fee_r$ The longer $p_{market}$ stays < $1, the higher $p_{par}$ will go, making redemption arbitrage more profitable. Long-term $p_{market}$ depeggings < $1 will be unlikely because of this. **Lower Bound of $p_{par}$** This lower bound is also re-inforced by lock-mint-sell arbitrage with a minimum c-ratio of 110%. $par_{lower} = p_{market}/1.10$ With $p_{market} >$ $1$, par will decrease until it reaches $p_{market}/1.10$. At this point arbitrage is possible and market will decrease to $1. When the market reaches $1, par will stop decreasing. Any deviation less than $1 by the market price will start an increase of par. So practically, $par_{lower} = 1/1.10 =$ $ $0.9090$ **Upper Bound of $p_{par}$** The practical upper bound of $p_{par}$ is expected to be a function of the risk-free rate. The more secondary markets price RD at a discount to other stablecoins, the higher $p_{par}$ will go. The max $p_{par}$ will be achieved when an equilibrium between redemption arbitrage and secondary markets(pricing RD at a discount due to risk-free rate) drives $p_{market}$ back up to $1 after a lower de-pegging. | Bound | Value | | -------- | -------- | | $p_{market}$ upper | $1.10 | | $p_{market}$ | $1 - $fee_r$ | | $p_{par}$ upper | $1 + $f(risk\_free\_rate)$ | | $p_{par}$ lower | $0.9090 | ## Interest Rate Mechanism The total interest rate for a loan is the sum of the base rate and dynamic rate. $rate_{total} = rate_{base} + rate_{dynamic}$ Where: $rate_{base}$: constant, $0.5\%\ annual$ $rate_{dynamic}$: dynamic >= $0\%$ The interest rate mechanism automatically controls $rate_{dynamic}$ to improve market price stability. ### Overview * If $p_{par}$ > $1, $rate_{dynamic}$ is raised. * If $p_{par}$ < $1, $rate_{dynamic}$ is lowered. * $rate_{dynamic}$ decays back to 0% over time ### Interest Rate Mechanism: Formal Definition The interest rate mechanism is a [PI](https://en.wikipedia.org/wiki/Proportional%E2%80%93integral%E2%80%93derivative_controller) controller. It measures the error between $p_{par}$ and $1 and controls the value of $rate_{dynamic}$. $rate_{dynamic} = max(0, K_pe_{t} + K_i( \sum_{i=0}^{t-1}e_i \Delta t + e_{t}\Delta t) + u_0)$ | Variable | Formal Name | System Value | | -------- | -------- | -------- | | $rate_{dynamic}$ | control variable | $rate_{dynamic}$| | $u_0$ | bias term, starting $rate_{dynamic}$ | 0| | $e_t$ | error, $r_t - y_t$ | $1 - $p_{par}$ | | $r_t$ | target | $1, constant | | $y_t$ | process output | $p_{par}$| | | $\sum_{i=0}^{t-1}e_i$ | integral | integral of error | | $K_p$ | proportional gain | weight of current error | | $K_i$ | integral gain | weight of historical error | ### Interest Rate Simulations Below is a simulation of RAI Dollar under a period of risk-free rates where RD is trading at a discount of 5% to other $1 yield-bearing stablecoins. #### Simulation Parameters: Simluation time: 7 days control period: how often rates are adjusted = 4 hours $K_p = 1e^{-10}$ $K_i = 1e^{-14}$ #### Simuation Actors: -Vault owners: repay and mint RD debt based on c-ratio -Redemption Arbitrageurs: RD to ETH and ETH to RD redemption arbitrage when it's profitable ![image](https://hackmd.io/_uploads/BydPnN5Vyx.png) #### Observations **Timestep 0**: $p_{market}$ initially trades < $1, (top middle) **Timestep 0-18000**: $p_{par}$ rises > $1 in response to $p_{market} <$ $ $1$, (top middle) **Timestep 0-20000**: $p_{market}$ rises as RD-> ETH redemption arbitrage happens, (top middle) **Timestep 0-70000**: To increase *non-redemption market demand*, $rate_{total}$ rises, (bottom right) **Timestep 20000**: Rising demand brings $p_{market}$ consistently >$1, (top middle) **Timestep 20000**: $p_{market} >$ $ $1$ causes $p_{par}$ to start correcting downwards, (top middle) **Timestep 80000**:(bottom right) $fee_{total}$ settles on an equilibrium rate, *which is equal to the discount RD is priced at on secondary markets* ## Fees and Rewards | Fees | System Liquidity Pool | System Surplus Pool |Stability Pool | | -------- | -------- | -------- |-------- | | Swap | $\checkmark$ | $\times$ |$\times$ | | Redemption | $\checkmark ^1$ | $\checkmark$ |$\checkmark ^2$ | | Liquidation | $\times$ | $\checkmark$ |$\checkmark$ | | Loan | $\checkmark$ | $\checkmark$ |$\checkmark$ | | Rewards | $\checkmark$ | $\checkmark$ |$\checkmark$ | $^1$: When RD balance > 1% supply $^2$: When RD balance > 20% supply