Skip to content

Commit 5a8c6a0

Browse files
committed
lint: typing, dict construction
1 parent 85d280d commit 5a8c6a0

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/degenbot/pathfinding.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class Direction(enum.Enum):
3333

3434
def find_paths(
3535
chain_id: int,
36-
start_tokens: Iterable[str],
37-
end_tokens: Iterable[str],
36+
start_tokens: Iterable[ChecksumAddress | str],
37+
end_tokens: Iterable[ChecksumAddress | str],
3838
min_depth: int = 2,
3939
max_depth: int | None = None,
4040
pool_types: Sequence[type] = [LiquidityPoolTable, UniswapV4PoolTable],
@@ -241,17 +241,20 @@ def get_tokens_with_min_degree(degree: int) -> set[TokenId]:
241241
f"{graph.number_of_nodes()} tokens, {graph.number_of_edges()} pools"
242242
)
243243

244+
start_tokens_checksummed = {get_checksum_address(token) for token in start_tokens}
245+
end_tokens_checksummed = {get_checksum_address(token) for token in end_tokens}
246+
244247
# Prepare an exhaustive traversal plan based on the Cartesian product of all start and end
245248
# nodes: e.g. P(a|b -> a|b) == P(a->a) + P(a->b) + P(b->a) + P(b->b)
246249
traversal_plan: dict[
247250
tuple[ChecksumAddress, ChecksumAddress],
248251
Direction,
249-
] = {
250-
(get_checksum_address(start_token), get_checksum_address(end_token)): Direction.FORWARD
251-
for start_token, end_token in itertools.product(start_tokens, end_tokens)
252-
}
252+
] = dict.fromkeys(
253+
itertools.product(start_tokens_checksummed, end_tokens_checksummed),
254+
Direction.FORWARD,
255+
)
253256

254-
tokens_used_for_start_and_end = set(start_tokens) & set(end_tokens)
257+
tokens_used_for_start_and_end = start_tokens_checksummed & end_tokens_checksummed
255258
if len(tokens_used_for_start_and_end) > 1:
256259
logger.debug("Optimizing traversal plan.")
257260
# One traversal can be eliminated for every combination from tokens in the starting and

0 commit comments

Comments
 (0)