From 6c5b7ae87997b2fc3bb3198b222ba9f4d0e4deef Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Sat, 21 Feb 2026 02:42:18 +0300 Subject: [PATCH] feat: save direct nominators and validators as activeStakers on AH Previously only pool stash accounts were saved as activeStakers. Direct nominators/validators on Asset Hub were missing, causing the wallet dashboard to show INACTIVE for direct stakers. --- src/mappings/PoolStakers.ts | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/mappings/PoolStakers.ts b/src/mappings/PoolStakers.ts index 0868f45..8c50c68 100644 --- a/src/mappings/PoolStakers.ts +++ b/src/mappings/PoolStakers.ts @@ -261,10 +261,52 @@ async function _computeAndSaveAPYInner(): Promise { maxAPY, }).save(); + // Save validators as active stakers on AH + for (const address of validatorAddresses) { + const stakerId = `${PEZKUWI_ASSET_HUB_GENESIS}-${STAKING_TYPE_RELAYCHAIN}-${address}`; + await ActiveStaker.create({ + id: stakerId, + networkId: PEZKUWI_ASSET_HUB_GENESIS, + stakingType: STAKING_TYPE_RELAYCHAIN, + address, + }).save(); + } + + // Save individual nominators as active stakers on AH + const activeNominators = new Set(); + const pages = await api.query.staking.erasStakersPaged.entries(currentEra); + for (const [, exp] of pages) { + let exposure: any; + try { + const asOpt = exp as Option; + if (asOpt.isNone) continue; + exposure = asOpt.unwrap(); + } catch { + exposure = exp as any; + } + if (exposure.others) { + for (const other of exposure.others) { + activeNominators.add(other.who.toString()); + } + } + } + + for (const address of activeNominators) { + const stakerId = `${PEZKUWI_ASSET_HUB_GENESIS}-${STAKING_TYPE_RELAYCHAIN}-${address}`; + await ActiveStaker.create({ + id: stakerId, + networkId: PEZKUWI_ASSET_HUB_GENESIS, + stakingType: STAKING_TYPE_RELAYCHAIN, + address, + }).save(); + } + logger.info( `AH APY: ${(maxAPY * 100).toFixed(2)}% from ${ validators.length - } validators, era ${currentEra}, stakedPortion=${( + } validators, ${ + activeNominators.size + } nominators, era ${currentEra}, stakedPortion=${( stakedPortion * 100 ).toFixed(2)}%`, );