Skip to content

Commit

Permalink
Fix functions create_sort_order and sort_key
Browse files Browse the repository at this point in the history
  • Loading branch information
barak manos committed May 17, 2024
1 parent bdd6f2d commit f827557
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
9 changes: 1 addition & 8 deletions fastlane_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,21 +548,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 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
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 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):
Expand Down
13 changes: 3 additions & 10 deletions fastlane_bot/modes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f827557

Please sign in to comment.