Skip to content

Commit

Permalink
feat(governance/xc_admin): support init pricefeed index (#1862)
Browse files Browse the repository at this point in the history
* chore: update pythnetwork/client package

* feat(governance/xc_admin): add init-price-feed-index cli command

* fix: rebase and update lockfile
  • Loading branch information
ali-bahjati authored Sep 3, 2024
1 parent 144f87f commit c967a84
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 39 deletions.
2 changes: 1 addition & 1 deletion apps/api-reference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@headlessui/react": "^2.0.4",
"@heroicons/react": "^2.1.4",
"@next/third-parties": "^14.2.4",
"@pythnetwork/client": "^2.21.1",
"@pythnetwork/client": "^2.22.0",
"@pythnetwork/pyth-sdk-solidity": "workspace:^",
"@solana/web3.js": "^1.95.1",
"@tanstack/react-query": "^5.45.1",
Expand Down
2 changes: 1 addition & 1 deletion contract_manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@cosmjs/stargate": "^0.32.3",
"@injectivelabs/networks": "^1.14.6",
"@mysten/sui": "^1.3.0",
"@pythnetwork/client": "^2.21.1",
"@pythnetwork/client": "^2.22.0",
"@pythnetwork/contract-manager": "workspace:*",
"@pythnetwork/cosmwasm-deploy-tools": "workspace:*",
"@pythnetwork/entropy-sdk-solidity": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion governance/xc_admin/packages/crank_executor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@coral-xyz/anchor": "^0.29.0",
"@injectivelabs/sdk-ts": "^1.10.72",
"@project-serum/anchor": "^0.25.0",
"@pythnetwork/client": "^2.21.1",
"@pythnetwork/client": "^2.22.0",
"@pythnetwork/xc-admin-common": "workspace:*",
"@solana/web3.js": "^1.73.0",
"@sqds/mesh": "^1.0.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@certusone/wormhole-sdk": "^0.10.15",
"@coral-xyz/anchor": "^0.29.0",
"@injectivelabs/sdk-ts": "^1.10.72",
"@pythnetwork/client": "^2.21.1",
"@pythnetwork/client": "^2.22.0",
"@pythnetwork/xc-admin-common": "workspace:*",
"@solana/web3.js": "^1.73.0",
"@sqds/mesh": "^1.0.6",
Expand Down
2 changes: 1 addition & 1 deletion governance/xc_admin/packages/proposer_server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@injectivelabs/sdk-ts": "^1.10.72",
"@pythnetwork/client": "^2.21.1",
"@pythnetwork/client": "^2.22.0",
"@pythnetwork/xc-admin-common": "workspace:*",
"@solana/web3.js": "^1.76.0",
"@sqds/mesh": "^1.0.6",
Expand Down
2 changes: 1 addition & 1 deletion governance/xc_admin/packages/xc_admin_cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@coral-xyz/anchor": "^0.29.0",
"@ledgerhq/hw-transport": "^6.27.10",
"@ledgerhq/hw-transport-node-hid": "^6.27.10",
"@pythnetwork/client": "^2.21.1",
"@pythnetwork/client": "^2.22.0",
"@pythnetwork/pyth-solana-receiver": "workspace:*",
"@pythnetwork/solana-utils": "workspace:^",
"@pythnetwork/xc-admin-common": "workspace:*",
Expand Down
63 changes: 61 additions & 2 deletions governance/xc_admin/packages/xc_admin_cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { Program } from "@coral-xyz/anchor";
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
import { TOKEN_PROGRAM_ID } from "@coral-xyz/anchor/dist/cjs/utils/token";
import { pythOracleProgram } from "@pythnetwork/client";
import {
pythOracleProgram,
PythHttpClient,
parseBaseData,
AccountType,
parsePriceData,
} from "@pythnetwork/client";
import {
PythCluster,
getPythClusterApiUrl,
Expand Down Expand Up @@ -33,9 +39,9 @@ import {
MultisigParser,
MultisigVault,
PROGRAM_AUTHORITY_ESCROW,
findDetermisticStakeAccountAddress,
getMultisigCluster,
getProposalInstructions,
findDetermisticStakeAccountAddress,
} from "@pythnetwork/xc-admin-common";

import {
Expand Down Expand Up @@ -500,6 +506,59 @@ multisigCommand(
);
});

multisigCommand(
"init-price-feed-index",
"Init price feed indexes to migrate old price feed accounts to the new index"
).action(async (options: any) => {
const vault = await loadVaultFromOptions(options);

const cluster: PythCluster = options.cluster;
const oracleProgramId = getPythProgramKeyForCluster(cluster);
const connection = new Connection(getPythClusterApiUrl(cluster));

const allPythAccounts = await connection.getProgramAccounts(oracleProgramId);

const pricePubkeysToInitialize = [];

for (const account of allPythAccounts) {
const data = account.account.data;
const pubkey = account.pubkey;

const base = parseBaseData(data);
if (base?.type === AccountType.Price) {
const parsed = parsePriceData(data);
if (parsed.feedIndex === 0) {
pricePubkeysToInitialize.push(pubkey);
}
}
}

// Create instructions to initialize the price feed indexes
const oracleProgram = pythOracleProgram(
oracleProgramId,
vault.getAnchorProvider()
);

const instructions: TransactionInstruction[] = [];
for (const pubkey of pricePubkeysToInitialize) {
instructions.push(
await oracleProgram.methods
.initPriceFeedIndex()
.accounts({
fundingAccount: await vault.getVaultAuthorityPDA(cluster),
priceAccount: pubkey,
})
.instruction()
);
}

await vault.proposeInstructions(
instructions,
cluster,
DEFAULT_PRIORITY_FEE_CONFIG
);
});

program
.command("parse-transaction")
.description("Parse a transaction sitting in the multisig")
Expand Down
2 changes: 1 addition & 1 deletion governance/xc_admin/packages/xc_admin_common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@coral-xyz/anchor": "^0.29.0",
"@injectivelabs/token-metadata": "~1.10.42",
"@project-serum/anchor": "^0.25.0",
"@pythnetwork/client": "^2.21.1",
"@pythnetwork/client": "^2.22.0",
"@pythnetwork/pyth-solana-receiver": "workspace:*",
"@pythnetwork/solana-utils": "workspace:*",
"@solana/buffer-layout": "^4.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@headlessui/react": "^1.7.7",
"@pythnetwork/client": "^2.21.1",
"@pythnetwork/client": "^2.22.0",
"@pythnetwork/solana-utils": "workspace:^",
"@pythnetwork/xc-admin-common": "workspace:*",
"@radix-ui/react-label": "^2.0.0",
Expand Down
Loading

0 comments on commit c967a84

Please sign in to comment.