diff --git a/Makefile b/Makefile index 1a34ffdd0..2b30e3608 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ test: - poetry run pytest fastlane_bot/tests -v $1 + poetry run pytest fastlane_bot/tests/$(subset) pull: git pull --recurse-submodules diff --git a/fastlane_bot/config/network.py b/fastlane_bot/config/network.py index 0bed6b542..c49963384 100644 --- a/fastlane_bot/config/network.py +++ b/fastlane_bot/config/network.py @@ -188,6 +188,7 @@ class ConfigNetwork(ConfigBase): ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" USDC_ADDRESS = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" MKR_ADDRESS = "0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2" + DAI_ADDRESS = "0x6B175474E89094C44Da98b954EedeAC495271d0F" LINK_ADDRESS = "0x514910771AF9Ca656af840dff83E8264EcF986CA" WBTC_ADDRESS = "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599" BNT_ADDRESS = "0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C" diff --git a/fastlane_bot/helpers/routehandler.py b/fastlane_bot/helpers/routehandler.py index 3dbf3ed48..e9b4eeddb 100644 --- a/fastlane_bot/helpers/routehandler.py +++ b/fastlane_bot/helpers/routehandler.py @@ -24,8 +24,6 @@ import eth_abi import pandas as pd -from arb_optimizer.curves import T - from .tradeinstruction import TradeInstruction from ..events.interface import Pool from fastlane_bot.config.constants import AGNI_V3_NAME, BUTTER_V3_NAME, CLEOPATRA_V3_NAME, PANCAKESWAP_V3_NAME, \ diff --git a/fastlane_bot/modes/base_triangle.py b/fastlane_bot/modes/base_triangle.py index 228dcfc6e..a198461ca 100644 --- a/fastlane_bot/modes/base_triangle.py +++ b/fastlane_bot/modes/base_triangle.py @@ -12,10 +12,6 @@ import itertools from typing import List, Any, Tuple, Union -import pandas as pd - -from arb_optimizer.curves import T - from fastlane_bot.modes.base import ArbitrageFinderBase @@ -176,51 +172,6 @@ def get_combos( ) return combos - @staticmethod - def get_mono_direction_carbon_curves( - miniverse: List[Any], trade_instructions_df: pd.DataFrame, token_in: str=None - ) -> List[Any]: - """ - Get mono direction carbon curves for triangular arbitrage - - Parameters - ---------- - miniverse : list - List of miniverses - token_in : str - Token in - trade_instructions_df : DataFrame - Trade instructions dataframe - - Returns - ------- - mono_direction_carbon_curves : list - List of mono direction carbon curves - - """ - - if token_in is None: - columns = trade_instructions_df.columns - check_nan = trade_instructions_df.copy().fillna(0) - first_bancor_v3_pool = check_nan.iloc[0] - second_bancor_v3_pool = check_nan.iloc[1] - - for idx, token in enumerate(columns): - if token == T.BNT: - continue - if first_bancor_v3_pool[token] < 0: - token_in = token - break - if second_bancor_v3_pool[token] < 0: - token_in = token - break - - wrong_direction_cids = [] - for idx, row in trade_instructions_df.iterrows(): - if (row[token_in] < 0) and ("-0" in idx or "-1" in idx): - wrong_direction_cids.append(idx) - - return [curve for curve in miniverse if curve.cid not in wrong_direction_cids] def build_pstart(self, CCm, tkn0list, tkn1): tkn0list = [x for x in tkn0list if x not in [tkn1]] pstart = {} diff --git a/fastlane_bot/modes/pairwise_multi_pol.py b/fastlane_bot/modes/pairwise_multi_pol.py index 6799864c9..3ad13585c 100644 --- a/fastlane_bot/modes/pairwise_multi_pol.py +++ b/fastlane_bot/modes/pairwise_multi_pol.py @@ -14,7 +14,6 @@ import pandas as pd from arb_optimizer import CurveContainer, PairOptimizer -from arb_optimizer.curves import T from fastlane_bot.modes.base_pairwise import ArbitrageFinderPairwiseBase @@ -194,12 +193,14 @@ def get_combos_pol(self, """ + gas_tokens = [self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS] # TODO: fix + bancor_pol_tkns = CCm.byparams(exchange="bancor_pol").tokens() - bancor_pol_tkns = set([tkn for tkn in bancor_pol_tkns if tkn not in [T.ETH, T.WETH]]) + bancor_pol_tkns = set([tkn for tkn in bancor_pol_tkns if tkn not in gas_tokens]) combos = [ (tkn0, tkn1) - for tkn0, tkn1 in itertools.product(bancor_pol_tkns, [T.ETH, T.WETH]) + for tkn0, tkn1 in itertools.product(bancor_pol_tkns, gas_tokens) # tkn1 is always the token being flash loaned # note that the pair is tkn0/tkn1, ie tkn1 is the quote token if tkn0 != tkn1 diff --git a/fastlane_bot/modes/triangle_bancor_v3_two_hop.py b/fastlane_bot/modes/triangle_bancor_v3_two_hop.py index f0caa9ac7..6c6ed4807 100644 --- a/fastlane_bot/modes/triangle_bancor_v3_two_hop.py +++ b/fastlane_bot/modes/triangle_bancor_v3_two_hop.py @@ -11,7 +11,6 @@ import math from typing import Union, List, Tuple, Any, Iterable -from arb_optimizer.curves import T from arb_optimizer import CurveContainer, MargPOptimizer, ConstantProductCurve from fastlane_bot.modes.base_triangle import ArbitrageFinderTriangleBase @@ -332,12 +331,12 @@ def get_miniverse_combos(self, combos: Iterable) -> List[Tuple[str, List]]: continue bancor_v3_curve_0 = ( - self.CCm.bypairs(f"{T.BNT}/{tkn0}") + self.CCm.bypairs(f"{self.ConfigObj.network.BNT_ADDRESS}/{tkn0}") .byparams(exchange="bancor_v3") .curves ) bancor_v3_curve_1 = ( - self.CCm.bypairs(f"{T.BNT}/{tkn1}") + self.CCm.bypairs(f"{self.ConfigObj.network.BNT_ADDRESS}/{tkn1}") .byparams(exchange="bancor_v3") .curves ) diff --git a/fastlane_bot/tests/test_050_TestBancorV2.py b/fastlane_bot/tests/test_050_TestBancorV2.py index 599695819..d57430501 100644 --- a/fastlane_bot/tests/test_050_TestBancorV2.py +++ b/fastlane_bot/tests/test_050_TestBancorV2.py @@ -12,7 +12,6 @@ This module contains the tests for the exchanges classes """ from arb_optimizer import ConstantProductCurve as CPC -from arb_optimizer.curves import T from fastlane_bot import Bot, Config from fastlane_bot.bot import CarbonBot @@ -277,8 +276,8 @@ def test_test_expected_output_bancorv2(): fl_token = fl_token_with_weth = calculated_trade_instructions[0].tknin_address # If the flashloan token is WETH, then use ETH - if fl_token == T.WETH: - fl_token = T.NATIVE_ETH + if fl_token == setup_bot.ConfigObj.network.WETH_ADDRESS: + fl_token = setup_bot.ConfigObj.network.ETH_ADDRESS best_profit = flashloan_tkn_profit = tx_route_handler.calculate_trade_profit(calculated_trade_instructions) diff --git a/fastlane_bot/tests/test_906_TargetTokens.py b/fastlane_bot/tests/test_906_TargetTokens.py index 048eb6deb..709494b45 100644 --- a/fastlane_bot/tests/test_906_TargetTokens.py +++ b/fastlane_bot/tests/test_906_TargetTokens.py @@ -15,9 +15,8 @@ import subprocess from arb_optimizer import ConstantProductCurve as CPC -from arb_optimizer.curves import T -from fastlane_bot import Bot +from fastlane_bot import Bot, ConfigNetwork from fastlane_bot.events.exchanges import UniswapV2, UniswapV3, CarbonV1, BancorV3 print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(CPC)) print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(Bot)) @@ -70,7 +69,7 @@ def run_command(mode): "--alchemy_max_block_fetch=5", "--logging_path=fastlane_bot/data/", "--timeout=120", - f"--target_tokens={T.WETH},{T.DAI}", + f"--target_tokens={ConfigNetwork.WETH_ADDRESS},{ConfigNetwork.DAI_ADDRESS}", "--blockchain=ethereum" ] diff --git a/main.py b/main.py index b5fe6588a..5e0e5837d 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,6 @@ (c) Copyright Bprotocol foundation 2023. Licensed under MIT """ -from arb_optimizer.curves import T from fastlane_bot.exceptions import ReadOnlyException, FlashloanUnavailableException from fastlane_bot.events.version_utils import check_version_requirements @@ -59,6 +58,18 @@ from run_blockchain_terraformer import terraform_blockchain import argparse +from fastlane_bot import ConfigNetwork +default_flashloan_tokens = ",".join([ + ConfigNetwork.LINK_ADDRESS, + ConfigNetwork.ETH_ADDRESS, + ConfigNetwork.BNT_ADDRESS, + ConfigNetwork.WBTC_ADDRESS, + ConfigNetwork.DAI_ADDRESS, + ConfigNetwork.USDC_ADDRESS, + ConfigNetwork.USDT_ADDRESS, + ConfigNetwork.WETH_ADDRESS, +]) + load_dotenv() @@ -571,7 +582,7 @@ def run(mgr, args, tenderly_uri=None) -> None: ) parser.add_argument( "--flashloan_tokens", - default=f"{T.LINK},{T.NATIVE_ETH},{T.BNT},{T.WBTC},{T.DAI},{T.USDC},{T.USDT},{T.WETH}", + default=default_flashloan_tokens, help="The --flashloan_tokens flag refers to those token denominations which the bot can take " "a flash loan in.", )