At its core, Uniswap is a unique solution for the problem of trading illiquid assets on a decentralized framework. Uniswap is a decentralized exchange that solves the lack of liquidity in trading these illiquid digital assets using automated market-making systems as opposed to traditional order books.
Decentralized finance has been a hot subject in the crypto space since the summer of 2020 and for anyone involved, Uniswap is one of the biggest names thrown around crypto circles and discussion forums.
Built on the Ethereum blockchain, Uniswap is a decentralized exchange that is changing the narrative for the entire DeFi movement. While centralized exchanges have been known as the main venues for outsourcing liquidity, Uniswap’s automated market maker has made decentralized exchanges just as capable of providing sufficient liquidity for the nascent crypto economy.
The hype and excitement around Uniswap has been so great triggering moments where the decentralized exchange occasionally managed to surpass the trading volumes of prominent centralized crypto exchanges.
In this article, we take a deep dive into the inner working mechanisms of Uniswap and take you on a step-by-step tutorial on how to use it.
The core concept of Uniswap was originally proposed by Vitalik Buterin back in 2016 when the Ethereum founder suggested the idea of a decentralized exchange (DeX) that would deploy an automated market maker on the blockchain. At the time, existing decentralized exchanges such as EtherDelta were using order-book-based models that were riddled with slow and costly transactions.
Hayden Adams started working on the idea a year later bringing the abstract concept into fruition after which he received several grants from the Ethereum Foundation to further develop the platform.
At the tail end of 2018, Uniswap was launched and almost immediately started gaining traction as liquidity providers and traders flocked to the platform.
At its core, Uniswap is a unique solution for the problem of trading illiquid assets on a decentralized framework. Uniswap is a decentralized exchange that solves the lack of liquidity in trading these illiquid digital assets using automated market-making systems as opposed to traditional order books.
Compared to conventional exchange platforms, Uniswap takes on a completely different approach to achieving decentralization with a model that outsources liquidity from platform users while using a protocol to achieve price discovery.
Unlike a profit-driven exchange, Uniswap is a completely open-source crypto exchange thus not only can anyone list a token of their making for free, but they can also copy Uniswap’s code and create their version of a decentralized exchange.
As a decentralized exchange, Uniswap is non-custodial meaning the exchange itself does not provide wallets to hold a trader’s crypto assets. Also, there are no KYC and AML requirements and traders have complete control of their digital assets at all times. This eliminates the risk of lost funds due to hacks on the DeX.
Liquidity is the cornerstone of any exchange platform and therefore, Uniswap operates as an automated liquidity protocol on smart contracts that outsource liquidity from platform users and facilitate the direct exchange of digital assets.
Although Uniswap only facilitates the exchange of ERC-20 tokens, anyone can supply liquidity to one of Uniswap’s liquidity pools. Liquidity providers (LPs) are incentivized to participate through the sharing of transaction fees generated with every trade. For fairness and transparency, smart contracts govern the liquidity pools keeping track of every LP’s stake in the pool. This obviates the need for intermediaries.
Each liquidity pool requires the LP to supply an equivalent value of each underlying token. For instance, if you want to provide liquidity for the ETH/ USDT market, you will have to provide an equivalent amount of ETH and USDT. For instance, with Ether’s price at $3,000 per token, a liquidity provider will submit 5 ETH tokens as well as 15,000 USDT tokens. Providing an equivalent value for each side of the trade as seen in the example above maintains balance in the liquidity pool.
After submitting liquidity to the pool, the liquidity providers receive a third token called “liquidity pool tokens’ produced by the smart contract in the liquidity pool. These tokens represent that LP’s share of the pool and are redeemable for the tokens initially submitted to the pool.
An automated market-making protocol is an engine that runs decentralized exchanges such as Uniswap. This is a program designed to replace the market-making role of a centralized exchange.
A market maker is simply a trader who matches the buy and sell orders of an exchange’s order book thus facilitating a constant supply of liquidity for both buy and sell orders. For instance, when trader A decides to buy ETH using USDT from trader B the market maker will ensure that there is a match for the order even when trader B doesn’t agree to the price set by trader A.
Likewise, if trader B is looking to sell at a price that doesn’t match trader A’s price the market maker fills the gap by producing orders that match. The market maker acts like a middle man that enables price discovery for every possible trade thus reducing the spread between buy and sell orders. You could picture a market maker in any market as a robot that is always willing to quote a price between two assets on the buy and sell-side of the trade.
While most centralized exchanges use an order book to match counterparties to make the market, Uniswap automates this entire process using the constant product formula that leaves the trader to interact with the smart contract-based liquidity pool instead of a counterparty.
The constant product formula (x*y=k) is the basis of the algorithm in the AMM protocol that sets a price for the tokens in the pool and balances their supply of each token in the pool with each trade. It states that where token X is multiplied by token Y a constant k must be produced. This formula enables the smart contracts that run Uniswap’s liquidity pools to determine the total liquidity in the liquidity pool as well as set the price for each token in the pool.
For instance, let’s say, Alice, Bob, and Jane supplied liquidity to an ETH/USDT pool on Uniswap, the constant product formula will calculate the amount everyone is supplying and set the ratio to maintain a constant balance between the supply of ETH and USDT in the pool.
Therefore if ETH is priced at $3000 per token and Alice supplied 2 ETH with 6000 USDT, Jane provided 5ETH with 15,000 USDT and Bob supplied 1ETH with 3,000 USDT, the formula would rebalance their supplied liquidity and determine the total value of the liquidity in the pool to be $48,000 with a total of 8 ETH tokens and 24,000 USDT tokens.
Alice, Bob, and Jane would also receive liquidity pool tokens proportional to the total value of the liquidity they provided. For example, Alive would receive $12,000 worth of liquidity pool tokens (LPT) as she supplied Ethereum worth $6,000 and USDT worth $6,000.
If a few traders used up the liquidity in the ETH/USDT pool such that there was an imbalance in the supply of ETH compared to USDT, the formula would increase the price for ETH as its supply reduces. The reverse is true. In our example where ETH in the pool is perhaps reduced to 4 ETH, the amount of USDT in the pool required to balance the formula would be 48,000 USDT as opposed to the original 24,000 USDT.
Here is a graphical representation of what the formula looks like.
Now that you understand what is under the hood when it comes to Unsiwap’s AMM protocol, let’s take a look at how to swap tokens and mine liquidity on the Uniswap DeX.
Uniswap is designed with a pretty intuitive user interface that makes the entire process of swapping or exchanging tokens easy.
To swap tokens follow these steps:
Step 1: Get a Web 3.0 wallet such as MetaMask. A web 3.0 wallet is a decentralized wallet that stores your private keys on your device instead of a centralized server as is the case with digital wallets on centralized exchanges.
Step 2: Next, go to the Uniswap App and connect your wallet to the app.
Step 3: Click the drop-down menu and select the token you would like to swap. If you have ETH in your wallet and would like to swap it for USDT, select USDT in the drop-down menu.
Step 4: After clicking swap, a preview pop-up of the transaction will appear for your confirmation of the fees and possible slippage.
Step 5: Wait for the transaction to finalize after which you will be able to receive your tokens in your wallet.
Next up is a short guide on how to supply liquidity on Uniswap to earn from the trading fees generated on the platform.
Uniswap uses a dual smart contract system where there is a smart contract that governs the formula through which ERC-20 tokens are listed on the exchange as well as a smart contract that governs the exchange of tokens.
Liquidity providers who submit their tokens to the liquidity pool can exit at any time and in return, they receive a cut of the 0.03% fees charged to traders and divided among liquidity providers in the pool.
To get started as a liquidity provider, follow the following steps.
Step 1: Get some ETH in your MetaMask wallet as well as the target ERC20 token in equivalent amounts. You can also swap some of the ETH you have for a stablecoin such as Dai that you can use to buy the target ERC-20 token.
Step 2: Once you have an equal dollar value of ETH and the ERC20 token, click on the “Pool” tab on the app and select “Add Liquidity” at the top of the page as seen below.
Step 3: Next, select the number of tokens you want to submit as liquidity to the pool and the app will automatically calculate how much you will need for the corresponding token.
Step 4: Approve the transaction and you are ready to get started as a liquidity provider on Uniswap. Once the transaction is confirmed on the blockchain, you will receive liquidity provider tokens in your MetaMask wallet proportional to your share of the general liquidity pool.
Step 5: To remove liquidity for access to the accumulated rewards, go back to the “Pool tab” then select remove liquidity
Providing liquidity on Uniswap comes with its risks top of which include the risk of impermanent loss.
Due to Unswap’s constant product formula, a liquidity provider might experience a percentage loss in the price of the tokens submitted as liquidity at the point of removing their liquidity, especially if one of the token’s prices moves far away from its counterpart in the pool.
For instance, if you submit 5 ETH and 15,000 DAI tokens to a pool while the market price is set at $3000 per token, an upward price movement on ETH will not reflect on the tokens you submitted and if you end up withdrawing liquidity, your ETH will be priced low. Therefore you will receive less ETH compared to the original allocation as the Uniswap AMM protocol will balance your stake to maintain a constant.
To prevent such risks and add flexibility to the Unsiwap experience, version 3 of the platform was launched in May 2021. Uniswap Version 3 comes with a fixed price range that allows liquidity providers to set a price range with which they can provide liquidity. This acts as a stop-loss order for providing liquidity. Within a certain price range, a liquidity provider can provide liquidity beyond which liquidity is removed. This feature is called concentrated liquidity.
Therefore, a trader can adjust their liquidity mining strategies to fit a preferred price range with the lowest fees. However, while this approach amplifies the profits for liquidity providers, it also increases the chances of higher impermanent loss.
The decentralized finance industry has the potential to change how we view the world of finance.
However, despite the amazing potential, the industry is only getting started and there are a variety of bottlenecks to be solved before real progress can be achieved. As it seems, Uniswap is leading the wave of change with new updates and upgrades that make its platform better by the day.
While some argue that Uniswap is not completely decentralized given its reliance on arbitrage trading, not to mention the issue of impermanence loss, upgrades such as Uniswap Version 3 are bound to bring unprecedented improvement to the platform and the industry as a whole.