June 8, 2022

Baby Moon Floki DEX Subgraph (API) Introduction

Baby Moon Floki DEX uses subgraph for indexing and organizing data from the Baby Moon Floki DEX smart contracts. These subgraph are hosted on The Graph hosted service and can be used to query Baby Moon Floki DEX data.

Production Endpoints

Subgraph has a dedicated endpoint for querying data, as well as a page on The Graph explorer the exposes the schema and available fields to query.

Baby Moon Floki DEX​


Subgraph Query Examples

This doc will teach you how to query Baby Moon Floki DEX analytics by writing GraphQL queries on the subgraph. You can fetch data points like :

  • collected fees for a position
  • current liquidity of a pool
  • volume on a certain day

and much more. Below are some example queries. To run a query copy and paste it into the explorer to get fresh data.

Global Data

Global data refers to data points about the Baby Moon Floki DEX protocol as a whole. Some examples of global data points are total value locked in the protocol, total pools deployed, or total transaction counts. Thus, to query global data you must pass in the Baby Moon Floki DEX Factory address 0xb79eDe982247Dec146b1dF1B9745EF49a8BFaCB2 and select the desired fields.

Current Global Data

An example querying total pool count, transaction count, and total volume in USD and ETH:

{
 flokiFactory(id: "0xb79eDe982247Dec146b1dF1B9745EF49a8BFaCB2" ) {
 	pairCount
 	txCount
 	totalVolumeUSD
 	totalVolumeETH
 }
}

Historical Global Data

You can also query historical data by specifying a block number.

{
 flokiFactory(id: "0xb79eDe982247Dec146b1dF1B9745EF49a8BFaCB2", block: {number: 17875969}) {
 	pairCount
 	txCount
 	totalVolumeUSD
 	totalVolumeETH
 }
}

Pair Data

Pair Overview

Fetch a snapshot of the current state of the pair with common values. This example fetches the USDC/WBNB pair.

{
 pair(id: "0x33a8ebcdc6f992e416dbe75196721fe432537201"){
     token0 {
       id
       symbol
       name
       derivedETH
     }
     token1 {
       id
       symbol
       name
       derivedETH
     }
     reserve0
     reserve1
     reserveUSD
     trackedReserveETH
     token0Price
     token1Price
     volumeUSD
     txCount
 }
}

All pairs in Baby Moon Floki DEX

The Graph limits entity return amounts to 1000 per query as of now. To get all pairs on Baby Moon Floki DEX use a loop and graphql skip query to fetch multiple chunks of 1000 pairs. The query would look like this.

{
   pairs(first: 1000, skip: 5) {
     id
   }
}

Most liquid pairs

Order by liquidity to get the most liquid pairs in Baby Moon Floki DEX.

{
 pairs(first: 1000, orderBy: reserveUSD, orderDirection: desc) {
   id
 }
}

Recent Swaps within a Pair

Get the last 100 swaps on a pair by fetching Swap events and passing in the pair address. You'll often want token information as well.

{
swaps(orderBy: timestamp, orderDirection: desc, where:
 { pair: "0x5a2d6e67d79f26e434476c56d52d6494c44bd8f9" }
) {
     pair {
       token0 {
         symbol
       }
       token1 {
         symbol
       }
     }
     amount0In
     amount0Out
     amount1In
     amount1Out
     amountUSD
     to
 }
}

Pair Daily Aggregated

Day data is useful for building charts and historical views around entities. To get stats about a pair in daily buckets query for day entities bounded by timestamps. This query gets the first 100 days after the given unix timestamp on the Floki/WBNB pair.

{
 pairDayDatas(first: 100, orderBy: date, orderDirection: asc,
   where: {
     pairAddress: "0x5a2d6e67d79f26e434476c56d52d6494c44bd8f9",
     date_gt: 1592505859
   }
 ) {
     date
     dailyVolumeToken0
     dailyVolumeToken1
     dailyVolumeUSD
     reserveUSD
 }
}

Token Data

Token data can be fetched using the token contract address as an ID. Token data is aggregated across all pairs the token is included in. Any token that is included in some pair in Baby Moon Floki DEX can be queried.

Token Overview

Get a snapshot of the current stats on a token in Baby Moon Floki DEX. This query fetches current stats on USDC. The allPairs field gets the first 200 pairs USDC is included in sorted by liquidity in derived USD.

{
 token(id: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d"){
   name
   symbol
   decimals
   derivedETH
   tradeVolumeUSD
   totalLiquidity
 }
}

All Tokens in Baby Moon Floki DEX

Similar to fetching all pairs (see above), you can query all tokens in Baby Moon Floki DEX. Because The Graph service limits return size to 1000 entities use graphql skip query.

{
   tokens(first: 1000) {
     id
     name
     symbol
   }
}

Token Transactions

This query fetches the latest 30 mints, swaps, and burns.

{
 mints(first: 30, orderBy: timestamp, orderDirection: desc) {
   transaction {
     id
     timestamp
   }
   to
   liquidity
   amount0
   amount1
   amountUSD
 }
 burns(first: 30, orderBy: timestamp, orderDirection: desc) {
   transaction {
     id
     timestamp
   }
   to
   liquidity
   amount0
   amount1
   amountUSD
 }
 swaps(first: 30, orderBy: timestamp, orderDirection: desc) {
   transaction {
     id
     timestamp
   }
   amount0In
   amount0Out
   amount1In
   amount1Out
   amountUSD
   to
 }
}

Token Daily Aggregated

Like pair and global daily lookups, tokens have daily entities that can be queries as well. This query gets daily information for USDC. Note that you may want to sort in ascending order to receive your days from oldest to most recent in the return array.

{
 tokenDayDatas(orderBy: date, orderDirection: asc,
  where: {
    token: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d"
  }
 ) {
    id
    date
    priceUSD
    totalLiquidityToken
    totalLiquidityUSD
    totalLiquidityETH
    dailyVolumeETH
    dailyVolumeToken
    dailyVolumeUSD
 }
}

ETH Price

You can use the Bundle entity to query current USD price of ETH in Baby Moon Floki DEX based on a weighted average of stablecoins.

{
 bundle(id: "1" ) {
   ethPrice
 }
}