0/5
In this lesson, we'll learn how to add liquidity to a DAI/WETH pair using the UniswapV2Router contract. We'll call the addLiquidity function inside the UniswapV2Router contract, passing in the following arguments: - TokenA: WETH - TokenB: DAI - AmountADesired: any amount of WETH - AmountBDesired: any amount of DAI We'll also need to make sure that the amount of WETH and DAI we pass in is less than or equal to the balances of these tokens that we've set up in our test. ```javascript function test_addLiquidity() public { // Exercise - Add Liquidity to DAI / WETH pool // Write your code here // Don't change any other code vm.prank(user); assertGt(pair.balanceOf(user), 0, "LP > 0"); } ``` The test will check that the user has received some shares of the pool after we call the addLiquidity function. The setup in our test has the following balances: - WETH: 100 - DAI: 1,000,000 We'll use the `vm.prank(user)` function to simulate sending this transaction from the user account that we've set up in our test. The test will run this transaction and we'll be able to see in the console that our user has received some shares in the DAI/WETH pool.
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.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
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)
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)
Last updated on October 9, 2024
Solidity Developer
Uniswap V2Duration: 14min
Duration: 1h 20min
Duration: 10min
Duration: 54min
Duration: 25min
Duration: 26min
Duration: 1h 03min
Duration: 59min
Course Overview
About the course
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)
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)
Last updated on October 9, 2024
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar