@typus/typus-perp-sdk 1.1.32-codegen-exp12 → 1.1.32-codegen-exp13-profit-vault
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/fetch.d.ts +38 -0
- package/dist/src/fetch.js +181 -10
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +8 -2
- package/package.json +2 -2
package/dist/src/fetch.d.ts
CHANGED
|
@@ -534,4 +534,42 @@ export declare function getAllPositionsWithTradingSymbol(client: TypusClient, in
|
|
|
534
534
|
} | null;
|
|
535
535
|
u64_padding: string[];
|
|
536
536
|
}[]>;
|
|
537
|
+
export type UserProfit = {
|
|
538
|
+
collateral_token: {
|
|
539
|
+
name: string;
|
|
540
|
+
};
|
|
541
|
+
base_token: {
|
|
542
|
+
name: string;
|
|
543
|
+
};
|
|
544
|
+
position_id: string;
|
|
545
|
+
order_id: string;
|
|
546
|
+
amount: string;
|
|
547
|
+
create_ts_ms: string;
|
|
548
|
+
};
|
|
549
|
+
export type LockedUserProfit = {
|
|
550
|
+
user_profit: UserProfit;
|
|
551
|
+
create_ts_ms: string;
|
|
552
|
+
};
|
|
553
|
+
export declare function fetchUserProfits(client: TypusClient, input: {
|
|
554
|
+
profitVault: string;
|
|
555
|
+
version: string;
|
|
556
|
+
user: string;
|
|
557
|
+
}): Promise<UserProfit[]>;
|
|
558
|
+
export declare function fetchLockedUserProfits(client: TypusClient, input: {
|
|
559
|
+
lockVault: string;
|
|
560
|
+
version: string;
|
|
561
|
+
user: string;
|
|
562
|
+
}): Promise<LockedUserProfit[]>;
|
|
563
|
+
export declare function fetchAllUserProfits(client: TypusClient, input?: {
|
|
564
|
+
profitVault?: string;
|
|
565
|
+
}): Promise<{
|
|
566
|
+
user: string;
|
|
567
|
+
profits: UserProfit[];
|
|
568
|
+
}[]>;
|
|
569
|
+
export declare function fetchAllLockedUserProfits(client: TypusClient, input?: {
|
|
570
|
+
lockVault?: string;
|
|
571
|
+
}): Promise<{
|
|
572
|
+
user: string;
|
|
573
|
+
lockedUserProfits: LockedUserProfit[];
|
|
574
|
+
}[]>;
|
|
537
575
|
export {};
|
package/dist/src/fetch.js
CHANGED
|
@@ -13,7 +13,12 @@ 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");
|
|
@@ -198,15 +203,13 @@ function parseOptionBidReceipts(positions) {
|
|
|
198
203
|
async function getUserStake(client, input) {
|
|
199
204
|
let tx = new transactions_1.Transaction();
|
|
200
205
|
for (let i of input.indexes) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
// })
|
|
209
|
-
// );
|
|
206
|
+
tx.add((0, stake_pool_1.allocateIncentive)({
|
|
207
|
+
arguments: {
|
|
208
|
+
version: _1.STAKE_POOL_VERSION,
|
|
209
|
+
registry: _1.STAKE_POOL,
|
|
210
|
+
index: BigInt(i),
|
|
211
|
+
},
|
|
212
|
+
}));
|
|
210
213
|
tx.add((0, stake_pool_1.getUserShares)({
|
|
211
214
|
arguments: {
|
|
212
215
|
registry: _1.STAKE_POOL,
|
|
@@ -221,7 +224,7 @@ async function getUserStake(client, input) {
|
|
|
221
224
|
let results = [];
|
|
222
225
|
for (var x = 0; x < input.indexes.length; x++) {
|
|
223
226
|
// @ts-ignore
|
|
224
|
-
var returnValues = res.results[x].returnValues[0][0];
|
|
227
|
+
var returnValues = res.results[2 * x + 1].returnValues[0][0];
|
|
225
228
|
// console.log(returnValues);
|
|
226
229
|
var reader = new bcs_1.BcsReader(new Uint8Array(returnValues));
|
|
227
230
|
let length = reader.readULEB();
|
|
@@ -423,3 +426,171 @@ async function getAllPositionsWithTradingSymbol(client, input) {
|
|
|
423
426
|
}
|
|
424
427
|
return positions;
|
|
425
428
|
}
|
|
429
|
+
const TypeNameBcs = bcs_1.bcs.struct("TypeName", {
|
|
430
|
+
name: bcs_1.bcs.string(),
|
|
431
|
+
});
|
|
432
|
+
const UserProfitBcs = bcs_1.bcs.struct("UserProfit", {
|
|
433
|
+
collateral_token: TypeNameBcs,
|
|
434
|
+
base_token: TypeNameBcs,
|
|
435
|
+
position_id: bcs_1.bcs.u64(),
|
|
436
|
+
order_id: bcs_1.bcs.u64(),
|
|
437
|
+
amount: bcs_1.bcs.u64(),
|
|
438
|
+
create_ts_ms: bcs_1.bcs.u64(),
|
|
439
|
+
});
|
|
440
|
+
const LockedUserProfitBcs = bcs_1.bcs.struct("LockedUserProfit", {
|
|
441
|
+
user_profit: UserProfitBcs,
|
|
442
|
+
create_ts_ms: bcs_1.bcs.u64(),
|
|
443
|
+
});
|
|
444
|
+
async function fetchUserProfits(client, input) {
|
|
445
|
+
let tx = new transactions_1.Transaction();
|
|
446
|
+
tx.moveCall({
|
|
447
|
+
target: `${_1.PERP_PACKAGE_ID}::profit_vault::get_user_profits`,
|
|
448
|
+
arguments: [tx.object(input.version), tx.object(input.profitVault), tx.pure.address(input.user)],
|
|
449
|
+
});
|
|
450
|
+
const res = await client.devInspectTransactionBlock({
|
|
451
|
+
sender: constants_1.SENDER,
|
|
452
|
+
transactionBlock: tx,
|
|
453
|
+
});
|
|
454
|
+
if (!res.results?.[0]?.returnValues?.[0]?.[0]) {
|
|
455
|
+
return [];
|
|
456
|
+
}
|
|
457
|
+
const returnValues = res.results[0].returnValues[0][0];
|
|
458
|
+
const reader = new bcs_1.BcsReader(new Uint8Array(returnValues));
|
|
459
|
+
const profits = [];
|
|
460
|
+
reader.readVec((reader) => {
|
|
461
|
+
const length = reader.readULEB();
|
|
462
|
+
const bytes = reader.readBytes(length);
|
|
463
|
+
const profit = UserProfitBcs.parse(Uint8Array.from(Array.from(bytes)));
|
|
464
|
+
profits.push(profit);
|
|
465
|
+
});
|
|
466
|
+
return profits;
|
|
467
|
+
}
|
|
468
|
+
async function fetchLockedUserProfits(client, input) {
|
|
469
|
+
let tx = new transactions_1.Transaction();
|
|
470
|
+
tx.moveCall({
|
|
471
|
+
target: `${_1.PERP_PACKAGE_ID}::profit_vault::get_locked_user_profits`,
|
|
472
|
+
arguments: [tx.object(_1.PERP_VERSION), tx.object(input.lockVault), tx.pure.address(input.user)],
|
|
473
|
+
});
|
|
474
|
+
const res = await client.devInspectTransactionBlock({
|
|
475
|
+
sender: constants_1.SENDER,
|
|
476
|
+
transactionBlock: tx,
|
|
477
|
+
});
|
|
478
|
+
if (!res.results?.[0]?.returnValues?.[0]?.[0]) {
|
|
479
|
+
return [];
|
|
480
|
+
}
|
|
481
|
+
const returnValues = res.results[0].returnValues[0][0];
|
|
482
|
+
const reader = new bcs_1.BcsReader(new Uint8Array(returnValues));
|
|
483
|
+
const lockedUserProfits = [];
|
|
484
|
+
reader.readVec((reader) => {
|
|
485
|
+
const length = reader.readULEB();
|
|
486
|
+
const bytes = reader.readBytes(length);
|
|
487
|
+
const profit = LockedUserProfitBcs.parse(Uint8Array.from(Array.from(bytes)));
|
|
488
|
+
lockedUserProfits.push(profit);
|
|
489
|
+
});
|
|
490
|
+
return lockedUserProfits;
|
|
491
|
+
}
|
|
492
|
+
async function fetchAllUserProfits(client, input) {
|
|
493
|
+
const provider = new client_1.SuiClient({ url: client.config.rpcEndpoint });
|
|
494
|
+
const profitVaultId = input?.profitVault ?? _1.PROFIT_VAULT;
|
|
495
|
+
// 1. Read ProfitVault object to get user_profits Table ID
|
|
496
|
+
const vaultResponse = await provider.getObject({
|
|
497
|
+
id: profitVaultId,
|
|
498
|
+
options: { showContent: true },
|
|
499
|
+
});
|
|
500
|
+
if (!vaultResponse.data?.content || vaultResponse.data.content.dataType !== "moveObject") {
|
|
501
|
+
return [];
|
|
502
|
+
}
|
|
503
|
+
const fields = vaultResponse.data.content.fields;
|
|
504
|
+
const tableId = fields?.user_profits?.fields?.id?.id;
|
|
505
|
+
if (!tableId) {
|
|
506
|
+
return [];
|
|
507
|
+
}
|
|
508
|
+
// 2. Get all dynamic fields (user addresses) from the Table
|
|
509
|
+
let cursor = null;
|
|
510
|
+
const allUsers = [];
|
|
511
|
+
while (true) {
|
|
512
|
+
const dynamicFields = await provider.getDynamicFields({
|
|
513
|
+
parentId: tableId,
|
|
514
|
+
cursor,
|
|
515
|
+
limit: 50,
|
|
516
|
+
});
|
|
517
|
+
for (const field of dynamicFields.data) {
|
|
518
|
+
const userAddress = field.name.value;
|
|
519
|
+
if (userAddress) {
|
|
520
|
+
allUsers.push(userAddress);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
if (!dynamicFields.hasNextPage) {
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
cursor = dynamicFields.nextCursor ?? null;
|
|
527
|
+
}
|
|
528
|
+
// 3. For each user, fetch their profits
|
|
529
|
+
const fetchUserProfitsPromises = [];
|
|
530
|
+
for (const user of allUsers) {
|
|
531
|
+
try {
|
|
532
|
+
const fetchUserProfitsWithUser = async () => {
|
|
533
|
+
const profits = await fetchUserProfits(client, { profitVault: profitVaultId, version: _1.PERP_VERSION, user });
|
|
534
|
+
return { user, profits };
|
|
535
|
+
};
|
|
536
|
+
fetchUserProfitsPromises.push(fetchUserProfitsWithUser());
|
|
537
|
+
}
|
|
538
|
+
catch (e) {
|
|
539
|
+
console.error(`Failed to get profits for user ${user}:`, e);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
const results = await Promise.all(fetchUserProfitsPromises);
|
|
543
|
+
return results;
|
|
544
|
+
}
|
|
545
|
+
async function fetchAllLockedUserProfits(client, input) {
|
|
546
|
+
const provider = new client_1.SuiClient({ url: client.config.rpcEndpoint });
|
|
547
|
+
// 1. Read LockVault object to get locked_user_profits Table ID
|
|
548
|
+
const vaultResponse = await provider.getObject({
|
|
549
|
+
id: input?.lockVault ?? _1.LOCK_VAULT,
|
|
550
|
+
options: { showContent: true },
|
|
551
|
+
});
|
|
552
|
+
if (!vaultResponse.data?.content || vaultResponse.data.content.dataType !== "moveObject") {
|
|
553
|
+
return [];
|
|
554
|
+
}
|
|
555
|
+
const fields = vaultResponse.data.content.fields;
|
|
556
|
+
const tableId = fields?.locked_user_profits?.fields?.id?.id;
|
|
557
|
+
if (!tableId) {
|
|
558
|
+
return [];
|
|
559
|
+
}
|
|
560
|
+
// 2. Get all dynamic fields (user addresses) from the Table
|
|
561
|
+
let cursor = null;
|
|
562
|
+
const allUsers = [];
|
|
563
|
+
while (true) {
|
|
564
|
+
const dynamicFields = await provider.getDynamicFields({
|
|
565
|
+
parentId: tableId,
|
|
566
|
+
cursor,
|
|
567
|
+
limit: 50,
|
|
568
|
+
});
|
|
569
|
+
for (const field of dynamicFields.data) {
|
|
570
|
+
const userAddress = field.name.value;
|
|
571
|
+
if (userAddress) {
|
|
572
|
+
allUsers.push(userAddress);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
if (!dynamicFields.hasNextPage) {
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
cursor = dynamicFields.nextCursor ?? null;
|
|
579
|
+
}
|
|
580
|
+
// 3. For each user, fetch their locked profits
|
|
581
|
+
const fetchLockedUserProfitsPromises = [];
|
|
582
|
+
for (const user of allUsers) {
|
|
583
|
+
try {
|
|
584
|
+
const fetchLockedUserProfitsWithUser = async () => {
|
|
585
|
+
const lockedUserProfits = await fetchLockedUserProfits(client, { lockVault: _1.LOCK_VAULT, version: _1.PERP_VERSION, user });
|
|
586
|
+
return { user, lockedUserProfits };
|
|
587
|
+
};
|
|
588
|
+
fetchLockedUserProfitsPromises.push(fetchLockedUserProfitsWithUser());
|
|
589
|
+
}
|
|
590
|
+
catch (e) {
|
|
591
|
+
console.error(`Failed to get locked profits for user ${user}:`, e);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const results = await Promise.all(fetchLockedUserProfitsPromises);
|
|
595
|
+
return results;
|
|
596
|
+
}
|
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"));
|
|
@@ -27,7 +27,7 @@ dotenv_1.default.config();
|
|
|
27
27
|
exports.NETWORK = process.env.NEXT_PUBLIC_CLUSTER == "testnet" ? "TESTNET" : "MAINNET";
|
|
28
28
|
exports.PERP_PACKAGE_ID = exports.NETWORK == "MAINNET"
|
|
29
29
|
? "0xe27969a70f93034de9ce16e6ad661b480324574e68d15a64b513fd90eb2423e5"
|
|
30
|
-
: "
|
|
30
|
+
: "0x7adddfb77658ff43ad0281e264fdb43403a1b97bc2f6328b55279dfb4253e1e0";
|
|
31
31
|
exports.STAKE_PACKAGE_ID = exports.NETWORK == "MAINNET"
|
|
32
32
|
? "0xc427209145715a00a93d7e674a95c556a7147d79fda1bbaeb1a1cac5f9923966"
|
|
33
33
|
: "0x02b94b340a8810f6c451bc244dc2dd8d9d50cf86d727798969ca2c287c3186aa";
|
|
@@ -59,3 +59,9 @@ exports.STAKE_POOL_VERSION = exports.NETWORK == "MAINNET"
|
|
|
59
59
|
exports.COMPETITION_CONFIG = exports.NETWORK == "MAINNET"
|
|
60
60
|
? "0x36056abf9adde86f81667dad680a8ac98868c9fc1cb4d519fd2222d5d4522906"
|
|
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/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-exp13-profit-vault",
|
|
4
4
|
"repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
|
|
5
5
|
"author": "Typus",
|
|
6
6
|
"description": "typus perp sdk",
|
|
@@ -44,4 +44,4 @@
|
|
|
44
44
|
},
|
|
45
45
|
"homepage": "https://github.com/Typus-Lab/typus-perp-sdk#readme",
|
|
46
46
|
"packageManager": "yarn@4.10.3+sha512.c38cafb5c7bb273f3926d04e55e1d8c9dfa7d9c3ea1f36a4868fa028b9e5f72298f0b7f401ad5eb921749eb012eb1c3bb74bf7503df3ee43fd600d14a018266f"
|
|
47
|
-
}
|
|
47
|
+
}
|