update_pricefeed.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import yargs from "yargs";
  2. import { hideBin } from "yargs/helpers";
  3. import { DefaultStore } from "../src";
  4. import { PriceServiceConnection } from "@pythnetwork/price-service-client";
  5. const parser = yargs(hideBin(process.argv))
  6. .scriptName("update_pricefeed.ts")
  7. .usage(
  8. "Usage: $0 --contract <contract_id> --feed-id <feed-id> --private-key <private-key>"
  9. )
  10. .options({
  11. contract: {
  12. type: "string",
  13. demandOption: true,
  14. desc: "Contract to update price feeds for (e.g mumbai_0xff1a0f4744e8582DF1aE09D5611b887B6a12925C)",
  15. },
  16. "feed-id": {
  17. type: "array",
  18. demandOption: true,
  19. desc: "Price feed ids to update without the leading 0x (e.g f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b). Can be provided multiple times for multiple feed updates",
  20. },
  21. "private-key": {
  22. type: "string",
  23. demandOption: true,
  24. desc: "Private key to use to sign transaction",
  25. },
  26. endpoint: {
  27. type: "string",
  28. desc: "Price service endpoint to use, defaults to https://xc-mainnet.pyth.network for mainnet and https://xc-testnet.pyth.network for testnet",
  29. },
  30. });
  31. async function main() {
  32. const argv = await parser.argv;
  33. const contract = DefaultStore.contracts[argv.contract];
  34. if (!contract) {
  35. throw new Error(`Contract ${argv.contract} not found`);
  36. }
  37. const defaultEndpoint = contract.getChain().isMainnet()
  38. ? "https://xc-mainnet.pyth.network"
  39. : "https://xc-testnet.pyth.network";
  40. const priceService = new PriceServiceConnection(
  41. argv.endpoint || defaultEndpoint
  42. );
  43. const vaas = await priceService.getLatestVaas(argv["feed-id"] as string[]);
  44. await contract.executeUpdatePriceFeed(
  45. argv["private-key"],
  46. vaas.map((vaa) => Buffer.from(vaa, "base64"))
  47. );
  48. }
  49. main();