From 700fa71e9c79bd02784b6e9eee0de1b8e96da4d6 Mon Sep 17 00:00:00 2001 From: Benjamin Smith Date: Wed, 19 Jul 2023 14:28:30 +0200 Subject: [PATCH] [Easy] Remove Undesired Sort (#320) --- src/fetch/transfer_file.py | 1 - src/models/transfer.py | 19 ----------- tests/unit/test_models.py | 64 -------------------------------------- 3 files changed, 84 deletions(-) diff --git a/src/fetch/transfer_file.py b/src/fetch/transfer_file.py index a8caf438..d2407226 100644 --- a/src/fetch/transfer_file.py +++ b/src/fetch/transfer_file.py @@ -114,7 +114,6 @@ def auto_propose( [os.environ["PROD_DB_URL"], os.environ["BARN_DB_URL"]] ), ) - Transfer.sort_list(payout_transfers) payout_transfers = list( filter( lambda payout: payout.amount_wei > args.min_transfer_amount_wei, diff --git a/src/models/transfer.py b/src/models/transfer.py index df26e164..cb172837 100644 --- a/src/models/transfer.py +++ b/src/models/transfer.py @@ -57,12 +57,6 @@ def __init__(self, token: Optional[Token], recipient: Address, amount_wei: int): self._recipient = recipient self.amount_wei = amount_wei - # It ensures that transfers are grouped - # 1. first by initial recipient (i.e. solvers), - # 2. then by token address (with native ETH last) and - # 3. finally ordered by amount descending (so that largest in category occur first). - self._sort_key = (recipient, str(token), -amount_wei) - @classmethod def from_dict(cls, obj: dict[str, str]) -> Transfer: """Converts Dune data dict to object with types""" @@ -104,11 +98,6 @@ def recipient(self) -> Address: """Read access to the recipient of a transfer""" return self._recipient - @property - def sort_key(self) -> tuple[Address, str, int]: - """Read access to the recipient of a transfer""" - return self._sort_key - @staticmethod def consolidate(transfer_list: list[Transfer]) -> list[Transfer]: """ @@ -201,11 +190,3 @@ def __str__(self) -> str: f"amount={self.amount})" ) raise ValueError(f"Invalid Token Type {self.token_type}") - - @staticmethod - def sort_list(transfer_list: list[Transfer]) -> None: - """ - This is the preferred and tested sort order we use for generating the transfer file. - Note that this method mutates the input data and nothing in returned. - """ - transfer_list.sort(key=lambda t: t.sort_key) diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index 9a33d53c..79c286cb 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -477,70 +477,6 @@ def test_summarize(self): "Total ETH Funds needed: 123.4568\nTotal COW Funds needed: 10000000.0000\n", ) - def test_sorted_output(self): - solver_1 = Address.from_int(1) - solver_2 = Address.from_int(2) - solver_3 = Address.from_int(3) - - reward_target_1 = Address.from_int(4) - reward_target_2 = Address.from_int(4) - - # These are not redirected. - eth_1 = Transfer(token=None, recipient=solver_1, amount_wei=2) - eth_2 = Transfer(token=None, recipient=solver_2, amount_wei=3) - eth_3 = Transfer(token=None, recipient=solver_3, amount_wei=5) - execution_reimbursements = [eth_1, eth_2, eth_3] - cow_token = Token(COW_TOKEN_ADDRESS) - cow_1 = redirected_transfer( - token=cow_token, - recipient=solver_1, - amount_wei=10, - redirect=reward_target_1, - ) - cow_2 = redirected_transfer( - token=cow_token, - recipient=solver_2, - amount_wei=20, - redirect=reward_target_2, - ) - cow_3 = redirected_transfer( - token=cow_token, - recipient=solver_3, - amount_wei=30, - redirect=reward_target_1, - ) - cow_rewards = [cow_1, cow_2, cow_3] - slip_1 = redirected_transfer( - token=None, recipient=solver_1, amount_wei=1, redirect=reward_target_2 - ) - slip_2 = redirected_transfer( - token=Token(COW_TOKEN_ADDRESS), - recipient=solver_2, - amount_wei=4, - redirect=reward_target_2, - ) - positive_slippage = [slip_1, slip_2] - - payout_transfers = execution_reimbursements + cow_rewards + positive_slippage - Transfer.sort_list(payout_transfers) - # This demonstrates that the sorting technique groups solvers (i.e. original recipients before redirects first) - # Then by token (with NATIVE ETH Last Since "0x" < "None") - # and finally by amount descending. - # Note that eth_1.amount > slip_1.amount while eth_2.amount < slip_2.amount - self.assertEqual( - payout_transfers, - [ - cow_1, - eth_1, - slip_1, # Solver 1 Transfers - cow_2, - slip_2, - eth_2, # Solver 2 Transfers - cow_3, - eth_3, # Solver 3 Transfers - ], - ) - class TestAccountingPeriod(unittest.TestCase): def test_str(self):