Day 11 (12 Days of Dune): The volatility of liquidity (k) and prices, compared.
Now that we know price impact depends on the x*y=k formula, let's understand the volatility of it.
We’ll be answering questions and covering more beginner-focused concepts during office hours at 2pm EST, so join us in the #12-days-of-dune discord channel. You’ll need to earn the course NFT and connect to the Dune guild.
Web3 Data Degens is a reader-supported publication. Posts are free, but I greatly appreciate your paid support as well :)
Welcome to day 11!
Just one more day left! You can find the full explanation below (premiering with a live watch party at 9 am EST today).
Here are the main concepts:
Swap price naturally affects liquidity (reserves) of the pool. If the pool starts out at 1000 token A and 100 token B then we have a swap rate of 100/1000 (0.1 token B per 1 token A) and a liquidity k of 100,000 (1000*100). If everyone keeps buying token B using token A, then the price will start drastically changing (hitting the steeper part of the pricing curve). Liquidity will also start drastically decreasing - say we now have 1050 token A and 50 token B, that means swap rate is now 0.047 token B for 1 token A and the liquidity is 52,500. Price and liquidity both changed by roughly 50%.
If you’re more of a visual learner, check out Dan Robinson’s desmos charts where you can drag around variables more easily.
So, given this - if the standard deviation of k (in percentage terms) is many magnitudes higher than the standard deviation of price, then there is likely some additional liquidity “instability” from reserves being added or removed since that would change k but not the price. Otherwise, they should be maintaining a relationship of close to 1:1. We define this as “magnitude” in our query.
The calculations for this require us to take average daily swap prices and end of day reserves, and then forward fill them for days without any changes (using
COALESCE() ignore nulls). There’s a lot of SQL magic that is taught today, so take it slow!
Altogether, we found the below results over a 20 month period. The query is on Dune here.
Remember, if you found this question hard make sure to come to our office hours (2 PM EST) in our discord! Details are at the top of the email.
Tomorrow, we’ll be covering the question:
Can you cluster and compare USDC pairs by some combination of variables by bringing together two or more of the stability concepts we’ve learned this week?
As always, feel free to reach out to me here or on Twitter with any questions you might have.