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

Комментарии • 51

  • @s2kcolin780
    @s2kcolin780 10 месяцев назад +1

    Thank you, hard to find content like this 🙏🙏🙏 i recently became very curious about the math behind deFi.

  • @andrzejkroszczynski8376
    @andrzejkroszczynski8376 3 года назад +5

    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!

  • @DistantVirtue
    @DistantVirtue 3 года назад

    Hello from France, I'm an ethereum developper and this is really good breaking down!

    • @EconomicsDesign
      @EconomicsDesign  3 года назад

      Hello to France! Glad you find it helpful!!

    • @eaglebaxter4951
      @eaglebaxter4951 2 года назад

      @@EconomicsDesign haha yes, but why 500 - 454.5 would equal 455 Lisa ?

  • @monodactyl3975
    @monodactyl3975 2 года назад +2

    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?

  • @arturo3511
    @arturo3511 3 года назад +6

    Hello:) I don't understand why the constant changes on the second example. It is set to 5000 why does it become 4999.5 ?

  • @knowledgelover2736
    @knowledgelover2736 3 года назад

    Outstanding explanation. Thanks Lisa.

  • @blackswanjh
    @blackswanjh 2 года назад

    I just subscribed to your channel. This is GOLD 🧠

  • @networkfreddy2000
    @networkfreddy2000 2 года назад

    Subscribed. I really like the content you put out.

  • @croissanceturque
    @croissanceturque 3 года назад

    Hello thanks a lot for the explanation, hello from France Paris :)

  • @mohitverma6291
    @mohitverma6291 Год назад

    great explanation !!

  • @forrestt2287
    @forrestt2287 3 года назад +1

    very good! Thank you for the help! Keep up the good work!

  • @sergey-investing
    @sergey-investing Год назад

    You're the best, thanks

  • @anyusheva
    @anyusheva 3 года назад +4

    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 ?

    • @EconomicsDesign
      @EconomicsDesign  3 года назад +1

      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!

    • @riffraffollie3602
      @riffraffollie3602 2 года назад

      Pp

  • @lherfel
    @lherfel 3 года назад

    Thanks

  • @inderjeetsingh-cj3ly
    @inderjeetsingh-cj3ly 2 года назад

    Hey i can please tell how to calculate no. Of trades?

  • @jboyce007
    @jboyce007 2 года назад

    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.

  • @itaiitai8960
    @itaiitai8960 3 года назад

    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 ?

  • @TheTheUltimatebro
    @TheTheUltimatebro 3 года назад

    Great channel

  • @dciriva5369
    @dciriva5369 3 года назад

    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?

    • @skeleskele
      @skeleskele 3 года назад

      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

  • @lherfel
    @lherfel 3 года назад

    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

    • @EconomicsDesign
      @EconomicsDesign  3 года назад +1

      Yes, but it depends on how the protocol integrates the swap fees! It might be changing K. or might go to treasury directly!

  • @subversionz4919
    @subversionz4919 3 года назад

    Oh my thank you so much for this! I learn better like this than uniswap's whitepapers lol

  • @polytic
    @polytic 2 года назад

    super

  • @ogcontraband
    @ogcontraband 2 года назад

    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?

    • @EconomicsDesign
      @EconomicsDesign  2 года назад +1

      It is the price within the protocol (in the AMM) vs outside. Think price within Uniswap vs Binance/Coinbase/Sushiswap

    • @ogcontraband
      @ogcontraband 2 года назад

      @@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

  • @iampanzergrenadier
    @iampanzergrenadier 3 года назад +1

    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.

    • @iampanzergrenadier
      @iampanzergrenadier 3 года назад

      so the final formula would be
      NumberOfLISATokens = (NumberOfETH * ReservesOfLISA) / (ReservesETH + NumberOfETH)

    • @EconomicsDesign
      @EconomicsDesign  3 года назад +1

      @@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.

    • @mcjohnson31
      @mcjohnson31 Год назад

      @@iampanzergrenadier you're wrong on your math, she did it right

  • @JorgeBartual1
    @JorgeBartual1 5 месяцев назад

    I fell in love with this girl she's so pretty

  • @itaiitai8960
    @itaiitai8960 3 года назад

    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 ?

    • @EconomicsDesign
      @EconomicsDesign  3 года назад +1

      It depends on the price then. Check www.gasnow.org/