Uniswap V2 - Pricing | DeFi

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 พ.ค. 2024
  • How are the prices for token exchanged determined on Uniswap? Here I will explain how pricing is calculated using a mathematical equation x * y = k
    x * y = k equation 0:43
    spreadsheet simulation 2:46
    dy = ? 5:17
    Uniswap V2 pair and router contract 7:01
    #DeFi #Uniswap #SmartContract #Ethereum
    References
    Uniswap app.uniswap.org/
    Etherscan etherscan.io
    Uniswap V2 Pair DAI - ETH contract
    etherscan.io/address/0xA478c2...
    Uniswap V2 Router contract
    etherscan.io/address/0x7a250d...
    x * y = k spreadsheet
    docs.google.com/spreadsheets/...
    Follow on Twitter: @ProgrammerSmart / programmersmart
    Join me on Discord: / discord
    Website: smartcontractprogrammer.com
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 90

  • @bobmil
    @bobmil ปีที่แล้ว +4

    This is great. Explained in such a detailed way. I loved the formula derivations.

  • @kowsikgelli7257
    @kowsikgelli7257 3 ปีที่แล้ว +1

    I am following your channel from 100 subscribers I think and you are the best

  • @mbc3kids
    @mbc3kids 3 ปีที่แล้ว +6

    your videos are damn undervalued, keep it up and you will get you share soon or later :)

  • @salem232
    @salem232 3 ปีที่แล้ว +1

    😍❤🙌 Thank you !!! Math and example was so well explained !! Thank god was straight forward enough to understand 😌

  • @remixisthis
    @remixisthis 2 ปีที่แล้ว

    Great video! Very thorough and transparent in your methodology

  • @lihe5156
    @lihe5156 2 ปีที่แล้ว +1

    Thank you !! This is the best tech channel I've ever seen

  • @BioHazarddasdadfasfsad
    @BioHazarddasdadfasfsad 2 ปีที่แล้ว

    You should know that this is the most satisfying video on the youtube for this subject

  • @jvjvalerio1
    @jvjvalerio1 ปีที่แล้ว

    your videos are seriously amazing!

  • @siddharthpatel7284
    @siddharthpatel7284 2 ปีที่แล้ว

    loved it thanks got to learn many things from you

  • @stuafleish
    @stuafleish 2 ปีที่แล้ว

    Thanks for the great content! When you are looking at the getReserve call, how do you know which token is reserve0 and which token is reserve1?

  • @madalinantonoiu9714
    @madalinantonoiu9714 2 ปีที่แล้ว

    Brilliant! Thanks for the lesson

  • @danieliniguezv
    @danieliniguezv 2 ปีที่แล้ว

    amazing job. thank you so much!!!

  • @smartcontractprogrammer
    @smartcontractprogrammer  3 ปีที่แล้ว +4

    x * y = k equation 0:43
    spreadsheet simulation 2:46
    dy = ? 5:17
    Uniswap V2 pair and router contract 7:01

    • @irinatomova7415
      @irinatomova7415 3 ปีที่แล้ว

      Need your opinion on PolkaCover. Can’t take a desition about them. Good insurance system and solutions but some price go down. I see it growing but I can’t definitely decide about this stuff. Help you bro outttt

    • @Katie-zq9ib
      @Katie-zq9ib ปีที่แล้ว

      This is such a great explanation, thank you. 🙏🏽
      One small note I wanted to ask -
      I can't figure out how dy = (y - xy)/(x +dx) turned to dy = (yx + ydx -xy)/(x + dx)

    • @iTubeItalia
      @iTubeItalia ปีที่แล้ว +1

      @@Katie-zq9ib Because it is not (y - xy) / (x + dx) but rather y - ( xy / (x + dx) ) and therefore you can multiply y by (x + dx)/(x + dx) and then rewrite all as ( y ( x + dx ) - xy ) / ( x + dx )

    • @shravan_andoria
      @shravan_andoria หลายเดือนก่อน

      @@iTubeItalia when we do y - ( xy / (x + dx) ), how do we got (x + dx) which multiplies by y, from where x + dx came which gets multiplied by y?

  • @dalelinney8437
    @dalelinney8437 3 ปีที่แล้ว +1

    Excellent vid again.

  • @user-u65
    @user-u65 3 ปีที่แล้ว

    Amazing! Now I got it! Thanks!

  • @majmunOR
    @majmunOR 3 ปีที่แล้ว +2

    Nice, great explanation! Btw, will you also do a video on how to use a Uniswap oracle? Especially TWAP, like a 10 minute twap or 1 week twap. :)

  • @vadimchilinciuc8296
    @vadimchilinciuc8296 3 หลายเดือนก่อน

    Thanks another time for all your work man!
    I have only one doubt, in the last part of the video , when you tell that ,"the less of one token we get the more expensive to buy using other token" : so the best deal will bee: to "trade tokens" when the reserve are 50% 50 % ? corect me if im wrong but when trades are made in the pool the reserve change right so it bee the best deal to have them at 50 % ?
    Thanks a lot !

    • @smartcontractprogrammer
      @smartcontractprogrammer  3 หลายเดือนก่อน +1

      best deals are trades that bring the token balances to 50 / 50

  • @crystalape2195
    @crystalape2195 2 ปีที่แล้ว

    your videos are the best

  • @validyor
    @validyor ปีที่แล้ว

    Excellent video SCP!

  • @cyberdisco9724
    @cyberdisco9724 2 ปีที่แล้ว

    excellent video!

  • @ninh3134
    @ninh3134 2 ปีที่แล้ว

    Thanks for your video. Which software do you use for drawing? It's great.

  • @ShkolnikPrahramist
    @ShkolnikPrahramist 2 ปีที่แล้ว

    Thanks for video. Does this formula applied to curve finance?

  • @blockchaindaily2348
    @blockchaindaily2348 ปีที่แล้ว

    Best video

  • @Ortons171
    @Ortons171 3 ปีที่แล้ว +3

    Will you make the same video about Uniswap V3 concentrated liquidity and how it works?

    • @TommyDJr45
      @TommyDJr45 3 ปีที่แล้ว +1

      I was literally going to ask the same thing.

    • @smartcontractprogrammer
      @smartcontractprogrammer  3 ปีที่แล้ว +2

      maybe in the future?

    • @Stevegerr8
      @Stevegerr8 2 ปีที่แล้ว +2

      @@smartcontractprogrammer Hey from the future ^

  • @thedefieur3621
    @thedefieur3621 2 ปีที่แล้ว

    Super great stuff! Btw, may I ask about the fees. Should the buyer pay more by 3%? If this is the case, then the multiplier should be 1.03 and not 0.97? Thank you very much, keep it up and more power to you.

    • @smartcontractprogrammer
      @smartcontractprogrammer  2 ปีที่แล้ว

      isn't the fee 0.3%?

    • @thedefieur3621
      @thedefieur3621 2 ปีที่แล้ว

      Oh sorry, I meant 0.3%. But then should the multiplier be 1.003 instead of 0.997?

    • @smartcontractprogrammer
      @smartcontractprogrammer  2 ปีที่แล้ว

      0.3% is taken out from you as trading fee hence (1 - 0.03) = 997 / 1000

    • @thedefieur3621
      @thedefieur3621 2 ปีที่แล้ว +1

      @@smartcontractprogrammer Ok got it. That was from the receiving end. Hence, the fee is taken out. I thought initially it was me paying out (hence the idea of putting the fee on top). Again, thanks for that great tutorial!

  • @TheDEMMX
    @TheDEMMX 2 ปีที่แล้ว +1

    I am not following the algebra on 6:30. How did we get from dy = (y - xy)/(x +dx) to dy = (yx + ydx -xy)/(x + dx)??? That implies y = yx + ydx, but why???

    • @iTubeItalia
      @iTubeItalia ปีที่แล้ว +1

      Because it is not (y - xy) / (x + dx) but rather y - ( xy / (x + dx) ) and therefore you can multiply y by (x + dx)/(x + dx) and then rewrite all as ( y ( x + dx ) - xy ) / ( x + dx )

  • @elephantmoney
    @elephantmoney 2 ปีที่แล้ว

    Thanks man. I hate how you can't choose a price you want to buy at

  • @senthilsamrat24
    @senthilsamrat24 ปีที่แล้ว

    Can you make video on how to find priceimpact of a token?

  • @LuccDev
    @LuccDev 2 ปีที่แล้ว

    Thanks for the explanation. But how is "K" decided ?

  • @harrytr.277
    @harrytr.277 2 ปีที่แล้ว

    Thank you so much. Are you the creator of solidity by example?

  • @phdcoder6249
    @phdcoder6249 2 ปีที่แล้ว +1

    Why in the denominator we add 0.997? The fee will be subtracted from a token that we are exchanging (y*0.997) but why add (0.997) to the x ?

    • @coinomer5912
      @coinomer5912 ปีที่แล้ว

      I was going to ask the same thing.

    • @coinomer5912
      @coinomer5912 ปีที่แล้ว

      I figured , the 0.997 in the numerator is because of dx not because of y , actually there is 0.997 * dx in both numerator and denominator

  • @salem232
    @salem232 3 ปีที่แล้ว +1

    Follow up question for more context of this type of transaction : 1. looks like the fees is charged on both side ? 2. What is incentivising the exchange requester or the provider? 3. Does the K curve here somewhat similar to demand cuve ? Will there be situation that x or y depleted unexpectly that disruptes the exchange?

    • @smartcontractprogrammer
      @smartcontractprogrammer  3 ปีที่แล้ว +2

      1. Fee is charged from the token that you are selling
      2. Incentive to exchange - you want to buy a token. Incentive to be liquidity provider - you earn trading fees
      3. Don't know what a demand curve is. Lower the amount of token, the more expensive it gets.

    • @salem232
      @salem232 3 ปีที่แล้ว

      @@smartcontractprogrammer ❤️ thanks so much!!! Make sense! Feels like being the middleman (liquidity provider) is the way to go !!🤩

    • @R24W86
      @R24W86 3 ปีที่แล้ว +2

      @@salem232 Yes, but the cost to the LP is impermanent loss

    • @salem232
      @salem232 3 ปีที่แล้ว

      thanks! I didn’t realize that tokens in the pool is disconnected vs. the market!!!! Why is designed that way? This will mean very large arbitrage existing

    • @salem232
      @salem232 3 ปีที่แล้ว

      @@R24W86 !!!

  • @tomok284
    @tomok284 ปีที่แล้ว

    How does the Uniswap price the tokens if there are many requests for trades nearly at the same time? Will they do it one by one via a queue?

  • @demelengopnik7187
    @demelengopnik7187 9 หลายเดือนก่อน

    Hi
    Router contract price and uniswap app price are different with app giving me more, which is weird. What's going on here?

  • @dev.regotube
    @dev.regotube 3 ปีที่แล้ว

    質問ですが、さらに流動性を提供すればkの値も変わりますよね?

    • @smartcontractprogrammer
      @smartcontractprogrammer  3 ปีที่แล้ว +1

      はい、
      addLiquidityでKの値が上がります。
      github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/UniswapV2Router02.sol#L61
      github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2Pair.sol#L128

    • @dev.regotube
      @dev.regotube 3 ปีที่แล้ว

      @@smartcontractprogrammer ありがとうございます!

  • @uzcryptoairdrop
    @uzcryptoairdrop 2 ปีที่แล้ว

    Hello admin, I have listed my token, I don't know how to set the price, please help

  • @kowsikgelli7257
    @kowsikgelli7257 3 ปีที่แล้ว

    Can you explain to me what is slippage and how to calculate it?

    • @smartcontractprogrammer
      @smartcontractprogrammer  3 ปีที่แล้ว +1

      slippage is different in price from moment you send transaction to the moment the trade is executed.

  • @peacelove3.6.9
    @peacelove3.6.9 2 ปีที่แล้ว

    i currently own 20k $ worth of shiryo tokens and i wonder how much i will need to pay when i convert them to eth once the coin will 10x or even 100x, how much will i lose from my shiryo tokens and is there a trick to prevent such a huge lost

  • @veliea5160
    @veliea5160 ปีที่แล้ว

    what is the benefit of subscribing to your website

  • @brucifer97
    @brucifer97 2 ปีที่แล้ว

    Is this the same formula sushiswap use?

  • @TheGaneshshow
    @TheGaneshshow ปีที่แล้ว

    is it 0.3 or 0.03%?, please tell. Thank you.

    • @smartcontractprogrammer
      @smartcontractprogrammer  ปีที่แล้ว +1

      0.3%
      docs.uniswap.org/protocol/V2/concepts/advanced-topics/fees

    • @TheGaneshshow
      @TheGaneshshow ปีที่แล้ว

      @@smartcontractprogrammer Thank you very much sir.

  • @testvb6417
    @testvb6417 หลายเดือนก่อน

    How is K constant determined?? idk why no one asked that lol

  • @itaidevops8677
    @itaidevops8677 2 ปีที่แล้ว

    Is the any calculator ? I didn’t understand this guy

  • @tobiasfan5407
    @tobiasfan5407 ปีที่แล้ว

    can someone be kind enough to help this humble dum-dum understand how he got from " dy = y - xy / (x +dx) " to " = (yx + ydx - xy) / (x + dx) " ? @6:53 🙏

    • @smartcontractprogrammer
      @smartcontractprogrammer  ปีที่แล้ว +1

      y - xy / (x +dx) = (y * (x + dx) - xy) / (x + dx) = (yx + ydx - xy) / (x + dx)

  • @sendlocation8476
    @sendlocation8476 10 หลายเดือนก่อน

    Confusing as

    • @smartcontractprogrammer
      @smartcontractprogrammer  10 หลายเดือนก่อน

      wait til you see Uni v3

    • @sendlocation8476
      @sendlocation8476 10 หลายเดือนก่อน

      @@smartcontractprogrammer which recommended to use v2 or v3?