Demystifying DeFi


There is a bunch of people who want to exchange A for B and B for A, and are willing to do so in different proportions (price) and for some limited amounts. Collecting their preferences we are building a CLOB:

A CLOB (central limit order book) is characterised by a time and price priority execution, such that any taker will be executed against whoever gave first the most advantageous offer, in case of multiple offers per price level.

Given the relatively long block times (discrete-time in DeFi vs continuous-time in CeFi) and the high tx fees needed to place and cancel offers on-chain, a new primitive was introduced: the AMM and their liquidity pools.

Initially, though it might seem like an outlandish concept, we will see how an AMM (automatic market maker) is actually just a generalisation of the concept of orderbook, operating in a price continuum, as opposed to CLOBs that operate in discrete price ticks!

Another fundamental difference is that liquidity pools process executions pro-rata rather while CLOBs use FIFO (first-in, first-out) for order matching. Despite these differences, we can try to map an AMM swap to a trade on a CLOB:

For the CLOB trade, we consider a simple exchange where q BTC are sold (swapped) for p*q USDT, where p is the BTC price in USDT.

For the AMM swap, we consider an equivalent exchange and specifically notice that our trade has modified the quantities of reserves available in the pool. BTC quantity has increased by q and USDT quantity has decreased by p*q, modifying the pool-implied price of BTC in USDT

Mapping this trade on these two apparently different primitives does not seem so challening afterall…

Let’s find some common representations.. Enter “Liquidity distribution”! We can introduce a new mapping of the orders (CLOB was represented using a price-quantity chart) and express them in terms of quantities instead (q1=q, q2=q*p)

A trade/swap in this new mapping is visualised as moving along the liquidity distribution curve as one asset is exchanged for the other

No longer bound by the constraint of the CLOB mapping we can imagine a whole class of liquidity distributions representing different markets and trading environments

designing different curves will determine how the price changes as trades are performed against the pool. High slippage vs low slippage, price discovery vs. stale price (high exposure to arbitrage).

So let’s revisit now the proposed AMM (tweet 2/17) and see what the rule for computing the swap price really means for the health of the pool:

We can see that what’s missing from the swap rule is slippage! 😱 Without slippage the pool can be exploited by first emptying the pool, causing the new price to be 0 and then acquiring all the BTC originally in the pool for an infinitesimal amount of USDT

In crypto two curves have had the most success and widely implemented: The so-called @uniswap curve XY=k and the stable-invariant introduced by @curve to limit slippage of kind-assets

To sum it up, we have seen how both CLOBs and AMMs can be represented as liquidity distribution curves, as well as introduced some of the properties of these curves and their effects on the trading activity

Another time for a discussion of an interesting phenomenon somewhat well hidden in traditional CLOBs but very much discussed in the world of AMMs: the impermanent loss / short convexity / adverse selection / optionality — given away when playing with your cards face-up