MCPcopy Index your code
hub / github.com/Uniswap/v4-subgraph

github.com/Uniswap/v4-subgraph @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
95 symbols 261 edges 41 files 1 documented · 1%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Uniswap V4 Subgraph

Running Unit Tests

  1. Install Docker if you don't have it already
  2. Install postgres: brew install postgresql
  3. yarn run build:docker
  4. yarn run test

Adding New Chains

  1. Create a new subgraph config in src/utils/chains.ts. This will require adding a new <NETWORK_NAME>_NETWORK_NAME const for the corresponding network.
  2. Add a new entry in networks.json for the new chain. The network name should be derived from the CLI Name in The Graph's supported networks documenation. The factory address can be derived from Uniswap's deployments documentation (not yet available).
  3. To deploy to Alchemy, run the following command:
yarn run deploy:alchemy --
  <SUBGRAPH_NAME>
  --version-label <VERSION_LABEL>
  --deploy-key <DEPLOYMENT_KEY>
  --network <NETWORK_NAME>

Generating subgraph.yaml

The subgraph.yaml file can be automatically generated from the networks.json configuration for a specific network. This ensures that all contract addresses and start blocks are correctly synchronized.

To generate the subgraph.yaml:

  1. Make sure your networks.json is up to date with the correct contract addresses and start blocks
  2. Run: bash yarn generate-subgraph <network> For example: bash yarn generate-subgraph mainnet # or yarn generate-subgraph arbitrum-one

This will create a new subgraph.yaml file based on the network-specific configuration. The script will:

  • Use the contract templates defined for each contract type (PoolManager, PositionManager, etc.)
  • Generate data sources for each contract in the specified network
  • Preserve all the necessary event handlers and ABI configurations

Available networks can be found in networks.json.

Extension points exported contracts — how you extend this code

ContractConfig (Interface)
(no doc)
scripts/generate-subgraph.ts
NetworkConfig (Interface)
(no doc)
scripts/generate-subgraph.ts
NetworksConfig (Interface)
(no doc)
scripts/generate-subgraph.ts

Core symbols most depended-on inside this repo

assertObjectMatches
called by 38
tests/handlers/constants.ts
hexToBigInt
called by 22
src/utils/index.ts
mulShift
called by 19
src/utils/liquidityMath/tickMath.ts
convertTokenToDecimal
called by 16
src/utils/index.ts
findNativePerToken
called by 14
src/utils/pricing.ts
safeDiv
called by 14
src/utils/index.ts
createAndStoreTestToken
called by 9
tests/handlers/constants.ts
sqrtPriceX96ToTokenPrices
called by 7
src/utils/pricing.ts

Shape

Function 60
Class 31
Interface 3
Enum 1

Languages

TypeScript100%

Modules by API surface

tests/handlers/constants.ts16 symbols
src/utils/index.ts7 symbols
src/utils/chains.ts6 symbols
src/utils/pricing.ts5 symbols
src/utils/intervalUpdates.ts5 symbols
scripts/generate-subgraph.ts5 symbols
src/utils/token.ts4 symbols
src/utils/staticTokenDefinition.ts3 symbols
src/utils/liquidityMath/tickMath.ts3 symbols
src/utils/liquidityMath/sqrtPriceMath.ts3 symbols
src/utils/id.ts3 symbols
src/mappings/swap.ts3 symbols

For agents

$ claude mcp add v4-subgraph \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact