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

Add Dock and Joystream #45

Merged
merged 1 commit into from
Mar 25, 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
5 changes: 5 additions & 0 deletions chainTypes/dockChaintypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Adapted from https://github.com/polkadot-js/apps/blob/master/packages/apps-config/src/api/spec/dock-mainnet.ts

import { spec } from '@docknetwork/node-types';

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

subquery-node-dock:
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-dock.yaml
- --multi-chain
- --db-schema=app
- --disable-historical
- --query-limit=1000000
- --batch-size=30
healthcheck:
test: [ "CMD", "curl", "-f", "http://subquery-node-dock:3000/ready" ]
interval: 3s
timeout: 5s
retries: 10

subquery-node-joystream:
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-joystream.yaml
- --multi-chain
- --db-schema=app
- --disable-historical
- --query-limit=1000000
- --batch-size=30
healthcheck:
test: [ "CMD", "curl", "-f", "http://subquery-node-joystream:3000/ready" ]
interval: 3s
timeout: 5s
retries: 10

subquery-node-polimec:
image: onfinality/subql-node:v2.2.1
depends_on:
Expand Down
2 changes: 1 addition & 1 deletion ipfs-cids/.project-multichain-cid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
QmbSqCFQBgQ7QUBVhT8yvf2bmkN1i7p9CF483JsPKdGZd2
QmXvwb3q4DKeVCosjVqgYxErDjX1zYM6pzsAUCndhNhED2
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"author": "Nova Wallet Team",
"license": "MIT",
"devDependencies": {
"@docknetwork/node-types": "0.17.0",
"@jest/globals": "^29.3.1",
"@polkadot/api": "^9",
"@subql/cli": "3.6.1",
Expand All @@ -36,6 +37,7 @@
"typescript": "^4.1.3"
},
"exports": {
"dockChaintypes": "./chainTypes/dockChaintypes.ts",
"alephZeroChaintypes": "./chainTypes/alephZeroChaintypes.ts",
"moonbeamChaintypes": "./chainTypes/moonbeamChaintypes.ts",
"polkadexChaintypes": "./chainTypes/polkadexChaintypes.ts",
Expand Down
61 changes: 61 additions & 0 deletions project-dock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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: "0x6bfe24dca2a3be10f22212678ac13a6446ec764103c0f3471c71609eac384aae"
endpoint: "wss://mainnet-node.dock.io"
chaintypes:
file: ./dist/dockChaintypes.js
dataSources:
- kind: substrate/Runtime
startBlock: 1
mapping:
file: ./dist/index.js
handlers:
- handler: handleDockNewEra
kind: substrate/EventHandler
filter:
module: staking
method: StakersElected

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

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

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

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

- handler: handleDockStakingSlash
kind: substrate/EventHandler
filter:
module: staking
method: Slashed
59 changes: 59 additions & 0 deletions project-joystream.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: "0x6b5e488e0fa8f9821110d5c13f4c468abcd43ce5e297e62b34c53c3346465956"
endpoint: "wss://rpc.joystream.org"
dataSources:
- kind: substrate/Runtime
startBlock: 1
mapping:
file: ./dist/index.js
handlers:
- handler: handleJoystreamNewEra
kind: substrate/EventHandler
filter:
module: staking
method: StakersElected

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

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

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

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

- handler: handleJoystreamStakingSlash
kind: substrate/EventHandler
filter:
module: staking
method: Slashed
2 changes: 1 addition & 1 deletion project-manta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ network:
endpoint: "wss://ws.manta.systems"
dataSources:
- kind: substrate/Runtime
startBlock: 2192400
startBlock: 1
mapping:
file: ./dist/index.js
handlers:
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//Exports all handler functions
export * from "./mappings/dock";
export * from "./mappings/joystream";
export * from "./mappings/polimec";
export * from "./mappings/polkadot";
export * from "./mappings/kusama";
Expand Down
46 changes: 46 additions & 0 deletions src/mappings/dock.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 DOCK_GENESIS = "0x6bfe24dca2a3be10f22212678ac13a6446ec764103c0f3471c71609eac384aae"
const DIRECT_STAKING_TYPE = "relaychain"

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

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

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

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


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

export async function handleDockStakingSlash(
event: SubstrateEvent<[account: Codec, slash: INumber]>,
): Promise<void> {
await handleRelaychainStakingSlash(event, DOCK_GENESIS, DIRECT_STAKING_TYPE)
}
57 changes: 57 additions & 0 deletions src/mappings/joystream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {SubstrateEvent} from "@subql/types";
import {handleNewEra, handleNewSession} from "./common";
import {createRewardCurveConfig, CustomRelaychainRewardCalculator} from "./rewards/Relaychain";
import {ValidatorStakingRewardCalculator} from "./rewards/ValidatorStakingRewardCalculator";
import {ValidatorEraInfoDataSource} from "./era/ValidatorEraInfoDataSource";
import {EraInfoDataSource} from "./era/EraInfoDataSource";
import {Codec} from "@polkadot/types/types";
import {INumber} from "@polkadot/types-codec/types/interfaces";
import {handleRelaychainStakingReward, handleRelaychainStakingSlash} from "./rewards/history/relaychain";

const JOYSTREAM_GENESIS = "0x6b5e488e0fa8f9821110d5c13f4c468abcd43ce5e297e62b34c53c3346465956"
const DIRECT_STAKING_TYPE = "relaychain"

export async function JoystreamRewardCalculator(eraInfoDataSource: EraInfoDataSource): Promise<ValidatorStakingRewardCalculator> {
const config = await createRewardCurveConfig({
maxInflation : 0.03,
minInflation : 0.007,
})

return CustomRelaychainRewardCalculator(eraInfoDataSource, config)
}

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

await handleNewEra(
validatorEraInfoDataSource,
await JoystreamRewardCalculator(validatorEraInfoDataSource),
JOYSTREAM_GENESIS,
DIRECT_STAKING_TYPE
)
}

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

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


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

export async function handleJoystreamStakingSlash(
event: SubstrateEvent<[account: Codec, slash: INumber]>,
): Promise<void> {
await handleRelaychainStakingSlash(event, JOYSTREAM_GENESIS, DIRECT_STAKING_TYPE)
}
2 changes: 2 additions & 0 deletions subquery-multichain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ query:
projects:
- project-aleph-zero.yaml
- project-calamari.yaml
- project-dock.yaml
- project-joystream.yaml
- project-kusama.yaml
- project-manta.yaml
- project-moonbeam.yaml
Expand Down
Loading