0/5
We're continuing to cover removing liquidity in this lesson. We'll use the `remove_liquidity_one_coin` function to remove a single coin from the pool. We can see that the function we'll be calling is `remove_liquidity_one_coin`: ```javascript function remove_liquidity_one_coin(uint256 lp, int128 i, uint256 min_coin) external; ``` We'll navigate to the `Curve/RemoveLiquidity/test.sol` file and use the `pool` variable to access the function. We'll also declare a variable named `LP_Bal`, which will store the balance of the LP token. ```javascript uint256 LP_Bal = pool.balanceOf(address(this)); ``` Now, we'll call the `remove_liquidity_one_coin` function, passing in the LP token balance, the index of the coin to remove, and a minimum amount of the coin we want to receive. ```javascript pool.remove_liquidity_one_coin(LP_Bal, 0, 1); ``` The index of the coin is 0 because we'll be removing DAI. We'll set the minimum amount to 1 to avoid receiving 0 coins. We'll also use `balanceOf` to get the balances of the other two coins in the pool, USDC and USDT. ```javascript uint256 bal = dai.balanceOf(address(this)); assertGt(bal, 0, "DAI balance = 0"); console2.log("DAI balance =%", bal); bal = usdc.balanceOf(address(this)); assertEq(bal, 0, "USDC balance > 0"); console2.log("USDC balance =%", bal); bal = usdt.balanceOf(address(this)); assertEq(bal, 0, "USDT balance > 0"); console2.log("USDT balance =%", bal); ``` We'll execute the test using Foundry, similar to the previous exercise: ```bash forge test --fork-url $FORK_URL --match-test "test_remove_liquidity_one_coin" -vvv ``` We see that our test passed and the results are as expected. We successfully removed liquidity for DAI and received back approximately 999,995 DAI as well as 0 USDC and 0 USDT.
A practical Solidity exercise on removing liquidity from a Curve pool - The lesson demonstrates how to call the remove_liquidity_one_coin function to withdraw a single stablecoin (DAI) from a 3pool, while also showcasing the expected outputs for the other stablecoins in the pool (USDC and USDT).
Previous lesson
Previous
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