@@ -8,6 +8,47 @@ export type WorkerFunction = typeof getExposure
88
99export type ExposureRecord = Record < number , Record < string , boolean > >
1010
11+ // DEPRECATION: Paged Rewards
12+ //
13+ // Temporary until paged rewards migration has completed on all networks. Wait 84 eras from Polkadot
14+ // start: 1420 + 84 = 1504, when full history depth will be moved over to new paged rewards storage.
15+ const pagedRewardsActiveEras : Record < `0x${string } `, number > = {
16+ // Polkadot
17+ '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3' : 1420 ,
18+ // Kusama
19+ '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe' : 6514 ,
20+ // Westend
21+ '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e' : 7167 ,
22+ }
23+
24+ const getEraExposeds = async ( api : ApiPromise , era : number ) => {
25+ const pagedRewardsActiveEra = pagedRewardsActiveEras [ api . genesisHash . toHex ( ) ]
26+ if ( pagedRewardsActiveEra === undefined || pagedRewardsActiveEra < era ) {
27+ const stakers = await api . query . staking . erasStakers . entries ( era )
28+
29+ const exposeds = stakers
30+ . map ( staker => staker [ 1 ] )
31+ . flatMap ( staker => staker . others . map ( other => other . who . toString ( ) ) )
32+
33+ return new Set ( exposeds )
34+ }
35+
36+ const stakerKeys = await api . query . staking . erasStakersOverview . keys ( era )
37+ const stakers = await Promise . all (
38+ stakerKeys
39+ . map ( key => key . args [ 1 ] )
40+ . map ( async address => await api . query . staking . erasStakersPaged . entries ( era , address ) )
41+ )
42+
43+ const exposeds = stakers
44+ . flat ( )
45+ . map ( staker => staker [ 1 ] )
46+ . filter ( staker => staker . isSome )
47+ . flatMap ( staker => staker . unwrap ( ) . others . map ( other => other . who . toString ( ) ) )
48+
49+ return new Set ( exposeds )
50+ }
51+
1152const generateExposure = async function * (
1253 endpoint : string ,
1354 activeEra : number ,
@@ -26,9 +67,7 @@ const generateExposure = async function* (
2667 const addressesToCheck = encodedAddresses . filter ( address => ! ( address in eraExposure ) )
2768
2869 if ( addressesToCheck . length > 0 ) {
29- const exposeds = await api . query . staking . erasStakers
30- . entries ( era )
31- . then ( x => new Set ( x . flatMap ( ( [ _ , exposure ] ) => exposure . others . flatMap ( ( { who } ) => who . toString ( ) ) ) ) )
70+ const exposeds = await getEraExposeds ( api , era )
3271
3372 for ( const address of addressesToCheck ) {
3473 eraExposure [ address ] = exposeds . has ( address )
0 commit comments