Repository navigation
feat: derive a Uniswap v3 pool address from the factory - #35
Merged
Merged
Conversation
Add uniswapV3Pool and the four fee tiers so callers share one CREATE2 address. The address is a prediction: getPool and liquidity still decide whether to offer the pool.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
🟡 Changes recommended
Declaration generation can fail on TextEncoder, and zero-address pairs currently produce impossible pool predictions.
3 open findings
What changed in this PR
Adds reusable Uniswap v3 CREATE2 pool-address derivation to the protocol catalog.
Changes:
- Adds pool derivation, fee-tier constants, and public exports.
- Adds known-pool and validation tests.
- Documents usage and adds the required hashing dependency and changeset.
| File | Description |
|---|---|
src/protocols/uniswapV3Pool.ts |
Implements pool derivation and checksumming. |
src/protocols/uniswap-v3.ts |
Adds canonical fee tiers. |
src/protocols/index.ts |
Exports the new API and types. |
tests/uniswapV3Pool.test.ts |
Tests derivation and invalid inputs. |
README.md |
Documents pool derivation usage. |
package.json |
Adds the hashing dependency. |
yarn.lock |
Locks the hashing dependency. |
.changeset/uniswap-v3-pool.md |
Records the minor release. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| /** EIP-55 checksum. `lowerHex` is 40 hex characters, no 0x prefix. */ | ||
| function checksumAddress(lowerHex: string): `0x${string}` { | ||
| const hash = bytesToHex(keccak_256(new TextEncoder().encode(lowerHex))); |
Comment on lines
+42
to
+43
| if (!tokenA || !tokenB) return undefined; | ||
| if (tokenA.lower === tokenB.lower) return undefined; |
Comment on lines
+71
to
+72
| }); | ||
| // pool.address is the CREATE2 address; token0 is the lower address. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Studio and the gateway each need the canonical Uniswap v3 pool for a token pair and a fee. This publishes that derivation from the catalog factory instead of copying it into each repo.
What
uniswapV3Pool({ chainId, tokenA, tokenB, fee })returns{ address, token0, token1 }.token0is the lower address. Argument order does not matter.UNISWAP_V3_FEE_TIER/UNISWAP_V3_FEE_TIERSare the four tiers to try: 100, 500, 3000, 10000.uniswapV3.feeTiersexposes the same list.initcode hash0xe34f199b…). Callers still checkfactory.getPoolandliquidity()before offering a pool. The package does not ship pool lists.@noble/hashes@1.8.0(keccak). v2 requires Node>=20.19, which would drop the Node 18 CI job.Minor changeset. Not published in this pull request.
Refs AvaProtocol/studio#1819
Test plan
yarn test:run— 76 tests, including Sepolia USDC/WETH 0.3%0x6Ce0896eAE6D4BD668fDe41BB784548fb8F59b50, Ethereum USDC/WETH 0.05%, Base WETH/USDC 0.05%, and Base Sepolia USDC/WETH 0.3%.yarn typecheckyarn releasepublishes the minor. Studio then drops its copy of the helper.