This article will give UX Designers an understanding of decentralized exchanges, as well as an introduction to the design patterns of a popular protocol Uniswap. This is part of an overall Web3 Design Bootcamp that teaches UX Designers about Web3 concepts and design patterns so they can land a job in the rapidly merging field.
Decentralized exchanges (DEXs) allow users to swap between different tokens. It’s a simple use-case, but one of the most foundational dapps in the Web3 ecosystem. Before, users had to temporarily give up custody of their tokens to a centralized exchange to make swaps. DEXs, on the other hand, facilitate token swaps with open-source smart contracts and no intermediaries. Uniswap is one of the most well-known DEXs – let’s see how it works.
After connecting their wallets, users select which token they want to swap from (Token A), and which token they want to swap to (Token B). Uniswap then calculates the exchange rate between this token pair. This tells users how many of Token B they should expect to receive. In the case above, I’m swapping .02 ETH for about 40 DAI, with an estimated network fee of $7.32. I will need to have extra ETH in my wallet to pay this network fee.
Now let’s talk about what is happening under the hood. For example, where did the DAI come from that I swapped into? Decentralized exchanges use a different method than centralized exchanges for making these trades. Centralized exchanges (CEXs) use something called a central limit order book, or CLOB, to match buyers and sellers. Basically, buyers place bids for how much they are willing to pay for an asset, and sellers place bids for how much they are willing to sell an asset. The transaction is executed when there is overlap between the buy and sell bids. An order book for Bitcoin is shown above, where the green area represents buy orders, and the red sell orders.
CLOBs are costly to run on-chain because they are transaction heavy and benefit from fast transaction processing. Thus, DEXs implement a different approach to token swaps. Every token pair you can swap on a DEX has a liquidity pool. So, in the example above, I made my swap using Uniswap’s ETH-DAI liquidity pool. We see $54.82M of tokens are locked in the ETH-DAI liquidity pool, made up of 23.81M DAI and 15.52k ETH. As users make swaps on these liquidity pools by depositing Token A and withdrawing Token B, an algorithm automatically recalculates the exchange rate for the token pair. These algorithms are known as “automated market makers”, or AMMs, and are responsible for updating token prices on DEXs based on supply and demand dynamics.
Now, where do the tokens in the liquidity pools initially come from? Liquidity providers (LPs) are other Web3 users who want to earn yield on their tokens. Uniswap charges a trading fee (0.3%) on each swap, and this trading fee is distributed to the liquidity providers for that pool. LPs deposit Token A and Token B into a liquidity pool, and receive LP tokens in return. At any point, users can burn their LP tokens for their initial liquidity plus whatever trading fees have accrued to them.
So, those are the basics of DEXs. Liquidity providers deposit tokens into liquidity pools to earn trading fees. Traders use these liquidity pools to make token swaps. And, AMM algorithms reprice tokens within liquidity pools based on market conditions. Uniswap is not the only DEX out there. Other DEXs have been created that excel for different use-cases. For example, Balancer allows liquidity pools containing up to 8 different tokens, whereas Uniswap liquidity pools always contain only 2. And, Curve is a DEX focused on stablecoin swaps, resulting in less slippage and reduced risk of impermanent loss.
Speaking of stablecoins… The vast majority of Web3 tokens have volatile prices, but a subset of them, called stablecoins, are designed to maintain a stable price over time. This makes them more attractive as a medium of exchange compared to volatile tokens. As Ryan Selkis puts it, “no one wants to spend currency they believe will be worth 10% more tomorrow, and no one wants to accept currency they think could be worth 10% less tomorrow.” This leads into another foundational DeFi protocol, MakerDAO, which allows users to deposit their volatile tokens (e.g. ETH), and mint stablecoins for tax-free spending.
If you enjoy videos over reading when it comes to online learning then checkout the course on YouTube. This is part 2 of 10 in the DeFi for UX Designers Course. Also, make sure to stay tuned for future Web3 Design Courses, which will cover emerging Web3 product categories.