Module 8: The Basics of Decentralized Exchanges
Module 8 is an essential introduction to decentralized exchanges (DEXs). We will go through what a DEX is, Automated Market Makers, how to use a DEX, the advantages, and more.
In the last module, we learned how to earn a passive income through yield farming. In this module we will be focusing on the basics of decentralized exchanges.
DEXs, or decentralized exchanges, are peer-to-peer markets where cryptocurrency traders interact directly without routing their assets through an intermediary or custodian. Liquidity is provided by liquidity providers in a DEX pool. These liquidity providers lock their cryptocurrencies into the corresponding liquidity pools. For each trade executed on the platform, DEXs typically charge a percentage transaction fee.
DEXs were established to do away with the necessity for a central authority to oversee and authorize trade on a particular exchange. They are usually non-custodial, which means that users keep ownership of their private keys. This is advantageous as it allows users to instantly access their funds once they log into the DEX with their private keys. In addition, users are not required to disclose any personally identifiable information, such as names and addresses, which is a significant benefit for those who prioritize privacy when managing their crypto.
Automated market makers and other innovations that solved liquidity issues initially attracted users to the DeFi space. If you are interested in crypto or blockchain technology you have probably heard of an AMM before. An AMM is the underlying technology that supports all decentralized exchanges. Simply put, they are self-contained trading mechanisms that remove the need for centralized exchanges and market-making procedures.
For example, by optimizing token prices, swap fees, and slippage while providing a better rate for users, DEX Aggregators and wallet extensions fostered the expansion of decentralized platforms.
What are DEXs?
Smart contracts enable traders to execute orders without the need for an intermediary on decentralized exchanges. On the other hand, centralized exchanges are run by a central institution, such as a bank, which is otherwise engaged in financial services and is seeking to earn a profit.
Because centralized exchanges are regulated businesses that retain users' assets and provide easy-to-use platforms for beginners, centralized exchanges account for most trading volume in the cryptocurrency market. Some centralized exchanges also offer insurance for the funds that are deposited.
A centralized exchange's services can be comparable to those provided by a bank. The bank safeguards its customers' cash and provides security and monitoring services that people cannot deliver on their own, making money transfers easier. However, CEXs are more vulnerable to malicious networks attacks compared to DEXs.
On the other hand, decentralized exchanges allow users to trade directly from their wallets by engaging with the trading platform's smart contracts. Traders are accountable for losing their funds if they make mistakes, such as misplacing their private keys or sending funds to incorrect addresses.
Customers' deposited funds or assets are branded with an "I owe you" (IOU) that can be freely sold on the network via decentralized exchange portals. A blockchain-based IOU is essentially a token with the same value as the underlying asset. Leading blockchains that support smart contracts have been used to build popular decentralized exchanges. They are constructed on top of the blockchain and are based on layer-one protocols.
How Do DEXs Work?
Because decentralized exchanges are built on blockchain networks that support smart contracts and where users hold their funds, each trade is charged a transaction fee in addition to the trading fee. In simple terms, traders interact with smart contracts on the blockchain to use DEXs.
Automated market makers, order book DEXs, and DEX aggregators are the three primary forms of decentralized exchanges. They all operate on smart contracts that allow users to trade directly with one another. The initial decentralized exchanges employed order books that were comparable to those used by centralized exchanges.
Automated Market Makers (AMMs)
An automated market maker (AMM) system based on smart contracts was built to tackle the liquidity problem. The establishment of these exchanges was influenced in part by Ethereum co-founder Vitalik Buterin's paper on decentralized exchanges, which explains how to perform trades on the blockchain using token-based contracts.
These AMMs rely on blockchain-based services, also known as blockchain oracles, that offer information from exchanges and other platforms to set the price of traded assets. Instead of matching buy and sell orders, these decentralized exchanges' smart contracts use liquidity pools, which are pre-funded pools of assets.
Other users fund the pools, and they are then entitled to the protocol's transaction fees for completing transactions with that pair. To earn income on their cryptocurrency holdings, these liquidity providers must deposit an equivalent value of each asset in the trading pair, a process known as liquidity mining. If they try to deposit more of one asset than the other, the pool's smart contract will reject the transaction.
Liquidity pools enable traders to execute orders or earn interest without requiring permission and in a secure manner. The amount of money locked into these exchanges' smart contracts, known as total value locked, is frequently used to rate them (TVL). When there is insufficient liquidity, the AMM model has a drawback: slippage.
Slippage happens when a buyer pays above market price for their transaction because of a lack of liquidity on the platform, with larger orders resulting in higher slippage. Conversely, large orders with little liquidity are likely to slip; hence a lack of liquidity can deter wealthy traders from using these platforms.
Liquidity providers are also exposed to a variety of risks, including volatility loss, which is a direct result of depositing two assets for a single trading pair. Trading on the exchange may diminish the amount of one of these assets in the liquidity pool if one is more volatile than the other. The liquidity providers suffer a non-permanent loss if the price of the highly volatile asset rises while the amount held by the liquidity providers declines. Because the asset's price can still climb and trading on the exchange can counteract the pair ratio, the loss is not permanent. The pair ratio denotes the percentage of each asset in the liquidity pool. Additionally, trading costs can be used to recuperate the loss over time.
Order Books DEXs
All open orders to buy and sell assets for specific asset pairs are recorded in order books. Buy orders show a trader's interest in purchasing an asset at a particular price, whereas sell orders indicate a trader's willingness to sell or ask for that item at a specific cost. The depth of the order book and the market price on the exchange is determined by the spread between these values.
On-chain order books and off-chain order books are the two forms of order book DEXs. Open order information is frequently kept on the chain by DEXs that use order books, and the users' funds remain in their wallets. Traders on these exchanges may be able to leverage their positions by borrowing money from lenders on the site. Leveraged trading raises the profit potential of a trade, but it also increases the danger of liquidation.
On the other hand, DEX platforms keep their order books off the blockchain and settle their deals exclusively to give traders the benefits of centralized exchanges. Off-chain order books help exchanges save money and time by ensuring that trades are performed at the prices users request.
These exchanges allow users to lend their funds to other traders to provide leveraged trading opportunities. The borrowed money earns interest over time and is secured by the exchange's liquidation mechanism, ensuring that the lenders are compensated even if the traders lose their bets.
It's worth noting that order book DEXs frequently have liquidity issues. Traders prefer centralized platforms because they compete with centralized exchanges and incur additional fees for transactions further up the chain. While DEXs with off-chain order books decrease these expenses, the requirement to deposit funds in smart contracts introduces other risks.
DEX Aggregators utilize a variety of protocols and strategies to address liquidity issues. These platforms essentially pool liquidity from various DEXs to reduce slippage on large orders, optimize swap costs and token prices, and provide traders with the best price in the quickest time.
DEX aggregators also have the purpose of protecting users from the pricing effect and minimizing the possibility of failed transactions. In addition, through interaction with select centralized exchanges, certain DEX aggregators utilize liquidity from centralized platforms to give consumers a better experience while staying non-buyable.
How to Use Decentralized Exchanges
There is no sign-up process to use a decentralized exchange. Traders instead require a wallet that is compatible with the exchange network's smart contracts. DEXs' financial services are accessible to everyone with a smartphone and an internet connection.
Users must first pick which network they wish to utilize before using DEXs, as each trade has a transaction charge. The next step is to choose a wallet compatible with the selected network and fill it with the native token of that network. A native token is a cryptocurrency that is used to pay transaction fees on a specific network.
Wallet extensions make it easier to connect with decentralized applications (DApps) like DEXs by allowing users to access their cash directly from their browser. They are installed similarly to other extensions, and the user must either import an existing wallet using a seed phrase or private key or create a new wallet. In addition, password protection improves security even more.
Because they have built-in browsers ready to interface with smart contract networks, these wallets can also have mobile apps, allowing traders to use DeFi protocols on the go. In addition, wallets can be synced between devices simply importing from one to the other.
Once you have selected a wallet, you will need to fill it with the tokens. This is used to pay the network's transaction fees. These tokens must be purchased on exchanges and recognized by their ticker symbol, such as ADA or ETH. After purchasing the tokens, users need to withdraw them into the wallets they control. Users who have a funded wallet can link their wallet via a pop-up prompt or by clicking the "Connect Wallet" button in one of DEX's upper corners.
Advantages of Using a DEX
Trading on decentralized exchanges can be costly, mainly if network transaction fees are high at the time of trade execution. However, there are numerous advantages to using DEXs:
DEX does not keep track of user funds or data. It is nearly impossible to hack the exchange because there is no single area where all funds can be accessed. The trader is the exclusive owner of all funds.
Users do not need to be authenticated to maintain their anonymity. The chance of third parties having access to your assets is reduced because you do not disclose your information to anyone.
DEX does not have a phone number that can be used to lock your account, share data with third parties, or prevent price manipulation.
Due to the use of distributed ledger technology, each node in the blockchain functions independently of the others, and regulators cannot shut down DEX.
A user-friendly interface is accessible, making it simple to comprehend the exchange's data.
Disadvantages of Using a DEX
There are no options such as margin trading or order mode selection.
Unlike centralized exchanges operated by private companies, DEXs have essentially no way to recover lost, stolen or misplaced money. Due to a lack of a KYC process or the inability to cancel a transaction in the event of a compromised account or loss of the private key, users cannot recover their data or retrieve their assets.
There is no exchange for fiat currency. This is a big drawback for many users, as not many goods and services can be purchased with cryptocurrency, so users have to exchange cryptocurrency for fiat currency.
How to Create a Decentralized Exchange
The 0x protocol is one of the most widely used and accessible frameworks for establishing a decentralized exchange. To access the protocol, you will first need to download node.js, Yarn, Docker, and npx.
Once you have downloaded the above, you will need to do the following:
Connect to a test network like Kovan or Mainnet using the 0x creation wizard.
Create an RPC URL with Infura.io and set the charge receiver and server port.
After you've finished creating the front-end, go to your browser and select a port to see your deployed launch kit.
Although centralized exchanges (CEXs) currently dominate cryptocurrency trading, decentralized exchanges (DEXs) are becoming increasingly popular. DEXs facilitate peer-to-peer trading by relying on automated smart contracts to execute trades without an intermediary. However, not all DEXs use the same underlying infrastructure. While some retain the traditional order book model, others use emergent liquidity protocols. In addition to exchange and liquidity protocols, developers are developing new aggregation tools to address the disjointed liquidity inherent in decentralized exchanges.
Join us in the next module to learn more about decentralized lending and borrowing.