Mike Rolish преди 1 месец
родител
ревизия
492c84150d

+ 21 - 21
target_chains/sui/sdk/js/README.md

@@ -115,36 +115,36 @@ pnpm turbo run example-relay --filter @pythnetwork/pyth-sui-js -- \
 ## Off-chain prices
 
 Many applications additionally need to display Pyth prices off-chain, for example, in their frontend application.
-The `SuiPriceServiceConnection` provides two different ways to fetch the current Pyth price.
+The `SuiPriceServiceConnection` is an extension of the [Hermes client](https://github.com/pyth-network/pyth-crosschain/tree/main/apps/hermes/client/js)
+and provides two different ways to fetch the current Pyth price.
 The code blocks below assume that the `connection` and `priceIds` objects have been initialized as shown above.
 The first method is a single-shot query:
 
 ```typescript
-// `getLatestPriceFeeds` returns a `PriceFeed` for each price id. It contains all information about a price and has
-// utility functions to get the current and exponentially-weighted moving average price, and other functionality.
-const priceFeeds = await connection.getLatestPriceFeeds(priceIds);
-// Get the price if it is not older than 60 seconds from the current time.
-console.log(priceFeeds[0].getPriceNoOlderThan(60)); // Price { conf: '1234', expo: -8, price: '12345678' }
-// Get the exponentially-weighted moving average price if it is not older than 60 seconds from the current time.
-console.log(priceFeeds[1].getEmaPriceNoOlderThan(60));
+// `getLatestPriceFeeds` returns a `PriceUpdate`; see the [hermes-client](https://github.com/pyth-network/pyth-crosschain/tree/main/apps/hermes/client/js) documentation for details.
+const priceUpdate: PriceUpdate = await connection.getLatestPriceUpdates(priceIds, { parsed: true });
+if (priceUpdate.parsed) {
+    console.log("ParsedPriceUpdate:", priceUpdate.parsed);
+}
 ```
 
-The object also supports a streaming websocket connection that allows you to subscribe to every new price update for a given feed.
+The object also supports a streaming Server-Sent Events (SSE) connection that allows you to subscribe to every new price update for a given feed.
 This method is useful if you want to show continuously updating real-time prices in your frontend:
 
 ```typescript
-// Subscribe to the price feeds given by `priceId`. The callback will be invoked every time the requested feed
-// gets a price update.
-connection.subscribePriceFeedUpdates(priceIds, (priceFeed) => {
-  console.log(
-    `Received update for ${priceFeed.id}: ${priceFeed.getPriceNoOlderThan(60)}`,
-  );
-});
-
-// When using the subscription, make sure to close the websocket upon termination to finish the process gracefully.
-setTimeout(() => {
-  connection.closeWebSocket();
-}, 60000);
+// Streaming price updates
+const eventSource = await connection.getPriceUpdatesStream(priceIds, { parsed: true });
+eventSource.onmessage = (event) => {
+    console.log("Received price update:", event.data);
+};
+eventSource.onerror = (error) => {
+    console.error("Error receiving updates:", error);
+    eventSource.close();
+};
+await sleep(5000);
+// To stop listening to the updates, you can call eventSource.close();
+console.log("Closing event source.");
+eventSource.close();
 ```
 
 ## Hermes endpoints

+ 2 - 2
target_chains/sui/sdk/js/src/SuiPriceServiceConnection.ts

@@ -16,7 +16,7 @@ export class SuiPriceServiceConnection extends HermesClient {
    */
   async getPriceFeedsUpdateData(priceIds: HexString[]): Promise<Buffer[]> {
     // Fetch the latest price feed update VAAs from the price service
-    const latestVaas: PriceUpdate = await this.getLatestPriceUpdates(priceIds, { encoding: "base64", parsed: false });
-    return latestVaas.binary.data.map((vaa) => Buffer.from(vaa, "base64"));
+    const updateData: PriceUpdate = await this.getLatestPriceUpdates(priceIds, { encoding: "base64", parsed: false });
+    return updateData.binary.data.map((update) => Buffer.from(update, "base64"));
   }
 }

+ 1 - 1
target_chains/sui/sdk/js/src/examples/SuiRelay.ts

@@ -89,7 +89,7 @@ async function run() {
   const wallet = Ed25519Keypair.fromSecretKey(
     Buffer.from(process.env.SUI_KEY, "hex"),
   );
-
+  tx.setGasBudget(1000000);
   const result = await provider.signAndExecuteTransaction({
     signer: wallet,
     transaction: tx,