-
Notifications
You must be signed in to change notification settings - Fork 0
/
BundleExecutor-after.sol
67 lines (56 loc) · 1.75 KB
/
BundleExecutor-after.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./shared.sol";
contract FlashBotsMultiCall {
address private immutable owner;
address private immutable executor;
IWETH private constant WETH =
IWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
modifier onlyExecutor() {
require(msg.sender == executor);
_;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
constructor(address _executor) payable {
owner = msg.sender;
executor = _executor;
if (msg.value > 0) {
WETH.deposit{value: msg.value}();
}
}
receive() external payable {}
function uniswapWeth(
uint256 _wethAmountToFirstMarket,
uint256 _gasCost,
uint256 _wethBalanceBefore,
address[] calldata _targets,
bytes[] calldata _payloads
) external payable onlyExecutor {
require(_targets.length == _payloads.length);
WETH.transfer(_targets[0], _wethAmountToFirstMarket);
for (uint256 i = 0; i < _targets.length; i++) {
(bool _success, bytes memory _response) = _targets[i].call(
_payloads[i]
);
require(_success);
_response;
}
uint256 _wethBalanceAfter = WETH.balanceOf(address(this));
unchecked {
require(_wethBalanceAfter > _wethBalanceBefore + _gasCost, "np");
}
}
function call(
address payable _to,
uint256 _value,
bytes calldata _data
) external payable onlyOwner returns (bytes memory) {
require(_to != address(0));
(bool _success, bytes memory _result) = _to.call{value: _value}(_data);
require(_success);
return _result;
}
}