🧑💻2024/08/08
Review of recent & in-progress subgraph DX enhancements (+ a few ideas)
Presentation feedback
Please submit your feedback in this form.
Q4 2023 -> Q2 2024
Aggregations and timeseries
Timeseries and aggregations enable your subgraph to track statistics like daily average price, hourly total transfers, etc.
This feature introduces two new types of subgraph entity. Timeseries entities record data points with timestamps. Aggregation entities perform pre-declared calculations on the Timeseries data points on an hourly or daily basis, then store the results for easy access via GraphQL.
Timeseries entities are defined with @entity(timeseries: true) in schema.graphql, while aggregation entities are defined with @aggregation.
Every timeseries entity must have a unique ID of the int8 type, a timestamp of the Timestamp type, and include data that will be used for calculation by aggregation entities.
These Timeseries entities can be saved in regular trigger handlers, and act as the “raw data” for the Aggregation entities.
Every aggregation entity defines the source from which it will gather data (which must be a Timeseries entity), sets the intervals (e.g., hour, day), and specifies the aggregation function it will use (e.g., sum, count, min, max, first, last).
Aggregation entities are automatically calculated on the basis of the specified source at the end of the required interval.
Example GraphQL query
Learn more about aggregations here.
Indexed argument filtering
Topic filters, also known as indexed argument filters, allow developers to precisely filter blockchain events based on the values of their indexed arguments.
When a smart contract emits an event, any arguments that are marked as indexed can be used as filters in a subgraph's manifest. This allows the subgraph to listen selectively for events that match these indexed arguments.
The Ethereum Virtual Machine (EVM) allows up to three indexed arguments per event.
The first indexed argument corresponds to
topic1, the second totopic2, and third totopic3
Token.sol
Topic filters are defined directly within the event handler configuration in the subgraph manifest.
subgraph.yaml with Topic 1 and Topic 2 filters for Transfer event
In this configuration:
topic1is configured to filterTransferevents where0xAddressAis the sender.topic2is configured to filterTransferevents where0xAddressBis the receiver.The subgraph will only index transactions that occur directly from
0xAddressAto0xAddressB.
Declarative eth_calls
Allows eth_calls to be executed ahead of time, enabling graph-node to execute them in parallel.
Declared eth_calls can access the event.address of the underlying event as well as all the event.params.
subgraph.yamlwith event.address
Details for the example above:
global0X128is the label of a declaredeth_call. So isglobal1X128.Pool[event.address].feeGrowthGlobal0X128()is the actualeth_callthat will be executed, which is in the form ofContract[address].function(arguments)The
addressandargumentscan be replaced with variables that will be available when the handler is executed.
subgraph.yaml with event.params
Q3 2024
In progress work in E&N's Graph Node team
Subgraph as dataSource/reuse existing entities
Functionality that allows subgraphs to query and leverage data from other subgraphs. This can be achieved by creating a separate blockstream that fetches triggers from subgraph database tables. New entities will be triggers.
subgraph.yaml
IPFS robustness improvements
Why? Enhanced scalability and reliability.
Migrate to IPFS Gateway API
Separate IPFS file hosting
i.e. required subgraph definition files vs optional IPFS File Data Sources
subgraph.yaml
schema.graphql
src/mappings.ts
kind: file/ipfs
Ideas
Early stage concepts that may never reach production
Plug-in system
Generic structure
subgraph.yaml
schema.graphql
ENS
Primary name reverse lookup
subgraph.yaml
schema.graphql
Oracle-powered price feeds
Chronicle Protocol
subgraph.yaml
schema.graphql
src/mappings/blocks.ts
query.graphql
Chainlink AggregatorV3Interface
subgraph.yaml
schema.graphql
src/mappings/blocks.ts
query.graphql
Last updated