Curve 稳定币设计白皮书(中英文参照版)
稳定币设计的核心思想是Lending-Liquidating AMM算法。
原文作者:JamesX ,iZUMi Research
原文来源:mirror
Curve 稳定币设计白皮书的中英文参照版本,加入一些辅助理解的中文注释,也修正了一些原版的拼写错误,供大家参考学习。
Subscribe
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.
这个稳定币的设计中有几个概念是最重要的:借贷-清算AMM算法(LLAMMA),PegKeeper(稳定保持机制),货币政策。但主要的设计点是在LLAMMA:用一个特殊用途的AMM代替传统超额抵押借贷的清算流程。
![Figure 2: Dependence of the loss on the price shift relative to the liquidation threshold. Time window for the observation is 3 days
图2:损失对相对于清算阈值的价格变动的依赖性。观察的时间窗口为3天
](https://images.mirror-media.xyz/publication-images/\_U6Ii9j2PLODLS07-HyTO.png?height=662&width=842)
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.
在这种设计中,如果有人用抵押品借款,即使是在清算阈值,抵押品的价格下跌后反弹--也不会发生明显的损失。例如,根据自2017年9月以来使用ETH/USD的历史数据进行的模拟,如果放着CDP无人看管3天,在此期间,价格下跌至低于清算价格10%的情况发生的话, 也只有1%的抵押品被损失。
AMM for continuous liquidation/deliquidation (LLAMMA)
持续清算/无需清算的AMM(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.
稳定币设计的核心思想是Lending-Liquidating AMM算法。这个想法是,它在抵押品(例如ETH)和稳定币(这里姑且称之为USD)之间进行转换。如果抵押品的价格很高--用户的存款都是ETH,但当价格降低时,它就会转换为USD稳定币。这与传统的AMM设计有很大不同,传统的AMM设计是将USD稳定币放在上面(AMM曲线上半截),ETH放在下面(AMM曲线下半截)。
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).
这只有通过外部预言机喂价才能实现。简而言之,如果一个人做了一个典型的AMM(例如,粘合曲线是一块双曲线),并将其 "中心价格 "从(例如)下降到上升,代币将从(例如)USD“绝热”地转换为ETH,同时在过程中提供两种方式的流动性(图3)。这有点类似于量子物理学中的“回避交叉”(也称为Landau-Zener跃迁)(虽然只是一个概念:对该过程的数学描述可能非常不同)。
流动性集中的范围在这里被称为“波段”(Band),在恒定的po波段有从pcd到pcu的流动性。我们寻求pcd(po)和pcu(po)只作为po的函数,函数比线性更陡峭,因此,增长速度比po快(图4)。此外,让我们把价格p↓和p↑定义为p↓(po)=po和p↑(po)=po的价格,定义为绝热极限中的波段两端(例如p=po)。
Figure 3: Behavior of an “AMM with an external price source”. External price pcenter determines a price around which liquidity is formed. AMM supports liquidity concentrated from prices pcd to pcu, pcd < pcenter < pcu. When current price p is out of range between pcd and pcu, AMM is either fully in stablecoin (when at pcu) or fully in collateral (when at pcd). When pcd ≤ p ≤ pcu, AMM price is equal to the current price p. 图3:"具有外部价格来源的AMM "的行为。外部价格pcenter决定了围绕流动性形成的一个价格。AMM支持流动性集中在价格pcd到pcu之间,pcd<pcenter<pcu。当当前价格p超出pcd和pcu之间的范围时,AMM要么完全进入稳定币(当在pcu时),要么完全进入抵押品(当在pcd时)。当pcd≤p≤pcu时,AMM价格等于当前价格p。
Figure 4: AMM which we search for. We seek to construct an AMM where pcd and pcu are such functions of po that when po grows, they grow even faster. In this case, this AMM will be all in ETH when ETH is expensive, and all in USD when ETH is cheap. 图4:我们寻找的AMM。我们试图构建一个AMM,其中pcd和pcu是po的函数,当po增长时,它们增长得更快。在这种情况下,当ETH昂贵时,这个AMM将全部转换为ETH,而当ETH便宜时,全部转换为USD。
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:
我们从一些波段开始,与Uniswap3类似,通过增加“虚拟余额”,保留了粘合曲线的双曲形状。比方说,USD的数量是x,ETH的数量是y,因此 "增强的 "常数-产品不变性将是:
We also can denotex0 ≡ x+fandy0 ≡ y+gso that the invariant can be written as a familiarI=x0 y0. However,fandgdo not stay constant: they change with the external price oracle (and so does the invariantI, so it is only the invariant while the oracle pricepois unchanged). At a givenpo,fandgare constant across the band. As mentioned before, we denotep↑as the top price of the band andp↓as the bottom price of the band. We defifineA(a measure of concentration of liquidity) in such a way that:
我们也可以表示x0≡x+f和y0≡y+g,这样不变式就可以写成熟悉的I=x0 y0。然而,f和g并不是保持不变的:它们随着外部预言机价格的变化而变化(不变量I也是如此,所以它只是在预言机价格po不变时的不变量)。在给定的po下,f和g在整个波段内是不变的。如前所述,我们把p↑表示为波段的顶部价格,p↓表示为波段的底部价格。我们对A(衡量流动性集中度的指标)的定义是这样的:
The property we are looking for is such that higher priceposhould lead to even higher price at the same balances, so that the current market price (which will, on average, followpo) is lower than that, and the band will trade towards being all in ETH (and the opposite is also true for the other direction). It is possible to find many ways to satisfy that but we need one:
我们正在寻找的属性是这样的:更高的价格po应该导致在相同的余额下更高的价格,因此,当前的市场价格(平均来说,将跟随po)低于这个价格,并且波段将朝着全部为ETH的方向交易(而另一个方向也是如此)。可以找到很多方法来满足,但我们需要这样一个:
wherey0 is ap0-dependent measure of deposits in the current band, denominated in ETH, defifined in such a way that when current pricep,p↑andpoare equal to each other, theny=y0 andx= 0 (see the point atpo=p↑on Fig. 4). Then if we substituteyat that moment:
其中y0是一个与p0相关的衡量当前波段存款的指标,以ETH为单位,其定义是:当当前价格p、p↑和po相互相等时,则y=y0,x=0(见图4上po=p↑的点)。那么,如果我们把那一刻的y替换掉:
Price is equal todx0 /dy0which then for a constant-product invariant is:
价格等于dx0 /dy0,那么对于一个恒定的产品不变量来说,就是:
One can substitute situations wherepo=p↑orpo=p↓withx= 0 ory= 0 correspndingly to verify that the above formulas are self-consistent.
我们可以用x=0或y=0来代替po=p↑或po=p↓的情况,以验证上述公式是自洽的。
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:
通常对于一个波段,我们知道p↑,因此也知道p↓、po、常数A,还有x和y(波段中的当前存款)。为了计算剩下的一切,我们需要找到yo。它可以通过解决不变量的二次方程来找到:
which turns into the quadratic equation againstyo:
这就变成了针对yo的二次方程:
In the smart contract, we solve this quadratic equation in get_y0 function.
在智能合约中,我们在get_y0函数中解决这个二次方程。
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:
在预言机价格po保持不变的情况下,AMM以正常的方式工作,例如,上涨时卖出ETH/下跌时买入ETH。通过简单地将x=0替换为 "当前下跌 "的价格pcd或y=0替换为 "当前上涨 "的价格pcu值分别代入不变量方程,就可以说明在po的当前值和p↑的当前值下的AMM价格是:
关于【Curve 稳定币设计白皮书(中英文参照版)】的延伸阅读
Base 链 DEX —— Aerodrome VS Curve
Velodrome是一个成功的DeFi案例,通过改进veCRV模板,实现了更优越的DEX模式。与Curve不同,Velodrome的流动性提供者不收取交易费用,而是通过VELO代币排放获得激励。通过仪表投票,veCRV/veVELO持有者决定每周发行的CRV/VELO代币分配比例。Velodrome避免了其他协议吞噬供应的可能性,并提供了类似于Convex的功能,但更简单。它正在成为超级链的基础流动性中心,可能会改变游戏规则。Velodrome已在Optimism上取得巨大成功,其产品套件包括收取和分配费用的DEX部分。
流动性提供者的博弈,Curve债务难题何解?
当场外交易的CRV变得可流动时,Curve将不得不经历另一次压力测试。
Another practically important question is: if price changes up or down so slowly that the oracle pricepois fully capable to follow itadiabatically, what amounty↑of ETH (if the price goes up) orx↓of USD (if the price goes down) will the band end up with, given current valuesxandyand that we start also atp=po. While it’s not an immediately trivial mathematical problem to solve, numeric computations showed a pretty simple answer:
另一个重要的实际问题是:如果价格的变化如此缓慢,以至于预言机价格po完全能够”绝热地”(在一个波段内)跟随它,那么在给定当前值x和y,并且我们也从p=po开始的情况下,这个波段最终会得到多少y↑的ETH(如果价格上涨)或x↓的USD(如果价格下跌)。虽然这不是一个立即可以解决的数学问题,但数字计算显示了一个相当简单的答案:
We will use these results when evaluating safety of the loan as well as the potential losses of the AMM.
在评估借贷的安全性以及AMM的潜在损失时,我们将使用这些结果。
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:
现在我们有了对一个波段的描述。我们把所有的价格空间分成若干波段,这些波段的价格p↓和p↑相互接触,因此,如果我们设定一个基础价格pbase,并有一个波段号n:
It is possible to prove that the solution of Eq. 7 and Eq. 5 for any band gives:
对于任何一个波段,可以证明公式7和公式5的解都可以得到:
which shows that there are no gaps between the bands.
这表明波段之间没有空隙。
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.
交易发生的同时保留了公式1的不变性,然而,当价格为po时,AMM内部的当前价格会发生变化:当po下降时,它就会上升,反之亦然(立方系数),从公式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).
稳定币是一种CDP,人们以不稳定的抵押品(加密货币,例如ETH)来借入稳定币。抵押品被加载到LLAMMA的价格范围内(这样的波段),如果抵押品的价格下降相对缓慢,ETH被转换成足够的稳定币来覆盖关闭CDP(这可以通过自我清算发生,或者通过外部清算,如果抵押率太接近危险的限制,或者根本不关闭,同时等待价格反弹)。
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”.
当用户存入抵押品并借入一个稳定币时,LLAMMA智能合约会计算出抵押品所在的波段。当抵押品的价格变化时,它开始被转换为稳定币。当系统处于 "水下 "时,用户已经有足够的USD来支付贷款。可以获得的稳定币数量可以通过一个公共的get_x_down方法来计算。如果它给出的数值过于接近清算阈值--外部清算人可以参与进来(通常不应该在抵押品价格下跌和横盘后的几天甚至几周内发生,甚至如果抵押品价格从未上涨或相对较快地回升,则永远不会发生)。当价格远高于 "清算 "时,一个健康的方法会返回get_x_down与债务的比率,再加上抵押品的价值增加。
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.
当一个稳定币收取利息时,这应该反映在AMM中。也要反映出来。这是通过调整价格的所有网格来实现的。因此,当一个稳定币 收取利率r时,AMM中的所有价格格都会向上移动,与 相同的利率r,这是通过一个基础价格乘数完成的。所以,只要收取的利率是正的,乘数会随着时间的推移而上升。
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.
当我们计算get_x_down或get_y_up时,我们首先要找的是如果当前价格移动到当前价格po的稳定币和抵押品x∗和y∗的数量。然后我们看一下,如果po绝热地变化到最低区间的最低价格,或最高区间的最高价格,我们分别得到多少稳定币或抵押品。这样,我们就可以得到一个衡量我们将获得多少稳定币的标准,它不依赖于当前的瞬时价格,这对夹层攻击的阻力很重要。**
**
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.
需要指出的是,LLAMMA使用定义为ETH/USD价格的po作为价格来源,我们的稳定币可以在挂钩之下(ps<1)或超过挂钩(ps>1)进行交易。如果ps<1,那么LLAMMA中的价格就是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:
在绝热近似中,p=po/ps,所有抵押品<>稳定币的转换将发生在较高的预言机价格上/就像预言机价格较低且等于:
At this price, the amount of stablecoins obtained at conversion is higher by factor of 1/ps (if ps < 1) .
在这个价格下,转换时获得的稳定币的数量要高出1/ps的系数(如果ps<1)。
It is less desirable to have ps > 1 for prolonged times, and for that we will use the stabilizer (see next)
在长时间内,ps>1是不太理想的,为此我们将使用稳定器(见下一章节)。
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.
当ps>1时(例如,由于对稳定币的需求增加),就会有锚定的储备,由稳定币和可赎回的参考币或LP代币之间的不对称存款到stableswap Curve池形成。 一旦ps>1,PegKeeper合约被允许铸造无抵押的稳定币,并且只将其单边存入stableswap池,这样做之后的最终价格仍然不低于1。当ps<1时,PegKeeper被允许提取(不对称地)并烧毁稳定币。
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.
这些行为导致价格ps高于1时迅速贬值,低于1时升值,因为不对称的存款和提款改变了价格。即使这部分“铸币”是没有抵押的,但稳定币似乎是由稳定币池中的流动性隐性抵押支持的。整个铸币/燃烧周期在最后似乎是有利可图的,同时提供了稳定性。
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:
让我们把铸造给稳定器(债务)的稳定币数量表示为dst,把计算在stableswap AMM get_dx中购买稳定币所需的可赎回USD数量的函数表示为fdx()。然后,为了保持“储备”不是非常大,我们通过改变借款r来使用 "缓慢 "的稳定机制。
wherehis the change inpsat which the raterchanges by factor of 2 (higherpsleads to lowerr). The amount of stabilizer debtdstwill equilibrate at different value depending on the rate atps= 1r0. Therefore, we can (instead of setting manually) be reducingr0 whiledst/supplyis larger than some target number (for example, 5%) (thereby incentivizing borrowers to borrow-and-dump the stablecoin, decreasing its price and forcing the system to burn thedst) or increasing if it’s lower (thereby incentivizing borrowers to return loans and pushingpsup, forcing the system to increase the debtdstand the stabilizer deposits).
其中h是ps的变化,速率r的变化为2倍(ps越高,r越低)。稳定器债务dst的数量将根据ps=1 r0的速率在不同的值上平衡。因此,我们可以(而不是手动设置)在dst/supply大于某个目标数字(例如5%)时减少r0(从而激励借款人借入并抛出稳定币,降低其价格并迫使系统燃烧dst),或者在它较低时增加(从而激励借款人归还贷款并推动ps上升,迫使系统增加债务dst和稳定器存款)。
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.
希望所提出的机制能够解决为制造稳定币和借贷目的而进行清算的风险性。此外,稳定器和自动货币政策机制可以帮助保持价格锚定,而不需要保持过大的PSM(Peg Stability Module 锚定稳定性模块)。
免责声明:本文仅代表作者个人观点,不代表链观CHAINLOOK立场,不承担法律责任。文章及观点也不构成投资意见。请用户理性看待市场风险,以及遵守所在国家和地区的相关法律法规。
图文来源:JamesX,如有侵权请联系删除。转载或引用请注明文章出处!