Exercise 2: Exchange

A practical Solidity exercise on swapping tokens using a Curve StableSwap3Pool. This lesson covers calling the `exchange` function and understanding the inputs required for a token swap, including the token index and the minimum amount expected back.

Solidity Developer

Curve Stableswap

1. Contract Calls
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. Duration: 1min
2. Code Outline
A comprehensive guide to understanding the steps involved in the 'exchange' function of StableSwap. This lesson outlines the algorithm for the function, including token balance normalization, token transfers, and the calculation of swap fees. Duration: 2min
3. Code Walkthrough exchange
A comprehensive Solidity function breakdown to understand how tokens are swapped on Curve B1AMM. The lesson explains the purpose of the function's inputs, how token balances are normalized, and the role of fees in transferring tokens. Duration: 8min
4. Code Walkthrough Get Y
A detailed explanation of the 'get_y_i' function implementation within the StableSwap3Pool.ly contract. This lesson covers the inner workings of the function, including how it calculates the new token balance and applies Newton’s method to find the desired result. Duration: 3min
5. Code Walkthrough Get Dy
A detailed explanation of the get_dy function used in the Curve StableSwap3Pool.vy contract. This lesson covers how the function calculates the output amount of tokens for a given input amount, taking into account the token balances, rates, and swap fees. Duration: 3min
6. Exercise 1: Get Dy Underlying
A practical guide to using the get_dy_underlying function in Curve Stableswap. This lesson explains how to calculate the amount of USDC you will get for swapping 1 million DAI to USDC using the get_dy_underlying function in the Curve Stableswap stable swap pool. Duration: 1min
7. Solution 1: Get Dy Underlying
A practical guide to interacting with Curve’s stable swap pool contract in Solidity - The lesson shows how to call the getDYUnderlying function on the Curve StableSwap3Pool contract and how to pass the correct inputs for a successful interaction. Duration: 2min
8. Exercise 2: Exchange
A practical Solidity exercise on swapping tokens using a Curve StableSwap3Pool. This lesson covers calling the `exchange` function and understanding the inputs required for a token swap, including the token index and the minimum amount expected back. Duration: 1min
9. Solution 2: Exchange
A practical exercise to swapping tokens on Curve B1 - This lesson covers the steps to swap 1 million DAI for USDC on Curve B1 by using the exchange() function, and specifying the correct index values for the tokens, the amount of DAI to swap, and the minimum amount of USDC expected. Duration: 2min

Course Overview

About the course

What you'll learn

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

Course Description

Who is this course for?

  • Software Engineers
  • Financial Analysts
  • Web3 Developers
  • Smart Contract Security Researchers

Potential Careers

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)

Meet your instructors

Tasuku Nakamura

Tasuku Nakamura

Founder at smartcontract.engineer

Smart contract engineer and educator.

Last updated on November 27, 2024

Testimonials

Students Reviews

Read what our students have to say about this course.

Chainlink

Chainlink

Chainlink

Gustavo Gonzalez

Gustavo Gonzalez

Solutions Engineer at OpenZeppelin

Francesco Andreoli

Francesco Andreoli

Lead Devrel at Metamask

Albert Hu

Albert Hu

DeForm Founding Engineer

Radek

Radek

Senior Developer Advocate at Ceramic

Boidushya

Boidushya

WalletConnect

Idris

Idris

Developer Relations Engineer at Axelar

Cyfrin
Updraft
CodeHawks
Solodit
Resources