DeFi: What Is Uniswap And How Does It Work?

Uniswap is a decentralized exchange (DEX) built on Ethereum smart contracts. The product is simple. It enables the exchange of ERC-20 coins against ETH or other ERC-20 coins while keeping full custody of the assets, i.e. custody of the assets is not given to a centralized third party. The only thing that needs to be trusted is the security of the smart contracts themselves.

Behind the project is Ethereum developer Hayden Adams. The second version of the decentralized exchange, known as Uniswap V2, was launched in May 2020, carrying certain improvements to the original protocol.

Uniswap V1

Swap

The first version of the protocol was announced and launched in November 2018 at Devcon 4. It already had the most important functions. Under the Swap function, it is possible to trade ERC-20 tokens for other ERC-20 tokens or ETH.

Send

The Send function is similar to Swap, but has the option of sending the tokens to an address of choice. The exchanged token are sent to the chosen address, not to the original address from where the traded tokens came. This function works best for chain transactions, e.g. flash loans.

Pool

The Pool function allows users to add liquidity to trading pair pools. This requires holding both tokens of the trading pair at a ratio equal to that of the price ratio. For example, we assume the ETH/DAI pair, with a price of 1 ETH=240 DAI. The required ratio of ETH/DAI will be 1/240. The necessary ratio is shown in the entry field when accessing the pool function. The exception is when someone is the first person to add liquidity to the pool, in which case they get to set the ratio and the trading price themselves (See below).

When adding liquidity to a pool, we obtain so called Pool-tokens. The exchange fees are also added to the pool. This increases the value of the Pool-token over time as fees are added to the pool, so when retrieving the tokens back from the pool, the end amount will be higher than the one originally added to the pool. The platform profits from this incentive, because it brings more liquidity to the pools, which means faster transactions and lower slippage. The slippage is a measure of how much the exchange price changes with respect to the traded volume.

How is the price determined?

Determining the price is fairly simple. The price is a reflection of the ratio if coins in the pool. To keep it with our ETH/DAI example, the price of ETH against DAI is obtained by dividing the total amount DAI by the total amount of ETH in the pool. This is why it is a must to keep the same ratio when adding liquidity to the pool, in order not to affect the price.

The slippage issue can best be shown with the following example. Let’s say the DAI-ETH pool has a total of 5 ETH coins at a price of 240 DAI each, then the pool has 1200 DAI in total. Now let’s say someone exchanges 3 ETH for DAI, this will increase the total amount of ETH in the pool to 8, and reduce the total amount of 1200 DAI by 720, so we’re left with 480 DAI. The ETH/DAI price will now become 480/8=60 DAI per ETH. If we repeat the same example but with 1000 ETH and 240,000 DAI in the original pool instead, the ETH price would’ve only “slipped” down to 238,56 Dai. Therefore the more liquidity, the lower the slippage.

How does the price adjust?

The price adjusts through arbitrage. In our example above the price of ETH dropped to 60 DAI. But on the market, ETH would still cost about 240 DAI. Traders would then use this opportunity to snatch up some cheap ETH tokens on Uniswap. This would make the price of ETH rise again and adjust to the global average.

Uniswap V2

As already mentioned, Uniswap V2 was introduced in May 2020. Uniswap V1 still runs in parallel. Uniswap V2 brought with it some improvements. The new protocol also supports wrapped ETH tokens. Wrapped ETH tokens are ERC-20 tokens that represent the value of 1 ETH each. This makes it possible to pool ETH with any possible ERC-20 coin. Uniswap V1 only supported pooling native ETH with ERC-20 tokens. This required the creation of a separate smart contract for every single trading pair.

Uniswap exchange rates were often used as price feeds for many other smart contracts, i.e. oracles. Uniswap V2 introduced an optimized oracle function, that makes manipulations more difficult. In the past, hacks were made possible by manipulating Uniswap V1 oracles.

Flash Swaps, just like flash loans, make it possible to borrow as many ERC-20 tokens as wanted, as long as they are returned in the same transaction. The fees go to the liquidity providers of individual pools.

There’s also other performance improvements on a technical level, that are of less interest to the user. They can be found in the official description if wanted.

Uniswap doesn’t maintain any business model with the platform. All fees go to the liquidity pools. There exists the possibility to reserve 0.05% of the trading volume to the protocol development, but it is completely optional.

Uniswap User Interface (UI)

Uniswap is easy to use. There are many ways to call the smart contract, among which are Metamask and Coinbase wallet.

A pre-determined choice of tokens can be found in a drop down list. If the wanted coin can’t be found in the drop down, then all we must do is paste the coin’s contract address into the field. The interface is standardized, and any ERC-20 token can be added.

Uniswap input form for coin exchange DEX
Uniswap exchange input form

In the picture above, we are attempting to exchange 1.5 ETH for LINK. At the price at the time of writing (07/14/2020), we get 44.111 LINK (0.0340051 ETH/LINK or 29.407 LINK/ETH). In the red square field, we can optionally input the receiver’s address. Unlessthe receiver’s address is stated differently, the LINK would go by default to the address that held the ETH. Minimum Received indicates how many LINK we will at least get. Due to slippage the end price will be 0.04% lower, which will affect the end amount received. 0.0045 Ether (0.3 %) go back to the liquidity pools as fees.

Uniswap Decentralized exchange (DEX) settings
Uniswap settings

In the settings we can choose the maximum slippage that we tolerate. In the picture above we selected 0.5%. For our example above, this means that the price can drop down to 0.0338350745 ETH/LINK in the worst case, otherwise the trade isn’t executed. The Transaction Deadline is a practical tool. Should the transaction take longer to be confirmed, it is nullified. This can be very helpful in volatile markets.

Uniswap also offers an extensive display of statistics which can be found in the menu. The stats show the liquidity of trading pairs, trading volume, transactions, etc…

Uniswap decentralized exchange statistics
Uniswap statisics 07/14/2020

The statistic clearly shows the steady increase in the value of coins locked in liquidity pools. The daily trading volume of $30 Million can be compared with that many centralized exchanges (CEX).

Warning: Recently, Uniswap was used by scammers on multiple occasions. Falsified token contracts were created, that mimic serious real projects. Always make sure you’re trading the correct pair.

Want more crypto news and price analyses? Join CryptoTicker on Telegram and Twitter

scroll to top