Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the importing of token addresses from the arb_optimizer module #633

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions fastlane_bot/config/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions fastlane_bot/helpers/routehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down
49 changes: 0 additions & 49 deletions fastlane_bot/modes/base_triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 = {}
Expand Down
7 changes: 4 additions & 3 deletions fastlane_bot/modes/pairwise_multi_pol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions fastlane_bot/modes/triangle_bancor_v3_two_hop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
5 changes: 2 additions & 3 deletions fastlane_bot/tests/test_050_TestBancorV2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions fastlane_bot/tests/test_906_TargetTokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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"
]

Expand Down
15 changes: 13 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -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.",
)
Expand Down
Loading