135 subscribers
join
Rating
Login
Logout

DEX Explained: The Ultimate Guide

Crypto Education

Table of Contents

Central to the ethos of blockchain is decentralization. But since its inception, centralized crypto exchanges have dominated the trading space. While they provide an easy onboarding/offboarding ramp, users are still trusting their assets to a centralized point-of-failure. Centralized exchanges often act as custodians that store and protect users’ private keys, which control access to their funds. Anyone who has been in the crypto space for any amount of time has seen how disastrous this can be if the exchange is hacked or becomes illiquid.

Decentralized exchanges (DEXs) are an alternative whichgive users custody of their own assets and let them trade digital assets without an intermediary.

What is a DEX?

Decentralized exchanges are peer-to-peer marketplaces that connect buyers and sellers of digital assets via smart contracts. These self-execute under set conditions and record each transaction to the blockchain. Decentralized exchanges are non-custodial, meaning users store and manage their own private keys.

On decentralized exchanges, users trade directly from their wallets. This allows them to always maintain control of their assets. Because you have to have the assets in your wallet in order to execute a trade, there is no risk of credit default. Many also do not require users to follow Know Your Customer (KYC) or Anti-Money Laundering (AML) protocols.

How Do DEXs Work?

DEXs work much like centralized exchanges by connecting buyers and sellers and providing liquidity so that they can enter and exit positions with relative ease. In the case of centralized exchanges, the exchange itself maintains the liquidity for users. Since DEXs are not centralized entities, liquidity must be provided, and is usually done so by the users in return for rewards.

Since DEXs are powered by smart contracts, they are often built on blockchain networks that support smart contracts, like Ethereum. Traders pay both a transaction fee and a trading fee with every trade, whether buying or selling. Let’s go over the three main types of decentralized exchanges:

Automated Market Makers (AMMs)

Automated market makers (AMMs) are, by far, the most popular type of DEX. Typically, an AMM uses liquidity pools to pre-fund trades so that when a buy or sell order is placed, the trade is executed instantly. Pools are simply smart contracts in which liquidity providers (LPs) lock their own tokens, which other users can then use to instantly swap assets.

Pools are funded by the users of the exchange, who provide their tokens in exchange for rewards. Typically, liquidity pool providers receive a portion of the transaction fees relative to how much liquidity they provided. LPs need to deposit the same value of each asset in a trading pair in order to earn interest. If they try to deposit an uneven value, the smart contract behind the pool invalidates the transaction.

An important factor to consider when using an AMM is total value locked (TVL), which is the value of assets locked in their smart contracts. Generally, DEXs strive to have higher TVL, as it reduces liquidity problems like slippage. Slippage occurs when there is not enough liquidity on the platform and as a result, the buyer pays above-market prices on their order. Larger orders tend to face higher slippage.

There are also risks for liquidity providers, such as impermanent loss. When depositing two assets for a specific trading pair, if one is more volatile than the other, trades on the exchange can lower the amount of one of those assets in the pool. LPs suffer an impermanent loss when a highly volatile asset’s price rises while the amount in the LPs hold drops.

The good news is that it’s called an “impermanent” loss for a reason, because the loss can be gained back. The price of the asset can move and trades on the exchange can balance the proportion of each asset held in the liquidity pool. The rewards collected from trading fees can also help make up for the loss over time.  

Order Book DEXs

Order books are similar to conventional centralized exchanges. They compile records of all open buy and sell orders. Buy orders contain the price at which a trader is bidding for a specific asset, and sell orders contain the price a trader is willing to sell at The spread between the prices of all the open orders determines the market price of an asset on the exchange.

There are two main types of order books: on-chain and off-chain. On-chain order books hold open order information on the blockchain, while your funds remain safe in your wallet. Off-chain order books only settle trade on the blockchain, which allows for reduced costs and increased speeds. One main criticism of order book DEXs is that they often deal with liquidity issues.

DEX Aggregators

DEX aggregators solve liquidity issues by using multiple protocols to aggregate liquidity. This helps minimize slippage on large orders, optimizes swap fees and token prices, and offers traders the best price in the shortest amount of time.

Some other goals of DEX aggregators include protecting users from the pricing effect and decreasing the likelihood of failed transactions. Some also pull liquidity from centralized exchanges to provide a better experience to users, while allowing them to remain non-custodial.  

Popular DEXs

Let’s examine some of the most popular DEXs and how their platforms operate:

Uniswap

Uniswap is one of the leading decentralized crypto exchanges. It runs on the Ethereum blockchain and any ERC20-based token can be swapped with another on the platform. According to DeFi Llama, there is currently $3.56 billion locked in Uniswap. The exchange has its own governance token, UNI.

Uniswap runs on two smart contracts: an “Exchange” contract that facilitates all token swaps (“trades”), and a “Factory” contract that is used to add new tokens to the platform. Uniswap creates liquidity through an automated liquidity protocol that works by giving users who trade on the protocol an incentive to become liquidity providers. Each listed token has its own pool, making it possible for buyers and sellers to execute a trade instantly at a known price as long as there is enough liquidity in the specific pool to facilitate it.

Uniswap charges users a flat 0.30% fee for every trade, which is automatically sent to a liquidity reserve. Liquidity providers receive a token that represents their staked contribution to the pool in exchange for locking up their funds that is redeemable for a share of the collected trading fees. When an LP decides they want to exit, they receive a portion of those trading fees in the liquidity reserve relative to the amount they staked.

Uniswap uses an AMM protocol that works by changing the price of a coin depending on the ratio of coins are in the respective pool. The equation used to determine the price of each token is x*y=k, with x being the amount of Token X, y being the amount of Token Y, and k being a constant value. In order to start a liquidity pool, someone must deposit an equal amount of both chosen ERC-20 tokens. The more money, or liquidity, in the pool, the less likely slippage is to occur.

Curve

Curve was launched in January 2020 and has risen  to become a central DeFi protocol. It runs on Ethereum and uses an AMM algorithm designed for extremely efficient stablecoin trading. There is currently $3.74 billion locked in Curve, and the exchange has its own governance token, Curve DAO Token (CRV), and its own vesting token, veCRV.

The Curve v1 protocol was designed to solve the peg problem that occurs with stablecoins, which are typically pegged to the dollar or another fiat currency. Since fiat prices fluctuate,  exchange rates can move so much that many open positions are liquidated. Curve uses liquidity pool  smart contracts that manage a pair of tokens. The AMM formula they developed is specifically for pools with pairs of tokens, the price of which must change in sync with each other. Curve v2 includes a new type of AMM that allows for extremely efficient trading and low risks for non-pegged assets.

For example, imagine a pool of DAI and USDC where 1 DAI = 1 USDC with 1,000 DAI and 1,000 USDC in the pool. If a trader exchanges 100 DAI for 100 USDC, the pool then becomes biased towards DAI with 1,100 DAI and 900 USDC. Traders are incentivized to take advantage of the arbitrage opportunity to exchange USDC for DAI and average the pool back.

Curve interests come from trading fees, which are collected every time someone uses Curve to exchange tokens and then a small fee is distributed to liquidity providers. Swap fees are around 0.04%. Some pools, like Compound or Aave, also earn interest from lending protocols, which can perform better when lending rates are high, but also introduce  more risk for liquidity providers.

SushiSwap

SushiSwap is a forked version of Uniswap that was created in the summer of 2020. It uses an AMM protocol and is on the Ethereum blockchain. There is currently $436.08 million locked in SushiSwap and the exchange has a governance token SUSHI that is distributed to  liquidity providers.

In order to obtain initial liquidity for the platform, a ‘vampire mining attack’ was executed on Uniswap to essentially source liquidity from Sushi’s parent platform. The SushiSwap team convinced liquidity providers on Uniswap to transfer their crypto assets by using additional rewards in the form of SUSHI tokens. After $1 billion in liquidity pool tokens were staked on the Sushi platform, the volume of assets on Uniswap temporarily fell by 75%, but eventually the protocol returned to its top position by airdropping UNI governance tokens.

SushiSwap uses an AMM protocol to facilitate liquidity pools. There are two main features: Trade, which is for swapping tokens, and Liquidity, which is used to add funds to liquidity pools. Sushiswap has also expanded into other areas of DeFi like lending, with their Kashi lending protocol that limits risk for collateral providers. LPs lock their tokens in liquidity pools that borrowers tap into to get a loan by locking their own tokens as collateral. Borrowers also pay APR depending on the token pair.

SushiSwap also offers SushiBar, a staking liquidity reserve. Users can stake their SUSHI tokens in SushiBar’s smart contracts to provide extra security against extreme market conditions.

Liquidity providers receive a small percentage of the fees generated by trading, as each swap requires a 0.30% transaction fee. 0.25% of that is given to LPs as a reward for contributing to the pool, and 0.05% goes to SUSHI token holders who stake in SushiBar

PancakeSwap

PancakeSwap is a BNB Chain-based DEX for swapping BEP-20 tokens. There is currently $2.41 billion locked in PancakeSwap. PancakeSwap uses an AMM model to allow users to trade against a liquidity pool. PancakeSwap’s governance token is CAKE.

Liquidity providers receive LP tokens in exchange for locking up their assets which they can use to reclaim their liquidity plus a portion of trading fees. PancakeSwap allows users to farm its governance token. LP tokens can be locked up in reward for CAKE. You can deposit a number of LP tokens in exchange for different asset. In addition to this, users can earn more rewards by staking CAKE in SYRUP pools, where you can earn other tokens through special staking pools.

Bancor

Launched in 2017, Bancor was the very first DeFi protocol. It runs on the Ethereum network. It is a decentralized network of on-chain AMMs that support instant, low-cost trading and it is  the only platform to support There is over $1.5 billion in assets locked in the protocol. Bancor has a native token, BNT, that is heavily used in the protocol, as well as a governance token, vBNT, which is a derivative of the native token that can be earned by supplying liquidity.

As an AMM protocol, Bancor facilitates the usual trade and liquidity provider functions. But Bancor also offers a unique advantage for liquidity providers: Single-Sided Liquidity. In most AMM models, users are required to deposit two amounts of assets of equal value. Instead, Bancor can facilitate an exchange where an asset is exchanged first for BNT, then the BNT is exchanged for the desired end asset, but to the user it all looks like one transaction.

Bancor supports Single-Sided Liquidity Provision of tokens in a liquidity pool. Their Single-Side Staking allows liquidity providers to deposit only one token, BNT, in order to earn. Trading fees are automatically re-added to users' deposits, compounding their gains as well as encouraging them to stay locked in the pool. Users can also earn Liquidity Mining Rewards that auto-compound.

Liquidswap: The 1st DEX on Aptos

Liquidswap is the first DEX and biggest AMM on Aptos. It supports both regular uncorrelated swaps like Uniswap, as well as stable swaps like Curve. The protocol uses smart contracts that are written in the Move language. There is currently over $8 million in assets locked on Liquidswap.

Most AMMs use a constant function, x*y=k, which is suitable for swaps with assets whose prices are not correlated to each other. For stablecoins and other correlated assets, the constant function is not effective. Liquidswap uses a different, more complex formula to minimize slippage, even for large transactions: x^3*y + x*y^3 = k.

In return for providing liquidity, users receive LP tokens, which are burned in order to redeem the liquidity together with the earned fees. Pools of uncorrelated assets are created with default 0.3% fees, and stable pools are created with default 0.04% fees. 66.7% of these fees are given to LPs, and 33.3% is sent to the treasury contract created for each pool on the DEX by default. The treasury itself will be initially managed by a multisignature of Pontem and trusted 3rd parties and then eventually migrated to a full-fledged treasury contract managed by the Pontem DAO.  

Install our wallet and try DEX

Related posts

dex-explained-the-ultimate-guide
63a46844848fd03cfd684ffd
amb-dex-explained-the-ultimate-guide