mirror of
https://github.com/pezkuwichain/pezkuwi-subquery.git
synced 2026-04-22 04:17:59 +00:00
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.
This commit is contained in:
@@ -261,10 +261,52 @@ async function _computeAndSaveAPYInner(): Promise<void> {
|
|||||||
maxAPY,
|
maxAPY,
|
||||||
}).save();
|
}).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<string>();
|
||||||
|
const pages = await api.query.staking.erasStakersPaged.entries(currentEra);
|
||||||
|
for (const [, exp] of pages) {
|
||||||
|
let exposure: any;
|
||||||
|
try {
|
||||||
|
const asOpt = exp as Option<any>;
|
||||||
|
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(
|
logger.info(
|
||||||
`AH APY: ${(maxAPY * 100).toFixed(2)}% from ${
|
`AH APY: ${(maxAPY * 100).toFixed(2)}% from ${
|
||||||
validators.length
|
validators.length
|
||||||
} validators, era ${currentEra}, stakedPortion=${(
|
} validators, ${
|
||||||
|
activeNominators.size
|
||||||
|
} nominators, era ${currentEra}, stakedPortion=${(
|
||||||
stakedPortion * 100
|
stakedPortion * 100
|
||||||
).toFixed(2)}%`,
|
).toFixed(2)}%`,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user