-
Notifications
You must be signed in to change notification settings - Fork 28
/
UniswapV2Liquidity.test.sol
75 lines (63 loc) · 2.21 KB
/
UniswapV2Liquidity.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import {Test, console2} from "forge-std/Test.sol";
import {IERC20} from "../../../src/interfaces/IERC20.sol";
import {IWETH} from "../../../src/interfaces/IWETH.sol";
import {IUniswapV2Router02} from
"../../../src/interfaces/uniswap-v2/IUniswapV2Router02.sol";
import {IUniswapV2Pair} from
"../../../src/interfaces/uniswap-v2/IUniswapV2Pair.sol";
import {
DAI,
WETH,
UNISWAP_V2_ROUTER_02,
UNISWAP_V2_PAIR_DAI_WETH
} from "../../../src/Constants.sol";
contract UniswapV2LiquidityTest is Test {
IWETH private constant weth = IWETH(WETH);
IERC20 private constant dai = IERC20(DAI);
IUniswapV2Router02 private constant router =
IUniswapV2Router02(UNISWAP_V2_ROUTER_02);
IUniswapV2Pair private constant pair =
IUniswapV2Pair(UNISWAP_V2_PAIR_DAI_WETH);
address private constant user = address(100);
function setUp() public {
// Fund WETH to user
deal(user, 100 * 1e18);
vm.startPrank(user);
weth.deposit{value: 100 * 1e18}();
weth.approve(address(router), type(uint256).max);
vm.stopPrank();
// Fund DAI to user
deal(DAI, user, 1000000 * 1e18);
vm.startPrank(user);
dai.approve(address(router), type(uint256).max);
vm.stopPrank();
}
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");
}
function test_removeLiquidity() public {
vm.startPrank(user);
(,, uint256 liquidity) = router.addLiquidity({
tokenA: DAI,
tokenB: WETH,
amountADesired: 1000000 * 1e18,
amountBDesired: 100 * 1e18,
amountAMin: 1,
amountBMin: 1,
to: user,
deadline: block.timestamp
});
pair.approve(address(router), liquidity);
// Exercise - Remove liquidity from DAI / WETH pool
// Write your code here
// Don’t change any other code
vm.stopPrank();
assertEq(pair.balanceOf(user), 0, "LP = 0");
}
}