Search…
Queries
The subgraph can be queried to retrieve important information about SwipeSwap, pairs, tokens, transactions, users, and more. This page will provide examples for common queries.
To try these queries and run your own visit the Exchange subgraph sandbox.

Global Data

To query global data you can pass in the SwipSwap Factory address and select from available fields.
Global Stats
All time volume in USD, total liquidity in USD, all time transaction count.
1
{
2
swipeswapFactory(id: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f") {
3
totalVolumeUSD
4
totalLiquidityUSD
5
txCount
6
}
7
}
Copied!
Global Historical lookup
To 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.
1
{
2
swipeswapFactory(
3
id: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
4
block: {number: 10291203}
5
) {
6
totalVolumeUSD
7
totalLiquidityUSD
8
txCount
9
}
10
}
Copied!

Pair Data

Pair Overview
Fetch a snapshot of the current state of the pair with common values. This example fetches the DAI/WETH pair.
1
{
2
pair(id: "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11") {
3
token0 {
4
id
5
symbol
6
name
7
derivedETH
8
}
9
token1 {
10
id
11
symbol
12
name
13
derivedETH
14
}
15
reserve0
16
reserve1
17
reserveUSD
18
trackedReserveETH
19
token0Price
20
token1Price
21
volumeUSD
22
txCount
23
}
24
}
Copied!
All pairs in SwipeSwap
The Graph limits entity return amounts to 1000 per query as of now. To get all pairs on SwipeSwap 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).
1
{
2
query pairs($skip: Int!) {
3
pairs(first: 1000, skip: $skip) {
4
id
5
}
6
}
7
}
Copied!
Most liquid pairs
Order by liquidity to get the most liquid pairs in SwipeSwap.
1
{
2
pairs(first: 1000, orderBy: reserveUSD, orderDirection: desc) {
3
id
4
}
5
}
Copied!
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.
1
{
2
swaps(orderBy: timestamp, orderDirection: desc, where: {pair: "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11" }) {
3
pair {
4
token0 { symbol }
5
token1 { symbol }
6
}
7
amount0In
8
amount0Out
9
amount1In
10
amount1Out
11
amountUSD
12
to
13
}
14
}
Copied!
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 DAI/WETH pair.
1
{
2
pairDayDatas(
3
first: 100, orderBy: date, orderDirection: asc,
4
where: {
5
pairAddress: "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11",
6
date_gt: 1592505859
7
}
8
) {
9
date
10
dailyVolumeToken0
11
dailyVolumeToken1
12
dailyVolumeUSD
13
reserveUSD
14
}
15
}
Copied!

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 SwipeSwap can be queried.
Token Overview
Get a snapshot of the current stats on a token in SwipeSwap. 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.
1
{
2
token(id: "0x6b175474e89094c44da98b954eedeac495271d0f") {
3
name
4
symbol
5
decimals
6
derivedETH
7
tradeVolumeUSD
8
totalLiquidity
9
}
10
}
Copied!
All Tokens in SwipeSwap
Similar to fetching all pairs (see above), you can query all tokens in SwipeSwap. 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).
1
{
2
query tokens($skip: Int!) {
3
tokens(first: 1000, skip: $skip) {
4
id
5
name
6
symbol
7
}
8
}
9
}
Copied!
Token Transactions
To 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/WETH pair address and the DAI/USDC pair address.
1
allPairs = [
2
"0xa478c2975ab1ea89e8196811f51a7b7ade33eb11",
3
"0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5"
4
]
Copied!
1
query($allPairs: [String!]) {
2
mints(first: 30, where: { pair_in: $allPairs }, orderBy: timestamp, orderDirection: desc) {
3
transaction {
4
id
5
timestamp
6
}
7
to
8
liquidity
9
amount0
10
amount1
11
amountUSD
12
}
13
burns(first: 30, where: { pair_in: $allPairs }, orderBy: timestamp, orderDirection: desc) {
14
transaction {
15
id
16
timestamp
17
}
18
to
19
liquidity
20
amount0
21
amount1
22
amountUSD
23
}
24
swaps(first: 30, where: { pair_in: $allPairs }, orderBy: timestamp, orderDirection: desc) {
25
transaction {
26
id
27
timestamp
28
}
29
amount0In
30
amount0Out
31
amount1In
32
amount1Out
33
amountUSD
34
to
35
}
36
}
Copied!
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 DAI. Note that you may want to sort in ascending order to receive your days from oldest to most recent in the return array.
1
{
2
tokenDayDatas(orderBy: date, orderDirection: asc, where: {
3
token: "0x6b175474e89094c44da98b954eedeac495271d0f"
4
}) {
5
id
6
date
7
priceUSD
8
totalLiquidityToken
9
totalLiquidityUSD
10
totalLiquidityETH
11
dailyVolumeETH
12
dailyVolumeToken
13
dailyVolumeUSD
14
}
15
}
Copied!

ETH Price

You can use the Bundle entity to query current USD price of ETH in SwipeSwap based on a weighted average of stablecoins.
1
{
2
bundle(id: "1" ) {
3
ethPrice
4
}
5
}
Copied!
Last modified 1yr ago
Copy link
Contents