Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Support for ranged time-travel queries #37

Open
@cvauclair

Description

Description

The Graph supports time-travel queries where one can optionally specify the block number at which query should be executed. This will execute the query against the state of the subgraph at that block (see time-travel queries documentation).

Currently, Subgrounds supports this out of the box. Using the Uniswap V3 subgraph as reference:

>>> pair = uniswap_v3.Query.pool(
...   id='0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8',
...   block={'number': 14673000}
... )

>>> sg.query([
...   pair.token0Price,
...   pair.token1Price
... ])
(2918.0646522066227, 0.00034269288695978894)

However, if one wishes to query the subgraph at multiple blocks (e.g.: getting historical data), one still has to create multiple queries. Subgrounds should support support providing a block range and interval to make it easier to run a query at multiple blocks. For example (WIP, not final):

>>> pair = uniswap_v3.Query.pool(
...   id='0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8',
...   block={
...     'from': 14663000,
...     'to': 14674000,
...     'interval': 1000
...   }
... )

>>> sg.query([
...   pair.token0Price,
...   pair.token1Price
... ])
[
  (14663000, 2807.466744495506, 0.0003561929992441272),
  (14664000, 2831.947023023911, 0.00035311395017983597),
  (14665000, 2866.517275937252, 0.0003488553892189729),
  ...
  (14674000, 2929.497568964089, 0.0003413554633375626),
]

If Subgrounds is performing a ranged time-travel query, then the returned data should be a list containing the query result at each block with an additional block field indicating the block at which the query was executed.

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions