Skip to content

feat: derive a Uniswap v3 pool address from the factory - #35

Merged
chrisli30 merged 2 commits into
mainfrom
feat/uniswap-v3-pool
Oct 8, 2026
Merged

chrisli30 merged 2 commits into
mainfrom
feat/uniswap-v3-pool

Conversation

@chrisli30

Copy link
Copy Markdown
Member

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 }. token0 is the lower address. Argument order does not matter.
  • UNISWAP_V3_FEE_TIER / UNISWAP_V3_FEE_TIERS are the four tiers to try: 100, 500, 3000, 10000. uniswapV3.feeTiers exposes the same list.
  • The address is a CREATE2 prediction (init code hash 0xe34f199b…). Callers still check factory.getPool and liquidity() before offering a pool. The package does not ship pool lists.
  • Runtime dependency is @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 typecheck
  • After merge, yarn release publishes the minor. Studio then drops its copy of the helper.

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.
@chrisli30
chrisli30 requested a balanced review from Copilot October 8, 2026 18:37
@socket-security

socket-security Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​noble/​hashes@​1.8.010010010084100

View full report

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

Comment thread src/protocols/uniswapV3Pool.ts Outdated

/** 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 thread README.md
Comment on lines +71 to +72
});
// pool.address is the CREATE2 address; token0 is the lower address.
@chrisli30
chrisli30 merged commit 1a6a8da into main Oct 8, 2026
6 checks passed
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