Constant Product AMM Math | DeFi

  Рет қаралды 12,230

Smart Contract Programmer

Smart Contract Programmer

Күн бұрын

Пікірлер: 51
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
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/
@guelster
@guelster 5 ай бұрын
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!💪
@stephenkoessler8315
@stephenkoessler8315 2 жыл бұрын
I think this would be even better to have some example, but this is a really good explanation, thank you!
@replikeit2204
@replikeit2204 2 жыл бұрын
lets do curve, with their quadratic equalution and weight math!
@carlhopkinson
@carlhopkinson 9 ай бұрын
Brilliant and clear derivations from the XY = K invariant.
@MrCoreyTexas
@MrCoreyTexas 2 ай бұрын
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
@kishorevb8331 Жыл бұрын
such a great video, no one explained how adding liquidity works
@user-bp3ch4xg5i
@user-bp3ch4xg5i Ай бұрын
What is T? 16:25 Answer: the total amount of shares before an increment
@chain_l
@chain_l 5 ай бұрын
Quintessential example of how an explanation should be. Is there a video explaining along with the fees that AMM's charge?
@smartcontractprogrammer
@smartcontractprogrammer 5 ай бұрын
On Uniswap V2, it's 0.3% of token in
@chain_l
@chain_l 5 ай бұрын
@@smartcontractprogrammer That's right, how the issuance of LP changes or how they are transferred after the platform fees is enabled.
@captainp.3305
@captainp.3305 2 жыл бұрын
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?
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
shares to mint = change in liquidity = sqrt(xy)
@user-qf2fm4js1z
@user-qf2fm4js1z 2 жыл бұрын
A very good math teacher!
@mister.solovev
@mister.solovev Жыл бұрын
Thank you for your clear explanation!
@chintancodewexy2933
@chintancodewexy2933 Жыл бұрын
(L1 - L0/L0) * T = S here how to calculate total share(T) ?
@smartcontractprogrammer
@smartcontractprogrammer Жыл бұрын
totalSupply
@chintancodewexy2933
@chintancodewexy2933 Жыл бұрын
@@smartcontractprogrammer thank you
@JayBInTech
@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
@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.
@kemalware4912
@kemalware4912 2 жыл бұрын
So good to be true man, mind blowing content
@user-sz3rd5qk9l
@user-sz3rd5qk9l 2 жыл бұрын
Would be really interesting to get your video on Bancor curve! Would you create one? =)
@santiagodevrel
@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
@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)
@MrCoreyTexas
@MrCoreyTexas 2 ай бұрын
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?
@smartcontractprogrammer
@smartcontractprogrammer 2 ай бұрын
sqrt(xy)
@Ortons171
@Ortons171 2 жыл бұрын
amazing math!
@ken14250
@ken14250 2 жыл бұрын
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!
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
No one uses constant sum. It's good for education purpose. Curve uses a hybrid of constant sum and product
@vermabharat
@vermabharat 2 жыл бұрын
Constant sum is not practically feasible
@paullawrence5841
@paullawrence5841 Жыл бұрын
Liquidity drains out in constant sum AMM much sooner as compared to constant product AMM.
@mayanknagwanshi
@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
@calvinjoshua9615
@calvinjoshua9615 2 жыл бұрын
24:05, wasn't it derived for liquidity ?
@codemuhammed
@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!
@aiduongphan285
@aiduongphan285 2 жыл бұрын
I have a question: where is 'slippage' in those equation? Cause when we swap token A to B there is also slippage.
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
time between when you submit the transaction and time the the transaction is executed, price might be different
@sattayakongkom8222
@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
@vermabharat
@vermabharat 2 жыл бұрын
Thanks for the video. Really appreciate it!
@salem232
@salem232 2 жыл бұрын
Legend !! 😍 THANK YOU!
@ebrahimkarimi1388
@ebrahimkarimi1388 2 жыл бұрын
Thank you. Its video is very good.
@marioarabaolaza5852
@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
@smartcontractprogrammer Жыл бұрын
check other videos about constant product AMM, Uniswap V2 and V3
@marioarabaolaza5852
@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
@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?
@smartcontractprogrammer
@smartcontractprogrammer Жыл бұрын
CPAMM - Uniswap V2 CPAMM + CSAMM hybrid = curve V1
@wuchuannn
@wuchuannn 2 жыл бұрын
What tool did you use for drawing this out?
@cleverblocks6422
@cleverblocks6422 2 жыл бұрын
Excalidraw
@wuchuannn
@wuchuannn 2 жыл бұрын
@@cleverblocks6422 thank you ser
@kishorevb8331
@kishorevb8331 Жыл бұрын
can you please tell me what software are you using to write these notes
@smartcontractprogrammer
@smartcontractprogrammer Жыл бұрын
excalidraw.com/
@MeredithGrey-13
@MeredithGrey-13 3 ай бұрын
Yo kittens! MEREDITH ==> crypto's worst rapping cat! ᓚᘏᗢ
Uniswap V3 - Single Hop Swap | DeFi
18:22
Smart Contract Programmer
Рет қаралды 9 М.
Constant Product Automated Market Maker | Solidity 0.8
30:01
Smart Contract Programmer
Рет қаралды 9 М.
МАИНКРАФТ В РЕАЛЬНОЙ ЖИЗНИ!🌍 @Mikecrab
00:31
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 37 МЛН
Constant Sum AMM Math | DeFi
14:35
Smart Contract Programmer
Рет қаралды 4,6 М.
How to Calculate Impermanent Loss on Uniswap V2 | DeFi
15:37
Smart Contract Programmer
Рет қаралды 3,9 М.
Constant Sum Automated Market Maker | Solidity 0.8
32:16
Smart Contract Programmer
Рет қаралды 8 М.
Defi AMM Arbitrage Explained
19:23
Bitcoin Trading Challenge
Рет қаралды 18 М.
Uniswap V3 - Curve of Real Reserves | DeFi
13:27
Smart Contract Programmer
Рет қаралды 5 М.
Lecture 5.2 AMM
14:39
Berkeley RDI Center on Decentralization & AI
Рет қаралды 5 М.
What is an Automated Market Maker? (Liquidity Pool Algorithm)
10:25
Whiteboard Crypto
Рет қаралды 388 М.
When to Exit a Liquidity Pool | Defi Passive Income
10:27
CryptoLabs Research | Defi Passive Income 🤑
Рет қаралды 4,8 М.