Skip to content
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

adding VARA project #53

Merged
merged 1 commit into from
May 7, 2024
Merged
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
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,33 @@ services:
timeout: 5s
retries: 5

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
depends_on:
Expand Down
59 changes: 59 additions & 0 deletions project-vara.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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: "[email protected]:nova-wallet/subquery-staking.git"
schema:
file: ./schema.graphql
network:
chainId: "0xfe1b4c55fd4d668101126434206571a7838a8b6b93a6d1b95d607e78e6c53763"
endpoint: "wss://vara-mainnet.public.blastapi.io"
dataSources:
- kind: substrate/Runtime
startBlock: 4545915 # first staking.rewarded https://vara.subscan.io/extrinsic/4545915-1?event=4545915-4
mapping:
file: ./dist/index.js
handlers:
- handler: handleVaraNewEra
kind: substrate/EventHandler
filter:
module: staking
method: StakersElected

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

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

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

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

- handler: handleVaraStakingSlash
kind: substrate/EventHandler
filter:
module: staking
method: Slashed
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export * from "./mappings/zeitgeist";
export * from "./mappings/polkadex";
export * from "./mappings/ternoa";
export * from "./mappings/westend";
import "@polkadot/api-augment";
export * from "./mappings/vara";
import "@polkadot/api-augment";
46 changes: 46 additions & 0 deletions src/mappings/vara.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {SubstrateEvent} from "@subql/types";
import {handleNewEra, handleNewSession} from "./common";
import {RelaychainRewardCalculator} from "./rewards/Relaychain";
import {ValidatorEraInfoDataSource} from "./era/ValidatorEraInfoDataSource";
import {Codec} from "@polkadot/types/types";
import {INumber} from "@polkadot/types-codec/types/interfaces";
import {handleRelaychainStakingReward, handleRelaychainStakingSlash} from "./rewards/history/relaychain";

const VARA_GENESIS = "0xfe1b4c55fd4d668101126434206571a7838a8b6b93a6d1b95d607e78e6c53763"
const DIRECT_STAKING_TYPE = "relaychain"

export async function handleVaraNewEra(_: SubstrateEvent): Promise<void> {
let validatorEraInfoDataSource = new ValidatorEraInfoDataSource();

await handleNewEra(
validatorEraInfoDataSource,
await RelaychainRewardCalculator(validatorEraInfoDataSource),
VARA_GENESIS,
DIRECT_STAKING_TYPE
)
}

export async function handleVaraNewSession(_: SubstrateEvent): Promise<void> {
let validatorEraInfoDataSource = new ValidatorEraInfoDataSource();
let mainRewardCalculator = await RelaychainRewardCalculator(validatorEraInfoDataSource)

await handleNewSession(
validatorEraInfoDataSource,
await mainRewardCalculator,
VARA_GENESIS,
DIRECT_STAKING_TYPE
)
}


export async function handleVaraStakingReward(
event: SubstrateEvent<[accountId: Codec, reward: INumber]>,
): Promise<void> {
await handleRelaychainStakingReward(event, VARA_GENESIS, DIRECT_STAKING_TYPE)
}

export async function handleVaraStakingSlash(
event: SubstrateEvent<[account: Codec, slash: INumber]>,
): Promise<void> {
await handleRelaychainStakingSlash(event, VARA_GENESIS, DIRECT_STAKING_TYPE)
}
Loading