A decentralized exchange, or more commonly a “DEX”, is one of the most fascinating aspects of the DeFi revolution. As you may already know, DeFi, is a movement wherein developers create decentralized alternatives of various traditional legacy financial institutions and products. The DEX is the decentralized version of an exchange, such as a crypto exchange. Before we answer the “what is a decentralized exchange” question, let’s learn about traditional exchanges and its many flaws.
What is a cryptocurrency exchange?
Centralized cryptocurrency exchanges are often the first point of contact that people have with the crypto world. The chances are that if you have cryptocurrency, you must have bought it from one of these exchanges. The exchanges act as a portal between the “real” world and the crypto world.
Now, don’t get us wrong. While they have plenty of flaws, they certainly have some advantages, as well.
- They enjoy consistently high liquidity.
- They are responsible for the vast majority of the trading volume.
- Centralized exchanges are generally a lot faster leading to better user experience.
Decentralized Exchange Blueprint: The Components of an Exchange
Before we even get into the differences between centralized and decentralized exchanges, let’s understand the different components that make an exchange.
- Graphical user interface (GUI): This is the customer-facing interface that contains everything that you see on the website as a user.
- Trading engine: A trading engine, aka matching engine, is a software that keeps the record of all the open orders and generates trades if there are two matching orders.
- Cryptocurrency wallets: Upon registering with the exchange, you will have wallets linked to your account for specific cryptos.
- Liquidity: Exchanges must have the liquidity required to sustain healthy trading.
Why choose decentralized exchange? The flaws of centralized exchanges
#1 Security flaws
Let’s get the main point out of the way.
Centralized exchanges are a significant security hazard because of their innate nature and architecture. If this seems like an over-exaggeration to you, then consider the following examples:
|Coincheck – The second largest Japanese exchange||$500 million worth of NEM|
|Bitgrailt – Italian exchange that was the first to list Nano||$195 million|
|Binance – One of the biggest exchanges in the world||$40 million|
|Coinrail – South African exchange||$40 million|
|Zaif – Japanese exchange||$60 million|
While leaders like Coinbase, Binance, and Bitfinex have done all that they can to bring in very admirable security, these exchanges will remain a target for the hackers. Either the hackers are directly trying to infiltrate the defenses, or they are trying to bombard the users with elaborate phishing scams.
#2 Giving up control over your funds
This is an extension of the previous point. In a centralized exchange, you have to give up control over your funds to a third party. These exchanges use “hot wallets” or wallets directly connected to store a small portion of its assets for trading purposes. The rest are stored in cold offline wallets. Unfortunately, there are some major issues with both these approaches:
- Hot wallets are connected to the internet, meaning that they are always vulnerable to hacks.
- While storing a majority of the coins in a cold wallet sounds like a good idea on paper, you are merely creating another dangerous dependency. One need not look any further than the Quadriga exchange debacle. The CEO, who was in charge of the cold wallets, suddenly passed away. In the process, the exchange lost around $145 million worth of crypto.
#3 Human greed
Back in 2018, CCN reported that exchanges could charge as much as $1-$3 million to list a token. To understand how ridiculous this is, consider that listing stock on NASDAQ costs just $125k-$300k (plus annual maintenance charge). However, this is not the only way that exchanges can exploit cryptocurrency projects. The following can happen as well:
- Exchanges have suspected of creating fake trading volume (called wash trading), insider trading, and price manipulation.
- The exchanges usually charge higher trading fees. The lack of transparency makes it impossible to look at how the exchanges are dealing with finances.
- All Exchanges have a withdrawal limit that constricts the amount that can be taken out at once. However, looking at it from another POV, by keeping your funds locked up, they manage to maximize their trading fees.
What is a decentralized exchange?
A decentralized exchange doesn’t have a centralized entity taking control of your assets or the order book. A DEX is often developed as a decentralized application that runs on a particular blockchain. A prime example is this Binance DEX that runs on top of the Binance blockchain. Users can use the native Binance token (BNB) and other tokens based on the Binance chain. Other examples of DEX include Waves DEX, IDEX, and Kyber.
Why use decentralized exchange?
- Security: Due to the lack of a centralized entity, DEXs don’t have a single point of failure.
- Your money is yours: You don’t need to hand over your money to a third-party that you’ll need to trust. In a DEX, your funds are completely in your hands. If something untoward does happen to the DEX, you’ll still have full control over your funds.
- Privacy: Centralized exchanges require a ton of documentation from their users to perform mandatory KYC and AML checks. Since a DEX is never under any central control, it requires no registration requirements.
- Inclusivity: Government regulations force exchanges to exclude users from certain areas. For example, many exchanges simply can’t service users in the US due to heavy regulation. A decentralized exchange is not subject to such governmental regulations.
How does a decentralized exchange work?
The first step to understanding the workings of a DEX is to know how a smart contract works. Simply put, smart contracts are automated, self-executing agreements between two parties that connect them directly to each other. If party A wants to procure a service from party B, they’ll lock up the contract’s payment. If B completes its task, the contract releases the amount to their wallet. Otherwise, it gets reverted to A.
EtherDelta – How does a decentralized exchange work?
Let’s look into the functionalities of a decentralized exchange through the perspective of EtherDelta.
Fund control and order books
EtherDelta uses a combination of:
- On-chain smart contract-based ERC-20 token trades.
- Off-chain, centralized order book.
So, how exactly does an order work here? Let’s go through the steps:
- Suppose a user wants to exchange their coin for another, they submit a buy or sell request to the order book and become a “Maker.”
- The order includes the token they want to exchange and how much they want or offer in return.
- The Maker then signs the order with their private key to validate the order.
- This order is stored on the exchange’s servers and broadcasted to the network.
- Traders that are interested in the order are known as Takers.
- If they are satisfied with the order and the exchange rate, they sign off with their Ethereum private key and send the funds to the smart contract.
- The smart contract then automatically verifies all the data and if everything is in order, the transaction goes through.
Decentralizing orders with Relayers
After reading the former section, you are probably thinking – “wait… a centralized order book? Isn’t that a potential point of failure?”
And you know what?
You are absolutely right.
To mitigate this, protocols like 0x have introduced the concept of “relayers.” Relayers are agents who:
- Provide their own off-chain order book.
- Helps in matching makers and takers.
Let’s look at how the whole process works:
- The relayers show makers the different transaction fees available.
- Makers choose the relayers that they are interested in interacting with.
- The maker sends the order to the relayer, which contains their Ethereum address and bid.
- The takers also look through the different maker offers and shortlist the one they are interested in.
- If both parties are satisfied with what they are getting, they can directly interact with each other via smart contracts.
How does a decentralized exchange work? Atomic Swaps
Back in 2017, BTC-LTC and LTC-DCR broke new grounds by conducting atomic swaps. Those in the know will be pretty well-aware of this famous tweet:
The idea is simple. How does Alice, who has coin A, swap it with Bob who has coin B, without going through a centralized exchange. The first few swaps couldn’t see much adoption because of the high cost, latency, and complexity. However, since then, the development in this area has progressed pretty steadily. Currently, we have exchanges like Komodo and blockchain.io implementing their own versions of atomic swaps. However, at its core, atomic swap functionalities remain the same.
- Alice has some BTC and Bob has BCH. They want to swap coins with each other.
- The two of them then open up a payment channel. The instigator of this swap (let’s say Alice) then creates a contract address
- Alice, being the instigator, locks up BTC in the address and comes up with a confidential value as well.
- Alice hashes the secret value and hands it over to Bob.
- Bob sends his BCH to the address generated by the hash.
- Since Alice herself came up with the confidential number, she will easily generate the hash and retrieve the BCH.
- When Alice gets the BCH, Bob automatically gets access to his BTC.
What is a Decentralized Exchange – Pros and Cons
- You remain in full control of your funds. At no point will you be asked to relinquish your private keys.
- The lack of a centralized entity and a single point of failure minimizes the risk of infiltration and attacks.
- The sheer diversity of coins listed on a DEX is overwhelmingly large compared to a centralized exchange.
The biggest con of decentralized exchange all has to do with the order book. Should you keep it on-chain or off-chain. In an ideal world, the order book should be on-chain. Unfortunately, online order books can make the whole order matching process extremely slow, cumbersome, and expensive.
Unable to cope with an inefficient on-chain book, many DEXs have opted for off-chain order books. In this system, market makers broadcast an order off-chain to be picked up by a counterparty who then passes the full order to a smart contract for fulfillment. While it’s comparatively more efficient, it still suffers from the following issues:
- The users are limited as to the kind of orders that they can make. Complicated orders like a “stop-loss” can become a problem.
- Canceled orders have to be processed on-chain, making it more expensive than it needs to be.
- Since every order gets committed to the blockchain, every single order can be soon before it gets processed. This makes the trades susceptible to interception. Wherein someone else can hijack your deal by paying a higher gas price.
Decentralized Exchange Examples
Before we finish up this guide, let’s give you a quick overview of one of the most popular DEX in the market.
As per DeFi Pulse, Uniswap currently has over $100 million locked up in it.
Native Token: N/A
The feature that makes Uniswap distinct is that it doesn’t use an order book at all. Instead, it uses a liquidity pool that utilizes an algorithmic pricing mechanism. This system not only guarantees liquidity but provides low spreads as well. All fees (around 0.3% per trade) gets added to the corresponding liquidity pool. Liquidity providers will receive these fees in proportion to their share of the pool’s liquidity.
Here are some features about Uniswap that you need to keep in mind:
- With volatility swings, liquidity providers suffer a loss. However, they make up for these losses when the bulls regain control. If Uniswap enjoys healthy trading volume, the liquidity providers may collect enough fees to offset their losses.
- Any user can swap between ETH and any ERC 20 token.
- Anyone can create a liquidity pool by supplying equal parts ETH and ERC20 tokens. The DEX allows only one market per ERC20 token,
- Uniswap has a “constant product market maker” mechanism that determines the exchange rate.
- The asset price changes when the liquidity of one half of the trading pair goes down relative to the other. This allows users to conduct arbitrage trades if needed.
Native Token: BNB
Binance is one of the most well-known crypto exchanges in the world. The Malta-based exchange has become synonymous with the crypto space over the last few years. Founder and CEO Changpeng “CZ” Zhao has become a crypto celebrity in his own right. Some exciting features to note are as follows:
- The Binance DEX platform has a UI that’s similar to the main platform. It also has the TradingView charts widget wherein users can do technical analysis.
- Integrates with Trust Wallet and Ledger Nano S
- Utilizes period auction to match all available orders. Since the match happens simultaneously for all orders, it does away with the Maker-Taker concept.
- Enhances security by using a combination of Byzantine Fault Tolerance (BFT) and Proof of Stake (PoS) based consensus mechanism.
- Its association with Binance gives the users access to the highest level of customer support.
Native Token: BAL
Balancer Exchange allows you to swap ERC20 tokens trustlessly across all Balancer’s liquidity pools. Balancer is an Ethereum-based, n-dimensional market-maker that allows anyone to or add liquidity to various pools and earn trading fees.
As per DeFi Pulse, Balancer current has >$250 million locked up in it.
The different types of pools available within Balancer are as follows:
- Private: Only the owner can contribute liquidity and has full permissions over the parameters governing the pool.
- Shared: The pool creator has no special power over the pool. Anyone can add liquidity to the shared pool. A special token called “BPT – Balancer Pool Token” is used to track the pool’s liquidity.
- Smart: It’s a variation of the private pool. In this case, the controller is a smart contract and anyone can contribute to the liquidity within the pool. BPTs can be issued to keep track of ownership.
What is a Decentralized Exchange – Conclusion
So there you have it. Hopefully, this guide will give you a nice starting point to understand one of the most fascinating aspects of DeFi – the decentralized exchange. In the course of the article, we answered the following questions for you:
- What is a decentralized exchange?
- What are the flaws of centralized exchange?
- How does a decentralized exchange work?
We also discussed some of the most popular DEX options in the market that you can explore in your own free time.
Do you want to learn more about DeFi? If yes, then consider checking out our blockchain courses at Ivan on Tech Academy. We have some of the most comprehensive DeFi courses in the world, prepared by industry experts.