Bancor Network 백서

Bancor Network

원문

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

istic values are usually somewhat closer together. However, the difference in volume is realistic: it may simply correspond to a “buy-low-sell-high” curve that has been seeded with USD and that did not get a chance of buying many RSK yet, so the RSK curve has not fully expanded at this point (see below for the meaning of “expanded”). The trade mechanics can be summarized by the following rules 1. Every token is sold on its own curve, where it appears on its y-axis 2. The y-value on a token’s own curve corresponds to actual token holdings; selling stops at y = 0 3. Every transaction yields a ∆ y <0 (sell the active asset) and a ∆ x >0 (buy the passive asset) 4. The ∆x obtained in a transaction is added to the y-axis on the other curve (¯y) in a 1:1 ratio 5. In case the other curve does not have sufficient capacity, ie if ¯y + ∆x> ¯yint in the other axis, then its capacity is increased by setting ¯yint := ¯y + ∆x 6. Curves only ever automatically expand, but they never shrink automatically; the 26 latter has to be done manually, if so desired To summarize, each of the curves describes the sale – and the sale only – of its active asset (by convention the one on the y axis), and selling stops when the curve runs out of tokens at y = 0. The tokens obtained against the sale are moved onto the opposite curve, expanding it if need be. The system never shrinks a curve, as this could open arbitrage opportunities. It may be worth going through a brief example with the following parameters: the lower range is [50, 100], with the effective price being its geometric average 70 .7. The upper range is [150, 200] with effective price 173 .2. If we start at a price between the ranges, say at 110, with 1 , 000 units of cash, and we go to below 50, then the cash will have been converted into 1000 /70.7≃ 14.1 units of the risk asset. Those risk asset units move onto their own sell curve, and we assume it needed expansion (it may even have started at zero!) so now we have a curve that is fully loaded with 14 .1 units of risk assets. If we move to 200, then those will be sold at an effective price of 173 .2, yielding 14.1∗ 173.2≃ 2, 449 units of cash that move to the other curve. We now have 2, 449 units of cash which would correspond to 2 , 449/70.7≃ 34.6 units of the risk asset if we’d go all the way down again. We assume, however, that we only dip into the lower order, to about 89, and we only get filled 5 units of the risk asset before prices go up again. The capacity of the risk curve is still 14 .1 so at this stage the curve is not “full”. This means that instead of starting to sell at 150 as a full curve would, the curve is top loaded, and selling will start closer to the end point, at 179 .79. We prepared the simulation workbook CarbonSim-WhitepaperExample.ipynb in our Carbon Simulator. The chart “Carbon Simulator example” shows the final state of the simulation, with y value of 5 in the first row indicating that the sell-RSK position contains 5 RSK, and the p marg value of 179.79 indicating that this starts being sold at a price of 179 .79. The second row shows the linked sell-RSK position, and the last column indicates that those two are indeed linked. 27 Figure 8: Carbon Simulator example 3.3 Carbon deployment strategies and the role of fees Taking a step back, the Carbon AMM can be fundamentally used for two different types of operations: 1. As a fee-earning liquidity provider to the market that is highly capital efficient due to the nimble deployment features discussed in a section below 2. As a limit or range order machine that allows traders to take a long-term view in range trading markets, or that assists market makers in making markets, and that are again greatly improved by the nimble deployment features discussed below We have discussed the limit / range order functionality above, and we now briefly discuss fees here. There are two ways of thinking about fees: the conventional way is that they are a payment rendered for services provided that are independent of the transaction at hand. This commercial view, however, is not the full picture: in a trading context, fees are much better understood as a bid-offer spread that increases the price when a market maker is selling, and decreases it when it is buying. For example, assume markets are “at 100”, and there are 1% fees. This means that a taker will pay 101 to buy (100 + 1 in fees), but will only receive 99 when selling (100 - 1 in fees). So fundamentally, fees describe a process where a liquidity provider buys and sells at different prices, just like any other market maker, and this is how they make money. At the moment, Carbon does not allow for specifying an AMM as a mid-price plus fees. This has a practical reason: the routing algorithm is more efficient if we do not allow for bidirectional curves with fees, but we consider it as a future extension. 28 We note however that in principle it is possible to replicate the mid-curve plus fees paradigm in our model. In order to do this, the buy and sell curve must be very similar. More precisely, if the mid-curve isPa...P b then the buy curve isPa/(1 +α)...P b/(1 +α) and the sell curve is Pa· (1 +α)...P b· (1 +α) for a fee level of 2α. Also, the two curves must be seeded with the correct amounts, so that the state of the two curves is correctly synched. Whether or not a Carbon UI allows for contributing such positions is a ques- tion left to the UI designers, but nothing prevents people from interacting directly with the contracts to create them. 3.4 Carbon and MEV An important issue for AMMs is MEV, the “Miner Extractable Value”, which are prof- its that parties who control the transaction flow – typically miners – can extract. An important MEV attack vector for AMMs is the sandwich attack, where a genuine trans- action is sandwiched between transactions of the attacker. An AMM sandwich attack is very similar to frontrunning in traditional markets, except that a sandwich attack is guaranteed to either succeed, or to fail costlessly, other than gas. The way it works is as follows: 1. The attacker identifies a reasonably large trade order, eg for buying ETH against USDC; this order is a “market order”, ie it fixes a USDC amount, and takes whatever amount of ETH it will get 2. The attacker inserts a large order buying ETH against USDC immediately before the attacked transaction 3. The attacker inserts an equal and opposite (apart from arbitrage gains) transaction to (2) immediately after the attacked transaction What happens if the above is executed successfully is that the price at which the attacked transaction gets filled is artificially high, due to the price impact of the transaction (2). The transaction (3), which is now selling ETH, benefits from both the price impact introduced by the transaction (2) and that introduced by the attacked transaction. 29 Net/net, the attacker shifted the transaction to a higher price point off-market and can pocket that difference in price in a risk-free manner. This particular attack vector is closed in Carbon, provided the asymmetric liquidity / two-curve pattern is used with curves that are non-overlapping, or at least far enough apart: whilst an attacker can still front-run a transaction as described under (2) above, the reverse transaction (3) will happen on the other curve, and therefore under vastly different conditions, making this particular attack vector no longer profitable. 3.5 Outlook One final thing to mention here is that in this paper we restrict the choice of Γ to the interval [0, 1], ie we allow for constant-price, constant-product, and curves that lie in- between those two. This is the reasonable choice for a market maker or trader, as for Γ> 1, collateral moves too far to the borders to be useful. We may investigate whether the increased convexity in a leveraged case – where the collateral that sits too close to zero and infinity is simply removed – is sensible for some use cases, but at the moment we do not believe it is. For Γ < 0, the curve becomes inverted, in the sense that when selling the risk assets, the first units are sold at a higher [sic] price than those that follow, and when buying them the first units are bought at a lower price, which reverses the order in an order book. Whilst this does not make sense from a market-making perspective, there are some use cases where this can be interesting. Selling the first units more expensively is something like a “volume discount”, and there may be an economic primitive for which this becomes interesting, eg for the token distribution use case discussed above. 4 Adjustable bonding curves We have previously discussed how Carbon bonding curves are “parametric”, in the sense that they are hyperbolic curves that are driven by a small number of parameters. When we first introduced those curves, we described them in terms of the parameters P0 (a 30 price-like parameter), x0 (a size-like parameter, expressed in the risk asset), and Γ (a unit-less parameter describing the shape of the curve). We also have the curve state x (another size-like parameter expressed in the risk asset). We have also shown that, as expected, we can replace the risk asset denominated parametersx0,x with the numeraire denominated ones y0,y and the shape of the curve remains the same. In this discussion, we use the second form because it aligns more closely with the form that we actually use in the implementation, but of course the essence of the discussion does not depend on the parameterization of the curve. We remind ourselves of this second equation below x = y0 (y (Γ− 1)−y0 (Γ− 2))P0 (Γy−y0 (Γ− 1)) (4.1) We also remind ourselves that in Carbon, liquidity is asymmetric. Because of this, the two tokens in a pool are not equivalent, as the one that is being sold defines the binding constraint: once the pool runs out of tokens to sell it stops, at least until it receives fresh tokens from a linked curve. In our convention, this “active” token is on the y-axis. As discussed in the section on AMM leverage, we use actual, not virtual, token balances, so the key constraint on the pool is y >0. If we ignore the constant-product boundary case (again, the manifold mapping problem), then we can describe our curves with three financial parameters • the start of the range, where the AMM starts selling the active token, Pstart; in our paramerization, this is the slope at the x-intercept, and is expressed with the active token as numeraire (“dy/dx”) • the end of the range, where the AMM stops selling, Pend; this is the slope at the y-intercept, again expressed with the active token as numeraire • the capacity of the curve, which determines how much collateral is needed to move from one end of the range to the other one; this is the y-interceptyint The state of the AMM is then described by y with 0≤y≤yint, which corresponds to 31 the amount of tokens on-curve . Taken together, these four parameters determine the entire trading curve of the AMM, and therefore in particular its marginal price. For y = yint the marginal price is Pmarg = Pstart and for y = 0 it is Pmarg = Pend. We always havePstart≥Pend which sounds counterintuitive until we understand that those P are expressed as dy/dx in the numeraire of the active asset, which inverts how we typically think about an asset that we are trading. If we consider y the risk asset and x the numeraire for a moment, then prices will be expressed as dx/dy, in which case the price at which selling starts is below the price at which selling ends, as it should be. The importance of the marginal price is that if we are not careful here, we may create an unnecessary arbitrage opportunity for the market. We here assume that there are reasonably liquid markets elsewhere, so the market price is well established. Without loss of generality, we assume that that market price, in the reverse units, is currently at ¯Pmkt = 100 “dx/dy”. The AMM is selling, therefore showing a price below 100 will yield an immediate arbitrage opportunity which we need to avoid. In terms of starting position we need to consider two cases 1. The AMM is (deep) out-of-the money, ie the current market price is far below (in dx/dy) the starting price of the range, ie ¯Pmkt≪ ¯Pstart. 2. The AMM is in (or at, or close to ) the money, ie the current market price is above (or equal to or close to) that starting price of the range, ie ¯Pmkt≥ ¯Pstart−ϵ where ϵ≥ 0 is some suitably chosen proximity parameter. In case (1), we have almost full freedom of how we adjust the range: the marginal price of the AMM is far away from the current market price, so we face little constraint in adjusting all parameters, including changing the state by adding or removing liquidity. In case (2) however, we need to be more careful: if ϵ = 0, we are in the range, and we need to ensure that we keep the marginal price constant ¯Pmarg;2 = ¯Pmarg (if the AMM is to remain at-the-money) or at least non-decreasing ¯Pmarg;2≥ ¯Pmarg. If ϵ >0, then we have a little room of maneuver, meaning the marginal price can decrease up to ϵ, but 32 other than that the same applies. In practice, what this means is that in case (1), all 4 parameters – or rather, 3 parameters plus 1 state variable – can be changed independently, whilst in case (2), only 3 parameters can be changed independently if the AMM is meant to remain at the current marginal price. Therefore in this case, the allowable parameter space is in the 3-dimensional hyper surface embedded into the 4-dimensional parameter space. In case the condition is relaxed, and we allow for moving out-of-the money, then the allowable parameter space is a 4-dimensional half-space, ie it lies in a 4-dimensional space, on one side of the aforementioned 3-dimensional “constant marginal price” hyper surface. We have just mentioned that the current state of the AMM, y, is part of this parameter set that needs to be carefully changed, yet we remind ourselves that strategies with linked curves do move collateral from one curve to the other which could be an issue. The way we currently avoid this is that the two linked curves (we do not currently allow more than two, and they must be on the same pair) must be non-overlapping. In this case, as long as one of the curves generates collateral to be placed on the other one, the target curve is forcibly out of the money, and therefore condition (1) applies. If we allow overlapping curves – or future strategies with more than two curves – however, this issue requires closer attention. We also want to point out that this is mostly a user interface issue: on the smart contract level (and possibly the API) we may well allow for adjustments that bring the contract into an arbitrageable condition. It is mostly important that users that make changes via a UI are protected here. There are too many possible combinations of changes to consider covering them all, so the important thing to keep in mind that parameters always have to, at least, be changed in pairs if we are in case (2): we cannot just change one variable, we need to adjust (at least) one other variable as a response to that. We are going here through one example, which is looking at how to resize or move a range. For this we definew =Pstart/Pend> 1 (we are back in the dy/dx numeraire) and we rewrite the marginal price equation as 33 Pmarg = P0 ( −y √ 1 w +y +yint √ 1 w )2 y2int √ 1 w (4.2) We remind ourselves that P0 =√Pstart·Pend corresponds to the location of the range. We can transform the above equation to P0 = Pmargy2int √ 1 w ( −y √ 1 w +y +yint √ 1 w )2 (4.3) which is of the functional form P0 = f(w). In other words, if we want to change the widthw of a range (and we want to keep the other parameters untouched) then we have to change its location P0 and vice versa. 5 Matching, routing, and arbitrage In this section we briefly deal with matching, routing, and arbitrage. Before we go on, we need to define those terms. Matching and routing is about finding the best way to execute a given trade, and in our terminology, matching only looks within a given pool whilst routing also looks at trades that go through different pools and therefore involve three or more tokens. Arbitrage is about identifying imbalances in the system, both at the single pool level, and between pools, so we de facto have the same duality as in routing here even though we do not semantically acknowledge it. 5.1 Matching and routing Matching is an exercise particular to Carbon because in other AMM designs it is not necessary. Or rather, it is so trivial that it is usually ignored. In order to understand this statement we need to take a step back and look at the theoretical foundations of AMMs. To make it somewhat more tangible, let us consider one of the most dramatic events in the history of AMMs, Sushiswap’s vampire attack on Uniswap. A key fact 34 is that SushiSwap cloned the Uniswap v2 (constant product) contracts and established identical pools to those of Uniswap, and then incentivized Uniswap liquidity to move (that’s the vampire bit). For the ease of presentation, we assume that Sushi cloned all pools, and that the condi- tions (most importantly, the fee levels), are exactly the same. We also assume negligible gas costs, which is a reasonable assumption at least for trades of $100,000 or above. In this case we have a routing problem (actually, a matching problem in our terminology) because if we want to trade, we need to decide how much to send through Uniswap and how much through Sushi. Fortunately, we have intermediaries like 1inch that determine the optimal path. We see that especially for bigger numbers (ie negligible gas cost), 1inch will show multiple routes for each trade. 1inch deals with a complex real-world problem, but for simplicity we’ll return to our two identical pools only situation. In this case it is easy to show that the optimal routing is simply pro-rata to the liquidity in the respective pools. Now we can do a two- step reasoning with important insights. Step 1 is to understand that, from a trader’s perspective and ignoring gas, Uniswap and Sushi are not really different entities. They just form part of a bigger “World AMM”. This yields Insight 1. All AMMs available on a single network like Ethereum constitute the “World AMM” for this network (cross network introduces additional complexity because of non-atomicity). Here we zoomed out to the big picture, so now we go the other way: if the World AMM in a world of only Sushi and Uniswap can be broken down into those two exchanges, surely any single AMM can be broken down further as well. This yields Insight 2. Any AMM can be considered as an aggregation of constituent AMMs that are formed by the individual user positions, with a routing (matching) algorithm to route trades to those constituent AMMs. In other words, pre-Carbon, AMMs already have individual user positions. However, 35 those positions are bucketed, rather than personalized, in order to ensure that routing is pro-rata and therefore trivial. This yields Insight 3. Pre-Carbon AMMs have been designed with the intent of mak- ing routing trivial, thereby impacting the user experience because users are forced into buckets. Carbon is designed in a manner that routing is still highly efficient, despite more personalized user positions. Here we leave it at that because routing is (a) the center of ongoing research and (b) the subject of a forthcoming paper. Suffice to say that our routing mechanisms can already be explored in the Carbon Simulator that is available under an open-source license on our Github. 5.2 Arbitrage Routing is the answer to the question “I want to trade [amount] of [TKN1] to [TKN2]. What is the best way to do it?” . Arbitrage is, in a narrower sense, the answer to the question “I can trade [amount] of [TKN2] to [TKN1]. If I do the reverse trade somewhere else, will I make money?” , so clearly those two are intimately related. Arbitrage however is more complex because it is the origi
프로젝트로 돌아가기