Decentralized Exchanges, the Cornerstone of DeFi?

Decentralized exchanges have the potential to change the dynamics of the crypto asset industry, bringing in the next wave of liquidity and fundamentally altering the power dynamics between projects and the markets that drive them.

Gbirioluwaseun
DIA Community Hub
13 min readAug 25, 2022

--

“Gradually, decentralized trust will be accepted as a new and effective trust model. We have seen this evolution of understanding before — on the Internet”- Roy San Filippo, A New World In Our Hearts

A free society is characterized by the decentralization of power, and thus, Decentralized Finance (DeFi) signifies the forefront of “true financial freedom.” However, the major driving force behind DeFi continues to be the Decentralized Exchanges (DEXs).

As the name implies, a DEX is a peer-to-peer marketplace where blockchain transactions are made without the handing over of fund management to intermediaries.

Such a marketplace allows people to trade cryptocurrencies directly with other people without a middleman (Centralised Exchanges) to facilitate the trade, which makes the transaction quicker and much more efficient.

Typically, when you want to trade your cryptocurrency, you create an account on a Centralized Exchange (CEX) like Binance, Coinbase or Kraken. Binance will then act as a third party and sell or buy the token you want from or to you in return for an “agent fee.”

But on a DEX, that “third party” is a smart contract.

Simply put, a DEX is a peer-to-peer marketplace that links cryptocurrency traders (buyers and sellers) without the aid of a third-party organization but via smart contracts that self-execute under set conditions and record each transaction on the blockchain.

Note: Smart contracts are softwares that digitally facilitate or enforce rules-based agreements or terms between transacting parties.

What are the types of DEXs that exist today?

types of decentralized exchanges visual
source: Cointelegraph

There are different types of DEXs, each with distinct functions and features.

1. Automated Market Maker (AMMs):

To understand AMMs, you need to know who Market Makers are.

Market makers are individuals or firms that provide the market with liquidity and depth. In other words, a market maker facilitates the process required for trading pairs (buyer and seller) on CEXs.

Imagine you decide to buy 1 $ETH (Ethereum) for $2000. The exchange then ensures that a trader is found who is willing to sell $ETH to you at this rate. In fact, the exchange acts as a middleman for your trade to be as hitch-free as possible.

And what if the CEX can’t find any trader that wants to sell $ETH?

This means the liquidity of $ETH is low, which will most likely cause slippage (making the price slip). Market makers are responsible for preventing slippage, and CEXs rely on financial institutions and professional traders to supply liquidity by creating multiple buy/sell orders to match the orders of smaller traders.

Therefore, when you trade $ETH, the entity that provides liquidity is called a Market Maker.

What are Automated Market Makers (AMMs)?

An Automated Market Maker is a system that DEXs use to solve the liquidity problem.

The AMM relies on smart contracts that provide information from exchanges and other trading platforms to establish the prices of the assets being traded.

You can think of AMMs as programs that automate the process of providing liquidity. You don’t need another trader to issue trades once you utilize its protocols, instead, a smart contract handles that for you.

Let’s take an example to illustrate this point.

Imagine you want to sell 1 $ETH without the involvement of a CEX that would help you identify a buyer within your price range. Through AMMs, you can simply search for the liquidity pool for the asset you want to sell.

The price of the token (ETH in this case) will be determined by the smart contract in various ways, taking into account the price history, current price, volume, etc.

So, rather than relying upon multiple buy/sell orders, liquidity pools are used, and anybody can provide liquidity as long as the requirements of the smart contract are fulfilled.

How Automatic Market Makers Work

If you want to trade $ETH in exchange for $USDT, the trading pair will be $ETH/$USDT, and you will have to search for an $ETH/$USDT liquidity pool. However, you don’t need another trader to make this trade, the smart contract does that for you.

AMMs use preset mathematical equations to eliminate discrepancies and make sure the ratio of assets in liquidity pools remains as balanced as possible.

The X*Y=K equation is what sets the relationship between the particular assets held in the liquidity pools.

The X*Y=K in action

In the equation, “X” represents the value of asset A, “Y” denotes the value of asset B, and K is the constant.

Therefore, liquidity pools always maintain a state whereby the multiplication of the value of asset A and asset B equals the same number, ensuring the pools are as balanced as possible.

Taking another example, when you buy 200 $ETH/$USDT, you are removing 200 $ETH and adding 200 $USDT to it. This action causes $ETH in the pool to fall, which will allow the price of $ETH in the liquidity pool to increase as more $USDT will be added. Hence, the greater the amount of the asset, the lower the price, and the lower the asset availability, the higher the price to balance the liquidity pool.

Note: this formula is not used by everyone, but most DEXs like Uniswap use it, while Balancer uses a much more complex formula.

You might be wondering: if I want to buy $10,000 worth of $ETH and the liquidity pool has only $11,000 worth of $ETH, won’t there be a noticeable change in the price of the asset in the liquidity pool?

Well, you might find an $ETH/$USDT pool that sells $ETH for $2800 when the price of $ETH in the market is $3,000. As explained above, this happens when someone injects a lot of $ETH into the pool to remove another token, indicating that the price of ETH will trade lower in the pool, providing more opportunities for arbitrage traders to buy and sell.

Slippage in AMMs

Note: Arbitrage traders are financially incentivized to find assets that trade at discounts in liquidity pools and buy them up until the asset’s price returns in line with its market price.

Examples of AMM DEXs include:

2. Order Book DEXs

An Order Book DEX interface

As the name suggests, an order book is just a book of orders. You have a list of prices for what you want to sell and what you want to buy.

It is a “book” that documents an asset’s buy and sell activity on a DEX, and shows an arranged view of a particular asset’s buy and sell orders.

An order book DEX is a type of DEX that makes use of the order book to record the buy and sell orders for assets (cryptocurrency) and employs smart contracts to sift and fulfil the buy and sell orders automatically.

An order book holds different information regarding an asset, such as the bid and asks sections, as well as visual methods like graphs, charts, and others, which are displayed to show the interaction of the market history of the asset to help traders make informed decisions.

Every time you buy ETH for, let’s say $1000, you place a buy order (bid).

The order book will bring you selling orders (asks) that are within your price range, and your bid will be matched with an ask when you use the order book DEXs to place your bid.

Types of Order book DEXs

  • On-chain order books:

Onchain order books are order books that hold all their transactions on the blockchain.

As every order is written on the blockchain, all transactions made are recorded, even alterations and cancellations.

Thus, a major advantage of an on-chain transaction is its transparency, as everything is recorded. Yet, one disadvantage is that it is more expensive than off-chain order books because every transaction is recorded on a blockchain. More fees are generated as a result, unlike its counterpart, whose transactions happen both on and off-chain.

Examples: Serum

  • Off-chain order books:

An off-chain order book DEX combines order books built off-chain (off a blockchain) with an on-chain settlement. This type of DEX uses a peer-to-peer order book to execute trades.

For instance, when someone sees your ask order on the order book, they will submit a bid to the DEX. Then, the smart contract will check if the funds are available for the trade.

The trade will be successful if there are funds available.

Unlike its counterpart, the off-chain order book does some trading activity to reduce costs and increase speeds. The trading activity happens elsewhere, with trade settlement occurring on-chain.

Examples of Off-chain order books are dYdX, IDEX, 0x

Order book DEXs represent a growing market and have seen adoption in recent years, but its numerous advantages are coupled with some downsides.

They often suffer in illiquid markets and encourage manipulation to some extent, especially in an on-chain order book DEX, where everything is recorded and open.

3. DEX Aggregators

A DEX aggregator is among the latest and most exciting innovations in DeFi’s growing market. DEX aggregators are also referred to as the “search engines” of DeFi trading.

As mentioned previously, other DEX types (e.g. AMMs and Order Book DEXs) usually encounter liquidity problems.

DEX aggregators were created to specifically solve this issue.

Dex aggregators are decentralized financial protocols that enable cryptocurrency traders to access a range of trading pools. They serve as a unified explorer of prices and liquidity offered by DEXs.

You input your trading pair ETH/USDT into the DEX aggregator (also known as a liquidity aggregator) and they recover the best possible price for you to execute your orders across all available platforms.

Imagine Google, where you get aggregated information on all the keywords you search for. Afterwards, you can pick the sites that will work best for you.

Similarly, these aggregators accumulate data from a wide array of DEXs and facilitate split trades to offer the best possible prices. DEX aggregators use smart contracts to complete numerous calculations and give users the option to perform split trades to secure the ideal price for a swap.

Due to the algorithmic order routing, you’d likely never be able to find better rates by searching on your own. You’d be competing against continuously refined algorithms to optimize trade routes, rates, and slippage, and against the backdrop of major liquidity fluctuations in real-time.

Among other types of DEXs, DEX aggregators offer a larger liquidity pool, better execution of prices, an easier interface, and fewer technicalities. It has accounted for over 30% of DeFi’s trading since 2020.

Examples are Pancake Swap, Droidex, Sushi, etc.

The Importance of Decentralized Exchanges to DeFi

Decentralised Exchanges are the cornerstone of DeFi, and the main aim is decentralization.

What better way is there to achieve this dream if not by decentralizing the crypto marketplace?

The worldwide market capitalization of cryptocurrencies reached a new all-time high in 2021. In addition, new blockchain trends, such as non-fungible tokens (NFTs), are propelling cryptocurrencies to the forefront of blockchain news. The trading volume of DEXs topped $11 billion in August 2020, which increased tremendously to $500 billion in 2022.

So far, DEXs have seen higher trading volumes than CEXs, accounting for more than 30% of all DeFi trades. The DeFi space has seen an influx of new traders since the introduction of DEX aggregators due to ease of use, enhanced liquidity, and added features.

Benefits of DEXs

Anonymity and Privacy

You don’t need to go through a standard identification process, such as Know Your Customer (KYC) process involving photographs or government-issued identification. Traders using DEX don’t need to disclose their private keys because wallets are held externally. You have full control of your funds and the DEX is not liable.

More Token Options:

Tokens are vetted to ensure that they comply with various local regulations before being listed on centralized exchanges. But DEXs can include any minted token on the blockchain as they are built upon more options than CEXs. Many altcoins are only accessible through DEXs, where P2P transactions can occur without high trading volumes. This allows for diversity and financial inclusion.

Security, transparency, and cost-efficient:

DEXs do not hold your funds as you can keep your assets in cold wallets, unlike CEXs, which require you to keep your assets in them. Because of this, hackers are less likely to target DEXs.

DEXs function through the use of self-executing smart contracts. The gas fee is reduced as there is no third-party agent (CEXs) to help effect a transaction. On the other hand, CEXs charge an agent fee for effecting transactions.

There is no risk of counterparty breach; the other person in the transaction cannot breach their contractual obligations. Because in P2P trading, there has to be an element of “trust.”

One party has to send their token first.

But what if the other party doesn’t send the agreed token/fee?

This can’t happen on DEX since it is a P2S (Peer-to-Smart contract).

Disadvantages of DEXs

Technicality and complexity

Technical proficiency in using wallets compatible with DEXs is necessary. To keep your money secure, you must also understand security-related topics. For instance, if you send $ETH to a $BTC wallet, that fund is gone forever.

To identify the appropriate wallets and fund them with the appropriate tokens for a transaction, you also need specialized wallets. You also have to identify the correct liquidity pools and correct wallets in the right ecosystem, or else you will lose your assets.

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.

When trading tokens with less liquidity, slippage prevention is all but impossible. Slippage tolerance often needs to be manually modified for orders, and doing so requires technical knowledge. Many users might not be aware of what it signifies or how it operates.

All these issues make it harder for users to trade on DEXs.

Lack of fiat trading

Current DEX technology does not facilitate the purchase of digital assets with fiat currency like USD, nor can you trade fiat or make withdrawals into your bank account. You can’t trade your tokens for your local currency on DEXs. Rather, you can only trade for stable coins like $USDT, $USDC, etc. While stablecoin technology is emerging to replicate the role of fiat in the DeFi ecosystem, the lack of fiat on and off-ramps is a barrier to entry for novice users.

Note: A stablecoin is a type of cryptocurrency that is linked to a “stable” reserve asset, such as gold or the US dollar. Stablecoins are intended to reduce volatility in comparison to unpegged cryptocurrencies like Bitcoin.

Liquidity:

DEX works by separating these select assets into trading pair pools. This act of “market segregation reduces liquidity because DEXs, which support a variety of trading pairs, are still fairly new. Despite this drawback, asset liquidity has been rising noticeably with the expansion of DeFi.

DEXs and Oracles

How DEXs provide transparent and auditable market data

As we mentioned earlier, DEXs execute trades through smart contracts and on-chain transactions. Aa a result, DEXs provide an enormous amount of trade information for a variety of asset pairs. As this trade information is generated and gets stored in on-chain environments, it provides transparent and publicly auditable data.

This data creation enables oracle protocols to import this data onto their respective platforms to build price oracles for cryptocurrency assets. A good example of this is DIA — the end-to-end oracle platform for Web3.

DIA’s unique open-source oracle infrastructure differentiates itself from other Web3 data solutions as it doesn’t rely on third-party data providers. To build the price oracles, DIA crowd-sources trade data at a very granular level directly from 45+ DEXs across 15+ networks, but also a 20+ off-chain sources.

DIA’s architecture enables the creation of tailor-made price feeds based on a variety of sources. The feeds can fully customizable in computational methodologies, data sources and more to meet the requirement of every dApp and use case. This approach enables DIA to cater to any specific data and asset needs a project might have and also provides users with full transparency about how the data feeds are constructed, following the ethos of DEXs.

When do DEXs need oracles?

As we all know, without oracles, smart contracts would have very limited use as they would only have access to data from within their networks. A similar scenario happens for Decentralised Exchanges.

Oracles can provide DEXs with the data streams of off-chain assets to unlock new features. For example, an oracle can supply a price feed for assets such as gold, exotic asset or stocks, enabling the DEX to support swaps for synthetic assets — digital assets that represent a real-world assets.

DIA, Chainlink, Band Protocol and other oracle protocols are important to the growth of DeFi as they keep pushing the innovation, UX and features of DeFi.

Conclusion

As of July 2022, Uniswap’s version 3 protocol was handling almost $2 billion in trading volume on some days. dYdX also experiences a daily volume of $830 million, while PancakeSwap sees $300 million to $600 million in daily volume, and Omnidex and Hummus exchange (which use DIA price oracles) see over $63 million and $500k in daily volume, respectively.

That marks an increase of more than 90% since 2020.

Despite the advantages that CEXs still enjoy, DEXs evidently remain the primary driving force behind DeFi to this day, and with the aid of oracle protocols like DIA, DEXs are here to stay.

Now that you are all caught up with DEXs and DeFi in general, you can be a part of this movement that helps DEXs thrive — the DIA DAO!

To join the DIA DAO discord: https://go.diadata.org/Community-Hub

Follow us on Twitter: https://twitter.com/DIACommunityHub

Written by DIA DAO Contributor Gbirioluwaseun

Reviewed by DIA DAO Contributor Umair Abbas

--

--