In a Constant Product Market Maker system where X × Y = K (constant), the change in Token Y (Delta Y) can be calculated from the original amounts of X and Y, and the change in Token X (Delta X) using two equivalent algebraic methods: either by distributing terms and factoring to get Delta Y = (-Y × Delta X) / (X + Delta X), or by dividing both sides by (X + Delta X) and subtracting Y to get Delta Y = (X × Y) / (X + Delta X) - Y. Both methods yield the same result and demonstrate how the constant product relationship constrains token price changes.
Token Engineering: Solving Constant Product Market Maker Formula
Added:the basic problem here is we are looking at a constant product Market maker X is the amount of token X Y is the amount of token Y and we're always going to have x times Y is equal to some constant if we knew if we have a new amount because we traded something in and these changes well it's still going to be the case that the new amounts multiply together to be this constant can take this new amount can decompose it into whatever the old amount was plus whatever the change was for each of the two variables you end up with this as our new equation but we'd want to solve for here is the Delta y variable in this particular case now there are actually two ways you can do it and either way the goal is just to isolate Delta Y what I notice here is that this this K is also equal to this original x times y so I'm going to sub that in here and get X Plus Delta x times y plus Delta Y is equal to x times Y how do you get from where the value use change to this so you are why is it not a constant anymore why is it x times here is a constant it is the exact same number what we know from this original equation that this number was equal to x times y substituting at x times y n here that's a good thing to emphasize thanks for okay we're going to distribute this through take this x multiply it by the Y and times the Delta Y and when we start Distributing through this first one gives me x times Y and then I do x times Delta y Delta x times Y which I'm going to write the Y first just make it look nicer plus Delta x times Delta Y and that's Distributing through and that gives me equals to x times y I want to isolate this Delta y so I'm going to try to do anything I can that gets Delta y by itself on this side so I'm going to subtract X Y from this side and if I do that I also have to subtract X Y from this X Y minus X Y is equal to zero just like 2 minus 2 is equal to have the same thing over here X Y minus X Y is equal to zero all I'm left with on this side is zero and then this zeros out so I have x times Delta y plus y times Delta X Plus Delta X Delta Y is equal to 0.
since my goal is to get Delta y by itself I'm going to subtract y Delta X from both sides so that cancels and I have X Delta y plus Delta X Delta Y is equal to negative y Delta X okay now my goal still is to isolate this Delta Y and so what I can do is Factor it out and so if you have the same thing here and here you can kind of undistribute it this is the same as Delta y times X Plus Delta X because I'm taking this Delta Y is in common to both and pulling it out front and then now the only thing we have left to do is we can divide it by what is being multiplied here so we're going to divide both sides by X Plus Delta X and when we divide that cancels this and leaves us with just the Delta y that we wanted so that let me that's probably worth writing out factor out the Delta Y and then we cancel final step is what happens after I've canceled that and now I've just got what I wanted which was the solution to Delta Y in terms of the other variables that are floating around for me to plug in so one solution you could have would be that your final answer was Delta y equal to this and that's the process you would use to get to it so there's no more that can be done this is the final answer this is actually what we wanted we would have to know the other three pieces of information in order to get this if we didn't know if we didn't know the original X or the original y or how much token X was changing we would not be able to calculate how much token y was changing there's an alternative solution method okay the alternative way you still know the the three you know X you know Delta X and you know why we should think about our goal we should know x y and Delta X and then from from that we want to be able to compute what the Delta y would be okay so we're still going to start out with our old equation being x times y equals K and then our new equation being X plus the change in x times y plus the change in y is equal to that same constant K and then I'm going to follow the same process where I'm going to replace this K with this x times y so the next step being X Plus Delta X is equal to Y plus Delta Y is equal to x times Y and my goal is still the same to find the Delta y but I didn't have to distribute this is Delta Y is by itself I could have just divided both sides by X Plus Delta X and then when I do that that isolates the Y plus Delta y cancel that and then I have y plus Delta Y is equal to X Y over X Plus Delta X okay so you're saving a whole step that's nice yeah and then I can subtract y from both sides because that's all I have left to get 2 and so I'm going to subtract y on both sides and the Y minus y 0 which cancels so then the alternative formula I could have come up with is Delta Y is X Y X Plus Delta x minus y and either way will work they should be equivalent
Up Next

Automated Market Makers Explained: Function and Purpose in DeFi
@kerman_crypto
38.3K views•2020-05-28

Torrent File Format & Bencoding: A Technical Deep Dive
@AsliEngineering
12.5K views•2022-08-08

Operational Security Essentials: A Guide for Hacktivists (OPSEC)
@hitbsecconf
157.4K views•2012-11-26

Understanding Ethereum: A Comprehensive Beginner's Overview
@99Bitcoins
3.1M views•2018-06-26
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Blockchain & Crypto



![개념을 말하다 - 수학상 1강 (쎈 1/1~1/8) [EBS,메가스터디,대성마이맥 송진규T]](https://i.ytimg.com/vi/6W9LCKsjSZ4/maxresdefault.jpg)


































