Queries

Query examples provided for the DFX subgraphs

All the query examples can be tested on the playground in the subgraphs provided below


DFX Factory

Total liquidity, volume, and pools

This query gets the all time information about DFX

{
  dfxfactories {
    id
    pairCount
    totalVolumeUSD
    totalLiquidityUSD
  }
}

DFX Day Data

Daily snapshots of all total liquidity and volume

This query gets the daily snapshots on the all time information about DFX such as the US dollar value of the total liquidity and total volume across all DFX pools

{
  dfxdayDatas (
    orderBy: date
    orderDirection: asc
  ){
    totalVolumeUSD
    totalLiquidityUSD
  }
}

Trade

This query gets the latest 10 trades that were made in a pool. i.e. the EURS/USDC pool

{
  trades (
    first: 10
    orderBy: timestamp
    orderDirection:desc
    where: {
      pair: "0x1a4ffe0dcbdb4d551cfca61a5626afd190731347"
    }
  ){
    timestamp
    trader
    origin
    target
    originAmount
    targetAmount
  }
}

Pairs

This query lists the all pairs offered by DFX

{
  pairs {
    id
    token0{
      name
    }
    token1 {
      name
    }
    swapRateUSD
  }
}

Pair by ID

This query gets a pair by its id (contract address). For example below is the EURS/USDC pool

{
  pairs (
    where: {
      id: "0x1a4ffe0dcbdb4d551cfca61a5626afd190731347"
    }
  ){
    id
    token0{
      name
    }
    token1 {
      name
    }
    swapRateUSD
  }
}

Pairs ordered by liquidity

This query lists the all pairs offered by DFX ordered by liquidity in descending direction

{
  pairs(
    orderBy: reserveUSD
    orderDirection: desc
  ){
    id
    reserveUSD
  }
}

Pairs ordered by volume

This query lists the all pairs offered by DFX ordered by volume in descending direction

{
  pairs(
    orderBy: volumeUSD
    orderDirection: desc
  ){
    id
    volumeUSD
  }
}

Pair Day Data

This query lists a pair's data for a particular day ordered by date in ascending direction. For example below is the CADC/USDC pool

{
  pairDayDatas(
    orderBy: date
    orderDirection: asc
    where: {
      pair: "0xa6c0cbcaebd93ad3c6c94412ec06aaa37870216d"
    }
  ){
    date
    swapRateUSD
    reserveUSD
    volumeUSD
    participantCount
  }
}

Tokens

This query lists the all tokens offered on DFX

{
  tokens {
    id
    name
    symbol
    decimals
    priceUSD
  }
}

Token by ID

This query gets a token by its id (contract address) For example below is the USDC token

{
  tokens (
    where: {
      id: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
    }
  ){
    id
    name
    symbol
    decimals
    priceUSD
  }
}

Token Day Data

This query lists a pair's data for a particular day ordered by date in ascending direction. For example below is the CADC/USDC pool

{
  tokenDayDatas (
    orderBy: date
    orderDirection: asc
    where: {
      token:"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
    }
  ){
    id
    dailyVolumeUSD
    priceUSD
  }
}

Pool Participants

Volume

This query lists the top 5 addresses by trading volume in a pool. For example below is the CADC/USDC pool

{
  poolParticipants (
    orderBy: volumeUSD
    orderDirection: desc
    first: 5
    where: {
      pair: "0xa6c0cbcaebd93ad3c6c94412ec06aaa37870216d"
    }
  ){
    id
    volumeUSD
  }
}

Last updated