Skip to content

Commit

Permalink
Update Astar WASM Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbayly committed Oct 13, 2023
1 parent 9bf4a2c commit e34bab9
Show file tree
Hide file tree
Showing 3 changed files with 280 additions and 180 deletions.
191 changes: 114 additions & 77 deletions docs/build/substrate-evm.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ We provide a custom data source processor for [Parity's Frontier EVM](https://gi

**Tested and Supported networks**

| Network Name | Websocket Endpoint | Dictionary Endpoint |
| -------------- | -------------------------------------------------- | ----------------------------------------------------------------------- |
| Moonbeam | `wss://moonbeam.api.onfinality.io/public-ws` | `https://api.subquery.network/sq/subquery/moonbeam-dictionary` |
| Moonriver | `wss://moonriver.api.onfinality.io/public-ws` | `https://api.subquery.network/sq/subquery/moonriver-dictionary` |
| Moonbase Alpha | `wss://moonbeam-alpha.api.onfinality.io/public-ws` | `https://api.subquery.network/sq/subquery/moonbase-alpha-dictionary` |
| Astar | `wss://astar.api.onfinality.io/public-ws` | `https://explorer.subquery.network/subquery/subquery/astar-dictionary` |
| Shiden | `wss://shiden.api.onfinality.io/public-ws` | `https://explorer.subquery.network/subquery/subquery/shiden-dictionary` |
| Acala | `wss://acala-polkadot.api.onfinality.io/public-ws` | `https://explorer.subquery.network/subquery/subquery/acala-dictionary` |
| Karura | `wss://karura.api.onfinality.io/public-ws` | `https://explorer.subquery.network/subquery/subquery/karura-dictionary` |

Theoretically the following networks should also be supported since they implement Parity's Frontier EVM. Please let us know if you verify this and we can add them to the known support:

Theoretically all the following networks (and more) should also be supported since they implement Parity's Frontier EVM. Please let us know if you verify this and we can add them to the known support:

- Moonbeam
- Moonriver
- Moonbase Alpha
- Acala
- Karura
- Astar
- Shiden
- Automata
- Bitcountry
- Clover
Expand All @@ -41,7 +38,7 @@ Theoretically the following networks should also be supported since they impleme
1. Add the custom datasource as a dependency:

- Create a new project from an EVM template though `subql init` OR
- For existing projects, `yarn add @subql/frontier-evm-processor` or `npm i @subql/acala-evm-processor`.
- For existing projects, `yarn add -D @subql/frontier-evm-processor` or `npm i @subql/acala-evm-processor --save-dev`.

2. Add exports to your `package.json` like below in order for IPFS deployments to work

Expand All @@ -54,6 +51,32 @@ Theoretically the following networks should also be supported since they impleme
}
```

3. Import processor file to your `project.ts` like below

```ts
import { FrontierEvmDatasource } from "@subql/frontier-evm-processor";

const project: SubstrateProject<FrontierEvmDatasource> = {
...
dataSources: [
{
// This is the datasource for Moonbeam's Native Substrate processor
kind: "substrate/FrontierEvm",
startBlock: 752073,
processor: {
file: "./node_modules/@subql/frontier-evm-processor/dist/bundle.js",
options: {
abi: "erc20",
address: "0xe3e43888fa7803cdc7bea478ab327cf1a0dc11a7", // FLARE token https://moonscan.io/token/0xe3e43888fa7803cdc7bea478ab327cf1a0dc11a7
},
},
assets: new Map([["erc20", { file: "./abis/erc20.abi.json" }]]),
mapping: {...},
},
],
}
```

3. Add a custom data source as described below.
4. Add handlers for the custom data source to your code.

Expand Down Expand Up @@ -240,74 +263,88 @@ This is an extract from the `project.ts` manifest file.
::: code-tabs
@tab Frontier EVM

```yaml
dataSources:
- kind: substrate/FrontierEvm
startBlock: 752073
processor:
file: "./node_modules/@subql/frontier-evm-processor/dist/bundle.js"
options:
# Must be a key of assets
abi: erc20
# Contract address (or recipient if transfer) to filter, if `null` should be for contract creation
address: "0x6bd193ee6d2104f14f94e2ca6efefae561a4334b"
assets:
erc20:
file: ./erc20.abi.json
mapping:
file: ./dist/index.js
handlers:
- handler: handleFrontierEvmEvent
kind: substrate/FrontierEvmEvent
filter:
topics:
- "Transfer(address indexed from,address indexed to,uint256 value)"
- null
- null
- null
- handler: handleFrontierEvmCall
kind: substrate/FrontierEvmCall
filter:
## The function can either be the function fragment or signature
# function: '0x095ea7b3'
# function: '0x7ff36ab500000000000000000000000000000000000000000000000000000000'
# function: approve(address,uint256)
function: "approve(address to,uint256 value)"
```ts
{
dataSources: [
{
// This is the datasource for Moonbeam's Native Substrate processor
kind: "substrate/FrontierEvm",
startBlock: 752073,
processor: {
file: "./node_modules/@subql/frontier-evm-processor/dist/bundle.js",
options: {
abi: "erc20",
address: "0xe3e43888fa7803cdc7bea478ab327cf1a0dc11a7", // FLARE token https://moonscan.io/token/0xe3e43888fa7803cdc7bea478ab327cf1a0dc11a7
},
},
assets: new Map([["erc20", { file: "./erc20.abi.json" }]]),
mapping: {
file: "./dist/index.js",
handlers: [
{
handler: "handleEvmEvent",
kind: "substrate/FrontierEvmEvent",
filter: {
topics: [
"Transfer(address indexed from,address indexed to,uint256 value)",
],
},
},
{
handler: "handleEvmCall",
kind: "substrate/FrontierEvmCall",
filter: {
function: "approve(address to,uint256 value)",
},
},
],
},
},
],
}
```

@tab Acala EVM+

```yaml
dataSources:
- kind: substrate/AcalaEvm
startBlock: 752073
processor:
file: "./node_modules/@subql/contract-processors/dist/acalaEvm.js"
options:
# Must be a key of assets
abi: erc20
# Contract address (or recipient if transfer) to filter, if `null` should be for contract creation
address: "0x6bd193ee6d2104f14f94e2ca6efefae561a4334b"
assets:
erc20:
file: "./erc20.abi.json"
mapping:
file: "./dist/index.js"
handlers:
- handler: handleAcalaEvmEvent
kind: substrate/AcalaEvmEvent
filter:
topics:
- Transfer(address indexed from,address indexed to,uint256 value)
- handler: handleAcalaEvmCall
kind: substrate/AcalaEvmCall
filter:
## The function can either be the function fragment or signature
# function: '0x095ea7b3'
# function: '0x7ff36ab500000000000000000000000000000000000000000000000000000000'
# function: approve(address,uint256)
function: approve(address to,uint256 value)
from: "0x6bd193ee6d2104f14f94e2ca6efefae561a4334b"
```ts
{
dataSources: [
{
// This is the datasource for Acala's EVM processor
kind: "substrate/AcalaEvm",
startBlock: 1000000,
processor: {
file: "./node_modules/@subql/acala-evm-processor/dist/bundle.js",
options: {
abi: "erc20",
address: "0x0000000000000000000100000000000000000000", // ACA Token https://blockscout.acala.network/address/0x0000000000000000000100000000000000000000
},
},
assets: new Map([["erc20", { file: "./erc20.abi.json" }]]),
mapping: {
file: "./dist/index.js",
handlers: [
{
handler: "handleAcalaEvmEvent",
kind: "substrate/AcalaEvmEvent",
filter: {
topics: [
"Transfer(address indexed from,address indexed to,uint256 value)",
],
},
},
{
handler: "handleAcalaEvmCall",
kind: "substrate/AcalaEvmCall",
filter: {
function: "approve(address to,uint256 value)",
},
},
],
},
},
],
}
```

:::
Expand Down
108 changes: 65 additions & 43 deletions docs/build/substrate-wasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,35 @@ We provide a custom data source processor for [Substrate WASM contract](https://
There is a [friendly quick start guide that introduces SubQuery's Substrate WASM support by using an example project in Astar Network](../quickstart/quickstart_chains/polkadot-astar.md). This guide covers most of the topics shown in the following guide in a format more easy to understand. You can return here when you need specific technical support for the Substrate WASM data source processor.
:::

**Tested and Supported networks**

| Network Name | Websocket Endpoint | Dictionary Endpoint |
| ------------ | -------------------------------------------- | -------------------------------------------------------------- |
| Astar | Coming soon | Coming soon |
| Shiden | `wss://shiden.api.onfinality.io/public-ws` | `https://api.subquery.network/sq/subquery/shiden-dictionary` |
| Shibuya | | `https://api.subquery.network/sq/subquery/shibuya-dictionary` |
| Edgeware | `wss://edgeware.api.onfinality.io/public-ws` | `https://api.subquery.network/sq/subquery/edgeware-dictionary` |

**You can also refer to the basic [Substrate WASM](https://github.com/subquery/subql-starter/tree/main/Astar/astar-evm-starter) example projects with an event and call handler.** This project is also hosted live in the SubQuery Explorer [here](https://explorer.subquery.network/subquery/subquery/tutorial-substrate-wasm-starter).
**You can also refer to the basic [Substrate WASM](../quickstart/quickstart_chains/polkadot-astar.md) example projects with an event and call handler.** This project is also hosted live in the SubQuery Explorer [here](https://explorer.subquery.network/subquery/subquery/tutorial-substrate-wasm-starter).

## Getting started

1. Add the custom datasource as a dependency. Create a new project from an WASM starter template though `subql init` OR for existing projects, `yarn add @subql/substrate-wasm-processor`.
1. Add the custom datasource as a dependency. Create a new project from an WASM starter template though `subql init` OR for existing projects, `yarn add -D @subql/substrate-wasm-processor`.
2. Import processor file to your `project.ts` like below

```yaml
```ts
import { WasmDatasource } from "@subql/substrate-wasm-processor";

const project: SubstrateProject<WasmDatasource> = {
...
dataSources:
- kind: substrate/Wasm
startBlock: 970733
processor:
file: ./node_modules/@subql/substrate-wasm-processor/dist/bundle.js
dataSources: [
{
// This is the datasource for Astar's Wasm processor
kind: "substrate/Wasm",
startBlock: 3281780,
processor: {
file: "./node_modules/@subql/substrate-wasm-processor/dist/bundle.js",
options: {
abi: "erc20",
contract: "bZ2uiFGTLcYyP8F88XzXa13xu5Mmp13VLiaW1gGn7rzxktc", // Mainnet,
},
},
assets: new Map([["erc20", { file: "./abis/erc20Metadata.abi.json" }]]),
mapping: {...},
},
],
}
```

3. Add a custom data source as described below.
Expand Down Expand Up @@ -172,32 +178,48 @@ export async function handleSubstrateWasmEvent(

This is an extract from the `project.ts` manifest file.

```yaml
dataSources:
- kind: substrate/Wasm
startBlock: 970733
processor:
file: ./node_modules/@subql/substrate-wasm-processor/dist/bundle.js
options:
abi: erc20
contract: "a6Yrf6jAPUwjoi5YvvoTE4ES5vYAMpV55ZCsFHtwMFPDx7H"
assets:
erc20:
file: ./erc20Metadata.json
mapping:
file: ./dist/index.js
handlers:
- handler: handleSubstrateWasmEvent
kind: substrate/WasmEvent
filter:
# from: 'xxxx'
contract: "a6Yrf6jAPUwjoi5YvvoTE4ES5vYAMpV55ZCsFHtwMFPDx7H"
identifier: "Transfer"
- handler: handleSubstrateCall
kind: substrate/WasmCall
filter:
selector: "0x681266a0"
method: "approve"
```ts
{
dataSources: [
{
// This is the datasource for Astar's Native Substrate processor
kind: "substrate/Wasm",
// This is the datasource for Astar's Wasm processor
startBlock: 3281780,
processor: {
file: "./node_modules/@subql/substrate-wasm-processor/dist/bundle.js",
options: {
abi: "erc20",
// contract: "a6Yrf6jAPUwjoi5YvvoTE4ES5vYAMpV55ZCsFHtwMFPDx7H" // Shibuya
contract: "bZ2uiFGTLcYyP8F88XzXa13xu5Mmp13VLiaW1gGn7rzxktc", // Mainnet,
},
},
assets: new Map([["erc20", { file: "./abis/erc20Metadata.abi.json" }]]),
mapping: {
file: "./dist/index.js",
handlers: [
{
handler: "handleWasmEvent",
kind: "substrate/WasmEvent",
filter: {
// contract: "a6Yrf6jAPUwjoi5YvvoTE4ES5vYAMpV55ZCsFHtwMFPDx7H" // Shibuya
contract: "bZ2uiFGTLcYyP8F88XzXa13xu5Mmp13VLiaW1gGn7rzxktc", // Mainnet
identifier: "Transfer",
},
},
{
handler: "handleWasmCall",
kind: "substrate/WasmEvent",
filter: {
selector: "0x681266a0",
method: "approve",
},
},
],
},
},
],
}
```

## Querying contracts
Expand Down
Loading

0 comments on commit e34bab9

Please sign in to comment.