DeFi : Cex & Dex

Nowadays, investors, speculators, geeks and the curious do enter the cryptocurrency market through its front gate, one that has been slowly but steadily pushed open over the last few years by unprecedented financial flows enabled by “exchange” platforms. These fall into two main categories: centralized exchanges (CEX) and decentralized exchanges (DEX).

“CEX trusts the intermediary, DEX trusts the code.”

part 1

CEX

CEXs are, as of today, more popular, with big names like Coinbase, Binance, Kraken, etc. They are said “centralized” because they are very similar to traditional trading platforms, with centrally-managed order books for buyers and sellers, and the potential involvement of market makers.

In a nutshell: funds are stored on the exchange platform and get accessed with a classic mail+password+2FA triplet. The price of assets depends, at any given time, on standard bid and ask, the difference of which is called the spread, which is used to measure market liquidity. When there are too few players, the market may be illiquid, and that’s when market makers come into play. These professionals create liquidity for trading pairs by continuously buying and selling, thus generating a reasonable spread — which makes for the commission that compensates their risk exposure.

e.g., a market maker could buy a token for $10, then sell it for $10.05 ($0.05 spread). To fill this role, Binance is for example always looking for traders with monthly volumes over 1000 BTC.

From a legal point of view, CEXs are subject to the regulations of the countries where they are established, and must follow security procedures like KYC (Know Your Customer) to ensure they know who their users are and they fight against money laundering.

Pros: reassuring environment, easy-to-use. 

Cons: CEXs handle the custody of the funds themselves, and the assets available for trading are at their discretion. Consequently, they are specifically targeted in countries that try to ban cryptocurrencies, and they are more often the victims of hacker attacks.

"Not your keys, not your ."

part 2

Dex and Pools

The first DEX used an order book model similar to CEXs’, but suffered from a significant lack of liquidity coupled with a poorly-efficient UX/UI. It was necessary to completely rethink the notion of trading and liquidity. 

Today, a DEX is defined by an AMM protocol (Automated Market Makers) powered by deterministic algorithms in an immutable smart contract system. In other words, it is a Peer-to-Contract (P2C) exchange where users connect their personal wallet to swap tokens by interacting with a smart contract. In a DEX, rules are known in advance, intermediaries are not needed, liquidity is automated and KYC is not required.

1 - How does it work?

Most DEXs operate with (a) an AMM protocol, (b) liquidity pools, (c) liquidity providers (LPs) and (d) users.

The AMM protocol is based on mathematical functions that estimate the exchange rate of 2 assets according to the available liquidity. There are several types of AMMs: constant function, constant average, hybrid constant, etc., these names being directly related to specific mathematical functions. An AMM replaces the need for market makers but requires constant liquidity to properly function: this is where liquidity pools come in. 

A liquidity pool is a reserve of tokens locked in a smart contract. To create a market, users called liquidity providers (LPs) are invited to add to the pool an equal value (1) of each of the two tokens of a trading pair. In other words, in an A/B pair pool, LPs deposit the same value of token A and token B. When the pool fills up, the market becomes more liquid.

A user can exchange one of the tokens of the trading pair for another against a commission that will be paid to the LPs (according to their respective holdings in the pool). 

Important: prices being set algorithmically (and/or with the help of oracles in some cases), this leads naturally to arbitrage behaviors, where some users buy and sell an asset for the sole purpose of profiting from the price difference between the asset and the market. This is sound, as it enables users to make a profit out of helping the DEX to stay aligned with the market price.

(1) Equal value: this is for example the case with Uniswap V2. But some other DEXs propose to deposit one or more coins in proportions different from 50%, like DODO which proposes for example to add a single coin, etc.

2 - Uniswap V2’s “x*y=k”, the 15 Billion Dollar equation

In this section, you will learn how AMM “functions” work. To that end, let’s take the example of x*y=k, the AMM function of the Uniswap V2 protocol, the one regularly used for vulgarization as it is easy to understand.

Disclaimer: With version V3 of Uniswap — the most popular DEX on Ethereum –, some processes have become more complex. The following explanations are simplified in the interest of education. And for that same reason, we shall ignore the 0.3% fee applied by Uniswap and which eventually increases “k”. But we’ll get to that later… 

In x*y=k, x is the number of tokens A, y the number of tokens B, and k the product or constant. This AMM is called CFMM (Constant Function Market Maker), but there exist other types. 

Let’s draw the graph of the function x*y=k: (Source: cryptocurrency)

The interpretation is very simple: 

– If the number of tokens B (y) increases, then the number of tokens A (x) decreases, and vice versa;

– If x or y varies, then k slides on the curve, it is called slippage, the curve indicates the values of k.

In its simplest terms, the price is a ratio between x and y where the price of x in relation to y is the ratio y/x and vice versa for y.

Swapping thus generates a price impact, i.e., a change in price caused by a change in ratio. A larger slippage means a larger price impact and a more expensive exchange price. 

The x*y=k equation finally adds the enviable property that larger trades (relative to reserves) are executed at exponentially higher rates than smaller ones.

3 - Limits

However ingenious, AMMs are not perfect and come with limits:

  • Small use of funds: to narrow down the price impact, slippage needs to be limited. As a result, one can never take full advantage of the available liquidity.
  • Non-permanent loss: providing liquidity is sometimes less profitable than simply keeping the funds in a wallet.
  • etc.

It is crucial to understand the protocol where one wants to block his/her funds in order to understand the risks involved. Today, DEXs continue to innovate to solve these issues. 

Examples: Uniswap V3 introduces the notion of concentrated liquidity to overcome the small use of funds; Bancor V2 uses automatic weighing (via an oracle) to limit non-permanent losses; Dofo uses a Proactive Market Maker (PMM); etc. 

DEXs are a core feature of DeFi (Decentralized Finance).

Next article: Decentralized Finance and Insurance.

Share on facebook
Share on twitter
Share on linkedin
Share on reddit

Leave a comment

Your email address will not be published. Required fields are marked *

Recent Comments

    Table of Contents

    Categories

    If you would like to receive the Talium Assets Newsletter, please submit your e-mail address:

    Where to find us:

    Head office

    56 av Jean Jaurès, 92290
    Châtenay-Malabry, France

    R & D office

    5a quai Finkmatt, 67000
    Strasbourg, France

    Our Solutions:

    Latests Article: