0/5
When we add liquidity to a constant product AMM, the amount of token X to add and the amount of token Y to add must follow a simple rule. The price after adding liquidity must be equal to the price before adding liquidity. For example, here we have two constant product AMM curves. The one in blue is before adding liquidity and the one in purple is after adding liquidity. Before adding liquidity, we have that the price is equal to 1.4. And after adding the correct amount of token X and the correct amount of token Y, we have that the price is still equal to 1.4. We discussed that one way to visualize that the price after adding liquidity is equal to the price before adding liquidity is to draw a straight line from the origin to the current price, and then extend this line. To increase liquidity from this blue point, the only valid amount of token X and amount of token Y that we can add must also be on this green line. In this case, we see that after adding liquidity, we get this purple curve, and the point where the price after adding liquidity is equal to the price before adding liquidity is over here, exactly on the green line. Now, when we remove liquidity from the constant product AMM, we again follow the same rule that the price after removing liquidity must be equal to the price before removing liquidity. So, let's say that our current AMM is described by this purple curve. After removing liquidity, the price must remain the same. The price before removing liquidity is P equals 1.4. So, after removing liquidity, the price must remain the same, 1.4. And the only way to do this is to have the balance of token X and token Y inside the constant product AMM be a point on this green line. For example, as we remove liquidity, you'll see that this purple curve approach this blue curve, and at every point, you'll see that the point where corresponds to price equals 1.4 be exactly on the green line. So, as I decrease liquidity, you can see that the point where the price is equal to 1.4 remains on the green line. And if I decrease all the way to the blue curve, it still remains on the green line. Okay, so after we remove liquidity from the constant product AMM, the price after removing liquidity must be equal to the price before removing liquidity. So, the next question is how much amount of token X and how much amount of token Y do we need to take out from this pool so that when we decrease liquidity, the price remains the same?
A visual guide to removing liquidity from a constant product AMM - This lesson visually explains how removing liquidity from a constant product automated market maker (AMM) works. This is done by creating a visualization with two liquidity curves (one before and one after removing liquidity), and showing how the price remains the same during this process.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
How to use Uniswap v2 dex and contracts
Interacting with the Uniswap v2 router and factory
How to create Uniswap v2 liquidity pools
How to add liquidity to Uniswap v2 pools
Swaps, flash swaps, flash swap arbitrage, and time-weighted average price (TWAP)
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on October 9, 2024
Solidity Developer
Uniswap V2Duration: 14min
Duration: 1h 20min
Duration: 10min
Duration: 54min
Duration: 25min
Duration: 26min
Duration: 1h 03min
Duration: 59min
Course Overview
About the course
How to use Uniswap v2 dex and contracts
Interacting with the Uniswap v2 router and factory
How to create Uniswap v2 liquidity pools
How to add liquidity to Uniswap v2 pools
Swaps, flash swaps, flash swap arbitrage, and time-weighted average price (TWAP)
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on October 9, 2024
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar