@pythnetwork/pyth-sui-js 2.0.0 → 2.1.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/LICENSE +1 -1
- package/README.md +12 -11
- package/lib/client.d.ts +7 -8
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +9 -6
- package/lib/examples/SuiRelay.d.ts +1 -1
- package/lib/examples/SuiRelay.d.ts.map +1 -1
- package/lib/examples/SuiRelay.js +6 -6
- package/package.json +10 -10
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -57,7 +57,8 @@ You can use `SuiPythClient` to build such transactions.
|
|
|
57
57
|
|
|
58
58
|
```ts
|
|
59
59
|
import { SuiPythClient } from "@pythnetwork/pyth-sui-js";
|
|
60
|
-
import {
|
|
60
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
61
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
61
62
|
|
|
62
63
|
const priceUpdateData = await connection.getPriceFeedsUpdateData(priceIds); // see quickstart section
|
|
63
64
|
|
|
@@ -69,8 +70,9 @@ const wallet: SignerWithProvider = getWallet();
|
|
|
69
70
|
const wormholeStateId = " 0xFILL_ME";
|
|
70
71
|
const pythStateId = "0xFILL_ME";
|
|
71
72
|
|
|
73
|
+
const provider = new SuiClient({ url: "https://fill-sui-endpoint" });
|
|
72
74
|
const client = new SuiPythClient(wallet.provider, pythStateId, wormholeStateId);
|
|
73
|
-
const tx = new
|
|
75
|
+
const tx = new Transaction();
|
|
74
76
|
const priceInfoObjectIds = await client.updatePriceFeeds(tx, priceFeedUpdateData, priceIds);
|
|
75
77
|
|
|
76
78
|
tx.moveCall({
|
|
@@ -82,15 +84,14 @@ tx.moveCall({
|
|
|
82
84
|
],
|
|
83
85
|
});
|
|
84
86
|
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const result = await wallet.signAndExecuteTransactionBlock(txBlock);
|
|
87
|
+
const result = await provider.signAndExecuteTransaction({
|
|
88
|
+
signer: wallet,
|
|
89
|
+
transaction: tx,
|
|
90
|
+
options: {
|
|
91
|
+
showEffects: true,
|
|
92
|
+
showEvents: true,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
94
95
|
```
|
|
95
96
|
|
|
96
97
|
Now in your contract you can consume the price by calling `pyth::get_price` or other utility functions on the `PriceInfoObject`.
|
package/lib/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { SuiClient } from "@mysten/sui
|
|
3
|
-
import {
|
|
2
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
3
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
4
4
|
import { HexString } from "@pythnetwork/price-service-client";
|
|
5
5
|
import { Buffer } from "buffer";
|
|
6
6
|
export type ObjectId = string;
|
|
@@ -27,10 +27,9 @@ export declare class SuiPythClient {
|
|
|
27
27
|
* @param vaas array of vaas to verify
|
|
28
28
|
* @param tx transaction block to add commands to
|
|
29
29
|
*/
|
|
30
|
-
verifyVaas(vaas: Buffer[], tx:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
kind: "NestedResult";
|
|
30
|
+
verifyVaas(vaas: Buffer[], tx: Transaction): Promise<{
|
|
31
|
+
$kind: "NestedResult";
|
|
32
|
+
NestedResult: [number, number];
|
|
34
33
|
}[]>;
|
|
35
34
|
/**
|
|
36
35
|
* Adds the necessary commands for updating the pyth price feeds to the transaction block.
|
|
@@ -38,8 +37,8 @@ export declare class SuiPythClient {
|
|
|
38
37
|
* @param updates array of price feed updates received from the price service
|
|
39
38
|
* @param feedIds array of feed ids to update (in hex format)
|
|
40
39
|
*/
|
|
41
|
-
updatePriceFeeds(tx:
|
|
42
|
-
createPriceFeed(tx:
|
|
40
|
+
updatePriceFeeds(tx: Transaction, updates: Buffer[], feedIds: HexString[]): Promise<ObjectId[]>;
|
|
41
|
+
createPriceFeed(tx: Transaction, updates: Buffer[]): Promise<void>;
|
|
43
42
|
/**
|
|
44
43
|
* Get the packageId for the wormhole package if not already cached
|
|
45
44
|
*/
|
package/lib/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,qBAAa,aAAa;IAOf,QAAQ,EAAE,SAAS;IACnB,WAAW,EAAE,QAAQ;IACrB,eAAe,EAAE,QAAQ;IARlC,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,iBAAiB,CAAuB;IAChD,OAAO,CAAC,cAAc,CAAoD;IAC1E,OAAO,CAAC,sBAAsB,CAAuC;IACrE,OAAO,CAAC,aAAa,CAAqB;gBAEjC,QAAQ,EAAE,SAAS,EACnB,WAAW,EAAE,QAAQ,EACrB,eAAe,EAAE,QAAQ;IAM5B,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAoBzC;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IA0BzD;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,WAAW;;;;IAwBhD;;;;;OAKG;IACG,gBAAgB,CACpB,EAAE,EAAE,WAAW,EACf,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,SAAS,EAAE,GACnB,OAAO,CAAC,QAAQ,EAAE,CAAC;IA8DhB,eAAe,CAAC,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE;IA2BxD;;OAEG;IACG,oBAAoB;IAO1B;;OAEG;IACG,gBAAgB;IAOtB;;;OAGG;IACG,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IA6B5E;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,QAAQ,CAAC;QAAC,SAAS,EAAE,QAAQ,CAAA;KAAE,CAAC;IAwBzE;;;;OAIG;IACH,qCAAqC,CAAC,kBAAkB,EAAE,MAAM,GAAG,MAAM;CAY1E"}
|
package/lib/client.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SuiPythClient = void 0;
|
|
4
|
-
const utils_1 = require("@mysten/sui
|
|
5
|
-
const bcs_1 = require("@mysten/sui
|
|
4
|
+
const utils_1 = require("@mysten/sui/utils");
|
|
5
|
+
const bcs_1 = require("@mysten/sui/bcs");
|
|
6
6
|
const buffer_1 = require("buffer");
|
|
7
7
|
const MAX_ARGUMENT_SIZE = 16 * 1024;
|
|
8
8
|
class SuiPythClient {
|
|
@@ -79,7 +79,8 @@ class SuiPythClient {
|
|
|
79
79
|
arguments: [
|
|
80
80
|
tx.object(this.wormholeStateId),
|
|
81
81
|
tx.pure(bcs_1.bcs
|
|
82
|
-
.
|
|
82
|
+
.vector(bcs_1.bcs.U8)
|
|
83
|
+
.serialize(Array.from(vaa), {
|
|
83
84
|
maxSize: MAX_ARGUMENT_SIZE,
|
|
84
85
|
})
|
|
85
86
|
.toBytes()),
|
|
@@ -109,7 +110,8 @@ class SuiPythClient {
|
|
|
109
110
|
arguments: [
|
|
110
111
|
tx.object(this.pythStateId),
|
|
111
112
|
tx.pure(bcs_1.bcs
|
|
112
|
-
.
|
|
113
|
+
.vector(bcs_1.bcs.U8)
|
|
114
|
+
.serialize(Array.from(updates[0]), {
|
|
113
115
|
maxSize: MAX_ARGUMENT_SIZE,
|
|
114
116
|
})
|
|
115
117
|
.toBytes()),
|
|
@@ -119,7 +121,7 @@ class SuiPythClient {
|
|
|
119
121
|
});
|
|
120
122
|
const priceInfoObjects = [];
|
|
121
123
|
const baseUpdateFee = await this.getBaseUpdateFee();
|
|
122
|
-
const coins = tx.splitCoins(tx.gas, feedIds.map(() => tx.pure(baseUpdateFee)));
|
|
124
|
+
const coins = tx.splitCoins(tx.gas, feedIds.map(() => tx.pure.u64(baseUpdateFee)));
|
|
123
125
|
let coinId = 0;
|
|
124
126
|
for (const feedId of feedIds) {
|
|
125
127
|
const priceInfoObjectId = await this.getPriceFeedObjectId(feedId);
|
|
@@ -158,7 +160,8 @@ class SuiPythClient {
|
|
|
158
160
|
arguments: [
|
|
159
161
|
tx.object(this.pythStateId),
|
|
160
162
|
tx.pure(bcs_1.bcs
|
|
161
|
-
.
|
|
163
|
+
.vector(bcs_1.bcs.U8)
|
|
164
|
+
.serialize(Array.from(updates[0]), {
|
|
162
165
|
maxSize: MAX_ARGUMENT_SIZE,
|
|
163
166
|
})
|
|
164
167
|
.toBytes()),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SuiRelay.d.ts","sourceRoot":"","sources":["../../src/examples/SuiRelay.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"SuiRelay.d.ts","sourceRoot":"","sources":["../../src/examples/SuiRelay.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAqC/C,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,aAEtC"}
|
package/lib/examples/SuiRelay.js
CHANGED
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getProvider = void 0;
|
|
7
7
|
const yargs_1 = __importDefault(require("yargs"));
|
|
8
8
|
const helpers_1 = require("yargs/helpers");
|
|
9
|
-
const client_1 = require("@mysten/sui
|
|
10
|
-
const transactions_1 = require("@mysten/sui
|
|
11
|
-
const ed25519_1 = require("@mysten/sui
|
|
9
|
+
const client_1 = require("@mysten/sui/client");
|
|
10
|
+
const transactions_1 = require("@mysten/sui/transactions");
|
|
11
|
+
const ed25519_1 = require("@mysten/sui/keypairs/ed25519");
|
|
12
12
|
const buffer_1 = require("buffer");
|
|
13
13
|
const client_2 = require("../client");
|
|
14
14
|
const index_1 = require("../index");
|
|
@@ -68,7 +68,7 @@ async function run() {
|
|
|
68
68
|
newFeeds,
|
|
69
69
|
existingFeeds,
|
|
70
70
|
});
|
|
71
|
-
const tx = new transactions_1.
|
|
71
|
+
const tx = new transactions_1.Transaction();
|
|
72
72
|
if (existingFeeds.length > 0) {
|
|
73
73
|
const updateData = await connection.getPriceFeedsUpdateData(existingFeeds);
|
|
74
74
|
await client.updatePriceFeeds(tx, updateData, existingFeeds);
|
|
@@ -78,9 +78,9 @@ async function run() {
|
|
|
78
78
|
await client.createPriceFeed(tx, updateData);
|
|
79
79
|
}
|
|
80
80
|
const wallet = ed25519_1.Ed25519Keypair.fromSecretKey(buffer_1.Buffer.from(process.env.SUI_KEY, "hex"));
|
|
81
|
-
const result = await provider.
|
|
81
|
+
const result = await provider.signAndExecuteTransaction({
|
|
82
82
|
signer: wallet,
|
|
83
|
-
|
|
83
|
+
transaction: tx,
|
|
84
84
|
options: {
|
|
85
85
|
showEffects: true,
|
|
86
86
|
showEvents: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pythnetwork/pyth-sui-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Pyth Network Sui Utilities",
|
|
5
5
|
"homepage": "https://pyth.network",
|
|
6
6
|
"author": {
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"test": "jest --passWithNoTests",
|
|
24
24
|
"build": "tsc",
|
|
25
|
-
"example-relay": "
|
|
25
|
+
"example-relay": "pnpm run build && node lib/examples/SuiRelay.js",
|
|
26
26
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
27
27
|
"lint": "eslint src/",
|
|
28
|
-
"prepublishOnly": "
|
|
29
|
-
"preversion": "
|
|
30
|
-
"version": "
|
|
28
|
+
"prepublishOnly": "pnpm run build && pnpm test && pnpm run lint",
|
|
29
|
+
"preversion": "pnpm run lint",
|
|
30
|
+
"version": "pnpm run format && git add -A src"
|
|
31
31
|
},
|
|
32
32
|
"keywords": [
|
|
33
33
|
"pyth",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"@types/node": "^18.11.18",
|
|
43
43
|
"@types/web3-provider-engine": "^14.0.1",
|
|
44
44
|
"@types/yargs": "^17.0.20",
|
|
45
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
46
|
-
"@typescript-eslint/parser": "^
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
46
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
47
47
|
"eslint": "^8.14.0",
|
|
48
48
|
"jest": "^29.4.1",
|
|
49
49
|
"prettier": "^2.6.2",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"yargs": "^17.0.20"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@mysten/sui
|
|
57
|
-
"@pythnetwork/price-service-client": "
|
|
56
|
+
"@mysten/sui": "^1.3.0",
|
|
57
|
+
"@pythnetwork/price-service-client": "1.9.0",
|
|
58
58
|
"buffer": "^6.0.3"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "9a31948be215682091abe580a68666909b976462"
|
|
61
61
|
}
|