How does Uniswap work?

0
58
Uniswap is an Ethereum based exchange that allows anyone to swap ERC20 tokens. Traditionally, token swaps require buyers and sellers to create liquidity. Uniswap creates markets automatically.

One of the most popular trends in the crypto industry, which replaced the era of ICO, is DeFi — projects and protocols for decentralized finance. The basis of DeFi — a decentralized opportunity for exchange, investment and lending, freely in practice and absolutely democratic in structure, with full control of funds, which are trusted not to specific individuals, but smart contracts and algorithms.

DeFi token yearn.finance (YFI) in just a month increased in price from $34 to $38 869 dollars. Chainlink jumped from $4.12 to a peak of $19.8 in two months. What do these coins have in common? All of them are trading on the decentralized platform Uniswap.

Interestingly, the development of Uniswap was facilitated by Vitalik Buterin’s idea for a decentralized exchange (DEX), which would involve an automated market maker. Actually, the protocol developer himself, Hayden Adams, at first tried to just practice development on Solidity, and later this hobby brought him several grants and $100 000 from the Ethereum Foundation.

Now the project went far beyond just entertainment and became one of the most important components of the entire DeFi industry.

The surge of DEX popularity

The trend of decentralized financing protocols has returned users to the use of decentralized exchanges. On Friday night, Dune Analytics statistics showed that DEX platforms continued to grow in volume with a seven-day increase of 178%. Global volume on decentralized platforms exceeded $7.1 billion in the last week and $968 million in the last 24 hours.

Uniswap protocol is the most widely used DEX trading platform today. Uniswap eclipses the majority of its rivals with 71.9% of the total volume of DEX trading. Since this platform is the most liquid one to date, we are talking about it.

What is the difference between DEX and CEX?

In fact, Uniswap is an Ethereum exchange, built using smart contracts and liquidity pools, as opposed to the order book of a traditional centralized exchange (CEX), such as Binance. With any Ethereum wallet, users can simply connect to the Uniswap application and effortlessly exchange ERC20 tokens without first sending them to the exchange platform account.

Previously, DEX platforms had liquidity problems, but the Uniswap liquidity pool model changed the rules of the game. The application allows users not only to exchange coins, but they can also create an ERC20 pool of any type or provide an existing pool with liquidity and earn money. Uniswap allows anyone and anywhere to exchange coins without authorization or identity verification process.

ERC20 tokens and Uniswap

ERC20 tokens, based on Ethereum, are the most popular and interchangeable tokens, which means that there is no difference between the same tokens of this standard.

ERC20 can be considered as the simplest unit of account for a variety of uses, including currency, bonus points, credit, interest-bearing bonds and much more. They support virtually unlimited division and can be sent in fractional pieces. Since tokens of this type are very popular, it is important to develop a simple way to exchange between them.

Smart contracts in Uniswap

With a set of smart contracts Uniswap standardizes the exchange mechanism for ERC20 tokens. Anyone can create an interface that connects to these contracts and immediately exchange tokens with everyone who uses Uniswap.

There are two different types of contracts that make up Uniswap. The first is known as the Exchange contract. Exchange contracts contain a pool of specific token and Ethereum, with which users can exchange. The second type of contract is Factory, responsible for creating new exchange contracts and binding the address of the ERC20 token to its personal exchange contract.

There are no fees for listing a new trading instrument in Uniswap. Anyone can call a function in the Factory contract to register a new token. The figure below shows an example of adding a DAI to Uniswap. Someone first called the createExchange function in a Factory contract with the DAI contract address. The Factory then checks the registry to see if the Exchange contract for this token was previously created. If this is not already the case, Factory creates an Exchange contract and writes its address to the registry.

Liquidity pools

Uniswap does not use the order book to estimate the asset value. In traditional crypto exchanges, like Coinbase Pro, a price is based on supply and demand, where the highest price is the one for which someone is willing to buy, and the lowest price is the one for which someone is willing to sell. In the image below, we see that the highest BTC bid price on Coinbase Pro is $9301.36, and the lowest bid price was $9301.37.

Instead, Uniswap uses Exchange contracts to pool both ETH and a specific token into one pool. When exchanging ETH for a token, ETH is sent to the contract pool and the token is returned to the user. As a result, the trader does not have to wait for a counterparty to exchange or worry about specifying a price. Since anyone can list a token, and users don’t need to think about matching a token to anyone, we easily avoid the problem of providing initial liquidity.

The amount that is returned after the exchange is based on an automatic market maker formula. The chart below helps to illustrate how this formula works. Essentially, the amount returned to you depends on the ratio of ETH to token in the pool. Regardless of the amount, the user is guaranteed to complete his transaction, because the more asset you add to one side of the pool, the further along the curve he moves you to another asset. This means that the bigger the bid relative to the pool, the smaller the bid you will get.

But if users only send a cryptocurrency, how is the correct token price maintained? The answer is that pools maintain a price balance with external markets through traders who arbitrate between pools. Imagine that DAI: ETH pools are expressed as weights and when they are balanced, the pool is appropriately valued relative to the market price of a centralized exchange. Suppose the current dollar price of ETH on a centralized exchange is $150, and the ratio in the Uniswap DAI: ETH pool returns 150 DAI for 1 ETH. As a result, we are balanced because the pool corresponds to the current market price on a centralized exchange.

Now let’s assume that there is a movement in the market that pushes the ETH price to $100 on the centralized exchange. Because of the price movement, we can now see that we are out of balance relative to the market price, because now people can trade 1 ETH for 150 DAI using Uniswap, while the market price on the centralized exchange is 100 dollars per 1 ETH.

In response, someone can now put the ETH in a pool, withdraw the DAI, then sell the DAI for the ETH on the centralized exchange for profit, and then repeat the transaction. They can do this until the pool aligns and reflects the current market price.

As a result, third-party arbitrations play a major role in maintaining the correct token-to-air ratio in Uniswap pools.

Pros and Cons of Uniswap

The exchange has a couple of key benefits:

  • No need for KYC. Uniswap users do not need to prove their identity. No matter how huge the trading volume or activity on the platform is, there will be no need to show your ID. The system operates on the basis of smart contracts and without any supervisory authorities on top;
  • No registration. You don’t need to create an account, use your e-mail and password either, because there are simply no accounts or personal accounts on Uniswap. You will only need to enter a password from your MetaMask wallet;
  • Almost instant execution of swaps. Uniswap users do not wait for orders to be executed as it happens on the centralized exchanges. Instead, they exchange tokens, and the speed of the process depends on the amount of fee;
  • Wide range of tokens. As we have already mentioned, you can list any token on Uniswap. Usually, coins appear there noticeably earlier than on major exchanges, and this is an opportunity to get profit;
  • Simple interface. It’s very easy to understand and it takes only a few clicks to make a transaction. If you already have MetaMask or experience with other online wallets, there will certainly be no problems with Uniswap.

But Uniswap is still far from perfect — it also has its cons:

  • Swaps can sometimes be too expensive. Token exchange process works through smart contracts, which spend much more gas than usual transfers. So if now you have to pay 1–2 dollars for an ordinary ETH transaction, in the case of Uniswap you should set up to give 4–5 dollars and more for an operation. If Ethereum network turns out to be busy, prepare to give away tens of dollars;
  • Investing requires a serious strategy. Given the high commission for swaps, you’ll have to think carefully about the tokens and funds you plan to invest in them;
  • Scammers. The free listing is actively abused by scammers who create coins with a similar ticker and hope that inattentive users will buy a useless fork instead of the original;
  • The platform is not suitable for large trades. The larger the purchase amount, the more the so-called premium is accrued on it.

Uniswap is a new step in the development of cryptocurrency exchanges. The platform operates in a decentralized manner while performing its tasks perfectly. Its user base against the background of the boom in popularity of the DeFi sphere in August has grown at least twice compared to the previous month, and the indicator clearly does not plan to stop.

The exchange performs its duties perfectly and works without failures. Yes, it is seriously spending resources of the Ethereum network, but these are costs of the current market situation. So, as a result, Uniswap deserves praise and recommendations for its use. To make more good deals on Uniswap you need more Ethereum. Where can you get it? At Ethex.bet, our fair crypto lotto, which rewards everyone who can guess the symbols of the next Ethereum block hash!

Also, Read

Get Best Software Deals Directly In Your Inbox

How does Uniswap work? was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.