SuiPriceServiceConnection.ts 947 B

123456789101112131415161718192021
  1. import {
  2. PriceServiceConnection,
  3. HexString,
  4. } from "@pythnetwork/price-service-client";
  5. import { Buffer } from "buffer";
  6. export class SuiPriceServiceConnection extends PriceServiceConnection {
  7. /**
  8. * Gets price update data (either batch price attestation VAAs or accumulator messages, depending on the chosen endpoint), which then
  9. * can be submitted to the Pyth contract to update the prices. This will throw an axios error if there is a network problem or
  10. * the price service returns a non-ok response (e.g: Invalid price ids)
  11. *
  12. * @param priceIds Array of hex-encoded price ids.
  13. * @returns Array of buffers containing the price update data.
  14. */
  15. async getPriceFeedsUpdateData(priceIds: HexString[]): Promise<Buffer[]> {
  16. // Fetch the latest price feed update VAAs from the price service
  17. const latestVaas = await this.getLatestVaas(priceIds);
  18. return latestVaas.map((vaa) => Buffer.from(vaa, "base64"));
  19. }
  20. }