Help me understand why we use 2 different invariants when adding liquidity & swapping tokens ? #49
-
Purely by looking at the source code for For swapping tokens we maintain but when it comes to adding liquidity, we try to maintain why do we do that ? and how does the whole math workout? |
Beta Was this translation helpful? Give feedback.
Answered by
TilakMaddy
Dec 29, 2023
Replies: 1 comment 2 replies
-
Where do we do that? And a few times we do some advanced algebra to derive equations from the y * x = k equation. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got my question answered after going through the formal verification paper here
x * y = k
is not true throughout the lifetime of the contract. Otherwise, you could never add extra money (for either token - x or y) without removing some from the other (how else would you have a product of two non-negative numbers be constant, right?). Therefore when it comes to adding liquidity, the value ofx * y
is expected to strictly increase.The invariant in this situation is the ratio
e:t:l
(e -> ether, t -> exchange token, l -> total liquidity amount). Say you want to provideΔe
to liquidity pool, in order to preserve thee:t:l
ratio they also expect you to providealpha * t
tot
and, in turn you…