Skip to content

Commit c7b2ff6

Browse files
committed
update lazer sui js sdk to use updated js sdk
1 parent bf0e141 commit c7b2ff6

File tree

3 files changed

+11
-30
lines changed

3 files changed

+11
-30
lines changed

lazer/contracts/sui/sdk/js/examples/fetch-and-verify-update.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,26 @@
11
import { SuiClient } from "@mysten/sui/client";
22
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
33
import { Transaction } from "@mysten/sui/transactions";
4-
import type { Request as SubscriptionRequest } from "@pythnetwork/pyth-lazer-sdk";
54
import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
65
import yargs from "yargs";
76
import { hideBin } from "yargs/helpers";
87

98
import { addParseAndVerifyLeEcdsaUpdateCall } from "../src/client.js";
109

11-
async function getOneLeEcdsaUpdate(urls: string[], token: string) {
10+
async function getOneLeEcdsaUpdate(token: string) {
1211
const lazer = await PythLazerClient.create({
13-
urls,
1412
token,
15-
numConnections: 1,
1613
});
1714

18-
const subscription: SubscriptionRequest = {
19-
subscriptionId: 1,
20-
type: "subscribe",
15+
const latestPrice = await lazer.get_latest_price({
2116
priceFeedIds: [1],
2217
properties: ["price", "bestBidPrice", "bestAskPrice", "exponent"],
2318
formats: ["leEcdsa"],
2419
channel: "fixed_rate@200ms",
25-
deliveryFormat: "binary",
2620
jsonBinaryEncoding: "hex",
27-
};
28-
29-
lazer.subscribe(subscription);
30-
31-
return new Promise<Uint8Array>((resolve) => {
32-
lazer.addMessageListener((event) => {
33-
if (event.type === "binary" && event.value.leEcdsa) {
34-
const buf = event.value.leEcdsa;
35-
36-
// For the purposes of this example, we only need one update.
37-
lazer.shutdown();
38-
resolve(buf);
39-
}
40-
});
4121
});
22+
23+
return latestPrice
4224
}
4325

4426
async function main() {
@@ -87,8 +69,7 @@ async function main() {
8769
const provider = new SuiClient({ url: args.fullnodeUrl });
8870

8971
// Fetch the price update
90-
const updateBytes = await getOneLeEcdsaUpdate(
91-
args.lazerUrls,
72+
const update = await getOneLeEcdsaUpdate(
9273
args.lazerToken,
9374
);
9475

@@ -100,7 +81,7 @@ async function main() {
10081
tx,
10182
packageId: args.packageId,
10283
stateObjectId: args.stateObjectId,
103-
updateBytes,
84+
updateBytes: Buffer.from(update.leEcdsa?.data ?? "", "hex"),
10485
});
10586

10687
// --- You can add more calls to the transaction that consume the parsed update here ---

lazer/contracts/sui/sdk/js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-lazer-sui-js",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "TypeScript SDK for the Pyth Lazer Sui contract",
55
"license": "Apache-2.0",
66
"type": "module",

lazer/sdk/js/examples/streaming.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { JsonUpdate } from "../src/index.js";
66
import { PythLazerClient } from "../src/index.js";
77

88
// Ignore debug messages
9-
console.debug = () => {};
9+
console.debug = () => { };
1010

1111
// Store feed data for in-place updates
1212
const feedData = new Map<
@@ -21,7 +21,7 @@ const feedData = new Map<
2121
>();
2222

2323
const client = await PythLazerClient.create({
24-
token: "your-token-here", // Replace with your actual access token
24+
token: "ZpIVWYXIXXIPAARXLt50VTRMNjW91UUAnDu-test", // Replace with your actual access token
2525
logger: console, // Optionally log operations (to the console in this case.)
2626
webSocketPoolConfig: {
2727
numConnections: 4, // Optionally specify number of parallel redundant connections to reduce the chance of dropped messages. The connections will round-robin across the provided URLs. Default is 4.
@@ -86,7 +86,7 @@ client.subscribe({
8686
properties: ["price", "exponent", "publisherCount", "confidence"],
8787
formats: ["evm"],
8888
deliveryFormat: "json",
89-
channel: "fixed_rate@200ms",
89+
channel: "fixed_rate@50ms",
9090
parsed: true,
9191
jsonBinaryEncoding: "hex",
9292
});
@@ -97,7 +97,7 @@ client.subscribe({
9797
properties: ["price", "confidence"],
9898
formats: ["solana"],
9999
deliveryFormat: "json",
100-
channel: "fixed_rate@200ms",
100+
channel: "real_time",
101101
parsed: true,
102102
jsonBinaryEncoding: "hex",
103103
});

0 commit comments

Comments
 (0)