@pythnetwork/pyth-lazer-sui-js 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,33 +10,18 @@ const pyth_lazer_sdk_1 = require("@pythnetwork/pyth-lazer-sdk");
10
10
  const yargs_1 = __importDefault(require("yargs"));
11
11
  const helpers_1 = require("yargs/helpers");
12
12
  const client_js_1 = require("../src/client.js");
13
- async function getOneLeEcdsaUpdate(urls, token) {
13
+ async function getOneLeEcdsaUpdate(token) {
14
14
  const lazer = await pyth_lazer_sdk_1.PythLazerClient.create({
15
- urls,
16
15
  token,
17
- numConnections: 1,
18
16
  });
19
- const subscription = {
20
- subscriptionId: 1,
21
- type: "subscribe",
17
+ const latestPrice = await lazer.getLatestPrice({
22
18
  priceFeedIds: [1],
23
19
  properties: ["price", "bestBidPrice", "bestAskPrice", "exponent"],
24
20
  formats: ["leEcdsa"],
25
21
  channel: "fixed_rate@200ms",
26
- deliveryFormat: "binary",
27
22
  jsonBinaryEncoding: "hex",
28
- };
29
- lazer.subscribe(subscription);
30
- return new Promise((resolve) => {
31
- lazer.addMessageListener((event) => {
32
- if (event.type === "binary" && event.value.leEcdsa) {
33
- const buf = event.value.leEcdsa;
34
- // For the purposes of this example, we only need one update.
35
- lazer.shutdown();
36
- resolve(buf);
37
- }
38
- });
39
23
  });
24
+ return latestPrice;
40
25
  }
41
26
  async function main() {
42
27
  const args = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
@@ -78,7 +63,7 @@ async function main() {
78
63
  }
79
64
  const provider = new client_1.SuiClient({ url: args.fullnodeUrl });
80
65
  // Fetch the price update
81
- const updateBytes = await getOneLeEcdsaUpdate(args.lazerUrls, args.lazerToken);
66
+ const update = await getOneLeEcdsaUpdate(args.lazerToken);
82
67
  // Build the Sui transaction
83
68
  const tx = new transactions_1.Transaction();
84
69
  // Add the parse and verify call
@@ -86,7 +71,7 @@ async function main() {
86
71
  tx,
87
72
  packageId: args.packageId,
88
73
  stateObjectId: args.stateObjectId,
89
- updateBytes,
74
+ updateBytes: Buffer.from(update.leEcdsa?.data ?? "", "hex"),
90
75
  });
91
76
  // --- You can add more calls to the transaction that consume the parsed update here ---
92
77
  const wallet = ed25519_1.Ed25519Keypair.fromSecretKey(
@@ -5,33 +5,18 @@ import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
5
5
  import yargs from "yargs";
6
6
  import { hideBin } from "yargs/helpers";
7
7
  import { addParseAndVerifyLeEcdsaUpdateCall } from "../src/client.js";
8
- async function getOneLeEcdsaUpdate(urls, token) {
8
+ async function getOneLeEcdsaUpdate(token) {
9
9
  const lazer = await PythLazerClient.create({
10
- urls,
11
10
  token,
12
- numConnections: 1,
13
11
  });
14
- const subscription = {
15
- subscriptionId: 1,
16
- type: "subscribe",
12
+ const latestPrice = await lazer.getLatestPrice({
17
13
  priceFeedIds: [1],
18
14
  properties: ["price", "bestBidPrice", "bestAskPrice", "exponent"],
19
15
  formats: ["leEcdsa"],
20
16
  channel: "fixed_rate@200ms",
21
- deliveryFormat: "binary",
22
17
  jsonBinaryEncoding: "hex",
23
- };
24
- lazer.subscribe(subscription);
25
- return new Promise((resolve) => {
26
- lazer.addMessageListener((event) => {
27
- if (event.type === "binary" && event.value.leEcdsa) {
28
- const buf = event.value.leEcdsa;
29
- // For the purposes of this example, we only need one update.
30
- lazer.shutdown();
31
- resolve(buf);
32
- }
33
- });
34
18
  });
19
+ return latestPrice;
35
20
  }
36
21
  async function main() {
37
22
  const args = await yargs(hideBin(process.argv))
@@ -73,7 +58,7 @@ async function main() {
73
58
  }
74
59
  const provider = new SuiClient({ url: args.fullnodeUrl });
75
60
  // Fetch the price update
76
- const updateBytes = await getOneLeEcdsaUpdate(args.lazerUrls, args.lazerToken);
61
+ const update = await getOneLeEcdsaUpdate(args.lazerToken);
77
62
  // Build the Sui transaction
78
63
  const tx = new Transaction();
79
64
  // Add the parse and verify call
@@ -81,7 +66,7 @@ async function main() {
81
66
  tx,
82
67
  packageId: args.packageId,
83
68
  stateObjectId: args.stateObjectId,
84
- updateBytes,
69
+ updateBytes: Buffer.from(update.leEcdsa?.data ?? "", "hex"),
85
70
  });
86
71
  // --- You can add more calls to the transaction that consume the parsed update here ---
87
72
  const wallet = Ed25519Keypair.fromSecretKey(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pythnetwork/pyth-lazer-sui-js",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "TypeScript SDK for the Pyth Lazer Sui contract",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  "@mysten/sui": "^1.3.0",
28
28
  "@types/yargs": "^17.0.33",
29
29
  "yargs": "^18.0.0",
30
- "@pythnetwork/pyth-lazer-sdk": "2.0.0"
30
+ "@pythnetwork/pyth-lazer-sdk": "4.0.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@cprussin/eslint-config": "^4.0.2",