Index and Query UniswapV3 Liquidity Pool Data with Traceye

Index and Query UniswapV3 Liquidity Pool Data with Traceye

·

8 min read

Whether you are a DeFi developer or a liquidity provider, you will need access to Uniswap v3 liquidity pool data, such as global, pool, and position data, to make well-informed decisions. While there can be several ways to fetch Uniswap data, this article explains the most simplified way of indexing Uniswap data using Traceye—an innovative, low-code tool for creating subgraphs for Web3 data indexing.

Demystifying UniswapV3 and its liquidity pool

Uniswap v3 is the latest version of non-custodial AMM (automated market maker) implemented on the Ethereum Virtual Machine. Compared to previous iterations of Uniswap protocol, Uniswap V3 offers increased capital efficiency, improved accuracy and accessibility of oracles, more flexibility in fee structure, and fine-tuned control for all liquidity providers. Anyone- individual users, high-frequency trade firms, or investment banks- can become an liquidity provider for Uniswap v3 pool, enabling the protocol to accommodate instant buying, selling, and exchange for the traders.

Uniswap v3 has already introduced a bunch of unique features and it continues to make add-ons over time.

Let’s highlight some of its significant features:

  • Concentrated liquidity:

Liquidity providers in Uniswap V3 have the flexibility to concentrate their liquidity through “bounding” within an arbitrary price range. This helps Uniswap improve the pool’s overall capital efficiency while allowing liquidity providers to get approximations for their desired reserve curve and maintain aggregation with the rest of the pool.

  • Flexible fee model:

Uniswap v3 doesn't lock the swap fee at 0.30%. Instead, the fee tier on each pool is based on initialization. The fee tiers supported at initial stages are 0.05%, 0.30%, and 1%.

  • Protocol fee governance:

UNI governance has even more flexibility for setting up the fraction of the swap fee that the Uniswap protocol collects as a whole.

Indexing uniswap data

  • Improved price fee oracles:

Uniswap v3 offers powerful price feed oracles that allows users to real-time price accumulator values, which eliminates the need of checkpointing the accumulator value during the beginning and end of the period for which a Time-Weighted Average Price (TWAP) is measured.

5. Liquidity oracle:

Liquidity oracles are integrated with minting contracts, introducing average, time-weighted liquidity to enable users to get comprehensive data such as trading pairs and liquidity-related stats.

Now, let’s brief Traceye

Traceye is a web3 data indexing solution designed to support quick deployment and end-to-end management of custom subgraphs for a comprehensive range of blockchain networks and dApps.

With Traceye, web3 projects and enterprises get the flexibility to deploy shared data indexes and dedicated indexers– depending on their requirements. All your subgraphs will be deployed and managed on a reliable enterprise-grade infrastructure to ensure their performance and uptime.

How to index and query UniswapV3 Liquidity Pool Data with Traceye?

With Traceye, you have the following two different options to index Uniswap data:

  1. Launch your own UniswapV3 Subgraph.

  2. Fetch data through ready-to-use community subgraphs.

Option:1 Launching your own Subgraph.

If you decide to go with the first option, you need to create a Subgraph and then deploy it to Traceye’s hosting infrastructure. For this, you need to write a subgraph manifest, get the necessary ABI files from Etherscan, and a GraphQL schema.

Here's an example of basic Subgraph manifest for indexing data from Uniswap V3 pools:

specVersion: 0.0.5
schema:
  file: ./schema.graphql

dataSources:
  - kind: ethereum/contract
    name: UniswapV3Pool
    network: mainnet
    source:
      address:0x1F98431c8aD98523631AE4a59f267346ea31F984
      abi: UniswapV3Pool  # Update with the correct ABI for Uniswap V3 pool contract
    mapping:
      kind: ethereum/events
      apiVersion: 0.0.4
      language: wasm/assemblyscript
      entities:
        - PoolData
        - TickData
      abis:
        - name: UniswapV3Pool
          file: ./abis/UniswapV3Pool.json  # Path to the ABI file for Uniswap V3 pool contract
      eventHandlers:
        - event: Swap(uint256,uint256,int256,int256,address)  # Event emitted when a swap occurs in the pool
          handler: handleSwap
        - event: Sync(int128,int256,uint256)  # Event emitted when liquidity is added or removed from the pool
          handler: handleSync
      file: ./src/mappings/uniswap-v3-pool-mapping.ts

And, here’s the example of GraphQL Schema:

type PoolData @entity {
  id: ID!
  poolAddress: String!
  token0: String!
  token1: String!
  liquidity: BigInt!
  fee: BigInt!
  sqrtPrice: BigInt!
  tick: BigInt!
  timestamp: BigInt!
}

type TickData @entity {
  id: ID!
  pool: PoolData!
  tickIdx: BigInt!
  liquidityGross: BigInt!
  liquidityNet: BigInt!
  timestamp: BigInt!
}

type Query {
  poolData(id: ID!): PoolData
  tickData(id: ID!): TickData
}

Once you build the Subgraph, you can go to Traceye and launch your Uniswap v3 Subgraph to start indexing data from its liquidity pool. For a step-by-step process,follow our dedicated guide.

While launching your own Subgraph can have additional benefits, this option may not be suitable for a range of users who seek an easy and simplified method to retrieve Uniswap data. Hence, let’s discuss another way.

Option2: Launch community Subgraph

The community subgraph option offered by Traceye is a means to provide an abstraction layer to the complex and tech-intensive process of creating subgraphs. If you launch Uniswap v3 subgraph with Traceye, it will offer you the following main benefits:

  1. Faster deployment: community subgraphs on Traceye are launched within a few seconds, enabling you to start indexing data immediately from any protocol. For example Uniswap protocol, in our case.

  2. Wider accessibility: community subgraphs are not at all complex, hence developers of all levels can leverage them to fetch relevant data and build sophisticated dApps.

  1. Significantly lower cost: querying data with Traceye’s community subgraphs requires only $39 per month. This is significantly lower than having a dedicated subgraph.

  2. Improved performance: Hosted on an enterprise-grade, highly optimized infrastructure, your subgraphs escape from performance bottlenecks such as downtime or inefficient queries.

  3. 24/7 support: With responsive support, all your queries or subgraph-related issues will be addressed in real-time so that it can not impact the performance.

Now, let’s deploy Uniswap V2 Subgraph with Traceye:

  • Login to Zeeve and navigate to Traceye located at the left-side panel. Click on ‘Hosted Subgraphs’. A new dashboard similar to the below will open.

Image description

Click on ‘Buy Subscription’ to get started with the payment process. Select the number of community subgraphs you need. For example, we are opting for 1 unit as of now. Proceed with Buy Now to complete your payment and activate community subgraph access.

Image description

Upon successful payment, you will see instructions similar to the below screenshot on your dashboard:

Image description

From here, you can start setting up your community subgraph. Again, navigate to ‘Hosted Subgraphs’ under Traceye and click ‘Add Subgraph’. A drop-down menu will open, allowing you to create new, import existing, and launch community subgraphs. Click on ‘Launch Community’ to see the community subgraphs currently supported on Traceye.

Image description

As you can see, Uniswap-V3 is available for Polygon, Optimism, and Ethereum on Traceye. Whichever is your preferred option, select that and click on ‘Activate’. Upon this, your Uniswap will be deployed instantly.

Image description

Now, you will be redirected to a dashboard where you can check the details of your subgraph, such as Sync Status, creation date, total requests made, total API units consumed, workspace type, and Query URL.

Image description

From the same dashboard, you can check logs, entities, add-on services like webhooks, and settings.

Image description

Now, to index and query Uniswap v3 liquidity pool data– you need to click on ‘open’ located with the Query URL (visible in the previous screenshot). It will redirect you to a playground environment where you can query Uniswap data.

Image description

As you know, you need to define entities for Uniswap v3 liquidity pool to be able to fetch specific data. Within the above playground, if you click on the GraphQL explorer icon on the left panel, it will open a comprehensive list of Uniswap v3 entities, including the pool-specific entities like pool, poolDayData, poolHourData, pools, etc.

Image description

Let’s say you want to fetch data for the first 15 pools. To do this, click on ‘pools’ entity and enter ‘15’ in the ‘first’ subentity. You can increase or decrease the number of pools as required. Also, within the pools data, you have multiple options such as orderby in which you can select order id for the data. For now, let’s move to fetching data for the first 15 pools. We have already entered the details, which are reflected in the GraphQL query.

Image description

Now, execute the query by clicking on the play button, and data for all the 15 pools will be fetched instantly.

Image description

Similarly, you can fetch data for all the other entities available for your Uniswap v3 subgraph. As we can see, indexing and querying the Uniswap v3 subgraph is extremely simple and effortless using Traceye’s community subgraph. That’s because Traceye already keeps bulks of indexed data, allowing subgraphs to fetch any type of data without hassle.

Wrap up!

And with that, our discussion around Indexing and querying Uniswap V3 liquidity pool data reaches the end. This article has been crafted to help dApp developers, web3 projects, and data consumers understand the simplicity and effortless approach of Traceye for indexing Uniswap data. Also, as we discussed, if your application requires a dedicated subgraph, you launch this with Traceye. On top of that, you will get support from Zeeve’s highly experienced web3 developers, who will build custom subgraphs for your project at a lower cost and in significantly reduced time for faster time-to-market.

If you want more information on Traceye or Zeeve’s blockchain services, connect with our experts. Send your queries via mail or schedule a one-on-one call for detailed discussion.