PositionDescriptor support; PositionManager read methods support; misc#425
PositionDescriptor support; PositionManager read methods support; misc#425liquid-8 merged 2 commits intouniswap-python:dev/v4-finfrom
Conversation
Greptile SummaryThis PR adds support for Uniswap v4 PositionDescriptor and PositionManager contracts — including contract addresses for 16 networks, new ABI files, and ~30 read-only wrapper methods in
Confidence Score: 1/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Uniswap4.__init__] --> B[Load contract addresses from constants.py]
B --> C[_str_to_addr for each address]
C --> D[_load_contract with ABI]
D --> E[quoter / router / stateview / permit2]
D --> F[position_descriptor\npos_descriptor.abi]
D --> G[pool_manager\npoolmanager.abi]
D --> H[position_manager\npos_manager.abi]
F -->|"❌ Proxy ABI - no functions"| I[get_currency_ratio_priority\nget_flip_ratio\nget_native_currency_label\nget_pool_manager\nget_token_uri\nget_wrapped_native_address]
H --> J[get_position_liquidity]
J -->|"❌ calls positionLiquidity\nABI has getPositionLiquidity"| K[Runtime Error]
H --> L[get_pool_and_position_info]
L -->|"❌ passes liquidity value\ninstead of token_id"| K
H --> M[get_next_token_id]
M -->|"❌ calls nonces\ninstead of nextTokenId"| K
H --> N[get_balance_of / get_approved\nget_owner_of / get_nonces\nget_name / get_symbol / ...]
N -->|"✅ Correct"| O[Success]
Last reviewed commit: feee9d1 |
uniswap/constants.py
Outdated
| "worldchain": "0x7da419153bd420b689f312363756d76836aeace4", | ||
| "ink": "0x42e3ccd9b7f67b5b2ee0c12074b84ccf2a8e7f36", | ||
| "soneium": "0x42e3ccd9b7f67b5b2ee0c12074b84ccf2a8e7f36", | ||
| "avalanche": " 0x2b1aed9445b05ac1a3b203eccc1e25dd9351f0a9", |
There was a problem hiding this comment.
Tab character in address string
The avalanche address contains a leading tab character (\t) before 0x. The _str_to_addr function in util.py checks s.startswith("0x"), so this string will not match and will raise a NameNotFound exception at runtime when initializing on the avalanche network.
| "avalanche": " 0x2b1aed9445b05ac1a3b203eccc1e25dd9351f0a9", | |
| "avalanche": "0x2b1aed9445b05ac1a3b203eccc1e25dd9351f0a9", |
uniswap/uniswap4.py
Outdated
| def get_next_token_id(self, token_id: int) -> int: | ||
| """ | ||
| :returns: The ID that will be used for the next minted liquidity position | ||
| """ | ||
| if self.version == 4: | ||
| next_token_id: int = int( | ||
| self.position_manager.functions.nonces(token_id).call() | ||
| ) |
There was a problem hiding this comment.
Wrong contract function called for nextTokenId
get_next_token_id calls nonces(token_id) but should call nextTokenId(). The ABI defines nextTokenId as a no-argument function that returns the next token ID. Additionally, the nonces function in the ABI expects (address owner, uint256 word) — not a single token_id argument — so this will also fail at the ABI encoding level.
| def get_next_token_id(self, token_id: int) -> int: | |
| """ | |
| :returns: The ID that will be used for the next minted liquidity position | |
| """ | |
| if self.version == 4: | |
| next_token_id: int = int( | |
| self.position_manager.functions.nonces(token_id).call() | |
| ) | |
| def get_next_token_id(self) -> int: | |
| """ | |
| :returns: The ID that will be used for the next minted liquidity position | |
| """ | |
| if self.version == 4: | |
| next_token_id: int = int( | |
| self.position_manager.functions.nextTokenId().call() | |
| ) |
uniswap/uniswap4.py
Outdated
| else: | ||
| raise ValueError("Function is not supported for this version") | ||
| pool_key: PoolKey = PoolKey(*pool_key_tuple) | ||
| return_value = return_value = { |
There was a problem hiding this comment.
Duplicate assignment
return_value = return_value = { ... } is a duplicated assignment. While it works, it appears to be a copy-paste error.
| return_value = return_value = { | |
| return_value = { |
No description provided.