原文標題:《Curve 穩定幣設計白皮書 中英文參照版本》
原文作者:JamesX,iZUMi Research
Curve 穩定幣設計白皮書的中英文參照版本,加入一些輔助理解的中文註釋,也修正了一些原版的拼寫錯誤,供大家參考學習。
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 天
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 called band here, at the constant po band has liquidity from pcd to pcu.We seek for pcd(po) and pcu(po) being functions of po only, functions being more steep than linear and, hence, growing faster than po(Fig.4).In addition, let』s defifine prices pand p being prices where p(po) = po, and p(po) = po, defining ends of bands in adiabatic limit (e.g. p = po).
這只有通過外部預言機餵價才能實現。簡而言之,如果一個人做了一個典型的 AMM(例如,粘合曲線是一塊雙曲線),並將其「中心價格」從(例如)下降到上升,Token 將從(例如)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.
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.
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 is x, and the amount of ETH is y, therefore the「amplifified」constant-product invariant would be:
我們從一些波段開始,與 Uniswap3 類似,通過增加「虛擬餘額」,保留了粘合曲線的雙曲形狀。比方說,USD 的數量是 x,ETH 的數量是 y,因此「增強的」常數-產品不變性將是:
We also can denote x0 x + f and y0 y + g so that the invariant can be written as a familiar I = x0 y0.However, f and g do not stay constant: they change with the external price oracle (and so does the invariant I, so it is only the invariant while the oracle price po is unchanged).At a given po, f and g are constant across the band.As mentioned before, we denote p as the top price of the band and pas the bottom price of the band.We defifine A (a measure of concentration of liquidity) in such a way that:
我們也可以表示 x0x+f 和 y0y+g,這樣不變式就可以寫成熟悉的 I=x0 y0。然而,f 和 g 並不是保持不變的:它們隨著外部預言機價格的變化而變化(不變量 I 也是如此,所以它只是在預言機價格 po 不變時的不變量)。在給定的 po 下,f 和 g 在整個波段內是不變的。如前所述,我們把 p 表示為波段的頂部價格,p 表示為波段的底部價格。我們對 A(衡量流動性集中度的指標)的定義是這樣的:
The property we are looking for is such that higher price po should lead to even higher price at the same balances, so that the current market price (which will, on average, follow po) 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 的方向交易(而另一個方向也是如此)。可以找到很多方法來滿足,但我們需要這樣一個:
where y0 is a p0-dependent measure of deposits in the current band, denominated in ETH, defifined in such a way that when current price p, p and po are equal to each other, then y = y0 and x = 0 (see the point at po = p on Fig.4).Then if we substitute y at that moment:
其中 y0 是一個與 p0 相關的衡量當前波段存款的指標,以 ETH 為單位,其定義是:噹噹前價格 p、p 和 po 相互相等時,則 y=y0,x=0(見圖 4 上 po=p 的點)。那麼,如果我們把那一刻的 y 替換掉:
Price is equal to dx0 /dy0 which then for a constant-product invariant is:
價格等於 dx0 /dy0,那麼對於一個恆定的產品不變量來說,就是:
One can substitute situations where po = p or po = p with x = 0 or y = 0 correspndingly to verify that the above formulas are self-consistent.
我們可以用 x=0 或 y=0 來代替 po=p 或 po=p 的情況,以驗證上述公式是自洽的。
Typically for a band, we know p and, hence, p, po, constant A, and also x and y (current deposits in the band).To calculate everything, we need to find yo.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 against yo:
這就變成了針對 yo 的二次方程:
In the smart contract, we solve this quadratic equation in get_y0 function.
在智能合約中,我們在 get_y0 函數中解決這個二次方程。
While oracle price po stays constant, the AMM works in a normal way, e.g. sells ETH when going up / buys ETH when going down.By simply substituting x = 0 for the「current down」price pcd or y = 0 for the「current up」price pcu values into the equation of the invariant respectively, it is possible to show that AMM prices at the current value of po and the current value of p are:
在預言機價格 po 保持不變的情況下,AMM 以正常的方式工作,例如,上漲時賣出 ETH/下跌時買入 ETH。通過簡單地將 x=0 替換為「當前下跌」的價格 pcd 或 y=0 替換為 "當前上漲 "的價格 pcu 值分別代入不變量方程,就可以說明在 po 的當前值和 p 的當前值下的 AMM 價格是:
Another practically important question is: if price changes up or down so slowly that the oracle price po is fully capable to follow it adiabatically, what amount y of ETH (if the price goes up) or x of USD (if the price goes down) will the band end up with, given current values x and y and that we start also at p = 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 prices p and p so that if we set a base price pbase and have a band number n:
現在我們有了對一個波段的描述。我們把所有的價格空間分成若干波段,這些波段的價格 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 price po: it goes up when po goes down and vice versa cubically, as can be seen from Eq.8.
交易發生的同時保留了公式 1 的不變性,然而,當價格為 po 時,AMM 內部的當前價格會發生變化:當 po 下降時,它就會上升,反之亦然(立方係數),從公式 8 可以看出。
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 是不太理想的,為此我們將使用穩定器(見下一章節)。
When ps > 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.Once ps > 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.When ps < 1, the PegKeeper is allowed to withdraw (asymmetrically) and burn the stablecoin.
當 ps>1 時(例如,由於對穩定幣的需求增加),就會有錨定的儲備,由穩定幣和可贖回的參考幣或 LPToken之間的不對稱存款到 stableswap Curve 池形成。一旦 ps>1,PegKeeper 合約被允許鑄造無抵押的穩定幣,並且只將其單邊存入 stableswap 池,這樣做之後的最終價格仍然不低於 1。當 ps<1 時,PegKeeper 被允許提取(不對稱地)並燒毀穩定幣。
These actions cause price ps to 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) as dst and the function which calculates necessary amount of redeemable USD to buy the stablecoin in a stableswap AMM get_dx as fdx().Then, in order to keep reserves not very large, we use the「slow」mechanism of stabilization via varying the borrow r:
讓我們把鑄造給穩定器(債務)的穩定幣數量表示為 dst,把計算在 stableswap AMM get_dx 中購買穩定幣所需的可贖回 USD 數量的函數表示為 fdx()。然後,為了保持「儲備」不是非常大,我們通過改變借款 r 來使用「緩慢」的穩定機制。
where h is the change in ps at which the rate r changes by factor of 2 (higher ps leads to lower r).The amount of stabilizer debt dst will equilibrate at different value depending on the rate at ps = 1 r0.Therefore, we can (instead of setting manually) be reducing r0 while dst/supply is 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 the dst) or increasing if it』s lower (thereby incentivizing borrowers to return loans and pushing ps up, forcing the system to increase the debt dst and the stabilizer deposits).
其中 h 是 ps 的變化,速率 r 的變化為 2 倍(ps 越高,r 越低)。穩定器債務 dst 的數量將根據 ps=1 r0 的速率在不同的值上平衡。因此,我們可以(而不是手動設置)在 dst/supply 大於某個目標數字(例如 5%)時減少 r0(從而激勵借款人借入並拋出穩定幣,降低其價格並迫使系統燃燒 dst),或者在它較低時增加(從而激勵借款人歸還貸款並推動 ps 上升,迫使系統增加債務 dst 和穩定器存款)。
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 錨定穩定性模塊)。
原文鏈接
歡迎加入律動 BlockBeats 官方社群:
Telegram 訂閱群:https://t.me/theblockbeats
Telegram 交流群:https://t.me/BlockBeats_App
Twitter 官方帳號:https://twitter.com/BlockBeatsAsia