bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 4쪽 중 2쪽
sume a standard
constant-product AMM with 100m in liquidity. We then remove some tokens, but with-
out telling the AMM about it, so it still trades as if it had 100m liquidity – up to the
point it runs out, at which point it stops trading in the direction in which it can no
longer trade.
To put it more formally, under the virtual tokens paradigm , the parameters x,y that
are used in the invariant curve do not correspond to the actual token holdings xact,y act.
Typically, we have xact < x,yact < y because otherwise there are a number of “dead”
tokens the AMM can never reach – in other words, the AMM is delevered. We remind
ourselves that x is the risk asset, so xact < x means the AMM runs into a hard stop
when it is trying to sell the risk asset. Therefore, the number xact determines the upper
boundary of the AMM’s trading interval. Likewise,yact<y corresponds to the numeraire
and therefore to purchases of the risk asset, so yact determines the lower boundary of
the interval. Upper and lower are to be understood in the numeraire where the asset
13
being traded is considered the risk asset of the pair.
Changing the curve is, well, changing the curve. In this context we remind ourselves
that
• the slope of the curve (tangent) corresponds to the marginal price at this particular
point of the curve
• a connection between two points on the curve (secant) corresponds to a trade, with
∆x being the amount of risk asset traded, ∆ y the amount of numeraire traded,
and ∆y/∆x being the effective price
• the amount of liquidity in a certain segment of a curve is determined by its curva-
ture, with flatter curves corresponding to more liquidity held in that price range.
The latter points merit more explanation because they may not be entirely intuitive.
We consider an interval on thex axis, and the corresponding curve segment. The length
of the interval on the x-axis is the amount of risk asset “contained” in this interval.
The slope of the curve at every point is the marginal price, so if the curve is a straight
line the entire liquidity is located at the same price point (the so-called “constant-price”
curve). The more the slope on the left-hand side of the interval is bigger than the slope
on the right-hand side (it can never be smaller as the curve is convex), the wider the
price range covered by the same amount of risk asset liquidity.
Carbon does something in between those two models: it changes the curve, but in
its current incarnation the curve change is equivalent to a virtual token model. The
difference is that, whilst the virtual token model puts ( x,y ) on a different point of the
curve, Carbon keeps (x,y ) tied to financially meaningful numbers, but moves the curve
around and stretches it. This can be seen nicely in the aforementioned Desmos model.
Financially this does not make a difference – yet. We are working on extensions of the
model that would generate entirely different curves. The main difference is technical,
which is important on the highly resource-constrained Ethereum chain. Implementation
of this curve is extremely gas efficient, and it can be combined with an efficient routing
14
framework. The parametric form of the curve allows for highly efficient implementation,
and it also unlocks new composability paradigms that are hard to achieve otherwise.
2.3.2 Carbon leverage
We now look at how Carbon leverage works in practice. First, we go back to the claim
that despite the apparent complexity of the formula, it is financially equivalent to the
virtual token model. For this we recall that the swap equation – which is the authoritative
record of the financial reality of this system – had effectively a very simple form along
the lines of a/(∆x +b), ie the curves only form a space of dimension 2. One of those
dimensions is frozen once we fix the price, so at any given price there is only one free
parameter left for the curve shape, and the set of curves attainable is exactly the same
as the one under virtual token model.
Again, the eagle-eyed will run into one problem – the virtual token model cannot create
the constant-price curve. It can get arbitrarily close to it, but it can never attain it.
This is the aforementioned well-known manifold problem – it turns out that the “map”
spanned by the virtual token model cannot represent the constant-price model because
this is the “point at infinity”. Which is another reason why our curve is superior – by
over-parameterizing the problem with a redundant parameter set, we manage to cover
the entire space.
Before we discuss Carbon liquidity in more detail, we need to point out that we are not
yet dealing with the asymmetric liquidity paradigm that Carbon is also implementing. In
this section we assume a standard, bi-directional curve, and we will discuss the changes
that stem from the unidirectional liquidity provision in the next section.
For this discussion, we are looking at the Q-and-intersect parametrization of the
invariant curve that we recall as
Q = xy(x−xint) (y−yint) (2.12)
15
Figure 2: Carbon invariant curve (Q=0.3)
We have plotted this invariant curve for reference in the chart “Carbon invariant curve
(Q=0.3)”, but we suggest looking at the interactive version on Desmos.
In the Carbon environment, the values of x,y correspond to actual token holdings. As
those holdings cannot go negative, the AMM stops trading in one direction when it hits
either of the axes. Therefore, the curve shown in the chart starts at 75 units of the risk
asset (x-axis) and 0 numeraire units on one side, and ends at 50 numeraire units (y-axis)
and 0 risk asset units on the other side. The average transaction price is 5075≃ 0.66. It is
somewhat hard to read from the chart here, but from the interactive version on Desmos
we find that the slope where it cuts the y-axis Py≃ 2.2 and the one at x is Px = 0.2,
so this particular curve covers a wide price range. It turns out that curves that cover
reasonable trading ranges look almost straight to the eye.
As for the original chart, Q = 0.3 is relatively close to the constant-product case Q = 0.
As reference we have also drawn the same curve with Q≃ 0.8 on the chart “Carbon
invariant curve (Q=0.8)” which can also be seen on Desmos. This curve yields a price
range of 0.5− 0.8 approximately, ie a range width of 1.5x.
We note en-passant that Q = (1− Γ)2, P0 =√PxPy, and Py/Px = 1/Q2, all of which
are detailed in the appendix.
16
Figure 3: Carbon invariant curve (Q=0.8)
2.3.3 Leverage, pool prices, and the asymptotic invariant equation
There are a number of occasions where it is useful to quantify leverage, one key example
being when we want to calculate the effective price of a pool. As will be discussed
in more detail in the section on matching and routing, Carbon is unusual in that the
matching algorithm, ie the algorithm that finds the best Carbon orders for a given trade,
is non-trivial. In a traditional AMM, if we even think about an AMM as being separated
into per-position pools, all those pools are set at the same price, by design. Now this
price may or may not be the current market price, provided such price meaningfully
exists in the first place, but at least all positions in the AMM agree what their current
marginal price is.
For Carbon this is different. Even when we are only looking at the active orders, ie the
orders where we have the strict inequalities 0 < y < yint and the price is not stuck at
the boundary, there is no guarantee that the marginal prices of all relevant pools are the
same. They will be the same if our standard routing algorithm has been used, and if
the last traded was routed through all active pools. However, there is no guarantee that
this is always the case.
So we can easily be, and often will be, in a situation, where the marginal prices of
17
all active pools diverge somewhat, and we would like to quantify something akin to
the average price, as well as the price divergence. A naive analysis of this problem
may suggest to simply use average and standard deviation, and in principle this is
not a bad idea, except that some pools may be very small, and some very big, so the
correct way to calculate the average is to use some pool-size weighted average, for each
trade direction separately. This measure is also incomplete, however, and may often be
misleading. At the very least it should be augmented by the best price available in each
direction. Ultimately, the gold standard measure in this situation is the full order book
that determines the price for every possible trade size.
Be that as it may, it is clear that we need a good measure of the pool size. As it turns
out, traditional constant-product pools have an excellent measure for pool size, which is
the pool constant k from the invariant equation k =x∗y. In fact, it is well known that
the best measure for pool size is
√
k, because it is the only measure that has the correct
scaling properties, ie the only measure that scales linearly in the token amounts.
We also know that Carbon curves are constant-product curves, just moved and, impor-
tantly, scaled. So what we need is that scaling factor. Once we have it, we can use it in
our weighted average above. To calculate the scaling factor, we introduce yet another
form of the pool invariant equation, its asymptotic form
(x−xasym) (y−yasym) =κ (2.13)
It has three parameters, the two asymptotes xasym,y asym and the pool constant κ (refer
again to the chart “The new invariant curve” and to Desmos for a graph showing those
asymptotes). The asymptotes are given as
xasym =x0
(
1− 1Γ) (2.14)
and
18
yasym =P0x0
(
1− 1Γ) (2.15)
which are negative numbers. If we substitute those into the above equation, and we also
substitutey with the right hand side of our initial invariant equation, then we find that
κ is
κ = P0x20
Γ2 (2.16)
The term on the top is P0x20 = x0y0 = k, ie it is equal to the pool constant k, and
therefore we get
√κ =√kΓ (2.17)
In other words, the scaling factor on a Carbon order is 1 /Γ. We remind ourselves that
Γ = 1−√Q and that Q = 1/√w where w =Py/Px > 1 is the percentage width of the
price range, or rather the greater-than-unity ratio of its two end points. So we finally
get the scaling equation we were looking for
desmos
√κ√
k
= 1
1− 4
√
Px
Py
(2.18)
We have plotted the equation in log scale on Desmos, and also in the chart “Log leverage
versus range percentage width”. On the x-axis this the percentage width of the range,
eg [100, 105] would be at 5. On the y-axis we have plotted log leverage. For example, at
a 50 range width, the leverage is 10 1≃ 10.
19
Figure 4: Log leverage versus range percentage width
3 Asymmetric liquidity
Carbon is designed as an AMM for traders and market makers, and in particular as a
“limit order machine”. There has been some discussion lately about using Uniswap v3 as
such, by putting liquidity into a thin out-of-the-money bucket that will be traded when
the prices go through the associated price interval. There are two issues associated with
this approach
1. It is only possible to create one type of limit order, the “out-of-the-money” type,
which is to buy the depreciating asset on the downside, or to sell the appreciating
asset on the upside; it is not possible to buy an asset on its upside or to sell it on
its downside.
2. When markets are jittering or range trading, the position may still be reversed
when the markets move the other way; to avoid this, limit order positions need to be
permanently monitored, and canceled immediately once they have been executed.
Carbon still has issue (1) – it is something intrinsic to AMMs, and it is not possible to
address it in an AMM framework. So, “buy-low-sell-high” strategies can be implemented
with AMMs, but stop-loss and buy-on-uptick ones cannot.
20
Carbon, however, fully solves issue (2). The way it does it is that every position has two
curves, one for buying and one for selling. Those curves can in principle be the same,
but they usually are not. So, one possible strategy is that if markets are at say 100,
there can be a “buy” curve to accumulate the asset from 80 down to 50. And there can
be a sell curve to sell from 150 to 200. Both curves can be present, but they do not have
to be present – a Carbon position can simply terminate once executed, so there is only
a buy order, or only a sell order.
3.1 Carbon asymmetric liquidity mechanics (simplified)
In this section we will go through a simplified version of the mechanics of asymmetric
liquidity provision in Carbon. In the next section, we will then discuss the detailed
mechanics.
Here, we will first discuss the mechanics with an example of a one-sided system (sell-
curve only) that can be used as a sophisticated token distribution engine. We will then
discuss an example of a generic “buy-low-sell-high” trading strategy.
3.1.1 T oken distribution strategy
Our first example refers to the chart “Token distribution curves”, but as usual we urge
the reader to look at the version on Desmos as it allows for the reader to modulate the
parameters.
(desmos)
• DC1 parameters (solid): Q = 0.5,x int = 500k,y int = 500k
• DC1 range (solid): Px = 0.5,P y = 2.0,P 0 = 1
• DC2 parameters (dashed): Q = 0.87,x int2 = 500k,y int2 = 870k
• DC2 range (dashed): Px2 = 1.5,P y2 = 2.0,P 02 = 1.7
The chart has two curves, DC1 (“Distribution Curve 1”) and DC2. We first look at DC1
21
Figure 5: Token distribution curves (DC1: solid; DC2: dashed)
on its own. This curve contains 500k of risk asset tokens, and it sells them at an average
price of 1, for 500k numeraire tokens. The price range is between 0 .5− 2.
The curve DC1 on its own is a valid distribution strategy, but it does only allow for a
limited number of choices – the price range and the amount. Therefore, we introduce
a curve DC2 that is in addition to DC1. In this case, DC2 distributes another 500 k
tokens, but in a smaller range 1.5− 2.0, receiving up to 870k in numeraire.
In other words – DC1 and DC2 together implement a distribution strategy in the range
0.5− 2.0 that distributes a total of 1m tokens, against a total 1.37m of cash. The distri-
bution process is back loaded, as the second half of the tokens is only distributed at 1.5
and above. Please refer to the workbooks CarbonSim-LitepaperExamples.ipynb and
CarbonSim-LitepaperExamplesShort.ipynb in our Carbon Simulator for a simulation
of this position using our open-sourced Python libraries.
3.1.2 Buy-low-sell-high trading strategy
Our second use case refers to the chart called “Buy-low-sell-high curves”, that can also
be found on Desmos.
(desmos)
For reference, the curve parameters are as follows
22
Figure 6: Buy-low-sell-high curves (buy: blue; sell: red) (blue)
• Buy (blue) parameters: Q = 0.8,x int = 100,y int = 50
• Lower range (buy; blue): Px = 0.4,P y = 0.625,P 0 = 0.5
• Sell (red) parameters: Q = 0.8,x intr = 100,y intr = 80
• Upper range (sell; red): Pxr = 0.64,P yr = 1.0,P 0r = 0.8
Here, the blue curve is the lower range, ie the range where the risk assetx is bought (and
the numeraire is sold), and the red curve is the upper range where the risk asset is sold
(and the numeraire is bought).
We assume we start outside and above the buy range, and the price of the risk asset
is falling. In this case, buying only starts once the range is entered, and buying stops
whenever prices go back up. Importantly, there is no selling off the blue curve on the
way up – it is simply paused. Buying resumes however whenever the prices go below its
previous low water mark.
So, in the chart shown, the risk asset is bought starting at a price of Py = 0.625y-per-x,
and ending at a price of Px = 0.4 y-per-x. Once buying is finished – ie when the price
drops to or below 0.4 – a total ofxint = 100 units of the risk asset will have been bought,
againstyint = 50 units of cash, ie at an effective price ofP0 = 0.5y-per-x. As a reminder,
23
P0 =
√
PxPy is the geometric average of the end prices of the range.
On the way up – the red curve – the situation is mutatis mutandis the same: the risk
asset is sold starting at a price of Pxr = 0.64 y-per-x, and an end price of Pyr = 1.0
y-per-x. Once selling is finished – ie when the price rises to or above 1 .0 – a total of
xintr = 100 units of the risk asset will have been sold, against yintr = 80 units of cash,
ie at an effective price of P0 = 0.80 y-per-x.
So, if we started between the ranges with 50 units of the numeraire, and we went all the
way down to below 0.4 and up again to 1 we end up with 80 units of cash, at a profit of
30.
This is a key use case of Carbon: the “liquidity provider” (we refer to them as “strategy
providers”) can use Carbon to run a buy-low-sell-high trading strategy. For this
strategy to work, we need the two curves present, and we need xint =xintr and yint <
yintr. Also, the curvatures Q,Q r must be chosen such that Py < Pxr, ie so that the
ranges do not intersect for x,y >0.
Again, please refer to the workbooksCarbonSim-LitepaperExamples.ipynb for a longer
discussion, and CarbonSim-LitepaperExamplesShort.ipynb for calculations-only, in
our Carbon Simulator for a simulation of this position using our open-sourced Python
libraries.
3.2 Actual Carbon asymmetric liquidity mechanics
After having described the simplified Carbon asymmetric liquidity dynamics above, in
this section we discuss thedetailed mechanics. Before we do that, however, we go through
a brief example to show what the issue is with the simplified dynamics.
For this discussion, we are again referring to the chart “Buy-low-sell-high curves” that
can also be found on Desmos. We assume we start somewhere between the ranges, eg
at a price of 0.63. We are above the buy range, so as far as the blue curve is concerned,
we need to be 100% in the numeraire. We are also below the sell range, so as far as the
24
red curve is concerned, we need to be 100% in the risk asset. The only solution that
satisfies both conditions is a zero position which is of course not particularly useful.
What we have just shown is that it is not possible to run both curves on a single shared
state (x,y ). Instead, we need two separate states ( x−,y −) for the lower range, and
(x+,y +) for the upper range. Note that the effective state space is of dimension 2, not
4, because of the two invariant curves that need to be satisfied that tie the x to their
respective y.
Using Carbon conventions, the active asset on a curve (the one being sold) is always on
the y-axis, and the passive asset is on the x-axis. There is a correspondence between
differences but not between the absolute values of the cross-axis. This is best explained
with an example. We examine the chart “Two linked curves”, where the active token
on the left-hand side is some asset RSK, and the active token on the right-hand side is
USD (note that the risk asset / numeraire distinction does not make sense in Carbon).
In this case we find that
1. The y-axis on the left-hand chart is denominated in RSK and corresponds to the
actual number of tokens on the “RSK” (sell RSK and buy USD) curve
2. The y-axis on the right-hand chart is denominated in USD and corresponds to the
actual number of tokens of the “USD” (sell USD and buy RSK) curve
3. The x-axis on the left-hand chart is denominated in USD; its absolute values do
not matter, but differences are transmitted 1:1 to the right-hand side y-axis (2)
4. The x-axis on the right-hand chart is denominated in RSK; its absolute values do
not matter, but differences are transmitted 1:1 to the left-hand side y-axis (1)
Note that the system only tracks the y-values of the respective charts, as the x-values
can be recovered from the invariant curves.
The LHS (“sell RSK”) chart contains up to 100 units of RSK, and it sells at a range
around the average value of 225 USD per 100 RSK, ie 2.25 USD/RSK. The RSK (“sell
25
Figure 7: Two linked curves
USD”) chart is much bigger – it contains up to 5,000 units of USD, and it buys RSK
at an average price of 5,000 USD per 14,000 RSK, ie 0.36 USD/RSK. Note that those
values are extreme for demonstration purposes – real프로젝트로 돌아가기