update_pricefeed.ts 1.7 KB

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