-
-
Notifications
You must be signed in to change notification settings - Fork 58
Encode_Uniswap_V4_Pool_Id
Elnaril edited this page Apr 25, 2025
·
1 revision
Let's say we want to encode the id
of the V4 WBTC/USDC pool with a 0.3% fee (= 3000), tick space of 60:
On Ethereum we have the following addresses:
- WBTC: 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599
- USDC: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
First, we need to build the pool key.
from uniswap_universal_router_decoder import RouterCodec
codec = RouterCodec()
pool_key = codec.encode.v4_pool_key('0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 3000, 60)
The Uniswap protocol needs the token addresses to be ordered, but no worries, the codec.encode.v4_pool_key()
method takes care of it.
The general call to codec.encode.v4_pool_key()
is done as follow:
pool_key = codec.encode.v4_pool_key(
currency_0_address,
currency_1_address,
fee,
tick_spacing,
hook_address, # or 0x0000000000000000000000000000000000000000 if no hook
)
And now, we can encode the pool id as follow:
pool_id = codec.encode.v4_pool_id(pool_key)
And print it as an hexadecimal string:
print(pool_id.hex())
b98437c7ba28c6590dd4e1cc46aa89eed181f97108e5b6221730d41347bc817f
If you find this library useful, consider a donation and be part of the Supporter Community! :)
- ☕️☕️☕️ https://www.buymeacoffee.com/elnaril ☕️☕️☕️
- Ethereum compatible: 0xe32A121C89121bF8B829D6d88BBEA89e5d88f002
- Sponsoring: https://github.com/sponsors/Elnaril
Thank you to all supporters!! 🙏
Also, consider ⭐ starring ⭐ the repository and following the GitHub account and/or 𝕏 to get the next lib updates!