Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions website/src/pages/en/subgraphs/developing/creating/advanced.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -504,17 +504,19 @@ Total time taken = max (3, 2, 4) = 4 seconds

#### Example Configuration in Subgraph Manifest

> This feature is available from `specVersion: 1.2.0`

Declared `eth_calls` can access the `event.address` of the underlying event as well as all the `event.params`.

`subgraph.yaml` using `event.address`:

```yaml
eventHandlers:
event: Swap(indexed address,indexed address,int256,int256,uint160,uint128,int24)
handler: handleSwap
calls:
global0X128: Pool[event.address].feeGrowthGlobal0X128()
global1X128: Pool[event.address].feeGrowthGlobal1X128()
- event: Swap(indexed address,indexed address,int256,int256,uint160,uint128,int24)
handler: handleSwap
calls:
global0X128: Pool[event.address].feeGrowthGlobal0X128()
global1X128: Pool[event.address].feeGrowthGlobal1X128()
```

Details for the example above:
Expand All @@ -528,9 +530,32 @@ Details for the example above:

```yaml
calls:
- ERC20DecimalsToken0: ERC20[event.params.token0].decimals()
ERC20DecimalsToken0: ERC20[event.params.token0].decimals()
```

`calls` is a map from labels to calls, not a list, so each entry is written as `label: call` without a leading `-`.

#### Accessing struct fields

> This feature is available from `specVersion: 1.4.0`

When an event parameter is a struct (a tuple in the ABI), a declared call can read one of its fields, either by position or by name:

```yaml
eventHandlers:
- event: AssetTransfer((address,uint256,bool),address,uint256)
handler: handleAssetTransfer
calls:
asset_owner: Contract[event.address].getOwner(event.params.asset.0)
- event: ComplexAssetCreated(((address,uint256,bool),string,uint256[]),uint256)
handler: handleComplexAssetCreated
calls:
base_asset_owner: Contract[event.address].getOwner(event.params.complexAsset.base.addr)
```

- `event.params.asset.0` reads the first field of the `asset` struct.
- `event.params.complexAsset.base.addr` reads the `addr` field of the `base` struct nested inside `complexAsset`. Field names come from the event's ABI.

### Grafting onto Existing Subgraphs

> **Note:** it is not recommended to use grafting when initially upgrading to The Graph Network. Learn more [here](/subgraphs/best-practices/grafting/#when-not-to-use-grafting).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dataSources:

The important entries to update for the manifest are:

- `specVersion`: a semver version that identifies the supported manifest structure and functionality for the Subgraph. The latest version is `1.3.0`. See [specVersion releases](#specversion-releases) section to see more details on features & releases.
- `specVersion`: a semver version that identifies the supported manifest structure and functionality for the Subgraph. See the [specVersion releases](#specversion-releases) section for the available versions and the features each one adds.

- `description`: a human-readable description of what the Subgraph is. This description is displayed in Graph Explorer when the Subgraph is deployed to Subgraph Studio.

Expand Down Expand Up @@ -539,6 +539,7 @@ indexerHints:

| Version | Release notes |
| :-: | --- |
| 1.4.0 | Added support for accessing [struct fields in declared `eth_call`s](/subgraphs/developing/creating/advanced/#accessing-struct-fields) |
| 1.3.0 | Added support for [Subgraph Composition](/subgraphs/best-practices/subgraph-composition/) |
| 1.2.0 | Added support for [Indexed Argument Filtering](/subgraphs/developing/creating/advanced/#indexed-argument-filters--topic-filters) & declared `eth_call` |
| 1.1.0 | Supports [Timeseries & Aggregations](/subgraphs/developing/creating/advanced/#timeseries-and-aggregations). Added support for type `Int8` for `id`. |
Expand Down
Loading