5/5
### Solution for Exercise 1: Getting the DAI/USDC Pool Address Let's walk through the solution for Exercise 1. Our goal is to get the address of the liquidity pool for the DAI/USDC pair with a 0.1% fee. To get the pool address, we need to call the `getPool` method from the `factory` object: ```javascript address pool = factory.getPool ``` Looking at the `IUniswapV3Factory` interface, we see the `getPool` function takes three parameters: the address of tokenA, the address of tokenB, and the pool fee, which is a `uint24`. ```javascript function getPool(address tokenA, address tokenB, uint24 fee) ``` In our scenario, the order in which we pass DAI and USDC doesn't matter, as we'll end up with the same pool address regardless. Let's add the DAI, USDC, and fee parameters into the `getPool` method: ```javascript address pool = factory.getPool(DAI, USDC, 100) ``` The question now is, how do we get 100 for the fee? The pool fee is calculated with a denominator of 10^6 or 1e6. Since we want 0.1%, we calculate this as 100 / 1e6. You can verify this using a calculator. The complete code for Exercise 1 is: ```javascript address pool = factory.getPool(DAI, USDC, 100); ``` Before running the test, let's remove Exercise 2's code temporarily: ```javascript function test_createPool() public { } ``` Now, let's execute our test. First, we need to set the `FORK_URL` environment variable in the terminal: ```bash FORK_URL=https://eth-mainnet.g.alchemy.com/v2/... ``` Then we run the test using `forge`: ```bash forge test --fork-url $FORK_URL --match-path test/uniswap-v3/exercises/UniswapV3Factory.test.sol ``` We can see that our test has passed successfully.
Let's walk through the solution for Exercise 1. Our goal is to get the address of the liquidity pool for the DAI/USDC pair with a 0.1% fee.
To get the pool address, we need to call the getPool
method from the factory
object:
Looking at the IUniswapV3Factory
interface, we see the getPool
function takes three parameters: the address of tokenA, the address of tokenB, and the pool fee, which is a uint24
.
In our scenario, the order in which we pass DAI and USDC doesn't matter, as we'll end up with the same pool address regardless.
Let's add the DAI, USDC, and fee parameters into the getPool
method:
The question now is, how do we get 100 for the fee? The pool fee is calculated with a denominator of 10^6 or 1e6. Since we want 0.1%, we calculate this as 100 / 1e6. You can verify this using a calculator.
The complete code for Exercise 1 is:
Before running the test, let's remove Exercise 2's code temporarily:
Now, let's execute our test. First, we need to set the FORK_URL
environment variable in the terminal:
Then we run the test using forge
:
We can see that our test has passed successfully.
A comprehensive guide to Uniswap V3 Factory. This lesson will help you understand how to use the Uniswap V3 Factory to create and manage pools on the Uniswap V3 exchange. We will go through the interface and how to call functions to interact with pools.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
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
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)
Last updated on August 11, 2025
Duration: 3min
Duration: 35min
Duration: 25min
Duration: 22min
Duration: 1h 43min
Duration: 11min
Duration: 1h 03min
Duration: 12min
Duration: 51min
Duration: 41min
Duration: 10min
Duration: 7min
Course Overview
About the course
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
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)
Last updated on August 11, 2025