Bancor Network 백서

Bancor Network

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 4쪽 중 4쪽

nal problem “squared”: In order to fully arbitrage a market we need to look at all possible optimal routes (side 1 of the square) and then look at all other possible routes (side 2 of the square) to see whether there is money to be made. Now we are not particularly interested in arbitraging the whole world – well, we are, but this is hard – so in our current research we focus on two questions: 1. Are there transactions within Carbon – ie transactions that connect two or more Carbon orders – that yield a positive return after fees and gas? 2. Are there transactions that allow me to arbitrage Carbon against the external market? Again, those are matters of active research and are subject to a forthcoming paper, and we will also release a simple arbitrage bot in due course. If you are interested in 36 discussing those topics with us before that, please do not hesitate to get in touch with any of the authors. 6 Conclusion In this paper, we discussed Carbon, a next-generation AMM protocol that pushes the boundaries of what AMMs can do, and that opens a whole new world of applications, notably in trading and market making. Carbon’s key design features are: • Asymmetric liquidity . Asymmetric liquidity means that each trading direction is determined by its own curve and state, ie there is one curve for selling, and one curve for buying. This makes Carbon particularly suitable for trading applications, eg for out-of-the-money limit orders as well as for more complex trading strategies, such as “buy low, sell high” strategies operating in arbitrary user-defined ranges. • Adjustable parametric curves (“orders”). The parametric nature of curves (or orders, as we call them) means every user position is individually parameter- ized by three parameters (eg starting price, ending price and capacity) as well as one state variable (tokens held). A curve could be set to “buy ETH for USDC be- tween 1500 and 1000, with a total budget of USDC 100k” , or the zero-width limit order “sell 10 ETH for USDC at 3,000” . Those parameters can be adjusted on the fly without closing and recreating the order, and in a non-arbitrageable man- ner, allowing for an easy and gas-efficient means of reacting to changes in market conditions. • Linked curves (“strategies”). Linked curves (or strategies, as we call them) means that multiple curves share a single collateral pool where collateral acquired on one curve is available for sale on another one; this allows for the design of advanced strategies like “buy ETH against USDC at 1000, sell at 2000; start with USDC 10k”. Carbon orders and strategies can be created permissionlessly by everyone, for every 37 possible pair of standard ERC20 tokens. This effectively creates a fully decentralized order book on-chain, against which everyone can trade. Because of the unidirectional nature of Carbon trades, they are not susceptible to key MEV attack vectors. Also there is no Impermanent Loss, in the sense that Carbon positions and strategies are not buy-and-hold liquidity positions but the expression of a particular trading view. The Carbon protocol is enabled and supported by sophisticated matching, routing, and arbitrage algorithms that will be made open-source in due course. Especially on the arbitrage side, we also encourage others to privately identify and execute profitable intra- Carbon and Carbon versus the market arbitrage opportunities, and the authors would be very glad to engage with anyone on this particular topic, or any Carbon-related topic for that matter. 38 Appendix A Formulas In this appendix we are summarizing and briefly discussing the key formulas of the Carbon model. There is also a Jupyter Notebook that is held roughly in sync with this appendix in terms of the formulas contained, and that some readers may find useful. A.1 Fundamental model parameters The Carbon AMM framework is based upon five parameters, only four of which can be independently chosen as they are tied together by the invariant curve. As in the remainder of the paper, quantities denoted with x are risk asset quantities, and those denoted with y are numeraire quantities. Unless otherwise noted, all prices are quoted in units of numeraire per risk asset, ie y/x. The “risk asset parametrization ” of the model consist of the following parameters • Pool Reference Risk Asset V olume x0. The risk asset volume x0 is a nominal and invariant indicator for the size of the pool, and it is denoted in units of the risk asset. It can be thought of as the virtual volume in a specific reference state. • Pool Reference Price P0. The reference price P0 (also sometimes referred to as P ) is a price-like invariant parameter that is to be read in conjunction withx0, and that is denoted in y per x. It can be thought of as the price in the aforementioned reference state. • Pool Convexity Γ. The pool convexity Γ is a dimensionless parameter that indicates the convexity of the curve. Its useful range is the interval [0 , 1]. At Γ = 0 the curve is straight, corresponding to a constant-price AMM, and at Γ = 1 corresponds to the constant-product AMM. • Virtual Risk Asset Amount x. The virtual risk asset amount x describes the current virtual state of the pool, determining its operations unless locked. The 39 actual state can differ due to leverage applied. • Virtual Numeraire Amount y. The virtual numeraire amount y describes the current virtual state of the pool, determining its operations unless locked. The actual state can differ due to leverage applied. In the “numeraire parametrization” we are using the Pool Reference Numeraire V olumey0 instead of x0. The reason why we need both is that in the numeraire parametrization the parameter P0 does not affect the pool size when looked at in nu- meraire terms, but it does affect it when looked at in risk asset terms, and vice versa. We also have the “volume parametrization” that uses x0,y 0 instead of P0 but this is more rarely used. Within the risk asset parametrization there are two particularly interesting alternatives which both keep the ratio x,x 0 fixed. Those are the r-parametrization based on x0 =rx (A.1) and the rho-parametrization using x =ρx0 (A.2) A.2 Invariant curves As already alluded to above, the pool invariant curves tie together the five parameters and state variables of the pool, reducing them effectively to 3 parameters and one state. In the risk asset parametrization x0,P 0, Γ the invariance formula looks as follows (desmos) Invariant Equation as function of Γ,P 0,x 0 40 y = P0x0 (x (Γ− 1)−x0 (Γ− 2))Γx−x0 (Γ− 1) (A.3) rewritten using r y =−P0rx (−Γ +r (Γ− 2) + 1)Γ−r (Γ− 1) (A.4) rewritten using ρ y = P0x0 (−Γ +ρ (Γ− 1) + 2)Γρ− Γ + 1 (A.5) in the numeraire parameterization as function of Γ,P 0,y 0 (desmos) y = y0 (P0x (Γ− 1)−y0 (Γ− 2))P0Γx−y0 (Γ− 1) (A.6) in the Q-form; here Q is a dimensionless parameter equivalent to Γ, and xint and yint are places where the curve cuts through the x and y axis respectively. See the next section for a more thorough discussion of those parameters and for related formulas. (desmos) Q = xy(x−xint) (y−yint) (A.7) In the asymptotic form as function of the asymptotes xint,y int and the levered pool constantκ (x−xasym) (y−yasym) =κ (A.8) 41 A.3 Swap and marginal price equations The swap equation is the fundamental operational equation of the AMM, describing what happens in a transaction. In addition to the parameters, we have seen before it also has the swap amounts ∆x (risk asset) and ∆ y (numeraire). Those are signed quantities, and the sign is observed from the vantage point of the AMM, so ∆ x > 0 means the AMM is buying the risk asset, and ∆ x <0 means it is selling it. Evidently ∆x, ∆y always have the opposing sign, hence the sign in front of the equation. Our representation of the formula isolates the numeraire change ∆y as a function of the risk asset trading volume ∆x, but of course the risk asset view (−∆x =··· ) or the effective price view (−∆y/∆x =··· ) of this equation are trivially obtained. −∆y = P0∆xx20 (Γ (x−x0) +x0) (Γ (∆x +x−x0) +x0) (A.9) ∆y = P0∆xr2x(Γ (r− 1)−r) (Γ (∆x−rx +x) +rx) (A.10) −∆y = P0∆xx0 (Γ (∆x +x0 (ρ− 1)) +x0) (Γ (ρ− 1) + 1) (A.11) The marginal swap equation is the swap equation for an infinitesimal ∆ x. It is here shown in the price view, where dx and dy can either be interpreted as infinitesimal quantities, or dy/dx can be interpreted as both the marginal price and the derivative of the invariance function. (desmos) −dydx = P0x20(Γ (x−x0) +x0)2 (A.12) The marginal price equation is exactly the same as the marginal swap equation, 42 except that we rename dy/dx as Pmarg to honor the fact that (a) this quantity is the marginal price, and (b) arguably this is the most important amongst all the equations presented. (desmos) Marginal Price Equation as function of Γ ,P 0,x 0 Pmarg = P0x20 (Γ (x−x0) +x0)2 (A.13) rewritten using r Pmarg = P0r2 (Γ (r− 1)−r)2 (A.14) rewritten using ρ Pmarg = P0 (Γ (ρ− 1) + 1)2 (A.15) as function of Q,P 0,x int (P...≃y/x) Pmarg = P0Qx2int (−Qx +Qxint +x)2 (A.16) as function of Q,P 0,y int (P...≃y/x) Pmarg = P0 (−Qy +Qyint +y)2Qy2int (A.17) as function of w,P 0,y int where P...≃y/x and √ 1/w =Q 43 Pmarg = P0 ( −y √ 1 w +y +yint √ 1 w )2 y2int √ 1 w (A.18) A.4 Parameters and their relationships The first parameter we look at is the Q-value Q that we have already seen above. In the interval [0 , 1], which is the one we focus on, Q is equivalent to Γ. Note that direction is reversed however, and Q = 0 is the constant-product case, whilst Q = 1 is the constant-price case. (desmos) Q = (1− Γ)2 (A.19) the inverse relationship is of course this one (desmos) Γ = 1− √ Q (A.20) Also, we have the relationship below, which is useful in the equations that follow (desmos) (desmos) 2− Γ 1− Γ = 1 + 1√Q (A.21) The risk asset intercept xint is the point at which the invariant curve intercepts the x-axis, and it is denominated in terms of the risk asset. Unsurprisingly it is proportional to x0, and the factor only depends on Γ. For Γ = 1, the constant-product case, this quantity diverges as the curve is asymptotic to the axis. The slope of the intercept is Px. 44 (desmos) (desmos) (desmos) xint = x0 (2− Γ)1− Γ (A.22) The numeraire intercept yint is analogous to xint, except that it is against the y-axis, and is therefore denominated in the numeraire. (desmos) (desmos) (desmos) yint = y0 (2− Γ)1− Γ (A.23) The risk asset intercept price Px is the slope of the invariant curve at the point of intercepting the x-axis, xint. It is price-like, denoted in y/x. We remind ourselves that Q = 1 is constant-price, in which case Px =P0. Also, Q = 0 is constant-product where there is no intercept, so the price goes formally to 0. (desmos) Px =P0Q (A.24) The numeraire intercept price Py is the slope of the invariant curve at the point of intercepting the y-axis, yint. Despite being on the other axis it is price-like, denoted in y/x, just like Px. For Q = 1, the constant-price case, we find Px =P0. For Q = 0, the constant-product case where there is no intercept, the price diverges. (desmos) Py = P0Q (A.25) We already mentioned the fundamental equation tying P0,x 0,y 0 at the beginning of the 45 appendix but here it is again for reference. P0 = y0x0 (A.26) As xint,y int are proportional to x0,y 0 with the same factor, the reference price P0 can also be recovered from the intercepts. This relationship is interesting from a financial point of view: yint/xint can be interpreted as the effective price of a series of limit order trades, and this equation shows that the average price at which they are filled does not depend on Γ. (desmos) P0 = yintxint (A.27) The relationship betweenQ and the intercept prices is trivial from the definition of those prices, but it is interesting to note, nevertheless. IfQ = 1 (constant-price) then the curve is a line and therefore the two prices are the same. For Q getting smaller the convexity increases, meaning the Py becomes bigger (steeper) and Px smaller (flatter). (desmos) Q = √ Px Py (A.28) This relationship is even more interesting in that form, linking the range width to Q2 w = 1Q2 (A.29) Again, this relationship between the pool reference price P0 and the intercept prices Px,P y is trivial from their definitions, but it is worth noting, nevertheless. It also echoes 46 the fact that the effective trading price of an AMM is the geometric average of the prices at the trade boundaries. (desmos) P0 = √ PxPy (A.30) The asymptotes xasym,y asym are a measure of the x and y translation of the curve in the respective direction. Those are non-positive numbers, meaning the curve has been moved to the left and down. In terms of our other paramters, the x-asymptote is xasym =x0 ( 1− 1Γ) (A.31) and the y-asymptote is yasym =P0x0 ( 1− 1Γ) (A.32) The most important use of those parameters is the asymptotic pool invaration equation above, where they are combined with the levered pool constant κ = P0x20 Γ2 (A.33) When reminding ourselves that P0x20 =x0y0 =k, the important corollary of the abpve equation is that as √ k is a measure of the pool size, 1 /Γ is the leverage factor, ie a measure for the amplification of the leverage in the pool due to the narrowing of the range. 47 B Implementation formula reference In this appendix, we focus on formulas that are important for the implementation. We will provide very little commentary here – this appendix is meant as a formula reference for people already familiar with the model, not as an introduction. Prices are always quoted in y per x; for historical reasons we use multiple names for the same prices: x,y denotes the axis intercept, to which they relate, a,b is reading them left to right, and min,max is ordering them in their natural quotation ie Pmax>P min. Pa =Py =Pmax Pb =Px =Pmin (B.1) The key implemenation parameters are B,S B = √ Pb S = √ Pa− √ Pb Pb =B2 Pa = (S +B)2 (B.2) Alternatively we can define S based on P0 =√PaPb and the shape parameters Q or Γ as S = √ P0 Q (1−Q) = √ P0 Γ (2− Γ) 1− Γ (B.3) B,S satisfy the following relationships 48 B2 =Pb S2 =Pa +Pb− 2√PaPb BS = √ PaPb−Pb =P0−Pb B2 +BS =√PaPb =P0 S2 +BS =Pa−√PaPb =Pa−P0 (B.4) The curve capacity is yint, and its utilisation is y; the utilization ratio is closely related to the marginal price y yint = √Pm−√Pb√Pa−√Pb =√Pm−BS Pm = ( S· yyint +B)2 (B.5) Effective prices and marginal prices, and matching by source −∆y∆x = (Sy +Byint)2y2int + ∆xS(Sy +Byint) Pm =−dydx = (Sy +Byint)2y2int =(S· yyint +B)2 (B.6) Matching by target −∆x∆y = y2int(Sy +Byint)(Sy +Byint−S∆y) (B.7) Invariant functions y = yint(yint−x(B2 +BS))x(BS +S2) +yint = yint(yint−x√PaPb)x(Pa−√PaPb) +yint x = yint(yint−y)yint(B2 +BS) +y(BS +S2) = yint(yint−y)yint√PaPb +y(Pa−√PaPb) (B.8) 49 Curve capacities in the respective tokens xint = yintB2 +BS = yint√PaPb (B.9) C Resources • The Carbon website is at carbondefi.xyz • On the Carbon website there is the current whitepaper, our litepaper, the innova- tion disclosure relating to our patent application, and a mathematical summary • On the Bancor github there is the Carbon Simulator. The simulator repo contains – a number of example workbooks looking at Carbon Orders (Demo1-1, Demo1- 2, Demo1-3), Carbon Strategies (Demo2-1, Demo2-2, Demo2-3) and the re- sulting order books (Demo3-1, Demo3-2), – the example workbooks for the whitepaper CarbonSim-WhitepaperExample), and the litepaper CarbonSim-LitepaperExample and CarbonSim-LitepaperExampleShort), – and the workbook providing the key Carbon formulas and calculations in SymPy, CarbonCalculations. 50
프로젝트로 돌아가기