@@ -2,7 +2,13 @@ import { Program } from "@coral-xyz/anchor";
22import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet" ;
33import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider" ;
44import { 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" ;
612import {
713 PythCluster ,
814 getPythClusterApiUrl ,
@@ -33,9 +39,9 @@ import {
3339 MultisigParser ,
3440 MultisigVault ,
3541 PROGRAM_AUTHORITY_ESCROW ,
42+ findDetermisticStakeAccountAddress ,
3643 getMultisigCluster ,
3744 getProposalInstructions ,
38- findDetermisticStakeAccountAddress ,
3945} from "@pythnetwork/xc-admin-common" ;
4046
4147import {
@@ -500,6 +506,59 @@ multisigCommand(
500506 ) ;
501507 } ) ;
502508
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+
503562program
504563 . command ( "parse-transaction" )
505564 . description ( "Parse a transaction sitting in the multisig" )
0 commit comments