Disruption Or Disillusion?

Upcoming exchange concepts – a farewell to the order book?

General Introduction and Uniswap

New exchange concepts are kick-starting in the blockchain space. For example, Uniswap has no orderbook and provides liquidity at all times (given there is at least one liquidity provider). Trades are instant because orders are filled by a deterministic function. Do ideas like this have the potential to change what we used to know in common finance?

Crypto projects often praise themselves for being disruptive “all new” projects. If you take a look behind the scenes, sometimes, disruption becomes disillusion. Scam, bad copy-cats, ideas far beyond reality, mooning marketing concepts and “making already existing solutions just more inefficient” are not unusual in the blockchain scene. Fortunately, people got more suspicious after the first bubble burst. Hence, it became harder for scam to survive and more promising projects evolve. But are these projects really disruptive? Do they have the potential to take over what we used to know?

I am a finance PhD student – currently employed as an auditor at Chainsecurity. We audit big projects and get unique insights into them. I will introduce (often – but not only – finance related) projects in my blog series: Disruption or disillusion? Please, don’t let this be a one-man show and start a lively discussion about these topics.

First and foremost, projects like Uniswap are not meant to replace everything but to add diversity. They target specific traders and not everyone. They are not perfect and we will discuss their flaws in the following paragraphs.

Let us start with a quick reminder on how common markets are classified and how they work. If you know it, feel free to skip the next two paragraphs.

We usually differ between three market types.
– Dealer market
– Broker market
– Exchange

We will not go into detail here about Dealer and Broker markets (this can be looked up quickly in the linked articles dealersmarket and brokerandmarketmaker). Instead, let us focus on Exchanges (very high-level and simplified). Exchanges try to connect the two parties (buyer and seller) directly this is usually done by an auction based market. In an auction based market, buyers enter competitive bids and sellers submit competitive offers. The exchange keeps track of all bids and offers (asks) in a so called orderbook. An exchange tries to match two orders if possible. The current price is the price at which the last bid/ask match was possible. The bid/ask spread is the price difference between the bid and ask orders closest to the current price. Here is a Youtube video explaining order books.

No need to go into more detail here, just let me quickly add that there are different ways to match the orders and the auction implementation may vary a little. For the sake of simplicity let us refer to these types of exchanges as “order book based” (sometimes referred to as Central Limit Order Book CLOB – even though this term can be misleading) exchanges.

Exchanges (order book based), brokers and dealer markets is what we are used to in common finance. Request For Quotation (RFQ) exchanges are another approach that might still sound familiar to some of you (as far as I know AIRSWAP is using this technique).
KYBER SWAP even combines multiple techniques. It is a project that leverages Ethereum’s potential for decentralization by combining different, independent liquidity providers. These are free to define and change their own pricing strategies and KyberSwap then automatically determines the best exchange rate for the user. All this takes place inside a single transaction and with minimal exchange rates that are protected by smart contract guarantees.

Another interesting approach take projects like Uniswap and Bancor. This article will focus on Uniswap, a project which has enormous support in the community and increasing volume. It is backed by the Ethereum Foundation and has lately been funded by Paradigma. To make markets they use an algorithm. This technique is sometimes referred to as “Automatic Market Maker”. The particular variant Uniswap uses, is called Constant Product Market Maker Model (CPMMM) (see here how the name came up). The CPMMM is a simple deterministic function and the name accurately describes what it does. – as we will see below.

I do not want to call it a new type because I do not know if they are new. Most likely this technique has been around for quite some time but lead an obscure existence.

A market without an order book. How does the CPMMM work?

I will only briefly touch the Constant Product Market Maker Model here. In Uniswap there is no order book. The CPMMM always provides liquidity. The price is a function depending on supply and demand. Given a pair of assets $ Asset_A $ and $ Asset_B $ e.g. DAI and ETH. The function is:
$$ supplyAsset_A*supplyAsset_B=C $$
The $ supplyAsset_A $ is the amount of Asset A currently available on the exchange and the same applies to Asset B.

The product is some value $ C $.
For example:
$$ 100_{DAI}*100_{ETH}=10000_{DAIxETH} $$
So far, so good, right?

There are two kinds of participants on Uniswap: the so called liquidity provider and the common traders.
First, let us focus on the trader who wants to buy $ 5_{DAI} $ for $ ETH $. Given the function above and the example liquidity of $ 100_{DAI} $ and $ 100_{ETH} $ on the exchange, the trader can calculate the price they have to pay for $ 5_{DAI} $. The simple rule is: Keep the product constant. Hence, after the trade has been executed, the product still needs to be $ 10000_{DAIxETH} $. Let us see how much ETH the trader needs to put into the ETH liquidity pool to take out $ 5_{DAI} $ and keep the product constant. This can easily be calculated by $ (100_{DAI} – 5_{DAI}) * (100_{ETH} + x_{ETH}) = 10000_{DAIxETH} $. We subtract $ 5_{DAI} $ because they are taken out of the pool. We add $ x_{ETH} $ because that is what the trader needs to pay (put into the pool) for taking the $ 5_{DAI} $ out. Solving for $ x_{ETH} $ gives $ x_{ETH} = \frac{10000_{DAIxETH}}{95_{DAI}} – 100_{ETH}$. Hence, the trader needs to put $ x_{ETH} = 5.263158_{ETH} $ into the ETH pool for taking out $ 5_{DAI} $. This price seems reasonable because we started with a 1:1 ratio of DAI and ETH. If one asset is in high demand, the liquidity pool will have less and less of this asset. Hence, it gets more and more expensive. Obviously, the function is a multiplication and therefore, this does not scale linearly. This can easily be visualized by plotting the function and all possible prices. I also added two example trades. You can find more information on the trades below the image.

In this example, let us assume we have 100 token x and 100 token y. Hence, the product $C$ would be $C=100 * 100=10000$ . The initial start from which prices are calculated, would be the point A in the picture. Let us assume that trader B will buy $ 20_y $ tokens. Hence, trader B has to pay (put into the liquidity pool): $ (100_y-20_y)*(100_x+x_x)=10000_{x*y} $. Therefore, $ x_x=\frac{10000_{x*y}}{(100_y-20_y)}-100_x=25_x $. We end up at point B (blue) in the illustration above.

Let us assume another trader C. This trader wants to buy 75 x tokens. Hence, trader C has to pay (put into the liquidity pool): $ (80_y+x_y)*(125_x-75_x)=10000_{x*y} $. Thus, $ x_y=\frac{10000_{x*y}}{(125_x-75_x)}-80_y=120_y $. We end up at point C (red) in the illustration above. It is obvious how the price shifts on curve.

Initial price to pay new
$ 100_x $ : $ 100_y $ $ 25_x $ for $ 20_y $ $ 125_x $ : $ 80_y $
$ 125_x $ : $ 80_y $ $ 120_y $ for $ 50_x $ $ 50_x $ : $ 200_y $

It is easy to see that the price impact decreases if the liquidity increases relative to the order size. Hence, the price directly depends on the order size. But this is similar to “common” exchanges. In the above example, the last order was over 60 percent of the whole liquidity of token y. Most likely it would have been very hard to fill this order at once on a “common” exchange. Instead of setting limit orders, the trader can pre-calculate the price and see if they want to execute it or not. Here front-running could be an issue. But let us cover this later in the code discussion.

Above, we assumed an initial liquidity pool aka supply of $ 100_{DAI} $ and $ 100_{ETH} $. Where did this come from? Let us look behind the scenes and see how liquidity is added to an exchange contract. The so called liquidity provider can deposit DAI and ETH into the liquidity pool. Let us take as an example a newly created exchange. No DAI and no ETH liquidity are deposited. A liquidity provider, as the name suggests, provides liquidity. But it is a little bit different to what most readers might be used to. A liquidity provider always needs to provide both assets. In our example they need to provide ETH and DAI.
A liquidity provider cannot just add ETH or DAI. Not in the CPMM model. Hence, the liquidity provider needs to deposit liquidity for both sides. In our example they need to add ETH and DAI in the correct ratio. The correct ratio is given by the current price. Let us assume the price is $ 10_{\frac{DAI}{ETH}} $. Hence, they need to deposit ten times more DAI than ETH. E.g. $ 1000_{DAI} $ and $ 100_{ETH} $. If the price does not change, the next liquidity provider will add liquidity for both assets in the same ratio. If the price changes the liquidity provider will adjust the ratio. In case they would not, arbitrageurs will immediately correct the price.

Liquidity providers get a so called liquidity token to keep track of their stake in the liquidity pool. They can redeem their tokens for the corresponding liquidity pool share. In a nutshell, that’s all. This sounds a little too simple. But maybe this is what makes this idea efficient and brilliant. What are the implications and drawbacks one may ask? Can the system collapse? Let us go into further detail and work through the questions.

Implications and drawbacks

The attentive reader will quickly realize that liquidity providers, in contrast to traders, are exposed to a risk: they need to lock down their funds to provide liquidity. Hence, they do have opportunity costs for the locked down capital. Let us examine the risk a liquidity provider bears in the following example. Let us assume the fair value of $ 1_{DAI} $ is $ 1_{ETH} $ (I know… it’s for illustration purposes only).

Scenario 1:

No trades happen

Value on Uniswap

$ t_0 $ $ t_1 $ $ t_2 $
100 DAI 100 DAI 100 DAI
100 ETH 100 ETH 100 ETH

Total value in $ t_2 $

Currency Value
mixed 100 DAI 100 ETH

Assuming another exchange provides enough volume at the current $ 1_{ETH} = 1_{DAI} $ price. Because, in case, the liquidity provider is the only one, another exchange is needed to convert the corresponding funds.

In $ t_3 $ the liquidity provider withdraws their funds and gets back what they put in initially ($ 100_{DAI} $ and $ 100_{ETH} $). Hence, the liquidity provider only has opportunity costs because they did not earn any interest on the capital during this time. The opportunity cost for locked down capital is pretty obvious. The liquidity provider could use the capital and e.g. earn interest rates on it (e.g. on compound.finance).

Scenario 2:

Trader 1 buys 5 DAI for ETH.

$ t_0 $ $ t_1 $ $ t_2 $
100 DAI 95 DAI 95 DAI
100 ETH 105.263158 ETH 105.263158 ETH

Total value in $ t_2 $

Currency Value
DAI $ 95_{DAI} + \frac{105.263158_{ETH}}{5.263158_{\frac{ETH}{DAI}}}*5=195_{DAI} $
ETH $ 95_{DAI}*\frac{5.263158_{\frac{ETH}{DAI}}}{5} + 105.263158_{ETH} = 205.263158_{ETH} $
mixed 100 DAI 100 ETH

Assuming another exchange provides enough volume at the current $ \frac{5.263158_{ETH}}{5} := 1_{DAI} $ price. Because, in case, the liquidity provider is the only one, another exchange is needed to convert the corresponding funds.

This time, the liquidity provider gets $ 95_{DAI} $ and $ 205.263158_{ETH} $ back. Now DAI is worth more than ETH. Therefore, the total value in DAI or ETH changes according to the currency used for evaluation. But overall, the value does not change. As before, the liquidity provider only has opportunity costs.

Scenario 3:

Trader 1 buys 5 DAI for ETH $ 5.263158_{\frac{ETH}{DAI}} $.

Trader 2 buys 5 DAI for ETH $ 5.84795_{\frac{ETH}{DAI}} $.

$ t_0 $ $ t_1 $ $ t_2 $
100 DAI 95 DAI 90 DAI
100 ETH 105.263158 ETH 111.111 ETH

Total value in $ t_2 $

Currency Value
DAI $ 90_{DAI} + \frac{111.111_{ETH}}{5.84795_{\frac{ETH}{DAI}}} *5 = 185_{DAI} $
ETH $ 90_{DAI}*\frac{5.263158_{\frac{DAI}{ETH}}}{5} + 111.111_{ETH} = 116.3741_{ETH} $
mixed 99.49991 DAI 100 ETH

Assuming another exchange provides enough volume at the current $ \frac{5.263158_{ETH}}{5} := 1_{DAI} $ price. Because, in case, the liquidity provider is the only one, another exchange is needed to convert the corresponding funds.

Now, it gets interesting. The liquidity provider would get back $ 90_{DAI} $ and $ 111.111_{ETH} $. But in total the liquidity provider lost $ 0.50009_{DAI} $ (or the corresponding amount in ETH). This is the additional risk the liquidity provider bears. To get back their initial investment the liquidity provider always needs to trade the asset which lost worth against the one which gained worth. As soon as the price starts moving into one direction, the liquidity provider will get the latest (but worst) price, to trade back their funds. In case the latest price was not the price to which all trades happened, a loss will be the result. In our example there was one trade at $ 5.263158_{\frac{ETH}{DAI}}$ and one at $5.84795_{\frac{ETH}{DAI}}$ . To get back the initial investment of $100_{DAI}$ and $100_{ETH}$ the liquidity provider would need to trade $5.84795_{ETH}$ for $5_{DAI}$ and $5.263158_{ETH}$ for another $5_{DAI}$ . But $5.263158_{\frac{ETH}{DAI}}$ is history. The current exchange rate is $5.84795_{\frac{ETH}{DAI}} $ and therefore, worse. Hence, the liquidity provider needs to exchange $ 11.111_{ETH} $ at $ 5.84795_{\frac{ETH}{DAI}} $. Thus, they lose $ 0.5000898=10_{DAI}-\frac{11.111_{ETH}}{5.84795_{\frac{ETH}{DAI}}}*5 $. The loss increases if more trades happened at a more favorable price and/or the price gap increases between the last price and the prices before.

What is the compensation for someone to become a liquidity provider? They do get a fee which is charged with each trade. The million dollar question is if or when do the fees compensate the risk plus the opportunity costs.

I do not want to make this article too long and this is why I will stop here.

What makes Uniswap so interesting?

  • Simplicity
  • Continuous liquidity
  • Immediate execution


I sometimes read that large orders on Uniswap are more expensive. I need to object that this only happens if they are large compared to the provided liquidity. A large order which drains a big share of liquidity on a “common” exchange will also be expensive or not executed at all. If the slippage is not controlled properly there is a chance to front run the Uniswap orders. Maybe more on that in upcoming parts.

Right now Uniswap does not want to replace existing exchanges. Furthermore, they see themselves as a kind of supplementary exchange and welcome arbitrage traders to adjust the prices. Hence, Uniswap depends on other exchanges to keep the rates balanced. Uniswap is still beta and highly experimental. Could Uniswap theoretically replace existing exchange/markets types? Would this be a market type which could make it out of the crypto space and disrupt the predominant exchange types? Has it any major drawbacks or limitations? What do you think?

Mail me (nico@chainsecurity.com) if you are interested in further blog posts (or podcasts/Youtube videos) about topics like:
– Does it make sense to become a liquidity provider for Uniswap?
– Arbitrage opportunities (at best this should be done by liquidity providers)
– Can the system collapse?
– How is the code implemented?
– Bancor – a different concept

Other sources on this topic: https://medium.com/scalar-capital/uniswap-a-unique-exchange-f4ef44f807bf or