diff --git a/website/src/pages/en/subgraphs/developing/creating/advanced.mdx b/website/src/pages/en/subgraphs/developing/creating/advanced.mdx index 525c92e9feaa..8c111e2bff08 100644 --- a/website/src/pages/en/subgraphs/developing/creating/advanced.mdx +++ b/website/src/pages/en/subgraphs/developing/creating/advanced.mdx @@ -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: @@ -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). diff --git a/website/src/pages/en/subgraphs/developing/creating/subgraph-manifest.mdx b/website/src/pages/en/subgraphs/developing/creating/subgraph-manifest.mdx index 9fe50054e22a..fb87487170bf 100644 --- a/website/src/pages/en/subgraphs/developing/creating/subgraph-manifest.mdx +++ b/website/src/pages/en/subgraphs/developing/creating/subgraph-manifest.mdx @@ -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. @@ -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`. |