@pythnetwork/pyth-sui-js 2.2.0 → 2.3.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/README.md +22 -22
- package/lib/SuiPriceServiceConnection.d.ts +2 -2
- package/lib/SuiPriceServiceConnection.d.ts.map +1 -1
- package/lib/SuiPriceServiceConnection.js +7 -4
- package/lib/client.d.ts +1 -1
- package/lib/client.d.ts.map +1 -1
- package/lib/examples/SuiRelay.js +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ const priceUpdateData = await connection.getPriceFeedsUpdateData(priceIds); // s
|
|
|
61
61
|
// It is either injected from browser or instantiated in backend via some private key
|
|
62
62
|
const wallet: SignerWithProvider = getWallet();
|
|
63
63
|
// Get the state ids of the Pyth and Wormhole contracts from
|
|
64
|
-
// https://docs.pyth.network/
|
|
64
|
+
// https://docs.pyth.network/price-feeds/contract-addresses/sui
|
|
65
65
|
const wormholeStateId = " 0xFILL_ME";
|
|
66
66
|
const pythStateId = "0xFILL_ME";
|
|
67
67
|
|
|
@@ -115,36 +115,36 @@ pnpm turbo run example-relay --filter @pythnetwork/pyth-sui-js -- \
|
|
|
115
115
|
## Off-chain prices
|
|
116
116
|
|
|
117
117
|
Many applications additionally need to display Pyth prices off-chain, for example, in their frontend application.
|
|
118
|
-
The `SuiPriceServiceConnection`
|
|
118
|
+
The `SuiPriceServiceConnection` is an extension of the [Hermes client](https://github.com/pyth-network/pyth-crosschain/tree/main/apps/hermes/client/js)
|
|
119
|
+
and provides two different ways to fetch the current Pyth price.
|
|
119
120
|
The code blocks below assume that the `connection` and `priceIds` objects have been initialized as shown above.
|
|
120
121
|
The first method is a single-shot query:
|
|
121
122
|
|
|
122
123
|
```typescript
|
|
123
|
-
// `getLatestPriceFeeds` returns a `
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// Get the exponentially-weighted moving average price if it is not older than 60 seconds from the current time.
|
|
129
|
-
console.log(priceFeeds[1].getEmaPriceNoOlderThan(60));
|
|
124
|
+
// `getLatestPriceFeeds` returns a `PriceUpdate`; see the [hermes-client](https://github.com/pyth-network/pyth-crosschain/tree/main/apps/hermes/client/js) documentation for details.
|
|
125
|
+
const priceUpdate: PriceUpdate = await connection.getLatestPriceUpdates(priceIds, { parsed: true });
|
|
126
|
+
if (priceUpdate.parsed) {
|
|
127
|
+
console.log("ParsedPriceUpdate:", priceUpdate.parsed);
|
|
128
|
+
}
|
|
130
129
|
```
|
|
131
130
|
|
|
132
|
-
The object also supports a streaming
|
|
131
|
+
The object also supports a streaming Server-Sent Events (SSE) connection that allows you to subscribe to every new price update for a given feed.
|
|
133
132
|
This method is useful if you want to show continuously updating real-time prices in your frontend:
|
|
134
133
|
|
|
135
134
|
```typescript
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
135
|
+
// Streaming price updates
|
|
136
|
+
const eventSource = await connection.getPriceUpdatesStream(priceIds, { parsed: true });
|
|
137
|
+
eventSource.onmessage = (event) => {
|
|
138
|
+
console.log("Received price update:", event.data);
|
|
139
|
+
};
|
|
140
|
+
eventSource.onerror = (error) => {
|
|
141
|
+
console.error("Error receiving updates:", error);
|
|
142
|
+
eventSource.close();
|
|
143
|
+
};
|
|
144
|
+
await sleep(5000);
|
|
145
|
+
// To stop listening to the updates, you can call eventSource.close();
|
|
146
|
+
console.log("Closing event source.");
|
|
147
|
+
eventSource.close();
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
## Hermes endpoints
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HermesClient, HexString } from "@pythnetwork/hermes-client";
|
|
2
2
|
import { Buffer } from "buffer";
|
|
3
|
-
export declare class SuiPriceServiceConnection extends
|
|
3
|
+
export declare class SuiPriceServiceConnection extends HermesClient {
|
|
4
4
|
/**
|
|
5
5
|
* Gets price update data (either batch price attestation VAAs or accumulator messages, depending on the chosen endpoint), which then
|
|
6
6
|
* can be submitted to the Pyth contract to update the prices. This will throw an axios error if there is a network problem or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SuiPriceServiceConnection.d.ts","sourceRoot":"","sources":["../src/SuiPriceServiceConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"SuiPriceServiceConnection.d.ts","sourceRoot":"","sources":["../src/SuiPriceServiceConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,SAAS,EAEV,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,qBAAa,yBAA0B,SAAQ,YAAY;IACzD;;;;;;;OAOG;IACG,uBAAuB,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAUxE"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SuiPriceServiceConnection = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hermes_client_1 = require("@pythnetwork/hermes-client");
|
|
5
5
|
const buffer_1 = require("buffer");
|
|
6
|
-
class SuiPriceServiceConnection extends
|
|
6
|
+
class SuiPriceServiceConnection extends hermes_client_1.HermesClient {
|
|
7
7
|
/**
|
|
8
8
|
* Gets price update data (either batch price attestation VAAs or accumulator messages, depending on the chosen endpoint), which then
|
|
9
9
|
* can be submitted to the Pyth contract to update the prices. This will throw an axios error if there is a network problem or
|
|
@@ -14,8 +14,11 @@ class SuiPriceServiceConnection extends price_service_client_1.PriceServiceConne
|
|
|
14
14
|
*/
|
|
15
15
|
async getPriceFeedsUpdateData(priceIds) {
|
|
16
16
|
// Fetch the latest price feed update VAAs from the price service
|
|
17
|
-
const
|
|
18
|
-
|
|
17
|
+
const updateData = await this.getLatestPriceUpdates(priceIds, {
|
|
18
|
+
encoding: "base64",
|
|
19
|
+
parsed: false,
|
|
20
|
+
});
|
|
21
|
+
return updateData.binary.data.map((update) => buffer_1.Buffer.from(update, "base64"));
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
exports.SuiPriceServiceConnection = SuiPriceServiceConnection;
|
package/lib/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SuiClient } from "@mysten/sui/client";
|
|
2
2
|
import { Transaction } from "@mysten/sui/transactions";
|
|
3
|
-
import { HexString } from "@pythnetwork/
|
|
3
|
+
import { HexString } from "@pythnetwork/hermes-client";
|
|
4
4
|
import { Buffer } from "buffer";
|
|
5
5
|
type NestedTransactionResult = {
|
|
6
6
|
$kind: "NestedResult";
|
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,oBAAoB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,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,4BAA4B,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,KAAK,uBAAuB,GAAG;IAC7B,KAAK,EAAE,cAAc,CAAC;IACtB,YAAY,EAAE,CAAC,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B,OAAO,CAAC,QAAQ,EAAE,CAAC;IAiBhB,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/examples/SuiRelay.js
CHANGED
|
@@ -84,6 +84,7 @@ async function run() {
|
|
|
84
84
|
await client.createPriceFeed(tx, updateData);
|
|
85
85
|
}
|
|
86
86
|
const wallet = ed25519_1.Ed25519Keypair.fromSecretKey(buffer_1.Buffer.from(process.env.SUI_KEY, "hex"));
|
|
87
|
+
tx.setGasBudget(1000000);
|
|
87
88
|
const result = await provider.signAndExecuteTransaction({
|
|
88
89
|
signer: wallet,
|
|
89
90
|
transaction: tx,
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { SuiPriceServiceConnection } from "./SuiPriceServiceConnection";
|
|
2
2
|
export { SuiPythClient } from "./client";
|
|
3
|
-
export { DurationInMs, HexString,
|
|
3
|
+
export { AssetType, BinaryPriceUpdate, DurationInMs, DurationInSeconds, EncodingType, HermesClientConfig, HexString, PriceFeedMetadata, PriceIdInput, PriceUpdate, PublisherCaps, TwapsResponse, UnixTimestamp, } from "@pythnetwork/hermes-client";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EACL,YAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,aAAa,EACb,aAAa,EACb,aAAa,GACd,MAAM,4BAA4B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SuiPythClient = exports.SuiPriceServiceConnection = void 0;
|
|
4
4
|
var SuiPriceServiceConnection_1 = require("./SuiPriceServiceConnection");
|
|
5
5
|
Object.defineProperty(exports, "SuiPriceServiceConnection", { enumerable: true, get: function () { return SuiPriceServiceConnection_1.SuiPriceServiceConnection; } });
|
|
6
6
|
var client_1 = require("./client");
|
|
7
7
|
Object.defineProperty(exports, "SuiPythClient", { enumerable: true, get: function () { return client_1.SuiPythClient; } });
|
|
8
|
-
var price_service_client_1 = require("@pythnetwork/price-service-client");
|
|
9
|
-
Object.defineProperty(exports, "Price", { enumerable: true, get: function () { return price_service_client_1.Price; } });
|
|
10
|
-
Object.defineProperty(exports, "PriceFeed", { enumerable: true, get: function () { return price_service_client_1.PriceFeed; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pythnetwork/pyth-sui-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Pyth Network Sui Utilities",
|
|
5
5
|
"homepage": "https://pyth.network",
|
|
6
6
|
"author": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@mysten/sui": "^1.3.0",
|
|
47
47
|
"buffer": "^6.0.3",
|
|
48
|
-
"@pythnetwork/
|
|
48
|
+
"@pythnetwork/hermes-client": "2.0.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsc",
|