0:00 - Intro 2:38 - Swap - How many tokens to return in a trade? 5:53 - Add liquidity - How many shares to mint? - Answer 6:20 - Add liquidity - Constraints 11:20 - How many shares to mint? 12:54 - How to measure liquidity? 16:04 - Simplify equation for shares to mint 22:05 - Remove liquidity - How many tokens to withdraw? Notes github.com/t4sk/notes Take a course www.smartcontract.engineer/
@guelster5 ай бұрын
I absolutely love all the videos you make! They are technical enough without being too bogged down in the fine details! Keep up the good work!💪
@stephenkoessler83152 жыл бұрын
I think this would be even better to have some example, but this is a really good explanation, thank you!
@replikeit22042 жыл бұрын
lets do curve, with their quadratic equalution and weight math!
@carlhopkinson9 ай бұрын
Brilliant and clear derivations from the XY = K invariant.
@MrCoreyTexas2 ай бұрын
At 21:00, I wanted to point out you can also get from dx/x = dy/y directly from dx/dy = x/y without having to go through some complex algebra.
@kishorevb8331 Жыл бұрын
such a great video, no one explained how adding liquidity works
@user-bp3ch4xg5iАй бұрын
What is T? 16:25 Answer: the total amount of shares before an increment
@chain_l5 ай бұрын
Quintessential example of how an explanation should be. Is there a video explaining along with the fees that AMM's charge?
@smartcontractprogrammer5 ай бұрын
On Uniswap V2, it's 0.3% of token in
@chain_l5 ай бұрын
@@smartcontractprogrammer That's right, how the issuance of LP changes or how they are transferred after the platform fees is enabled.
@captainp.33052 жыл бұрын
21:20 What if we just created a pool and total shares (T) is equal to zero? I mean in this situation shares to mint (s) will be equal to zero too?
@smartcontractprogrammer2 жыл бұрын
shares to mint = change in liquidity = sqrt(xy)
@user-qf2fm4js1z2 жыл бұрын
A very good math teacher!
@mister.solovev Жыл бұрын
Thank you for your clear explanation!
@chintancodewexy2933 Жыл бұрын
(L1 - L0/L0) * T = S here how to calculate total share(T) ?
@smartcontractprogrammer Жыл бұрын
totalSupply
@chintancodewexy2933 Жыл бұрын
@@smartcontractprogrammer thank you
@JayBInTech Жыл бұрын
Thanks for the great tutorial. It is really helpful, but I have two questions to ask. 1. 10:51 How do you summarize dy = ydx / x and dx = xdy / y to dx/dy = x/y? 2. 12:24 This may be simple math but I don't know how you simplify L1/L0 * T - T to L1-L0/LO * T
@user-zu1ix3yq2w Жыл бұрын
2. it works so that's all that matters. What rules are involved? I want to know, too. I'll figure it out later. You can't just remove "T - T" and simplify it to L1/L0. That's wrong.
@kemalware49122 жыл бұрын
So good to be true man, mind blowing content
@user-sz3rd5qk9l2 жыл бұрын
Would be really interesting to get your video on Bancor curve! Would you create one? =)
@santiagodevrel Жыл бұрын
Thanks for this amazing video!! Your content is gold. Just a quick doubt: Maybe for the shares to mint formula, isn't easy to do it like this? SharesToMint = sqrt(dx*dy) in this way we can get the shares to mint in 2 operations. (of course using a library for square root)
@smartcontractprogrammer Жыл бұрын
I think that will give incorrect or inconsistent numbers. Liquidity is measured as sqrt(xy) so change in liquidity is sqrt((x+dx)(y+dy)) - sqrt(xy)
@MrCoreyTexas2 ай бұрын
How did you come up with "the square root of x * y is no greater than 2 times the max of x and y? I'm just plugging numbers into the formula, I've never thought how do you relate square root of a product with maximum? You're coming up with a ceiling / floor somehow?
@smartcontractprogrammer2 ай бұрын
sqrt(xy)
@Ortons1712 жыл бұрын
amazing math!
@ken142502 жыл бұрын
Great video! But there is one question that has been bothering me for so long...What is the dif between constant sum and constant product AMM? And what's the advantage of each over the other? Thank you!
@smartcontractprogrammer2 жыл бұрын
No one uses constant sum. It's good for education purpose. Curve uses a hybrid of constant sum and product
@vermabharat2 жыл бұрын
Constant sum is not practically feasible
@paullawrence5841 Жыл бұрын
Liquidity drains out in constant sum AMM much sooner as compared to constant product AMM.
@mayanknagwanshi Жыл бұрын
I am not sure if this is correct but in x*y=k, you can never have x=0 or y=0, however in x+y=k, there can be x=0 or y=0, if x=k or y=k
@calvinjoshua96152 жыл бұрын
24:05, wasn't it derived for liquidity ?
@codemuhammed Жыл бұрын
In summary: CPAMM (Constant product automated market making) One such rule is the constant product formula X * Y = k, where X and Y are the reserves of two tokens, A and B. To withdraw some token A, one must deposit a proportional amount of token B to maintain the constant k before fees. How do we get initial LP shares, T, after adding initial X and Y reserve? f(X,Y) => sqrt(X*Y) = T To add liquidity, the price impact must be zero X/Y = (X+dx)/(Y+dy) X/Y = dx/dy How many LP shares to mint after adding liquidity? s = (dx/X)T = (dy/Y)T, where T = current LP shares How many tokens dx and dy to withdraw after removing liquidity and burning s? dx = (s/T)X and dy = (s/T)Y and T' = T-s How many tokens to return in a trade? When you want to buy dx from X tokens reserve, you pay by adding dy to Y tokens reserve, in other words, tokens are priced along an iso-liquidity price curve for non-zero token reserves. (X - dx) * (Y + dy) = k, where k = X * Y Thanks for this awesome video!
@aiduongphan2852 жыл бұрын
I have a question: where is 'slippage' in those equation? Cause when we swap token A to B there is also slippage.
@smartcontractprogrammer2 жыл бұрын
time between when you submit the transaction and time the the transaction is executed, price might be different
@sattayakongkom8222 Жыл бұрын
1.before Swap and After Swap , K not change ? 2.How to calculate with fees if r is 0.1% of fees (X - dx) * (Y + (r)(dy)) = k
@vermabharat2 жыл бұрын
Thanks for the video. Really appreciate it!
@salem2322 жыл бұрын
Legend !! 😍 THANK YOU!
@ebrahimkarimi13882 жыл бұрын
Thank you. Its video is very good.
@marioarabaolaza5852 Жыл бұрын
Awesome video, like really awesome. I have a question: why the function for liquidity is √xy?? Is there an explanation for that apart the one from the video??
@smartcontractprogrammer Жыл бұрын
check other videos about constant product AMM, Uniswap V2 and V3
@marioarabaolaza5852 Жыл бұрын
@@smartcontractprogrammer thanks!! Also how could we interpretate the equation: dx = (x *dy)/y + dy ?? For example if we separate dy/y + dy is giving this a ratio or something??
@qiuhaoli Жыл бұрын
Thanks for the helpful video! May I ask when to use CPAMM and when to use CSAMM? Is there any references I can view?