Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 6 additions & 27 deletions lazer/contracts/sui/sdk/js/examples/fetch-and-verify-update.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,26 @@
import { SuiClient } from "@mysten/sui/client";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
import { Transaction } from "@mysten/sui/transactions";
import type { Request as SubscriptionRequest } from "@pythnetwork/pyth-lazer-sdk";
import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";

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

async function getOneLeEcdsaUpdate(urls: string[], token: string) {
async function getOneLeEcdsaUpdate(token: string) {
const lazer = await PythLazerClient.create({
urls,
token,
numConnections: 1,
});

const subscription: SubscriptionRequest = {
subscriptionId: 1,
type: "subscribe",
const latestPrice = await lazer.get_latest_price({
priceFeedIds: [1],
properties: ["price", "bestBidPrice", "bestAskPrice", "exponent"],
formats: ["leEcdsa"],
channel: "fixed_rate@200ms",
deliveryFormat: "binary",
jsonBinaryEncoding: "hex",
};

lazer.subscribe(subscription);

return new Promise<Uint8Array>((resolve) => {
lazer.addMessageListener((event) => {
if (event.type === "binary" && event.value.leEcdsa) {
const buf = event.value.leEcdsa;

// For the purposes of this example, we only need one update.
lazer.shutdown();
resolve(buf);
}
});
});

return latestPrice;
}

async function main() {
Expand Down Expand Up @@ -87,10 +69,7 @@ async function main() {
const provider = new SuiClient({ url: args.fullnodeUrl });

// Fetch the price update
const updateBytes = await getOneLeEcdsaUpdate(
args.lazerUrls,
args.lazerToken,
);
const update = await getOneLeEcdsaUpdate(args.lazerToken);

// Build the Sui transaction
const tx = new Transaction();
Expand All @@ -100,7 +79,7 @@ async function main() {
tx,
packageId: args.packageId,
stateObjectId: args.stateObjectId,
updateBytes,
updateBytes: Buffer.from(update.leEcdsa?.data ?? "", "hex"),
});

// --- You can add more calls to the transaction that consume the parsed update here ---
Expand Down
2 changes: 1 addition & 1 deletion lazer/contracts/sui/sdk/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/pyth-lazer-sui-js",
"version": "0.1.0",
"version": "0.1.1",
"description": "TypeScript SDK for the Pyth Lazer Sui contract",
"license": "Apache-2.0",
"type": "module",
Expand Down
48 changes: 48 additions & 0 deletions lazer/sdk/js/examples/history.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable no-console */

import { displayParsedPrices } from "./util.js";
import { PythLazerClient } from "../src/index.js";

const client = await PythLazerClient.create({
token: "your-token-here",
logger: console,
});

// Example 1: Get latest price for BTC using feed IDs
console.log("\n=== Example 1: Latest BTC price (requested with feed ID) ===");
const response1 = await client.get_latest_price({
priceFeedIds: [1],
properties: ["price", "confidence", "exponent"],
formats: [],
jsonBinaryEncoding: "hex",
parsed: true,
channel: "fixed_rate@200ms",
});
displayParsedPrices(response1);

// Example 2: Get latest price using symbols
console.log("\n=== Example 2: Latest ETH price (requested with symbols) ===");
const response2 = await client.get_latest_price({
priceFeedIds: [2],
properties: ["price", "confidence", "exponent"],
formats: [],
parsed: true,
channel: "real_time",
});
displayParsedPrices(response2);

// Example 3: Get historical price at specific timestamp
console.log("\n=== Example 3: Historical BTC price at timestamp ===");
const timestamp = 1_754_348_458_565_000;
console.log(
`Requesting price from timestamp: ${timestamp.toString()} (${new Date(timestamp / 1000).toISOString()})`,
);
const response3 = await client.get_price({
timestamp: timestamp,
priceFeedIds: [1],
properties: ["price", "confidence", "exponent"],
formats: [],
parsed: true,
channel: "real_time",
});
displayParsedPrices(response3);
89 changes: 0 additions & 89 deletions lazer/sdk/js/examples/index.ts

This file was deleted.

Loading
Loading