@pythnetwork/pyth-sui-js 1.2.3 → 1.2.5

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 CHANGED
@@ -21,14 +21,14 @@ $ yarn add @pythnetwork/pyth-sui-js
21
21
  Pyth stores prices off-chain to minimize gas fees, which allows us to offer a wider selection of products and faster update times.
22
22
  See [On-Demand Updates](https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand) for more information about this approach.
23
23
  Typically, to use Pyth prices on chain,
24
- they must be fetched from an off-chain price service. The `SuiPriceServiceConnection` class can be used to interact with these services,
24
+ they must be fetched from an off-chain Hermes instance. The `SuiPriceServiceConnection` class can be used to interact with these services,
25
25
  providing a way to fetch these prices directly in your code. The following example wraps an existing RPC provider and shows how to obtain
26
26
  Pyth prices and submit them to the network:
27
27
 
28
28
  ```typescript
29
29
  const connection = new SuiPriceServiceConnection(
30
30
  "https://hermes-beta.pyth.network"
31
- ); // See Price Service endpoints section below for other endpoints
31
+ ); // See Hermes endpoints section below for other endpoints
32
32
 
33
33
  const priceIds = [
34
34
  // You can find the ids of prices at https://pyth.network/developers/price-feed-ids#sui-testnet
@@ -99,7 +99,7 @@ Now in your contract you can consume the price by calling `pyth::get_price` or o
99
99
 
100
100
  [This example](./src/examples/SuiRelay.ts) shows how to update prices on an Sui network. It does the following:
101
101
 
102
- 1. Fetches update data from the Price Service for the given price feeds.
102
+ 1. Fetches update data from Hermes for the given price feeds.
103
103
  2. Calls the Pyth Sui contract with the update data.
104
104
 
105
105
  You can run this example with `npm run example-relay`. A full command that updates prices on Sui testnet looks like:
@@ -148,4 +148,6 @@ setTimeout(() => {
148
148
  }, 60000);
149
149
  ```
150
150
 
151
- ## [Price Service endpoints](https://docs.pyth.network/documentation/pythnet-price-feeds/price-service#public-endpoints)
151
+ ## Hermes endpoints
152
+
153
+ You can find the list of Hermes public endpoints [here](https://docs.pyth.network/documentation/pythnet-price-feeds/hermes#public-endpoints).
package/lib/client.d.ts CHANGED
@@ -69,16 +69,5 @@ export declare class SuiPythClient {
69
69
  id: ObjectId;
70
70
  fieldType: ObjectId;
71
71
  }>;
72
- /**
73
- * Checks if a message is an accumulator message or not
74
- * @param msg - update message from price service
75
- */
76
- isAccumulatorMsg(msg: Buffer): boolean;
77
- /**
78
- * Obtains the vaa bytes embedded in an accumulator message.
79
- * @param accumulatorMessage - the accumulator price update message
80
- * @returns vaa bytes as a uint8 array
81
- */
82
- extractVaaBytesFromAccumulatorMessage(accumulatorMessage: Buffer): Buffer;
83
72
  }
84
73
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,eAAe,EACf,QAAQ,EAER,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,qBAAa,aAAa;IAOf,QAAQ,EAAE,eAAe;IACzB,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,eAAe,EACzB,WAAW,EAAE,QAAQ,EACrB,eAAe,EAAE,QAAQ;IAM5B,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAkBzC;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAuBzD;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,gBAAgB;;;;;;;;;;;;;;;IAuBrD;;;;;OAKG;IACG,gBA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IAkBzC;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAuBzD;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,gBAAgB;;;;;;;;;;;;;;;IAuBrD;;;;;OAKG;IACG,gBAAgB,CACpB,EAAE,EAAE,gBAAgB,EACpB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,SAAS,EAAE,GACnB,OAAO,CAAC,QAAQ,EAAE,CAAC;IA+EhB,eAAe,CAAC,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE;IA4C7D;;OAEG;IACG,oBAAoB;IAO1B;;OAEG;IACG,gBAAgB;IAOtB;;;OAGG;IACG,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IA2B5E;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,QAAQ,CAAC;QAAC,SAAS,EAAE,QAAQ,CAAA;KAAE,CAAC;CAuB1E"}
package/lib/client.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SuiPythClient = void 0;
4
4
  const sui_js_1 = require("@mysten/sui.js");
5
+ const price_service_client_1 = require("@pythnetwork/price-service-client");
5
6
  const buffer_1 = require("buffer");
6
7
  const MAX_ARGUMENT_SIZE = 16 * 1024;
7
8
  class SuiPythClient {
@@ -94,11 +95,11 @@ class SuiPythClient {
94
95
  const wormholePackageId = await this.getWormholePackageId();
95
96
  const packageId = await this.getPythPackageId();
96
97
  let priceUpdatesHotPotato;
97
- if (updates.every((update) => this.isAccumulatorMsg(update))) {
98
+ if (updates.every((update) => (0, price_service_client_1.isAccumulatorUpdateData)(update))) {
98
99
  if (updates.length > 1) {
99
100
  throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");
100
101
  }
101
- const vaa = this.extractVaaBytesFromAccumulatorMessage(updates[0]);
102
+ const vaa = (0, price_service_client_1.parseAccumulatorUpdateData)(updates[0]).vaa;
102
103
  const verifiedVaas = await this.verifyVaas([vaa], tx);
103
104
  [priceUpdatesHotPotato] = tx.moveCall({
104
105
  target: `${packageId}::pyth::create_authenticated_price_infos_using_accumulator`,
@@ -114,7 +115,7 @@ class SuiPythClient {
114
115
  ],
115
116
  });
116
117
  }
117
- else if (updates.every((vaa) => !this.isAccumulatorMsg(vaa))) {
118
+ else if (updates.every((vaa) => !(0, price_service_client_1.isAccumulatorUpdateData)(vaa))) {
118
119
  const verifiedVaas = await this.verifyVaas(updates, tx);
119
120
  [priceUpdatesHotPotato] = tx.moveCall({
120
121
  target: `${packageId}::pyth::create_price_infos_hot_potato`,
@@ -163,11 +164,11 @@ class SuiPythClient {
163
164
  async createPriceFeed(tx, updates) {
164
165
  const wormholePackageId = await this.getWormholePackageId();
165
166
  const packageId = await this.getPythPackageId();
166
- if (updates.every((update) => this.isAccumulatorMsg(update))) {
167
+ if (updates.every((update) => (0, price_service_client_1.isAccumulatorUpdateData)(update))) {
167
168
  if (updates.length > 1) {
168
169
  throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");
169
170
  }
170
- const vaa = this.extractVaaBytesFromAccumulatorMessage(updates[0]);
171
+ const vaa = (0, price_service_client_1.parseAccumulatorUpdateData)(updates[0]).vaa;
171
172
  const verifiedVaas = await this.verifyVaas([vaa], tx);
172
173
  tx.moveCall({
173
174
  target: `${packageId}::pyth::create_price_feeds_using_accumulator`,
@@ -183,7 +184,7 @@ class SuiPythClient {
183
184
  ],
184
185
  });
185
186
  }
186
- else if (updates.every((vaa) => !this.isAccumulatorMsg(vaa))) {
187
+ else if (updates.every((vaa) => !(0, price_service_client_1.isAccumulatorUpdateData)(vaa))) {
187
188
  const verifiedVaas = await this.verifyVaas(updates, tx);
188
189
  tx.moveCall({
189
190
  target: `${packageId}::pyth::create_price_feeds`,
@@ -268,32 +269,5 @@ class SuiPythClient {
268
269
  }
269
270
  return this.priceTableInfo;
270
271
  }
271
- /**
272
- * Checks if a message is an accumulator message or not
273
- * @param msg - update message from price service
274
- */
275
- isAccumulatorMsg(msg) {
276
- const ACCUMULATOR_MAGIC = "504e4155";
277
- return msg.toString("hex").slice(0, 8) === ACCUMULATOR_MAGIC;
278
- }
279
- /**
280
- * Obtains the vaa bytes embedded in an accumulator message.
281
- * @param accumulatorMessage - the accumulator price update message
282
- * @returns vaa bytes as a uint8 array
283
- */
284
- extractVaaBytesFromAccumulatorMessage(accumulatorMessage) {
285
- if (!this.isAccumulatorMsg(accumulatorMessage)) {
286
- throw new Error("Not an accumulator message");
287
- }
288
- // the first 6 bytes in the accumulator message encode the header, major, and minor bytes
289
- // we ignore them, since we are only interested in the VAA bytes
290
- const trailingPayloadSize = accumulatorMessage.readUint8(6);
291
- const vaaSizeOffset = 7 + // header bytes (header(4) + major(1) + minor(1) + trailing payload size(1))
292
- trailingPayloadSize + // trailing payload (variable number of bytes)
293
- 1; // proof_type (1 byte)
294
- const vaaSize = accumulatorMessage.readUint16BE(vaaSizeOffset);
295
- const vaaOffset = vaaSizeOffset + 2;
296
- return accumulatorMessage.subarray(vaaOffset, vaaOffset + vaaSize);
297
- }
298
272
  }
299
273
  exports.SuiPythClient = SuiPythClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pythnetwork/pyth-sui-js",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Pyth Network Sui Utilities",
5
5
  "homepage": "https://pyth.network",
6
6
  "author": {
@@ -57,5 +57,5 @@
57
57
  "@pythnetwork/price-service-client": "*",
58
58
  "buffer": "^6.0.3"
59
59
  },
60
- "gitHead": "2b51cffdc7e782995e7c267d2fc3b0a8a24e1c60"
60
+ "gitHead": "0d49986eb1cd77c969059bcb72857e90ba8ae4f8"
61
61
  }