-
Notifications
You must be signed in to change notification settings - Fork 155
Streamingfast/docs #765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Streamingfast/docs #765
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b063822
StreamingFast docs on Substreams-powered subgraphs
Giuliano-1 8f92321
added a title
Giuliano-1 0c10608
Add SpS documentation to the menu
enoldev 4b0f462
Fix format
enoldev 34b2a0c
Addressing feedback
Giuliano-1 04ef801
editing the _meta.js
Giuliano-1 3be0142
fix
Giuliano-1 99da12b
trying to fix prettier
Giuliano-1 1252733
fixing prettier
Giuliano-1 a40c3aa
Fix title
enoldev 3817c7a
`sps-intro` => `introduction`
benface 6b97445
Duplicate new pages in every language
benface File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
'sps-intro': '', | ||
'triggers': '', | ||
'triggers-example': '' | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: Introduction | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
--- | ||
|
||
By leveraging a Substreams package (`.yaml`) as a data source, your subgraph gains access to pre-extracted, indexed blockchain data, enabling more efficient and scalable data handling, especially when dealing with large or complex blockchain networks. | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
This technology opens up more efficient and versatile indexing for diverse blockchain environments. For more information on how to build a Substreams-powered subgraph, [click here](./triggers.mdx). You can also visit the following links for How-To Guides on using code-generation tooling to scaffold your first end to end project quickly: | ||
|
||
- [Solana](https://substreams.streamingfast.io/documentation/how-to-guides/intro-your-first-application/solana) | ||
- [EVM](https://substreams.streamingfast.io/documentation/how-to-guides/intro-your-first-application/evm) | ||
- [Injective](https://substreams.streamingfast.io/documentation/how-to-guides/intro-your-first-application/injective) | ||
|
||
**Public Substreams packages** | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
A Substreams package is a precompiled binary file that defines the specific data you want to extract from the blockchain—similar to the `mapping.ts` file in traditional subgraphs. | ||
|
||
Visit [substreams.dev](https://substreams.dev/) to explore a growing collection of ready-to-use Substreams packages across various blockchain networks that can be easily integrated into your subgraph. If you can’t find a suitable Substreams package and want to build your own, click [here](https://thegraph.com/docs/en/substreams/) for detailed instructions on creating a custom package tailored to your needs. | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
--- | ||
title: Example Susbtreams Trigger | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
--- | ||
|
||
Here you’ll walk through a Solana based example for setting up your Substreams-powered subgraph project. If you haven’t already, first check out the [Getting Started Guide](https://github.com/streamingfast/substreams/blob/enol/how-to-guides/docs/new/how-to-guides/intro-how-to-guides.md) for more information on how to initialize your project. | ||
|
||
Consider the following example of a Substreams manifest (`substreams.yaml`), a configuration file similar to the `subgraph.yaml`, using the SPL token program Id: | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```graphql | ||
specVersion: v0.1.0 | ||
package: | ||
name: my_project_sol | ||
version: v0.1.0 | ||
|
||
imports: #Pass your spkg of interest | ||
solana: https://github.com/streamingfast/substreams-solana-spl-token/raw/master/tokens/solana-spl-token-v0.1.0.spkg | ||
|
||
modules: | ||
|
||
- name: map_spl_transfers | ||
use: solana:map_block #Select corresponding modules available within your spkg | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
initialBlock: 260000082 | ||
|
||
- name: map_transactions_by_programid | ||
use: solana:solana:transactions_by_programid_without_votes | ||
|
||
network: solana-mainnet-beta | ||
|
||
params: #Modify the param fields to meet your needs | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
#For program_id: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
map_spl_transfers: token_contract:orcaEKTdK7LKz57vaAYr9QeNsVEPfiu6QeMU1kektZE | ||
``` | ||
|
||
|
||
|
||
Now see the corresponding subgraph manifest **(`subgraph.yaml`)** using a Substreams package as the data source: | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```yaml | ||
specVersion: 1.0.0 | ||
description: my-project-sol Substreams-powered-Subgraph | ||
indexerHints: | ||
prune: auto | ||
schema: | ||
file: ./schema.graphql | ||
dataSources: | ||
- kind: substreams | ||
name: my_project_sol | ||
network: solana-mainnet-beta | ||
source: | ||
package: | ||
moduleName: map_spl_transfers | ||
file: ./my-project-sol-v0.1.0.spkg | ||
mapping: | ||
apiVersion: 0.0.7 | ||
kind: substreams/graph-entities | ||
file: ./src/mappings.ts | ||
handler: handleTriggers | ||
``` | ||
|
||
Once your manifests are created, define in the `schema.graphql` the data fields you’d like saved in your subgraph entities: | ||
|
||
```graphql | ||
type MyTransfer @entity { | ||
id: ID! | ||
amount: String! | ||
source: String! | ||
designation: String! | ||
signers: [String!]! | ||
} | ||
``` | ||
|
||
The Protobuf object is generated in AssemblyScript by running `npm run protogen` after running `substreams codegen subgraph` in the devcontainer, so you can import it in the subgraph code. Then transform your decoded Substreams data within the `src/mappings.ts` file, just like in a standard subgraph: | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```tsx | ||
import { Protobuf } from "as-proto/assembly"; | ||
import { Events as protoEvents } from "./pb/sf/solana/spl/token/v1/Events"; | ||
import { MyTransfer } from "../generated/schema"; | ||
|
||
export function handleTriggers(bytes: Uint8Array): void { | ||
const input: protoEvents = Protobuf.decode<protoEvents>(bytes, protoEvents.decode); | ||
|
||
for (let i=0; i<input.data.length; i++) { | ||
const event = input.data[i]; | ||
|
||
if (event.transfer != null) { | ||
let entity_id: string = `${event.txnId}-${i}`; | ||
const entity = new MyTransfer(entity_id); | ||
entity.amount = (event.transfer!.instruction!.amount).toString(); | ||
entity.source = event.transfer!.accounts!.source; | ||
entity.designation = event.transfer!.accounts!.destination; | ||
|
||
if (event.transfer!.accounts!.signer!.single != null){ | ||
entity.signers = [event.transfer!.accounts!.signer!.single.signer]; | ||
} | ||
else if (event.transfer!.accounts!.signer!.multisig != null) { | ||
entity.signers = event.transfer!.accounts!.signer!.multisig!.signers; | ||
} | ||
entity.save(); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Here's what you’re seeing in the `mappings.ts`: | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
1. The bytes containing Substreams data are decoded into the generated `Transactions` object, this object is used like any other AssemblyScript object | ||
2. Looping over the transactions | ||
3. Create a new subgraph entity for every transaction | ||
|
||
> Note: It's beneficial to have more of your logic in Substreams, as it allows for a parallelized model, whereas triggers are linearly consumed in `graph-node`. | ||
> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
---- | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
title: Substreams Triggers | ||
---- | ||
|
||
Substreams triggers allow you to integrate Substreams data directly into your subgraph. By importing the [Protobuf definitions](https://substreams.streamingfast.io/documentation/develop/creating-protobuf-schemas#protobuf-overview) emitted by your Substreams module, you can receive and process this data in your subgraph's handler. This enables efficient and streamlined data handling within the subgraph framework. | ||
|
||
> Note: If you haven’t already, visit one of the How-To Guides found [here](./sps_intro) to scaffold your first project in the devcontainer. | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
To go through a coded example of a trigger based Subgraph, [click here](./triggers_example). | ||
Giuliano-1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.