What is A Decentralized Exchange and How Does It Work?
A DEX allows users to trade cryptocurrencies directly with each other, without an intermediary. It uses a decentralized network, often based on blockchain technology, to operate in a trustless manner, thereby reducing the risk of fraud or other wrongdoings.
The crypto world has two types of exchanges: centralized and decentralized, allowing users to trade cryptocurrencies.
However, both exchanges work very differently. A centralized exchange (CEX) runs on an internal infrastructure and is controlled by a centralized entity. On the other hand, a decentralized exchange (DEX) is run by software that no one controls.
In this article, we will explain how a DEX works moderately without the involvement of a centralized party. But, first, let’s understand what a DEX is.
What is a Decentralized exchange(dex)?
Short for decentralized exchange, a DEX is a marketplace that allows users to trade cryptocurrencies directly with each other. Such a marketplace works as per a smart contract, which essentially is software code that defines how a trade will happen fairly. This smart contract is deployed on a public chain for everyone to check and verify the authenticity of the underlying code of the DEX.
One key feature of a DEX is that it allows users to trade assets directly with each other, using their own wallets and without the need to deposit their assets on the exchange. This can make the process faster and more secure, as users retain control of their assets at all times.
Another important aspect of a Decentralized exchange is that it can operate in a trustless manner, meaning that users do not need to trust a central authority or intermediaries to facilitate their trades. This can help to reduce the risk of fraud or other types of wrongdoing, as there is no central point of failure that can be exploited.
Since DEXs do not necessitate KYC compliance for users, they don’t support fiat on-ramp functions. They are solely for trading one crypto with another.
How does a Decentralized exchange(dex) work?
It is understood that no central entity controls a DEX and that it runs as per its smart contract. But, how does such a marketplace work? Let’s understand the working of a DEX through the example of one of the most popular decentralized exchanges, Uniswap.
Uniswap – how it works?
Traditional, centralized exchanges work as per an order book, which essentially is a list of orders from different buyers and sellers for a certain asset. The list shows the prices and volumes that buyers are willing to buy and the sellers are willing to sell.
Unlike CEXs, Uniswap does not use an order book for trades. Instead, it uses a variant of Automated Market Market (AMM) called Constant Product Market Maker.
what is an Automated market maker(amm)?
An automated market maker (AMM) is a type of system that is designed to facilitate the trading of assets, typically on a decentralized exchange (DEX). It uses algorithms to set the prices of the assets being traded and to automatically match buyers and sellers.
One key aspect of an AMM is that it allows users to buy and sell assets without the need for a traditional order book. Instead, the AMM uses a mathematical formula to determine the price of an asset based on the supply and demand for that asset. This formula can be adjusted to ensure that the AMM remains solvent and able to fulfill trades.
Another important feature of an AMM is that it can be programmed to offer liquidity to the market by automatically creating and filling orders for buy and sell trades. This helps to ensure that there is always someone available to trade with and that the market remains active and liquid.
To simplify it: It is like a robot that helps people buy and sell cryptocurrencies by using special math to set the prices of the crypto assets people want to buy or sell. When someone wants to buy a cryptocurrency, the robot helps them find someone who has it and is willing to sell it. And when someone wants to sell an asset, the robot helps them find someone who wants to buy it.
The robot also helps ensure that someone is always available to buy or sell crypto, so people can always find someone to trade. It helps make the market for buying and selling crypto more active and easy to use.
Overall, the goal of an AMM is to provide a simple, efficient, and decentralized platform for buying and selling assets. It allows users to trade without the need for a central authority or intermediaries, which can make the process faster, cheaper, and more secure.
How does Uniswap use AMM for matching trades?
The AMM that Uniswap uses is based on a mathematical formula called a “constant product formula.” The formula works by setting the price of an asset concerning the supply and demand for that asset. When the supply of an asset is high and the demand is low, the price will be low. When the supply is low and the demand is high, the price will be high.
The constant product formula is expressed as follows:
price = constant / (supply * demand)
In this formula, “constant” is a fixed value set by the AMM. It represents the overall value of the pool of assets traded on Uniswap. “Supply” is the amount of the asset currently available for sale on Uniswap, and “demand” is the amount of the asset that buyers are willing to purchase.
The constant product formula is designed to ensure that the AMM remains solvent and able to fulfill trades. If the AMM runs out of assets to sell, it can issue new tokens to buyers, which helps to maintain the constant value of the pool.
Overall, the constant product formula is a key part of the AMM that powers Uniswap, and it helps to ensure that the platform can provide a simple, efficient, and decentralized way for users to buy and sell assets.
How Uniswap works IN REAL WORLD?
Imagine that you have 100 units of a cryptocurrency called “MyCoinX” that you want to sell on Uniswap. You connect your Ethereum wallet to Uniswap and deposit the MyCoinXs into the platform.
At the same time, there are two other users on Uniswap who want to buy MyCoinXs. One user is willing to pay $10 for each MyCoinX, and the other is willing to pay $20.
The AMM on Uniswap uses the constant product formula to determine the price of the MyCoinXs based on the supply (100 MyCoinXs) and the demand (the two users who want to buy them). The constant product formula is expressed as follows:
price = constant / (supply * demand)
In this case, the constant value is set at $2,000, which represents the overall value of the pool of assets being traded on Uniswap. Using this formula, the AMM calculates the price of the MyCoinXs as follows.
price = $2,000 / (100 MyCoinXs * 2 buyers) price = $10 per MyCoinX
This means that the users who want to buy MyCoinXs will pay $10 each for them. The AMM will then automatically execute the trades and transfer the MyCoinXs to the buyers.
This is a very simplified example, but it illustrates how the constant product formula can be used to determine the price of an asset based on the supply and demand for that asset. In the real world, there are often many more factors at play, and the constant product formula is just one part of the complex algorithms that power the AMM on Uniswap.
DEXs Using On-Chain Order Books
In addition to the AMM model, DEXs use frameworks like an on-chain order book for decentralized trading.
On a DEX that uses an on-chain order book, the order book is stored on the blockchain, along with all the other information related to the exchange. This can make the order book more transparent and immutable, as it is stored on a decentralized network of computers that are managed by multiple parties.
One advantage of an on-chain order book is that it can allow for faster and more efficient matching of buy and sell orders. Because the order book is stored on the blockchain, it can be accessed and updated by multiple parties simultaneously, which can reduce delays in the trading process.
Another advantage is that an on-chain order book can provide more transparency and security, as it is stored on a decentralized and immutable platform. As it is more difficult to manipulate or alter the order book. It significantly minimizes the chance of fraud.
Final Words
With the rise of the self-custody narrative caused by recent events like FTX and Celsius, DEXs are observing an uptick in usage. It is mostly because they are designed to be decentralized, allowing users to trade assets directly with each other without the need for a central authority or intermediaries.
If the momentum continues and as the world becomes more aware of “Not Your Keys, Not Your Coins”, we are likely to see a massive shift from centralized exchanges to decentralized exchanges in the coming time.
Integrating Base Blockchain with RocketX: Your Guide to Swap, Convert, and Bridge ETH to Base
With RocketX Exchange's new integration of the Base Blockchain, users can now make cryptocurrency transactions more efficiently and...
Buy PNUT Coin Seamlessly on RocketX: A Tribute to Peanut the Squirrel’s Legacy
Introduction Cryptocurrencies have often seen innovative and quirky ideas come to life, and the Peanut the Squirrel (PNUT) coin is no exception. Combining a heartfelt story with the viral nature of...