aftermath-ts-sdk 1.3.23-perps.34 → 1.3.23-perps.36

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.
@@ -25,7 +25,20 @@ const caller_1 = require("../../general/utils/caller");
25
25
  const utils_1 = require("../../general/utils");
26
26
  const perpetuals_1 = require("./perpetuals");
27
27
  const transactions_1 = require("@mysten/sui/transactions");
28
- // TODO: create refresh account positions function ?
28
+ /**
29
+ * Note on “refreshing” account state:
30
+ *
31
+ * This class is a thin wrapper around a snapshot of {@link PerpetualsAccountObject}
32
+ * that is typically fetched via {@link Perpetuals.getAccount}. The transaction builders
33
+ * use the current snapshot to derive fields like `hasPosition` and to construct
34
+ * SL/TP helpers that depend on the position side.
35
+ *
36
+ * If your app is long-lived, you may want to periodically re-fetch the account
37
+ * (and recreate this wrapper) to avoid stale local position/order state. For example:
38
+ * - After placing/canceling orders
39
+ * - After fills/liquidations/funding settlements
40
+ * - After switching markets or wallets
41
+ */
29
42
  /**
30
43
  * High-level wrapper around a single Perpetuals account or vault account.
31
44
  *
@@ -110,11 +123,11 @@ class PerpetualsAccount extends caller_1.Caller {
110
123
  * @param inputs.depositCoinArg - Transaction object argument referencing a
111
124
  * coin to deposit (mutually exclusive with `depositAmount`).
112
125
  *
113
- * @returns Transaction response containing a serialized `txKind`.
126
+ * @returns Transaction response containing a `tx`.
114
127
  *
115
128
  * @example
116
129
  * ```ts
117
- * const { txKind } = await account.getDepositCollateralTx({
130
+ * const { tx } = await account.getDepositCollateralTx({
118
131
  * depositAmount: BigInt("1000000000"),
119
132
  * });
120
133
  * ```
@@ -147,12 +160,12 @@ class PerpetualsAccount extends caller_1.Caller {
147
160
  * coins directly.
148
161
  * @param inputs.tx - Optional transaction to extend (defaults to new `Transaction()`).
149
162
  *
150
- * @returns A response containing `txKind` and the `coinOutArg` where the
163
+ * @returns A response containing `tx` and the `coinOutArg` where the
151
164
  * withdrawn coins end up if `recipientAddress` is not used.
152
165
  *
153
166
  * @example
154
167
  * ```ts
155
- * const { txKind, coinOutArg } = await account.getWithdrawCollateralTx({
168
+ * const { tx, coinOutArg } = await account.getWithdrawCollateralTx({
156
169
  * withdrawAmount: BigInt("1000000000"),
157
170
  * });
158
171
  * ```
@@ -186,7 +199,7 @@ class PerpetualsAccount extends caller_1.Caller {
186
199
  * @param inputs.allocateAmount - Amount of collateral to allocate.
187
200
  * @param inputs.tx - Optional transaction to extend.
188
201
  *
189
- * @returns Transaction response containing a serialized `txKind`.
202
+ * @returns Transaction response containing a `tx`.
190
203
  */
191
204
  getAllocateCollateralTx(inputs) {
192
205
  return __awaiter(this, void 0, void 0, function* () {
@@ -217,7 +230,7 @@ class PerpetualsAccount extends caller_1.Caller {
217
230
  * @param inputs.deallocateAmount - Amount of collateral to deallocate.
218
231
  * @param inputs.tx - Optional transaction to extend.
219
232
  *
220
- * @returns Transaction response containing a serialized `txKind`.
233
+ * @returns Transaction response containing a `tx`.
221
234
  */
222
235
  getDeallocateCollateralTx(inputs) {
223
236
  return __awaiter(this, void 0, void 0, function* () {
@@ -247,7 +260,7 @@ class PerpetualsAccount extends caller_1.Caller {
247
260
  * @param inputs.toAccountId - Destination account ID.
248
261
  * @param inputs.tx - Optional transaction to extend.
249
262
  *
250
- * @returns Transaction response containing a serialized `txKind`.
263
+ * @returns Transaction response containing a `tx`.
251
264
  */
252
265
  getTransferCollateralTx(inputs) {
253
266
  return __awaiter(this, void 0, void 0, function* () {
@@ -279,6 +292,12 @@ class PerpetualsAccount extends caller_1.Caller {
279
292
  * - Derives `hasPosition` based on the current account state for the given market.
280
293
  * - Optionally attaches SL/TP stop orders via the `slTp` input.
281
294
  *
295
+ * Important behavioral notes:
296
+ * - `hasPosition` is derived from the local {@link PerpetualsAccountObject} snapshot.
297
+ * If the snapshot is stale, consider re-fetching the account first.
298
+ * - For vault-backed accounts, the API routes to `/perpetuals/vault/...` and uses
299
+ * `vaultId` as the identity discriminator. For direct accounts, it uses `accountId`.
300
+ *
282
301
  * @param inputs - See {@link SdkPerpetualsPlaceMarketOrderInputs} for details.
283
302
  * Notably:
284
303
  * - `marketId`, `side`, `size`, `collateralChange`, `reduceOnly`
@@ -286,11 +305,11 @@ class PerpetualsAccount extends caller_1.Caller {
286
305
  * - Optional `slTp` params
287
306
  * - Optional `tx` to extend
288
307
  *
289
- * @returns Transaction response containing `txKind`.
308
+ * @returns Transaction response containing `tx`.
290
309
  *
291
310
  * @example
292
311
  * ```ts
293
- * const { txKind } = await account.getPlaceMarketOrderTx({
312
+ * const { tx } = await account.getPlaceMarketOrderTx({
294
313
  * marketId: "0x...",
295
314
  * side: PerpetualsOrderSide.Bid,
296
315
  * size: BigInt("1000000000"),
@@ -327,9 +346,14 @@ class PerpetualsAccount extends caller_1.Caller {
327
346
  * - Requires `price` and `orderType`.
328
347
  * - Supports reduce-only flags, expiry, optional leverage, and SL/TP stop orders.
329
348
  *
349
+ * Notes:
350
+ * - `hasPosition` is derived from local account state; refresh the account if needed.
351
+ * - This method does not validate tick/lot sizing locally; the API/on-chain
352
+ * will enforce market constraints.
353
+ *
330
354
  * @param inputs - See {@link SdkPerpetualsPlaceLimitOrderInputs}.
331
355
  *
332
- * @returns Transaction response containing `txKind`.
356
+ * @returns Transaction response containing `tx`.
333
357
  */
334
358
  getPlaceLimitOrderTx(inputs) {
335
359
  return __awaiter(this, void 0, void 0, function* () {
@@ -355,13 +379,21 @@ class PerpetualsAccount extends caller_1.Caller {
355
379
  /**
356
380
  * Build a `cancel-orders` transaction for this account.
357
381
  *
382
+ * Each market in `marketIdsToData` supplies:
383
+ * - `orderIds`: the orders to cancel in that market
384
+ * - `collateralChange`: collateral adjustment to apply alongside cancellation
385
+ * - `leverage`: leverage context used for estimating/validating constraints server-side
386
+ *
387
+ * Notes:
388
+ * - Cancels are applied per market; some markets may succeed while others fail
389
+ * depending on API/on-chain validation (returned as a transaction failure at execution).
390
+ * - If you need to understand the effect prior to building a tx, use
391
+ * {@link getCancelOrdersPreview}.
392
+ *
358
393
  * @param inputs.tx - Optional transaction to extend.
359
- * @param inputs.marketIdsToData - Mapping from market IDs to:
360
- * - `orderIds`: order IDs to cancel
361
- * - `collateralChange`: net collateral impact (if any)
362
- * - `leverage`: current leverage used for estimating effects
394
+ * @param inputs.marketIdsToData - Mapping from market IDs to cancel payloads.
363
395
  *
364
- * @returns Transaction response containing `txKind`.
396
+ * @returns Transaction response containing `tx`.
365
397
  */
366
398
  getCancelOrdersTx(inputs) {
367
399
  return __awaiter(this, void 0, void 0, function* () {
@@ -384,10 +416,13 @@ class PerpetualsAccount extends caller_1.Caller {
384
416
  /**
385
417
  * Build a `cancel-stop-orders` transaction for this account.
386
418
  *
419
+ * This cancels stop-order *objects/tickets* by their object IDs. These IDs are
420
+ * returned by stop-order query endpoints (see {@link getStopOrderDatas}).
421
+ *
387
422
  * @param inputs.tx - Optional transaction to extend.
388
423
  * @param inputs.stopOrderIds - Array of stop-order ticket IDs to cancel.
389
424
  *
390
- * @returns Transaction response containing `txKind`.
425
+ * @returns Transaction response containing `tx`.
391
426
  */
392
427
  getCancelStopOrdersTx(inputs) {
393
428
  return __awaiter(this, void 0, void 0, function* () {
@@ -413,9 +448,14 @@ class PerpetualsAccount extends caller_1.Caller {
413
448
  * This allows placing one or more stop orders in a single transaction,
414
449
  * optionally with a dedicated gas coin and a sponsored gas flag.
415
450
  *
451
+ * Typical usage:
452
+ * - Construct stop order payload(s) client-side
453
+ * - Call this method to build a transaction kind
454
+ * - Sign/execute the transaction via Sui
455
+ *
416
456
  * @param inputs - See {@link SdkPerpetualsPlaceStopOrdersInputs}.
417
457
  *
418
- * @returns Transaction response containing `txKind`.
458
+ * @returns Transaction response containing `tx`.
419
459
  */
420
460
  getPlaceStopOrdersTx(inputs) {
421
461
  return __awaiter(this, void 0, void 0, function* () {
@@ -446,9 +486,14 @@ class PerpetualsAccount extends caller_1.Caller {
446
486
  * in a given market. If the account has no position for `marketId`, this
447
487
  * throws an error.
448
488
  *
489
+ * Implementation details:
490
+ * - Determines the current position side from the account snapshot.
491
+ * - Sets `positionSide` for the API so SL/TP orders are bound to closing logic
492
+ * (i.e. they should trigger on the opposite side of the open position).
493
+ *
449
494
  * @param inputs - See {@link SdkPerpetualsPlaceSlTpOrdersInputs}.
450
495
  *
451
- * @returns Transaction response containing `txKind`.
496
+ * @returns Transaction response containing `tx`.
452
497
  */
453
498
  getPlaceSlTpOrdersTx(inputs) {
454
499
  return __awaiter(this, void 0, void 0, function* () {
@@ -480,10 +525,15 @@ class PerpetualsAccount extends caller_1.Caller {
480
525
  *
481
526
  * This endpoint lets you update existing stop orders in batch.
482
527
  *
528
+ * Notes:
529
+ * - You must provide the full updated stop-order objects (including object IDs).
530
+ * - This is typically used to adjust trigger prices, sizes, expiries, or the
531
+ * embedded limit-order parameters.
532
+ *
483
533
  * @param inputs.stopOrders - Full updated stop-order payloads to apply.
484
534
  * @param inputs.tx - Optional transaction to extend.
485
535
  *
486
- * @returns Transaction response containing `txKind`.
536
+ * @returns Transaction response containing `tx`.
487
537
  */
488
538
  getEditStopOrdersTx(inputs) {
489
539
  return __awaiter(this, void 0, void 0, function* () {
@@ -548,13 +598,18 @@ class PerpetualsAccount extends caller_1.Caller {
548
598
  * This updates the effective leverage for the position (or potential position)
549
599
  * in `marketId`, and optionally adjusts collateral in tandem.
550
600
  *
601
+ * Notes:
602
+ * - Leverage changes may be constrained by protocol risk limits and current
603
+ * position state.
604
+ * - If you want to understand the effect first, use {@link getSetLeveragePreview}.
605
+ *
551
606
  * @param inputs.tx - Optional transaction to extend.
552
607
  * @param inputs.leverage - Target leverage value.
553
608
  * @param inputs.collateralChange - Net collateral change to apply alongside
554
609
  * the leverage update.
555
610
  * @param inputs.marketId - Market whose leverage to adjust.
556
611
  *
557
- * @returns Transaction response containing `txKind`.
612
+ * @returns Transaction response containing `tx`.
558
613
  */
559
614
  getSetLeverageTx(inputs) {
560
615
  return __awaiter(this, void 0, void 0, function* () {
@@ -601,6 +656,12 @@ class PerpetualsAccount extends caller_1.Caller {
601
656
  * This payload is intended to be signed off-chain and then submitted to
602
657
  * `getStopOrderDatas` as a proof of account ownership.
603
658
  *
659
+ * Important:
660
+ * - The returned payload is *not* a Sui transaction; it is an off-chain
661
+ * “authentication” message.
662
+ * - The backend expects `account_id` to be a decimal string. This code
663
+ * normalizes the bigint `accountId` by stripping the trailing `n`.
664
+ *
604
665
  * @param inputs.marketIds - Optional list of market IDs to scope the query.
605
666
  *
606
667
  * @returns An object describing the action and account/market IDs, suitable
@@ -659,6 +720,9 @@ class PerpetualsAccount extends caller_1.Caller {
659
720
  /**
660
721
  * Preview the effects of placing a market order (without building a tx).
661
722
  *
723
+ * This is a read-only API call that runs the protocol’s pricing / margin /
724
+ * slippage logic against the current market state and your account/vault context.
725
+ *
662
726
  * @param inputs - See {@link SdkPerpetualsPlaceMarketOrderPreviewInputs}.
663
727
  * @param abortSignal - Optional `AbortSignal` to cancel the request.
664
728
  *
@@ -687,6 +751,11 @@ class PerpetualsAccount extends caller_1.Caller {
687
751
  /**
688
752
  * Preview the effects of placing a limit order (without building a tx).
689
753
  *
754
+ * The preview simulates:
755
+ * - How much size would execute immediately vs post to the book
756
+ * - Expected slippage and execution price
757
+ * - Resulting position and margin impact
758
+ *
690
759
  * @param inputs - See {@link SdkPerpetualsPlaceLimitOrderPreviewInputs}.
691
760
  * @param abortSignal - Optional `AbortSignal` to cancel the request.
692
761
  *
@@ -710,15 +779,19 @@ class PerpetualsAccount extends caller_1.Caller {
710
779
  /**
711
780
  * Preview the effects of canceling orders across one or more markets.
712
781
  *
782
+ * This is commonly used to:
783
+ * - Validate that cancels are allowed under current margin constraints
784
+ * - Estimate how collateral/margin would change after canceling (and applying
785
+ * the associated `collateralChange` values)
786
+ *
713
787
  * If `marketIdsToData` is empty, this returns a trivial preview with:
714
- * - `collateralChange: 0`
715
- * - `updatedPositions: []`
788
+ * - `marketIdsToData: {}`
716
789
  *
717
790
  * @param inputs - See {@link SdkPerpetualsCancelOrdersPreviewInputs}.
718
791
  * @param abortSignal - Optional `AbortSignal` to cancel the request.
719
792
  *
720
793
  * @returns Either:
721
- * - `{ updatedPositions, collateralChange }`, or
794
+ * - `{ marketIdsToData }`, or
722
795
  * - `{ error }`.
723
796
  */
724
797
  getCancelOrdersPreview(inputs, abortSignal) {
@@ -779,6 +852,10 @@ class PerpetualsAccount extends caller_1.Caller {
779
852
  /**
780
853
  * Preview the effects of setting leverage for a given market.
781
854
  *
855
+ * The preview returns:
856
+ * - The position after the leverage change (`updatedPosition`)
857
+ * - The collateral delta required/produced (`collateralChange`)
858
+ *
782
859
  * @param inputs.marketId - Market whose leverage you want to adjust.
783
860
  * @param inputs.leverage - Target leverage value.
784
861
  * @param abortSignal - Optional `AbortSignal` to cancel the request.
@@ -806,6 +883,10 @@ class PerpetualsAccount extends caller_1.Caller {
806
883
  * Preview the effects of allocating/deallocating collateral for the position in
807
884
  * a given market.
808
885
  *
886
+ * Semantics:
887
+ * - Positive `collateralChange` previews allocation (moving collateral into the market).
888
+ * - Negative `collateralChange` previews deallocation (moving collateral out of the market).
889
+ *
809
890
  * @param inputs.marketId - Market of whose position you want to allocate/deallocate
810
891
  * collateral to/from.
811
892
  * @param inputs.collateralChange - The target collateral change (a positive number
@@ -874,8 +955,12 @@ class PerpetualsAccount extends caller_1.Caller {
874
955
  * This is especially useful after a long-running session where on-chain
875
956
  * pending orders may have changed relative to the local `account` state.
876
957
  *
877
- * @returns Array of {@link PerpetualsOrderData} describing each pending order.
878
- * Returns `[]` if there are no pending orders.
958
+ * The request payload is derived from this instance’s current snapshot:
959
+ * - It enumerates `account.positions[].pendingOrders`
960
+ * - Sends each `{ orderId, currentSize }` to the API to resolve canonical order data
961
+ *
962
+ * @returns {@link ApiPerpetualsAccountOrderDatasResponse} containing an `orderDatas`
963
+ * array. Returns `{ orderDatas: [] }` if there are no pending orders.
879
964
  */
880
965
  getOrderDatas() {
881
966
  return __awaiter(this, void 0, void 0, function* () {
@@ -900,12 +985,16 @@ class PerpetualsAccount extends caller_1.Caller {
900
985
  * Fetch stop-order ticket data for this account, using an off-chain signed
901
986
  * payload.
902
987
  *
903
- * @param inputs.bytes - Serialized message that was signed (e.g. from
904
- * {@link getStopOrdersMessageToSign}).
988
+ * Typical flow:
989
+ * 1) Call {@link getStopOrdersMessageToSign} to construct a deterministic payload
990
+ * 2) Sign the payload with the wallet
991
+ * 3) Provide the signed payload to this method to fetch stop order data
992
+ *
993
+ * @param inputs.bytes - Serialized message that was signed (e.g. JSON string).
905
994
  * @param inputs.signature - Signature over `bytes`.
906
995
  * @param inputs.marketIds - Optional subset of markets to filter results by.
907
996
  *
908
- * @returns Array of {@link PerpetualsStopOrderData}.
997
+ * @returns {@link ApiPerpetualsStopOrderDatasResponse} containing `stopOrderDatas`.
909
998
  */
910
999
  getStopOrderDatas(inputs) {
911
1000
  return __awaiter(this, void 0, void 0, function* () {
@@ -926,11 +1015,15 @@ class PerpetualsAccount extends caller_1.Caller {
926
1015
  * Fetch paginated collateral-change history for this account, including
927
1016
  * deposits, withdrawals, funding settlements, liquidations, etc.
928
1017
  *
1018
+ * Pagination:
1019
+ * - Use `beforeTimestampCursor` to fetch older entries.
1020
+ * - The API returns a `nextBeforeTimestampCursor` to continue pagination.
1021
+ *
929
1022
  * @param inputs.beforeTimestampCursor - Optional cursor for pagination.
930
1023
  * @param inputs.limit - Optional limit per page.
931
1024
  *
932
1025
  * @returns {@link ApiPerpetualsAccountCollateralHistoryResponse} containing
933
- * an array of changes and a `nextBeforeTimestampCursor`.
1026
+ * an array of changes and a `nextBeforeTimestampCursor`.
934
1027
  */
935
1028
  getCollateralHistory(inputs) {
936
1029
  return __awaiter(this, void 0, void 0, function* () {
@@ -940,18 +1033,39 @@ class PerpetualsAccount extends caller_1.Caller {
940
1033
  /**
941
1034
  * Fetch paginated order history for this account.
942
1035
  *
1036
+ * This endpoint is distinct from {@link getOrderDatas}:
1037
+ * - `getOrderDatas` resolves current/pending orders based on the snapshot.
1038
+ * - `getOrderHistory` returns historical order events (fills, cancels, etc.)
1039
+ * over time with cursor-based pagination.
1040
+ *
943
1041
  * @param inputs.beforeTimestampCursor - Optional cursor for pagination.
944
1042
  * @param inputs.limit - Optional limit per page.
945
1043
  *
946
1044
  * @returns {@link ApiPerpetualsAccountOrderHistoryResponse} containing a list of
947
- * orders and a `nextBeforeTimestampCursor`.
1045
+ * orders and a `nextBeforeTimestampCursor`.
948
1046
  */
949
1047
  getOrderHistory(inputs) {
950
1048
  return __awaiter(this, void 0, void 0, function* () {
951
1049
  return this.fetchApi("account/order-history", Object.assign(Object.assign({}, inputs), { accountId: this.accountCap.accountId }));
952
1050
  });
953
1051
  }
954
- // TODO: docs
1052
+ /**
1053
+ * Fetch historical margin snapshots for this account over a time range.
1054
+ *
1055
+ * This endpoint returns time-series margin data suitable for charting UI
1056
+ * such as equity and available collateral over time.
1057
+ *
1058
+ * Inputs:
1059
+ * - `fromTimestamp` / `toTimestamp` are Unix timestamps in **milliseconds**.
1060
+ * - `intervalMs` controls the resolution (e.g. 60_000 for 1-minute points).
1061
+ *
1062
+ * Notes:
1063
+ * - Returned points are typically aligned to the requested interval.
1064
+ * - This is an account-level view (aggregated across markets).
1065
+ *
1066
+ * @param inputs - {@link ApiPerpetualsAccountMarginHistoryBody} without `accountId`.
1067
+ * @returns {@link ApiPerpetualsAccountMarginHistoryResponse} containing `marginHistoryDatas`.
1068
+ */
955
1069
  getMarginHistory(inputs) {
956
1070
  return __awaiter(this, void 0, void 0, function* () {
957
1071
  return this.fetchApi("account/margin-history", Object.assign(Object.assign({}, inputs), { accountId: this.accountCap.accountId }));
@@ -988,6 +1102,10 @@ class PerpetualsAccount extends caller_1.Caller {
988
1102
  * A stop order is considered SL/TP if it appears in the combined set of
989
1103
  * SL/TP orders across **all** markets (see {@link slTpStopOrderDatas}).
990
1104
  *
1105
+ * Note:
1106
+ * - This implementation uses JSON string equality to compare objects.
1107
+ * This is pragmatic but assumes stable field ordering and identical shapes.
1108
+ *
991
1109
  * @param inputs.stopOrderDatas - Full array of stop-order ticket data.
992
1110
  * @returns An array of non-SL/TP stop orders, or `undefined` if none exist.
993
1111
  */
@@ -1011,6 +1129,9 @@ class PerpetualsAccount extends caller_1.Caller {
1011
1129
  * - "Full" SL/TP orders (size >= `i64MaxBigInt`)
1012
1130
  * - "Partial" SL/TP orders (size < `i64MaxBigInt`)
1013
1131
  *
1132
+ * The "full vs partial" distinction is a protocol convention: some systems
1133
+ * encode “close entire position” using a sentinel max size.
1134
+ *
1014
1135
  * @param inputs.stopOrderDatas - Full list of stop-order tickets.
1015
1136
  * @returns Array of SL/TP stop orders, or `undefined` if none exist.
1016
1137
  */
@@ -1064,6 +1185,10 @@ class PerpetualsAccount extends caller_1.Caller {
1064
1185
  * - Order side is opposite of the position side.
1065
1186
  * - At least a `stopLossIndexPrice` or `takeProfitIndexPrice` is set.
1066
1187
  *
1188
+ * Notes on matching:
1189
+ * - The side comparison uses the current position side derived from the account snapshot.
1190
+ * - If `baseAssetAmount === 0` (no effective position), the method returns no SL/TP orders.
1191
+ *
1067
1192
  * @param inputs.marketId - Market to categorize stop orders for.
1068
1193
  * @param inputs.stopOrderDatas - Full list of stop orders.
1069
1194
  *
@@ -1081,7 +1206,14 @@ class PerpetualsAccount extends caller_1.Caller {
1081
1206
  };
1082
1207
  }
1083
1208
  const side = !position ? undefined : perpetuals_1.Perpetuals.positionSide(position);
1084
- // TODO: clean this up
1209
+ /**
1210
+ * Implementation note:
1211
+ *
1212
+ * This method uses a pair of predicates that differ only by the `size` threshold
1213
+ * to split “full close” SL/TP from “partial close” SL/TP. The sentinel threshold
1214
+ * is {@link Casting.i64MaxBigInt}. Keeping the logic explicit (rather than
1215
+ * abstracting into helpers) makes it easier to reason about protocol conventions.
1216
+ */
1085
1217
  const fullSlTpOrder = stopOrderDatas.find((order) => order.marketId === marketId &&
1086
1218
  order.slTp &&
1087
1219
  order.side !== side &&
@@ -1102,6 +1234,9 @@ class PerpetualsAccount extends caller_1.Caller {
1102
1234
  /**
1103
1235
  * Convenience accessor for the account's available collateral (in coin units).
1104
1236
  *
1237
+ * This is the amount of collateral not currently locked/allocated across markets,
1238
+ * as represented by the backend response.
1239
+ *
1105
1240
  * @returns Available collateral as a `number`.
1106
1241
  */
1107
1242
  collateral() {
@@ -1127,20 +1262,26 @@ class PerpetualsAccount extends caller_1.Caller {
1127
1262
  /**
1128
1263
  * Resolve the owner wallet address of this account or vault.
1129
1264
  *
1130
- * - For direct accounts, returns the `walletAddress` field.
1131
- * - For vault-backed accounts, returns `ownerAddress`.
1265
+ * - For direct accounts, returns the cap's `walletAddress` field.
1266
+ * - For vault-backed accounts, returns the vault cap's `ownerAddress`.
1267
+ *
1268
+ * Naming note:
1269
+ * - Some types use `walletAddress` for direct ownership. For vault-backed accounts
1270
+ * the analogous field is `ownerAddress`.
1132
1271
  *
1133
1272
  * @returns Owner wallet {@link SuiAddress}.
1134
1273
  */
1135
1274
  ownerAddress() {
1136
1275
  return "walletAddress" in this.accountCap
1137
- ? // TODO: change to ownerAddress ?
1276
+ ? // NOTE: direct accounts expose `walletAddress`; vault accounts expose `ownerAddress`.
1138
1277
  this.accountCap.walletAddress
1139
1278
  : this.accountCap.ownerAddress;
1140
1279
  }
1141
1280
  /**
1142
1281
  * Get the underlying account object ID.
1143
1282
  *
1283
+ * This is the on-chain object that holds the account's state and positions.
1284
+ *
1144
1285
  * @returns {@link ObjectId} of the account object.
1145
1286
  */
1146
1287
  accountObjectId() {
@@ -1149,6 +1290,8 @@ class PerpetualsAccount extends caller_1.Caller {
1149
1290
  /**
1150
1291
  * Get the numeric perpetuals account ID.
1151
1292
  *
1293
+ * This is the protocol-level identifier (bigint-derived) used across API calls.
1294
+ *
1152
1295
  * @returns {@link PerpetualsAccountId} for this account.
1153
1296
  */
1154
1297
  accountId() {
@@ -1157,12 +1300,13 @@ class PerpetualsAccount extends caller_1.Caller {
1157
1300
  /**
1158
1301
  * Get the account cap object ID, if this is a direct account.
1159
1302
  *
1160
- * **Note:** This is **not** available for vault-backed accounts and will
1161
- * throw an error if called on one.
1303
+ * Direct accounts are controlled via an on-chain “cap” object. Vault-backed
1304
+ * accounts are controlled via vault caps and do not expose a direct account-cap ID.
1305
+ *
1306
+ * @throws If called for a vault-backed account.
1162
1307
  *
1163
1308
  * @returns {@link ObjectId} of the account cap.
1164
1309
  */
1165
- // TODO: make this work with vaults
1166
1310
  accountCapId() {
1167
1311
  if ("vaultId" in this.accountCap)
1168
1312
  throw new Error("not account cap id present on vault owned account");