DEX vs. CEX Part 2
Decentralized Exchanges: Pros and Cons
TL;DR:
Welcome back to the world of crypto exchanges, where the battle between centralization and decentralization rages on! In part one, we explored the inner workings of centralized exchanges and their role in the cryptocurrency ecosystem. Now we turn our attention to the decentralized side of things. From cutting out middlemen to maintaining user privacy, decentralized exchanges offer a new approach to trading that's both thrilling and controversial. So buckle up, and get ready to explore the benefits and drawbacks of decentralized exchanges in this second part of our three-part blog post series.
Just like a centralized exchange, a decentralized exchange (DEX) is an online marketplace for buying and selling cryptocurrencies. However, a DEX is non-custodial, which means there is no need for a middleman. Instead, these peer-to-peer platforms are facilitated via smart contracts, which are code stored on a blockchain that performs certain functions when preset conditions are met. This allows for full transparency when trading.
Main features of a DEX
Providing liquidity and yield farming
Since there is no middleman in a DEX, there is no entity that can match buyers and sellers. This is in contrast to the order book model used by a CEX. Instead, DEXs use facilitators called liquidity providers that ensure tokens are available to be traded at all times by offering them in aggregated liquidity pools: a group of two (or more) crypto assets managed by a smart contract. The simplest pools have balanced amounts of two different assets. For example, if a liquidity provider wants to enter a balanced pool of Ethereum and USD Coin (USDC, a digital stablecoin pegged to the United States dollar), they need to deposit 1 ETH (currently around $1600) and 1600 USDC. By offering tokens to this pool, a liquidity provider signals that they’re always willing to redeem ETH for USDC and vice versa. If the demand for ETH rises faster than USDC, the liquidity provider has less ETH in their position and more USDC. However, the total percentage of the pool represented by the liquidity provider’s position remains unchanged.
In return for this service, liquidity providers receive rewards. One of the biggest benefits of being a liquidity provider is that they collect a proportional amount of the fees from trades made in the pool. When a token is first offered on a DEX, there is generally a lot of volume: this is a great opportunity to provide liquidity and capture fees, especially if there is relatively little liquidity in the pool so far. These fees can be added to the liquidity provider’s liquidity position, either automatically or manually depending on the protocol, adding to the liquidity position like compound interest.
Video: Shimmer Defi Education Session #2 by BanklessConsulting: Token Swaps Dex vs. Cex 15/09/22
The fees can be offered in the form of one of the assets in the pool, or in the form of another token altogether known as a Liquidity Provider (LP) token. These LP tokens are platform-specific but generally composable. In some cases, you can deposit them with the protocol and receive a yield on them: this practice is known as yield farming. You can also borrow against them by using them as collateral. Different protocols have devised creative ways of adding value to LP tokens.
The bottom line is that liquidity providers allow the DEX market to function by offering their tokens to traders. If there are very few liquidity providers, this will have a negative effect on a DEX. In this case, token holders that want to buy or sell won’t be able to without moving the price significantly during the trade. Low liquidity increases volatility and doesn’t allow traders to get the maximum value for their tokens. Even after tokens are available for trading through the liquidity-providing mechanism, there must still be a way to determine the price for each asset based on supply and demand. Enter the Automated Market Maker.
Automated Market Maker: the algorithm behind a DEX
The Automated Market Maker (AMM) is simply a mathematical curve that determines the price of each asset in a pool based on the amount of each token in the pool:
Illustration: Constant product Automated Market Maker
The curve in the figure above illustrates how the price of an asset reacts to changes in the amount of assets in a pool. Specifically, the prices of asset A and asset B are calculated via the formula x*y = k, where ‘x’ is the amount of asset ‘A’, y is the amount of asset ‘B’, and ‘k’ is a constant. For this reason, this type of AMM is called a “constant product”. For example, let’s assume that a pool is balanced and the same amount of assets are available on each side. If a trader continuously sells the same asset, the price asymptotically approaches zero without actually ever reaching zero. This ensures that there is always a price for each asset in the pool and tokens will be available for trading. Although liquidity is available at all times, it will decrease as the chart moves farther away from zero. Having assets available to trade as well as a price for each asset is extremely important to the operation of a DEX.
Small orders generally don’t result in a significant price change as long as there is sufficient liquidity. However, larger orders can cause a significant change to the curve illustrated above. Slippage refers to the amount the price of an asset in a liquidity pool will deviate due to your trade. The higher the liquidity in a given pool, the less the slippage. Similarly, the lower the liquidity, the more slippage. If you make a large trade, the price changes over the course of your trade. While this also occurs in CEX order books, it’s a defined equation in a DEX. If there isn't much liquidity and you want to purchase a large amount of a given token, the slippage will be high and you will pay more and more per token as your order gets filled.
To combat the effects of slippage, DEXs generally allow you to set a parameter called the slippage tolerance. This number represents the percentage price movement you’re willing to tolerate to execute the order. For example, if you set the slippage tolerance to 1%, your order will only execute if the price moves less than or equal to one percent while executing your order. If your order causes the price to move more than that, the DEX won’t be able to execute your order. This is important because it’s often difficult to know how much the price will change as a result of your order since other traders can submit transactions to the same block. Most DEXs will inform traders of the expected slippage before executing an order.
Now that we’ve looked at DEXs from several angles, let’s summarize their strengths and weaknesses
Strengths of DEX
- Trustless: There is no counterparty risk as you’re only interacting with smart contracts.
- Transparent: You can see all of the orders on the blockchain and you can verify the code executing the order if you like. The entire process is verifiable.
- Permissionless: There are no gatekeepers preventing access, enforcing terms of service, or requiring KYC. Anyone in the world can participate.
- Composable: The DEX framework is modular and allows others to build on top of the foundations that exchanges have developed. In many cases, this can even be done without the permission of the exchange. This allows for improved network effects in building different ecosystems.
Weaknesses of DEX
- Exploit risk: The smart contract code could have a bug or an exploit leading to loss of funds. To minimize this risk, make sure that the smart contracts have been audited. For even more peace of mind, verify the audit at the website of the auditing company.
- Technical complexity: Interacting with a DEX is fundamentally different and more complicated than interacting with a CEX. It involves a steep learning curve and, without a firm understanding of the basics, it can be easy to lose money. Some of the more subtle, advanced considerations will be explored in the next section.
Despite the exploit risk noted above, this can be mitigated by the Lindy Effect. This is based on the belief that the longer a smart contract has been in use without being exploited, the more trustworthy it is. The amount of funds locked in these smart contracts tends to increase over time, making them more and more enticing to hackers. The more time has passed without an exploit since the contract was put in use, the less likely an exploit will be found. However, this is no guarantee, just a rule of thumb!
DEX or CEX?
In conclusion, DEXs are much more complicated than CEXs. However, the benefits far outweigh the drawbacks and enable privacy and self-custody — key features of cryptocurrencies. At the same time, CEXs certainly have their place and can provide peace of mind about regulations as well as convenient fiat on- and off-ramps.
In conclusion, both centralized and decentralized exchanges have their own unique set of benefits and drawbacks. Centralized exchanges offer ease of use, high liquidity, and strong regulatory compliance, but at the cost of centralization and potential vulnerability to hacks and fraud. Decentralized exchanges, on the other hand, offer increased privacy and self-custody - key features of crypto, as well as a more democratic, community-driven approach to trading, but at the cost of lower liquidity and potentially more complex user interfaces.
Hungry for more? In the next part of this blog post, we’ll dive a little deeper into more advanced elements of a DEX.
Next: Mastering Decentralized Exchanges
Beginner's Guide to DEX vs. CEX
Part 1: Centralized Exchanges: Pros and Cons
Part 2: Decentralized Exchanges: Pros and Cons
Part 3: Mastering Decentralized Exchanges
Also in this series
Beginner's Guide to Crypto Wallets
Beginners Guide to DEX vs. CEX
Beginner's Guide to DeFi Lending & Borrowing
Beginner's Guide to Yield Farming
Follow us on our official channels for all the latest Shimmer news:
Discord | Twitter | LinkedIn | Reddit