@typus/typus-sdk 1.6.29 → 1.7.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/dist/src/auto-bid/view-function.js +0 -48
- package/dist/src/typus/leaderboard/authority-entry.d.ts +15 -0
- package/dist/src/typus/leaderboard/authority-entry.js +29 -0
- package/dist/src/utils/api/price.d.ts +6 -0
- package/dist/src/utils/api/price.js +67 -0
- package/dist/src/utils/pyth/constant.js +1 -0
- package/package.json +4 -4
|
@@ -71,54 +71,6 @@ var client_1 = require("@mysten/sui/client");
|
|
|
71
71
|
var bcs_1 = require("@mysten/bcs");
|
|
72
72
|
var transactions_1 = require("@mysten/sui/transactions");
|
|
73
73
|
var tools_1 = require("../../src/utils/tools");
|
|
74
|
-
var bcs = new bcs_1.BCS((0, bcs_1.getSuiMoveConfig)());
|
|
75
|
-
bcs.registerStructType("StrategyV2", {
|
|
76
|
-
id: "address",
|
|
77
|
-
vault_index: "u64",
|
|
78
|
-
signal_index: "u64",
|
|
79
|
-
user: "address",
|
|
80
|
-
price_percentage: "u64",
|
|
81
|
-
size: "u64",
|
|
82
|
-
max_times: "u64",
|
|
83
|
-
target_rounds: "vector<u64>",
|
|
84
|
-
receipts: "vector<TypusBidReceipt>",
|
|
85
|
-
active: "bool",
|
|
86
|
-
u64_padding: "vector<u64>",
|
|
87
|
-
bid_times: "u64",
|
|
88
|
-
bid_round: "u64",
|
|
89
|
-
bid_ts_ms: "u64",
|
|
90
|
-
bid_rounds: "vector<u64>",
|
|
91
|
-
accumulated_profit: "u64",
|
|
92
|
-
strategy_index: "u64",
|
|
93
|
-
});
|
|
94
|
-
// struct StrategyV2 has key, store {
|
|
95
|
-
// id: UID,
|
|
96
|
-
// vault_index: u64,
|
|
97
|
-
// signal_index: u64,
|
|
98
|
-
// user: address,
|
|
99
|
-
// // balance: Balance<B_TOKEN>,
|
|
100
|
-
// // profit: Balance<D_TOKEN>,
|
|
101
|
-
// price_percentage: u64,
|
|
102
|
-
// size: u64,
|
|
103
|
-
// max_times: u64,
|
|
104
|
-
// target_rounds: vector<u64>,
|
|
105
|
-
// receipts: vector<TypusBidReceipt>,
|
|
106
|
-
// active: bool,
|
|
107
|
-
// u64_padding: vector<u64>,
|
|
108
|
-
// // log
|
|
109
|
-
// bid_times: u64,
|
|
110
|
-
// bid_round: u64,
|
|
111
|
-
// bid_ts_ms: u64,
|
|
112
|
-
// bid_rounds: vector<u64>,
|
|
113
|
-
// accumulated_profit: u64,
|
|
114
|
-
// }
|
|
115
|
-
bcs.registerStructType("TypusBidReceipt", {
|
|
116
|
-
id: "address",
|
|
117
|
-
vid: "address",
|
|
118
|
-
index: "u64",
|
|
119
|
-
metadata: "String",
|
|
120
|
-
u64_padding: "vector<u64>",
|
|
121
|
-
});
|
|
122
74
|
function getUserStrategies(config, input
|
|
123
75
|
// typeArguments: string[] // [D_TOKEN, B_TOKEN]
|
|
124
76
|
) {
|
|
@@ -28,3 +28,18 @@ export declare function getDeactivateLeaderboardTx(config: TypusConfig, tx: Tran
|
|
|
28
28
|
key: string;
|
|
29
29
|
id: string;
|
|
30
30
|
}): Promise<Transaction>;
|
|
31
|
+
/**
|
|
32
|
+
public fun extend_leaderboard(
|
|
33
|
+
version: &Version,
|
|
34
|
+
registry: &mut TypusLeaderboardRegistry,
|
|
35
|
+
key: String,
|
|
36
|
+
id: address,
|
|
37
|
+
end_ts_ms: u64,
|
|
38
|
+
ctx: &mut TxContext,
|
|
39
|
+
)
|
|
40
|
+
*/
|
|
41
|
+
export declare function getExtendLeaderboardTx(config: TypusConfig, tx: Transaction, input: {
|
|
42
|
+
key: string;
|
|
43
|
+
id: string;
|
|
44
|
+
end_ts_ms: string;
|
|
45
|
+
}): Promise<Transaction>;
|
|
@@ -38,6 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.getActivateLeaderboardTx = getActivateLeaderboardTx;
|
|
40
40
|
exports.getDeactivateLeaderboardTx = getDeactivateLeaderboardTx;
|
|
41
|
+
exports.getExtendLeaderboardTx = getExtendLeaderboardTx;
|
|
41
42
|
/**
|
|
42
43
|
public fun activate_leaderboard(
|
|
43
44
|
version: &Version,
|
|
@@ -92,3 +93,31 @@ function getDeactivateLeaderboardTx(config, tx, input) {
|
|
|
92
93
|
});
|
|
93
94
|
});
|
|
94
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
public fun extend_leaderboard(
|
|
98
|
+
version: &Version,
|
|
99
|
+
registry: &mut TypusLeaderboardRegistry,
|
|
100
|
+
key: String,
|
|
101
|
+
id: address,
|
|
102
|
+
end_ts_ms: u64,
|
|
103
|
+
ctx: &mut TxContext,
|
|
104
|
+
)
|
|
105
|
+
*/
|
|
106
|
+
function getExtendLeaderboardTx(config, tx, input) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
tx.moveCall({
|
|
110
|
+
target: "".concat(config.package.typus, "::leaderboard::extend_leaderboard"),
|
|
111
|
+
typeArguments: [],
|
|
112
|
+
arguments: [
|
|
113
|
+
tx.object(config.version.typus),
|
|
114
|
+
tx.object(config.registry.typus.leaderboard),
|
|
115
|
+
tx.pure.string(input.key),
|
|
116
|
+
tx.pure.address(input.id),
|
|
117
|
+
tx.pure.u64(input.end_ts_ms),
|
|
118
|
+
],
|
|
119
|
+
});
|
|
120
|
+
return [2 /*return*/, tx];
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export declare function getPairPrices(pair: string, startTs: string, endTs: string): Promise<any>;
|
|
2
2
|
export declare function getLatestPrice(pair: string): Promise<string>;
|
|
3
3
|
export declare function getPythLatestPrice(): Promise<Map<string, number> | undefined>;
|
|
4
|
+
/**
|
|
5
|
+
* Fetch latest Pyth prices for the specified symbols.
|
|
6
|
+
* @param symbols Array of token symbols (e.g., ["BTC", "ETH"]) to fetch prices for.
|
|
7
|
+
* @returns Map where keys are token symbols and values are their latest prices.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getPythLatestPriceBySymbols(symbols: string[]): Promise<Map<string, number>>;
|
|
4
10
|
export declare function getLatestPriceUSD(): Promise<Map<string, number>>;
|
|
@@ -35,6 +35,22 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
38
54
|
var __values = (this && this.__values) || function(o) {
|
|
39
55
|
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
56
|
if (m) return m.call(o);
|
|
@@ -50,6 +66,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
50
66
|
exports.getPairPrices = getPairPrices;
|
|
51
67
|
exports.getLatestPrice = getLatestPrice;
|
|
52
68
|
exports.getPythLatestPrice = getPythLatestPrice;
|
|
69
|
+
exports.getPythLatestPriceBySymbols = getPythLatestPriceBySymbols;
|
|
53
70
|
exports.getLatestPriceUSD = getLatestPriceUSD;
|
|
54
71
|
var apiUrl = "https://us-central1-aqueous-freedom-378103.cloudfunctions.net/db-price";
|
|
55
72
|
function getPairPrices(pair, startTs, endTs) {
|
|
@@ -140,6 +157,56 @@ function getPythLatestPrice() {
|
|
|
140
157
|
});
|
|
141
158
|
});
|
|
142
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Fetch latest Pyth prices for the specified symbols.
|
|
162
|
+
* @param symbols Array of token symbols (e.g., ["BTC", "ETH"]) to fetch prices for.
|
|
163
|
+
* @returns Map where keys are token symbols and values are their latest prices.
|
|
164
|
+
*/
|
|
165
|
+
function getPythLatestPriceBySymbols(symbols) {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
167
|
+
var idsParam, apiUrlWithParams, response, map, data;
|
|
168
|
+
return __generator(this, function (_a) {
|
|
169
|
+
switch (_a.label) {
|
|
170
|
+
case 0:
|
|
171
|
+
idsParam = Object.entries(pythId)
|
|
172
|
+
.filter(function (_a) {
|
|
173
|
+
var _b = __read(_a, 2), id = _b[0], token = _b[1];
|
|
174
|
+
return symbols.includes(token);
|
|
175
|
+
})
|
|
176
|
+
.map(function (_a) {
|
|
177
|
+
var _b = __read(_a, 1), id = _b[0];
|
|
178
|
+
return "ids[]=".concat(id);
|
|
179
|
+
})
|
|
180
|
+
.join("&");
|
|
181
|
+
apiUrlWithParams = "https://hermes.pyth.network/api/latest_price_feeds?".concat(idsParam);
|
|
182
|
+
return [4 /*yield*/, fetch(apiUrlWithParams, {
|
|
183
|
+
method: "GET",
|
|
184
|
+
headers: { "Content-Type": "application/json" },
|
|
185
|
+
})];
|
|
186
|
+
case 1:
|
|
187
|
+
response = _a.sent();
|
|
188
|
+
map = new Map();
|
|
189
|
+
if (!response.ok) return [3 /*break*/, 3];
|
|
190
|
+
return [4 /*yield*/, response.json()];
|
|
191
|
+
case 2:
|
|
192
|
+
data = _a.sent();
|
|
193
|
+
data.forEach(function (p) {
|
|
194
|
+
var token = pythId[p.id];
|
|
195
|
+
// Convert price using exponent provided
|
|
196
|
+
var price = p.price.price / Math.pow(10, -p.price.expo);
|
|
197
|
+
if (symbols.includes(token)) {
|
|
198
|
+
map.set(token, price);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
return [3 /*break*/, 4];
|
|
202
|
+
case 3:
|
|
203
|
+
console.error("Failed to fetch Pyth prices: ".concat(response.status));
|
|
204
|
+
_a.label = 4;
|
|
205
|
+
case 4: return [2 /*return*/, map];
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
}
|
|
143
210
|
function getLatestPriceUSD() {
|
|
144
211
|
return __awaiter(this, void 0, void 0, function () {
|
|
145
212
|
var prices, _a, _b, pair, currentTimestampInSeconds, minuteAgo, res, price, result, e_2_1;
|
|
@@ -100,6 +100,7 @@ exports.priceInfoObjectIds = {
|
|
|
100
100
|
JUP: "0xb804ada6f77feb30a73fbed7fc53dc66ff25133dee0815109d4267e43b2e6bdd",
|
|
101
101
|
WAL: "0xeb7e669f74d976c0b99b6ef9801e3a77716a95f1a15754e0f1399ce3fb60973d",
|
|
102
102
|
LBTC: "0xeba15840ddf425dacb5ff0990334fc03d034487f4ad416280859b96bf2af89f8",
|
|
103
|
+
XAU: "0x5b36eb3c0935908082926c0c767a55b87a2a4eb3a45908785b41f9d5a11e4f7b",
|
|
103
104
|
},
|
|
104
105
|
TESTNET: {
|
|
105
106
|
SUI: "0x1ebb295c789cc42b3b2a1606482cd1c7124076a0f5676718501fda8c7fd075a0",
|
package/package.json
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"name": "@typus/typus-sdk",
|
|
3
3
|
"author": "Typus",
|
|
4
4
|
"description": "typus sdk",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.7.0",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@mysten/bcs": "
|
|
8
|
-
"@mysten/kiosk": "0.
|
|
9
|
-
"@mysten/sui": "1.
|
|
7
|
+
"@mysten/bcs": "1.6.1",
|
|
8
|
+
"@mysten/kiosk": "0.12.6",
|
|
9
|
+
"@mysten/sui": "1.30.0",
|
|
10
10
|
"@pythnetwork/client": "^2.21.0",
|
|
11
11
|
"@pythnetwork/pyth-sui-js": "^2.1.0",
|
|
12
12
|
"@typemove/sui": "^1.6.1",
|