Posts

An Example How Uniswap Calculate The Price Of The Tokens and What Happens When A Swap Is Made

avatar of @dalz
25
@dalz
·
·
0 views
·
5 min read

For those who don’t know Uniswap is a Decentralized Exchange (DEX) on the Ethereum blockchain. Unlike the CEX (centralized exchange) DEX’s are decentralized and this means that anyone can list any token out there

Up until Uniswap the DEX’s greatest weakness was liquidity. Also, complexity and user interface. Then Uniswap enter the game and changes everything.

source

The revolutionary concept here are the liquidity providers or LPs in short. Revolutionary might be a hard word but what is happening now with DEX’s is really a big leap. Another pro is that on DEX’s like Uniswap, when you swap an ERC token, they never leave your wallet. On CEX’s you literally gave away your funds and put trust in them not to steal them away, or get hacked.

How Does Uniswap Determine The Price Of a Token

Let’s go through this with an example.

A new token is created and will be listed on Uniswap. The token creator, (individual, company or a group of people) want to list the token on Uniswap. Since Uniswap is an ETH DEX, only ETH tokens can be traded there. Technically when an ETH token is created after that there is no limits to list it on the exchange.

But for the token to be consider relevant there needs to be liquidity for that token. What this means is when someone wants to buy or sell the token, especially larger amounts, they should be able to do this without impacting the price to much. If you take a look at the Hive Engine tokens and their order books, selling and buying larger amounts of tokens ($1000) on Hive Engine will drastically impact the price.

Uniswap as the name suggest is a swap platform.
Similar to blocktrades exchange. There are no buy or sell orders. You can't put orders on Uniswap as well, just swap token in the moment.
So, how is the price set?

Here is the example.

Token A is listed on Uniswap. The next step is to add liquidity, so you can have to whom to sell or buy from.
Like If you go in a market that buy and sell tomatoes. You enter and ask for tomatoes, but they say, oh it’s just a statement that we have tomatoes. We don’t have them in stock actually. Or if you want to sell tomatoes, they need to have money to buy them from you.
That’s what liquidities does. It provides tomatoes on one side (the token) and money on the other side (ETH), so people can enter in the store and buy or sell tomatoes.

What this means is basically there needs to be some capital locked for trades to happen. For this capital to be locked there need to be some incentives. As the interest in the bank. Here the incentive comes from the fees that are generated from trades that are going directly to the liquidity providers. Not the centralized exchange, but the ones that are providing liquidity.

Liquidity is added by depositing (pooling) some amount of the token and ETH. Basically, the token is balanced against ETH. You need both of the currencies to provide liquidity, the token and ETH.

Running some numbers.

100k of token A is added in the liquidity pool and 100 ETH at the same time.

The balance equation is as follows:

100 ETH ETH Price = 100k TokenA Token Price

100 ETH at $350 is 35k USD, meaning the value of the tokens on the other side is also 35k USD. Since there are 100k tokens, the price will equal 35000/100000 = $0.35

The equation for the the token price, is this:

TokenPrice = (100 ETH ETH Price) / 100k TokenA = 0.35**

From here you can change the values and basically get the price of any token, depending on these few parameters.

This is a totally different way of price discovery than the standard buys and sell orders. Here the price is determined by the liquidity pools, the value of the ETH and the number of tokens.

What happens when a trade/swap is made?

From the example above we have $35K on both sides of the equation. A total of $70K liquidity. 100 ETH and 100k TokenA.

Next let’s say someone want to swap 10k TokenA for ETH. What this means is that the amounts of ETH and TokenA in the liquidity pool will rebalance.

A 10k swap from TokenA to ETH will result in 110k TokenA and 90 ETH in the pools. If we enter these values in the equesion above now we will get this:

*TokenPrice = (90 ETH ETH Price) / 110k TokenA = 0.286

The swapping of 10k tokens (10% of the liquidity) for eth resulted in drop in the price for the token from 0.35 to 0.286, or almost a 20% drop.

Swapping 10% of the liquidity is considered a large chunk. But for low liquid coins this can happens easily. That’s why a large liquid pool is great to have so swapping large amounts of tokens wont impact the price as much.

In the example above we were swapping tokenA for ETH, and the price of the token went down. I someone is swapping ETH for TokenA then to oposit will happen and the price will go up.

How much do liquidity providers earn?

From what I found, on Uniswap, LP earns 0.3% of all the transactions as fees. The fees are distributed in both of the tokens. This is a fee that the protocol takes and gives it to the LPs. Gas fees are on top of this. You can make the calculation from the screenshot above as well.

The ETH – USDT pair has around 25.5M liquidity atm. There has been around 70M volume traded in the last 24h, that have generated 209k USD in fees. You can go out and calculate APR from these numbers: 209k*365=76M/25.5M = 300% 😊.

Note that this is only from one day numbers. Today was not a standard day, as there has been a huge move in liquidity from Uniswap to Sushi, generating a lot of volume.

In the last days the APR for the ETH-USDT pairs was 30% to 40%, so you can see things can change a lot on a daily basis.

Since liquidity is the name of the game, what we are now seeing that is happening is LPs incentives. A lot of tokens offer incentives for the liquidity providers. This has led to sort of farming from LPs, since they go where the incentive is. Sometimes with a bad outcome 😊.

The worst case scenario for a liquidity provider is to end up holding a worthless token. They are starting with a 50%/50% value in the pool, but if a lot of swapping is happening in one direction, their ETH will be swapped for the other token, and if that token loose value then their capital will be lost.


The above is just a simple showcase how this new concept work. There are now new and emerging platforms, like balancer, rune etc, that offer even more sophisticated ways of managing the liquidity pools.

DeFi has become a buzz word and can be a lot of things. The first thing that was offered, the capability to mint stable coins via collateral was not very impressive for me personally. It was a self-borrowing so to speak.

The concept of liquidity providers, LPs, with combination of DEX is a much better thing in my eyes. It opens a totally new world of possibilities. It’s totally different concept for price discovery and sort of revolutionary. Also it enable everyone to be a liquidity provider, boosting a whole ecosystem.

All the best @dalz

Posted Using LeoFinance Beta