Skip to content

Commit

Permalink
VARA and AVAIL (#64)
Browse files Browse the repository at this point in the history
* adding VARA project (#53)

* Adding Avail network (#63)

* adding avail network

* fix problem with handleres

* update index file

* update reward curve

* fix genesis name

* update readme with required steps

* Adding VARA to multichain (#62)
  • Loading branch information
stepanLav authored May 27, 2024
1 parent 8f34ac2 commit 458fe49
Show file tree
Hide file tree
Showing 10 changed files with 539 additions and 10 deletions.
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,36 @@ Last, under the project directory, run following command to install all the depe
yarn install
```

## Configure your project
## Adding a New Network

In the starter package, we have provided a simple example of project configuration. You will be mainly working on the following files:
To add a new network to your SubQuery project, follow these steps:

- The Manifest in `project.yaml`
- The GraphQL Schema in `schema.graphql`
- The Mapping functions in `src/mappings/` directory
1. **Create a Project YAML File**:
- Create a new file named `project-{name}.yaml` in the root directory of your project.
- This file will contain the configuration specific to the new network.

For more information on how to write the SubQuery,
check out our doc section on [Define the SubQuery](https://doc.subquery.network/define_a_subquery.html)
2. **Set Network Data**:
- In the newly created `project-{name}.yaml` file, set the network parameters such as `endpoint`, `genesisHash`, and other relevant details.

#### Code generation
3. **Add Separate Mapping**:
- Create a new mapping file in the [src/mappings/](src/mappings) directory, named `{name}.ts`.
- This file should include the necessary handlers and logic for the new network.

4. **Include Genesis, DIRECT_STAKING_TYPE, and RewardCurveConfig**:
- In your new mapping file, ensure you define the `genesis`, `DIRECT_STAKING_TYPE`, and `rewardCurveConfig` specific to the new network.

5. **Export in `src/index.ts`**:
- Update the [src/index.ts](./src/index.ts) file to export the new handlers from your `{name}.ts` mapping file.

6. **Add Network Types**:
- If the new network requires custom types, add them to the `chainTypes` section in the appropriate configuration file. Do not forget to add new exports in [package.json](./package.json)

7. **Update `@subquery-multichain.yaml`**:
- Add the new project file to the `projects` array in [subquery-multichain.yaml](./subquery-multichain.yaml).

By following these steps, you can extend your SubQuery project to support additional networks.

## Code generation

In order to index your SubQuery project, it is mandatory to build your project first.
Run this command under the project directory.
Expand Down
183 changes: 183 additions & 0 deletions chainTypes/availChainTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
import { OverrideBundleDefinition } from "@polkadot/types/types";

const definitions: OverrideBundleDefinition = {
types: [
{
minmax: [0, undefined],
types: {
"AppId": "Compact<u32>",
"DataLookupItem": {
"appId": "AppId",
"start": "Compact<u32>"
},
"CompactDataLookup": {
"size": "Compact<u32>",
"index": "Vec<DataLookupItem>"
},
"KateCommitment": {
"rows": "Compact<u16>",
"cols": "Compact<u16>",
"commitment": "Vec<u8>",
"dataRoot": "H256"
},
"V3HeaderExtension": {
"appLookup": "CompactDataLookup",
"commitment": "KateCommitment"
},
"HeaderExtension": {
"_enum": {
"V1": null,
"V2": null,
"V3": "V3HeaderExtension"
}
},
"DaHeader": {
"parentHash": "Hash",
"number": "Compact<BlockNumber>",
"stateRoot": "Hash",
"extrinsicsRoot": "Hash",
"digest": "Digest",
"extension": "HeaderExtension"
},
"Header": "DaHeader",
"CheckAppIdExtra": {
"appId": "AppId"
},
"CheckAppIdTypes": {},
"CheckAppId": {
"extra": "CheckAppIdExtra",
"types": "CheckAppIdTypes"
},
"BlockLengthColumns": "Compact<u32>",
"BlockLengthRows": "Compact<u32>",
"BlockLength": {
"max": "PerDispatchClass",
"cols": "BlockLengthColumns",
"rows": "BlockLengthRows",
"chunkSize": "Compact<u32>"
},
"PerDispatchClass": {
"normal": "u32",
"operational": "u32",
"mandatory": "u32"
},
"DataProof": {
"roots": "TxDataRoots",
"proof": "Vec<H256>",
"numberOfLeaves": "Compact<u32>",
"leafIndex": "Compact<u32>",
"leaf": "H256"
},
"TxDataRoots": {
"dataRoot": "H256",
"blobRoot": "H256",
"bridgeRoot": "H256"
},
"ProofResponse": {
"dataProof": "DataProof",
"message": "Option<AddressedMessage>"
},
"AddressedMessage": {
"message": "Message",
"from": "H256",
"to": "H256",
"originDomain": "u32",
"destinationDomain": "u32",
"id": "u64"
},
"Message": {
"_enum": {
"ArbitraryMessage": "ArbitraryMessage",
"FungibleToken": "FungibleToken"
}
},
"MessageType": {
"_enum": [
"ArbitraryMessage",
"FungibleToken"
]
},
"FungibleToken": {
"assetId": "H256",
"amount": "String"
},
"BoundedData": "Vec<u8>",
"ArbitraryMessage": "BoundedData",
"Cell": {
"row": "u32",
"col": "u32"
}
},
},
],
rpc: {
"kate": {
"blockLength": {
"description": "Get Block Length",
"params": [
{
"name": "at",
"type": "Hash",
"isOptional": true
}
],
"type": "BlockLength"
},
"queryProof": {
"description": "Generate the kate proof for the given `cells`",
"params": [
{
"name": "cells",
"type": "Vec<Cell>"
},
{
"name": "at",
"type": "Hash",
"isOptional": true
}
],
"type": "Vec<(U256, [u8; 48])>"
},
"queryDataProof": {
"description": "Generate the data proof for the given `transaction_index`",
"params": [
{
"name": "transaction_index",
"type": "u32"
},
{
"name": "at",
"type": "Hash",
"isOptional": true
}
],
"type": "ProofResponse"
},
"queryRows": {
"description": "Query rows based on their indices",
"params": [
{
"name": "rows",
"type": "Vec<u32>"
},
{
"name": "at",
"type": "Hash",
"isOptional": true
}
],
"type": "Vec<Vec<U256>>"
}
}
},
signedExtensions: {
"CheckAppId": {
"extrinsic": {
"appId": "AppId"
},
"payload": {}
}
}
};

export default { typesBundle: { spec: { "avail": definitions } } };
54 changes: 54 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,60 @@ services:
interval: 5s
timeout: 5s
retries: 5

subquery-node-avail:
image: onfinality/subql-node:v2.2.1
depends_on:
"postgres":
condition: service_healthy
restart: always
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: postgres
DB_PORT: 5432
volumes:
- ./:/app
command:
- -f=/app/project-avail.yaml
- --multi-chain
- --db-schema=app
- --disable-historical
- --query-limit=1000000
- --batch-size=10
healthcheck:
test: [ "CMD", "curl", "-f", "http://subquery-node-dock:3000/ready" ]
interval: 3s
timeout: 5s
retries: 10

subquery-node-vara:
image: onfinality/subql-node:v2.2.1
depends_on:
"postgres":
condition: service_healthy
restart: always
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: postgres
DB_PORT: 5432
volumes:
- ./:/app
command:
- -f=/app/project-vara.yaml
- --multi-chain
- --db-schema=app
- --disable-historical
- --query-limit=1000000
- --batch-size=10
healthcheck:
test: [ "CMD", "curl", "-f", "http://subquery-node-dock:3000/ready" ]
interval: 3s
timeout: 5s
retries: 10

subquery-node-dock:
image: onfinality/subql-node:v2.2.1
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"polkadexChaintypes": "./chainTypes/polkadexChaintypes.ts",
"ternoaChaintypes": "./chainTypes/ternoaChaintypes.ts",
"zeitgeistChaintypes": "./chainTypes/zeitgeistChaintypes.ts",
"calamariChainTypes": "./chainTypes/calamariChainTypes.ts"
"calamariChainTypes": "./chainTypes/calamariChainTypes.ts",
"availChainTypes": "./chainTypes/availChainTypes.ts"
},
"dependencies": {
"@moonbeam-network/api-augment": "^0.2301.0",
Expand Down
79 changes: 79 additions & 0 deletions project-avail.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
specVersion: 1.0.0
name: nova-wallet-staking
version: 0.0.1
runner:
node:
name: "@subql/node"
version: ">=1.0.0"
query:
name: "@subql/query"
version: "*"
description: >-
Project that provides up-to-date information about on-chain staking APY
repository: "git@github.com:nova-wallet/subquery-staking.git"
schema:
file: ./schema.graphql
network:
chainId: "0x128ea318539862c0a06b745981300d527c1041c6f3388a8c49565559e3ea3d10"
endpoint: "wss://zeref-api.slowops.xyz/ws"
chaintypes:
file: ./dist/availChainTypes.js
dataSources:
- kind: substrate/Runtime
startBlock: 1
mapping:
file: ./dist/index.js
handlers:
- handler: handleAvailNewEra
kind: substrate/EventHandler
filter:
module: staking
method: StakersElected

- handler: handleAvailNewSession
kind: substrate/EventHandler
filter:
module: session
method: NewSession

- handler: handleAvailStakingReward
kind: substrate/EventHandler
filter:
module: staking
method: Reward

- handler: handleAvailStakingReward
kind: substrate/EventHandler
filter:
module: staking
method: Rewarded

- handler: handleAvailPoolStakingReward
kind: substrate/EventHandler
filter:
module: nominationPools
method: PaidOut

- handler: handleAvailStakingSlash
kind: substrate/EventHandler
filter:
module: staking
method: Slash

- handler: handleAvailStakingSlash
kind: substrate/EventHandler
filter:
module: staking
method: Slashed

- handler: handleAvailPoolStakingBondedSlash
kind: substrate/EventHandler
filter:
module: nominationPools
method: PoolSlashed

- handler: handleAvailPoolStakingUnbondingSlash
kind: substrate/EventHandler
filter:
module: nominationPools
method: UnbondingPoolSlashed
Loading

0 comments on commit 458fe49

Please sign in to comment.