@pythnetwork/pyth-lazer-sui-js 0.1.1 → 0.2.0
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.
- package/dist/cjs/client.cjs +23 -0
- package/dist/cjs/package.json +1 -1
- package/dist/esm/{src/client.js → client.mjs} +3 -4
- package/dist/esm/package.json +1 -1
- package/package.json +16 -16
- package/dist/cjs/examples/fetch-and-verify-update.d.ts +0 -1
- package/dist/cjs/examples/fetch-and-verify-update.js +0 -91
- package/dist/cjs/src/client.js +0 -16
- package/dist/esm/examples/fetch-and-verify-update.d.ts +0 -1
- package/dist/esm/examples/fetch-and-verify-update.js +0 -86
- /package/dist/cjs/{src/client.d.ts → client.d.ts} +0 -0
- /package/dist/esm/{src/client.d.ts → client.d.ts} +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "addParseAndVerifyLeEcdsaUpdateCall", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return addParseAndVerifyLeEcdsaUpdateCall;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _bcs = require("@mysten/sui/bcs");
|
|
12
|
+
const _utils = require("@mysten/sui/utils");
|
|
13
|
+
function addParseAndVerifyLeEcdsaUpdateCall({ tx, packageId, stateObjectId, updateBytes }) {
|
|
14
|
+
const [updateObj] = tx.moveCall({
|
|
15
|
+
target: `${packageId}::pyth_lazer::parse_and_verify_le_ecdsa_update`,
|
|
16
|
+
arguments: [
|
|
17
|
+
tx.object(stateObjectId),
|
|
18
|
+
tx.object(_utils.SUI_CLOCK_OBJECT_ID),
|
|
19
|
+
tx.pure(_bcs.bcs.vector(_bcs.bcs.U8).serialize(updateBytes).toBytes())
|
|
20
|
+
]
|
|
21
|
+
});
|
|
22
|
+
return updateObj;
|
|
23
|
+
}
|
package/dist/cjs/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"commonjs"}
|
|
1
|
+
{ "type": "commonjs" }
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { bcs } from "@mysten/sui/bcs";
|
|
2
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
3
2
|
import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
|
|
4
|
-
export function addParseAndVerifyLeEcdsaUpdateCall({ tx, packageId, stateObjectId, updateBytes
|
|
3
|
+
export function addParseAndVerifyLeEcdsaUpdateCall({ tx, packageId, stateObjectId, updateBytes }) {
|
|
5
4
|
const [updateObj] = tx.moveCall({
|
|
6
5
|
target: `${packageId}::pyth_lazer::parse_and_verify_le_ecdsa_update`,
|
|
7
6
|
arguments: [
|
|
8
7
|
tx.object(stateObjectId),
|
|
9
8
|
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
10
|
-
tx.pure(bcs.vector(bcs.U8).serialize(updateBytes).toBytes())
|
|
11
|
-
]
|
|
9
|
+
tx.pure(bcs.vector(bcs.U8).serialize(updateBytes).toBytes())
|
|
10
|
+
]
|
|
12
11
|
});
|
|
13
12
|
return updateObj;
|
|
14
13
|
}
|
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module"}
|
|
1
|
+
{ "type": "module" }
|
package/package.json
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pythnetwork/pyth-lazer-sui-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "TypeScript SDK for the Pyth Lazer Sui contract",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": "22"
|
|
8
|
+
"node": ">=22.14.0"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
|
-
"dist"
|
|
11
|
+
"dist/**/*"
|
|
12
12
|
],
|
|
13
13
|
"exports": {
|
|
14
|
-
"
|
|
15
|
-
"import": {
|
|
16
|
-
"types": "./dist/esm/client.d.ts",
|
|
17
|
-
"default": "./dist/esm/client.js"
|
|
18
|
-
},
|
|
14
|
+
"./client": {
|
|
19
15
|
"require": {
|
|
20
16
|
"types": "./dist/cjs/client.d.ts",
|
|
21
|
-
"default": "./dist/cjs/client.
|
|
17
|
+
"default": "./dist/cjs/client.cjs"
|
|
18
|
+
},
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./dist/esm/client.d.ts",
|
|
21
|
+
"default": "./dist/esm/client.mjs"
|
|
22
22
|
}
|
|
23
|
-
}
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
24
25
|
},
|
|
25
26
|
"sideEffects": false,
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@mysten/sui": "^1.3.0",
|
|
28
29
|
"@types/yargs": "^17.0.33",
|
|
29
30
|
"yargs": "^18.0.0",
|
|
30
|
-
"@pythnetwork/pyth-lazer-sdk": "
|
|
31
|
+
"@pythnetwork/pyth-lazer-sdk": "5.2.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@cprussin/eslint-config": "^4.0.2",
|
|
34
35
|
"@cprussin/tsconfig": "^3.1.2",
|
|
35
36
|
"@types/node": "^22.14.0",
|
|
36
37
|
"eslint": "^9.23.0",
|
|
37
|
-
"prettier": "^3.5.3"
|
|
38
|
-
"typescript": "^5.8.2"
|
|
38
|
+
"prettier": "^3.5.3"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"build
|
|
45
|
-
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm && echo '{\"type\":\"module\"}' > dist/esm/package.json",
|
|
44
|
+
"build": "ts-duality --clean",
|
|
46
45
|
"fix:format": "prettier --write .",
|
|
47
46
|
"fix:lint": "eslint --fix .",
|
|
48
47
|
"test:format": "prettier --check .",
|
|
49
48
|
"test:lint": "eslint . --max-warnings 0",
|
|
50
49
|
"test:types": "tsc",
|
|
51
|
-
"example:fetch-and-verify": "tsx examples/fetch-and-verify-update.ts"
|
|
50
|
+
"example:fetch-and-verify": "tsx examples/fetch-and-verify-update.ts",
|
|
51
|
+
"clean": "rm -rf ./dist"
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const client_1 = require("@mysten/sui/client");
|
|
7
|
-
const ed25519_1 = require("@mysten/sui/keypairs/ed25519");
|
|
8
|
-
const transactions_1 = require("@mysten/sui/transactions");
|
|
9
|
-
const pyth_lazer_sdk_1 = require("@pythnetwork/pyth-lazer-sdk");
|
|
10
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
11
|
-
const helpers_1 = require("yargs/helpers");
|
|
12
|
-
const client_js_1 = require("../src/client.js");
|
|
13
|
-
async function getOneLeEcdsaUpdate(token) {
|
|
14
|
-
const lazer = await pyth_lazer_sdk_1.PythLazerClient.create({
|
|
15
|
-
token,
|
|
16
|
-
});
|
|
17
|
-
const latestPrice = await lazer.get_latest_price({
|
|
18
|
-
priceFeedIds: [1],
|
|
19
|
-
properties: ["price", "bestBidPrice", "bestAskPrice", "exponent"],
|
|
20
|
-
formats: ["leEcdsa"],
|
|
21
|
-
channel: "fixed_rate@200ms",
|
|
22
|
-
jsonBinaryEncoding: "hex",
|
|
23
|
-
});
|
|
24
|
-
return latestPrice;
|
|
25
|
-
}
|
|
26
|
-
async function main() {
|
|
27
|
-
const args = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
28
|
-
.option("fullnodeUrl", {
|
|
29
|
-
type: "string",
|
|
30
|
-
description: "URL of the full Sui node RPC endpoint. e.g: https://fullnode.testnet.sui.io:443",
|
|
31
|
-
demandOption: true,
|
|
32
|
-
})
|
|
33
|
-
.option("packageId", {
|
|
34
|
-
type: "string",
|
|
35
|
-
description: "Lazer contract package ID",
|
|
36
|
-
demandOption: true,
|
|
37
|
-
})
|
|
38
|
-
.option("stateObjectId", {
|
|
39
|
-
type: "string",
|
|
40
|
-
description: "Lazer contract shared State object ID",
|
|
41
|
-
demandOption: true,
|
|
42
|
-
})
|
|
43
|
-
.option("lazerUrls", {
|
|
44
|
-
type: "array",
|
|
45
|
-
string: true,
|
|
46
|
-
description: "Lazer WebSocket URLs",
|
|
47
|
-
default: [
|
|
48
|
-
"wss://pyth-lazer-0.dourolabs.app/v1/stream",
|
|
49
|
-
"wss://pyth-lazer-1.dourolabs.app/v1/stream",
|
|
50
|
-
],
|
|
51
|
-
})
|
|
52
|
-
.option("lazerToken", {
|
|
53
|
-
type: "string",
|
|
54
|
-
description: "Lazer authentication token",
|
|
55
|
-
demandOption: true,
|
|
56
|
-
})
|
|
57
|
-
.help()
|
|
58
|
-
.parseAsync();
|
|
59
|
-
// Defined as a dependency in turbo.json
|
|
60
|
-
// eslint-disable-next-line n/no-process-env
|
|
61
|
-
if (process.env.SUI_KEY === undefined) {
|
|
62
|
-
throw new Error(`SUI_KEY environment variable should be set to your Sui private key in hex format.`);
|
|
63
|
-
}
|
|
64
|
-
const provider = new client_1.SuiClient({ url: args.fullnodeUrl });
|
|
65
|
-
// Fetch the price update
|
|
66
|
-
const update = await getOneLeEcdsaUpdate(args.lazerToken);
|
|
67
|
-
// Build the Sui transaction
|
|
68
|
-
const tx = new transactions_1.Transaction();
|
|
69
|
-
// Add the parse and verify call
|
|
70
|
-
(0, client_js_1.addParseAndVerifyLeEcdsaUpdateCall)({
|
|
71
|
-
tx,
|
|
72
|
-
packageId: args.packageId,
|
|
73
|
-
stateObjectId: args.stateObjectId,
|
|
74
|
-
updateBytes: Buffer.from(update.leEcdsa?.data ?? "", "hex"),
|
|
75
|
-
});
|
|
76
|
-
// --- You can add more calls to the transaction that consume the parsed update here ---
|
|
77
|
-
const wallet = ed25519_1.Ed25519Keypair.fromSecretKey(
|
|
78
|
-
// eslint-disable-next-line n/no-process-env
|
|
79
|
-
Buffer.from(process.env.SUI_KEY, "hex"));
|
|
80
|
-
const res = await provider.signAndExecuteTransaction({
|
|
81
|
-
signer: wallet,
|
|
82
|
-
transaction: tx,
|
|
83
|
-
options: { showEffects: true, showEvents: true },
|
|
84
|
-
});
|
|
85
|
-
// eslint-disable-next-line no-console
|
|
86
|
-
console.log("Execution result:", JSON.stringify(res, undefined, 2));
|
|
87
|
-
}
|
|
88
|
-
// eslint-disable-next-line unicorn/prefer-top-level-await
|
|
89
|
-
main().catch((error) => {
|
|
90
|
-
throw error;
|
|
91
|
-
});
|
package/dist/cjs/src/client.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addParseAndVerifyLeEcdsaUpdateCall = addParseAndVerifyLeEcdsaUpdateCall;
|
|
4
|
-
const bcs_1 = require("@mysten/sui/bcs");
|
|
5
|
-
const utils_1 = require("@mysten/sui/utils");
|
|
6
|
-
function addParseAndVerifyLeEcdsaUpdateCall({ tx, packageId, stateObjectId, updateBytes, }) {
|
|
7
|
-
const [updateObj] = tx.moveCall({
|
|
8
|
-
target: `${packageId}::pyth_lazer::parse_and_verify_le_ecdsa_update`,
|
|
9
|
-
arguments: [
|
|
10
|
-
tx.object(stateObjectId),
|
|
11
|
-
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
12
|
-
tx.pure(bcs_1.bcs.vector(bcs_1.bcs.U8).serialize(updateBytes).toBytes()),
|
|
13
|
-
],
|
|
14
|
-
});
|
|
15
|
-
return updateObj;
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { SuiClient } from "@mysten/sui/client";
|
|
2
|
-
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
3
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
4
|
-
import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
|
|
5
|
-
import yargs from "yargs";
|
|
6
|
-
import { hideBin } from "yargs/helpers";
|
|
7
|
-
import { addParseAndVerifyLeEcdsaUpdateCall } from "../src/client.js";
|
|
8
|
-
async function getOneLeEcdsaUpdate(token) {
|
|
9
|
-
const lazer = await PythLazerClient.create({
|
|
10
|
-
token,
|
|
11
|
-
});
|
|
12
|
-
const latestPrice = await lazer.get_latest_price({
|
|
13
|
-
priceFeedIds: [1],
|
|
14
|
-
properties: ["price", "bestBidPrice", "bestAskPrice", "exponent"],
|
|
15
|
-
formats: ["leEcdsa"],
|
|
16
|
-
channel: "fixed_rate@200ms",
|
|
17
|
-
jsonBinaryEncoding: "hex",
|
|
18
|
-
});
|
|
19
|
-
return latestPrice;
|
|
20
|
-
}
|
|
21
|
-
async function main() {
|
|
22
|
-
const args = await yargs(hideBin(process.argv))
|
|
23
|
-
.option("fullnodeUrl", {
|
|
24
|
-
type: "string",
|
|
25
|
-
description: "URL of the full Sui node RPC endpoint. e.g: https://fullnode.testnet.sui.io:443",
|
|
26
|
-
demandOption: true,
|
|
27
|
-
})
|
|
28
|
-
.option("packageId", {
|
|
29
|
-
type: "string",
|
|
30
|
-
description: "Lazer contract package ID",
|
|
31
|
-
demandOption: true,
|
|
32
|
-
})
|
|
33
|
-
.option("stateObjectId", {
|
|
34
|
-
type: "string",
|
|
35
|
-
description: "Lazer contract shared State object ID",
|
|
36
|
-
demandOption: true,
|
|
37
|
-
})
|
|
38
|
-
.option("lazerUrls", {
|
|
39
|
-
type: "array",
|
|
40
|
-
string: true,
|
|
41
|
-
description: "Lazer WebSocket URLs",
|
|
42
|
-
default: [
|
|
43
|
-
"wss://pyth-lazer-0.dourolabs.app/v1/stream",
|
|
44
|
-
"wss://pyth-lazer-1.dourolabs.app/v1/stream",
|
|
45
|
-
],
|
|
46
|
-
})
|
|
47
|
-
.option("lazerToken", {
|
|
48
|
-
type: "string",
|
|
49
|
-
description: "Lazer authentication token",
|
|
50
|
-
demandOption: true,
|
|
51
|
-
})
|
|
52
|
-
.help()
|
|
53
|
-
.parseAsync();
|
|
54
|
-
// Defined as a dependency in turbo.json
|
|
55
|
-
// eslint-disable-next-line n/no-process-env
|
|
56
|
-
if (process.env.SUI_KEY === undefined) {
|
|
57
|
-
throw new Error(`SUI_KEY environment variable should be set to your Sui private key in hex format.`);
|
|
58
|
-
}
|
|
59
|
-
const provider = new SuiClient({ url: args.fullnodeUrl });
|
|
60
|
-
// Fetch the price update
|
|
61
|
-
const update = await getOneLeEcdsaUpdate(args.lazerToken);
|
|
62
|
-
// Build the Sui transaction
|
|
63
|
-
const tx = new Transaction();
|
|
64
|
-
// Add the parse and verify call
|
|
65
|
-
addParseAndVerifyLeEcdsaUpdateCall({
|
|
66
|
-
tx,
|
|
67
|
-
packageId: args.packageId,
|
|
68
|
-
stateObjectId: args.stateObjectId,
|
|
69
|
-
updateBytes: Buffer.from(update.leEcdsa?.data ?? "", "hex"),
|
|
70
|
-
});
|
|
71
|
-
// --- You can add more calls to the transaction that consume the parsed update here ---
|
|
72
|
-
const wallet = Ed25519Keypair.fromSecretKey(
|
|
73
|
-
// eslint-disable-next-line n/no-process-env
|
|
74
|
-
Buffer.from(process.env.SUI_KEY, "hex"));
|
|
75
|
-
const res = await provider.signAndExecuteTransaction({
|
|
76
|
-
signer: wallet,
|
|
77
|
-
transaction: tx,
|
|
78
|
-
options: { showEffects: true, showEvents: true },
|
|
79
|
-
});
|
|
80
|
-
// eslint-disable-next-line no-console
|
|
81
|
-
console.log("Execution result:", JSON.stringify(res, undefined, 2));
|
|
82
|
-
}
|
|
83
|
-
// eslint-disable-next-line unicorn/prefer-top-level-await
|
|
84
|
-
main().catch((error) => {
|
|
85
|
-
throw error;
|
|
86
|
-
});
|
|
File without changes
|
|
File without changes
|