@@ -2,7 +2,13 @@ import { Program } from "@coral-xyz/anchor";
2
2
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet" ;
3
3
import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider" ;
4
4
import { TOKEN_PROGRAM_ID } from "@coral-xyz/anchor/dist/cjs/utils/token" ;
5
- import { pythOracleProgram } from "@pythnetwork/client" ;
5
+ import {
6
+ pythOracleProgram ,
7
+ PythHttpClient ,
8
+ parseBaseData ,
9
+ AccountType ,
10
+ parsePriceData ,
11
+ } from "@pythnetwork/client" ;
6
12
import {
7
13
PythCluster ,
8
14
getPythClusterApiUrl ,
@@ -33,9 +39,9 @@ import {
33
39
MultisigParser ,
34
40
MultisigVault ,
35
41
PROGRAM_AUTHORITY_ESCROW ,
42
+ findDetermisticStakeAccountAddress ,
36
43
getMultisigCluster ,
37
44
getProposalInstructions ,
38
- findDetermisticStakeAccountAddress ,
39
45
} from "@pythnetwork/xc-admin-common" ;
40
46
41
47
import {
@@ -500,6 +506,59 @@ multisigCommand(
500
506
) ;
501
507
} ) ;
502
508
509
+ multisigCommand (
510
+ "init-price-feed-index" ,
511
+ "Init price feed indexes to migrate old price feed accounts to the new index"
512
+ ) . action ( async ( options : any ) => {
513
+ const vault = await loadVaultFromOptions ( options ) ;
514
+
515
+ const cluster : PythCluster = options . cluster ;
516
+ const oracleProgramId = getPythProgramKeyForCluster ( cluster ) ;
517
+ const connection = new Connection ( getPythClusterApiUrl ( cluster ) ) ;
518
+
519
+ const allPythAccounts = await connection . getProgramAccounts ( oracleProgramId ) ;
520
+
521
+ const pricePubkeysToInitialize = [ ] ;
522
+
523
+ for ( const account of allPythAccounts ) {
524
+ const data = account . account . data ;
525
+ const pubkey = account . pubkey ;
526
+
527
+ const base = parseBaseData ( data ) ;
528
+ if ( base ?. type === AccountType . Price ) {
529
+ const parsed = parsePriceData ( data ) ;
530
+ if ( parsed . feedIndex === 0 ) {
531
+ pricePubkeysToInitialize . push ( pubkey ) ;
532
+ }
533
+ }
534
+ }
535
+
536
+ // Create instructions to initialize the price feed indexes
537
+ const oracleProgram = pythOracleProgram (
538
+ oracleProgramId ,
539
+ vault . getAnchorProvider ( )
540
+ ) ;
541
+
542
+ const instructions : TransactionInstruction [ ] = [ ] ;
543
+ for ( const pubkey of pricePubkeysToInitialize ) {
544
+ instructions . push (
545
+ await oracleProgram . methods
546
+ . initPriceFeedIndex ( )
547
+ . accounts ( {
548
+ fundingAccount : await vault . getVaultAuthorityPDA ( cluster ) ,
549
+ priceAccount : pubkey ,
550
+ } )
551
+ . instruction ( )
552
+ ) ;
553
+ }
554
+
555
+ await vault . proposeInstructions (
556
+ instructions ,
557
+ cluster ,
558
+ DEFAULT_PRIORITY_FEE_CONFIG
559
+ ) ;
560
+ } ) ;
561
+
503
562
program
504
563
. command ( "parse-transaction" )
505
564
. description ( "Parse a transaction sitting in the multisig" )
0 commit comments