Skip to content

feat: encode Uniswap v3 multihop paths - #477

Closed
TimeToBuildBob wants to merge 1 commit into
uniswap-python:masterfrom
TimeToBuildBob:dev/multihop-v3
Closed

feat: encode Uniswap v3 multihop paths#477
TimeToBuildBob wants to merge 1 commit into
uniswap-python:masterfrom
TimeToBuildBob:dev/multihop-v3

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Supersedes #221 with its surviving, conflict-resolved slice.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Closing this companion PR: the original #221 is stale WIP and should be closed rather than revived as a one-function fragment.

@TimeToBuildBob
TimeToBuildBob deleted the dev/multihop-v3 branch August 9, 2026 11:43
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.07%. Comparing base (bc8fdf4) to head (1f4a865).

Files with missing lines Patch % Lines
uniswap/util.py 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #477      +/-   ##
==========================================
- Coverage   73.26%   73.07%   -0.19%     
==========================================
  Files          12       12              
  Lines        2319     2325       +6     
==========================================
  Hits         1699     1699              
- Misses        620      626       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@greptile-apps

greptile-apps Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR implements tightly packed Uniswap V3 multihop path encoding in uniswap/util.py.

  • Serializes the input token followed by each three-byte big-endian fee and output token.
  • Rejects fees outside the uint24 range.
  • Leaves empty routes representable even though they do not form valid V3 paths.

Confidence Score: 4/5

The PR appears safe to merge, with one non-blocking validation gap for empty routes in the new encoder.

Normal multihop routes are packed in the expected token-fee-token order with bounded uint24 fees, while an empty route returns a 20-byte value that cannot be decoded as a valid V3 path.

Files Needing Attention: uniswap/util.py

Important Files Changed

Filename Overview
uniswap/util.py Implements the previously stubbed V3 path encoder correctly for ordinary routes, but does not reject an empty route before returning malformed path bytes.

Reviews (1): Last reviewed commit: "feat: started working on multihop swaps ..." | Re-trigger Greptile

Comment thread uniswap/util.py
"""
raise NotImplementedError
"""Encode a Uniswap V3 route as tightly packed token and fee values."""
path = bytearray(_str_to_addr(token_in))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Empty routes produce invalid paths

An empty route skips the loop and returns only the 20-byte input-token address, while a valid Uniswap V3 path requires at least one fee-and-token hop. Rejecting this input locally prevents callers from passing malformed path bytes to a router or quoter and receiving an opaque contract revert.

Suggested change
path = bytearray(_str_to_addr(token_in))
if not route:
raise ValueError("route must contain at least one hop")
path = bytearray(_str_to_addr(token_in))

Knowledge Base Used: Token Registry, Fee Tiers, Constants, and Shared Utilities

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants