Timeswap
Published in

Timeswap

Using the Timeswap subgraph

What is subgraph?

The Graph is a decentralized protocol, which is used for indexing and querying data from blockchains, using events emitted by the transactions. It makes it possible to query data that is difficult to query directly.

How to use Timeswap subgraph?

  1. Visit the Timeswap subgraph https://thegraph.com/hosted-service/subgraph/emmanuelantony2000/timeswap-v1/
  2. This houses the playground where you can play around with the queries and retrieve the data for Timeswap. As soon as you visit this webpage, you will see 3 sections:
  • Queries’ section: This is the section in which you will also see the ‘Example query’. All the queries that you would want to run across the Graph have to mentioned over here. This will involve the example query and a few more that we have mentioned below. Note: the example query currently live uses the term “eRC20Tokens”; this is now revised to “erc20Tokens”. We are in the process of updating the sample query on the above link, but it will take sometime, hence, request you to please make this change when you run this query
  • Results’ section: This is self-explanatory
  • Schema section: Each Graph Query has to follow a rule-book. You can say schema is the rule book.

The resulting data is in JSON format, which is the key-value format. Where key is the property name and value is its corresponding data.

Example query 1:

{
timeswapFactories{
id
tokenCount
pairCount
poolCount
}
}

Explanation of the example query:

  • timeswapFactory is an entity defined in the schema. If you check on the schema(right-hand side) and check for timeswapFactory entity, you’ll find the properties that are defined in this entity:
  • The first one is the id which is of type ID. id is used to make the entity unique.
    Here, in the TimeswapFactory, the id is defined by the address of the factory contract. So, id should give you the factory address as result.
  • tokenCount: It gives the total count of unique tokens deployed in the timeswap pairs. For example, if there is only 1 pair deployed on timeswap, so you’ll see 2 as tokenCount. One for the asset and one for the collateral. But if the same tokens are used in other pairs, the tokenCount won’t increase, because only unique tokens are counted.
  • pairCount: it is the total number of pair that is deployed on Timeswap.
  • poolCount: It is the total number of unique pools that are deployed on timeswap.

So when you run the above query you will get the address of timeswap factory contact, number of tokens count, number of pairs, and number of pools:

Example query 2:

{
pools{
pair{
asset{
id
name
symbol
}
collateral{
id
name
symbol
}
}
maturity
}
}

The above query will give you the asset details (id=address of asset token, name=name of asset token, symbol=symbol of asset token), collateral details, and the maturity of the pool.

When you execute the above query, you’ll get the following resulting data:

Similarly, you can play around with different queries by looking into the schema and trying to create your own query ;)

Important Links

Website: www.timeswap.io
Twitter: https://twitter.com/TimeswapLabs
Discord: https://discord.gg/YTUtTJfc6S
Telegram: t.me/timeswap
Medium: http://timeswap.medium.com

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store