Uniswap
Introduction
Uniswap is a decentralized exchange protocol built on the Ethereum network. Uniswap enables you to do the following things:
- Swap tokens (ERC20/ETH OR ERC20/ERC20)
- Earn fees by adding liquidity
- Remove liquidity from pools
In a nutshell, Uniswap is a peer-to-peer marketplace for token trading!
** Note: This tutorial assumes you have already installed Metamask, if not follow our tutorial on how to install Metamask before proceeding.
How To Use Uniswap
First Step Connect your Metamask to Uniswap.org
Step 1: Go to Uniswap.org
Step 2: Press Connect to a wallet
Step 3: Choose Metamask option
Step 4: Approve necessary permission for Uniswap and connect to Uniswap. (We will explain what this “approve” function actually does in later, more in-depth articles regarding Uniwap)
Step 5: Connect wallet to Uniswap
ֿHow To — Swap Tokens
Step 1: Go to Uniswap.org.
Step 2: Press Launch app
Step 3: Press Swap
Step 4: Choose swapping direction ERC20 -> ETH or ETH -> ERC20 and amount to be swapped. and Press Swap
In this example, I have choose to swap my ETH to DAI token (Buy DAI)
Step 5: Confirm swap
Step 6: Confirm transaction on Metamask
After the transaction is finished you will see the token in your Metamask wallet
Understanding Uniswap mechanism
Liquidity provider
What does it mean to be a liquidity provider?
Whenever an investment is bought or sold, there must be someone on the other end of the transaction. If you want to buy 100 shares of Google, for example, you must find someone who wants to sell 100 shares of Google. However, in the crypto world, especially when dealing with random ERC-20 tokens, it’s unlikely that you will immediately find someone who wants to sell the amount of tokens you want to buy. This is where market makers come in. Market makers, or liquidity providers, are always ready to buy or sell at the market price.
Who can be a liquidity provider?
Liquidity providers can be anyone who is able to supply equal values of ETH and an ERC-20 token to a Uniswap exchange contract. Liquidity provider is the one who “holds” all the tokens and is ready for selling/buying tokens immediately.
How Uniswap calculate token’s price?
Lets say 100 token is being added to the pool and 100ETH is added to the pool.
100 Tokens = 100 ETH
1Token = 1ETH
The equation for the the token price, is this:
Token Price = (Number of ETH in the pool)/(Number of tokens in the pool)
What happens when Swapping is made?
Lets say someone want to swap 10ETH for 10 Tokens(1Token = 1ETH), this transaction increases the amount of ETH in the pool and decreasing the amout of Tokens in the pool. Now our pool have 110ETH and 90 Tokens. If we enter these values to the equation above we will get that the new price per one token is:
Token Price = 110/90 = 1.22ETH, instead of the previous price of 1 Token = 1 ETH, which means the price went up by 20%, after purchasing only 10% from the pool!
Uniswap’s pricing model follows the x*y = k model, which guarantees that as long as there are some tokens in the pool, transactions can occur, but with increasingly higher prices. The following graph shows the ratio between ETH and the token in the pool: