Skip to content

Commit c967a84

Browse files
authored
feat(governance/xc_admin): support init pricefeed index (#1862)
* chore: update pythnetwork/client package * feat(governance/xc_admin): add init-price-feed-index cli command * fix: rebase and update lockfile
1 parent 144f87f commit c967a84

File tree

10 files changed

+98
-39
lines changed

10 files changed

+98
-39
lines changed

apps/api-reference/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@headlessui/react": "^2.0.4",
2828
"@heroicons/react": "^2.1.4",
2929
"@next/third-parties": "^14.2.4",
30-
"@pythnetwork/client": "^2.21.1",
30+
"@pythnetwork/client": "^2.22.0",
3131
"@pythnetwork/pyth-sdk-solidity": "workspace:^",
3232
"@solana/web3.js": "^1.95.1",
3333
"@tanstack/react-query": "^5.45.1",

contract_manager/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@cosmjs/stargate": "^0.32.3",
2828
"@injectivelabs/networks": "^1.14.6",
2929
"@mysten/sui": "^1.3.0",
30-
"@pythnetwork/client": "^2.21.1",
30+
"@pythnetwork/client": "^2.22.0",
3131
"@pythnetwork/contract-manager": "workspace:*",
3232
"@pythnetwork/cosmwasm-deploy-tools": "workspace:*",
3333
"@pythnetwork/entropy-sdk-solidity": "workspace:*",

governance/xc_admin/packages/crank_executor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@coral-xyz/anchor": "^0.29.0",
2525
"@injectivelabs/sdk-ts": "^1.10.72",
2626
"@project-serum/anchor": "^0.25.0",
27-
"@pythnetwork/client": "^2.21.1",
27+
"@pythnetwork/client": "^2.22.0",
2828
"@pythnetwork/xc-admin-common": "workspace:*",
2929
"@solana/web3.js": "^1.73.0",
3030
"@sqds/mesh": "^1.0.6",

governance/xc_admin/packages/crank_pythnet_relayer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@certusone/wormhole-sdk": "^0.10.15",
2424
"@coral-xyz/anchor": "^0.29.0",
2525
"@injectivelabs/sdk-ts": "^1.10.72",
26-
"@pythnetwork/client": "^2.21.1",
26+
"@pythnetwork/client": "^2.22.0",
2727
"@pythnetwork/xc-admin-common": "workspace:*",
2828
"@solana/web3.js": "^1.73.0",
2929
"@sqds/mesh": "^1.0.6",

governance/xc_admin/packages/proposer_server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"dependencies": {
2323
"@coral-xyz/anchor": "^0.29.0",
2424
"@injectivelabs/sdk-ts": "^1.10.72",
25-
"@pythnetwork/client": "^2.21.1",
25+
"@pythnetwork/client": "^2.22.0",
2626
"@pythnetwork/xc-admin-common": "workspace:*",
2727
"@solana/web3.js": "^1.76.0",
2828
"@sqds/mesh": "^1.0.6",

governance/xc_admin/packages/xc_admin_cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@coral-xyz/anchor": "^0.29.0",
2424
"@ledgerhq/hw-transport": "^6.27.10",
2525
"@ledgerhq/hw-transport-node-hid": "^6.27.10",
26-
"@pythnetwork/client": "^2.21.1",
26+
"@pythnetwork/client": "^2.22.0",
2727
"@pythnetwork/pyth-solana-receiver": "workspace:*",
2828
"@pythnetwork/solana-utils": "workspace:^",
2929
"@pythnetwork/xc-admin-common": "workspace:*",

governance/xc_admin/packages/xc_admin_cli/src/index.ts

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { Program } from "@coral-xyz/anchor";
22
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
33
import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
44
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";
612
import {
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

4147
import {
@@ -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+
503562
program
504563
.command("parse-transaction")
505564
.description("Parse a transaction sitting in the multisig")

governance/xc_admin/packages/xc_admin_common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@coral-xyz/anchor": "^0.29.0",
3030
"@injectivelabs/token-metadata": "~1.10.42",
3131
"@project-serum/anchor": "^0.25.0",
32-
"@pythnetwork/client": "^2.21.1",
32+
"@pythnetwork/client": "^2.22.0",
3333
"@pythnetwork/pyth-solana-receiver": "workspace:*",
3434
"@pythnetwork/solana-utils": "workspace:*",
3535
"@solana/buffer-layout": "^4.0.1",

governance/xc_admin/packages/xc_admin_frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@coral-xyz/anchor": "^0.29.0",
1313
"@headlessui/react": "^1.7.7",
14-
"@pythnetwork/client": "^2.21.1",
14+
"@pythnetwork/client": "^2.22.0",
1515
"@pythnetwork/solana-utils": "workspace:^",
1616
"@pythnetwork/xc-admin-common": "workspace:*",
1717
"@radix-ui/react-label": "^2.0.0",

0 commit comments

Comments
 (0)