Skip to content

Commit 492c841

Browse files
committed
Fixes, README
1 parent 3986c96 commit 492c841

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

target_chains/sui/sdk/js/README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -115,36 +115,36 @@ pnpm turbo run example-relay --filter @pythnetwork/pyth-sui-js -- \
115115
## Off-chain prices
116116

117117
Many applications additionally need to display Pyth prices off-chain, for example, in their frontend application.
118-
The `SuiPriceServiceConnection` provides two different ways to fetch the current Pyth price.
118+
The `SuiPriceServiceConnection` is an extension of the [Hermes client](https://github.com/pyth-network/pyth-crosschain/tree/main/apps/hermes/client/js)
119+
and provides two different ways to fetch the current Pyth price.
119120
The code blocks below assume that the `connection` and `priceIds` objects have been initialized as shown above.
120121
The first method is a single-shot query:
121122

122123
```typescript
123-
// `getLatestPriceFeeds` returns a `PriceFeed` for each price id. It contains all information about a price and has
124-
// utility functions to get the current and exponentially-weighted moving average price, and other functionality.
125-
const priceFeeds = await connection.getLatestPriceFeeds(priceIds);
126-
// Get the price if it is not older than 60 seconds from the current time.
127-
console.log(priceFeeds[0].getPriceNoOlderThan(60)); // Price { conf: '1234', expo: -8, price: '12345678' }
128-
// Get the exponentially-weighted moving average price if it is not older than 60 seconds from the current time.
129-
console.log(priceFeeds[1].getEmaPriceNoOlderThan(60));
124+
// `getLatestPriceFeeds` returns a `PriceUpdate`; see the [hermes-client](https://github.com/pyth-network/pyth-crosschain/tree/main/apps/hermes/client/js) documentation for details.
125+
const priceUpdate: PriceUpdate = await connection.getLatestPriceUpdates(priceIds, { parsed: true });
126+
if (priceUpdate.parsed) {
127+
console.log("ParsedPriceUpdate:", priceUpdate.parsed);
128+
}
130129
```
131130

132-
The object also supports a streaming websocket connection that allows you to subscribe to every new price update for a given feed.
131+
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.
133132
This method is useful if you want to show continuously updating real-time prices in your frontend:
134133

135134
```typescript
136-
// Subscribe to the price feeds given by `priceId`. The callback will be invoked every time the requested feed
137-
// gets a price update.
138-
connection.subscribePriceFeedUpdates(priceIds, (priceFeed) => {
139-
console.log(
140-
`Received update for ${priceFeed.id}: ${priceFeed.getPriceNoOlderThan(60)}`,
141-
);
142-
});
143-
144-
// When using the subscription, make sure to close the websocket upon termination to finish the process gracefully.
145-
setTimeout(() => {
146-
connection.closeWebSocket();
147-
}, 60000);
135+
// Streaming price updates
136+
const eventSource = await connection.getPriceUpdatesStream(priceIds, { parsed: true });
137+
eventSource.onmessage = (event) => {
138+
console.log("Received price update:", event.data);
139+
};
140+
eventSource.onerror = (error) => {
141+
console.error("Error receiving updates:", error);
142+
eventSource.close();
143+
};
144+
await sleep(5000);
145+
// To stop listening to the updates, you can call eventSource.close();
146+
console.log("Closing event source.");
147+
eventSource.close();
148148
```
149149

150150
## Hermes endpoints

target_chains/sui/sdk/js/src/SuiPriceServiceConnection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class SuiPriceServiceConnection extends HermesClient {
1616
*/
1717
async getPriceFeedsUpdateData(priceIds: HexString[]): Promise<Buffer[]> {
1818
// Fetch the latest price feed update VAAs from the price service
19-
const latestVaas: PriceUpdate = await this.getLatestPriceUpdates(priceIds, { encoding: "base64", parsed: false });
20-
return latestVaas.binary.data.map((vaa) => Buffer.from(vaa, "base64"));
19+
const updateData: PriceUpdate = await this.getLatestPriceUpdates(priceIds, { encoding: "base64", parsed: false });
20+
return updateData.binary.data.map((update) => Buffer.from(update, "base64"));
2121
}
2222
}

target_chains/sui/sdk/js/src/examples/SuiRelay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async function run() {
8989
const wallet = Ed25519Keypair.fromSecretKey(
9090
Buffer.from(process.env.SUI_KEY, "hex"),
9191
);
92-
92+
tx.setGasBudget(1000000);
9393
const result = await provider.signAndExecuteTransaction({
9494
signer: wallet,
9595
transaction: tx,

0 commit comments

Comments
 (0)