Skip to content

Commit

Permalink
[Easy] Remove Undesired Sort (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Jul 19, 2023
1 parent b378369 commit 700fa71
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 84 deletions.
1 change: 0 additions & 1 deletion src/fetch/transfer_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 0 additions & 19 deletions src/models/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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]:
"""
Expand Down Expand Up @@ -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)
64 changes: 0 additions & 64 deletions tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 700fa71

Please sign in to comment.