What are decentralized exchanges, and how do DEXs work?

 

Decentralized exchanges, also known as DEXs, are peer-to-peer marketplaces where cryptocurrency traders make transactions directly without handing over management of their funds to an intermediary or custodian. These transactions are facilitated through the use of self-executing agreements written in code called smart contracts.

DEXs were created to remove the requirement for any authority to oversee and authorize trades performed within a specific exchange. Decentralized exchanges allow for peer-to-peer (P2P) trading of cryptocurrencies. Peer-to-peer refers to a marketplace that links buyers and sellers of cryptocurrencies. They are usually non-custodial, which means users keep control of their wallet's private keys. A private key is a type of advanced encryption that enables users to access their cryptocurrencies. Users can immediately access their crypto balances after logging into the DEX with their private key. They will not be required to submit any personal information like names and addresses, which is great for individuals who cherish their privacy.

Innovations that solved liquidity-related problems such as automated market makers helped attract users to the decentralized finance (DeFi) space and largely contributed to its growth. DEX aggregators and wallet extensions fueled the growth of decentralized platforms by optimizing token prices, swap fees and slippage, all while offering a better rate for users.

What are decentralized exchanges?

Decentralized exchanges rely on smart contracts to allow traders to execute orders without an intermediary. On the other hand, centralized exchanges are managed by a centralized organization such as a bank that is otherwise involved in financial services looking to make a profit.

Centralized exchanges account for the vast majority of the trading volume in the cryptocurrency market because they are regulated entities that custody users’ funds and offer easy-to-use platforms for newcomers. Some centralized exchanges even provide insurance on deposited assets.

The services offered by a centralized exchange can be compared to those offered by a bank. The bank keeps its clients’ funds safe and provides security and surveillance services that individuals cannot deliver independently, making it easier to move funds around.

In contrast, decentralized exchanges allow users to trade directly from their wallets by interacting with the smart contracts behind the trading platform. Traders guard their funds and are responsible for losing them if they make mistakes such as losing their private keys or sending funds to the wrong addresses.

The customers' deposited funds or assets are issued an “I owe you” (IOU) via decentralized exchange portals, which can be freely traded on the network. An IOU is essentially a blockchain-based token that has the same value as the underlying asset. 

Popular decentralized exchanges have been built on top of leading blockchains that support smart contracts. They are built on top of layer-one protocols, meaning that they are built directly on the blockchain. The most popular DEXs are built on the Ethereum blockchain.

How do DEXs work?

As decentralized exchanges are built on top of blockchain networks that support smart contracts and where users keep custody of their funds, every trade incurs a transaction fee along with the trading fee. In essence, traders interact with smart contracts on the blockchain to use DEXs.

There are three main types of decentralized exchanges: Automated market makers, Order books DEXs and DEX aggregators. All of them allow users to trade directly with each other through their smart contracts. The first decentralized exchanges used the same type of order books, similar to centralized exchanges.

Automated market makers (AMMs)

An automated market maker (AMM) system that relies on smart contracts was created to solve the liquidity problem. The creation of these exchanges partly came from inspiration originating from Ethereum co-founder Vitalik Buterin’s paper on decentralized exchanges, describing how to execute trades on the blockchain using contracts holding tokens.

These AMMs rely on blockchain-based services that provide information from exchanges and other platforms to set the price of traded assets called blockchain oracles. Instead of matching buy orders and sell orders, the smart contracts of these decentralized exchanges use pre-funded pools of assets known as liquidity pools. 

The pools are funded by other users who are then entitled to the transaction fees that the protocol charges for executing trades on that pair. These liquidity providers need to deposit an equivalent value of each asset in the trading pair to earn interest on their cryptocurrency holdings, a process known as liquidity mining. If they attempt to deposit more of one asset than the other, the smart contract behind the pool invalidates the transaction.

The use of liquidity pools allows traders to execute orders or to earn interest in a permissionless and trustless way. These exchanges are often ranked according to the amount of funds locked in their smart contracts called total value locked (TVL), as the AMM model has a downside when there is not enough liquidity: slippage.

Slippage occurs when a lack of liquidity on the platform results in the buyer paying above-market prices on their order, with larger orders facing higher slippage. A lack of liquidity can deter wealthy traders from using these platforms, as large orders are likely to suffer from slippage without deep liquidity.

Liquidity providers also face various risks including impermanent loss, which is a direct result of depositing two assets for a specific trading pair. When one of these assets is more volatile than the other, trades on the exchange can lower the amount of one asset in the liquidity pool.

If the highly volatile asset's price rises while the amount liquidity providers hold drops, liquidity providers suffer an impermanent loss. The loss is impermanent because the price of the asset can still move back up and trades on the exchange can balance the pair’s ratio. The pair’s ratio describes the proportion of each asset held in the liquidity pool. Furthermore, fees collected from trading can make up for the loss over time.

Order book DEXs

Order books compile records of all open orders to buy and sell assets for specific asset pairs. Buy orders signify that a trader is willing to buy or bid for an asset at a specific price, while sell orders indicate that a trader is ready to sell or ask a particular price for the asset under consideration. The spread between these prices determines the depth of the order book and the market price on the exchange.

Order book DEXs have two types: on-chain order books and off-chain order books. DEXs using order books often hold open order information on-chain, while users’ funds remain in their wallets. These exchanges may allow traders to leverage their positions using funds borrowed from lenders on their platform. Leveraged trading increases the earning potential of a trade, but it also increases the risk of liquidation as it enhances the size of the position with borrowed funds, which have to be repaid even if the traders lose their bet. 

However, the DEX platforms that hold their order books off the blockchain only settle trades on the blockchain to bring the benefits of centralized exchanges to traders. Using off-chain order books helps exchanges reduce costs and increase speed to guarantee that trades are executed at the prices desired by the users.

To offer leveraged trading options, these exchanges also allow users to lend their funds to other traders. Loaned funds earn interest over time and are secured by the exchange’s liquidation mechanism, ensuring lenders get paid even if traders lose their bets.

It is important to point out that order book DEXs often suffer from liquidity issues. Since they are essentially competing with centralized exchanges and incur extra fees because of what’s paid to transact on-chain, traders usually stick to centralized platforms. While DEXs with off-chain order books reduce these costs, smart contract-related risks arise because of the need to deposit funds in them.

DEX aggregators

DEX aggregators use several different protocols and mechanisms to solve problems associated with liquidity. These platforms essentially aggregate liquidity from several DEXs to minimize slippage on large orders, optimize swap fees and token prices and offer traders the best price possible in the shortest possible time.

Protecting users from the pricing effect and decreasing the likelihood of failed transactions are two other significant goals of DEX aggregators. Some DEX aggregators also use liquidity from centralized platforms to provide users with a better experience, all while remaining non-custodial by leveraging an integration with specific centralized exchanges.

How to use decentralized exchanges

Using a decentralized exchange does not involve a sign-up process, as you do not even need an email address to interact with these platforms. Instead, traders will need a wallet compatible with the smart contracts on the exchange’s network. Anyone with a smartphone and an internet connection can benefit from the financial services offered by DEXs.

To use DEXs, the first step is to decide which network a user wants to use, as each trade will incur a transaction fee. The next one is to choose a wallet compatible with the selected network and fund it with its native token. A native token is the token used to pay for transaction fees in a specific network.

Wallet extensions that allow users to access their funds directly in their browsers make it easy to interact with decentralized applications (DApps) such as DEXs. These are installed like any other extension and require users to either import an existing wallet through a seed phrase, or private key or create a new one. The security is further enforced through password protection.

These wallets may also have mobile applications so traders can use DeFi protocols on the go, as they come with built-in browsers ready to interact with smart contract networks. Users can synchronize wallets between devices by importing from one to the other. 

After picking a wallet, it will need to be funded with the tokens used to pay for transaction fees on the chosen network. These tokens have to be bought on centralized exchanges and are easily identifiable through the ticker symbol they use like ETH for Ethereum. After buying the tokens, users simply have to withdraw them to wallets they control. 

It is crucial to avoid moving funds to the wrong network. Therefore, users must withdraw their funds to the correct one. With a funded wallet, users can either connect their wallet through a pop-up prompt or click the “Connect Wallet” button on one of the upper corners on the website of DEXs.

Advantages of using a DEX

Trading on decentralized exchanges can be expensive, especially if network transaction fees are high when the trades are executed. Nevertheless, there are numerous advantages of using DEX platforms.

Token availability

Centralized exchanges have to individually vet tokens and ensure they comply with local regulations before listing them. Decentralized exchanges can include any token minted on the blockchain they are built upon, meaning that new projects will likely list on these exchanges before being available on their centralized counterparts.

While this can mean traders can get in as early as possible on projects, it also implies that all sorts of scams are listed on DEXs. A common scam is known as a “rug pull,” a typical exit scam. Rug pulls occur when the team behind a project dumps the tokens used to provide liquidity on these exchanges’ pools when their price goes up, making it impossible for other trades to sell.

Anonymity 

When users exchange one cryptocurrency for another, their anonymity is preserved on DEXs. In contrast to centralized exchanges, users do not need to go through a standard identification process known as Know Your Customer (KYC). KYC processes involve collecting traders’ personal information, including their full legal name and a photograph of their government-issued identification document. As a result, DEXs attract a large number of people who do not wish to be identified.

Reduced security risks

Experienced cryptocurrency users who custody their funds are at a reduced risk of being hacked using DEXs, as these exchanges do not control their funds. Instead, traders guard their funds and only interact with the exchange when they wish to do so. If the platform gets hacked, only liquidity providers may be at risk.

Reduced counterparty risk

Counterparty risk happens when the other party involved in a transaction does not fulfill its part of the deal and defaults on its contractual obligations. Because decentralized exchanges operate without intermediaries and are based on smart contracts, this risk is eliminated.

To ensure no other risks arise when using a DEX, users can quickly do a web search to find out whether the exchange’s smart contracts have been audited and can make decisions based on other traders’ experience.

Disadvantages of using DEXs

Despite the above advantages, there are various drawbacks of decentralized exchanges including a lack of technical knowledge needed to interact with these exchanges, the amount of smart contract vulnerabilities and unvetted token listings.

Specific knowledge is required

DEXs are accessible using cryptocurrency wallets that can interact with smart contracts. Not only do users have to know how to use these wallets, they also have to understand security-related concepts associated with keeping their funds secure.

These wallets have to be funded with the correct tokens for each network. Without a network’s native token, other funds may get stuck, as the trader cannot pay the fee required to move them. Specific knowledge is required to both choose a wallet and fund it with the correct tokens. 

Moreover, avoiding slippage can be challenging even for experienced investors, or even near impossible when purchasing tokens with less liquidity. Often, slippage tolerance on DEX platforms has to be manually adjusted for orders. Additionally, adjusting slippage can be technical, and some users may not fully understand what it means.

Without specific knowledge, traders can commit various errors which may lead to a loss of funds. Withdrawing coins to the wrong network, overpaying transaction fees and losing out to impermanent loss are just a few examples of what could go wrong.

Smart contract vulnerabilities

Smart contracts on blockchains like Ethereum are publicly available and anyone can review their code. Moreover, smart contracts of large decentralized exchanges are audited by reputable firms that help secure the code.

To err is human. Therefore, exploitable bugs can still slip past audits and other code reviews. Auditors may even be unable to foresee potential new exploits that can cost liquidity providers their tokens.

Unvetted token listings

Anyone can list a new token on a decentralized exchange and provide liquidity by pairing it with other coins. This can leave investors susceptible to scams such as rug pulls that make them believe that they are buying a different token.

Some DEXs counter these risks by asking users to verify the smart contract of the tokens they are looking to buy. While this solution works for experienced users, it circles back to specific knowledge problems for others. 

Before buying, traders can try to get as much information as possible about a token by reading its white paper, joining its community on social media and looking for potential audits on the project. This type of due diligence helps avoid common scams where malicious actors take advantage of unsuspecting users.

Decentralized exchanges keep evolving 

The first decentralized exchanges appeared in 2014, but these platforms only became popular as decentralized financial services built on blockchain gained traction and AMM technology helped solve the liquidity problems previously faced by DEXs.

It is hard for these platforms to enforce Know Your Customer and Anti-Money Laundering checks, as there is no central entity verifying the type of information traditionally submitted to centralized platforms. Regulators may nevertheless attempt to implement these checks on decentralized platforms.

Regulations applied to custodians would also not apply to these platforms, as those that do accept users’ deposits still require users to sign messages on the blockchain to move funds off of their platforms.

Decentralized exchanges nowadays let users borrow funds to leverage their positions, lend funds to passively earn interest, or provide liquidity to collect trading fees.

As these platforms are built on self-executing smart contracts, more use cases may be created in the future. Flash loans, which refer to loans taken and repaid in a single transaction, are an example of how innovation in the decentralized finance space can create products and services that were not possible before.