@typus/typus-perp-sdk 1.1.32-codegen-exp14-profit-vault → 1.1.32-codegen-exp16

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.
@@ -534,42 +534,4 @@ 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
- }[]>;
575
537
  export {};
package/dist/src/fetch.js CHANGED
@@ -13,12 +13,7 @@ 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;
20
16
  const transactions_1 = require("@mysten/sui/transactions");
21
- const client_1 = require("@mysten/sui/client");
22
17
  const bcs_1 = require("@mysten/bcs");
23
18
  const constants_1 = require("@typus/typus-sdk/dist/src/constants");
24
19
  const utils_1 = require("@typus/typus-sdk/dist/src/utils");
@@ -426,171 +421,3 @@ async function getAllPositionsWithTradingSymbol(client, input) {
426
421
  }
427
422
  return positions;
428
423
  }
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
- }
@@ -11,5 +11,3 @@ 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.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;
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;
21
21
  __exportStar(require("./fetch"), exports);
22
22
  __exportStar(require("./user"), exports);
23
23
  const dotenv_1 = __importDefault(require("dotenv"));
@@ -26,42 +26,36 @@ dotenv_1.default.config();
26
26
  // default MAINNET
27
27
  exports.NETWORK = process.env.NEXT_PUBLIC_CLUSTER == "testnet" ? "TESTNET" : "MAINNET";
28
28
  exports.PERP_PACKAGE_ID = exports.NETWORK == "MAINNET"
29
- ? "0xe27969a70f93034de9ce16e6ad661b480324574e68d15a64b513fd90eb2423e5"
30
- : "0x7adddfb77658ff43ad0281e264fdb43403a1b97bc2f6328b55279dfb4253e1e0";
29
+ ? "0xcb1c8159eb40b02877c0ceed599cf019cc8e61e8ec19c4d64db15e20ff630f05"
30
+ : "0x94cd358f552e9dd5df837de85939a9d1d682e97480740a203121e6f4c0078853";
31
31
  exports.STAKE_PACKAGE_ID = exports.NETWORK == "MAINNET"
32
- ? "0xc427209145715a00a93d7e674a95c556a7147d79fda1bbaeb1a1cac5f9923966"
32
+ ? "0x6cf6c6cc05316e238a338ba82c018d38a1af7e6da26b85fffa433df98e8f1bdb"
33
33
  : "0x02b94b340a8810f6c451bc244dc2dd8d9d50cf86d727798969ca2c287c3186aa";
34
34
  // lp_pool::Registry
35
35
  exports.LP_POOL = exports.NETWORK == "MAINNET"
36
- ? "0xfee68e535bf24702be28fa38ea2d5946e617e0035027d5ca29dbed99efd82aaa"
36
+ ? "0xb4b5e5fff9c6036f5ba22434467df1d23c2a77709807c43c7c9200816edb7006"
37
37
  : "0x85fa3cc6dc0fa8b47dda95ba0335fe1cec61dde4a2a8486ccd040f94d399b4c3";
38
38
  // liquidity_pool_registry
39
39
  exports.LIQUIDITY_POOL = exports.NETWORK == "MAINNET"
40
- ? "0x9973b7dd68ab8ba18702d913191a4c62c597847d9cd9f0b5bd97f1b938fc9a0a"
40
+ ? "0x422d57052da4465c5cbed8270e815dd9bc943cba827865db44fa067c525de9d9"
41
41
  : "0xe034d157764f273df5a1e264a3c0f78d8f922c37f942c340dabb1d66244c72ba";
42
42
  // MarketRegistry
43
43
  exports.MARKET = exports.NETWORK == "MAINNET"
44
- ? "0xc969d946a2b6b917a83b5fb71765793c4a52149e50d2c8cf5c01d7421fc7cd73"
44
+ ? "0x09a1fb68e7b07ac48d8f370cec4b5dabc80eb9a3a548ba4d06fa8e5ce1cf03ad"
45
45
  : "0xd0685e3eca9530f0618625d4a617a80db09f000609285b32a85f863da6baf811";
46
46
  exports.PERP_VERSION = exports.NETWORK == "MAINNET"
47
- ? "0xa12c282a068328833ec4a9109fc77803ec1f523f8da1bb0f82bac8450335f0c9"
47
+ ? "0x6ed8676315014e829c89f56d95a88e35167ade69911f853aed8b92c25746ecbc"
48
48
  : "0xbb0615832168e64e301db2ebd6ad71b3fe170d7e217ccd0c08714de56b41676b";
49
49
  exports.TLP_TREASURY_CAP = exports.NETWORK == "MAINNET"
50
- ? "0x77c75fb1d78cca25b5e2d69decfe2837abf95c4ef44b809868e6ca20f42b63bc"
50
+ ? "0xf836ae7b9d53bddb9be877b4fbc3ebd93b01327ca76b437d8618940d5081d222"
51
51
  : "0x1b39c2a5bc109ac520787c62f924da9244343e869bad755157e6e3e22bd7b7ae";
52
52
  // StakePoolRegistry
53
53
  exports.STAKE_POOL = exports.NETWORK == "MAINNET"
54
- ? "0x2cdf93717f87a8a7aeb98b27777b3b643f0ae2b277f44e6bcda0fc655a47d3e0"
54
+ ? "0x60c771d32a7b7f0f5f58d7dc2e6d83f76a6512f58d79bded2ee458a1d79b786c"
55
55
  : "0x8e5e5435c3fcd77f07cf097c5fbd381af7c2b394420ea035685662215471e578";
56
56
  exports.STAKE_POOL_VERSION = exports.NETWORK == "MAINNET"
57
- ? "0xdf3ed1599218b2415b2cd7fa06296f7f647676019b2873ec18e55a626c584f1b"
57
+ ? "0x57ddf480a4649da5f92b4e607cf1fac75bc11d8b582816509989d66f8bc7e329"
58
58
  : "0x02b94b340a8810f6c451bc244dc2dd8d9d50cf86d727798969ca2c287c3186aa";
59
59
  exports.COMPETITION_CONFIG = exports.NETWORK == "MAINNET"
60
- ? "0x36056abf9adde86f81667dad680a8ac98868c9fc1cb4d519fd2222d5d4522906"
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
@@ -356,7 +356,7 @@ async function getGraphQLEvents(module, sender, beforeCursor = null) {
356
356
  }}
357
357
  `,
358
358
  });
359
- let response = await fetch(`https://graphql.${src_1.NETWORK.toLowerCase()}.sui.io/graphql`, {
359
+ let response = await fetch(`https://sui-${src_1.NETWORK.toLowerCase()}.mystenlabs.com/graphql`, {
360
360
  method: "POST",
361
361
  headers: { "Content-Type": "application/json" },
362
362
  body: graphql,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typus/typus-perp-sdk",
3
- "version": "1.1.32-codegen-exp14-profit-vault",
3
+ "version": "1.1.32-codegen-exp16",
4
4
  "repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
5
5
  "author": "Typus",
6
6
  "description": "typus perp sdk",