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

Add relevant bancor v3 tokens to the combos and flashloan tokens #429

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 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 fastlane_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ def _handle_trade_instructions(
)

flashloan_struct = tx_route_handler.generate_flashloan_struct(
trade_instructions_objects=calculated_trade_instructions
trade_instructions_objects=calculated_trade_instructions, b3_flashloan_tokens=list(CCm.byparams(exchange="bancor_v3").tknys())+[self.ConfigObj.BNT_ADDRESS]
)

# Get the flashloan token
Expand Down
1 change: 1 addition & 0 deletions fastlane_bot/config/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ class _ConfigNetworkMainnet(ConfigNetwork):

BALANCER_VAULT_ADDRESS = "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
CHAIN_FLASHLOAN_TOKENS = {
"ETH": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"WBTC": "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
"BNT": "0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C",
"WETH": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
Expand Down
46 changes: 26 additions & 20 deletions fastlane_bot/helpers/routehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,48 +511,54 @@ def get_custom_address(
else:
return pool.tkn0_address

def generate_flashloan_struct(self, trade_instructions_objects: List[TradeInstruction]) -> list:
def generate_flashloan_struct(self, trade_instructions_objects: List[TradeInstruction], b3_flashloan_tokens: list = None) -> list:
"""
Generates the flashloan struct for submitting FlashLoanAndArbV2 transactions
:param trade_instructions_objects: a list of TradeInstruction objects

:return:
list
Args:
trade_instructions_objects (List[TradeInstruction]): A list of trade instruction objects
b3_flashloan_tokens (list): A list of tokens to flashloan from Bancor V3

Returns:
list: A list of flashloan structs
"""
return self._get_flashloan_struct(trade_instructions_objects=trade_instructions_objects)
return self._get_flashloan_struct(trade_instructions_objects=trade_instructions_objects, b3_flashloan_tokens=b3_flashloan_tokens)

def _get_flashloan_platform_id(self, tkn: str) -> int:
def _get_flashloan_platform_id(self, tkn: str, b3_flashloan_tokens: list = None) -> int:
"""
Returns the platform ID to take the flashloan from
:param tkn: str

:return:
int

Args:
tkn (str): The token address
b3_flashloan_tokens (list): A list of tokens to flashloan from Bancor V3

Returns:
int: The platform ID
"""

if self.ConfigObj.NETWORK not in ["ethereum", "tenderly"]:
return 7

# Using Bancor V3 to flashloan BNT, ETH, WBTC, LINK, USDC, USDT
if tkn in [self.ConfigObj.BNT_ADDRESS, self.ConfigObj.ETH_ADDRESS, self.ConfigObj.WBTC_ADDRESS,
self.ConfigObj.LINK_ADDRESS, self.ConfigObj.BNT_ADDRESS, self.ConfigObj.ETH_ADDRESS,
self.ConfigObj.WBTC_ADDRESS, self.ConfigObj.LINK_ADDRESS]:
return 2
else:
return 7
return 2 if tkn in b3_flashloan_tokens else 7
Copy link
Collaborator

@barakman barakman Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument of type 'NoneType' is not iterable, so you probably want to remove that None default value for this list everywhere in the code (or by the least, change it to [], though if no default value is really required, then no need to declare one).


def _get_flashloan_struct(self, trade_instructions_objects: List[TradeInstruction]) -> list:
def _get_flashloan_struct(self, trade_instructions_objects: List[TradeInstruction], b3_flashloan_tokens: list = None) -> list:
"""
Turns an object containing trade instructions into a struct with flashloan tokens and amounts ready to send to the smart contract.
:param flash_tokens: an object containing flashloan tokens in the format {tkn: {"tkn": tkn_address, "flash_amt": tkn_amt}}

Args:
trade_instructions_objects (List[TradeInstruction]): A list of trade instruction objects
b3_flashloan_tokens (list): A list of tokens to flashloan from Bancor V3

Returns:
list: A list of flashloan structs
"""
flash_tokens = self._extract_single_flashloan_token(trade_instructions=trade_instructions_objects)
flashloans = []
balancer = {"platformId": 7, "sourceTokens": [], "sourceAmounts": []}
has_balancer = False

for tkn in flash_tokens.keys():
platform_id = self._get_flashloan_platform_id(tkn)
platform_id = self._get_flashloan_platform_id(tkn, b3_flashloan_tokens)
source_token = flash_tokens[tkn]["tkn"]
source_amounts = abs(flash_tokens[tkn]["flash_amt"])
if platform_id == 7:
Expand Down
2 changes: 1 addition & 1 deletion fastlane_bot/modes/base_triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def get_combos(
if arb_mode in ["b3_two_hop"]:
combos = [
(tkn0, tkn1)
for tkn0, tkn1 in itertools.product(flashloan_tokens, flashloan_tokens)
for tkn0, tkn1 in itertools.product(flashloan_tokens, CCm.byparams(exchange="bancor_v3").tknys())
# note that the pair is tkn0/tkn1, ie tkn1 is the quote token
if tkn0 != tkn1
]
Expand Down
Loading