💰Pricing with Subgraph

Kodiak provides two distinct protocols — V2 and V3 — each with separate endpoints for their subgraphs. While the structure of the queries remains the same across both protocols, the results may differ due to the underlying differences in how liquidity and pricing are handled.

Endpoints:

  • Kodiak V2 Subgraph Endpoint:

    https://api.goldsky.com/api/public/project_clpx84oel0al201r78jsl0r3i/subgraphs/kodiak-v2-berachain-bartio/latest/gn
  • Kodiak V3 Subgraph Endpoint:

    https://api.goldsky.com/api/public/project_clpx84oel0al201r78jsl0r3i/subgraphs/kodiak-v3-berachain-bartio/latest/gn

Steps to Get Started:

  1. Understand the Basics of Subgraphs:

    • Subgraphs index blockchain data and expose it through GraphQL endpoints.

    • Each subgraph has entities (e.g., token, pool, transaction) that define the structure of the data you can query.

  2. Read the Subgraph Documentation: Learn how subgraph works The Graph Doucmentation

  3. Set Up a GraphQL Client:

    • Use tools like Postman, Insomnia, or GraphQL playgrounds to send queries.

    • In your application, you can use libraries like graphql-request or Apollo Client.

  4. Know the Key Entities:

    • token: Represents individual tokens, their metadata, and derived pricing.

    • bundle: Contains aggregate data like the current price of ETH in USD.

Query examples

  1. Fetching a Specific Token’s Price in ETH and USD

    {
      token(id: "TOKEN_ADDRESS") {
        id
        symbol
        name
        derivedETH
      }
      bundle(id: "1") {
        ethPrice
      }
    }
    • Replace TOKEN_ADDRESS with the contract address of the token you’re querying.

    • Use thie formula to calculate USD price:

      • Token Price (USD) = derivedETH * ethPrice

  2. Listing All Tokens with Derived Prices

    {
      tokens(first: 10) {
        id
        symbol
        name
        derivedETH
      }
      bundle(id: "1") {
        ethPrice
      }
    }

    Example response:

    {
      "data": {
        "tokens": [
          { "id": "0x...123", "symbol": "USDT", "name": "Tether", "derivedETH": "0.0005" },
          { "id": "0x...456", "symbol": "USDC", "name": "USD Coin", "derivedETH": "0.0005" }
        ],
        "bundle": {
          "ethPrice": "2000"
        }
      }
    }

Last updated