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 - วิทยาศาสตร์และเทคโนโลยี
This is great. Explained in such a detailed way. I loved the formula derivations.
I am following your channel from 100 subscribers I think and you are the best
your videos are damn undervalued, keep it up and you will get you share soon or later :)
😍❤🙌 Thank you !!! Math and example was so well explained !! Thank god was straight forward enough to understand 😌
Great video! Very thorough and transparent in your methodology
Thank you !! This is the best tech channel I've ever seen
You should know that this is the most satisfying video on the youtube for this subject
your videos are seriously amazing!
loved it thanks got to learn many things from you
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?
Brilliant! Thanks for the lesson
amazing job. thank you so much!!!
x * y = k equation 0:43
spreadsheet simulation 2:46
dy = ? 5:17
Uniswap V2 pair and router contract 7:01
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
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)
@@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 )
@@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?
Excellent vid again.
Amazing! Now I got it! Thanks!
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. :)
I am thinking about it. First I need to learn about it myself
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 !
best deals are trades that bring the token balances to 50 / 50
your videos are the best
Excellent video SCP!
excellent video!
Thanks for your video. Which software do you use for drawing? It's great.
excalidraw.com/
Thanks for video. Does this formula applied to curve finance?
No Curve pricing is more complex
Best video
Will you make the same video about Uniswap V3 concentrated liquidity and how it works?
I was literally going to ask the same thing.
maybe in the future?
@@smartcontractprogrammer Hey from the future ^
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.
isn't the fee 0.3%?
Oh sorry, I meant 0.3%. But then should the multiplier be 1.003 instead of 0.997?
0.3% is taken out from you as trading fee hence (1 - 0.03) = 997 / 1000
@@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!
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???
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 )
Thanks man. I hate how you can't choose a price you want to buy at
Can you make video on how to find priceimpact of a token?
Thanks for the explanation. But how is "K" decided ?
initialization XY = K
Thank you so much. Are you the creator of solidity by example?
yes
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 ?
I was going to ask the same thing.
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
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?
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.
@@smartcontractprogrammer ❤️ thanks so much!!! Make sense! Feels like being the middleman (liquidity provider) is the way to go !!🤩
@@salem232 Yes, but the cost to the LP is impermanent loss
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
@@R24W86 !!!
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?
yes, one by one
Hi
Router contract price and uniswap app price are different with app giving me more, which is weird. What's going on here?
質問ですが、さらに流動性を提供すればkの値も変わりますよね?
はい、
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
@@smartcontractprogrammer ありがとうございます!
Hello admin, I have listed my token, I don't know how to set the price, please help
Can you explain to me what is slippage and how to calculate it?
slippage is different in price from moment you send transaction to the moment the trade is executed.
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
what is the benefit of subscribing to your website
test your knowledge
be on leaderboard
Is this the same formula sushiswap use?
It might be. Sushiswap may have tweaked their pricing formula
is it 0.3 or 0.03%?, please tell. Thank you.
0.3%
docs.uniswap.org/protocol/V2/concepts/advanced-topics/fees
@@smartcontractprogrammer Thank you very much sir.
How is K constant determined?? idk why no one asked that lol
number of tokens in the contract (reserve0 and reserve1)
Is the any calculator ? I didn’t understand this guy
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 🙏
y - xy / (x +dx) = (y * (x + dx) - xy) / (x + dx) = (yx + ydx - xy) / (x + dx)
Confusing as
wait til you see Uni v3
@@smartcontractprogrammer which recommended to use v2 or v3?