5/5
To swap tokens with the Curve's B1AMM, we will call the function `exchange`. For example, let's say that this user wanted to swap DAI for USDC from the StableSwap3Pool contract. First, we will call the function `exchange` specifying that the token in is DAI and the amount of DAI to swap. The StableSwap3Pool contract will transfer the DAI in from the user over to the pool contract, calculate the amount of USDC to get back and then transfer the USDC from the pool contract over to the user.
To swap tokens with the Curve's B1AMM, we will call the function exchange
.
For example, let's say that this user wanted to swap DAI for USDC from the StableSwap3Pool contract.
First, we will call the function exchange
specifying that the token in is DAI and the amount of DAI to swap.
The StableSwap3Pool contract will transfer the DAI in from the user over to the pool contract, calculate the amount of USDC to get back and then transfer the USDC from the pool contract over to the user.
A simplified overview of the exchange function in Curve's StableSwap3Pool smart contract. This lesson explains how users can swap tokens within the pool, covering the process from calling the exchange function to receiving their desired token.
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 June 6, 2025
Duration: 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 June 6, 2025