Overview
The design of the stablecoin has few concepts: lending-liquidating amm algorithm (LLAMMA), PegKeeper, Monetary Policy are the most important ones. But the main idea is in LLAMMA: replacing liquidations with a special-purpose AMM.
Figure 2: Dependence of the loss on the price shift relative to the liquidation threshold. Time window for the observation is 3 days
In this design, if someone borrows against collateral, even at liquidation threshold, and the price of collateral dips and bounces - no significant loss happen. For example, according to simulations using historic data for ETH/USD since Sep 2017, if one leaves the CDP unattended for 3 days and during this time the price drop of 10% below the liquidation threshold happened - only 1% of collateral gets lost.
AMM for continuous liquidation/deliquidation (LLAMMA)
The core idea of the stablecoin design is Lending-Liquidating AMM Algorithm. The idea is that it converts between collateral (for example, ETH) and the stablecoin (let’s call it USD here). If the price of collateral is high - a user has deposits all in ETH, but as it goes lower, it converts to USD. This is very different from traditional AMM designs where one has USD on top and ETH on the bottom instead.
The below description doesn’t serve as fully self-consistent rigorous proofs. A lot of that (especially the invariant) are obtained from dimensional considerations. More research might be required to have a full mathematical description, however the below is believed to be enough to implement in practice.
This is only possible with an external price oracle. In a nutshell, if one makes a typical AMM (for example with a bonding curve being a piece of hyperbola) and ramps its “center price” from (for example) down to up, the tokens will adiabatically convert from (for example) USD to ETH while proving liquidity in both ways on the way (Fig. 3). It is somewhat similar to avoided crossing (also called Landau-Zener transition) in quantum physics (though only as an idea: mathematical description of the process could be very different). The range where the liquidity is concentrated is calledbandhere, at the constantpoband has liquidity frompcdtopcu. We seek forpcd(po) andpcu(po) being functions ofpoonly, functions being more steep than linear and, hence, growing faster thanpo(Fig. 4). In addition, let’s defifine pricesp↓andp↑being prices wherep↓(po) =po, andp↑(po) =po, defining ends of bands in adiabatic limit (e.g.p=po).
We start from a number of bands where, similarly to Uniswap3, hyperbolic shape of the bonding curve is preserved by adding virtual balances. Let say, the amount of USD isx, and the amount of ETH isy, therefore the “amplifified” constant-product invariant would be:
Typically for a band, we knowp↑and, hence,p↓,po, constantA, and alsoxandy(current deposits in the band). To calculate everything, we need to findyo. It can be found by solving the quadratic equation for the invariant:
While oracle pricepostays constant, the AMM works in a normal way, e.g. sells ETH when going up / buys ETH when going down. By simply substitutingx= 0 for the “current down” pricepcdory= 0 for the “current up” pricepcuvalues into the equation of the invariant respectively, it is possible to show that AMM prices at the current value ofpoand the current value ofp↑are:
Now we have a description of one band. We split all the price space into bands which touch each other with pricesp↓andp↑so that if we set a base pricepbaseand have a band numbern:
Trades occur while preserving the invariant from Eq. 1, however the current price inside the AMM shifts when the pricepo: it goes up whenpogoes down and vice versa cubically, as can be seen from Eq. 8.
LLAMMA vs Stablecoin
Stablecoin is a CDP where one borrows stablecoin against a volatile collateral (cryptocurrency, for example, against ETH). The collateral is loaded into LLAMMA in such a price range (such bands) that if price of collateral goes down relatively slowly, the ETH gets converted into enough stablecoin to cover closing the CDP (which can happen via a self-liquidation, or via an external liquidation if the coverage is too close to dangerous limits, or not close at all while waiting for the price bounce).
When a user deposits collateral and borrows a stablecoin, the LLAMMA smart contract calculates the bands where to locate the collateral. When the price of the collateral changes, it starts getting converted to the stablecoin. When the system is “underwater”, user already has enough USD to cover the loan. The amount of stablecoins which can be obtained can be calculated using a public get_x_down method. If it gives values too close to the liquidation thresholds - an external liquidator can be involved (typically shouldn’t happen within a few days or even weeks after the collateral price went down and sideways, or even will not happen ever if collateral price never goes up or goes back up relatively quickly). A health method returns a ratio of get_x_down to debt plus the value increase in collateral when the price is well above “liquidation”.
When a stablecoin charges interest, this should be reflected in the AMM, too. This is done by adjusting all the grid of prices. So, when a stablecoin charges interest rate r, all the grid of prices in the AMM shifts upwards with the same rate r which is done via a base_price multiplier. So, the multiplier goes up over time as long as the charged rate is positive.
When we calculate get_x_down or get_y_up, we are first looking for the amounts of stablecoin and collateral x∗ and y∗ if current price moves to the current price po. Then we look at how much stablecoin or collateral we get if po adiabatically changes to either the lowest price of the lowest band, or the highest price of the highest band respectively. This way, we can get a measure of how much stablecoin we will which is not dependent on the current instantaneous price, which is important for sandwich attack resistance.
It is important to point out that the LLAMMA uses po defined as ETH/USD price as a price source, and our stablecoin could be traded under the peg (ps < 1) or over peg (ps > 1). If ps < 1, then price in the LLAMMA is p > po.
In adiabatic approximation, p = po/ps, and all the collateral<>stablecoin conversion would happen at a higher oracle price / as if oracle price was lower and equal to:
It is less desirable to have ps > 1 for prolonged times, and for that we will use the stabilizer (see next)
Automatic Stabilizer and Monetary Policy
Whenps >1 (for example, because of the increased demand for stablecoin), there is peg-keeping reserve formed by an asymmetric deposit into a stableswap Curve pool between the stablecoin and a redeemable reference coin or LP token. Onceps >1, the PegKeeper contract is allowed to mint uncollateralized stablecoin and (only!) deposit it to the stableswap pool single-sided in such a way that the final price after this is still no less than 1. Whenps <1, the PegKeeper is allowed to withdraw (asymmetrically) and burn the stablecoin.
These actions cause pricepsto quickly depreciate when it’s higher than 1 and appreciate if lower than 1 because asymmetric deposits and withdrawals change the price. Even though the mint is uncollateralized, the stablecoin appears to be implicitly collateralized by liquidity in the stablecoin pool. The whole mint/burn cycle appears, at the end, to be profitable while providing stability.
Let’s denote the amount of stablecoin minted to the stabilizer (debt) asdstand the function which calculates necessary amount of redeemable USD to buy the stablecoin in a stableswap AMM get_dx asfdx(). Then, in order to keep reserves not very large, we use the “slow” mechanism of stabilization via varying the borrowr:
Conclusion / 总结
The presented mechanisms can, hopefully, solve the riskiness of liquidations for stablecoin-making and borrowing purposes. In addition, stabilizer and automatic monetary policy mechanisms can help with peg-keeping without the need of keeping overly big PSMs.