Add Liq Code Walk

A detailed look at the Uniswap V2 Router code - This lesson covers how Uniswap V2 Router handles adding liquidity to a B2 pair, including how it calculates the amount of each token needed based on the current reserves and how it utilizes the Uniswap V2 Library to perform the quote.

Solidity Developer

Uniswap V2

1. Pool Shares Intro
A simple explanation of how Uniswap V2 mints pool shares - This lesson helps understand how Uniswap V2 works, specifically in the context of how a pool mints shares when users deposit tokens. It illustrates how the pool uses a simple equation to determine how many shares to mint based on the existing token pool and the tokens a user deposits. Duration: 5min
2. Pool Shares Mint Math
A simple equation to calculate mint pool shares - The lesson covers how to calculate the number of shares to mint for a user who deposits USDC into a Uniswap v2 pair contract. The lesson defines the variables used in the equation, derives the equation, and explains how to use the equation to solve for the number of shares to mint. Duration: 3min
3. Pool Shares Mint Math Example
A practical guide to understanding share minting in liquidity pools - This lesson walks through how to calculate the number of shares to mint after a deposit has been made into a liquidity pool, showing the relationship between shares and the overall value of the pool. Duration: 2min
4. Pool Shares Burn
A simple example of a burn pool in action. This lesson covers how a burn pool functions and how the pool contract divides USDC amongst users that burn their shares. Duration: 1min
5. Pool Shares Burn Math
A mathematical breakdown of how to burn pool shares - This lesson goes through the mathematical formula for burning shares in a liquidity pool. The equation is broken down in detail to understand how the values L0 and L1 change when shares are burnt. Duration: 3min
6. Pool Shares Burn Example
A simple explanation of how the amount of USDC is calculated when burning shares in a liquidity pool - This lesson covers the ratio of share to total share in a liquidity pool and how that ratio is applied to calculate the USDC reward to the user for burning shares. The lesson provides a numerical example to illustrate this process. Duration: 2min
7. Add Liq Graph
A visual explanation of how adding liquidity to a Uniswap V2 pool affects the spot price of a token. The lesson explains that when liquidity is added to a constant product AMM, the product of the tokens before and after adding liquidity must be the same. Adding liquidity shifts the curve, but the price remains the same. The lesson also shows that the amount of tokens to add is determined by the slope of a line drawn from the origin to the point representing the current amount of tokens in the pool. The slope of this line must be equal to the spot price of the token. Duration: 5min
8. Add Liq Math
A mathematical derivation of how to add liquidity to a constant product AMM. The lesson covers why liquidity must be added in a certain ratio to ensure that the price after adding liquidity is equal to the price before adding liquidity. Duration: 4min
9. Add Liq Pool Shares Math Intro
A practical equation to calculate pool shares to mint - This lesson will teach you how to combine two previous equations to derive the amount of shares you would need to mint when you provide some amount of tokens to an AMM. Duration: 2min
10. Add Liq Pool Shares Math Liq Funcs
A simple explanation of liquidity in automated market makers - This lesson covers the definition of liquidity and how it changes as the amount of tokens in an automated market maker change. The lesson also defines the pool value as a function of the token amounts and shows the derivation of the relationship between changes in liquidity and the ratio of changes in token amounts. Duration: 1min
11. Add Liq Pool Shares Math Sqrt
A technical explanation of the formula used to calculate pool value. The lesson covers the derivation of the pool value formula using the square root of the product of the pool's token quantities, demonstrating its application in a real-world scenario. Duration: 4min
12. Add Liq Pool Shares Math 2x
An advanced guide to liquidity impermanent loss - This lesson covers two approaches to calculating liquidity impermanent loss. First, the lesson uses a function that takes in the amounts of each token in the pool and returns a value based on one of the tokens in the pool. Next, the lesson goes over a method of calculating the difference in liquidity before and after adding liquidity to a pool by using the function defined in the first part of the lesson. Duration: 3min
13. Add Liq Pool Shares Math Summary
A detailed explanation of how to calculate pool shares in a liquidity pool - This lesson covers calculating the number of shares to be minted in a liquidity pool based on the liquidity before and after adding liquidity. The lesson also examines how to relate the changes in liquidity in a pool to the changes in the token amounts. Duration: 1min
14. Add Liq Contract Call
A visual overview of Uniswap V2's add liquidity process. This lesson covers the steps that are taken when an individual provides liquidity to a Uniswap trading pool. The lesson covers how the router, factory, and pair contracts interact during the add liquidity process and explains how the router contract transfers tokens directly to the pair contract before a mint function is called on the pair contract. Duration: 1min
15. Add Liq Code Walk
A detailed look at the Uniswap V2 Router code - This lesson covers how Uniswap V2 Router handles adding liquidity to a B2 pair, including how it calculates the amount of each token needed based on the current reserves and how it utilizes the Uniswap V2 Library to perform the quote. Duration: 7min
16. Add Liq Code Walk Mint
A detailed code walkthrough of the Uniswap V2 Pair contract’s mint function - This lesson covers the key steps of the mint function including how internal balances are used, how liquidity is calculated when there is no prior liquidity, how to protect against vault inflation attacks, and how protocol fees are accounted for. Duration: 4min
17. Add Liq Ex
A comprehensive guide to adding liquidity to a DAI/WETH pool using the UniswapV2Router contract. This lesson covers the fundamentals of using UniswapV2Router to add liquidity to a pair, including passing the correct token addresses, understanding the function parameters, and testing the liquidity addition process. Duration: 1min
18. Add Liq Ex Sol
A comprehensive guide to adding liquidity to a Uniswap V2 pool - The lesson covers using a test to ensure you have properly added liquidity to a Uniswap V2 pool. It demonstrates how to send in tokens and set minimum amounts that the pair must receive. The code also prints out various parameters for reference. Duration: 5min

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