diff --git a/chainTypes/dockChaintypes.ts b/chainTypes/dockChaintypes.ts new file mode 100644 index 0000000..85ddb3f --- /dev/null +++ b/chainTypes/dockChaintypes.ts @@ -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 } }; \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 370b07f..0dd690d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/ipfs-cids/.project-multichain-cid b/ipfs-cids/.project-multichain-cid index a8a7ec1..29a2021 100644 --- a/ipfs-cids/.project-multichain-cid +++ b/ipfs-cids/.project-multichain-cid @@ -1 +1 @@ -QmbSqCFQBgQ7QUBVhT8yvf2bmkN1i7p9CF483JsPKdGZd2 \ No newline at end of file +QmXvwb3q4DKeVCosjVqgYxErDjX1zYM6pzsAUCndhNhED2 \ No newline at end of file diff --git a/package.json b/package.json index a3b2618..ed9a7b5 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/project-dock.yaml b/project-dock.yaml new file mode 100644 index 0000000..544c642 --- /dev/null +++ b/project-dock.yaml @@ -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: "git@github.com: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 \ No newline at end of file diff --git a/project-joystream.yaml b/project-joystream.yaml new file mode 100644 index 0000000..dbfeef8 --- /dev/null +++ b/project-joystream.yaml @@ -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: "git@github.com: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 \ No newline at end of file diff --git a/project-manta.yaml b/project-manta.yaml index 3c383d0..e9c238b 100644 --- a/project-manta.yaml +++ b/project-manta.yaml @@ -18,7 +18,7 @@ network: endpoint: "wss://ws.manta.systems" dataSources: - kind: substrate/Runtime - startBlock: 2192400 + startBlock: 1 mapping: file: ./dist/index.js handlers: diff --git a/src/index.ts b/src/index.ts index bb0b047..8009c54 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"; diff --git a/src/mappings/dock.ts b/src/mappings/dock.ts new file mode 100644 index 0000000..4d1b390 --- /dev/null +++ b/src/mappings/dock.ts @@ -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 { + let validatorEraInfoDataSource = new ValidatorEraInfoDataSource(); + + await handleNewEra( + validatorEraInfoDataSource, + await RelaychainRewardCalculator(validatorEraInfoDataSource), + DOCK_GENESIS, + DIRECT_STAKING_TYPE + ) +} + +export async function handleDockNewSession(_: SubstrateEvent): Promise { + 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 { + await handleRelaychainStakingReward(event, DOCK_GENESIS, DIRECT_STAKING_TYPE) +} + +export async function handleDockStakingSlash( + event: SubstrateEvent<[account: Codec, slash: INumber]>, +): Promise { + await handleRelaychainStakingSlash(event, DOCK_GENESIS, DIRECT_STAKING_TYPE) +} \ No newline at end of file diff --git a/src/mappings/joystream.ts b/src/mappings/joystream.ts new file mode 100644 index 0000000..4a9d8f2 --- /dev/null +++ b/src/mappings/joystream.ts @@ -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 { + const config = await createRewardCurveConfig({ + maxInflation : 0.03, + minInflation : 0.007, + }) + + return CustomRelaychainRewardCalculator(eraInfoDataSource, config) +} + +export async function handleJoystreamNewEra(_: SubstrateEvent): Promise { + let validatorEraInfoDataSource = new ValidatorEraInfoDataSource(); + + await handleNewEra( + validatorEraInfoDataSource, + await JoystreamRewardCalculator(validatorEraInfoDataSource), + JOYSTREAM_GENESIS, + DIRECT_STAKING_TYPE + ) +} + +export async function handleJoystreamNewSession(_: SubstrateEvent): Promise { + 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 { + await handleRelaychainStakingReward(event, JOYSTREAM_GENESIS, DIRECT_STAKING_TYPE) +} + +export async function handleJoystreamStakingSlash( + event: SubstrateEvent<[account: Codec, slash: INumber]>, +): Promise { + await handleRelaychainStakingSlash(event, JOYSTREAM_GENESIS, DIRECT_STAKING_TYPE) +} \ No newline at end of file diff --git a/subquery-multichain.yaml b/subquery-multichain.yaml index 0d392c3..322c73f 100644 --- a/subquery-multichain.yaml +++ b/subquery-multichain.yaml @@ -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