@@ -34,10 +34,6 @@ interface AccountInfo {
3434 id : string ;
3535 amount : string ;
3636 } [ ] ;
37- freezes : {
38- id : string ;
39- amount : string ;
40- } [ ] ;
4137}
4238
4339interface OutputData {
@@ -79,129 +75,57 @@ async function main() {
7975 const delegatorAddresses : string [ ] = [ ] ;
8076 const candidateAddresses : string [ ] = [ ] ;
8177 const detailedInfo : AccountInfo [ ] = [ ] ;
82- const PAGE_SIZE = 50 ; // Balance between efficiency and RPC timeout risk
78+ const PAGE_SIZE = 300 ; // Balance between efficiency and RPC timeout risk
8379
8480 // Get all delegators from parachain staking with pagination
8581 console . log ( "Querying delegators with pagination..." ) ;
86- let delegatorCount = 0 ;
87- let lastDelegatorKey : any = null ;
82+ let processed = 0 ;
83+ let lastKey : any = null ;
8884
8985 for ( ; ; ) {
90- const delegatorBatch = await api . query . parachainStaking . delegatorState . entriesPaged ( {
86+ const locksBatch = await api . query . balances . locks . entriesPaged ( {
9187 args : [ ] ,
9288 pageSize : PAGE_SIZE ,
93- startKey : lastDelegatorKey ,
89+ startKey : lastKey ,
9490 } ) ;
9591
96- console . log (
97- ` Loaded ${ delegatorBatch . length } delegators (batch ${ Math . floor ( delegatorCount / PAGE_SIZE ) + 1 } )...` ,
98- ) ;
92+ console . log ( ` Loaded ${ locksBatch . length } locks (batch ${ processed / PAGE_SIZE + 1 } )...` ) ;
9993
100- for ( const [ key , value ] of delegatorBatch ) {
94+ for ( const [ key , value ] of locksBatch ) {
10195 if ( value . isEmpty ) continue ;
10296
10397 // Extract account ID from storage key using args
10498 const accountId = key . args [ 0 ] ;
10599 const accountIdStr = accountId . toString ( ) ;
106100
107- // Check if this delegator has been migrated
108- const isMigrated = await api . query . parachainStaking . migratedDelegators ( accountId ) ;
109-
110- if ( ! isMigrated . toHuman ( ) ) {
111- // Not migrated yet, get lock and freeze info
112- const locks = await api . query . balances . locks ( accountId ) ;
113- const freezes = await api . query . balances . freezes ( accountId ) ;
114-
115- const lockData = locks . toJSON ( ) as any [ ] ;
116- const freezeData = freezes . toJSON ( ) as any [ ] ;
117-
118- const stakingLocks = lockData . filter (
119- ( lock : any ) => lock . id === "stkngdel" || lock . id === "0x73746b6e6764656c" ,
120- ) ;
121-
122- if ( stakingLocks . length > 0 ) {
123- delegatorAddresses . push ( accountIdStr ) ;
124- detailedInfo . push ( {
125- address : accountIdStr ,
126- locks : stakingLocks ,
127- freezes : freezeData ,
128- } ) ;
129- }
130- }
131-
132- delegatorCount ++ ;
133- lastDelegatorKey = key ;
134- }
101+ const lockData = value . toJSON ( ) as any [ ] ;
135102
136- // Save progress after each batch
137- const outputData : OutputData = {
138- delegators : delegatorAddresses ,
139- candidates : candidateAddresses ,
140- } ;
141- fs . writeFileSync ( OUTPUT_FILE , JSON . stringify ( outputData , null , 2 ) ) ;
142- fs . writeFileSync ( DETAILED_OUTPUT_FILE , JSON . stringify ( detailedInfo , null , 2 ) ) ;
143- console . log (
144- ` Progress saved: ${ delegatorAddresses . length } delegators, ${ candidateAddresses . length } candidates` ,
145- ) ;
103+ const stkngdelLocks = lockData . filter (
104+ ( lock : any ) => lock . id === "0x73746b6e6764656c" , // stkngdel
105+ ) ;
146106
147- if ( delegatorBatch . length < PAGE_SIZE ) {
148- console . log ( `\nTotal delegators processed: ${ delegatorCount } ` ) ;
149- break ;
150- }
151- }
152-
153- console . log ( `Delegators needing migration: ${ delegatorAddresses . length } \n` ) ;
154-
155- // Get all collator candidates with pagination
156- console . log ( "Querying candidates with pagination..." ) ;
157- let candidateCount = 0 ;
158- let lastCandidateKey : any = null ;
159-
160- for ( ; ; ) {
161- const candidateBatch = await api . query . parachainStaking . candidateInfo . entriesPaged ( {
162- args : [ ] ,
163- pageSize : PAGE_SIZE ,
164- startKey : lastCandidateKey ,
165- } ) ;
166-
167- console . log (
168- ` Loaded ${ candidateBatch . length } candidates (batch ${ Math . floor ( candidateCount / PAGE_SIZE ) + 1 } )...` ,
169- ) ;
107+ if ( stkngdelLocks . length > 0 ) {
108+ delegatorAddresses . push ( accountIdStr ) ;
109+ detailedInfo . push ( {
110+ address : accountIdStr ,
111+ locks : stkngdelLocks ,
112+ } ) ;
113+ }
170114
171- for ( const [ key , value ] of candidateBatch ) {
172- if ( value . isEmpty ) continue ;
115+ const stkngcolLocks = lockData . filter (
116+ ( lock : any ) => lock . id === "0x73746b6e67636f6c" , // stkngcol
117+ ) ;
173118
174- // Extract account ID from storage key using args
175- const accountId = key . args [ 0 ] ;
176- const accountIdStr = accountId . toString ( ) ;
177-
178- // Check if this candidate has been migrated
179- const isMigrated = await api . query . parachainStaking . migratedCandidates ( accountId ) ;
180-
181- if ( ! isMigrated . toHuman ( ) ) {
182- // Not migrated yet, get lock and freeze info
183- const locks = await api . query . balances . locks ( accountId ) ;
184- const freezes = await api . query . balances . freezes ( accountId ) ;
185-
186- const lockData = locks . toJSON ( ) as any [ ] ;
187- const freezeData = freezes . toJSON ( ) as any [ ] ;
188-
189- const stakingLocks = lockData . filter (
190- ( lock : any ) => lock . id === "stkngcol" || lock . id === "0x73746b6e67636f6c" ,
191- ) ;
192-
193- if ( stakingLocks . length > 0 ) {
194- candidateAddresses . push ( accountIdStr ) ;
195- detailedInfo . push ( {
196- address : accountIdStr ,
197- locks : stakingLocks ,
198- freezes : freezeData ,
199- } ) ;
200- }
119+ if ( stkngcolLocks . length > 0 ) {
120+ candidateAddresses . push ( accountIdStr ) ;
121+ detailedInfo . push ( {
122+ address : accountIdStr ,
123+ locks : stkngcolLocks ,
124+ } ) ;
201125 }
202126
203- candidateCount ++ ;
204- lastCandidateKey = key ;
127+ processed ++ ;
128+ lastKey = key ;
205129 }
206130
207131 // Save progress after each batch
@@ -215,12 +139,13 @@ async function main() {
215139 ` Progress saved: ${ delegatorAddresses . length } delegators, ${ candidateAddresses . length } candidates` ,
216140 ) ;
217141
218- if ( candidateBatch . length < PAGE_SIZE ) {
219- console . log ( `\nTotal candidates processed: ${ candidateCount } ` ) ;
142+ if ( locksBatch . length < PAGE_SIZE ) {
143+ console . log ( `\nTotal locks processed: ${ processed } ` ) ;
220144 break ;
221145 }
222146 }
223147
148+ console . log ( `Delegators needing migration: ${ delegatorAddresses . length } \n` ) ;
224149 console . log ( `Candidates needing migration: ${ candidateAddresses . length } \n` ) ;
225150
226151 const totalAccounts = delegatorAddresses . length + candidateAddresses . length ;
@@ -242,8 +167,7 @@ async function main() {
242167 console . log ( "\n" + "=" . repeat ( 50 ) ) ;
243168 console . log ( "Summary:" ) ;
244169 console . log ( "=" . repeat ( 50 ) ) ;
245- console . log ( `Total delegators checked: ${ delegatorCount } ` ) ;
246- console . log ( `Total candidates checked: ${ candidateCount } ` ) ;
170+ console . log ( `Total locks checked: ${ processed } ` ) ;
247171 console . log ( `Accounts needing migration: ${ totalAccounts } ` ) ;
248172 console . log ( ` - Delegators: ${ delegatorAddresses . length } ` ) ;
249173 console . log ( ` - Candidates: ${ candidateAddresses . length } ` ) ;
0 commit comments