How to Calculate the Price of Trade on Uniswap: AMM Math Explained
HTML-код
- Опубликовано: 7 сен 2024
- In this video, I go into detail on an example of AMM and Uniswap, so that you can make sound decisions when dealing with AMM.
1) How is the invariant calculated?
2) Using example of $LISA (does not exist!) and $ETH
3) How the formula works when a trade happens? E.g. someone buys $LISA using $ETH
4) How to calculate the trade (without fees)
5) What happens to the tokens inside the liquidity pool after the trade happens?
6) How does that affect the invariant? (Before and after trade, using numbers)
7) The price change in each trade. How and why? Explaining with numbers.
Want more in-depth content? Join our patreon for premium content at www.patreon.com/economicsdesign
🔥 Listen on Podcast: bit.ly/ED-podcast
📚 TLDR on Substack: economicsdesig...
👉🏻 Nerd out on www.economicsd...
😎 Level up with #TokenEconomics course: education.econ...
Disclaimer
This is not financial advice. Information shared is found publicly on the internet. All analysis and opinions are my own. The purpose of sharing the information is for education and knowledge sharing. The information shared is accurate at the time of recording. Purchasing cryptocurrencies poses a considerable risk of loss. Past performance does not indicate future results.
#economicsdesign #tokeneconomics #tokenomics #DeFi #uniswap #amm #dex #defimath #casestudy #bondingcurve #invariant #defitrade #math
Thank you, hard to find content like this 🙏🙏🙏 i recently became very curious about the math behind deFi.
Thank you very much. You are extremely smart and it is very nice of you to share your knowledge. Good luck in all your endeavors!
Thank you very much!
Hello from France, I'm an ethereum developper and this is really good breaking down!
Hello to France! Glad you find it helpful!!
@@EconomicsDesign haha yes, but why 500 - 454.5 would equal 455 Lisa ?
Do you think you could expand this a little bit to show how fees would accrue to the pool if a fee was charged on trades? How would this change the constant K? Or maybe point me in the direction of some reading material?
Hello:) I don't understand why the constant changes on the second example. It is set to 5000 why does it become 4999.5 ?
Exactly what I was thinking
Constant is token A x token B. So, 11x454.5 = 4999.5
Outstanding explanation. Thanks Lisa.
You are so welcome!
I just subscribed to your channel. This is GOLD 🧠
Welcome aboard! -Lisa
Subscribed. I really like the content you put out.
Hello thanks a lot for the explanation, hello from France Paris :)
Hello!
great explanation !!
very good! Thank you for the help! Keep up the good work!
Cheers mate
You're the best, thanks
Hello! Thank you a lot for your video! Can you please explain why the there's 4999.5 instead of 5000? Is it just an example of how constant can be changed during other trades in the system and this 0.5 difference is just an assumption or it is has mathematical explanation that I didn't get ?
Hi! It's actually 5000. I used 2 sig fig in the previous calculations, hence there is a small difference. In reality with machines calculating, it's 5000!
Pp
Thanks
Hey i can please tell how to calculate no. Of trades?
At 6:56 you say "during this trade there are other trades happening within the ecosystem". I understand how a trade before another trade changes the exchange price but I do not understand how the price can change during a trade. Or are you referring to another trade coming in after your trade and being prioritised thus changing the price aka transaction order is changed in mempool.
If i have a value of 1 milion $ in saitama or shiba inu and now i want to swap all of it to ETH on the uniswap platform What will the the gas fee that i would have to play for this conversion ?
Great channel
thank you
I think there is another fee or algorithm except 0.3% swap fee nowadays. Now Swap fee is like 0.82% on V2. is there any formula?
Fees are determined by Uniswap governance. UNI token holders are part of a DAO and vote/stake their tokens for or against proposals, which would be required for a fee increase/decrease. No formula, arbitrarily decided by DAO
so if the swap fee in the very first example of 0.3 percent was included, does the pool constant K increase due to the fee? Thanks
Yes, but it depends on how the protocol integrates the swap fees! It might be changing K. or might go to treasury directly!
Oh my thank you so much for this! I learn better like this than uniswap's whitepapers lol
Glad that it helps you!
super
Thank you! -lisa
Does anybody know where "price impact" come from though? By the way although it's called "price slippage", I'm assuming the Lisa token value actually went up since you're getting less per ETH. So it's designed to keep both tokens in the pool at all times by raising the price of the Lisa token that's in demand, right?
It is the price within the protocol (in the AMM) vs outside. Think price within Uniswap vs Binance/Coinbase/Sushiswap
@@EconomicsDesign how does someone get to trade for the price within the protocol? Seems when I go to a dex, that kind of outside world price fees on top of it. How to get the inside protocol price? Thanks for your reply. That matches what I'm seeing
I think you are calculating incorrectly the value of how many LISA tokens you can get. Because the trade is described as:
(ReservesETH + NumberOfETH) * (ReservesOfLISA - NumberOfLISATokens) = K , where K = ReservesOfEth * ReservesOfLISA, that is 5000. Which is also the way Uniswap has coded that.
so the final formula would be
NumberOfLISATokens = (NumberOfETH * ReservesOfLISA) / (ReservesETH + NumberOfETH)
@@iampanzergrenadier Yes you are right that
(Total number of ETH) * (Total number of LISA) = K
Expanding the formula, you get:
Total LISA = K/(Total ETH)
Change in LISA = Old total number of LISA - (K / (Total number of ETH)
Total number = reserve + change in number.
@@iampanzergrenadier you're wrong on your math, she did it right
I fell in love with this girl she's so pretty
and intelligent
If i have a value of 1 milion $ in saitama or shiba inu and now i want to swap all of it to ETH on the uniswap platform What will the the gas fee that i would have to play for this conversion ?
It depends on the price then. Check www.gasnow.org/