What are DEXes? And how can we use them? Are Decentralized Exchanges better than centralized exchanges? Have you ever wondered why and how many DeFi protocols all follow a particular guideline or structure of code or governance that all dApps should follow?
In this article, we will dissect what exactly a DEX is, how they work, and examine the biggest DEX and the pros and cons of using a DEX. Shall we?
BTW, if you are really interested in learning everything about DeFi, check this out.
What are Decentralized Exchange (DEX) Protocols
Decentralized exchanges are a marketplace that facilitates the exchange of one cryptocurrency to the other with no centralized parties involved. Everything is automated via Smart Contracts on the blockchain. The core capabilities of every DEX are buying, selling, trading, and portfolio management. These rely on the smart contract to lock funds (tokens) and automate transactions through AMM — Automated Market Maker.
In a DEX, users can only swap cryptocurrency for another cryptocurrency. Unlike centralized finance, where a user is matched with an individual seller and can set a buy order, the AMM offers tokens from a pool where people (also called liquidity providers) have deposited their tokens over time. This is called liquidity pool or yield farming.
Liquidity pools are the mechanism by which users can deposit their assets into a DEX smart contract so other traders can have access to swap their tokens. We will talk further about this later in this article.
What is the biggest DEX?
The first ever DEX in the Ethereum network was EtherDelta launched in 2016. EtherDelta is still active, by the way. From inception till now, many other dexes have emerged. We have the likes of Curve, Balancer, dYdX (for perpetual), Sushi swap, Pancake swap, Uniswap, Quickswap, and the other numerous “swaps”. In all these, a few of the major game players are Uniswap, Curve, and dYdX.
Why are these considered the biggest DEX? If we look at their stats on coinmarketcap, the market cap for Uniswap, Curve and Pancake Swap are approximately $4.9b, $3.3b, and $639m, respectively. This shows they are one of the big guys on the block.
Additionally, as you can see below, the top DEX according to their TVL — Total Value Locked — are Curve, Uniswap, Pnacakeswap, and Balancer.
Top Decentralized Exchanges by TVL. You can check this sourceto see many other DEX.
Later in this article, we will do a tutorial on how to use Uniswap.
How do DEXes work?
The process of using a DEX is very very simple. Actually simple than using most banking centralized exchange apps.
A part of this process involves yield farming (or liquidity providing). Most DEX use an Automated Market Maker (AMM), which is also known as the liquidity pool algorithm. This enables users to trade with a pool of funds from the liquidity pools. The AMM matches buyer's and seller's orders, sets prices, and allows traders to trade algorithmically using the smart contract. Unlike in traditional order books, you don’t have a buy or stop-loss order (except if you use platforms like https://dydx.exchange/ or https://gmx.io/.)
Automated Market Marker(AMM)
Let’s talk further on AMM. AMM allows traders to buy/sell assets based on algorithms. It is basically supply and demand sequence but based on an algorithm that works on the top of the liquidity pool. The law of demand and supply states that “the higher the demand, the lower the supply.” We could use a simple analogy of farming. Let’s add a little drama to it...
POV: *Alice is a mango farmer while Bob owns a cherry farm*
Alice: Hey bob, I am tired of eating only mangoes. Do you mind if we exchange produce so I can have a taste of other fruits?
Bob: *excitely* oh my!…he said, you took it outta my mouth. I thought I would die eating cherries all my life.
*They both had a plan in place to swap their produce for each other based on its value. For each mango, Bob gives Alice 10 cherries. This goes on for a few months. One day, Bob meets Alice with a suggestion*
Bob: Why don’t we check if there are other farmers like us who would like to exchange their farm produce for ours as well?
Alice: Oh, sure…why not?!
They got some other addition to the team. Frank and Tom. Frank farms Tomato, while Tom rears livestock. They all agree to store their produce in a barn. This barn is the liquidity pool. Here the exchange happens, and they can trade their produce for another among available produce in the pool. All these farmers are the liquidity providers.
There is a twist to this, however. They all want structure. They agreed on a formula to sort this. The value of each produce is determined against the liquidity pool(pl). The price feeds are calculated based on the Constant Product Market Maker. So we have,
X * Y = K
Where X = Quantity of asset X in the pool
Y = Quantity of asset Y in the pool
K = A total of all asset that needs to be in the pool. This value is Constant.
Let us assume each farmer’s produce deposited cost $1000 each. This shows they have $4000 total value locked (TVL) in the pool. Note that assets exchange are usually in a pair. So Alice deposits $1000 worth of mangoes, locked in, and she gets rewarded the lp token based on the portion of what was deposited. Bob does the same thing and gets rewarded the lp token as well. The pool is equally balanced, hence K will be $2000. So when people buy more mangoes, we have more cherries and fewer mangoes in the pool. This means more cherries will be sold for a lower price, and mangoes will be more expensive to balance their value in the pool. This could also lead to Impermanent loss.
Liquidity Pools
Liquidy providers provide tokens to the pool and earn rewards/interest on the funds/assets locked in the liquidity pool.
Anyone can add liquidity to Uniswap (or to other DEXes). You will earn part of the fees that are collected from the people that trade the pair that you have provided (in the screenshot above, it’s DAI/ETH.) The fees in this case are 0.3%, and at the end, it may represent a few percentage points for the LPs.
Users who want to swap their tokens for another token go into the pool and perform their transaction to swap their tokens without an intermediary taking custody of the funds.
BTW, I explain all these concepts in depth here.
Impermanent loss
Liquidity providers are exposed to impermanent loss. This loss is not permanent, hence the name “impermanent loss.”
Impermanent loss only happens if the prices of the assets change. It doesn’t necessarily mean you will lose money. Instead, in some circumstances, you’d be better off just holding those assets. Changes in the token price affect the composition of the liquidity pool, resulting in having slightly more or less of a particular token. The LP has a right to earn a fee on every transaction in the pool, and this may mitigate the impermanent loss. However, in the end, there are variations in the quantity of the assets in the pool.
Changes in the price of the assets that you provide will translate into a different token distribution. which leads to impermanent loss.
Impermanent Loss can also be defined as the difference between simply holding an asset and using that asset to provide liquidity to a pool
Note that you don’t need to worry about impermanent loss if you just wish to trade on a dex.
Slippage
Slippage is when the market price is different from the transaction price. It can happen in any market. This can happen in any market. There are a few reasons why slippage may happen:
- Market with lower liquidity
- High volatility
- Low market dept
- When a large order is executed, and there is not enough volume to maintain the current bid/ask.
Example of slippage in a low liquidity token pair on Uniswap.
How to use Uniswap?
We’re going to be doing a hands-on of one of the top DEX: Uniswap.
Uniswap is more than an exchange platform. It is a decentralized liquidity protocol. To use Uniswap to trade or exchange/swap crypto, follow the steps below:
- Visit the Uniswap website.
- Click on the launch app
3. Select the token you want to swap for the other and insert the amount.
4. Click on connect wallet (make sure you have actual funds in your wallet for this to go through. lol)
5. Don’t forget to connect to the right network on your wallet as well.
6. “Confirm swap.” Your metamask wallet shows up and then approve the transaction.
You should notice on the menu bar that we have the options “swap”, “pool”, “vote”, and”charts”.
Let’s talk about the “pool” menu. You should see a list of tokens in the pool that you already deposit. If not, follow along, and let’s make some investments to earn some yield…
- Go to the liquidity pool. You will see numerous tokens/coins listed.
- Deposit into the pool
Congratulations on being a liquidity provider and “low-budget investor.” The yield generated is not high, but Uniswap is quite awell battle-tested and safe DEX. Always make sure that you interact only with solid DEX that has been audited!
Downsides of using a dex
- No user education or support. Only community support
- Low liquidity. If you are a whale and if you sell a ton of tokens, you can crash the price, and if you buy a lot, you can hike the price.
- Hacker attacks in small, untested, and not audited DEXes.
All Comments