@typus/typus-perp-sdk 1.0.61 → 1.0.63

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.
@@ -24,7 +24,7 @@ export declare function obj(tx: Transaction, arg: TransactionObjectInput): {
24
24
  } | ((tx: Transaction) => Exclude<import("valibot").InferInput<typeof import("@mysten/sui/transactions").Argument>, {
25
25
  Input: unknown;
26
26
  type?: "pure";
27
- }>);
27
+ }>) | import("@mysten/sui/dist/cjs/transactions/Transaction").AsyncTransactionThunk<import("@mysten/sui/dist/cjs/transactions/Transaction").TransactionResultArgument>;
28
28
  export declare function pure(tx: Transaction, arg: PureArg, type: string): TransactionArgument;
29
29
  export declare function option(tx: Transaction, type: string, arg: GenericArg | null): TransactionArgument;
30
30
  export declare function generic(tx: Transaction, type: string, arg: GenericArg): TransactionArgument;
@@ -2,6 +2,7 @@ import { Markets, SymbolMarket } from "./typus_perp/trading/structs";
2
2
  import { LiquidityPool } from "./typus_perp/lp-pool/structs";
3
3
  import { TradingOrder, Position } from "./typus_perp/position/structs";
4
4
  import { LpUserShare, StakePool } from "./typus_stake_pool/stake-pool/structs";
5
+ import { TOKEN } from "@typus/typus-sdk/dist/src/constants";
5
6
  import { PythClient, TypusConfig } from "@typus/typus-sdk/dist/src/utils";
6
7
  import { TypusBidReceipt } from "./_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/vault/structs";
7
8
  export declare function getLpPools(config: TypusConfig): Promise<LiquidityPool[]>;
@@ -29,3 +30,14 @@ export declare function getLiquidationPriceAndPnl(config: TypusConfig, pythClien
29
30
  positions: Position[];
30
31
  user: string;
31
32
  }): Promise<(string | number)[][] | undefined>;
33
+ export declare function getPositionCount(config: TypusConfig, input: {
34
+ baseToken: TOKEN;
35
+ }): Promise<number>;
36
+ export declare function getAllPositions(config: TypusConfig, input: {
37
+ baseToken: TOKEN;
38
+ slice: string;
39
+ page: string;
40
+ }): Promise<Position[]>;
41
+ export declare function getAllPositionsWithTradingSymbol(config: TypusConfig, input: {
42
+ baseToken: TOKEN;
43
+ }): Promise<Position[]>;
package/dist/src/fetch.js CHANGED
@@ -57,6 +57,9 @@ exports.getUserPositions = getUserPositions;
57
57
  exports.parseOptionBidReceipts = parseOptionBidReceipts;
58
58
  exports.getUserStake = getUserStake;
59
59
  exports.getLiquidationPriceAndPnl = getLiquidationPriceAndPnl;
60
+ exports.getPositionCount = getPositionCount;
61
+ exports.getAllPositions = getAllPositions;
62
+ exports.getAllPositionsWithTradingSymbol = getAllPositionsWithTradingSymbol;
60
63
  var client_1 = require("@mysten/sui/client");
61
64
  var transactions_1 = require("@mysten/sui/transactions");
62
65
  var bcs_1 = require("@mysten/bcs");
@@ -493,3 +496,119 @@ function getLiquidationPriceAndPnl(config, pythClient, input) {
493
496
  });
494
497
  });
495
498
  }
499
+ function getPositionCount(config, input) {
500
+ return __awaiter(this, void 0, void 0, function () {
501
+ var provider, tx, res, raw, maxPageBytes, view, maxPage;
502
+ var _a, _b, _c, _d;
503
+ return __generator(this, function (_e) {
504
+ switch (_e.label) {
505
+ case 0:
506
+ provider = new client_1.SuiClient({ url: config.rpcEndpoint });
507
+ tx = new transactions_1.Transaction();
508
+ // Rust 實作是呼叫 get_all_positions(slice = 1, page = 1) 然後取最後 8 bytes。
509
+ // 這裡直接複用相同邏輯,只需要 max_page。
510
+ (0, functions_1.getAllPositions)(tx, constants_1.tokenType[_1.NETWORK][input.baseToken], {
511
+ version: _1.PERP_VERSION,
512
+ registry: _1.MARKET,
513
+ marketIndex: BigInt(0),
514
+ slice: BigInt(1),
515
+ page: BigInt(1),
516
+ });
517
+ return [4 /*yield*/, provider.devInspectTransactionBlock({
518
+ sender: "0x0000000000000000000000000000000000000000000000000000000000000000",
519
+ transactionBlock: tx,
520
+ })];
521
+ case 1:
522
+ res = _e.sent();
523
+ // 沒有資料時,回傳 0
524
+ if (!((_d = (_c = (_b = (_a = res.results) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.returnValues) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d[0])) {
525
+ return [2 /*return*/, 0];
526
+ }
527
+ raw = new Uint8Array(res.results[0].returnValues[0][0]);
528
+ // 至少要含 8 bytes 的 max_page;不足代表無 Position
529
+ if (raw.length < 8)
530
+ return [2 /*return*/, 0];
531
+ maxPageBytes = raw.slice(raw.length - 8);
532
+ view = new DataView(maxPageBytes.buffer, maxPageBytes.byteOffset, 8);
533
+ maxPage = Number(view.getBigUint64(0, true));
534
+ return [2 /*return*/, maxPage];
535
+ }
536
+ });
537
+ });
538
+ }
539
+ function getAllPositions(config, input) {
540
+ return __awaiter(this, void 0, void 0, function () {
541
+ var provider, tx, res, raw, withoutMaxPage, reader, userPositionsLen, positions, i, fields, pos;
542
+ var _a, _b, _c, _d;
543
+ return __generator(this, function (_e) {
544
+ switch (_e.label) {
545
+ case 0:
546
+ provider = new client_1.SuiClient({ url: config.rpcEndpoint });
547
+ tx = new transactions_1.Transaction();
548
+ (0, functions_1.getAllPositions)(tx, constants_1.tokenType[_1.NETWORK][input.baseToken], {
549
+ version: _1.PERP_VERSION,
550
+ registry: _1.MARKET,
551
+ marketIndex: BigInt(0),
552
+ slice: BigInt(input.slice),
553
+ page: BigInt(input.page),
554
+ });
555
+ return [4 /*yield*/, provider.devInspectTransactionBlock({
556
+ sender: "0x0000000000000000000000000000000000000000000000000000000000000000",
557
+ transactionBlock: tx,
558
+ })];
559
+ case 1:
560
+ res = _e.sent();
561
+ console.log(res);
562
+ if (!((_d = (_c = (_b = (_a = res.results) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.returnValues) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d[0])) {
563
+ return [2 /*return*/, []];
564
+ }
565
+ raw = new Uint8Array(res.results[0].returnValues[0][0]);
566
+ // 1) 至少要有 8 bytes 的 max_page
567
+ if (raw.length < 8)
568
+ return [2 /*return*/, []];
569
+ withoutMaxPage = raw.slice(0, raw.length - 8);
570
+ reader = new bcs_1.BcsReader(withoutMaxPage);
571
+ userPositionsLen = reader.read8() - 1;
572
+ positions = [];
573
+ for (i = 0; i < userPositionsLen; i++) {
574
+ reader.read16();
575
+ fields = structs_3.Position.bcs.read(reader);
576
+ pos = structs_3.Position.fromFields(fields);
577
+ positions.push(pos);
578
+ }
579
+ return [2 /*return*/, positions];
580
+ }
581
+ });
582
+ });
583
+ }
584
+ function getAllPositionsWithTradingSymbol(config, input) {
585
+ return __awaiter(this, void 0, void 0, function () {
586
+ var total, slice, pages, pagePromises, page, results;
587
+ return __generator(this, function (_a) {
588
+ switch (_a.label) {
589
+ case 0: return [4 /*yield*/, getPositionCount(config, { baseToken: input.baseToken })];
590
+ case 1:
591
+ total = _a.sent();
592
+ // 2) 若無倉位直接回傳 []
593
+ if (total === 0) {
594
+ return [2 /*return*/, []];
595
+ }
596
+ slice = Math.min(total, 100);
597
+ pages = Math.ceil(total / slice);
598
+ pagePromises = [];
599
+ for (page = 1; page <= pages; page++) {
600
+ pagePromises.push(getAllPositions(config, {
601
+ baseToken: input.baseToken,
602
+ slice: slice.toString(),
603
+ page: page.toString(),
604
+ }));
605
+ }
606
+ return [4 /*yield*/, Promise.all(pagePromises)];
607
+ case 2:
608
+ results = _a.sent();
609
+ // 5) 扁平化後回傳
610
+ return [2 /*return*/, results.flat()];
611
+ }
612
+ });
613
+ });
614
+ }
package/dist/src/index.js CHANGED
@@ -30,7 +30,7 @@ exports.PERP_PACKAGE_ID = exports.NETWORK == "MAINNET"
30
30
  ? "0xe27969a70f93034de9ce16e6ad661b480324574e68d15a64b513fd90eb2423e5"
31
31
  : "0x585924f160f83ef16f8927ec117e4d740abb6f4e571ecfa89ff3e973042cb1b9";
32
32
  exports.PERP_PUBLISHED_AT = exports.NETWORK == "MAINNET"
33
- ? "0x347b833859a487218737de4a5e6b0fb861d37e653a10f44d420279c984badf9c"
33
+ ? "0xec8f626d408bbd572ee42111462bd8dfa552cca529c1664d4009fccadf3164c0"
34
34
  : "0x15844f80fb085bb8fd7cc688ade6282cd6991209eae78934ca001dced8b1b7de";
35
35
  exports.PERP_PKG_V1 = exports.NETWORK == "MAINNET"
36
36
  ? "0xe27969a70f93034de9ce16e6ad661b480324574e68d15a64b513fd90eb2423e5"
@@ -39,7 +39,7 @@ exports.STAKE_PACKAGE_ID = exports.NETWORK == "MAINNET"
39
39
  ? "0xc427209145715a00a93d7e674a95c556a7147d79fda1bbaeb1a1cac5f9923966"
40
40
  : "0x220e7ba8923c0c30b57c0baab3bc15d781a39bb294cf7af318c0fc816b5cf7e6";
41
41
  exports.STAKE_PUBLISHED_AT = exports.NETWORK == "MAINNET"
42
- ? "0xd9965c09d5ad7d69306b7c550b3b135d94b34f98c3adc379a7333fff2f05808b"
42
+ ? "0x758c5a79d4f788364303cc547f44a46a1622318073006937451e817c0e682c00"
43
43
  : "0x34ba6bf1893409b1a7494350189e060ee79cc2aba6f0c5e4045af9372d96fe85";
44
44
  exports.STAKE_PKG_V1 = exports.NETWORK == "MAINNET"
45
45
  ? "0xc427209145715a00a93d7e674a95c556a7147d79fda1bbaeb1a1cac5f9923966"
@@ -13,6 +13,11 @@ export interface AddTradingSymbolArgs {
13
13
  basicFundingRate: bigint | TransactionArgument;
14
14
  fundingIntervalTsMs: bigint | TransactionArgument;
15
15
  expMultiplier: bigint | TransactionArgument;
16
+ maxBuyOpenInterest: bigint | TransactionArgument;
17
+ maxSellOpenInterest: bigint | TransactionArgument;
18
+ maintenanceMarginRateBp: bigint | TransactionArgument;
19
+ optionMaintenanceMarginRateBp: bigint | TransactionArgument;
20
+ optionTradingFeeConfig: Array<bigint | TransactionArgument> | TransactionArgument;
16
21
  clock: TransactionObjectInput;
17
22
  }
18
23
  export declare function addTradingSymbol(tx: Transaction, typeArg: string, args: AddTradingSymbolArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
@@ -238,6 +243,14 @@ export interface GetActiveOrdersByOrderTagAndCtokenArgs {
238
243
  orderTypeTag: number | TransactionArgument;
239
244
  }
240
245
  export declare function getActiveOrdersByOrderTagAndCtoken(tx: Transaction, typeArgs: [string, string], args: GetActiveOrdersByOrderTagAndCtokenArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
246
+ export interface GetAllPositionsArgs {
247
+ version: TransactionObjectInput;
248
+ registry: TransactionObjectInput;
249
+ marketIndex: bigint | TransactionArgument;
250
+ slice: bigint | TransactionArgument;
251
+ page: bigint | TransactionArgument;
252
+ }
253
+ export declare function getAllPositions(tx: Transaction, typeArg: string, args: GetAllPositionsArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
241
254
  export interface GetEstimatedLiquidationPriceAndPnlArgs {
242
255
  version: TransactionObjectInput;
243
256
  registry: TransactionObjectInput;
@@ -592,6 +605,14 @@ export interface ReleaseCollateralArgs {
592
605
  releaseAmount: bigint | TransactionArgument;
593
606
  }
594
607
  export declare function releaseCollateral(tx: Transaction, typeArgs: [string, string], args: ReleaseCollateralArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
608
+ export interface RemoveLinkedOrder_Args {
609
+ version: TransactionObjectInput;
610
+ marketIndex: bigint | TransactionArgument;
611
+ symbolMarket: TransactionObjectInput;
612
+ order: TransactionObjectInput;
613
+ user: string | TransactionArgument;
614
+ }
615
+ export declare function removeLinkedOrder_(tx: Transaction, typeArg: string, args: RemoveLinkedOrder_Args, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
595
616
  export interface RemoveLinkedOrdersArgs {
596
617
  version: TransactionObjectInput;
597
618
  marketIndex: bigint | TransactionArgument;
@@ -676,6 +697,9 @@ export interface UpdateMarketConfigArgs {
676
697
  expMultiplier: bigint | TransactionArgument | TransactionArgument | null;
677
698
  maxBuyOpenInterest: bigint | TransactionArgument | TransactionArgument | null;
678
699
  maxSellOpenInterest: bigint | TransactionArgument | TransactionArgument | null;
700
+ maintenanceMarginRateBp: bigint | TransactionArgument | TransactionArgument | null;
701
+ optionCollateralMaintenanceMarginRateBp: bigint | TransactionArgument | TransactionArgument | null;
702
+ optionCollateralTradingFeeConfig: Array<bigint | TransactionArgument> | TransactionArgument | TransactionArgument | null;
679
703
  }
680
704
  export declare function updateMarketConfig(tx: Transaction, typeArg: string, args: UpdateMarketConfigArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
681
705
  export interface UpdateProtocolFeeShareBpArgs {
@@ -19,6 +19,7 @@ exports.executeOrder_ = executeOrder_;
19
19
  exports.exerciseBidReceipts = exerciseBidReceipts;
20
20
  exports.getActiveOrdersByOrderTag = getActiveOrdersByOrderTag;
21
21
  exports.getActiveOrdersByOrderTagAndCtoken = getActiveOrdersByOrderTagAndCtoken;
22
+ exports.getAllPositions = getAllPositions;
22
23
  exports.getEstimatedLiquidationPriceAndPnl = getEstimatedLiquidationPriceAndPnl;
23
24
  exports.getExpiredPositionInfo = getExpiredPositionInfo;
24
25
  exports.getLinkedPosition = getLinkedPosition;
@@ -48,6 +49,7 @@ exports.newMarkets = newMarkets;
48
49
  exports.reduceOptionCollateralPositionSize = reduceOptionCollateralPositionSize;
49
50
  exports.reduceOptionCollateralPositionSizeV2 = reduceOptionCollateralPositionSizeV2;
50
51
  exports.releaseCollateral = releaseCollateral;
52
+ exports.removeLinkedOrder_ = removeLinkedOrder_;
51
53
  exports.removeLinkedOrders = removeLinkedOrders;
52
54
  exports.removeTradingSymbol = removeTradingSymbol;
53
55
  exports.resumeMarket = resumeMarket;
@@ -83,6 +85,11 @@ function addTradingSymbol(tx, typeArg, args, published_at) {
83
85
  (0, util_1.pure)(tx, args.basicFundingRate, "u64"),
84
86
  (0, util_1.pure)(tx, args.fundingIntervalTsMs, "u64"),
85
87
  (0, util_1.pure)(tx, args.expMultiplier, "u64"),
88
+ (0, util_1.pure)(tx, args.maxBuyOpenInterest, "u64"),
89
+ (0, util_1.pure)(tx, args.maxSellOpenInterest, "u64"),
90
+ (0, util_1.pure)(tx, args.maintenanceMarginRateBp, "u64"),
91
+ (0, util_1.pure)(tx, args.optionMaintenanceMarginRateBp, "u64"),
92
+ (0, util_1.pure)(tx, args.optionTradingFeeConfig, "vector<u64>"),
86
93
  (0, util_1.obj)(tx, args.clock),
87
94
  ],
88
95
  });
@@ -398,6 +405,20 @@ function getActiveOrdersByOrderTagAndCtoken(tx, typeArgs, args, published_at) {
398
405
  arguments: [(0, util_1.obj)(tx, args.version), (0, util_1.obj)(tx, args.registry), (0, util_1.pure)(tx, args.marketIndex, "u64"), (0, util_1.pure)(tx, args.orderTypeTag, "u8")],
399
406
  });
400
407
  }
408
+ function getAllPositions(tx, typeArg, args, published_at) {
409
+ if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
410
+ return tx.moveCall({
411
+ target: "".concat(published_at, "::trading::get_all_positions"),
412
+ typeArguments: [typeArg],
413
+ arguments: [
414
+ (0, util_1.obj)(tx, args.version),
415
+ (0, util_1.obj)(tx, args.registry),
416
+ (0, util_1.pure)(tx, args.marketIndex, "u64"),
417
+ (0, util_1.pure)(tx, args.slice, "u64"),
418
+ (0, util_1.pure)(tx, args.page, "u64"),
419
+ ],
420
+ });
421
+ }
401
422
  function getEstimatedLiquidationPriceAndPnl(tx, typeArgs, args, published_at) {
402
423
  if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
403
424
  return tx.moveCall({
@@ -891,6 +912,20 @@ function releaseCollateral(tx, typeArgs, args, published_at) {
891
912
  ],
892
913
  });
893
914
  }
915
+ function removeLinkedOrder_(tx, typeArg, args, published_at) {
916
+ if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
917
+ return tx.moveCall({
918
+ target: "".concat(published_at, "::trading::remove_linked_order_"),
919
+ typeArguments: [typeArg],
920
+ arguments: [
921
+ (0, util_1.obj)(tx, args.version),
922
+ (0, util_1.pure)(tx, args.marketIndex, "u64"),
923
+ (0, util_1.obj)(tx, args.symbolMarket),
924
+ (0, util_1.obj)(tx, args.order),
925
+ (0, util_1.pure)(tx, args.user, "address"),
926
+ ],
927
+ });
928
+ }
894
929
  function removeLinkedOrders(tx, typeArg, args, published_at) {
895
930
  if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
896
931
  return tx.moveCall({
@@ -1018,6 +1053,9 @@ function updateMarketConfig(tx, typeArg, args, published_at) {
1018
1053
  (0, util_1.pure)(tx, args.expMultiplier, "".concat(structs_1.Option.$typeName, "<u64>")),
1019
1054
  (0, util_1.pure)(tx, args.maxBuyOpenInterest, "".concat(structs_1.Option.$typeName, "<u64>")),
1020
1055
  (0, util_1.pure)(tx, args.maxSellOpenInterest, "".concat(structs_1.Option.$typeName, "<u64>")),
1056
+ (0, util_1.pure)(tx, args.maintenanceMarginRateBp, "".concat(structs_1.Option.$typeName, "<u64>")),
1057
+ (0, util_1.pure)(tx, args.optionCollateralMaintenanceMarginRateBp, "".concat(structs_1.Option.$typeName, "<u64>")),
1058
+ (0, util_1.pure)(tx, args.optionCollateralTradingFeeConfig, "".concat(structs_1.Option.$typeName, "<vector<u64>>")),
1021
1059
  ],
1022
1060
  });
1023
1061
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@typus/typus-perp-sdk",
3
- "version": "1.0.61",
3
+ "version": "1.0.63",
4
4
  "repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
5
5
  "author": "Typus",
6
6
  "description": "typus perp sdk",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "@typus/typus-sdk": "1.6.26"
9
+ "@typus/typus-sdk": "1.7.0"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@types/bs58": "^4.0.1",