1/5
## Removing Liquidity From Curve Let's learn about removing liquidity from Curve! We will explore the process of removing liquidity from Curve. For this lesson, we will use a test contract that has been initialized with 1 million DAI, and this 1 million DAI has been provided as liquidity to a Curve pool. ### Exercise 1 The first exercise involves calling the `removeLiquidity` function. Remember, the `removeLiquidity` function will burn LP tokens and give you back all of the tokens in the pool. For the Curve StableSwap 3 pool, the tokens are DAI, USDC, and USDT. To start, we will call the `removeLiquidity` function and then retrieve the balances of the tokens. The code below will print the balances of the tokens in the pool. ```javascript function testRemoveLiquidity() public { assertEq(lp.balanceOf(address(this)), 0, "3CRV balance > 0"); uint256 bal = 0; dai = dai.balanceOf(address(this)); assertGt(bal, 0, "DAI balance = 0"); console.log("DAI balance %e", bal); usdc = usdc.balanceOf(address(this)); assertGt(bal, 0, "USDC balance = 0"); console.log("USDC balance %e", bal); usdt = usdt.balanceOf(address(this)); assertGt(bal, 0, "USDT balance = 0"); console.log("USDT balance %e", bal); } ``` ### Exercise 2 For the second exercise, we will again call the `removeLiquidity` function but this time we will specify the amount of LP to burn. To achieve this, we will first obtain the balance of the LP token. Since the LP token is an ERC20, we can get the balance by calling the `balanceOf` function, which returns the amount of LP tokens locked inside the test contract. ```javascript function setUp() public { dai.approve(address(pool), type(uint256).max); uint256[3] memory coins = [uint256(1e6 * 1e18), uint256(0), uint256(0)]; pool.addLiquidity(coins, 1); } ``` The `removeLiquidity` function takes two parameters: - `uint256 lp` - The amount of LP to burn - `uint256[3] calldata min_coins` - The minimum amount of coins you expect to get back when burning the LP For simplicity, you can put the minimum coins as 0 or 1 or whatever you want. ```javascript function removeLiquidity(uint256 lp, uint256[3] calldata min_coins) external; ```
A practical guide to removing liquidity from Curve.fi - The lesson demonstrates how to remove liquidity from Curve pools, with step-by-step instructions on interacting with the removeLiquidity function and understanding the minimum amount of coins expected.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
AMM math for Curve Stableswap
How to calculate swap amount and liquidity
Curve Stableswap contracts
How to implement a swap function
How to implement the add and remove liquidity functions
How to quantify liquidity pools
How to control the flatness of the curve
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Blockchain Financial Analyst
$100,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Last updated on November 27, 2024
Solidity Developer
Curve StableswapDuration: 14min
Duration: 32min
Duration: 26min
Duration: 23min
Duration: 20min
Duration: 23min
Course Overview
About the course
AMM math for Curve Stableswap
How to calculate swap amount and liquidity
Curve Stableswap contracts
How to implement a swap function
How to implement the add and remove liquidity functions
How to quantify liquidity pools
How to control the flatness of the curve
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Blockchain Financial Analyst
$100,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Last updated on November 27, 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