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

avatar
(Edited)

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.

01.png

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?

02.png

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



0
0
0.000
32 comments
avatar

Would it be fair to say that price isn't even applicable here?
Realistically it's just the ratio (1A = ?B)
Price on other exchanges let's us know if the ratio on uniswap presents an arbitrage opportunity.

0
0
0.000
avatar

Its a ratio yes. But its not guided from the other exchanges price. A lot of these tokens are listed on uniswap only. The sushi token was listed in uniswap only and had 200+ M marketcap. Later binance listed it.

So no need for reference price.

0
0
0.000
avatar
(Edited)

I'm trying to build up an analogy in my head. If I add equal values for A and B, and A is heading to zero; as that happens, people are going to be dumping heaps of A into the pool for less and less B.
Does that mean that assuming both tokens have the same chance of going to zero, providing liquidity doubles the chances of a contributor losing the value they put in?
If I'm holding A and B in my wallet and one of them goes bust, I still have the other; but if I'm holding them both in a uniswap smart contract and one of them goes bust, that's all I'm going to be left holding, right?

0
0
0.000
avatar
(Edited)

Yes, that is the risk. If more and more swaps happens in one direction only, you as liquidity provider will have more from the token that its been sold, and at the same time at lower price of that token.

Now with some liquidity in, as the price of the token drops more and more, it will become harder to push the price lower. At some point it will reach some bottom that will not be zero, but close to it.

Lets say for LEO :)
If there is 30k/30k liquidity pool, and a lot of people are selling leo, at some point the leo price will drop maybe under 1 cent (highly unlikely :), and you will need 100k leo (less than 1000$ worth at that price) to push the price even further. Having in mind that a lot of the leo tokens are locked for curation, or they will be in the liquidity pool, there will be maybe 100k, or 200k leo trading/swapping around.

Basically what this means is when certain token reach some liquidity (and has healthy distribution, no dev fund, funders fund with 50% share or something) his price is more or less guarantied to a certain degree. Off course nothings for sure :)

0
0
0.000
avatar

Perfect, thanks. Just what I thought. I don't believe it constitutes an existential threat to a token like LEO; and Ethereum's not going anywhere; just trying to wrap my head around it all. When you mention the price, uniswap doesn't refer directly to any other exchange; so would you say it prices A in terms of B and B in terms of A, and that's it? More a ratio than a "price".

0
0
0.000
avatar

Its an interesting thing, and if nothing else at least we are learning something.

LEO is priced in terms of ETH. Not the other way around. ETH is the base.

The interesting point here is how Uniswap takes the price of ETH in dollar terms. There must be some oracles (that how they call them) that provide trusted ETH $ price.

Having trusted oracles, (data sources to outside systems) its a business of its own. For example LINK that has exploded this year its only function is that. To provide reliable data from the outside world to the blockchain.

Whats even more amazing is that Hive/Steem has a sort of oracle of its own for the Hive price. The top 20 witnesses do this in a decentralized manner. All of the top 20 witnesses provide a price input for Hive, from the outside exchanges into the Hive blockchain, from where the blockchain calculates the debt and the issuance of the HBD.

0
0
0.000
avatar

What would uniswap use the price of ETH for exactly?

0
0
0.000
avatar

To set the price of the token. As from the example above:

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

Otherwise it will be just one unit against another, with no common denominator.

0
0
0.000
avatar

Having in mind that a lot of the leo tokens are locked for curation ...

How can it be locked for curation if you've swapped it? That would be like having the same money in the bank and the stock market at the same time. Aren't you limited to doing one or the other?

0
0
0.000
avatar
(Edited)

I'm just point out the overall supply of the token. Up until the wLEO anouncment and the incentives, 90% of the token was staked. Now the whales are unstaking and will move to liquidity providers on eth.

For sure you can not have them on both places :)

Ones they are unstaked and wrapped on eth, they are there only.
Still not everyone will move and a lot of the tokens will remain staked, constraining the supply.

0
0
0.000
avatar

Thank you for your engagement on this post, you have recieved ENGAGE tokens.

0
0
0.000
avatar

Have you studied the spread between the "real-time" price of a buy and that of a sell?

0
0
0.000
avatar

There is something call sliperage. If that is what you are refering to. You can adjust the sliperage on Uniswap if your swap affect the price a lot. You can set it to 10% even 20%

0
0
0.000
avatar

It's not exactly slippage (https://www.investopedia.com/terms/s/slippage.asp)

I'm referring to the spread.

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.

When you go to swap xyz coin, the interface gives you an estimate of how many abc coins you are going to get in exchange. Do that first on the buy side and calculate the price. Then do the opppsite on the sell side (i.e. sell abc for xyz) and calculate the price. I'll venture a guess that the difference is at least 10%, maybe more. That's the spead, and that's the real cost the customer pays (over and above any fees and commission costs that there might be).

0
0
0.000
avatar

No 10% is to much and it happens only to low liquid coins. Usualy its far less bellow 1%

Screenshot_20200911-120828_Chrome.jpg

Check the screenshot above. There is a price impact note bellow. Its less than 0.01%

10% or more can happen only in very low liquid tokens.

0
0
0.000
avatar

That's ETH-USDT. That's the platform's main trading pair. The main pair usually has a spread around 2%. (But there are 'gas' fees to take into account here.)

You need to look at a minor pair like wLeo-ETH, and you need to look at both what it would cost you to buy and what you would get if you sold, and then calculate the difference.

0
0
0.000
avatar

Uniswap will calculate it for me :)
Just as for the examole above. This is beffore you execute the swap.

0
0
0.000
avatar
  1. The example above is only a sell.

  2. You need to do a buy too (how much USDT will it take to get 1 ETH).

  3. And then calculate the difference.

As I said, the ETH-USDT major pair will have a relatively small spread. Do the same operation with the smaller pairs and I'm sure you'll find that they have much bigger spreads.

0
0
0.000
avatar

Informative and very well written. Thanks.
How would the token price impact how much you need to invest when you enter the Liquidity pool? How does the total value rebalance when you have lesser amount on one of the coins? For example on wLEO- ETH pair, if all wLEO tokens are swapped to ETH and we don't have enough wLEO, what happens then?
I don't know, if I know what I am asking here :P

Posted Using LeoFinance Beta

0
0
0.000
avatar

When you enter a pool you invest 50/50 token/eth at the curent price.

If someone is buying leo, swapping eth for leo he will push the price up. The he buys the higher the price. At some point leo will become extremly expensive, sp buying it all will be hard/stupid :). The same goes the other way.

0
0
0.000
avatar

Congratulations @dalz! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You distributed more than 36000 upvotes. Your next target is to reach 37000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @hivebuzz:

HiveBuzz supports meetups of the Hive UK Community
0
0
0.000
avatar

If all the money is coming from trade, isn't the DEX becoming rich only ? At one point, all these would collapse and by that time, they would have made nice amount ?

0
0
0.000
avatar

The money doesnt go to the DEX. There is central authority. It goes to the individual liquid providers, that can be anyone who want to provide liquidity.

0
0
0.000
avatar

I came across another posttoday, which shows it as negative. So I think, there is a very high possibility that you loose everything pretty quickly, same goes with the earnings as well ?

0
0
0.000
avatar

I'm pretty sure you're on to something here. In auction markets, the money is won on the spread. Forget about investing or trading - ups and downs don't count. Limit the analysis to the business of 'liquidity provider', or market maker as they've been traditionally called. The MM, or 'LP', makes their money off the spread. Period.

And here, everyone wants to be both market maker and customer at the same time (unless they've got a master plan for onboarding up their sleeves ... and a savve customer base to draw on). That sounds like wanting to have your cake and eat it too. 😉

Of course, the air will come out of the balloon rather quickly I would think.

0
0
0.000
avatar

That sounds like wanting to have your cake and eat it too.

At some point you will give up both and it's going to happen very quickly:)

0
0
0.000
avatar

when you swap an ERC token, they never leave your wallet.

You're saying that they never leave your wallet mgr tool, MetaMask for example, but they do change wallets, just like if I sell BTC and buy LTC, I still have control, but the wallets are different, even if I'm using Trezor, right?

0
0
0.000
avatar

Sure they change wallet, but trough a smart contract on eth ... not buy depositing them on exchanges wallet :)

0
0
0.000