@pythnetwork/pyth-sui-js 1.2.4 → 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/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;IAu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B;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,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.4",
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": "44ebfbaf5512acd96a12b3cdf361b47e64802dbf"
60
+ "gitHead": "0d49986eb1cd77c969059bcb72857e90ba8ae4f8"
61
61
  }