@typus/typus-sdk 1.7.14 → 1.7.15
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SuiPriceServiceConnection, SuiPythClient } from "@pythnetwork/pyth-sui-js";
|
|
2
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
1
|
+
import { HexString, SuiPriceServiceConnection, SuiPythClient } from "@pythnetwork/pyth-sui-js";
|
|
2
|
+
import { Argument, Transaction } from "@mysten/sui/transactions";
|
|
3
3
|
import { TOKEN } from "../../../src/constants";
|
|
4
4
|
import { ObjectId } from "@pythnetwork/pyth-sui-js/lib/client";
|
|
5
5
|
export declare class PythClient {
|
|
@@ -11,5 +11,12 @@ export declare function createPythClient(provider: any, network: "MAINNET" | "TE
|
|
|
11
11
|
/**
|
|
12
12
|
* @returns priceInfoObjectIds
|
|
13
13
|
*/
|
|
14
|
-
export declare function updatePyth(pythClient: PythClient, tx: Transaction, tokens: TOKEN[]): Promise<ObjectId[]>;
|
|
14
|
+
export declare function updatePyth(pythClient: PythClient, tx: Transaction, tokens: TOKEN[], suiCoin?: Argument): Promise<ObjectId[]>;
|
|
15
15
|
export declare function updateOracleWithPythUsd(pythClient: PythClient, tx: Transaction, oraclePackage: string, baseToken: TOKEN): void;
|
|
16
|
+
/**
|
|
17
|
+
* Adds the necessary commands for updating the pyth price feeds to the transaction block.
|
|
18
|
+
* @param tx transaction block to add commands to
|
|
19
|
+
* @param updates array of price feed updates received from the price service
|
|
20
|
+
* @param feedIds array of feed ids to update (in hex format)
|
|
21
|
+
*/
|
|
22
|
+
export declare function updatePriceFeeds(pythClient: PythClient, tx: Transaction, updates: Buffer[], feedIds: HexString[], suiCoin?: Argument): Promise<ObjectId[]>;
|
|
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.createPythClient = createPythClient;
|
|
40
40
|
exports.updatePyth = updatePyth;
|
|
41
41
|
exports.updateOracleWithPythUsd = updateOracleWithPythUsd;
|
|
42
|
+
exports.updatePriceFeeds = updatePriceFeeds;
|
|
42
43
|
var pyth_sui_js_1 = require("@pythnetwork/pyth-sui-js");
|
|
43
44
|
var constant_1 = require("./constant");
|
|
44
45
|
var constants_1 = require("../../../src/constants");
|
|
@@ -53,7 +54,7 @@ function createPythClient(provider, network) {
|
|
|
53
54
|
/**
|
|
54
55
|
* @returns priceInfoObjectIds
|
|
55
56
|
*/
|
|
56
|
-
function updatePyth(pythClient, tx, tokens) {
|
|
57
|
+
function updatePyth(pythClient, tx, tokens, suiCoin) {
|
|
57
58
|
return __awaiter(this, void 0, void 0, function () {
|
|
58
59
|
var _priceIDs, priceFeedUpdateData, priceInfoObjectIds;
|
|
59
60
|
return __generator(this, function (_a) {
|
|
@@ -63,7 +64,7 @@ function updatePyth(pythClient, tx, tokens) {
|
|
|
63
64
|
return [4 /*yield*/, pythClient.connection.getPriceFeedsUpdateData(_priceIDs)];
|
|
64
65
|
case 1:
|
|
65
66
|
priceFeedUpdateData = _a.sent();
|
|
66
|
-
return [4 /*yield*/,
|
|
67
|
+
return [4 /*yield*/, updatePriceFeeds(pythClient, tx, priceFeedUpdateData, _priceIDs, suiCoin)];
|
|
67
68
|
case 2:
|
|
68
69
|
priceInfoObjectIds = _a.sent();
|
|
69
70
|
return [2 /*return*/, priceInfoObjectIds];
|
|
@@ -83,3 +84,30 @@ function updateOracleWithPythUsd(pythClient, tx, oraclePackage, baseToken) {
|
|
|
83
84
|
],
|
|
84
85
|
});
|
|
85
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Adds the necessary commands for updating the pyth price feeds to the transaction block.
|
|
89
|
+
* @param tx transaction block to add commands to
|
|
90
|
+
* @param updates array of price feed updates received from the price service
|
|
91
|
+
* @param feedIds array of feed ids to update (in hex format)
|
|
92
|
+
*/
|
|
93
|
+
function updatePriceFeeds(pythClient, tx, updates, feedIds, suiCoin) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
95
|
+
var packageId, priceUpdatesHotPotato, baseUpdateFee, coins;
|
|
96
|
+
return __generator(this, function (_a) {
|
|
97
|
+
switch (_a.label) {
|
|
98
|
+
case 0: return [4 /*yield*/, pythClient.client.getPythPackageId()];
|
|
99
|
+
case 1:
|
|
100
|
+
packageId = _a.sent();
|
|
101
|
+
return [4 /*yield*/, pythClient.client.verifyVaasAndGetHotPotato(tx, updates, packageId)];
|
|
102
|
+
case 2:
|
|
103
|
+
priceUpdatesHotPotato = _a.sent();
|
|
104
|
+
return [4 /*yield*/, pythClient.client.getBaseUpdateFee()];
|
|
105
|
+
case 3:
|
|
106
|
+
baseUpdateFee = _a.sent();
|
|
107
|
+
coins = tx.splitCoins(suiCoin !== null && suiCoin !== void 0 ? suiCoin : tx.gas, feedIds.map(function () { return tx.pure.u64(baseUpdateFee); }));
|
|
108
|
+
return [4 /*yield*/, pythClient.client.executePriceFeedUpdates(tx, packageId, feedIds, priceUpdatesHotPotato, coins)];
|
|
109
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
@@ -11,5 +11,4 @@ export declare function splitCoins(tx: Transaction, token: string, coins: string
|
|
|
11
11
|
$kind: "NestedResult";
|
|
12
12
|
NestedResult: [number, number];
|
|
13
13
|
};
|
|
14
|
-
export declare function promptYesNo(question: string): Promise<boolean>;
|
|
15
14
|
export declare function getNumberStringWithDecimal(input: string, decimal: number): string;
|
package/dist/src/utils/tools.js
CHANGED
|
@@ -23,11 +23,9 @@ exports.countFloating = exports.checkNumber = exports.insertAt = exports.prettif
|
|
|
23
23
|
exports.U64FromBytes = U64FromBytes;
|
|
24
24
|
exports.AddressFromBytes = AddressFromBytes;
|
|
25
25
|
exports.splitCoins = splitCoins;
|
|
26
|
-
exports.promptYesNo = promptYesNo;
|
|
27
26
|
exports.getNumberStringWithDecimal = getNumberStringWithDecimal;
|
|
28
27
|
var utils_1 = require("@mysten/sui/utils");
|
|
29
28
|
var constants_1 = require("../../src/constants");
|
|
30
|
-
// import * as readline from "readline";
|
|
31
29
|
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
32
30
|
var sleep = function (ms) { return new Promise(function (resolve) { return setTimeout(resolve, ms); }); };
|
|
33
31
|
exports.sleep = sleep;
|
|
@@ -96,24 +94,6 @@ function splitCoins(tx, token, coins, amount, sponsored) {
|
|
|
96
94
|
}
|
|
97
95
|
return coin;
|
|
98
96
|
}
|
|
99
|
-
function promptYesNo(question) {
|
|
100
|
-
// const rl = readline.createInterface({
|
|
101
|
-
// input: process.stdin,
|
|
102
|
-
// output: process.stdout,
|
|
103
|
-
// });
|
|
104
|
-
// return new Promise((resolve) => {
|
|
105
|
-
// rl.question(`${question} [y/N] `, (answer) => {
|
|
106
|
-
// const normalizedAnswer = answer.toLowerCase();
|
|
107
|
-
// if (normalizedAnswer === "y" || normalizedAnswer === "yes") {
|
|
108
|
-
// resolve(true);
|
|
109
|
-
// } else {
|
|
110
|
-
// resolve(false);
|
|
111
|
-
// }
|
|
112
|
-
// rl.close();
|
|
113
|
-
// });
|
|
114
|
-
// });
|
|
115
|
-
return new Promise(function (resolve) { return resolve(true); });
|
|
116
|
-
}
|
|
117
97
|
function getNumberStringWithDecimal(input, decimal) {
|
|
118
98
|
input = input.padStart(decimal, "0");
|
|
119
99
|
var integer = input.slice(0, input.length - decimal).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
package/package.json
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
"name": "@typus/typus-sdk",
|
|
3
3
|
"author": "Typus",
|
|
4
4
|
"description": "typus sdk",
|
|
5
|
-
"version": "1.7.
|
|
5
|
+
"version": "1.7.15",
|
|
6
|
+
"resolutions": {
|
|
7
|
+
"@mysten/sui": "1.30.0"
|
|
8
|
+
},
|
|
6
9
|
"dependencies": {
|
|
7
10
|
"@mysten/bcs": "1.6.1",
|
|
8
11
|
"@mysten/kiosk": "0.12.6",
|
|
9
|
-
"@
|
|
10
|
-
"@pythnetwork/pyth-sui-js": "^2.1.0",
|
|
12
|
+
"@pythnetwork/pyth-sui-js": "^2.2.0",
|
|
11
13
|
"@shinami/clients": "^0.9.6",
|
|
12
14
|
"@typemove/sui": "^1.6.1",
|
|
13
15
|
"@types/node": "^20.5.7",
|