From 140b3f855a8d5cbd7878f49ea024f94cf93da428 Mon Sep 17 00:00:00 2001 From: barak manos <> Date: Fri, 17 May 2024 12:22:27 +0300 Subject: [PATCH] Fix functions `create_sort_order` and `sort_key` --- fastlane_bot/bot.py | 9 +-------- fastlane_bot/modes/base.py | 13 +++---------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/fastlane_bot/bot.py b/fastlane_bot/bot.py index d3993c637..6600d51f2 100644 --- a/fastlane_bot/bot.py +++ b/fastlane_bot/bot.py @@ -548,9 +548,6 @@ def get_prices_simple(self, CCm, tkn0, tkn1): curve_prices += [(x.params['exchange'],x.descr,x.cid,1/x.p) for x in CCm.bytknx(tkn1).bytkny(tkn0)] return curve_prices - # Global constant for Carbon Forks ordering - CARBON_SORTING_ORDER = float('inf') - # Create a sort order mapping function def create_sort_order(self, sort_sequence): # Create a dictionary mapping from sort sequence to indices, except for Carbon Forks @@ -558,11 +555,7 @@ def create_sort_order(self, sort_sequence): # Define the sort key function separately def sort_key(self, item, sort_order): - # Check if the item is Carbon Forks - if item[0] in self.ConfigObj.CARBON_V1_FORKS: - return self.CARBON_SORTING_ORDER - # Otherwise, use the sort order from the dictionary, or a default high value - return sort_order.get(item[0], self.CARBON_SORTING_ORDER - 1) + return float('inf') if item[0] in self.ConfigObj.CARBON_V1_FORKS else sort_order.get(item[0], float('inf')) # Define the custom sort function def custom_sort(self, data, sort_sequence): diff --git a/fastlane_bot/modes/base.py b/fastlane_bot/modes/base.py index 24287c859..5384827f1 100644 --- a/fastlane_bot/modes/base.py +++ b/fastlane_bot/modes/base.py @@ -59,21 +59,14 @@ def get_prices_simple(self, CCm, tkn0, tkn1): curve_prices += [(x.params['exchange'],x.descr,x.cid,1/x.p) for x in CCm.bytknx(tkn1).bytkny(tkn0)] return curve_prices - # Global constant for 'carbon_v1' order - CARBON_SORTING_ORDER = float('inf') - # Create a sort order mapping function def create_sort_order(self, sort_sequence): - # Create a dictionary mapping from sort sequence to indices, except for 'carbon_v1' - return {key: index for index, key in enumerate(sort_sequence) if key != 'carbon_v1'} + # Create a dictionary mapping from sort sequence to indices, except for Carbon Forks + return {key: index for index, key in enumerate(sort_sequence) if key not in self.ConfigObj.CARBON_V1_FORKS} # Define the sort key function separately def sort_key(self, item, sort_order): - # Check if the item is 'carbon_v1' - if item[0] in self.ConfigObj.CARBON_V1_FORKS: - return self.CARBON_SORTING_ORDER - # Otherwise, use the sort order from the dictionary, or a default high value - return sort_order.get(item[0], self.CARBON_SORTING_ORDER - 1) + return float('inf') if item[0] in self.ConfigObj.CARBON_V1_FORKS else sort_order.get(item[0], float('inf')) # Define the custom sort function def custom_sort(self, data, sort_sequence):