DefiPlaza's Subgraph API

DefiPlaza uses subgraphs to index and organize the data from the smart contracts. These subgraphs make the information on the Ethereum blockchain available via a GraphQL API on the web.

Endpoints and API explorer

Github Source: https://github.com/OmegaSyndicate/dex-subgraph

Explorer page: https://thegraph.com/hosted-service/subgraph/omegasyndicate/defiplaza

API Endpoint: https://api.thegraph.com/subgraphs/name/omegasyndicate/defiplaza

The Explorer page contains all example queries on this page for an easy way to explore and play with the subgraph API.

All USD values are derived from the average number of the three stable coins on DefiPlaza: USDC, USDT and DAI.

Subgraph Reference

Factory

The factory object contains consolidated information on the DefiPlaza dex, such as the total value locked in USD and the circulating supply of the DFP2 Governance token.

You can retrieve the data via the contract's address:

{
  factory(id: "0xe68c1d72340aeefe5be76eda63ae2f4bc7514110") {
    swapCount
    totalValueLockedUSD
    totalTradeVolumeUSD
    totalFeesEarnedUSD
    dfp2TotalSupply
    dfp2MarketCap
    xdp2TotalSupply
    xdp2Staked
  }
}

Try


Token

The token object contains information on each of the 16 tokens trade-able on DefiPlaza.

You can query the tokens in different ways, for example by times swapped. The id of the Token is it’s address on the Ethereum blockchain.

{
  tokens(orderBy:swapCount, orderDirection:desc) {
    id
    symbol
    tokenAmount
    swapCount
  }
}

Try

To query the price of a token in the last 28 days:

{
  dailyTokens(where: {token: "0x2f57430a6ceda85a67121757785877b4a71b8e6d"}, first: 28, orderBy: date, orderDirection: desc) {
    date
    swapUSD
    token {
      id
      symbol
    }
    tokenPriceUSD
    tokenPriceMin
    tokenPriceMax
  }
}

Try


Pair

All 120 pairs present on DefiPlaza, created alphabetically. The id is the base and quote symbol, for example: DFP2_ETH.

{
  pairs(orderBy:id, orderDirection:asc) {
    id
    baseToken {
      symbol
    }
    quoteToken {
      symbol
    }
    swapCount
  }
}

Try


Swap

Every swap on DefiPlaza is logged and available to query. It includes the pair, the input and output token, the amounts of both tokens, and the value in USD.

{
  swaps(first:10, orderBy:timestamp, orderDirection:desc) {
    id
    pair {
      id
    }
    inputToken {
      symbol
    }
    inputAmount
    outputToken {
      symbol
    }
    outputAmount
    swapUSD
  }
}

Try

To retrieve the swaps for token ETH_USDC:

{
  swaps(where: {pair: "ETH_USDC"}, first: 10, orderBy: timestamp, orderDirection: desc) {
    id
    pair {
      id
    }
    inputToken {
      id
      symbol
    }
    inputAmount
    outputToken {
      id
      symbol
    }
    outputAmount
    swapUSD
  }
}

Try


Hourly and Daily stats

The subgraphs also feature hourly and daily stats for both the complete dex and per token. You can explore these here.

To retrieve the stats for the last 28 days:

{
  dailies(first: 28, orderBy: date, orderDirection: desc) {
    date
    liquidityUSD
    liquidityAddedUSD
    liquidityRemovedUSD
    tradeVolumeUSD
    swapUSD
    totalValueLockedUSD
  }
}

Try

To retrieve the stats for the last 12 hours:

{
  hourlies(first: 12, orderBy: date, orderDirection: desc) {
    date
    liquidityUSD
    liquidityAddedUSD
    liquidityRemovedUSD
    tradeVolumeUSD
    swapUSD
    totalValueLockedUSD
  }
}

Try