-
Notifications
You must be signed in to change notification settings - Fork 23
/
UniswapV3Factory.test.sol
51 lines (44 loc) · 1.65 KB
/
UniswapV3Factory.test.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import {Test, console2} from "forge-std/Test.sol";
import {IUniswapV3Factory} from
"../../../src/interfaces/uniswap-v3/IUniswapV3Factory.sol";
import {IUniswapV3Pool} from
"../../../src/interfaces/uniswap-v3/IUniswapV3Pool.sol";
import {
UNISWAP_V3_FACTORY,
DAI,
USDC,
UNISWAP_V3_POOL_DAI_USDC_100
} from "../../../src/Constants.sol";
import {ERC20} from "../../../src/ERC20.sol";
contract UniswapV3FactoryTest is Test {
IUniswapV3Factory private factory = IUniswapV3Factory(UNISWAP_V3_FACTORY);
// 3000 = 0.3%
// 100 = 0.01%
uint24 private constant POOL_FEE = 100;
ERC20 private tokenA;
ERC20 private tokenB;
function setUp() public {
tokenA = new ERC20("A", "A", 18);
tokenB = new ERC20("B", "B", 18);
}
// Exercise 1 - Get the address of DAI/USDC (0.1% fee) pool
function test_getPool() public {
// Write your code here
address pool = factory.getPool(DAI, USDC, 100);
assertEq(pool, UNISWAP_V3_POOL_DAI_USDC_100);
}
// Exercise 2 - Deploy a new pool with tokenA and tokenB, 0.1% fee
function test_createPool() public {
// Write your code here
address pool =
factory.createPool(address(tokenA), address(tokenB), POOL_FEE);
(address token0, address token1) = address(tokenA) <= address(tokenB)
? (address(tokenA), address(tokenB))
: (address(tokenB), address(tokenA));
assertEq(IUniswapV3Pool(pool).token0(), token0);
assertEq(IUniswapV3Pool(pool).token1(), token1);
assertEq(IUniswapV3Pool(pool).fee(), POOL_FEE);
}
}