Decentralized Finance (DeFi) is one of the greatest innovations that came out of the Web3 revolution. One of the first inventions was the decentralized exchange (DEX)— a mechanism to trade tokens without the need for a centralized entity to facilitate the trade.
This article compares a centralized exchange to a decentralized one and covers the benefits and downsides of both.
A centralized exchange (CEX) is a type of cryptocurrency exchange that is operated by a company that owns it in a centralized manner. It has an order book that collects all ‘limit orders’ of market participants. A limit order is an order that has a target price to buy or sell the asset within a certain timeframe. For example, if an asset is trading right now for $10.50 and you would like to purchase it for $10, you can put a limit order at $10, which will then buy the asset when that price target is hit.
As a market participant, you can also place a market order— in this case, you buy or sell the asset for any price someone else is willing to sell or buy it for. A centralized exchange connects buyers with sellers and vice versa. In any case, two parties are required to set a price to buy or sell and those are then matched. A limit order is a passive action to buy or sell and a market order is an active one.
Centralized exchanges are efficient and cheap. The cost of a transaction is close to zero. The downside is that a centralized authority has control. In some cases, transactions can be reversed, which is fundamentally against the principle of crypto open markets.
Another downside is that exchanges can be closed for certain amounts of time, not giving market participants the option to get in and out of positions. Participation is also permitted, in some cases you need to have a particular brokerage account, be an accredited investor or come from a certain region to participate in the market.
Binance, Kraken, Coinbase, and FTX are some examples of centralized exchanges.
A DEX operates in a fundamentally different way. Instead of having two parties that decide to engage in a trade, the buyer and seller, a DEX only has one party that actively decides to trade.
This is possible, because the counterparty, the liquidity provider, has locked up the token you want to sell and the token you want to buy with the trade you intend to make. This works as follows:
Let’s say you want to trade Ethereum for Bitcoin. A liquidity provider has locked up both Ethereum and Bitcoin in a liquidity pool. You can then send Ethereum into the pool and receive Bitcoin back, without the liquidity provider having to do anything.
Let’s assume the price of Ethereum was $1,000 and the price of Bitcoin $10,000. If the pool would be 50/50 balanced, it would contain 10x as much Ethereum. The total for example could be 100 Ethereum and 10 Bitcoin within the pool.
Now when you swap 10 Ethereum for 1 Bitcoin, the pool would have 110 Ethereum and 9 Bitcoin. The beauty of a DEX is that the total value of the pool stays the same, ensuring that the liquidity provider doesn’t lose money, but actually makes money on the paid fees for the trade.
The way that works is with the following formula: x * y = k
If we go back to the example we can demonstrate that it works. x will be the price of Ethereum and y the price of Bitcoin. Before the trade the total value of the liquidity pool is (( $1,000 * 100 = $100,000) + ($10,000 * 10 = $100,000) = $200,000).
After the trade, the total value of the pool must still be $200k, split 50/50 over Ethereum and Bitcoin. This assures that anyone can always buy or sell either asset. The price would of course go up exponentially until there are no assets left in the pool.
In reality, the pools are much bigger and there are arbitrage hunters that assure the price of assets stay more or less the same across centralized and decentralized exchanges.
The beauty of decentralized exchanges is that you can always buy or sell your asset. It is permissionless, so anyone anywhere can trade assets. There is no centralized institution that can halt trading or cancel past orders.
You might argue that in some cases it is good to halt trading, as entities caught up in massive short squeezes could derail the global financial system, as they get margin calls and cannot pay, which causes a ripple effect of margin calls across financial institutions.
This is currently true, however, in the future, the risk taken on by a lender will be fully on-chain, making it much more transparent for all parties involved. This could for example execute the margin call directly when certain thresholds are met, or execute it in phases as the entity is approaching insolvency.
Crypto has seen several huge drawdowns in the past, without any major implications on players in the industry, other than the ones becoming insolvent, as everything is much more transparent and tradeable 24/7, meaning you don’t get caught into a gap up or down overnight.
The downside of a DEX is that liquidity providers can suffer from impermanent loss (IL)—if IL exceeds fees earned by a user when they withdraw, it means the user has suffered negative returns compared with simply holding their tokens outside the pool. This happens when one of the tokens goes up significantly vs. the other token within the liquidity pool. In that case, the liquidity provider would have made more money just holding both tokens without the automatic rebalancing function of the liquidity pool. So in fact it is not really a loss, it is just fewer profits than otherwise would have happened.
Uniswap, Sushiswap, Balancer, Trader Joe, and Pancake Swap are some examples of DEXes.
All in all
Decentralized exchanges are a major innovation and one of the most successful use cases so far within crypto. In the future, all trading will probably be executed on decentralized exchanges, as over time it will be cheaper and quicker, including all benefits outlined above.
For parties not wanting to engage wallets and connect themselves to a DEX, they could have the interface of a traditional broker, and that broker using a DEX in the back-end to execute trades. We await what the future holds and hope that security is involved in the development process.
Lossless is the world’s first DeFi hack mitigation tool for token creators. Apart from our known cyber security solutions and renowned professionals, the community also plays a role. With a tangible reward system, community members are also encouraged to explore new ways to detect hacks and fraudulent transactions.
Our protocol halts counterfeit transactions through various methods of fraud identification and automatically reverses any stolen tokens back to the original owner. Our solutions to the impending problems of cyber theft within the blockchain space are thorough and applicable within many protocols.