Swap Contract Call

A comprehensive guide to Uniswap V2 Swaps - The lesson covers the different functions the router contract uses to swap between ERC20 tokens and native ETH, as well as how multiple contracts can be called to exchange between tokens not directly supported by a single pool.

Solidity Developer

Uniswap V2

1. Swap Math
An introductory guide to understanding swaps in an automated market maker (AMM) - This lesson covers how to find a formula for calculating the amount of tokens that a user receives after a swap in an AMM. The lesson illustrates these concepts using a basic example where Alice swaps an amount of tokens 'X' for an amount of tokens 'Y', giving a step-by-step derivation of the formula for the amount of token Y that Alice receives. Duration: 5min
2. Swap Fee
A simple explanation of swap fees in Uniswap V2 - This video lesson explains the concept of swap fees in Uniswap V2 by first defining the swap fee rate, then showing how to calculate the swap fee and finally showing how to calculate the token that comes out of a swap after accounting for the swap fee. Duration: 3min
3. Swap Contract Call
A comprehensive guide to Uniswap V2 Swaps - The lesson covers the different functions the router contract uses to swap between ERC20 tokens and native ETH, as well as how multiple contracts can be called to exchange between tokens not directly supported by a single pool. Duration: 4min
4. Code Repo
A thorough breakdown of the Uniswap V2 protocol - Learn how the Uniswap V2 protocol is split into two repos: 'v2-core' and 'v2-periphery'. This lesson dives into the responsibilities of the periphery, including the 'Uniswap V2 Router 02' contract, which handles swapping tokens and adding/removing liquidity. Duration: 2min
5. Code Walk Swap Exact Tokens For Tokens
A detailed look at the code for UniSwap V2 Router swap functions - This video lesson takes a detailed look at the code for the UniSwap V2 Router swap functions. We will cover two functions in this lesson: swapExactTokensForTokens and swapTokensForExactTokens. We will also discuss the internal function called swap, and explain how each function calculates the amount of tokens to transfer for a given input. Duration: 7min
6. Code Walk Get Amounts Out
A detailed explanation of the `getAmountOut` function from the UniswapV2Library Solidity code. The lesson covers how the function works, what calculations are being performed, how the code is structured, and how it relates to other UniswapV2 functions like `getAmountIn` and `getReserves`. Duration: 5min
7. Get Amounts Out Fork
A practical example of UniswapV2Library.getAmoutsOut - This lesson demonstrates how to use the UniswapV2Library.getAmoutsOut function by calling it within a test. We set up a path using the addresses of WETH, DAI, and MKR tokens and then use the function to determine the expected output for a trade with an input amount of 1 WETH. Duration: 5min
8. Get Amounts Out Example
A technical walkthrough of the Uniswap V2 library 'getAmountsOut' function. The video steps through an example of how this function works by showing how each iteration of the code populates an array of amounts with the expected values, given an initial amount of 1 ETH and a path of WETH, DAI, and MKR. Duration: 4min
9. Code Walk Swap Tokens For Exact Tokens
A comprehensive guide to the UniSwap V2 Router's swapTokensForExactTokens function. The lesson covers the function's purpose, how it works with other functions, and its application in swapping tokens for exact amounts. Duration: 2min
10. Code Walk Get Amounts In
A detailed code walkthrough of the function getAmountIn in Uniswap V2 library - The lesson covers how the function calculates the required amount of tokens to get a certain amount of token out after a swap, along with its mathematical derivation. Duration: 5min
11. Get Amounts In Fork
A practical guide to testing the getAmountIn function from Uniswap V2 library - The lesson covers writing a Foundry test to test getAmountIn function. It then steps through testing the function by using a specific path for the swap. Duration: 3min
12. Get Amounts In Example
A step-by-step walkthrough of the getAmountsIn function in the Uniswap V2 library. This lesson covers how the function works using an example that iterates over a path of three tokens - WETH, DAI, and MKR. This process uses the getReserves function to determine the amount of each token needed to achieve the desired amount of the last token in the path. Duration: 4min
13. Code Walk Swap Pair
A detailed code walkthrough of the Uniswap V2 Pair smart contract's swap function. The lesson covers how the swap function calculates the amount of tokens that came in, transfers one token for the other, and avoids stack too deep errors by wrapping code inside curly braces. Duration: 10min
14. Swap Ex 1
A comprehensive guide to Uniswap V2 router smart contracts. The lesson covers the basic setup for Uniswap V2 Router 02, the function swapExactTokensForTokens, and how to test that a swap has been successful using a simulated transaction. Duration: 2min
15. Swap Ex 1 Sol
A comprehensive guide to understanding multi-hop swaps using Uniswap V2 Router. This lesson goes over testing an existing function called swapExactTokensForTokens, and covers how to simulate a transaction, use a forked mainnet environment, and output logs from your test. Duration: 3min
16. Swap Ex 2
A comprehensive overview of a Uniswap V2 Router smart contract - This lesson covers two functions included in the Uniswap V2 Router contract. The first function, "swapExactTokensForTokens", allows the user to exchange any number of tokens in for as many tokens out as possible. The second function, "swapTokensForExactTokens" allows the user to specify an exact amount of tokens out in exchange for a minimum amount of tokens in. Duration: 2min
17. Swap Ex 2 Sol
A comprehensive guide to testing a Uniswap V2 smart contract. This lesson covers how to set up a unit test to run against your contract using the Foundry testing framework. It demonstrates how to set up a unit test, include input parameters, and perform assertions to ensure the function returns the expected result. Duration: 2min
18. Spot Price Graph
A simple demonstration of the exchange rate in a Uniswap v2 AMM - This lesson explains how the slope of a tangent line to the liquidity curve of a Uniswap v2 AMM can be used to calculate the exchange rate between two tokens. The lesson also explains how the exchange rate changes with the size of the trade. Duration: 2min
19. Spot Price Math
A simple introduction to calculating the spot price of a token in an AMM. The lesson covers the concept of spot price, the formula used to calculate spot price, and how that formula is derived. Duration: 4min
20. Slippage
An illustrative explanation of slippage in AMMs - This video covers what slippage is in the context of automated market makers (AMMs), explaining the concept using an example, and detailing how slippage is caused by market movement. Duration: 6min

Course Overview

About the course

What you'll learn

How to use Uniswap v2 dex and contracts

Interacting with the Uniswap v2 router and factory

How to create Uniswap v2 liquidity pools

How to add liquidity to Uniswap v2 pools

Swaps, flash swaps, flash swap arbitrage, and time-weighted average price (TWAP)

Course Description

Who is this course for?

  • Advanced smart contract engineers
  • Web3 developers
  • Smart Contract Security researchers

Potential Careers

Security researcher

$49,999 - $120,000 (avg. salary)

Smart Contract Auditor

$100,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 October 9, 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