mirror of
https://github.com/pezkuwichain/pezkuwi-subquery.git
synced 2026-04-21 23:37:56 +00:00
Remove relay staking handlers after pallet removal (spec 1_020_006)
Staking pallet (index 9), FastUnstake (15), and VoterBagsList (100) were removed from the relay chain. The relay indexer now only tracks transfers and signed extrinsics. Added safety try-catch to staking queries in case handlers are accidentally re-enabled.
This commit is contained in:
+1
-58
@@ -8,7 +8,7 @@ runner:
|
||||
query:
|
||||
name: "@subql/query"
|
||||
version: "*"
|
||||
description: Pezkuwi Staking SubQuery - Indexes staking rewards, slashes, era data for PezWallet
|
||||
description: Pezkuwi Relay SubQuery - Indexes transfer history and governance-related data
|
||||
repository: https://github.com/pezkuwichain/pezkuwi-subquery
|
||||
schema:
|
||||
file: ./schema.graphql
|
||||
@@ -26,71 +26,14 @@ dataSources:
|
||||
mapping:
|
||||
file: ./dist/index.js
|
||||
handlers:
|
||||
# Block handler: initialize active relay stakers from chain state
|
||||
- handler: handleRelayBlock
|
||||
kind: substrate/BlockHandler
|
||||
# Signed extrinsics for history
|
||||
- handler: handleHistoryElement
|
||||
kind: substrate/CallHandler
|
||||
filter:
|
||||
isSigned: true
|
||||
# Staking rewards (old format)
|
||||
- handler: handleReward
|
||||
kind: substrate/EventHandler
|
||||
filter:
|
||||
module: staking
|
||||
method: Reward
|
||||
# Staking rewards (new format - Polkadot 2.0)
|
||||
- handler: handleRewarded
|
||||
kind: substrate/EventHandler
|
||||
filter:
|
||||
module: staking
|
||||
method: Rewarded
|
||||
# Nomination Pools rewards
|
||||
- handler: handlePoolReward
|
||||
kind: substrate/EventHandler
|
||||
filter:
|
||||
module: nominationPools
|
||||
method: PaidOut
|
||||
# Slashing (old format)
|
||||
- handler: handleSlash
|
||||
kind: substrate/EventHandler
|
||||
filter:
|
||||
module: staking
|
||||
method: Slash
|
||||
# Slashing (new format)
|
||||
- handler: handleSlashed
|
||||
kind: substrate/EventHandler
|
||||
filter:
|
||||
module: staking
|
||||
method: Slashed
|
||||
# Pool bonded slash
|
||||
- handler: handlePoolBondedSlash
|
||||
kind: substrate/EventHandler
|
||||
filter:
|
||||
module: nominationPools
|
||||
method: PoolSlashed
|
||||
# Pool unbonding slash
|
||||
- handler: handlePoolUnbondingSlash
|
||||
kind: substrate/EventHandler
|
||||
filter:
|
||||
module: nominationPools
|
||||
method: UnbondingPoolSlashed
|
||||
# Transfers
|
||||
- handler: handleTransfer
|
||||
kind: substrate/EventHandler
|
||||
filter:
|
||||
module: balances
|
||||
method: Transfer
|
||||
# Era changes (old format)
|
||||
- handler: handleNewEra
|
||||
kind: substrate/EventHandler
|
||||
filter:
|
||||
module: staking
|
||||
method: StakingElection
|
||||
# Era changes (new format - Polkadot 2.0)
|
||||
- handler: handleStakersElected
|
||||
kind: substrate/EventHandler
|
||||
filter:
|
||||
module: staking
|
||||
method: StakersElected
|
||||
|
||||
+28
-4
@@ -30,7 +30,19 @@ export async function handleRelayBlock(block: SubstrateBlock): Promise<void> {
|
||||
|
||||
logger.info("Initializing active relay stakers from live chain state...");
|
||||
|
||||
const activeEraOpt = (await api.query.staking.activeEra()) as Option<any>;
|
||||
// Safety: staking pallet was removed from relay chain in spec 1_020_006
|
||||
if (!api.query.staking || !api.query.staking.activeEra) {
|
||||
logger.info("Staking pallet not available on relay chain - skipping relay staker init");
|
||||
return;
|
||||
}
|
||||
|
||||
let activeEraOpt: Option<any>;
|
||||
try {
|
||||
activeEraOpt = (await api.query.staking.activeEra()) as Option<any>;
|
||||
} catch (e) {
|
||||
logger.warn(`Failed to query staking.activeEra on relay: ${e}`);
|
||||
return;
|
||||
}
|
||||
if (activeEraOpt.isNone) {
|
||||
logger.info("No active era found on relay chain");
|
||||
return;
|
||||
@@ -121,9 +133,21 @@ export async function handleStakersElected(
|
||||
}
|
||||
|
||||
export async function handleNewEra(event: SubstrateEvent): Promise<void> {
|
||||
const currentEra = ((await api.query.staking.currentEra()) as Option<any>)
|
||||
.unwrap()
|
||||
.toNumber();
|
||||
// Safety: staking pallet was removed from relay chain in spec 1_020_006
|
||||
if (!api.query.staking || !api.query.staking.currentEra) {
|
||||
logger.warn("Staking pallet not available - skipping handleNewEra");
|
||||
return;
|
||||
}
|
||||
|
||||
let currentEra: number;
|
||||
try {
|
||||
currentEra = ((await api.query.staking.currentEra()) as Option<any>)
|
||||
.unwrap()
|
||||
.toNumber();
|
||||
} catch (e) {
|
||||
logger.warn(`Failed to query staking.currentEra: ${e}`);
|
||||
return;
|
||||
}
|
||||
|
||||
let validatorExposures: Array<{
|
||||
address: string;
|
||||
|
||||
@@ -170,6 +170,20 @@ function calculateYearlyInflation(stakedPortion: number): number {
|
||||
}
|
||||
|
||||
async function computeAndSaveAPY(): Promise<void> {
|
||||
// Safety: check staking pallet availability before querying
|
||||
if (!api.query.staking || !api.query.staking.activeEra) {
|
||||
logger.warn("Staking pallet not available on this chain - skipping APY computation");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await _computeAndSaveAPYInner();
|
||||
} catch (e) {
|
||||
logger.warn(`APY computation failed: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function _computeAndSaveAPYInner(): Promise<void> {
|
||||
// Use AH's own totalIssuance. AH staking pallet mints inflation from AH supply.
|
||||
const TOTAL_SUPPLY = (
|
||||
(await api.query.balances.totalIssuance()) as any
|
||||
|
||||
Reference in New Issue
Block a user