Skip to content

Commit 6f700d1

Browse files
authored
[Xc admin] init price (#526)
* Format * Change exponent * Format
1 parent fdb2c5e commit 6f700d1

File tree

1 file changed

+44
-1
lines changed
  • governance/xc-admin/packages/xc-admin-cli/src

1 file changed

+44
-1
lines changed

governance/xc-admin/packages/xc-admin-cli/src/index.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import {
77
AccountMeta,
88
} from "@solana/web3.js";
99
import { program } from "commander";
10-
import { PythCluster } from "@pythnetwork/client/lib/cluster";
10+
import {
11+
getPythProgramKeyForCluster,
12+
PythCluster,
13+
} from "@pythnetwork/client/lib/cluster";
1114
import { getPythClusterApiUrl } from "@pythnetwork/client/lib/cluster";
1215
import { AnchorProvider, Program } from "@coral-xyz/anchor";
1316
import fs from "fs";
@@ -24,6 +27,7 @@ import {
2427
proposeInstructions,
2528
WORMHOLE_ADDRESS,
2629
} from "xc-admin-common";
30+
import { pythOracleProgram } from "@pythnetwork/client";
2731

2832
const mutlisigCommand = (name: string, description: string) =>
2933
program
@@ -165,6 +169,45 @@ mutlisigCommand("upgrade-program", "Upgrade a program from a buffer")
165169
await proposeInstructions(squad, vault, [proposalInstruction], false);
166170
});
167171

172+
mutlisigCommand(
173+
"init-price",
174+
"Init price (useful for changing the exponent), only to be used on unused price feeds"
175+
)
176+
.requiredOption("-p, --price <pubkey>", "Price account to modify")
177+
.requiredOption("-e, --exponent <number>", "New exponent")
178+
.action(async (options: any) => {
179+
const wallet = new NodeWallet(
180+
Keypair.fromSecretKey(
181+
Uint8Array.from(JSON.parse(fs.readFileSync(options.wallet, "ascii")))
182+
)
183+
);
184+
const cluster: PythCluster = options.cluster;
185+
const vault: PublicKey = new PublicKey(options.vault);
186+
const priceAccount: PublicKey = new PublicKey(options.price);
187+
const exponent = options.exponent;
188+
const squad = SquadsMesh.endpoint(getPythClusterApiUrl(cluster), wallet);
189+
190+
const msAccount = await squad.getMultisig(vault);
191+
const vaultAuthority = squad.getAuthorityPDA(
192+
msAccount.publicKey,
193+
msAccount.authorityIndex
194+
);
195+
196+
const provider = new AnchorProvider(
197+
squad.connection,
198+
wallet,
199+
AnchorProvider.defaultOptions()
200+
);
201+
const proposalInstruction: TransactionInstruction = await pythOracleProgram(
202+
getPythProgramKeyForCluster(cluster),
203+
provider
204+
)
205+
.methods.initPrice(exponent, 1)
206+
.accounts({ fundingAccount: vaultAuthority, priceAccount })
207+
.instruction();
208+
await proposeInstructions(squad, vault, [proposalInstruction], false);
209+
});
210+
168211
program
169212
.command("parse-transaction")
170213
.description("Parse a transaction sitting in the multisig")

0 commit comments

Comments
 (0)