What is a Decentralized Exchange?

Community sourced content

A Decentralized Exchange, often called as DEX, is a peer-to-peer marketplace where direct asset transactions happen between traders without the need of fund management and custody from a third-party organization. In this article, we will deeply dive into decentralized exchanges (DEXs), their mechanisms, and some of their benefits and drawbacks.

TLDR:

  • Centralized exchanges are still attracting a huge number of users nowadays but have some negative aspects.
  • A decentralized exchange allows direct peer-to-peer trading for traders without the need for third-party management.
  • There are three types of decentralized exchanges: oderbook-based DEX, automated market maker (AMM), and a DEX aggregator.
  • Orderbook DEX has two types: on-chain order books and off-chain order books.
  • An on-chain order book decentralized exchange will execute everything on-chain while the user's funds still remain in their wallet.
  • An Off-chain order book decentralized exchange provides lower gas fees and faster transaction times compared to the on-chain models thanks to partial off-chain execution.
  • An automated market maker (AMM) is a decentralized exchange where traders can trade crypto assets in a “liquidity pool” without the need of order books.
  • A DEX aggregator integrates a wide range of liquidity pools from various decentralized exchanges to minimize the slippage, and optimize gas fees.
  • Advantages of using a decentralized exchange: permissionless and privacy, no counterparty risk, vast token availability.
  • Disadvantages of using a decentralized exchange: specialized knowledge requirement, smart contract vulnerability, high-risk token.

What is a decentralized exchange?

From the early days of cryptocurrency, exchanges have been playing a vital role in providing a marketplace to match crypto buyers and sellers. Centralized Exchanges (CEXs) are currently dominating this field by offering a liquid marketplace with high trading volume. However, when you send funds and exchange it on these exchanges, they will act as custodians of your assets by storing your funds along with your private key and executing your transactions in their database.

This operating mechanism in fact requires users to KYC identity and trust the solvency of the business, which are often seen as negative to crypto users (basically you don’t always trust anyone in this market!). The crypto industry is aiming to become decentralized as much as possible in order to provide a trustless environment for all users. That’s why with the proliferation of available technology and the emerging sector of Decentralized Finance (DeFi), the number of decentralized exchanges are growing rapidly with the purpose to eradicate intermediary independence.

The significance growth of Decentralized Exchanges (DEXs) in 2020 (Source: CoinDesk)

A decentralized exchange will allow direct peer-to-peer trading for traders without the need for third-party management. Instead, these transactions between buyers and sellers are facilitated on-chain with the use of self-executing agreements written in code called smart contract. Therefore, a decentralized exchange can operate in the non-custodial framework, in which users will have full control over their funds and private keys. Specifically, it allows users to transact with assets directly from their wallet by interacting with the smart contract behind the exchanges.

As powered by blockchain technology, every decentralized exchange is always built on top of a layer-1 blockchain network. Cross-chain decentralized exchanges have been in use, but famous decentralized exchanges still revolve around blockchains. For example, Uniswap is the most popular decentralized exchange on Ethereum, while PancakeSwap is the leading one on BNB Smart Chain.

How a decentralized exchange works

Keep in mind that currently there are three types of decentralized exchanges: oderbook-based decentralized exchange, automated market maker (AMM), DEX aggregator, which offer different trading mechanisms. But still, these decentralized exchanges share the same common features: on-chain execution with smart contracts and user’s full responsibility for their funds.

Oderbook-based decentralized exchanges

In the early development of decentralized exchanges, some platforms utilized an implementation of an order book, which is the popular model used by most centralized exchanges. This allows users to place their best bid or ask price as well as being able to use common orders from CEXs such as limit, take profit, and stop-loss orders. An orderbook-based decentralized exchange has two types: on-chain orderbook decentralized exchange and off-chain orderbook decentralized exchange.

Example of OrderBook-based Decentralized Exchange (Source: Mango Market)

On-chain order book Decentralized Exchanges

A decentralized exchange using an on-chain order book will execute everything on-chain, including transactions history, cancellations and alterations on the blockchain, while the user's fund still remain in their wallet. This is the most transparent decentralized exchange where everything will be published on-chain and you don’t need to trust and depend on any third party to relay orders to you. However, it exposes some of the drawbacks to users.

Firstly, the transactions on these decentralized exchanges would be costly since it requires every node to record every order on the blockchain. Secondly, users also have to wait for validator confirmation, which may cause a cumbersome trading experience on these decentralized exchanges. Furthermore, as every information was published on a global ledger, a miner can be aware of pending transactions and may take advantage to ensure that their own orders gets added first, causing slow settlement for oher traders.

Some examples of decentralized exchanges using on-chain order books are Stellar and Bitshares DEXs.

Off-chain order book Decentralized Exchanges

With an off-chain orderbook, these problems from the on-chain model can be tackled. Instead of validating every transaction on the blockchain, every trading activity in the orderbook will be executed off-chain with settlements occuring on-chain. This solution can lower the gas fees and speed up the transaction time as it doesn't use blockchain as much. Ironically, this decentralized exchange becomes more “centralized” and requires you to put some trusts into the platform. However, you would still benefit from its non-custodial storage.

Binance DEX and EtherData are some examples of decentralized exchanges that use off-chain order-book models.

Automated Market Maker (AMM)

An automated market maker (AMM) is a decentralized exchange with a set of smart contracts that use “liquidity pools” where traders can trade crypto assets without the need of order books. Basically, users will interact directly with the smart contract that holds all the funds in the pre-funded pools. When making a transaction (swapping) between two different assets, for example A and B, users will put their funds (A) into the pool and the smart contract will confirm and return the other (B) to the traders.

A liquidity pool is a pool of funds of the two specific assets whose prices will be determined by a mathematical formula such as the basic formula below:

Example basic formula from Uniswap

  • K is the fix variable
  • X is the number of token A.
  • Y is the number of token B.

Different AMM decentralized exchanges may have different formulas but they all share the same goal: to ensure both of the tokens in the pool are always equal to each other in value.

Let’s take a simple example for the ETH/USDT pair in the liquidity pool. With the current price of 1 $ETH = 100 $USDT, the conversion ratio in the pool would be 1:100. Assume we have around 100 $ETH (x) : 10,000 $USDT (y) in the liquidity pool, which makes our k ratio = 100*10,000 = 1,000,000. A buyer uses 100 $USDT (v) to purchase $ETH, therefore, the number of $USDT increases by 100, while the number of $ETH in the pool decreases based on the calculation (let’s say a z for the number of $ETH users will get from the trade)

(x-z)*(y+v) = k => z = 100 - (1,000,000/10,100) = 0.901 $ETH.
Therefore, the buyer will get around 0.9 $ETH from 100 $USDT due to the slippage since this trade also has increased the price of $ETH to around $111. Slippage also can be an issue for an AMM decentralized exchange if there’s a lack of liquidity, which can result in above-market price purchase from users. Therefore, it’s always recommended to trade on the asset pair that has large liquidity pools to avoid high slippage problems.

On the other hand, liquidity pools are required to be funded by liquidity providers (LP). These providers will provide liquidity so traders can easily swap assets on this decentralized exchange, in return, they will earn % on the trading fees. The total value locked, popularly known as TVL, is among important indicators to rank these decentralized exchanges. However, Liquidity Providers should also be aware of some potential risks such as Impermanent Loss, which can affect the amount of token within the asset pair due to the price volatility.

However, an AMM decentralized exchange still has the merits of providing a permissionless and trustless environment for users to trade and earn interest. Since the code is all open-source, everyone can easily develop and launch their own tokens with provided funds on these decentralized exchanges at ease. Uniswap is by far the best-known example of an AMM decentralized exchange which allows anyone to swap $ETH and any liquid ERC-20 token on Ethereum. Other blockchain networks also have their own native AMM decentralized exchanges, such as PancakeSwap on BNB Smart Chain or Raydium on Solana.

Pontem Network is also building a native AMM decentralized exchange on the Aptos blockchain. Aptos is a new layer 1 powered by the innovative Move programming language and Move VM. Our AMM decentralized exchange will be among the important foundational dApps to further develop the ecosystem and onboard a billion users in the future. Try swapping assets on Aptos here.

Pontem Network AMM Liquidity Swap

Currently, the Pontem Network AMM is still in the testing phase. We offer all the fundamental features, including liquidity swap, liquidity providers, along with some unique ones such as pool creation and burn liquidity. In order to use these features, you will have to install the MultiMask wallet via our instructions here. Community feedback is essential and we will have some amazing rewards for every user who uses our products and has a meaningful contribution.

DEX Aggregator

As the above two types of decentralized exchanges all face issues with lack of liquidity, especially for smaller tokens. DEX Aggregators were created to solve this problem. This type of decentralized exchange integrates wide ranges of liquidity pools from various decentralized exchanges into one comprehensive interface to minimize the slippage, and optimize gas fees.

Source: 1inch Network

Take the 1inch liquidity swap feature as an example, this decentralized exchange offers crypto traders to get access to other liquidity pools from different decentralized exchanges in one place. When you enter your trading pair, the liquidity aggregator will automatically uncover which decentralized exchanges should have the best prices for your trade.

Advantages of using a Decentralized Exchange

There are numerous merits of using a decentralized exchange compared to the traditional marketplace.

Permissionless and Privacy

There is no information required to use a decentralized exchange. All you need to have is a crypto wallet with the native coins of that blockchain for transaction fees. This is a huge advantage as it allows users to get access to these decentralized exchanges easier and protect users' identity. While centralized exchanges always require users to give out personal information via a standard identification process known as Know Your Customer (KYC).

No Counterparty Risk

Counterparty Risk is the probability that the other party involved in a transaction does not fulfill its part of the deal, for example when a centralized exchange goes bankrupt and can not pay back all the money to users. This situation will never happen to a decentralized exchange as it doesn’t hold customer funds. However, to ensure the best security, it is recommended for users to check the decentralized exchange’s smart contracts whether they have been audited or not before deciding to use the platform.

Vast Token Availability

Decentralized Exchanges can provide trading pairs of tokens that haven't been listed on centralized exchanges as long as there's a pre-funded liquidity pool for the assets. CEXs have to ensure the project has been complying with the local regulations before listing them. This process usually gets prolonged and costs lots of resources. That’s why lots of new crypto projects often launch their tokens on decentralized exchanges first before getting to be listed on centralized counterparts.

Disadvantages of using a Decentralized Exchange

However, decentralized exchanges still contain some drawbacks that reduce customer experience when using these protocols.

Require More Specialized Knowledge

While centralized exchanges only require your personal information and some basic understanding for transfering funds, users will have to learn lots of concepts to be able to use decentralized exchanges easily. This includes the deep understanding of your cryptocurrency wallet, which used to interact with smart contracts on decentralized exchanges, and some actions related to transaction fees, token management and security.

Furthermore, avoiding some common problems such as high slippage and impermanent loss

remains a challenge on decentralized exchanges. Without any specific knowledge and some technical experience, newcomers may easily commit some common errors that lead to the loss of funds on these decentralized exchanges. Therefore, it is recommended to learn and maybe use a little of your fund to experiment with these decentralized exchanges before making any bigger decision.

Smart Contract Vulnerability

Smart Contracts are the core operation of decentralized exchanges, however, their code can be prone to exploited bugs that can pose threats to your fund when you interact with them. Therefore, users are encouraged to do research and scrutinize the audited process of smart contracts and also incentive fixing bug programs from the projects. Although there will still be potential risks due to some human factors, it definitely enhances the security of that specific decentralized exchange.

High-risk token

As the code is all open source and anyone can easily create their own market and launch their own token on decentralized exchanges, there is a higher risk for users to buy low-quality or malicious tokens that can lead to some scamming situations such as rug pulls.

Before making any purchase decision, investors must do research and consider all the risks related to these early-stage projects.

The Future of Decentralized exchanges

Launched in 2014 with the first decentralized exchange, these platforms have been evolving rapidly and just gained huge adoption in 2020 when decentralized finance (DeFi) blew up. These decentralized exchanges provide users a permissionless and trustless environment with no KYC process, a democratized access to the financial system, and an opportunity to launch and market small projects at ease.

Although we can not predict if there is a shift of trading activity from traditional exchanges to decentralized exchanges in the future, it is undeniable that decentralized exchanges are still playing a vital foundation in the cryptocurrency economy. These protocols will continue their development for better smart contract security, governance infrastructure, liquidity as well as offering new applications for users. These decentralized exchanges will continue evolving to fulfill the whole Web3 mission: decentralizing financial systems powered by blockchain technology.

A simple thing proving how important decentralized exchange is the fact that each blockchain network needs to have at least one decentralized exchange. It’s the source of all the basic financial activities of a crypto user when they enter the world of decentralized finance on blockchain. For example, BNB Smart Chain with its PancakeSwap project or Raydium on Solana blockchain. None of them will be successfully developed if they lose the core foundation of decentralized exchanges. This goes the same thing with the newly emerged blockchain, Aptos. Pontem Network liquidity swap will be among the first native decentralized exchanges on this nascent blockchain, enabling liquidity and discoverability for protocol tokens in the Aptos ecosystem. We commit to bring a unique and exceptional experience for DeFi users with extremely fast transactions and better security derived from Aptos network.

About Pontem

Pontem is a product studio working toward global financial inclusion powered by blockchains. We are partnered with Aptos to build foundational dApps, development tools, AMMs, and more.The Move IntelliJ IDE and Move Playground are just the beginning."

Join our community on:

Twitter

Telegram

Github

Discord

Install our wallet and try DEX