@pythnetwork/pyth-sui-js 1.2.0 → 1.2.2
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 +6 -2
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +17 -13
- package/lib/examples/SuiRelay.js +2 -1
- package/package.json +2 -2
package/lib/client.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { JsonRpcProvider, ObjectId, TransactionBlock } from "@mysten/sui.js";
|
|
3
3
|
import { HexString } from "@pythnetwork/price-service-client";
|
|
4
|
+
import { Buffer } from "buffer";
|
|
4
5
|
export declare class SuiPythClient {
|
|
5
6
|
provider: JsonRpcProvider;
|
|
6
7
|
pythStateId: ObjectId;
|
|
7
8
|
wormholeStateId: ObjectId;
|
|
8
9
|
private pythPackageId;
|
|
9
10
|
private wormholePackageId;
|
|
10
|
-
private
|
|
11
|
+
private priceTableInfo;
|
|
11
12
|
private priceFeedObjectIdCache;
|
|
12
13
|
private baseUpdateFee;
|
|
13
14
|
constructor(provider: JsonRpcProvider, pythStateId: ObjectId, wormholeStateId: ObjectId);
|
|
@@ -64,7 +65,10 @@ export declare class SuiPythClient {
|
|
|
64
65
|
* Fetches the price table object id for the current state id if not cached
|
|
65
66
|
* @returns price table object id
|
|
66
67
|
*/
|
|
67
|
-
|
|
68
|
+
getPriceTableInfo(): Promise<{
|
|
69
|
+
id: ObjectId;
|
|
70
|
+
fieldType: ObjectId;
|
|
71
|
+
}>;
|
|
68
72
|
/**
|
|
69
73
|
* Checks if a message is an accumulator message or not
|
|
70
74
|
* @param msg - update message from price service
|
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,EAEL,eAAe,EACf,QAAQ,EAER,gBAAgB,EACjB,MAAM,gBAAg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CAAC,QAAQ,GAAG,SAAS,CAAC;IA2B5E;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,QAAQ,CAAC;QAAC,SAAS,EAAE,QAAQ,CAAA;KAAE,CAAC;IAwBzE;;;OAGG;IACH,gBAAgB,CAAC,GAAG,EAAE,MAAM;IAK5B;;;;OAIG;IACH,qCAAqC,CAAC,kBAAkB,EAAE,MAAM,GAAG,MAAM;CAe1E"}
|
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 buffer_1 = require("buffer");
|
|
5
6
|
const MAX_ARGUMENT_SIZE = 16 * 1024;
|
|
6
7
|
class SuiPythClient {
|
|
7
8
|
provider;
|
|
@@ -9,7 +10,7 @@ class SuiPythClient {
|
|
|
9
10
|
wormholeStateId;
|
|
10
11
|
pythPackageId;
|
|
11
12
|
wormholePackageId;
|
|
12
|
-
|
|
13
|
+
priceTableInfo;
|
|
13
14
|
priceFeedObjectIdCache = new Map();
|
|
14
15
|
baseUpdateFee;
|
|
15
16
|
constructor(provider, pythStateId, wormholeStateId) {
|
|
@@ -131,25 +132,26 @@ class SuiPythClient {
|
|
|
131
132
|
throw new Error("Can't mix accumulator and non-accumulator messages");
|
|
132
133
|
}
|
|
133
134
|
const priceInfoObjects = [];
|
|
135
|
+
const baseUpdateFee = await this.getBaseUpdateFee();
|
|
136
|
+
const coins = tx.splitCoins(tx.gas, feedIds.map(() => tx.pure(baseUpdateFee)));
|
|
137
|
+
let coinId = 0;
|
|
134
138
|
for (const feedId of feedIds) {
|
|
135
139
|
const priceInfoObjectId = await this.getPriceFeedObjectId(feedId);
|
|
136
140
|
if (!priceInfoObjectId) {
|
|
137
141
|
throw new Error(`Price feed ${feedId} not found, please create it first`);
|
|
138
142
|
}
|
|
139
143
|
priceInfoObjects.push(priceInfoObjectId);
|
|
140
|
-
const coin = tx.splitCoins(tx.gas, [
|
|
141
|
-
tx.pure(await this.getBaseUpdateFee()),
|
|
142
|
-
]);
|
|
143
144
|
[priceUpdatesHotPotato] = tx.moveCall({
|
|
144
145
|
target: `${packageId}::pyth::update_single_price_feed`,
|
|
145
146
|
arguments: [
|
|
146
147
|
tx.object(this.pythStateId),
|
|
147
148
|
priceUpdatesHotPotato,
|
|
148
149
|
tx.object(priceInfoObjectId),
|
|
149
|
-
|
|
150
|
+
coins[coinId],
|
|
150
151
|
tx.object(sui_js_1.SUI_CLOCK_OBJECT_ID),
|
|
151
152
|
],
|
|
152
153
|
});
|
|
154
|
+
coinId++;
|
|
153
155
|
}
|
|
154
156
|
tx.moveCall({
|
|
155
157
|
target: `${packageId}::hot_potato_vector::destroy`,
|
|
@@ -224,13 +226,13 @@ class SuiPythClient {
|
|
|
224
226
|
async getPriceFeedObjectId(feedId) {
|
|
225
227
|
const normalizedFeedId = feedId.replace("0x", "");
|
|
226
228
|
if (!this.priceFeedObjectIdCache.has(normalizedFeedId)) {
|
|
227
|
-
const tableId = await this.
|
|
229
|
+
const { id: tableId, fieldType } = await this.getPriceTableInfo();
|
|
228
230
|
const result = await this.provider.getDynamicFieldObject({
|
|
229
231
|
parentId: tableId,
|
|
230
232
|
name: {
|
|
231
|
-
type: `${
|
|
233
|
+
type: `${fieldType}::price_identifier::PriceIdentifier`,
|
|
232
234
|
value: {
|
|
233
|
-
bytes: Array.from(Buffer.from(normalizedFeedId, "hex")),
|
|
235
|
+
bytes: Array.from(buffer_1.Buffer.from(normalizedFeedId, "hex")),
|
|
234
236
|
},
|
|
235
237
|
},
|
|
236
238
|
});
|
|
@@ -248,8 +250,8 @@ class SuiPythClient {
|
|
|
248
250
|
* Fetches the price table object id for the current state id if not cached
|
|
249
251
|
* @returns price table object id
|
|
250
252
|
*/
|
|
251
|
-
async
|
|
252
|
-
if (this.
|
|
253
|
+
async getPriceTableInfo() {
|
|
254
|
+
if (this.priceTableInfo === undefined) {
|
|
253
255
|
const result = await this.provider.getDynamicFieldObject({
|
|
254
256
|
parentId: this.pythStateId,
|
|
255
257
|
name: {
|
|
@@ -257,12 +259,14 @@ class SuiPythClient {
|
|
|
257
259
|
value: "price_info",
|
|
258
260
|
},
|
|
259
261
|
});
|
|
260
|
-
if (!result.data) {
|
|
262
|
+
if (!result.data || !result.data.type) {
|
|
261
263
|
throw new Error("Price Table not found, contract may not be initialized");
|
|
262
264
|
}
|
|
263
|
-
|
|
265
|
+
let type = result.data.type.replace("0x2::table::Table<", "");
|
|
266
|
+
type = type.replace("::price_identifier::PriceIdentifier, 0x2::object::ID>", "");
|
|
267
|
+
this.priceTableInfo = { id: result.data.objectId, fieldType: type };
|
|
264
268
|
}
|
|
265
|
-
return this.
|
|
269
|
+
return this.priceTableInfo;
|
|
266
270
|
}
|
|
267
271
|
/**
|
|
268
272
|
* Checks if a message is an accumulator message or not
|
package/lib/examples/SuiRelay.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.getProvider = void 0;
|
|
|
7
7
|
const yargs_1 = __importDefault(require("yargs"));
|
|
8
8
|
const helpers_1 = require("yargs/helpers");
|
|
9
9
|
const sui_js_1 = require("@mysten/sui.js");
|
|
10
|
+
const buffer_1 = require("buffer");
|
|
10
11
|
const client_1 = require("../client");
|
|
11
12
|
const index_1 = require("../index");
|
|
12
13
|
const argvPromise = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
@@ -54,7 +55,7 @@ async function run() {
|
|
|
54
55
|
const client = new client_1.SuiPythClient(provider, pythStateId, wormholeStateId);
|
|
55
56
|
const tx = new sui_js_1.TransactionBlock();
|
|
56
57
|
await client.updatePriceFeeds(tx, priceFeedUpdateData, feeds);
|
|
57
|
-
const wallet = new sui_js_1.RawSigner(sui_js_1.Ed25519Keypair.fromSecretKey(Buffer.from(process.env.SUI_KEY, "hex")), provider);
|
|
58
|
+
const wallet = new sui_js_1.RawSigner(sui_js_1.Ed25519Keypair.fromSecretKey(buffer_1.Buffer.from(process.env.SUI_KEY, "hex")), provider);
|
|
58
59
|
const txBlock = {
|
|
59
60
|
transactionBlock: tx,
|
|
60
61
|
options: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pythnetwork/pyth-sui-js",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
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": "
|
|
60
|
+
"gitHead": "061f6a028d152ce586c9f9ea237fccdb68144328"
|
|
61
61
|
}
|