@@ -265,50 +265,47 @@ export class PythCoreAdapter implements ProgramAdapter {
265
265
*/
266
266
private sortData ( data : any ) {
267
267
const sortedData : any = { } ;
268
- Object . keys ( data )
269
- . sort ( )
270
- . forEach ( ( key ) => {
271
- const sortedInnerData : any = { } ;
272
- Object . keys ( data [ key ] )
273
- . sort ( )
274
- . forEach ( ( innerKey ) => {
275
- if ( innerKey === "metadata" ) {
276
- sortedInnerData [ innerKey ] = this . sortObjectByKeys (
277
- data [ key ] [ innerKey ] ,
278
- ) ;
279
- } else if ( innerKey === "priceAccounts" ) {
280
- // Sort price accounts by address
281
- sortedInnerData [ innerKey ] = data [ key ] [ innerKey ] . sort (
282
- ( priceAccount1 : any , priceAccount2 : any ) =>
283
- priceAccount1 . address . localeCompare ( priceAccount2 . address ) ,
284
- ) ;
285
- // Sort price accounts keys
286
- sortedInnerData [ innerKey ] = sortedInnerData [ innerKey ] . map (
287
- ( priceAccount : any ) => {
288
- const sortedPriceAccount : any = { } ;
289
- Object . keys ( priceAccount )
290
- . sort ( )
291
- . forEach ( ( priceAccountKey ) => {
292
- if ( priceAccountKey === "publishers" ) {
293
- sortedPriceAccount [ priceAccountKey ] = priceAccount [
294
- priceAccountKey
295
- ] . sort ( ( pub1 : string , pub2 : string ) =>
296
- pub1 . localeCompare ( pub2 ) ,
297
- ) ;
298
- } else {
299
- sortedPriceAccount [ priceAccountKey ] =
300
- priceAccount [ priceAccountKey ] ;
301
- }
302
- } ) ;
303
- return sortedPriceAccount ;
304
- } ,
305
- ) ;
306
- } else {
307
- sortedInnerData [ innerKey ] = data [ key ] [ innerKey ] ;
308
- }
309
- } ) ;
310
- sortedData [ key ] = sortedInnerData ;
311
- } ) ;
268
+ const keys = Object . keys ( data ) . sort ( ) ;
269
+ for ( const key of keys ) {
270
+ const sortedInnerData : any = { } ;
271
+ const innerKeys = Object . keys ( data [ key ] ) . sort ( ) ;
272
+ for ( const innerKey of innerKeys ) {
273
+ if ( innerKey === "metadata" ) {
274
+ sortedInnerData [ innerKey ] = this . sortObjectByKeys (
275
+ data [ key ] [ innerKey ] ,
276
+ ) ;
277
+ } else if ( innerKey === "priceAccounts" ) {
278
+ // Sort price accounts by address
279
+ sortedInnerData [ innerKey ] = data [ key ] [ innerKey ] . sort (
280
+ ( priceAccount1 : any , priceAccount2 : any ) =>
281
+ priceAccount1 . address . localeCompare ( priceAccount2 . address ) ,
282
+ ) ;
283
+ // Sort price accounts keys
284
+ sortedInnerData [ innerKey ] = sortedInnerData [ innerKey ] . map (
285
+ ( priceAccount : any ) => {
286
+ const sortedPriceAccount : any = { } ;
287
+ const priceAccountKeys = Object . keys ( priceAccount ) . sort ( ) ;
288
+ for ( const priceAccountKey of priceAccountKeys ) {
289
+ if ( priceAccountKey === "publishers" ) {
290
+ sortedPriceAccount [ priceAccountKey ] = priceAccount [
291
+ priceAccountKey
292
+ ] . sort ( ( pub1 : string , pub2 : string ) =>
293
+ pub1 . localeCompare ( pub2 ) ,
294
+ ) ;
295
+ } else {
296
+ sortedPriceAccount [ priceAccountKey ] =
297
+ priceAccount [ priceAccountKey ] ;
298
+ }
299
+ }
300
+ return sortedPriceAccount ;
301
+ } ,
302
+ ) ;
303
+ } else {
304
+ sortedInnerData [ innerKey ] = data [ key ] [ innerKey ] ;
305
+ }
306
+ }
307
+ sortedData [ key ] = sortedInnerData ;
308
+ }
312
309
return sortedData ;
313
310
}
314
311
@@ -317,11 +314,10 @@ export class PythCoreAdapter implements ProgramAdapter {
317
314
*/
318
315
private sortObjectByKeys ( obj : any ) {
319
316
const sortedObj : any = { } ;
320
- Object . keys ( obj )
321
- . sort ( )
322
- . forEach ( ( key ) => {
323
- sortedObj [ key ] = obj [ key ] ;
324
- } ) ;
317
+ const keys = Object . keys ( obj ) . sort ( ) ;
318
+ for ( const key of keys ) {
319
+ sortedObj [ key ] = obj [ key ] ;
320
+ }
325
321
return sortedObj ;
326
322
}
327
323
@@ -347,7 +343,7 @@ export class PythCoreAdapter implements ProgramAdapter {
347
343
const changes : Record < string , any > = { } ;
348
344
349
345
// Check for changes to existing symbols
350
- Object . keys ( uploadedConfig ) . forEach ( ( symbol ) => {
346
+ for ( const symbol of Object . keys ( uploadedConfig ) ) {
351
347
// Remove duplicate publishers
352
348
if (
353
349
uploadedConfig [ symbol ] ?. priceAccounts ?. [ 0 ] ?. publishers &&
@@ -380,18 +376,18 @@ export class PythCoreAdapter implements ProgramAdapter {
380
376
changes [ symbol ] . prev = { ...existingConfig [ symbol ] } ;
381
377
changes [ symbol ] . new = { ...uploadedConfig [ symbol ] } ;
382
378
}
383
- } ) ;
379
+ }
384
380
385
381
// Check for symbols to remove (in existing but not in uploaded)
386
- Object . keys ( existingConfig ) . forEach ( ( symbol ) => {
382
+ for ( const symbol of Object . keys ( existingConfig ) ) {
387
383
if ( ! uploadedConfig [ symbol ] ) {
388
384
changes [ symbol ] = { prev : { } } ;
389
385
changes [ symbol ] . prev = { ...existingConfig [ symbol ] } ;
390
386
}
391
- } ) ;
387
+ }
392
388
393
389
// Validate that address field is not changed for existing symbols
394
- Object . keys ( uploadedConfig ) . forEach ( ( symbol ) => {
390
+ for ( const symbol of Object . keys ( uploadedConfig ) ) {
395
391
if (
396
392
existingSymbols . has ( symbol ) &&
397
393
uploadedConfig [ symbol ] . address &&
@@ -402,10 +398,10 @@ export class PythCoreAdapter implements ProgramAdapter {
402
398
error : `Address field for product cannot be changed for symbol ${ symbol } . Please revert any changes to the address field and try again.` ,
403
399
} ;
404
400
}
405
- } ) ;
401
+ }
406
402
407
403
// Validate that priceAccounts address field is not changed
408
- Object . keys ( uploadedConfig ) . forEach ( ( symbol ) => {
404
+ for ( const symbol of Object . keys ( uploadedConfig ) ) {
409
405
if (
410
406
existingSymbols . has ( symbol ) &&
411
407
uploadedConfig [ symbol ] . priceAccounts ?. [ 0 ] &&
@@ -419,10 +415,10 @@ export class PythCoreAdapter implements ProgramAdapter {
419
415
error : `Address field for priceAccounts cannot be changed for symbol ${ symbol } . Please revert any changes to the address field and try again.` ,
420
416
} ;
421
417
}
422
- } ) ;
418
+ }
423
419
424
420
// Check that no price account has more than the maximum number of publishers
425
- Object . keys ( uploadedConfig ) . forEach ( ( symbol ) => {
421
+ for ( const symbol of Object . keys ( uploadedConfig ) ) {
426
422
const maximumNumberOfPublishers = getMaximumNumberOfPublishers ( cluster ) ;
427
423
if (
428
424
uploadedConfig [ symbol ] . priceAccounts ?. [ 0 ] ?. publishers &&
@@ -434,7 +430,7 @@ export class PythCoreAdapter implements ProgramAdapter {
434
430
error : `${ symbol } has more than ${ maximumNumberOfPublishers } publishers.` ,
435
431
} ;
436
432
}
437
- } ) ;
433
+ }
438
434
439
435
return {
440
436
isValid : true ,
0 commit comments