From c15287e2aef61bfd922dad7d9f375e744a7791f1 Mon Sep 17 00:00:00 2001 From: Mike Casale <46603283+mikewcasale@users.noreply.github.com> Date: Mon, 31 Jul 2023 06:36:25 -0700 Subject: [PATCH 1/4] Adds test for the min bnt issue. --- log.txt | 1 + main.py | 4 +- ...BTest_905_RespectMinProfitClickParam.ipynb | 287 ++++++++++++++++++ .../NBTest_905_RespectMinProfitClickParam.py | 100 ++++++ 4 files changed, 391 insertions(+), 1 deletion(-) create mode 100644 log.txt create mode 100644 resources/NBTest/NBTest_905_RespectMinProfitClickParam.ipynb create mode 100644 resources/NBTest/NBTest_905_RespectMinProfitClickParam.py diff --git a/log.txt b/log.txt new file mode 100644 index 000000000..012d8253c --- /dev/null +++ b/log.txt @@ -0,0 +1 @@ +Searching for main.py in /Users/mikewcasale/Documents/GitHub/fastlane-bot \ No newline at end of file diff --git a/main.py b/main.py index 50822b026..9c224e3c2 100644 --- a/main.py +++ b/main.py @@ -607,6 +607,9 @@ def update_pools_from_contracts( del bot bot = init_bot(mgr) + assert bot.ConfigObj.DEFAULT_MIN_PROFIT == mgr.cfg.DEFAULT_MIN_PROFIT, "bot failed to update min profit" + mgr.cfg.logger.debug("Bot successfully updated min profit") + # Compare the initial state to the final state, and update the state if it has changed final_state = mgr.pool_data.copy() assert bot.db.state == final_state, "\n *** bot failed to update state *** \n" @@ -637,7 +640,6 @@ def update_pools_from_contracts( # Sleep for the polling interval time.sleep(polling_interval) - print(f"timeout: {timeout}") if timeout is not None and time.time() - start_timeout > timeout: mgr.cfg.logger.info("Timeout hit... stopping bot") break diff --git a/resources/NBTest/NBTest_905_RespectMinProfitClickParam.ipynb b/resources/NBTest/NBTest_905_RespectMinProfitClickParam.ipynb new file mode 100644 index 000000000..9bbbf3235 --- /dev/null +++ b/resources/NBTest/NBTest_905_RespectMinProfitClickParam.ipynb @@ -0,0 +1,287 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 4, + "id": "initial_id", + "metadata": { + "ExecuteTime": { + "end_time": "2023-07-31T13:31:38.164934Z", + "start_time": "2023-07-31T13:31:38.131008Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ConstantProductCurve v2.14 (23/May/2023)\n", + "CarbonBot v3-b2.2 (20/June/2023)\n", + "UniswapV2 v0.0.1 (2023-07-03)\n", + "UniswapV3 v0.0.1 (2023-07-03)\n", + "SushiswapV2 v0.0.1 (2023-07-03)\n", + "CarbonV1 v0.0.1 (2023-07-03)\n", + "BancorV3 v0.0.1 (2023-07-03)\n", + "Version = 3-b2.2 [requirements >= 3.0 is met]\n" + ] + } + ], + "source": [ + "# coding=utf-8\n", + "\"\"\"\n", + "This module contains the tests which ensure that the minimum profit BNT parameter is respected.\n", + "\"\"\"\n", + "from fastlane_bot import Bot\n", + "from fastlane_bot.tools.cpc import ConstantProductCurve as CPC\n", + "from fastlane_bot.events.exchanges import UniswapV2, UniswapV3, SushiswapV2, CarbonV1, BancorV3\n", + "import subprocess, os, sys\n", + "import pytest\n", + "print(\"{0.__name__} v{0.__VERSION__} ({0.__DATE__})\".format(CPC))\n", + "print(\"{0.__name__} v{0.__VERSION__} ({0.__DATE__})\".format(Bot))\n", + "print(\"{0.__name__} v{0.__VERSION__} ({0.__DATE__})\".format(UniswapV2))\n", + "print(\"{0.__name__} v{0.__VERSION__} ({0.__DATE__})\".format(UniswapV3))\n", + "print(\"{0.__name__} v{0.__VERSION__} ({0.__DATE__})\".format(SushiswapV2))\n", + "print(\"{0.__name__} v{0.__VERSION__} ({0.__DATE__})\".format(CarbonV1))\n", + "print(\"{0.__name__} v{0.__VERSION__} ({0.__DATE__})\".format(BancorV3))\n", + "from fastlane_bot.testing import *\n", + "plt.rcParams['figure.figsize'] = [12,6]\n", + "from fastlane_bot import __VERSION__\n", + "require(\"3.0\", __VERSION__)" + ] + }, + { + "cell_type": "markdown", + "id": "dfafc69730cbead3", + "metadata": {}, + "source": [ + "# Setup" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "1640a40ee6ae871c", + "metadata": { + "ExecuteTime": { + "end_time": "2023-07-31T13:31:38.184588Z", + "start_time": "2023-07-31T13:31:38.141260Z" + } + }, + "outputs": [], + "source": [ + "def find_main_py():\n", + " # Start at the directory of the current script\n", + " cwd = os.path.abspath(os.path.join(os.getcwd()))\n", + " \n", + " print(f\"Searching for main.py in {cwd}\")\n", + " while True:\n", + " # Check if main.py exists in the current directory\n", + " if \"main.py\" in os.listdir(cwd):\n", + " return cwd # Found the directory containing main.py\n", + " else:\n", + " # If not, go up one directory\n", + " new_cwd = os.path.dirname(cwd)\n", + "\n", + " # If we're already at the root directory, stop searching\n", + " if new_cwd == cwd:\n", + " raise FileNotFoundError(\"Could not find main.py in any parent directory\")\n", + "\n", + " cwd = new_cwd\n", + " \n", + " \n", + "def run_command(arb_mode, expected_log_line):\n", + " \n", + " # Find the correct path to main.py\n", + " main_script_path = find_main_py()\n", + " print(f\"Found main.py in {main_script_path}\")\n", + " main_script_path = main_script_path + \"/main.py\"\n", + "\n", + " # Run the command\n", + " cmd = [\n", + " \"python\",\n", + " main_script_path,\n", + " f\"--arb_mode={arb_mode}\",\n", + " \"--default_min_profit_bnt=60\",\n", + " \"--limit_bancor3_flashloan_tokens=False\",\n", + " \"--use_cached_events=True\",\n", + " \"--logging_path=fastlane_bot/data/\",\n", + " \"--timeout=45\",\n", + " \"--loglevel=DEBUG\",\n", + " ]\n", + " subprocess.Popen(cmd)\n", + " \n", + " # Wait for the expected log line to appear\n", + " found = False\n", + " result = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=60)\n", + "\n", + " # Check if the expected log line is in the output\n", + " if expected_log_line in result.stderr or expected_log_line in result.stdout:\n", + " found = True\n", + "\n", + " if not found:\n", + " pytest.fail(\"Expected log line was not found within 1 minute\") # If we reach this point, the test has failed" + ] + }, + { + "cell_type": "markdown", + "id": "614f482aec4be2f8", + "metadata": {}, + "source": [ + "## Test Minimum Profit BNT Is Respected" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "c6e198d0eeba3183", + "metadata": { + "ExecuteTime": { + "end_time": "2023-07-31T13:32:35.094624Z", + "start_time": "2023-07-31T13:31:38.145856Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Searching for main.py in /Users/mikewcasale/Documents/GitHub/fastlane-bot/resources/NBTest\n", + "Found main.py in /Users/mikewcasale/Documents/GitHub/fastlane-bot\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-07-31 06:31:41,451 [fastlane:INFO] - Using mainnet config\n", + "2023-07-31 06:31:41,452 [fastlane:INFO] - Running data fetching for exchanges: ['carbon_v1', 'bancor_v3', 'uniswap_v3', 'uniswap_v2', 'sushiswap_v2']\n", + "2023-07-31 06:31:41,740 [fastlane:INFO] - Time taken to add initial pools: 0.08876180648803711\n", + "2023-07-31 06:31:41,950 [fastlane:INFO] - Fetching events from 17811304 to 17813304... 0\n", + "2023-07-31 06:31:41,950 [fastlane:INFO] - Using cached events\n", + "2023-07-31 06:31:41,950 [fastlane:INFO] - Found 25 new events\n", + "2023-07-31 06:31:44,370 [fastlane:INFO] - Updating carbon pools w/ multicall...\n", + "2023-07-31 06:31:45,277 [fastlane:INFO] - Fetched 250 carbon strategies in 0.9065101146697998 seconds\n", + "2023-07-31 06:31:49,886 [fastlane:INFO] - Updated 250 carbon strategies info in 4.609120845794678 seconds\n", + "2023-07-31 06:32:07,245 [fastlane:INFO] - Initializing the bot...\n", + "2023-07-31 06:32:07,350 [fastlane:DEBUG] - Bot successfully updated min profit\n", + "2023-07-31 06:32:07,350 [fastlane:INFO] - State has changed...\n", + "2023-07-31 06:32:07,355 [fastlane:INFO] - Removed 122 unmapped uniswap_v2/sushi pools. 5047 uniswap_v2/sushi pools remaining\n", + "2023-07-31 06:32:07,355 [fastlane:INFO] - Unmapped uniswap_v2/sushi pools:\n", + "2023-07-31 06:32:07,654 [fastlane:INFO] - uniswap_v3: 0\n", + "2023-07-31 06:32:07,654 [fastlane:INFO] - uniswap_v2: 122\n", + "2023-07-31 06:32:07,654 [fastlane:INFO] - sushiswap_v2: 0\n", + "2023-07-31 06:32:19,758 [fastlane:INFO] - Fetching events from 17813304 to 17813307... 17813304\n", + "2023-07-31 06:32:19,758 [fastlane:INFO] - Using cached events\n", + "2023-07-31 06:32:19,758 [fastlane:INFO] - Found 25 new events\n", + "2023-07-31 06:32:22,399 [fastlane:INFO] - Initializing the bot...\n", + "2023-07-31 06:32:22,508 [fastlane:DEBUG] - Bot successfully updated min profit\n", + "2023-07-31 06:32:22,512 [fastlane:INFO] - Removed 122 unmapped uniswap_v2/sushi pools. 5047 uniswap_v2/sushi pools remaining\n", + "2023-07-31 06:32:22,512 [fastlane:INFO] - Unmapped uniswap_v2/sushi pools:\n", + "2023-07-31 06:32:22,815 [fastlane:INFO] - uniswap_v3: 0\n", + "2023-07-31 06:32:22,815 [fastlane:INFO] - uniswap_v2: 122\n", + "2023-07-31 06:32:22,815 [fastlane:INFO] - sushiswap_v2: 0\n", + "2023-07-31 06:32:22,817 [fastlane:INFO] - uniswap_v3: 11\n", + "2023-07-31 06:32:22,817 [fastlane:INFO] - sushiswap_v2: 2\n", + "2023-07-31 06:32:22,817 [fastlane:INFO] - uniswap_v2: 13\n", + "2023-07-31 06:32:22,817 [fastlane:INFO] - bancor_v2: 0\n", + "2023-07-31 06:32:22,817 [fastlane:INFO] - bancor_v3: 34\n", + "2023-07-31 06:32:22,817 [fastlane:INFO] - carbon_v1: 250\n", + "2023-07-31 06:32:22,832 [fastlane:INFO] - uniswap_v3_zero_liquidity_pools: 1483\n", + "2023-07-31 06:32:22,832 [fastlane:INFO] - sushiswap_v2_zero_liquidity_pools: 87\n", + "2023-07-31 06:32:22,832 [fastlane:INFO] - uniswap_v2_zero_liquidity_pools: 3130\n", + "2023-07-31 06:32:22,832 [fastlane:INFO] - bancor_v2_zero_liquidity_pools: 0\n", + "2023-07-31 06:32:22,832 [fastlane:INFO] - bancor_v3_zero_liquidity_pools: 37\n", + "2023-07-31 06:32:22,832 [fastlane:INFO] - carbon_v1_zero_liquidity_pools: 0\n", + "2023-07-31 06:32:22,833 [fastlane:INFO] - Removed 0 unsupported exchanges. 310 pools remaining\n", + "2023-07-31 06:32:22,833 [fastlane:INFO] - Pools remaining per exchange:\n", + "2023-07-31 06:32:22,833 [fastlane:INFO] - carbon_v1: 250\n", + "2023-07-31 06:32:22,833 [fastlane:INFO] - bancor_v3: 34\n", + "2023-07-31 06:32:22,833 [fastlane:INFO] - uniswap_v3: 11\n", + "2023-07-31 06:32:22,833 [fastlane:INFO] - uniswap_v2: 13\n", + "2023-07-31 06:32:22,833 [fastlane:INFO] - sushiswap_v2: 2\n", + "2023-07-31 06:32:22,836 [fastlane:DEBUG] - [_carbon_to_cpc] error in curve 1 [probably empty: {'cid': '1701411834604692317316873037158841057285-1', 'yint': Decimal('0.006039951546952498'), 'y': Decimal('0.006039951546952498'), 'pb': Decimal('0E-12'), 'pa': Decimal('0E-12'), 'tkny': 'WETH-6Cc2', 'pair': 'WETH-6Cc2/USDC-eB48', 'params': {'exchange': 'carbon_v1', 'tknx_dec': 18, 'tkny_dec': 6, 'tknx_addr': '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17813306}, 'fee': 0.002, 'descr': 'carbon_v1 ETH-EEeE/USDC-eB48 0.002'}] - [pa > pb required (0.0, 0.0)]\n", + "\n", + "2023-07-31 06:32:22,836 [fastlane:DEBUG] - [_carbon_to_cpc] error in curve 1 [probably empty: {'cid': '1701411834604692317316873037158841057339-1', 'yint': Decimal('0.00057166313905193'), 'y': Decimal('0.00057166313905193'), 'pb': Decimal('0E-12'), 'pa': Decimal('0E-12'), 'tkny': 'WETH-6Cc2', 'pair': 'WETH-6Cc2/USDC-eB48', 'params': {'exchange': 'carbon_v1', 'tknx_dec': 18, 'tkny_dec': 6, 'tknx_addr': '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17813306}, 'fee': 0.002, 'descr': 'carbon_v1 ETH-EEeE/USDC-eB48 0.002'}] - [pa > pb required (0.0, 0.0)]\n", + "\n", + "2023-07-31 06:32:22,836 [fastlane:DEBUG] - [_carbon_to_cpc] error in curve 0 [probably empty: {'cid': '1701411834604692317316873037158841057343-0', 'yint': Decimal('1987.061039'), 'y': Decimal('1987.061039'), 'pb': Decimal('0'), 'pa': Decimal('0'), 'tkny': 'USDC-eB48', 'pair': 'WETH-6Cc2/USDC-eB48', 'params': {'exchange': 'carbon_v1', 'tknx_dec': 18, 'tkny_dec': 6, 'tknx_addr': '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17813306}, 'fee': 0.002, 'descr': 'carbon_v1 ETH-EEeE/USDC-eB48 0.002'}] - [pa > pb required (0.0, 0.0)]\n", + "\n", + "2023-07-31 06:32:22,836 [fastlane:DEBUG] - [_carbon_to_cpc] error in curve 1 [probably empty: {'cid': '1701411834604692317316873037158841057365-1', 'yint': Decimal('0.009882507039899549'), 'y': Decimal('0.009882507039899549'), 'pb': Decimal('0E-12'), 'pa': Decimal('0E-12'), 'tkny': 'WETH-6Cc2', 'pair': 'WETH-6Cc2/USDC-eB48', 'params': {'exchange': 'carbon_v1', 'tknx_dec': 18, 'tkny_dec': 6, 'tknx_addr': '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17813306}, 'fee': 0.002, 'descr': 'carbon_v1 ETH-EEeE/USDC-eB48 0.002'}] - [pa > pb required (0.0, 0.0)]\n", + "\n", + "2023-07-31 06:32:22,837 [fastlane:DEBUG] - [_carbon_to_cpc] error in curve 0 [probably empty: {'cid': '1701411834604692317316873037158841057439-0', 'yint': Decimal('300'), 'y': Decimal('300'), 'pb': Decimal('0'), 'pa': Decimal('0'), 'tkny': 'USDC-eB48', 'pair': 'WETH-6Cc2/USDC-eB48', 'params': {'exchange': 'carbon_v1', 'tknx_dec': 18, 'tkny_dec': 6, 'tknx_addr': '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17813306}, 'fee': 0.002, 'descr': 'carbon_v1 ETH-EEeE/USDC-eB48 0.002'}] - [pa > pb required (0.0, 0.0)]\n", + "\n", + "2023-07-31 06:32:22,837 [fastlane:DEBUG] - [_carbon_to_cpc] error in curve 1 [probably empty: {'cid': '1701411834604692317316873037158841057439-1', 'yint': Decimal('0.1'), 'y': Decimal('0.1'), 'pb': Decimal('0E-12'), 'pa': Decimal('0E-12'), 'tkny': 'WETH-6Cc2', 'pair': 'WETH-6Cc2/USDC-eB48', 'params': {'exchange': 'carbon_v1', 'tknx_dec': 18, 'tkny_dec': 6, 'tknx_addr': '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17813306}, 'fee': 0.002, 'descr': 'carbon_v1 ETH-EEeE/USDC-eB48 0.002'}] - [pa > pb required (0.0, 0.0)]\n", + "\n", + "2023-07-31 06:32:22,839 [fastlane:DEBUG] - [_carbon_to_cpc] error in curve 1 [probably empty: {'cid': '5784800237655953878877368326340059594782-1', 'yint': Decimal('50.90664577252261339'), 'y': Decimal('50.90664577252261339'), 'pb': Decimal('0'), 'pa': Decimal('0'), 'tkny': 'RPL-A51f', 'pair': 'RPL-A51f/XCHF-fc08', 'params': {'exchange': 'carbon_v1', 'tknx_dec': 18, 'tkny_dec': 18, 'tknx_addr': '0xD33526068D116cE69F19A9ee46F0bd304F21A51f', 'tkny_addr': '0xB4272071eCAdd69d933AdcD19cA99fe80664fc08', 'blocklud': 17813306}, 'fee': 0.002, 'descr': 'carbon_v1 RPL-A51f/XCHF-fc08 0.002'}] - [pa > pb required (0.0, 0.0)]\n", + "\n", + "2023-07-31 06:32:22,840 [fastlane:DEBUG] - [_carbon_to_cpc] error in curve 1 [probably empty: {'cid': '15652988878363169319315231941861337727077-1', 'yint': Decimal('0.02262429'), 'y': Decimal('0.02262429'), 'pb': Decimal('0'), 'pa': Decimal('0'), 'tkny': 'WBTC-C599', 'pair': 'WBTC-C599/rETH-6393', 'params': {'exchange': 'carbon_v1', 'tknx_dec': 8, 'tkny_dec': 18, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xae78736Cd615f374D3085123A210448E74Fc6393', 'blocklud': 17813306}, 'fee': 0.002, 'descr': 'carbon_v1 WBTC-C599/rETH-6393 0.002'}] - [pa > pb required (0.0, 0.0)]\n", + "\n", + "2023-07-31 06:32:22,844 [fastlane:DEBUG] - \n", + " ************ combos: 540 ************\n", + "\n", + "2023-07-31 06:32:22,850 [fastlane:DEBUG] - Profit in bnt: -0.0000 ['0x7c746d3518854384f7a73a6d2da821454319d305a2af4b7015bbf8734a394e49']\n", + "2023-07-31 06:32:22,853 [fastlane:DEBUG] - Profit in bnt: -0.0000 ['0x72489592d291e402a4881f28823983b97a028e5ac5efbf87c428db2dbf06c81b']\n", + "2023-07-31 06:32:22,856 [fastlane:DEBUG] - Profit in bnt: 3.0700 ['0x748ab2bef0d97e5a044268626e6c9c104bab818605d44f650fdeaa03a3c742d2', '3743106036130323098097120681749450326076-0']\n", + "2023-07-31 06:32:22,856 [fastlane:DEBUG] - *************\n", + "2023-07-31 06:32:22,856 [fastlane:DEBUG] - New best profit: 3.0700241268896207\n", + "2023-07-31 06:32:22,858 [fastlane:DEBUG] - best_trade_instructions_df: WETH-6Cc2 BNT-FF1C\n", + "0x748ab2bef0d97e5a044268626e6c9c104bab818605d44... 3.982716e-03 -19.655884\n", + "3743106036130323098097120681749450326076-0 -3.982725e-03 16.585860\n", + "PRICE 4.935290e+03 1.000000\n", + "AMMIn 3.982716e-03 16.585860\n", + "AMMOut -3.982725e-03 -19.655884\n", + "TOTAL NET -8.378986e-09 -3.070024\n", + "2023-07-31 06:32:22,858 [fastlane:DEBUG] - *************\n", + "2023-07-31 06:32:22,880 [fastlane:DEBUG] - Profit in bnt: 0.2318 ['0x68bd2250b4b44996e193e9e001f74a5e5a31b31fbd0bb7df34c66eb8da7e6be2', '1701411834604692317316873037158841057299-0', '1701411834604692317316873037158841057371-0', '1701411834604692317316873037158841057409-0', '1701411834604692317316873037158841057432-0', '1701411834604692317316873037158841057499-0', '1701411834604692317316873037158841057533-0', '1701411834604692317316873037158841057598-0']\n", + "2023-07-31 06:32:22,883 [fastlane:DEBUG] - Profit in bnt: 3.0701 ['0x748ab2bef0d97e5a044268626e6c9c104bab818605d44f650fdeaa03a3c742d2', '3743106036130323098097120681749450326076-0']\n", + "2023-07-31 06:32:22,883 [fastlane:DEBUG] - *************\n", + "2023-07-31 06:32:22,883 [fastlane:DEBUG] - New best profit: 3.070071956771537\n", + "2023-07-31 06:32:22,884 [fastlane:DEBUG] - best_trade_instructions_df: WETH-6Cc2 BNT-FF1C\n", + "0x748ab2bef0d97e5a044268626e6c9c104bab818605d44... 0.003361 -1.658586e+01\n", + "3743106036130323098097120681749450326076-0 -0.003983 1.658586e+01\n", + "PRICE 1.000000 2.026223e-04\n", + "AMMIn 0.003361 1.658586e+01\n", + "AMMOut -0.003983 -1.658586e+01\n", + "TOTAL NET -0.000622 9.564246e-09\n", + "2023-07-31 06:32:22,884 [fastlane:DEBUG] - *************\n", + "2023-07-31 06:32:22,886 [fastlane:DEBUG] - Profit in bnt: -0.0000 ['0xc4771395e1389e2e3a12ec22efbb7aff5b1c04e5ce9c7596a82e9dc8fdec725b']\n", + "2023-07-31 06:32:22,889 [fastlane:DEBUG] - Profit in bnt: -0.0000 ['0xc4771395e1389e2e3a12ec22efbb7aff5b1c04e5ce9c7596a82e9dc8fdec725b']\n", + "2023-07-31 06:32:22,898 [fastlane:DEBUG] - Profit in bnt: 0.2313 ['0x68bd2250b4b44996e193e9e001f74a5e5a31b31fbd0bb7df34c66eb8da7e6be2', '1701411834604692317316873037158841057299-0', '1701411834604692317316873037158841057371-0', '1701411834604692317316873037158841057409-0', '1701411834604692317316873037158841057432-0', '1701411834604692317316873037158841057499-0', '1701411834604692317316873037158841057533-0', '1701411834604692317316873037158841057598-0']\n", + "2023-07-31 06:32:22,901 [fastlane:DEBUG] - Profit in bnt: -0.0000 ['0xc4be7ee1e92f6eaebe2b6c46db7eb95e883dc9baa76915812d9b50b83af82b26']\n", + "2023-07-31 06:32:22,906 [fastlane:DEBUG] - Profit in bnt: -382768.5002 ['0x7c746d3518854384f7a73a6d2da821454319d305a2af4b7015bbf8734a394e49']\n", + "/Users/mikewcasale/Documents/GitHub/fastlane-bot/fastlane_bot/tools/optimizer/margpoptimizer.py:217: RuntimeWarning: divide by zero encountered in scalar divide\n", + " price = get(p, tokens_ix.get(tknb)) / get(p, tokens_ix.get(tknq))\n", + "2023-07-31 06:32:22,910 [fastlane:DEBUG] - Profit in bnt: -0.0000 ['0xa00c086bd39848389cc244a239012092df251285163ed7d97e4261d87d733cc6']\n", + "2023-07-31 06:32:22,910 [fastlane:INFO] - No eligible arb opportunities.\n", + "2023-07-31 06:32:34,916 [fastlane:INFO] - Timeout hit... stopping bot\n" + ] + } + ], + "source": [ + "expected_log_line = \"Bot successfully updated min profit\"\n", + "arb_mode = \"multi\"\n", + "run_command(arb_mode=arb_mode, expected_log_line=expected_log_line)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.17" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/resources/NBTest/NBTest_905_RespectMinProfitClickParam.py b/resources/NBTest/NBTest_905_RespectMinProfitClickParam.py new file mode 100644 index 000000000..489abc1fe --- /dev/null +++ b/resources/NBTest/NBTest_905_RespectMinProfitClickParam.py @@ -0,0 +1,100 @@ +# --- +# jupyter: +# jupytext: +# text_representation: +# extension: .py +# format_name: light +# format_version: '1.5' +# jupytext_version: 1.14.7 +# kernelspec: +# display_name: Python 3 (ipykernel) +# language: python +# name: python3 +# --- + +# coding=utf-8 +""" +This module contains the tests which ensure that the minimum profit BNT parameter is respected. +""" +from fastlane_bot import Bot +from fastlane_bot.tools.cpc import ConstantProductCurve as CPC +from fastlane_bot.events.exchanges import UniswapV2, UniswapV3, SushiswapV2, CarbonV1, BancorV3 +import subprocess, os, sys +import pytest +print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(CPC)) +print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(Bot)) +print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(UniswapV2)) +print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(UniswapV3)) +print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(SushiswapV2)) +print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(CarbonV1)) +print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(BancorV3)) +from fastlane_bot.testing import * +plt.rcParams['figure.figsize'] = [12,6] +from fastlane_bot import __VERSION__ +require("3.0", __VERSION__) + + +# # Setup + +# + +def find_main_py(): + # Start at the directory of the current script + cwd = os.path.abspath(os.path.join(os.getcwd())) + + print(f"Searching for main.py in {cwd}") + while True: + # Check if main.py exists in the current directory + if "main.py" in os.listdir(cwd): + return cwd # Found the directory containing main.py + else: + # If not, go up one directory + new_cwd = os.path.dirname(cwd) + + # If we're already at the root directory, stop searching + if new_cwd == cwd: + raise FileNotFoundError("Could not find main.py in any parent directory") + + cwd = new_cwd + + +def run_command(arb_mode, expected_log_line): + + # Find the correct path to main.py + main_script_path = find_main_py() + print(f"Found main.py in {main_script_path}") + main_script_path = main_script_path + "/main.py" + + # Run the command + cmd = [ + "python", + main_script_path, + f"--arb_mode={arb_mode}", + "--default_min_profit_bnt=60", + "--limit_bancor3_flashloan_tokens=False", + "--use_cached_events=True", + "--logging_path=fastlane_bot/data/", + "--timeout=45", + "--loglevel=DEBUG", + ] + subprocess.Popen(cmd) + + # Wait for the expected log line to appear + found = False + result = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=60) + + # Check if the expected log line is in the output + if expected_log_line in result.stderr or expected_log_line in result.stdout: + found = True + + if not found: + pytest.fail("Expected log line was not found within 1 minute") # If we reach this point, the test has failed + + +# - + +# ## Test Minimum Profit BNT Is Respected + +# + is_executing=true +expected_log_line = "Bot successfully updated min profit" +arb_mode = "multi" +run_command(arb_mode=arb_mode, expected_log_line=expected_log_line) From bc526136a67674682c1b73eb6f137bf0e782a377 Mon Sep 17 00:00:00 2001 From: Mike Casale <46603283+mikewcasale@users.noreply.github.com> Date: Mon, 31 Jul 2023 06:38:46 -0700 Subject: [PATCH 2/4] Change test timeout value to 120 seconds to avoid premature failings. --- resources/NBTest/NBTest_905_RespectMinProfitClickParam.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/NBTest/NBTest_905_RespectMinProfitClickParam.ipynb b/resources/NBTest/NBTest_905_RespectMinProfitClickParam.ipynb index 9bbbf3235..7b687deaa 100644 --- a/resources/NBTest/NBTest_905_RespectMinProfitClickParam.ipynb +++ b/resources/NBTest/NBTest_905_RespectMinProfitClickParam.ipynb @@ -112,7 +112,7 @@ " \n", " # Wait for the expected log line to appear\n", " found = False\n", - " result = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=60)\n", + " result = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=120)\n", "\n", " # Check if the expected log line is in the output\n", " if expected_log_line in result.stderr or expected_log_line in result.stdout:\n", From 3ff20e3f0accb5a5e4c392a118d67f651ede24e1 Mon Sep 17 00:00:00 2001 From: Mike Casale <46603283+mikewcasale@users.noreply.github.com> Date: Mon, 31 Jul 2023 06:39:29 -0700 Subject: [PATCH 3/4] Change test timeout value to 120 seconds to avoid premature failings. --- resources/NBTest/NBTest_904_Bancor3DataValidation.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/NBTest/NBTest_904_Bancor3DataValidation.ipynb b/resources/NBTest/NBTest_904_Bancor3DataValidation.ipynb index 72120e12e..6d61d3309 100644 --- a/resources/NBTest/NBTest_904_Bancor3DataValidation.ipynb +++ b/resources/NBTest/NBTest_904_Bancor3DataValidation.ipynb @@ -111,7 +111,7 @@ " \n", " # Wait for the expected log line to appear\n", " found = False\n", - " result = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=60)\n", + " result = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=120)\n", "\n", " # Check if the expected log line is in the output\n", " if expected_log_line in result.stderr or expected_log_line in result.stdout:\n", From a1839665d1db3c5315233b4891ceabad3ccf9559 Mon Sep 17 00:00:00 2001 From: Mike Casale <46603283+mikewcasale@users.noreply.github.com> Date: Mon, 31 Jul 2023 06:41:34 -0700 Subject: [PATCH 4/4] Change test timeout value to 120 seconds to avoid premature failings. --- resources/NBTest/NBTest_903_FlashloanTokens.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/NBTest/NBTest_903_FlashloanTokens.ipynb b/resources/NBTest/NBTest_903_FlashloanTokens.ipynb index d5991e469..b1f0c771f 100644 --- a/resources/NBTest/NBTest_903_FlashloanTokens.ipynb +++ b/resources/NBTest/NBTest_903_FlashloanTokens.ipynb @@ -115,7 +115,7 @@ " # Wait for the expected log line to appear\n", " expected_log_line = \"limiting flashloan_tokens to [\"\n", " found = False\n", - " result = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=60)\n", + " result = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=120)\n", "\n", " # Check if the expected log line is in the output\n", " if expected_log_line in result.stderr:\n",