Code Walkthrough Exact Input

A detailed code walkthrough of the contract SwapRouter02 in the Uniswap V3 Router contracts. This lesson covers the functions exactInput, exactInputSingle, and exactInputInternal, explaining how they work and how they are used to execute swaps with single or multiple pools.

DeFi Developer

Uniswap V3

1. Swap Algorithm
A detailed walkthrough of Uniswap V3's swap algorithm. The lesson covers a step-by-step explanation of the swap algorithm, including the inputs, types of swap, how to calculate amount in and amount out, and how to update state variables. It also provides an example to illustrate the concepts. Duration: 11min
2. Liquidity Net Intro
A visual guide to understanding active liquidity in Uniswap V3. The lesson shows how active liquidity changes based on price movement and demonstrates how Uniswap V3 keeps track of active liquidity at any given price using a visual representation. Duration: 2min
3. Math Liquidity Net
A comprehensive explanation of how Uniswap V3 keeps track of liquidity and how to calculate liquidity net in the context of price changes and active liquidity. The lesson covers the basics of understanding liquidity net, the role of ticks, and how liquidity net changes when the current price moves across ticks. Duration: 4min
4. Graph Liquidity Net
A detailed explanation of how the current liquidity is updated using liquidity net. The lesson covers the basics of liquidity net, including the initial tick, tick delta, the location of the tick, the tick after the price changes, the current liquidity, and how these values change as the price changes. Duration: 6min
5. Math Price Delta
A comprehensive guide to understanding delta price on Uniswap V3. The lesson covers understanding delta price from a liquidity provider's perspective, including how to calculate the amount of token X and Y between Plower and Pupper, and the price after adding or removing Delta X and Delta Y tokens. Duration: 10min
6. Math Swap Fee
A detailed explanation of swap fees in Uniswap V3. This lesson covers the math behind calculating Uniswap V3 swap fees, along with different cases to consider for when the caller specifies an exact amount out or an exact amount in. Duration: 10min
7. Code Walkthrough Swap
A comprehensive guide to the UniswapV3Pool.sol contract - This video walks through the code inside the UniswapV3Pool.sol contract, going over the inputs and outputs of the swap function. The video covers topics like reentrancy protection, gas optimization, and fee calculations. Duration: 13min
8. Exact Input Single
A detailed walkthrough of the Uniswap V3 contract calls. The lesson covers the path parameter, how tokens and fees are encoded for the contract calls, and the call trace when using exact input single function in the contract. Duration: 4min
9. Exact Input
A detailed walkthrough of the exact input function on the UniswapV3Router02 contract - The lesson will cover the different function calls involved in the exact input function as well as the parameters that are passed in for each function call. Duration: 7min
10. Exact Output Single
A comprehensive guide to understanding Uniswap V3's Exact Output Single function. This lesson outlines the core concepts of Exact Output Single and provides a step-by-step breakdown of the call trace, including the functions called in each step of the swap process. Duration: 2min
11. Exact Output
A detailed walkthrough of the Uniswap V3 `exactOutput` function - The lesson covers how to use `exactOutput` to execute a swap involving multiple pools in reverse order, explaining the steps in the process. The user will learn how to call the `exactOutput` function, calculate the amounts of tokens needed for each swap, and how to handle the call trace. Duration: 7min
12. Code Walkthrough Exact Input
A detailed code walkthrough of the contract SwapRouter02 in the Uniswap V3 Router contracts. This lesson covers the functions exactInput, exactInputSingle, and exactInputInternal, explaining how they work and how they are used to execute swaps with single or multiple pools. Duration: 7min
13. Code Walkthrough Exact Output
A deep dive into the code walkthrough for the functions exactOutput and exactOutputSingle - This video breaks down the complex logic of the exactOutput and exactOutputSingle functions in the Uniswap V3 Router contract. The functions are called when a user wants a specific amount of token, but with exactOutputSingle, the amount of the token out is given and exactOutput is used when multiple pools are used to reach the desired token. The lesson explores how these functions interact with Uniswap V3 pools to calculate the required input amount and execute the swap. Duration: 7min
14. Exercise 1 Swap Exact Input Single
A comprehensive guide to UniswapV3 swap router functions - In this lesson, we will take a look at UniswapV3's swap router contract and walk through four exercises on how to use its functions to perform swaps. Duration: 2min
15. Solution 1 Swap Exact Input Single
A practical guide to Uniswap V3 swaps using Foundry. The lesson focuses on performing a simple swap between DAI and WETH on Uniswap V3, setting up the pool fee and recipient parameters and then executing the swap. Duration: 2min
16. Exercise 2 Swap Exact Input
A comprehensive guide to Uniswap v3 swaps using the SwapRouter02 contract. This lesson covers the `exactInput` function and how to prepare the `ExactInputParams` struct for swaps involving multiple tokens. Duration: 1min
17. Solution 2 Swap Exact Input
A comprehensive guide to Uniswap V3 swaps and path encoding. This lesson covers the fundamentals of swapping tokens on Uniswap V3, demonstrating how to encode paths, and provides a detailed example of calling the exact input function on Uniswap V3 Router 02. Duration: 2min
18. Exercise 3 Swap Exact Output Single
A comprehensive guide to using the exactOutputSingle function to swap tokens on Uniswap V3. The lesson covers how to use the exactOutputSingle function to swap a maximum amount of DAI to receive a specific amount of WETH, and how to use the function to define the price limit of the trade. Duration: 1min
19. Solution 3 Swap Exact Output Single
A detailed walkthrough of how to call exactOutputSingle on the Uniswap V3 router contract to execute a swap. The lesson covers how to define the necessary parameters for the function call, including token in, token out, fee, recipient, amount in maximum, and sqrtPriceLimitX96. Duration: 2min
20. Exercise 4 Swap Exact Output
A comprehensive guide to performing an exact output swap on Uniswap V3 - In this lesson, we'll use the exactOutput function on the Uniswap V3 router to perform a series of token swaps. Specifically, we will swap 1000 DAI for WBTC, and then send the WBTC back to our test contract. In the process, we will learn how to use the exactOutput function and how to encode the swap path, paying close attention to the order of the tokens, the recipient address, and the amountOut and amountIn maximum values. Duration: 1min
21. Solution 4 Swap Exact Output
A comprehensive guide to swapping with Uniswap V3 using the exact output function - In this lesson, we'll learn how to use the exact output function in Uniswap V3 to swap tokens. We'll go over how to prepare the parameters for the function, including the path, recipient, amount out, and amount in maximum. We'll also explore how to execute the function and interpret the results. Duration: 2min

Course Overview

About the course

What you'll learn

Concentrated liquidity and derive its equations

Uniswap V3 math

How to calculate the spot price of tokens

Single and multi position swapping

Factory contract architecture

How to calculate liquidity requirements

Uniswap V3 fee algorithm

Flash loans

TWAP price oracle

Course Description

Who is this course for?

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

Potential Careers

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)

Meet your instructors

Tasuku Nakamura

Tasuku Nakamura

Founder at smartcontract.engineer

Smart contract engineer and educator.

Last updated on May 15, 2025