Understanding Uniswap: Order Books vs. Automated Market Making

in LeoFinancelast month

There are a lot of questions surrounding wLEO, Uniswap and becoming a liquidity provider. With all of the nuances surrounding this new world of finance that we are all exploring together, I thought I would answer this common question about how Uniswap trading works with graphics and examples that explain the dynamics of liquidity providing.

This might get a little technical but I tried to keep the examples simple.

Order Books vs. Automated Market Making

The Uniswap exchange doesn't work like other exchanges. With an exchange like Hive-Engine or Binance, you're using a centralized order book to transact with other traders.

For example, if you look at the below screenshot from Hive-Engine, the highest bid order is set to buy 153.41 LEO at the price of 0.651850 LEO/HIVE. The lowest ask (the lowest price at which someone is willing to sell LEO) is set to sell 82.647 LEO at the price of 0.651868 LEO/HIVE:

image.png

On order book based exchanges, this is how traders interact with a token. They either buy/sell from the existing order book (which would be called a market order), or they set a limit order to place a specific price that the underlying asset has not yet reached.

In the LEO order book on HE, I could place a sell at 0.651867 to undercut the next available seller.. or if I'm impatient, I could sell into the bid side with a market order and fill buyers who have already placed orders at lower prices.

These are the fundamentals behind how centralized order books work. Users have the choice to either buy/sell into the existing order book or set a limit order and wait for someone else to buy/sell the asset at the price they've chosen.

Uniswap & Automated Market Makers

Uniswap, on the other hand, is not an order book based exchange. Instead, Uniswap uses something called Automated Market Making.

Automated Market Making on Uniswap works by having 2 parties involved in transactions:

  • Liquidity Providers - market makers who provide liquidity on both the sell and buy side of every transaction by owning a share in a public pool of the paired tokens
  • Swappers - people who trade the underlying assets

In the wLEO-ETH pool, liquidity providers deposit 50% of their money as ETH and 50% of their money as wLEO. In exchange, they receive a new token in their wallet called a liquidity provider (LP) token. This LP token represents their fractionalized share of the total liquidity pool.

You could think of an LP token as similar to an IOU - the pool protocol issues these IOUs which represent a redeemable coin that LP's can "cash in" to withdraw from the liquidity pool and receive their wLEO-ETH back.

Since liquidity providers are the ones facilitating trades (market making), they receive a portion of all fees accrued by the exhange (0.30% fee on each trade). The fees accrue in the shared pool and when someone withdraws, they receive their position + accrued fees during their tenure as an LP.

When a swapper interacts with a trading pair, they are instantaneously trading one currency for another.

For example, if a swapper wants to buy wLEO out of the wLEO-ETH pool, then they would take a certain amount of ETH and instantly swap it for a certain amount of wLEO based on the current price of the tokens.

The reverse holds true if they want to sell wLEO through the pool - they would send wLEO and instantly receive ETH back based on the current prices.

Calculating LP Returns and Divergence Loss

Impermanent loss is a term that is getting thrown around the DeFi space a lot. It's got some misconceptions attached to it, which is why a lot of people are starting to call it "divergence loss".

Regardless of what you decide to call it, the mechanics work the same way:

When you deposit liquidity to a pool, you are taking a specified ratio of 2 tokens and depositing it to a shared pool. When that pool is interacted with (by swappers who trade through it), the ratio of those assets fluctuate.

We did an example of this in a clip from a previous LEO roundtable podcast. I made this graphic to help explain it:

image.png

Let's reuse this example and expand upon it to show what an LP's returns would look like in this scenario:

In the above example (look at the graphic on the left side), the existing pool is 1 ETH and 3,000 wLEO. ETH is priced at $360 which means that wLEO is priced at $0.12

you get 12 cents by taking the total ETH in the pool / the total wLEO in the pool * current ETH price

Let's assume that you are an LP in the pool. Let's say that you own 50% of the total liquidity pool which means that you have deposited 0.50 ETH and 1,500 wLEO to the pool. The USD value of your position = $180 in ETH and $180 in wLEO.

Since the pool is still 1 ETH - 3,000 wLEO, your position hasn't changed yet.

But now I come to the pool and I want to buy wLEO with my ETH. Based on the current price, I have to swap 0.139 ETH into the pool in order to receive 416 wLEO in exchange.

0.139 ETH = $50 using the above prices. I swap $50 worth of ETH and receive $50 worth of wLEO at the current price = sending 0.139 ETH in exchange for 416 wLEO

Since I have now swapped my ETH for wLEO, the pool now holds more ETH and less wLEO than it did before. This has caused the ratio of assets to fluctuate which in turn changes the price of wLEO.

In terms of total USD, the value of the pool has not changed at all.

In terms of ETH, the amount of ETH tokens in the total liquidity pool has increased (since I sent ETH to the pool).

In terms of wLEO, the amount of wLEO tokens in the total LP has decreased (since I received wLEO back in exchange for my ETH).

As a 50% owner of the liquidity pool, your position is now 50% of the total pool = 0.5695 ETH and 1,292 wLEO. Your value breakdowns:

  • in USD, the value of your position = $205 worth of ETH | $205 worth of wLEO
  • in token terms, you have less wLEO and more ETH (since you have effectively sold your wLEO to me in exchange for ETH)

Why Did the Value of Your Holdings Increase Drastically?

The value of your holdings increased because of major price slippage. In a pool that only has 1 ETH - 3000 wLEO at the prices laid out above, a $50 transaction is an enormous one proportional to the liquidity available.

This means that I paid a hefty premium for the wLEO I just bought from the pool and in turn, I caused the value of wLEO to increase drastically. The value of your holdings went up because of the premium that I paid to the pool for the wLEO token.

The inverse is also true:

If you were to take the opposite of the example I just gave (where I would come in with $50 worth of wLEO and sell it to the pool in exchange for ETH), then you would see a drastic shift in the pool dynamics which causes the value of wLEO to dip significantly.

Oversimplification

Obviously, this example is overly simplified. The numbers aren't quite so static and there are other factors at play - i.e. a fluctuating ETH price, multiple LP's coming and going, etc.

The key takeaway you should have from this is that pool dynamics govern the returns you receive. Depending on how you value your position, you may or may not "lose" as a liquidity provider.

If, for example, you deposit wLEO and ETH to the pool to become an LP and the price of ETH moons and wLEO doesn't, then your LP position would start to hold more and more wLEO and less and less ETH.

The USD value hasn't necessarily changed, but the amount of ETH and wLEO you hold has.

The reverse is true as well: if wLEO outperforms ETH, then you as a liquidity provider would hold less and less wLEO as the price skyrockets and you would hold more and more ETH. You'd essentially be selling out of your wLEO position on the way up as the price increases.

This is where the term "impermanent" or "divergence" loss comes from. If you see losses as a liquidity provider - in terms of one token mooning against the other and causing pool imbalances - then your losses might reverse if the prices find their way back to equilibrium.


This was kind of a brain dump, but I hope the concepts are a bit clearer after reading that. I wrote this post by stitching together DM's / comment conversations I've had over the last few days about liquidity pools and then rewrote a lot of the examples.

 
steemleo black token divider.png
 

Join Our Hive Community & Earn LEO Rewards!

Earn LEO + HIVE rewards by creating crypto/finance-related content in our PeakD community or directly from our hive-based interface at leofinance.io or LeoFinance Beta

Track Hive DataNew Interface!About Us
HivestatsLeoFinance BetaLearn More
Trade Hive TokensLearn & ContributeHive Witness
LeoDexLeoPediaVote

Follow @leofinance for official updates

Posted Using LeoFinance Beta

Sort:  

I'm asking for the third time:

There are a couple of leo tokens circulating out there. What's your plan to deal with this? People will be confused.

Hive LEO's logo is much cooler?

Posted Using LeoFinance

Such cool developments on a fantastic project. If you went into more technical detail, you may have lost me but it was a nice primer.

Are you learning this as you go with advisors or do you have that deep a technical background?

Cool stuff man!

Nice summary. I thought I understood it. I jumped into the Uniswap bandwagon and realized there are nuances you will understand once you are in the system. It is a good primer/knowledge product for all the beginners.

Posted Using LeoFinance Beta

It gets me to ask more questions
but I am finding the answers as well.
Like the reason the LP needs to be a fair amount so
everything stays balance at all time.

Posted Using LeoFinance

Hmm, sometimes, this long posts of yours end up confusing non-technical traders like myself. You could start up a LeoSchool on LeoPedia on wLEO and Uniswap. Make it simple and just one item per time. Give some simple exercises as well. I would even love to pay LEO to enroll in such school and I think there are others as well. I hope that would be a new usecase for LeoFinance/Leopedia.

Posted Using LeoFinance

hello bros I got muted on @leofinance [ noleo4u ignored ] need help please unmute me
I cant post or comment on leofinance

Would love to see something like this soon on Brave!

Posted Using LeoFinance

can anyone help me out and tell me why i cant claim the rewards in my wallet? I click the tab to claim them as i do on hive and steem but the website just does not update my balance. click page refresh and again just doesnt add to my balance. Tried a different browser and just same.

Posted Using LeoFinance

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

You made more than 4000 comments. Your next target is to reach 4500 comments.

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:

Update for regular authors