Subgraph Data (GraphQL)

Subgraph Data (GraphQL)

Introduction#

The Graph and GraphQL#

The Graph is a decentralized protocol for indexing and querying data from blockchains, initially applied on Ethereum. This means it is a simple way to retrieve specific data from the blockchain, aligning with web3 principles and offering the advantages of decentralization and reliability.

GraphQL is the underlying query language used by The Graph. What is the difference between traditional RESTful API calls and GraphQL calls? The main difference is that traditional APIs require developers to create specific endpoints for users to retrieve specific data. If users need more information, they may have to make multiple API calls, sometimes hundreds of calls, to get the data they need. With The Graph (GraphQL), developers only need to create a flexible schema once and make a single call.

For more information about The Graph and the underlying GraphQL, please refer to the GraphQL Introduction.

If you are using GraphQL data in your application, we recommend using feature-rich libraries like Apollo or lightweight implementations like GraphQL-Request.

DODO Subgraph#

To view the source code of the subgraph, please refer to our GitHub repository.

DODOEX#

Indexes DODO smart routing trade data, liquidity pool data, liquidity pool trade data, liquidity pool TVL data, and crowdfunding pool data.

To view the subgraph development introduction, please refer to the Subgraph Project Introduction.

For subgraphs on other chains, if using The Graph service, you can search here: https://thegraph.com/explorer?search=dodo&orderBy=Query+Count&orderDirection=desc If using DODO's self-hosted subgraph, simply replace the chainId with the desired value for other chains.

ChainNameChainId
moonriver1285
aurora1313161554
avax43114
optimism10
............

ERC20Token#

Indexes data related to tokens created on DODO. Data application page: https://app.dodoex.io/dev/erc20?network=mainnet

DODO Ming V3#

Indexes data related to mining pools created on DODO. Data application page: https://app.dodoex.io/dev/pool?network=mainnet

Query Examples#

Using The Graph Subgraph Studio#

You need to register with a wallet and deposit GRT tokens as query fees. Then, replace [api-key] with your own.

subgraph2
curl 'https://gateway.thegraph.com/api/[api-key]/subgraphs/id/GxV9XL6Wnjz75z919NPNdrLhEkqDR99PweUY3oh7Lh94' \
  -H 'content-type: application/json' \
  --data-raw '{"query":"{\n  dodoZoos(first: 5) {\n    id\n    pairCount\n    tokenCount\n    crowdpoolingCount\n  }\n}"}' \
  --compressed

Using DODO Self-hosted Subgraph#

You need to register an account on the DODO Developer Platform and apply for an API key. Replace ${your_id} with your ID and ${apikey} with your API key.

curl -i -X POST \
   -H "Content-Type:application/json" \
   -H "User-Agent:DODO-${your_id}" \
   -d \
'{
    "query": "{\n  dodoZoos(first: 5) {\n    id\n    pairCount\n    tokenCount\n    crowdpoolingCount\n  }\n}"
}' \
 'https://api.dodoex.io/subgraph/graphql?chainId=1&schemaName=dodoex&apikey=${apikey}'

Query the latest 10 transaction records, including smart routing orders.#

{
  orderHistories(first:10, orderBy: timestamp, orderDirection: desc){
    id
    hash
    block
    from
    to
    fromToken{
      id
      symbol
    }
    toToken{
      id
      symbol
    }
    amountIn
    amountOut
    timestamp
  }
}

Query swap records for liquidity pools.#

{
  swaps(where:{pair:"0xc9f93163c99695c6526b799ebca2207fdf7d61ad"},first:10){
    hash
    from
    to
### Query the most recently updated pools

```javascript
{
  pairs(first:100,where:{type_not:"VIRTUAL"}, orderBy:updatedAt, orderDirection: desc){
    id
    type
    baseToken{
      id
    }
    quoteToken{
      id
    }
    baseReserve
    quoteReserve
    updatedAt
  }
}

Retrieve pool status based on daily and hourly dimensions#

{
  pairDayDatas(first:100, where: {date_gt: 1684113421},orderBy:date,orderDirection:desc){
    date
    volumeBase
    volumeQuote
    feeBase
    feeQuote
    baseToken{
      symbol
    }
    quoteToken{
      symbol
    }
  }
}

Query user liquidity provision data#

{
  liquidityPositions{
    id
    pair{
      id
      baseSymbol
      quoteSymbol
    }
    user{
      id
    }
    lpToken{
      id
      symbol
    }
    liquidityTokenBalance
    liquidityTokenInMining
    updatedAt
  }
}

Query user information#

{
  user(id:"0x8982a82a77eaf1cd6f490b67ad982304ecc590af"){
    id
    txCount
    tradingRewardRecieved
  }
}

Query crowdfunding pool status#

{
  crowdPoolingDayDatas{
    date
    crowdPooling {
      id
      creator
      baseToken{
        symbol
      }
      quoteToken{
        symbol
      }
    }
    investedQuote
    investCount
    newcome
    poolQuote
  }
}

FAQ#

How can I retrieve the latest updated data from a subgraph?#

You can use the parameters first:10, orderBy: timestamp, orderDirection: desc to retrieve the latest updated data in descending order by timestamp.