DEX; UNISWAP MECHANISMS
PREAMBLE
The very idea of a DEX (Decentralized Exchange) speaks to the true intent of the cryptoverse, a financial policy that is owned by everyone and can be monitored by everyone. The sole purpose of this article is to expound on what is a DEX, using Uniswap as a case study, while in Uniswap the goal is to turn its mechanisms inside out, take them apart, inspect them and see how they can be properly utilized on a personal basis. Now one article can’t do full justice so for this article the mechanisms under the inspection lenses are V1, V2 and V3.
DEX | CEX
In the crypto space, they are two kinds of exchanges a DEX and a CEX (Centralized Exchange). A CEX is basically a third-party between buyers and sellers in the crypto space. They create a platform that allows users to buy and sell cryptocurrencies for fiat currencies. They operate as trustworthy brokers in deals and frequently serve as custodians and trusted intermediaries, safeguarding your cash and wallet keys. Examples include: Binance, Bittrex etc.
A DEX on the other hand takes a different approach to buying selling of digital assets; they operate without a third-party intermediary between traders, instead relying on self-executing smart contracts to facilitate trading. In simpler terms, on a CEX you have a third-party in the middle of the trade, who monitors the trade, and ensures that traders involved in a particular trade each get what they want, (for a transaction fee charge of course) and sometimes if a trader wants to sell a certain token that is dumping, the third-party bears the brunt and buys said token form the buyer. Effectively, this means regardless of whether there is a corresponding buyer to a seller or vice-versa, a trade always goes through on a CEX because the CEX assumes the role od buying off your tokens when you want to sell or vice-versa, (for a transaction charge). But on DEX, for every sale they must be a corresponding buy, so if I want to sell say my DAI tokens on DEX, unlike CEX where be there a buyer of DAI or not my tokens will be sold, on a DEX your order can only be filled when a buyer is available. As you can see right away, littles problems in trade such as delay, occurs frequently.
Now different DEX’s went about the solution to the issue differently, but the focus here will be on how Uniswap went about it.
Uniswap’s solution came in liquidity pools. A liquidity pool or liquidity in this context is a mechanism set up to bypass the third-party hiccup of CEX. A liquidity pool is basically a pile of cryptocurrency locked in a smart contract and it is a self-executing program based on the agreements between the buyer and the seller. The pool enables cryptocurrency trading by providing users of Uniswap with liquidity. Liquidity refers to the ease with which a token can be swapped for another, in simpler terms liquidity is the purchasing or selling power backing up transactions in the Defi ecosystem, given the numerous cryptocurrencies in the market currently. Liquidity pools are provided by liquidity providers (LP) or “investors”, liquidity providers provide a service to DEX users by equipping them with tokens that are easily tradeable within the same blockchain.
Furthermore, LPs are necessary to initiate trading in an environment where there is no seller, meaning if a trader wants to buy certain tokens, but nobody wants to sell the LPs fill in that vacuum. Now for their service as LPs, they receive an interest/reward in form of trading fees from the trades traders make within their pool. Uniswap’s liquidity pool solution first started with the version one (V1), then version two (V2) and now version three (V3).
VERSION ONE (V1)
Allows traders trade with a pool of money at any point in time with very low fees, for theoretically infinite amount of money. Now V1 had different pools for different traders, it had DAI/ETH BTC/ETH USDC/ETH.
This meant if you had DAI, and wanted USDC, you had to trade with different pools meaning more work and more expenses. In simpler terms, under V1 you needed ETH for every transaction and if you don’t have it, you would have to interact with multiple pools. So, if I had DAI tokens and I wanted USDC tokens, I had to swap my DAI for ETH first before being able to swap my ETH for USDC, which was quite tasking but at the time very useful.
VERSION TWO (V2)
This version was a fix to V1, V1 had an interaction pool problem, V2 fixed it by creating pools that don't need Ethereum. Which means traders can interact via any pool as they see fit. For example in V1 if a trader had USDC tokens and wanted to exchange them for BAT tokens, they had to interact first to get their USDC converted to ETH tokens, then use the ETH tokens to initiate a fresh swap in order to get their initial needed BAT tokens, but in V2 if a trader had USDC tokens and wanted to get BAT tokens, the trader simply had to create their own pool by initiating a direct swap across the DEX for the BAT token they wanted, instead of having to convert to ETH then swapping for BAT. What V2 solved was immense, because not only was time conserved, but the transaction fees of V1 was reduced by half. The forking of the project made the Uniswap code invaluable.
VERSION THREE (V3)
Uniswap V3 was launched in March 2021, on both the Ethereum main net and the optimisim main net (optimisim is a secondary network used to scale Ethereum). The update in V3 is called Concentrated Liquidity. Now liquidity basically is money you provide someone else so they can trade with it and give you a commission for using your money. Concentrated liquidity is you giving your money extra set of rules, as an investor or liquidity provider, your money or Ethereum assets is lent to the pool, now the pool lets the traders trade your assets back and forth, while you the investor or provider collects fees from those traders as payment; that way everybody is happy.
In other versions (V1 & V2), when you provide liquidity, your asset is spread evenly between the range of $0 to infinity dollars for traders to trade with, meaning every trader has equal rights and limits to trading with your assets or any other asset in the pool, but in concentrated liquidity instead of letting your assets be spread thin across all price ranges, you can now select where you want to deploy your liquidity that is the price range you want the pool to make your assets available for trading, which means not all traders can have access to the liquidity you've provided. The benefit to this is that the capital a provider provides is essentially multiplied. Two major things happen when the market price falls out of the range for your concentrated liquidity.
1. No more fees earned
2. Your money or the liquidity you provided will be turned into one simple asset; to explain this, we need the basics once more. When you provide liquidity, you provide them in assets, an Ethereum asset and any other asset of your choosing, now if you provided liquidity under V3 what it means is that you've indirectly placed a Sell/Buy limit on your assets. This means that if the market price goes below your range, all your Ethereum assets will be converted to the other of two assets you provided and if the market price goes above your range, all your other asset will be converted to Ethereum.
COMPARISON BETWEEN V2 & V3
Comparing both versions is quite simple, let me explain; Say two investors, Investor A and Investor B provided liquidity to a pool under V2 and V3 respectively, Investor's A assets would be spread evenly across the price range of 0 - infinity while Investor's B asset will be restricted to a particular range, which means Investor A will bear most of the risks of the market fluctuations while Investor B won't but will rather depending on the APY of the market make more than Investor A. The risk faced by V2 users is general market fluctuations and nothing more, but in V3 you are in risk of impermanent loss. V2 users can also suffer impermanent loss but not as bad as V3 users.
Impermanent loss happens when you provide liquidity to a pool, and the price of your digital assets fluctuates compared to the initial price when you deposited them. The bigger the fluctuations, the more your exposure to impermanent loss. Impermanent loss is the unrealized loss that occurs when your share of a liquidity provider position becomes uneven compared to its original position. For example, Reynolds decides to provide liquidity with the ETH/BANK pair. He provides 5ETH at the market price of 100USD for 1ETH and 500BANK at the market price of 100USD for 100BANK, which means an equal ratio of 500USD on each of the token in the pair and a total worth of 1000USD. After he provided the liquidity, ETH price rose from 100USD to 200USD, then arbitrage trader interacts with Reynold’s pool intending to buy ETH low and sell outside high. Now the arbitrage trader intends to buy 2ETH, the pool calculates and charges the trader 200BANK which is worth 200USD and gives the trader the 2ETH. The pool now has 3ETH left at 300USD and 700BANK at 700USD still equal to 1000USD. Now Reynolds decides to withdraw his liquidity of 3ETH and 700BANK, the market price of ETH is now 200USD which means his 3ETH is now worth 600USD as opposed to the initial 500USD worth of ETH he had earlier, plus his BANK he now has a total worth of 1300USD cool right? But if Reynolds was hodling and not providing liquidity his 5ETH of then 500USD will be worth 1000USD, combined with his BANK to give a total value of 1500USD. If you work out the difference, he has an impermanent loss (which is now permanent by the way) of 200USD. Now the transaction fees he gained can mitigate the loss a little but not fully.
The best way to avoid impermanent loss and to maximize provision of liquidity is to always go for pairs that do not fluctuate in the market as often as others i.e. pairs with relatively low volatility, example DAI/USDC