0/5
## Exercise 1: Remove Liquidity The first exercise we are going to tackle is how to remove liquidity from Curve V2. We will do this by calling the function `test_remove_liquidity`. Let's take a look at the setup. The pool contract that we are dealing with is the USDC, WBTC, and WETH pool. Inside the `setUp` function, this contract mints 1,000 USDC to itself. It then approves the pool contract to spend this USDC. ```solidity function setUp() public { deal(USDC, address(this), 1e3 * 1e6); usdc.approve(address(pool), type(uint256).max); uint256[3] memory amounts = [uint256(1e3 * 1e6), uint256(0), uint256(0)]; pool.add_liquidity{ amounts: amounts, min_lp: 1, use_eth: false, receiver: address(this) } } ``` Since this exercise deals with removing liquidity, inside the setup, we also add liquidity to mint some LP shares. Here you can see that it adds USDC as liquidity. So after this code executes, this contract has some LP tokens that it can use to withdraw liquidity. For the first exercise, we are going to call the function `remove_liquidity` on the pool contract to remove all of the liquidity that is possible by this contract. To do this, you will need to first figure out the amount of LP shares that this contract has. Since the Tricrypto is an ERC20 token, we can simply call `pool.balanceOf` querying the balance of this contract. Once we have the LP balance, call `remove_liquidity` to remove all the liquidity that this contract can.
Withdraw your LP tokens by calling remove_liquidity—this exercise walks you through removing USDC liquidity from a Curve V2 pool.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
AMM math for Curve Cryptoswap
How liquidity is concentrated
Price-repegging
How function calls interact with the AMM
Curve Cryptoswap state variables
How the function exchange works
How to swap tokens
How to add and remove liquidity
Math for Curve Cryptoswap’s internal price oracle
Implicit differentiation
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Blockchain Financial Analyst
$100,000 - $150,000 (avg. salary)
DeFi Developer
$75,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 May 15, 2025
DeFi Developer
Curve CryptoswapDuration: 4min
Duration: 1h 21min
Duration: 28min
Duration: 26min
Duration: 14min
Duration: 24min
Duration: 59min
Duration: 5min
Course Overview
About the course
AMM math for Curve Cryptoswap
How liquidity is concentrated
Price-repegging
How function calls interact with the AMM
Curve Cryptoswap state variables
How the function exchange works
How to swap tokens
How to add and remove liquidity
Math for Curve Cryptoswap’s internal price oracle
Implicit differentiation
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Blockchain Financial Analyst
$100,000 - $150,000 (avg. salary)
DeFi Developer
$75,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 May 15, 2025