AMM DEXs: Decentralised exchanges that run on smart contracts
DEX, Decentralised exchanges, have existed since the early years of bitcoin, however, they were very complex sites to use and not very accessible. On top of that, they often had problems with liquidity and price slippage.
In 2019, UniSwap appeared, giving way to a series of exchanges based entirely on smart contracts.
DEXs before UniSwap
Decentralised exchanges are protocols on blockchain that allow anonymous or pseudonymous trading, without censorship and without relying on a central server.
The first decentralised exchanges were, like the centralised ones, based on an order book that matched buyers and sellers, supply and demand.
Exchanges were peer-to-peer, i.e. directly between one trader and another. So there was no company to help regulate the exchanges and keep the platform secure, but there was a smart contract to do so.
That’s why decentralised exchanges even today are non-custodial, i.e. they don’t allow cryptocurrencies to be stored on an integrated wallet.
So what was the problem?
The problem was basically the order book. The order book is a record of all buy and sell orders placed at a certain price and for a certain amount.
Typically in advanced or decentralised exchanges, it is possible to either place a market order, i.e. at the next available market price, or to place an order that will only be executed when a certain price is reached, and thus remains pending in the order book (stop or limit order).
In basic exchanges there is an order book and when you buy or sell you are placing an order, only this book is not visible and all orders are at market price.
Order book-based exchanges operate with two types of traders: makers and takers.
When you place an order that does not match an existing order in the order book, you become a “Maker” because you create a new order. In this case, you are adding liquidity to the market.
When you place an order and it can be filled by an existing order in the order book, you become a “Taker“. This is because you have filled someone else’s buy or sell order and thus “took” an order from the order book. In this case, you are taking liquidity from the market.
Usually the difficulties start when there are not enough makers, or when there are more takers than makers. As a result, there is a lack of liquidity, orders are executed at undesirable prices and trading stops.
UniSwap and AMMs
To save the day, an Ethereum-based protocol arrives in 2019. It is UniSwap, which introduces the concept of Automated Market Makers (AMMs), software that enables the automation of market orders by overcoming liquidity and volume issues.
AMMs make it possible to programme trades, so-called swaps, as they are smart contracts. Thus, we move beyond peer-to-peer exchanges and discover peer-to-contract.
The Maker, the fundamental element of the exchange, becomes a smart contract. But where do these UniSwap makers get their liquidity from?
UniSwap uses Liquidity Pools, which are other types of smart contracts dedicated to storing large pair quantities of liquid tokens, i.e. immediately exchangeable.
So, for example, to fuel the ETH-DAI trades, there is a dedicated liquidity pool in which a large number of Ethereum and DAI tokens are stored.
And where do these large quantities of tokens come from? Do the protocol developers provide them for free? Is there a company or a foundation?
No, because it would not be a decentralised system and would not be sustainable in the long run.
To incentivise the provision of liquidity, UniSwap decides to give periodic rewards to those who are willing to lock their cryptocurrencies in liquidity pools. In this way, they help the DEX and receive rewards proportional to the amount used and the duration of their supply. These rewards are made up of the exchange’s transaction fees, paid by traders.
The Swap Boom
During 2020, a number of DEXs based on this concept began to emerge. Where SushiSwap and PancakeSwap copied the basic UniSwap code, on the other hand Curve Finance created its own AMM formula, Balancer brought multi-token pools and 1Inch proposed instead to aggregate several DEX AMMs.
Having dedicated in-depth studies to all Swaps, we will analyse here the rest of the most innovative and successful DEX at the current state (end of 2021), namely Curve, 1Inch and Balancer.
Curve Finance: how it works
While most DEX AMMs are on Ethereum, Curve is multichain. That means it exists on multiple blockchains. Curve’s primary blockchain is Ethereum, but other blockchains such as Polygon, Harmony, xDAI and Avalanche offer Curve advantages including speed and cost.
In order to use Curve on other blockchains, it is necessary to send funds from Ethereum to the secondary blockchain using a bridge.
Curve addresses the problem of Uniswap, where pools of similarly priced pairs do not work well. These are for example pairs of stablecoins or wrapped tokens of the same coin.
Curve thus started as a DEX for stablecoins, however it also offers plenty of pairs of different forms of Bitcoin, Ethereum and some cryptocurrencies from the blockchains on which it is available. Since stablecoins “should” all have the same price, Curve allows different percentages of each token to be deposited into the pool, and has pools that contain more than 2 stablecoins.
Due to its unique price curve formula, Curve manages to maintain the value in a stablecoin pool over a much wider price range than Uniswap.
The ends of the curve are much more pronounced, so outside of that price range the value of the pools could fluctuate a lot, however at that point it is a problem of the stablecoins not being able to keep themselves pegged to the dollar.
The ends of the curve are much more pronounced, so outside that price range the value of the pools could fluctuate significantly, though at this point the problem is with stablecoins failing to keep their peg to the dollar.
Balancer and 1Inch
Balancer and 1inch are still different types of DEX with a specific added value and are both based on Ethereum.
Balancer, in addition to being an AMM-based DEX and liquidity pool, is a portfolio management protocol. On Balancer, each pool can contain up to 8 tokens, as each pool reflects a kind of diversified “fund” of cryptocurrencies.
Liquidity providers can deposit their tokens in:
- a private pool, of which they have full management
- in a shared pool, whose options and rules are collectively managed through a dedicated token (BPT)
- in a smart pool, managed by a dedicated smart contract.
1Inch on the other hand is an aggregator of different DEXs, which allows it to have large volumes and liquidity available for trading. 1Inch is also available on Solana and Polygon.
When you place an order on 1Inch, it chooses for you the most convenient DEX to carry out the trade on, optimising fees and avoiding price slippage.