Skip to content

Commit

Permalink
Simplify the method for finding a reliable price
Browse files Browse the repository at this point in the history
  • Loading branch information
barak manos committed May 29, 2024
1 parent 7b994d4 commit daf21f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
28 changes: 14 additions & 14 deletions fastlane_bot/modes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ def __init__(self, flashloan_tokens, CCm, ConfigObj):
self.flashloan_tokens = flashloan_tokens
self.CCm = CCm
self.ConfigObj = ConfigObj
self.sort_order = {
key: index for index, key in enumerate(
["bancor_v2", "bancor_v3"]
+ ConfigObj.UNI_V2_FORKS
+ ConfigObj.UNI_V3_FORKS
)
}

def find_combos(self) -> List[Any]:
return self.find_arbitrage()["combos"]
Expand Down Expand Up @@ -62,20 +55,27 @@ def calculate_profit(self, src_token: str, src_profit: float) -> Decimal:
return Decimal(str(src_profit)) / Decimal(str(price))
return Decimal(str(src_profit))

def get_params(self, cc, dst_tokens, src_token):
def get_params(self, container, dst_tokens, src_token):
pstart = {src_token: 1}
for dst_token in dst_tokens:
if dst_token != src_token:
pstart[dst_token] = self.find_reliable_price(cc, dst_token, src_token)
pstart[dst_token] = self.find_reliable_price(container, dst_token, src_token)
if pstart[dst_token] is None:
return None
return {"pstart": pstart}

def find_reliable_price(self, cc, dst_token, src_token):
list1 = [{"exchange": curve.params.exchange, "price": curve.p / 1} for curve in cc.bytknx(dst_token).bytkny(src_token).curves]
list2 = [{"exchange": curve.params.exchange, "price": 1 / curve.p} for curve in cc.bytknx(src_token).bytkny(dst_token).curves]
items = sorted(list1 + list2, key = lambda item: self.sort_order.get(item["exchange"], float("inf")))
return items[0]["price"] if len(items) > 0 else None
def find_reliable_price(self, container, dst_token, src_token):
container1 = container.bytknx(dst_token).bytkny(src_token)
container2 = container.bytknx(src_token).bytkny(dst_token)
for exchange in ["bancor_v2", "bancor_v3", *self.ConfigObj.UNI_V2_FORKS, *self.ConfigObj.UNI_V3_FORKS]:
list1 = [curve.p / 1 for curve in container1.byparams(exchange=exchange).curves]
list2 = [1 / curve.p for curve in container2.byparams(exchange=exchange).curves]
price = [list1 + list2 + [None]][0]
if price is not None:
return price
list1 = [curve.p / 1 for curve in container1.curves]
list2 = [1 / curve.p for curve in container2.curves]
return [list1 + list2 + [None]][0]

def is_net_change_small(trade_instructions_df) -> bool:
try:
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 @@ -18,10 +18,9 @@ def get_combos(self) -> List[Any]:
miniverse_combos = []

CC = self.CCm.byparams(exchange="bancor_v3")

if self.ConfigObj.LIMIT_BANCOR3_FLASHLOAN_TOKENS:
# Filter out tokens that are not in the existing flashloan_tokens list
flashloan_tokens = [tkn for tkn in CC.tknys() if tkn in self.flashloan_tokens]
self.ConfigObj.logger.info(f"limiting flashloan_tokens to {self.flashloan_tokens}")
flashloan_tokens = list(set(CC.tknys()) & set(self.flashloan_tokens))
else:
flashloan_tokens = CC.tknys()

Expand Down

0 comments on commit daf21f9

Please sign in to comment.