0/5
## Adding Liquidity to Curve V2 Traders can swap tokens using the Curve V2 AMM. But, how are the tokens put into the pool contract in the first place? This is what liquidity providers do. Liquidity providers deposit tokens into the Curve V2 AMM, and in return, they can claim the swap fees collected from traders. As a liquidity provider, we would not want the deposited tokens to be stuck in the pool contract indefinitely. Therefore, there's an option to remove liquidity at any time. Let's consider an example for a USDC, WBTC, and ETH pool. To add liquidity, a user will call the `add_liquidity` function. This will specify the amount of USDC, WBTC, and ETH to deposit into the Curve V2 AMM contract. There are no restrictions on the amount of tokens that can be deposited. For example, a user can deposit 100 USDC, 0 WBTC, and 0 ETH, or equal amounts of 100 USDC, 100 WBTC, and 100 ETH. After the user adds liquidity, the pool contract will mint liquidity provider shares. These shares represent the percentage of liquidity owned by the user. Liquidity can have different meanings for different AMMs. The basic idea of liquidity involves taking the token amounts and parameters, performing calculations, and determining a value. For instance, in a constant product AMM, `x * y = L�`. Liquidity is calculated by multiplying the token balances and then taking the square root to solve for L. Curve V2 employs a more complex method for calculating liquidity. A user also has the option to add liquidity using WETH. This is similar to swapping with WETH in Curve V2. If a user chooses to add liquidity using WETH instead of ETH, after transferring WETH from the user to the pool contract, the pool contract will call `withdraw` on the WETH contract. The WETH contract takes the WETH owned by the pool contract and transfers ETH back to the pool contract. ```javascript xy = L� ```
Traders can swap tokens using the Curve V2 AMM. But, how are the tokens put into the pool contract in the first place? This is what liquidity providers do. Liquidity providers deposit tokens into the Curve V2 AMM, and in return, they can claim the swap fees collected from traders.
As a liquidity provider, we would not want the deposited tokens to be stuck in the pool contract indefinitely. Therefore, there's an option to remove liquidity at any time. Let's consider an example for a USDC, WBTC, and ETH pool. To add liquidity, a user will call the add_liquidity
function. This will specify the amount of USDC, WBTC, and ETH to deposit into the Curve V2 AMM contract. There are no restrictions on the amount of tokens that can be deposited. For example, a user can deposit 100 USDC, 0 WBTC, and 0 ETH, or equal amounts of 100 USDC, 100 WBTC, and 100 ETH.
After the user adds liquidity, the pool contract will mint liquidity provider shares. These shares represent the percentage of liquidity owned by the user. Liquidity can have different meanings for different AMMs. The basic idea of liquidity involves taking the token amounts and parameters, performing calculations, and determining a value.
For instance, in a constant product AMM, x * y = L�
. Liquidity is calculated by multiplying the token balances and then taking the square root to solve for L. Curve V2 employs a more complex method for calculating liquidity.
A user also has the option to add liquidity using WETH. This is similar to swapping with WETH in Curve V2. If a user chooses to add liquidity using WETH instead of ETH, after transferring WETH from the user to the pool contract, the pool contract will call withdraw
on the WETH contract. The WETH contract takes the WETH owned by the pool contract and transfers ETH back to the pool contract.
A comprehensive guide to adding liquidity to Curve's B2AMM. The lesson explains how liquidity providers can deposit tokens into the Curve B2AMM pool, and how they can claim swap fees collected from traders. Additionally, the lesson explains the concept of liquidity in different AMMs, including the formula used to calculate liquidity in a constant product AMM. The lesson then explains how a user can add liquidity using WETH and how the pool contract will handle the transfer of WETH between the user and the pool contract.
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 July 2, 2025
Duration: 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 July 2, 2025