Queries
The subgraph can be queried to retrieve important information about Pegasys, pairs, tokens, transactions, users, and more. This page will provide examples for common queries.
To try these queries and run your own visit the subgraph sandbox.
#
Global DataTo query global data you can pass in the Pegasys Factory address and select from available fields.
#
Global StatsAll time volume in USD, total liquidity in USD, all time transaction count.
#
Global Historical lookupTo get a snapshot of past state, use The Graph's block query feature and query at a previous block. See this post to get more information about fetching block numbers from timestamps. This can be used to calculate things like 24hr volume.
#
Pair Data#
Pair OverviewFetch a snapshot of the current state of the pair with common values. This example fetches the DAI/WSYS pair.
#
All pairs in PegasysThe Graph limits entity return amounts to 1000 per query as of now. To get all pairs on Pegasys use a loop and graphql skip query to fetch multiple chunks of 1000 pairs. The query would look like this (where skip is some incrementing variable passed into your query).
#
Most liquid pairsOrder by liquidity to get the most liquid pairs in Pegasys.
#
Recent Swaps within a PairGet 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.
#
Pair Daily AggregatedDay 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 DAI/WSYS pair.
#
Token DataToken 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 Pegasys can be queried.
#
Token OverviewGet a snapshot of the current stats on a token in Pegasys. This query fetches current stats on DAI. The allPairs field gets the first 200 pairs DAI is included in sorted by liquidity in derived USD.
#
All Tokens in PegasysSimilar to fetching all pairs (see above), you can query all tokens in Pegasys. Because The Graph service limits return size to 1000 entities use graphql skip query. (Note this query will not work in the graph sandbox and more resembles the structure of a query you'd pass to some graphql middleware like Apollo).
#
Token TransactionsTo get transactions that include a token you'll need to first fetch an array of pairs that the token is included in (this can be done with the allPairs field on the Token entity.) Once you have an array of pairs the token is included in, filter on that in the transaction lookup.
This query fetches the latest 30 mints, swaps, and burns involving DAI. The allPairs array could look something like this where we include the DAI/WSYS pair address and the USDC/WSYS pair address.
#
Token Daily AggregatedLike pair and global daily lookups, tokens have daily entities that can be queries as well. This query gets daily information for DAI. Note that you may want to sort in ascending order to receive your days from oldest to most recent in the return array.
#
SYS PriceYou can use the Bundle entity to query current USD price of SYS in Pegasys based on a weighted average of stablecoins.