forked from Cyfrin/advanced-defi-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUniswapV2Arb1.sol
60 lines (55 loc) · 1.87 KB
/
UniswapV2Arb1.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import {IUniswapV2Pair} from
"../../../src/interfaces/uniswap-v2/IUniswapV2Pair.sol";
import {IUniswapV2Router02} from
"../../../src/interfaces/uniswap-v2/IUniswapV2Router02.sol";
import {IERC20} from "../../../src/interfaces/IERC20.sol";
contract UniswapV2Arb1 {
struct SwapParams {
// Router to execute first swap - tokenIn for tokenOut
address router0;
// Router to execute second swap - tokenOut for tokenIn
address router1;
// Token in of first swap
address tokenIn;
// Token out of first swap
address tokenOut;
// Amount in for the first swap
uint256 amountIn;
// Revert the arbitrage if profit is less than this minimum
uint256 minProfit;
}
// Exercise 1
// - Execute an arbitrage between router0 and router1
// - Pull tokenIn from msg.sender
// - Send amountIn + profit back to msg.sender
function swap(SwapParams calldata params) external {
// Write your code here
// Don’t change any other code
}
// Exercise 2
// - Execute an arbitrage between router0 and router1 using flash swap
// - Borrow tokenIn with flash swap from pair
// - Send profit back to msg.sender
/**
* @param pair Address of pair contract to flash swap and borrow tokenIn
* @param isToken0 True if token to borrow is token0 of pair
* @param params Swap parameters
*/
function flashSwap(address pair, bool isToken0, SwapParams calldata params)
external
{
// Write your code here
// Don’t change any other code
}
function uniswapV2Call(
address sender,
uint256 amount0Out,
uint256 amount1Out,
bytes calldata data
) external {
// Write your code here
// Don’t change any other code
}
}