@typus/typus-perp-sdk 1.1.32-codegen-exp16 → 1.1.32-codegen-exp18
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/api/sentio.js +12 -12
- package/dist/src/fetch.d.ts +39 -0
- package/dist/src/fetch.js +182 -2
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +7 -1
- package/dist/src/user/history.js +1 -1
- package/dist/src/user/order.d.ts +2 -0
- package/dist/src/user/order.js +28 -22
- package/package.json +2 -2
package/dist/src/api/sentio.js
CHANGED
|
@@ -13,11 +13,11 @@ exports.getUserPnlFromSentio = getUserPnlFromSentio;
|
|
|
13
13
|
exports.getLeaderboardFromSentio = getLeaderboardFromSentio;
|
|
14
14
|
const src_1 = require("../../src");
|
|
15
15
|
const headers = {
|
|
16
|
-
"api-key": "
|
|
16
|
+
"api-key": "hCsD8shJaUbbiNLMKBG3oKhr9PL3H5EJ5",
|
|
17
17
|
"Content-Type": "application/json",
|
|
18
18
|
};
|
|
19
19
|
async function getFromSentio(event, userAddress, startTimestamp, cranker) {
|
|
20
|
-
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/
|
|
20
|
+
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp/sql/execute";
|
|
21
21
|
// add cranker fileter
|
|
22
22
|
let crankerFilter = "";
|
|
23
23
|
if (cranker) {
|
|
@@ -50,7 +50,7 @@ async function getFromSentio(event, userAddress, startTimestamp, cranker) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
async function getRecentTradesFromSentio(base_token) {
|
|
53
|
-
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/
|
|
53
|
+
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp/sql/execute";
|
|
54
54
|
let tokenFilter = "";
|
|
55
55
|
if (base_token) {
|
|
56
56
|
tokenFilter = `WHERE base_token = '${(0, src_1.toSentioToken)(base_token)}'`;
|
|
@@ -142,7 +142,7 @@ async function getRecentTradesFromSentio(base_token) {
|
|
|
142
142
|
* value: Volume[]
|
|
143
143
|
*/
|
|
144
144
|
async function getTradingVolumeFromSentio(fromTimestamp, interval, toTimestamp) {
|
|
145
|
-
let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/
|
|
145
|
+
let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp/query";
|
|
146
146
|
let requestData = {
|
|
147
147
|
timeRange: {
|
|
148
148
|
start: `${fromTimestamp}`,
|
|
@@ -206,7 +206,7 @@ async function getTradingVolumeFromSentio(fromTimestamp, interval, toTimestamp)
|
|
|
206
206
|
return map;
|
|
207
207
|
}
|
|
208
208
|
async function getMinuteTradingVolumeFromSentio(base_token, minute, size) {
|
|
209
|
-
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/
|
|
209
|
+
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp/sql/execute";
|
|
210
210
|
let requestData = {
|
|
211
211
|
sqlQuery: {
|
|
212
212
|
sql: `
|
|
@@ -243,7 +243,7 @@ function parseTimestamp(s) {
|
|
|
243
243
|
return Math.round(Date.parse(s) / 1000);
|
|
244
244
|
}
|
|
245
245
|
async function getTlpFeeFromSentio(fromTimestamp, toTimestamp) {
|
|
246
|
-
let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/
|
|
246
|
+
let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp/query";
|
|
247
247
|
let requestData = {
|
|
248
248
|
timeRange: {
|
|
249
249
|
start: `${fromTimestamp ?? 0}`,
|
|
@@ -290,7 +290,7 @@ async function getTlpFeeFromSentio(fromTimestamp, toTimestamp) {
|
|
|
290
290
|
return fee;
|
|
291
291
|
}
|
|
292
292
|
async function getTotalVolumeFromSentio(fromTimestamp, toTimestamp) {
|
|
293
|
-
let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/
|
|
293
|
+
let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp/query";
|
|
294
294
|
let requestData = {
|
|
295
295
|
timeRange: {
|
|
296
296
|
start: `${fromTimestamp ?? 0}`,
|
|
@@ -335,7 +335,7 @@ async function getTotalVolumeFromSentio(fromTimestamp, toTimestamp) {
|
|
|
335
335
|
}
|
|
336
336
|
/** Returns Accumulated Users */
|
|
337
337
|
async function getAccumulatedUser() {
|
|
338
|
-
let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/
|
|
338
|
+
let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp/query";
|
|
339
339
|
let requestData = {
|
|
340
340
|
timeRange: {
|
|
341
341
|
start: "now-1h",
|
|
@@ -392,7 +392,7 @@ async function getAccumulatedUser() {
|
|
|
392
392
|
* { timestamp: string, value: number }[]
|
|
393
393
|
*/
|
|
394
394
|
async function getTlpPriceFromSentio(fromTimestamp, toTimestamp) {
|
|
395
|
-
let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/
|
|
395
|
+
let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp/query";
|
|
396
396
|
let requestData = {
|
|
397
397
|
timeRange: {
|
|
398
398
|
start: `${fromTimestamp ?? 0}`,
|
|
@@ -431,7 +431,7 @@ async function getTlpPriceFromSentio(fromTimestamp, toTimestamp) {
|
|
|
431
431
|
return samples[0].values;
|
|
432
432
|
}
|
|
433
433
|
async function getTlpComparisonFromSentio(startTimestamp, endTimestamp) {
|
|
434
|
-
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/
|
|
434
|
+
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp/sql/execute";
|
|
435
435
|
let requestData = {
|
|
436
436
|
sqlQuery: {
|
|
437
437
|
sql: `
|
|
@@ -507,7 +507,7 @@ async function getTlpComparisonFromSentio(startTimestamp, endTimestamp) {
|
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
509
|
async function getUserPnlFromSentio(startTimestamp, endTimestamp, userAddress) {
|
|
510
|
-
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/
|
|
510
|
+
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp/sql/execute";
|
|
511
511
|
let userFilter = "";
|
|
512
512
|
if (userAddress) {
|
|
513
513
|
userFilter = `AND address == '${userAddress}'`;
|
|
@@ -592,7 +592,7 @@ async function getUserPnlFromSentio(startTimestamp, endTimestamp, userAddress) {
|
|
|
592
592
|
}
|
|
593
593
|
}
|
|
594
594
|
async function getLeaderboardFromSentio(startTs, endTs) {
|
|
595
|
-
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/
|
|
595
|
+
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp/sql/execute";
|
|
596
596
|
let size = (10 * (endTs - startTs)) / 60 / 60 / 24; // day * 10
|
|
597
597
|
let requestData = {
|
|
598
598
|
sqlQuery: {
|
package/dist/src/fetch.d.ts
CHANGED
|
@@ -423,6 +423,7 @@ export declare function getDeactivatingShares(client: TypusClient, input: {
|
|
|
423
423
|
* @returns [liquidationPrice, pnl(in USD)]
|
|
424
424
|
*/
|
|
425
425
|
export declare function getLiquidationPriceAndPnl(client: TypusClient, input: {
|
|
426
|
+
oracle?: string;
|
|
426
427
|
positions: (typeof Position.$inferType)[];
|
|
427
428
|
}): Promise<PositionInfo[]>;
|
|
428
429
|
interface PositionInfo {
|
|
@@ -534,4 +535,42 @@ export declare function getAllPositionsWithTradingSymbol(client: TypusClient, in
|
|
|
534
535
|
} | null;
|
|
535
536
|
u64_padding: string[];
|
|
536
537
|
}[]>;
|
|
538
|
+
export type UserProfit = {
|
|
539
|
+
collateral_token: {
|
|
540
|
+
name: string;
|
|
541
|
+
};
|
|
542
|
+
base_token: {
|
|
543
|
+
name: string;
|
|
544
|
+
};
|
|
545
|
+
position_id: string;
|
|
546
|
+
order_id: string;
|
|
547
|
+
amount: string;
|
|
548
|
+
create_ts_ms: string;
|
|
549
|
+
};
|
|
550
|
+
export type LockedUserProfit = {
|
|
551
|
+
user_profit: UserProfit;
|
|
552
|
+
create_ts_ms: string;
|
|
553
|
+
};
|
|
554
|
+
export declare function fetchUserProfits(client: TypusClient, input: {
|
|
555
|
+
profitVault: string;
|
|
556
|
+
version: string;
|
|
557
|
+
user: string;
|
|
558
|
+
}): Promise<UserProfit[]>;
|
|
559
|
+
export declare function fetchLockedUserProfits(client: TypusClient, input: {
|
|
560
|
+
lockVault: string;
|
|
561
|
+
version: string;
|
|
562
|
+
user: string;
|
|
563
|
+
}): Promise<LockedUserProfit[]>;
|
|
564
|
+
export declare function fetchAllUserProfits(client: TypusClient, input?: {
|
|
565
|
+
profitVault?: string;
|
|
566
|
+
}): Promise<{
|
|
567
|
+
user: string;
|
|
568
|
+
profits: UserProfit[];
|
|
569
|
+
}[]>;
|
|
570
|
+
export declare function fetchAllLockedUserProfits(client: TypusClient, input?: {
|
|
571
|
+
lockVault?: string;
|
|
572
|
+
}): Promise<{
|
|
573
|
+
user: string;
|
|
574
|
+
lockedUserProfits: LockedUserProfit[];
|
|
575
|
+
}[]>;
|
|
537
576
|
export {};
|
package/dist/src/fetch.js
CHANGED
|
@@ -13,10 +13,16 @@ exports.getDeactivatingShares = getDeactivatingShares;
|
|
|
13
13
|
exports.getLiquidationPriceAndPnl = getLiquidationPriceAndPnl;
|
|
14
14
|
exports.getAllPositions = getAllPositions;
|
|
15
15
|
exports.getAllPositionsWithTradingSymbol = getAllPositionsWithTradingSymbol;
|
|
16
|
+
exports.fetchUserProfits = fetchUserProfits;
|
|
17
|
+
exports.fetchLockedUserProfits = fetchLockedUserProfits;
|
|
18
|
+
exports.fetchAllUserProfits = fetchAllUserProfits;
|
|
19
|
+
exports.fetchAllLockedUserProfits = fetchAllLockedUserProfits;
|
|
16
20
|
const transactions_1 = require("@mysten/sui/transactions");
|
|
21
|
+
const client_1 = require("@mysten/sui/client");
|
|
17
22
|
const bcs_1 = require("@mysten/bcs");
|
|
18
23
|
const constants_1 = require("@typus/typus-sdk/dist/src/constants");
|
|
19
24
|
const utils_1 = require("@typus/typus-sdk/dist/src/utils");
|
|
25
|
+
const utils_2 = require("@typus/typus-sdk/dist/src/utils");
|
|
20
26
|
const _1 = require(".");
|
|
21
27
|
const trading_1 = require("./generated/typus_perp/trading");
|
|
22
28
|
const lp_pool_1 = require("./generated/typus_perp/lp_pool");
|
|
@@ -294,10 +300,16 @@ async function getLiquidationPriceAndPnl(client, input) {
|
|
|
294
300
|
tokens.push(TOKEN);
|
|
295
301
|
tokens.push(BASE_TOKEN);
|
|
296
302
|
}
|
|
297
|
-
|
|
298
|
-
|
|
303
|
+
const tokensWithoutTypus = tokens.filter((token) => token !== "TYPUS");
|
|
304
|
+
await (0, utils_1.updatePyth)(client.pythClient, tx, Array.from(new Set(tokensWithoutTypus)));
|
|
305
|
+
for (let token of Array.from(new Set(tokensWithoutTypus))) {
|
|
299
306
|
(0, utils_1.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
|
|
300
307
|
}
|
|
308
|
+
if (tokens.includes("TYPUS")) {
|
|
309
|
+
// TODO: update oracle contract
|
|
310
|
+
const oracleContract = input.oracle ?? "0x51fc5517f5ba4e3ba8862cd74c345e7294193c693ab41376694d1c516033e2e8";
|
|
311
|
+
tx = await (0, utils_2.updateOracleWithSignatureTx)(_1.NETWORK, tx, oracleContract, constants_1.tokenType[_1.NETWORK]["TYPUS"]);
|
|
312
|
+
}
|
|
301
313
|
for (let position of input.positions) {
|
|
302
314
|
// parse from Position
|
|
303
315
|
let TOKEN = (0, constants_1.typeArgToAsset)(position.collateral_token.name);
|
|
@@ -421,3 +433,171 @@ async function getAllPositionsWithTradingSymbol(client, input) {
|
|
|
421
433
|
}
|
|
422
434
|
return positions;
|
|
423
435
|
}
|
|
436
|
+
const TypeNameBcs = bcs_1.bcs.struct("TypeName", {
|
|
437
|
+
name: bcs_1.bcs.string(),
|
|
438
|
+
});
|
|
439
|
+
const UserProfitBcs = bcs_1.bcs.struct("UserProfit", {
|
|
440
|
+
collateral_token: TypeNameBcs,
|
|
441
|
+
base_token: TypeNameBcs,
|
|
442
|
+
position_id: bcs_1.bcs.u64(),
|
|
443
|
+
order_id: bcs_1.bcs.u64(),
|
|
444
|
+
amount: bcs_1.bcs.u64(),
|
|
445
|
+
create_ts_ms: bcs_1.bcs.u64(),
|
|
446
|
+
});
|
|
447
|
+
const LockedUserProfitBcs = bcs_1.bcs.struct("LockedUserProfit", {
|
|
448
|
+
user_profit: UserProfitBcs,
|
|
449
|
+
create_ts_ms: bcs_1.bcs.u64(),
|
|
450
|
+
});
|
|
451
|
+
async function fetchUserProfits(client, input) {
|
|
452
|
+
let tx = new transactions_1.Transaction();
|
|
453
|
+
tx.moveCall({
|
|
454
|
+
target: `${_1.PERP_PACKAGE_ID}::profit_vault::get_user_profits`,
|
|
455
|
+
arguments: [tx.object(input.version), tx.object(input.profitVault), tx.pure.address(input.user)],
|
|
456
|
+
});
|
|
457
|
+
const res = await client.devInspectTransactionBlock({
|
|
458
|
+
sender: constants_1.SENDER,
|
|
459
|
+
transactionBlock: tx,
|
|
460
|
+
});
|
|
461
|
+
if (!res.results?.[0]?.returnValues?.[0]?.[0]) {
|
|
462
|
+
return [];
|
|
463
|
+
}
|
|
464
|
+
const returnValues = res.results[0].returnValues[0][0];
|
|
465
|
+
const reader = new bcs_1.BcsReader(new Uint8Array(returnValues));
|
|
466
|
+
const profits = [];
|
|
467
|
+
reader.readVec((reader) => {
|
|
468
|
+
const length = reader.readULEB();
|
|
469
|
+
const bytes = reader.readBytes(length);
|
|
470
|
+
const profit = UserProfitBcs.parse(Uint8Array.from(Array.from(bytes)));
|
|
471
|
+
profits.push(profit);
|
|
472
|
+
});
|
|
473
|
+
return profits;
|
|
474
|
+
}
|
|
475
|
+
async function fetchLockedUserProfits(client, input) {
|
|
476
|
+
let tx = new transactions_1.Transaction();
|
|
477
|
+
tx.moveCall({
|
|
478
|
+
target: `${_1.PERP_PACKAGE_ID}::profit_vault::get_locked_user_profits`,
|
|
479
|
+
arguments: [tx.object(_1.PERP_VERSION), tx.object(input.lockVault), tx.pure.address(input.user)],
|
|
480
|
+
});
|
|
481
|
+
const res = await client.devInspectTransactionBlock({
|
|
482
|
+
sender: constants_1.SENDER,
|
|
483
|
+
transactionBlock: tx,
|
|
484
|
+
});
|
|
485
|
+
if (!res.results?.[0]?.returnValues?.[0]?.[0]) {
|
|
486
|
+
return [];
|
|
487
|
+
}
|
|
488
|
+
const returnValues = res.results[0].returnValues[0][0];
|
|
489
|
+
const reader = new bcs_1.BcsReader(new Uint8Array(returnValues));
|
|
490
|
+
const lockedUserProfits = [];
|
|
491
|
+
reader.readVec((reader) => {
|
|
492
|
+
const length = reader.readULEB();
|
|
493
|
+
const bytes = reader.readBytes(length);
|
|
494
|
+
const profit = LockedUserProfitBcs.parse(Uint8Array.from(Array.from(bytes)));
|
|
495
|
+
lockedUserProfits.push(profit);
|
|
496
|
+
});
|
|
497
|
+
return lockedUserProfits;
|
|
498
|
+
}
|
|
499
|
+
async function fetchAllUserProfits(client, input) {
|
|
500
|
+
const provider = new client_1.SuiClient({ url: client.config.rpcEndpoint });
|
|
501
|
+
const profitVaultId = input?.profitVault ?? _1.PROFIT_VAULT;
|
|
502
|
+
// 1. Read ProfitVault object to get user_profits Table ID
|
|
503
|
+
const vaultResponse = await provider.getObject({
|
|
504
|
+
id: profitVaultId,
|
|
505
|
+
options: { showContent: true },
|
|
506
|
+
});
|
|
507
|
+
if (!vaultResponse.data?.content || vaultResponse.data.content.dataType !== "moveObject") {
|
|
508
|
+
return [];
|
|
509
|
+
}
|
|
510
|
+
const fields = vaultResponse.data.content.fields;
|
|
511
|
+
const tableId = fields?.user_profits?.fields?.id?.id;
|
|
512
|
+
if (!tableId) {
|
|
513
|
+
return [];
|
|
514
|
+
}
|
|
515
|
+
// 2. Get all dynamic fields (user addresses) from the Table
|
|
516
|
+
let cursor = null;
|
|
517
|
+
const allUsers = [];
|
|
518
|
+
while (true) {
|
|
519
|
+
const dynamicFields = await provider.getDynamicFields({
|
|
520
|
+
parentId: tableId,
|
|
521
|
+
cursor,
|
|
522
|
+
limit: 50,
|
|
523
|
+
});
|
|
524
|
+
for (const field of dynamicFields.data) {
|
|
525
|
+
const userAddress = field.name.value;
|
|
526
|
+
if (userAddress) {
|
|
527
|
+
allUsers.push(userAddress);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (!dynamicFields.hasNextPage) {
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
cursor = dynamicFields.nextCursor ?? null;
|
|
534
|
+
}
|
|
535
|
+
// 3. For each user, fetch their profits
|
|
536
|
+
const fetchUserProfitsPromises = [];
|
|
537
|
+
for (const user of allUsers) {
|
|
538
|
+
try {
|
|
539
|
+
const fetchUserProfitsWithUser = async () => {
|
|
540
|
+
const profits = await fetchUserProfits(client, { profitVault: profitVaultId, version: _1.PERP_VERSION, user });
|
|
541
|
+
return { user, profits };
|
|
542
|
+
};
|
|
543
|
+
fetchUserProfitsPromises.push(fetchUserProfitsWithUser());
|
|
544
|
+
}
|
|
545
|
+
catch (e) {
|
|
546
|
+
console.error(`Failed to get profits for user ${user}:`, e);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
const results = await Promise.all(fetchUserProfitsPromises);
|
|
550
|
+
return results;
|
|
551
|
+
}
|
|
552
|
+
async function fetchAllLockedUserProfits(client, input) {
|
|
553
|
+
const provider = new client_1.SuiClient({ url: client.config.rpcEndpoint });
|
|
554
|
+
// 1. Read LockVault object to get locked_user_profits Table ID
|
|
555
|
+
const vaultResponse = await provider.getObject({
|
|
556
|
+
id: input?.lockVault ?? _1.LOCK_VAULT,
|
|
557
|
+
options: { showContent: true },
|
|
558
|
+
});
|
|
559
|
+
if (!vaultResponse.data?.content || vaultResponse.data.content.dataType !== "moveObject") {
|
|
560
|
+
return [];
|
|
561
|
+
}
|
|
562
|
+
const fields = vaultResponse.data.content.fields;
|
|
563
|
+
const tableId = fields?.locked_user_profits?.fields?.id?.id;
|
|
564
|
+
if (!tableId) {
|
|
565
|
+
return [];
|
|
566
|
+
}
|
|
567
|
+
// 2. Get all dynamic fields (user addresses) from the Table
|
|
568
|
+
let cursor = null;
|
|
569
|
+
const allUsers = [];
|
|
570
|
+
while (true) {
|
|
571
|
+
const dynamicFields = await provider.getDynamicFields({
|
|
572
|
+
parentId: tableId,
|
|
573
|
+
cursor,
|
|
574
|
+
limit: 50,
|
|
575
|
+
});
|
|
576
|
+
for (const field of dynamicFields.data) {
|
|
577
|
+
const userAddress = field.name.value;
|
|
578
|
+
if (userAddress) {
|
|
579
|
+
allUsers.push(userAddress);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (!dynamicFields.hasNextPage) {
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
cursor = dynamicFields.nextCursor ?? null;
|
|
586
|
+
}
|
|
587
|
+
// 3. For each user, fetch their locked profits
|
|
588
|
+
const fetchLockedUserProfitsPromises = [];
|
|
589
|
+
for (const user of allUsers) {
|
|
590
|
+
try {
|
|
591
|
+
const fetchLockedUserProfitsWithUser = async () => {
|
|
592
|
+
const lockedUserProfits = await fetchLockedUserProfits(client, { lockVault: _1.LOCK_VAULT, version: _1.PERP_VERSION, user });
|
|
593
|
+
return { user, lockedUserProfits };
|
|
594
|
+
};
|
|
595
|
+
fetchLockedUserProfitsPromises.push(fetchLockedUserProfitsWithUser());
|
|
596
|
+
}
|
|
597
|
+
catch (e) {
|
|
598
|
+
console.error(`Failed to get locked profits for user ${user}:`, e);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
const results = await Promise.all(fetchLockedUserProfitsPromises);
|
|
602
|
+
return results;
|
|
603
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -11,3 +11,5 @@ export declare const TLP_TREASURY_CAP: string;
|
|
|
11
11
|
export declare const STAKE_POOL: string;
|
|
12
12
|
export declare const STAKE_POOL_VERSION: string;
|
|
13
13
|
export declare const COMPETITION_CONFIG: string;
|
|
14
|
+
export declare const PROFIT_VAULT: string;
|
|
15
|
+
export declare const LOCK_VAULT: string;
|
package/dist/src/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.COMPETITION_CONFIG = exports.STAKE_POOL_VERSION = exports.STAKE_POOL = exports.TLP_TREASURY_CAP = exports.PERP_VERSION = exports.MARKET = exports.LIQUIDITY_POOL = exports.LP_POOL = exports.STAKE_PACKAGE_ID = exports.PERP_PACKAGE_ID = exports.NETWORK = void 0;
|
|
20
|
+
exports.LOCK_VAULT = exports.PROFIT_VAULT = exports.COMPETITION_CONFIG = exports.STAKE_POOL_VERSION = exports.STAKE_POOL = exports.TLP_TREASURY_CAP = exports.PERP_VERSION = exports.MARKET = exports.LIQUIDITY_POOL = exports.LP_POOL = exports.STAKE_PACKAGE_ID = exports.PERP_PACKAGE_ID = exports.NETWORK = void 0;
|
|
21
21
|
__exportStar(require("./fetch"), exports);
|
|
22
22
|
__exportStar(require("./user"), exports);
|
|
23
23
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
@@ -59,3 +59,9 @@ exports.STAKE_POOL_VERSION = exports.NETWORK == "MAINNET"
|
|
|
59
59
|
exports.COMPETITION_CONFIG = exports.NETWORK == "MAINNET"
|
|
60
60
|
? "0xf7fcb3dbabe52c0a7e3fe01e28bb0f7045e2e45463f62bfa739e8c14a911f4be"
|
|
61
61
|
: "0x2b811b120177839555aabdc2c28b28078170e663e855d29aa9072013d4fc918d";
|
|
62
|
+
exports.PROFIT_VAULT = exports.NETWORK == "MAINNET"
|
|
63
|
+
? "" // TODO: Add mainnet PROFIT_VAULT address
|
|
64
|
+
: "0xb1d603139b24db2c46f6a423c8613ce677f329a0b159ff6e57672f3b663aec47"; // TODO: Add testnet PROFIT_VAULT address
|
|
65
|
+
exports.LOCK_VAULT = exports.NETWORK == "MAINNET"
|
|
66
|
+
? "" // TODO: Add mainnet LOCK_VAULT address
|
|
67
|
+
: "0x25dd9540f031b9a62b83784a727e1ef410f9aa91ecf7e3bb27a0c61f8ceecbfb"; // TODO: Add testnet LOCK_VAULT address
|
package/dist/src/user/history.js
CHANGED
|
@@ -356,7 +356,7 @@ async function getGraphQLEvents(module, sender, beforeCursor = null) {
|
|
|
356
356
|
}}
|
|
357
357
|
`,
|
|
358
358
|
});
|
|
359
|
-
let response = await fetch(`https://
|
|
359
|
+
let response = await fetch(`https://graphql.${src_1.NETWORK.toLowerCase()}.sui.io/graphql`, {
|
|
360
360
|
method: "POST",
|
|
361
361
|
headers: { "Content-Type": "application/json" },
|
|
362
362
|
body: graphql,
|
package/dist/src/user/order.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare function findMarketIndex(client: TypusClient, input: {
|
|
|
9
9
|
}): number | undefined;
|
|
10
10
|
export declare function createTradingOrder(client: TypusClient, tx: Transaction, input: {
|
|
11
11
|
perpIndex: string;
|
|
12
|
+
poolIndex: string;
|
|
12
13
|
coins: string[];
|
|
13
14
|
cToken: TOKEN;
|
|
14
15
|
amount: string;
|
|
@@ -19,6 +20,7 @@ export declare function createTradingOrder(client: TypusClient, tx: Transaction,
|
|
|
19
20
|
isStopOrder: boolean;
|
|
20
21
|
reduceOnly: boolean;
|
|
21
22
|
linkedPositionId: string | null;
|
|
23
|
+
oracleContract?: string;
|
|
22
24
|
suiCoins?: string[];
|
|
23
25
|
}): Promise<Transaction>;
|
|
24
26
|
export declare function zeroCoin(tx: Transaction, typeArgs: [string]): import("@mysten/sui/transactions").TransactionResult;
|
package/dist/src/user/order.js
CHANGED
|
@@ -10,13 +10,14 @@ exports.collectPositionFundingFee = collectPositionFundingFee;
|
|
|
10
10
|
const trading_1 = require("../../src/generated/typus_perp/trading");
|
|
11
11
|
const __1 = require("..");
|
|
12
12
|
const utils_1 = require("@typus/typus-sdk/dist/src/utils");
|
|
13
|
+
const utils_2 = require("@typus/typus-sdk/dist/src/utils");
|
|
13
14
|
const constants_1 = require("@typus/typus-sdk/dist/src/constants");
|
|
14
|
-
const
|
|
15
|
+
const utils_3 = require("@mysten/sui/utils");
|
|
15
16
|
function findMarketIndex(client, input) {
|
|
16
17
|
let target = constants_1.tokenType[client.config.network][input.tradingToken];
|
|
17
18
|
for (let i = 0; i < input.markets.length; i++) {
|
|
18
19
|
for (let symbol of input.markets[i].symbols) {
|
|
19
|
-
if ((0,
|
|
20
|
+
if ((0, utils_3.normalizeStructTag)(symbol.name) == target) {
|
|
20
21
|
return i;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -33,19 +34,24 @@ async function createTradingOrder(client, tx, input) {
|
|
|
33
34
|
let suiCoin;
|
|
34
35
|
if (TOKEN == "SUI" && client.config.sponsored) {
|
|
35
36
|
// split together
|
|
36
|
-
[coin, suiCoin] = (0,
|
|
37
|
+
[coin, suiCoin] = (0, utils_2.splitCoins)(tx, constants_1.tokenType.MAINNET.SUI, input.coins, [input.amount, tokens.length.toString()], client.config.sponsored);
|
|
37
38
|
}
|
|
38
39
|
else if (client.config.sponsored) {
|
|
39
|
-
coin = (0,
|
|
40
|
-
suiCoin = (0,
|
|
40
|
+
coin = (0, utils_2.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
|
|
41
|
+
suiCoin = (0, utils_2.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
|
|
41
42
|
}
|
|
42
43
|
else {
|
|
43
|
-
coin = (0,
|
|
44
|
+
coin = (0, utils_2.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
|
|
44
45
|
// no suiCoin
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const tokensWithoutTypus = Array.from(new Set([TOKEN, BASE_TOKEN])).filter((token) => token !== "TYPUS");
|
|
48
|
+
await (0, utils_2.updatePyth)(client.pythClient, tx, tokensWithoutTypus, suiCoin);
|
|
49
|
+
for (let token of tokensWithoutTypus) {
|
|
50
|
+
(0, utils_2.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
|
|
51
|
+
}
|
|
52
|
+
if (tokens.includes("TYPUS")) {
|
|
53
|
+
const oracleContract = input.oracleContract ?? "0x51fc5517f5ba4e3ba8862cd74c345e7294193c693ab41376694d1c516033e2e8";
|
|
54
|
+
tx = await (0, utils_1.updateOracleWithSignatureTx)(__1.NETWORK, tx, oracleContract, constants_1.tokenType[__1.NETWORK]["TYPUS"]);
|
|
49
55
|
}
|
|
50
56
|
tx.add((0, trading_1.createTradingOrder)({
|
|
51
57
|
arguments: {
|
|
@@ -53,7 +59,7 @@ async function createTradingOrder(client, tx, input) {
|
|
|
53
59
|
registry: __1.MARKET,
|
|
54
60
|
poolRegistry: __1.LP_POOL,
|
|
55
61
|
marketIndex: BigInt(input.perpIndex),
|
|
56
|
-
poolIndex: BigInt(input.
|
|
62
|
+
poolIndex: BigInt(input.poolIndex),
|
|
57
63
|
typusOracleCToken: constants_1.oracle[__1.NETWORK][TOKEN],
|
|
58
64
|
typusOracleTradingSymbol: constants_1.oracle[__1.NETWORK][BASE_TOKEN],
|
|
59
65
|
collateral: coin,
|
|
@@ -104,19 +110,19 @@ async function increaseCollateral(client, tx, input) {
|
|
|
104
110
|
let suiCoin;
|
|
105
111
|
if (TOKEN == "SUI" && client.config.sponsored) {
|
|
106
112
|
// split together
|
|
107
|
-
[coin, suiCoin] = (0,
|
|
113
|
+
[coin, suiCoin] = (0, utils_2.splitCoins)(tx, constants_1.tokenType.MAINNET.SUI, input.coins, [input.amount, tokens.length.toString()], client.config.sponsored);
|
|
108
114
|
}
|
|
109
115
|
else if (client.config.sponsored) {
|
|
110
|
-
coin = (0,
|
|
111
|
-
suiCoin = (0,
|
|
116
|
+
coin = (0, utils_2.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
|
|
117
|
+
suiCoin = (0, utils_2.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
|
|
112
118
|
}
|
|
113
119
|
else {
|
|
114
|
-
coin = (0,
|
|
120
|
+
coin = (0, utils_2.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
|
|
115
121
|
// no suiCoin
|
|
116
122
|
}
|
|
117
|
-
await (0,
|
|
123
|
+
await (0, utils_2.updatePyth)(client.pythClient, tx, tokens, suiCoin);
|
|
118
124
|
for (let token of tokens) {
|
|
119
|
-
(0,
|
|
125
|
+
(0, utils_2.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
|
|
120
126
|
}
|
|
121
127
|
// @ts-ignore
|
|
122
128
|
let marketIndex = BigInt(input.position.marketIndex);
|
|
@@ -143,11 +149,11 @@ async function releaseCollateral(client, tx, input) {
|
|
|
143
149
|
let tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
|
|
144
150
|
let suiCoin;
|
|
145
151
|
if (client.config.sponsored) {
|
|
146
|
-
suiCoin = (0,
|
|
152
|
+
suiCoin = (0, utils_2.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
|
|
147
153
|
}
|
|
148
|
-
await (0,
|
|
154
|
+
await (0, utils_2.updatePyth)(client.pythClient, tx, tokens, suiCoin);
|
|
149
155
|
for (let token of tokens) {
|
|
150
|
-
(0,
|
|
156
|
+
(0, utils_2.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
|
|
151
157
|
}
|
|
152
158
|
let cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
153
159
|
let baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
|
@@ -177,11 +183,11 @@ async function collectPositionFundingFee(client, tx, input) {
|
|
|
177
183
|
let tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
|
|
178
184
|
let suiCoin;
|
|
179
185
|
if (client.config.sponsored) {
|
|
180
|
-
suiCoin = (0,
|
|
186
|
+
suiCoin = (0, utils_2.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
|
|
181
187
|
}
|
|
182
|
-
await (0,
|
|
188
|
+
await (0, utils_2.updatePyth)(client.pythClient, tx, tokens, suiCoin);
|
|
183
189
|
for (let token of tokens) {
|
|
184
|
-
(0,
|
|
190
|
+
(0, utils_2.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
|
|
185
191
|
}
|
|
186
192
|
let cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
187
193
|
let baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typus/typus-perp-sdk",
|
|
3
|
-
"version": "1.1.32-codegen-
|
|
3
|
+
"version": "1.1.32-codegen-exp18",
|
|
4
4
|
"repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
|
|
5
5
|
"author": "Typus",
|
|
6
6
|
"description": "typus perp sdk",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@mysten/bcs": "1.9.2",
|
|
10
10
|
"@mysten/sui": "1.44.0",
|
|
11
|
-
"@typus/typus-sdk": "1.8.
|
|
11
|
+
"@typus/typus-sdk": "1.8.31"
|
|
12
12
|
},
|
|
13
13
|
"resolutions": {
|
|
14
14
|
"@mysten/bcs": "1.9.2",
|