aftermath-ts-sdk 1.3.23-perps.35 → 1.3.23-perps.37

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,10 +24,52 @@ exports.PerpetualsVault = void 0;
24
24
  const transactions_1 = require("@mysten/sui/transactions");
25
25
  const caller_1 = require("../../general/utils/caller");
26
26
  const perpetuals_1 = require("./perpetuals");
27
+ /**
28
+ * High-level wrapper around a single Perpetuals vault.
29
+ *
30
+ * A vault is a managed perpetuals account that accepts user deposits (LP),
31
+ * trades across up to a bounded set of markets, and supports withdrawals via
32
+ * a request flow.
33
+ *
34
+ * This class provides:
35
+ *
36
+ * - Transaction builders for:
37
+ * - User actions (deposit, create/cancel withdraw request, update slippage)
38
+ * - Force-withdraw processing (close positions and settle a request)
39
+ * - Owner admin actions (update params, process requests, withdraw fees/collateral)
40
+ * - Read helpers for:
41
+ * - Vault withdraw requests
42
+ * - LP token pricing
43
+ * - Accessing the vault’s underlying perpetuals account
44
+ * - Static validation helpers for LP coin metadata (name/symbol constraints)
45
+ * - A small calculation helper for withdraw-request slippage
46
+ *
47
+ * Typical usage:
48
+ *
49
+ * ```ts
50
+ * const perps = afSdk.Perpetuals();
51
+ * const { vaults } = await perps.getAllVaults();
52
+ * const vault = vaults[0];
53
+ *
54
+ * const { tx } = await vault.getDepositTx({
55
+ * walletAddress: "0x...",
56
+ * depositAmount: BigInt("1000000000"),
57
+ * minLpAmountOut: 0n,
58
+ * });
59
+ * ```
60
+ */
27
61
  class PerpetualsVault extends caller_1.Caller {
28
62
  // =========================================================================
29
63
  // Constructor
30
64
  // =========================================================================
65
+ /**
66
+ * Create a new {@link PerpetualsVault} wrapper.
67
+ *
68
+ * @param vaultObject - Raw on-chain vault object snapshot.
69
+ * @param config - Optional {@link CallerConfig} (network, auth, base URL).
70
+ * @param Provider - Optional shared {@link AftermathApi} provider. When provided,
71
+ * transaction builders will serialize {@link Transaction}s into `txKind`.
72
+ */
31
73
  constructor(vaultObject, config, Provider) {
32
74
  super(config, "perpetuals");
33
75
  this.vaultObject = vaultObject;
@@ -39,129 +81,233 @@ class PerpetualsVault extends caller_1.Caller {
39
81
  // =========================================================================
40
82
  // Withdraw Request Txs
41
83
  // =========================================================================
84
+ /**
85
+ * Build a `process-force-withdraw-request` transaction.
86
+ *
87
+ * Force-withdraw is a mechanism that closes required positions and processes
88
+ * a withdraw request after a delay window (see vault params).
89
+ *
90
+ * @param inputs.walletAddress - User wallet that owns the withdraw request.
91
+ * @param inputs.sizesToClose - Mapping of marketId -> size (base units) to close.
92
+ * @param inputs.recipientAddress - Optional recipient of the withdrawn collateral.
93
+ * @param inputs.tx - Optional transaction to extend.
94
+ *
95
+ * @returns Transaction response containing `tx` (and any additional outputs
96
+ * provided by the backend response type).
97
+ */
42
98
  getProcessForceWithdrawRequestTx(inputs) {
43
99
  return __awaiter(this, void 0, void 0, function* () {
44
100
  var _a;
45
101
  const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
46
- return this.fetchApiTxObject("vault/transactions/process-force-withdraw-request", Object.assign(Object.assign({}, otherInputs), {
47
- // NOTE: should this be `vaultIds` ?
48
- vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
102
+ return this.fetchApiTxObject("vault/transactions/process-force-withdraw-request", Object.assign(Object.assign({}, otherInputs), { vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
49
103
  tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
50
- })) }), undefined, {
51
- txKind: true,
52
- });
104
+ })) }), undefined, { txKind: true });
53
105
  });
54
106
  }
107
+ /**
108
+ * Build an `update-withdraw-request-slippage` transaction.
109
+ *
110
+ * This updates the user's minimum acceptable collateral output amount
111
+ * for an existing withdraw request.
112
+ *
113
+ * @param inputs.minCollateralAmountOut - New minimum collateral amount out.
114
+ * @param inputs.tx - Optional transaction to extend.
115
+ *
116
+ * @returns Transaction response containing `tx`.
117
+ */
55
118
  getUpdateWithdrawRequestSlippageTx(inputs) {
56
119
  return __awaiter(this, void 0, void 0, function* () {
57
120
  var _a;
58
121
  const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
59
122
  return this.fetchApiTxObject("vault/transactions/update-withdraw-request-slippage", Object.assign(Object.assign({}, otherInputs), { vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
60
123
  tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
61
- })) }), undefined, {
62
- txKind: true,
63
- });
124
+ })) }), undefined, { txKind: true });
64
125
  });
65
126
  }
66
127
  // =========================================================================
67
128
  // Owner Settings Txs
68
129
  // =========================================================================
130
+ /**
131
+ * Build an owner transaction to update the vault's force withdraw delay.
132
+ *
133
+ * @param inputs.forceWithdrawDelayMs - New delay (ms). Should be <= {@link constants.maxForceWithdrawDelayMs}.
134
+ * @param inputs.tx - Optional transaction to extend.
135
+ *
136
+ * @returns Transaction response containing `tx`.
137
+ */
69
138
  getOwnerUpdateForceWithdrawDelayTx(inputs) {
70
139
  return __awaiter(this, void 0, void 0, function* () {
71
140
  var _a;
72
141
  const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
73
142
  return this.fetchApiTxObject("vault/transactions/owner/update-force-withdraw-delay", Object.assign(Object.assign({}, otherInputs), { vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
74
143
  tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
75
- })) }), undefined, {
76
- txKind: true,
77
- });
144
+ })) }), undefined, { txKind: true });
78
145
  });
79
146
  }
147
+ /**
148
+ * Build an owner transaction to update the vault's lock period.
149
+ *
150
+ * @param inputs.lockPeriodMs - New lock period (ms). Should be <= {@link constants.maxLockPeriodMs}.
151
+ * @param inputs.tx - Optional transaction to extend.
152
+ *
153
+ * @returns Transaction response containing `tx`.
154
+ */
80
155
  getOwnerUpdateLockPeriodTx(inputs) {
81
156
  return __awaiter(this, void 0, void 0, function* () {
82
157
  var _a;
83
158
  const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
84
159
  return this.fetchApiTxObject("vault/transactions/owner/update-lock-period", Object.assign(Object.assign({}, otherInputs), { vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
85
160
  tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
86
- })) }), undefined, {
87
- txKind: true,
88
- });
161
+ })) }), undefined, { txKind: true });
89
162
  });
90
163
  }
164
+ /**
165
+ * Build an owner transaction to update the vault performance fee.
166
+ *
167
+ * @param inputs.performanceFeePercentage - New fee as a fraction (e.g. `0.2` = 20%).
168
+ * Should be <= {@link constants.maxPerformanceFeePercentage}.
169
+ * @param inputs.tx - Optional transaction to extend.
170
+ *
171
+ * @returns Transaction response containing `tx`.
172
+ */
91
173
  getOwnerUpdatePerformanceFeeTx(inputs) {
92
174
  return __awaiter(this, void 0, void 0, function* () {
93
175
  var _a;
94
176
  const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
95
177
  return this.fetchApiTxObject("vault/transactions/owner/update-performance-fee", Object.assign(Object.assign({}, otherInputs), { vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
96
178
  tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
97
- })) }), undefined, {
98
- txKind: true,
99
- });
179
+ })) }), undefined, { txKind: true });
100
180
  });
101
181
  }
102
182
  // =========================================================================
103
183
  // Owner Interactions Txs
104
184
  // =========================================================================
185
+ /**
186
+ * Build an owner transaction to process one or more users' withdraw requests.
187
+ *
188
+ * This is the normal (non-force) processing path for withdrawals. The owner
189
+ * batches users and settles their requests in a single transaction.
190
+ *
191
+ * @param inputs.userAddresses - Users whose requests should be processed.
192
+ * @param inputs.tx - Optional transaction to extend.
193
+ *
194
+ * @returns Transaction response containing `tx`.
195
+ */
105
196
  getOwnerProcessWithdrawRequestsTx(inputs) {
106
197
  return __awaiter(this, void 0, void 0, function* () {
107
198
  var _a;
108
199
  const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
109
- return this.fetchApiTxObject("vault/transactions/owner/process-withdraw-requests", Object.assign(Object.assign({}, otherInputs), {
110
- // NOTE: should this be `vaultIds` ?
111
- vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
200
+ return this.fetchApiTxObject("vault/transactions/owner/process-withdraw-requests", Object.assign(Object.assign({}, otherInputs), { vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
112
201
  tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
113
- })) }), undefined, {
114
- txKind: true,
115
- });
202
+ })) }), undefined, { txKind: true });
116
203
  });
117
204
  }
205
+ /**
206
+ * Build an owner transaction to withdraw accrued performance fees.
207
+ *
208
+ * @param inputs.withdrawAmount - Amount of collateral to withdraw as fees.
209
+ * @param inputs.recipientAddress - Optional recipient address for the withdrawn fees.
210
+ * @param inputs.tx - Optional transaction to extend.
211
+ *
212
+ * @returns Response containing `tx` and any extra outputs described by
213
+ * {@link ApiPerpetualsVaultOwnerWithdrawPerformanceFeesTxResponse}.
214
+ */
118
215
  getOwnerWithdrawPerformanceFeesTx(inputs) {
119
216
  return __awaiter(this, void 0, void 0, function* () {
120
217
  var _a;
121
218
  const { tx: txFromInputs } = inputs, otherInputs = __rest(inputs, ["tx"]);
122
219
  return this.fetchApiTxObject("vault/transactions/owner/withdraw-performance-fees", Object.assign(Object.assign({}, otherInputs), { vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
123
220
  tx: txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction(),
124
- })) }), undefined, {
125
- txKind: true,
126
- });
221
+ })) }), undefined, { txKind: true });
127
222
  });
128
223
  }
224
+ /**
225
+ * Build an owner transaction to withdraw vault collateral by redeeming LP.
226
+ *
227
+ * @param inputs.lpWithdrawAmount - Amount of LP to redeem.
228
+ * @param inputs.minCollateralAmountOut - Minimum collateral out to protect from slippage.
229
+ * @param inputs.recipientAddress - Optional recipient address for withdrawn collateral.
230
+ * @param inputs.tx - Optional transaction to extend.
231
+ *
232
+ * @returns Response containing `tx` and any extra outputs described by
233
+ * {@link ApiPerpetualsVaultOwnerWithdrawCollateralTxResponse}.
234
+ */
129
235
  getOwnerWithdrawCollateralTx(inputs) {
130
236
  return __awaiter(this, void 0, void 0, function* () {
131
237
  var _a;
132
238
  const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
133
239
  return this.fetchApiTxObject("vault/transactions/owner/withdraw-collateral", Object.assign(Object.assign({}, otherInputs), { vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
134
240
  tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
135
- })) }), undefined, {
136
- txKind: true,
137
- });
241
+ })) }), undefined, { txKind: true });
138
242
  });
139
243
  }
140
244
  // =========================================================================
141
245
  // User Interactions Txs
142
246
  // =========================================================================
247
+ /**
248
+ * Build a user transaction to create a vault withdraw request.
249
+ *
250
+ * Withdrawals are request-based: the user specifies how much LP to redeem
251
+ * and a minimum collateral output amount.
252
+ *
253
+ * @param inputs.walletAddress - Wallet creating the request.
254
+ * @param inputs.lpWithdrawAmount - Amount of LP to withdraw.
255
+ * @param inputs.minCollateralAmountOut - Minimum collateral out (slippage guard).
256
+ * @param inputs.tx - Optional transaction to extend.
257
+ *
258
+ * @returns Transaction response containing `tx`.
259
+ */
143
260
  getCreateWithdrawRequestTx(inputs) {
144
261
  return __awaiter(this, void 0, void 0, function* () {
145
262
  var _a;
146
263
  const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
147
264
  return this.fetchApiTxObject("vault/transactions/create-withdraw-request", Object.assign(Object.assign({}, otherInputs), { vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
148
265
  tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
149
- })) }), undefined, {
150
- txKind: true,
151
- });
266
+ })) }), undefined, { txKind: true });
152
267
  });
153
268
  }
269
+ /**
270
+ * Build a user transaction to cancel an existing vault withdraw request.
271
+ *
272
+ * @param inputs.walletAddress - Wallet canceling the request.
273
+ * @param inputs.tx - Optional transaction to extend.
274
+ *
275
+ * @returns Transaction response containing `tx`.
276
+ */
154
277
  getCancelWithdrawRequestTx(inputs) {
155
278
  return __awaiter(this, void 0, void 0, function* () {
156
279
  var _a;
157
280
  const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
158
281
  return this.fetchApiTxObject("vault/transactions/cancel-withdraw-request", Object.assign(Object.assign({}, otherInputs), { vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
159
282
  tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
160
- })) }), undefined, {
161
- txKind: true,
162
- });
283
+ })) }), undefined, { txKind: true });
163
284
  });
164
285
  }
286
+ /**
287
+ * Build a user transaction to deposit collateral into the vault in exchange for LP.
288
+ *
289
+ * You can specify the deposit as:
290
+ * - `depositAmount` (wallet pays directly), OR
291
+ * - `depositCoinArg` (use an existing transaction argument)
292
+ *
293
+ * @param inputs.walletAddress - Depositor wallet.
294
+ * @param inputs.minLpAmountOut - Minimum LP out (slippage guard).
295
+ * @param inputs.isSponsoredTx - Whether the tx is sponsored (gas paid by another party).
296
+ * @param inputs.depositAmount - Amount of collateral to deposit (mutually exclusive with `depositCoinArg`).
297
+ * @param inputs.depositCoinArg - Transaction argument referencing collateral coin.
298
+ * @param inputs.tx - Optional transaction to extend.
299
+ *
300
+ * @returns Transaction response containing `tx`.
301
+ *
302
+ * @example
303
+ * ```ts
304
+ * const { txKind } = await vault.getDepositTx({
305
+ * walletAddress: "0x...",
306
+ * depositAmount: 1_000_000_000n,
307
+ * minLpAmountOut: 0n,
308
+ * });
309
+ * ```
310
+ */
165
311
  // TODO: make return lp coin out ?
166
312
  getDepositTx(inputs) {
167
313
  return __awaiter(this, void 0, void 0, function* () {
@@ -172,45 +318,50 @@ class PerpetualsVault extends caller_1.Caller {
172
318
  depositAmount: otherInputs.depositAmount,
173
319
  collateralCoinType: this.vaultObject.collateralCoinType,
174
320
  }
175
- : {
176
- depositCoinArg: otherInputs.depositCoinArg,
177
- };
321
+ : { depositCoinArg: otherInputs.depositCoinArg };
178
322
  return this.fetchApiTxObject("vault/transactions/deposit", Object.assign(Object.assign(Object.assign({}, otherInputs), depositInputs), { vaultId: this.vaultObject.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
179
323
  tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
180
- })) }), undefined, {
181
- txKind: true,
182
- });
324
+ })) }), undefined, { txKind: true });
183
325
  });
184
326
  }
185
327
  // =========================================================================
186
328
  // Objects
187
329
  // =========================================================================
330
+ /**
331
+ * Fetch all withdraw requests for this vault.
332
+ *
333
+ * @returns {@link ApiPerpetualsVaultsWithdrawRequestsResponse} containing requests
334
+ * scoped to `this.vaultObject.objectId`.
335
+ *
336
+ * @remarks
337
+ * This currently calls the `vaults/withdraw-requests` endpoint with a single vault ID.
338
+ * This may be moved to {@link Perpetuals} as a shared helper.
339
+ */
188
340
  // TODO: move to `Perpetuals` (as well) ?
189
341
  getAllWithdrawRequests() {
190
342
  return this.fetchApi("vaults/withdraw-requests", {
191
343
  vaultIds: [this.vaultObject.objectId],
192
344
  });
193
345
  }
194
- // // TODO: add to perps account as well ?
195
- // public async getWithdrawRequestsForUser(inputs: {
196
- // walletAddress: SuiAddress;
197
- // }) {
198
- // return this.fetchApi<
199
- // PerpetualsVaultWithdrawRequest[],
200
- // ApiPerpetualsVaultWithdrawRequestsBody
201
- // >("owned-withdraw-requests", {
202
- // ...inputs,
203
- // vaultIds: [this.vaultObject.objectId],
204
- // });
205
- // }
206
346
  // =========================================================================
207
347
  // Owner Previews
208
348
  // =========================================================================
349
+ /**
350
+ * Preview the results of an owner processing one or more withdraw requests.
351
+ *
352
+ * @param inputs.userAddresses - Users to process.
353
+ * @returns Preview response with expected effects.
354
+ */
209
355
  getPreviewOwnerProcessWithdrawRequests(inputs) {
210
356
  return __awaiter(this, void 0, void 0, function* () {
211
357
  return this.fetchApi("vault/previews/owner/process-withdraw-requests", Object.assign(Object.assign({}, inputs), { vaultId: this.vaultObject.objectId }));
212
358
  });
213
359
  }
360
+ /**
361
+ * Preview the amount available for the owner to withdraw as performance fees.
362
+ *
363
+ * @returns Preview response including withdrawable fees and related metadata.
364
+ */
214
365
  getPreviewOwnerWithdrawPerformanceFees() {
215
366
  return __awaiter(this, void 0, void 0, function* () {
216
367
  return this.fetchApi("vault/previews/owner/withdraw-performance-fees", {
@@ -218,6 +369,12 @@ class PerpetualsVault extends caller_1.Caller {
218
369
  });
219
370
  });
220
371
  }
372
+ /**
373
+ * Preview an owner collateral withdrawal (LP redemption).
374
+ *
375
+ * @param inputs.lpWithdrawAmount - LP amount to redeem.
376
+ * @returns Preview response including estimated collateral out.
377
+ */
221
378
  getPreviewOwnerWithdrawCollateral(inputs) {
222
379
  return __awaiter(this, void 0, void 0, function* () {
223
380
  return this.fetchApi("vault/previews/owner/withdraw-collateral", Object.assign(Object.assign({}, inputs), { vaultId: this.vaultObject.objectId }));
@@ -226,16 +383,38 @@ class PerpetualsVault extends caller_1.Caller {
226
383
  // =========================================================================
227
384
  // User Previews
228
385
  // =========================================================================
386
+ /**
387
+ * Preview creating a withdraw request.
388
+ *
389
+ * @param inputs.walletAddress - Requesting wallet.
390
+ * @param inputs.lpWithdrawAmount - LP amount to withdraw.
391
+ * @returns Preview response including estimated collateral out and constraints.
392
+ */
229
393
  getPreviewCreateWithdrawRequest(inputs) {
230
394
  return __awaiter(this, void 0, void 0, function* () {
231
395
  return this.fetchApi("vault/previews/create-withdraw-request", Object.assign(Object.assign({}, inputs), { vaultId: this.vaultObject.objectId }));
232
396
  });
233
397
  }
398
+ /**
399
+ * Preview depositing into the vault.
400
+ *
401
+ * @param inputs.depositAmount - Deposit amount in collateral coin units.
402
+ * @returns Preview response including estimated LP out.
403
+ */
234
404
  getPreviewDeposit(inputs) {
235
405
  return __awaiter(this, void 0, void 0, function* () {
236
406
  return this.fetchApi("vault/previews/deposit", Object.assign(Object.assign({}, inputs), { vaultId: this.vaultObject.objectId }));
237
407
  });
238
408
  }
409
+ /**
410
+ * Preview processing a force withdraw request for a user.
411
+ *
412
+ * This is useful to determine what positions/sizes must be closed or what
413
+ * the expected outputs are prior to building the actual transaction.
414
+ *
415
+ * @param inputs.walletAddress - User wallet with a pending force-withdraw.
416
+ * @returns Preview response describing expected processing effects.
417
+ */
239
418
  getPreviewProcessForceWithdrawRequest(inputs) {
240
419
  return __awaiter(this, void 0, void 0, function* () {
241
420
  return this.fetchApi("vault/previews/process-force-withdraw-request", Object.assign(Object.assign({}, inputs), { vaultId: this.vaultObject.objectId }));
@@ -244,6 +423,13 @@ class PerpetualsVault extends caller_1.Caller {
244
423
  // =========================================================================
245
424
  // Inspections
246
425
  // =========================================================================
426
+ /**
427
+ * Fetch the current LP coin price for this vault (in collateral units).
428
+ *
429
+ * Internally calls {@link Perpetuals.getLpCoinPrices} and returns the first price.
430
+ *
431
+ * @returns LP coin price as a `number`.
432
+ */
247
433
  getLpCoinPrice() {
248
434
  return __awaiter(this, void 0, void 0, function* () {
249
435
  return (yield new perpetuals_1.Perpetuals(this.config, this.Provider).getLpCoinPrices({
@@ -254,6 +440,12 @@ class PerpetualsVault extends caller_1.Caller {
254
440
  // =========================================================================
255
441
  // Account
256
442
  // =========================================================================
443
+ /**
444
+ * Build a lightweight “cap-like” object for the vault’s underlying account.
445
+ *
446
+ * @returns {@link PerpetualsPartialVaultCap} suitable for account fetch helpers
447
+ * such as {@link Perpetuals.getAccount}.
448
+ */
257
449
  partialVaultCap() {
258
450
  return {
259
451
  vaultId: this.vaultObject.objectId,
@@ -263,6 +455,11 @@ class PerpetualsVault extends caller_1.Caller {
263
455
  collateralCoinType: this.vaultObject.collateralCoinType,
264
456
  };
265
457
  }
458
+ /**
459
+ * Fetch the underlying perpetuals account object for this vault.
460
+ *
461
+ * @returns `{ account }` where `account` is the on-chain {@link PerpetualsAccountObject}.
462
+ */
266
463
  getAccountObject() {
267
464
  return __awaiter(this, void 0, void 0, function* () {
268
465
  return {
@@ -272,6 +469,11 @@ class PerpetualsVault extends caller_1.Caller {
272
469
  };
273
470
  });
274
471
  }
472
+ /**
473
+ * Fetch a {@link PerpetualsAccount} wrapper for the vault’s underlying account.
474
+ *
475
+ * @returns `{ account }` where `account` is a high-level {@link PerpetualsAccount}.
476
+ */
275
477
  getAccount() {
276
478
  return __awaiter(this, void 0, void 0, function* () {
277
479
  return new perpetuals_1.Perpetuals(this.config, this.Provider).getAccount({
@@ -284,10 +486,14 @@ exports.PerpetualsVault = PerpetualsVault;
284
486
  // =========================================================================
285
487
  // Public Constants
286
488
  // =========================================================================
489
+ /**
490
+ * Vault-level protocol limits and UI-friendly constraints.
491
+ *
492
+ * @remarks
493
+ * These are SDK constants (not fetched from chain). They should match the
494
+ * on-chain / backend limits enforced by the vault module.
495
+ */
287
496
  PerpetualsVault.constants = {
288
- // NOTE: what is this ?
289
- // /// Time necessary for the next vault's params update
290
- // vaultParamsUpdateFrequency: 28800000, // 8hrs
291
497
  /**
292
498
  * Maximum lock period in milliseconds.
293
499
  */
@@ -297,11 +503,11 @@ PerpetualsVault.constants = {
297
503
  */
298
504
  maxForceWithdrawDelayMs: 86400000, // 1 day
299
505
  /**
300
- * Maximum vault fee.
506
+ * Maximum vault fee (performance fee).
301
507
  */
302
508
  maxPerformanceFeePercentage: 0.2, // 20%
303
509
  /**
304
- * Minimum USD value required for users deposits.
510
+ * Minimum USD value required for user deposits.
305
511
  */
306
512
  minDepositUsd: 1,
307
513
  /**
@@ -309,11 +515,11 @@ PerpetualsVault.constants = {
309
515
  */
310
516
  minOwnerLockUsd: 1,
311
517
  /**
312
- * The maximum number of distinct `ClearingHouse`.
518
+ * The maximum number of distinct markets (`ClearingHouse`s) the vault can trade.
313
519
  */
314
520
  maxMarketsInVault: 12,
315
521
  /**
316
- * The maximum number of pending orders allowed for a single position in the `Vault`.
522
+ * The maximum number of pending orders allowed for a single position in the vault.
317
523
  */
318
524
  maxPendingOrdersPerPosition: 70,
319
525
  };
@@ -324,16 +530,22 @@ PerpetualsVault.constants = {
324
530
  * Checks if a string is a valid LP coin name.
325
531
  *
326
532
  * @param value - The string to check.
327
- * @returns `true` if `value` is can be used as a valid LP coin name, otherwise `false`.
533
+ * @returns `true` if `value` can be used as a valid LP coin name, otherwise `false`.
534
+ *
535
+ * @remarks
536
+ * Current rule: ASCII-only. This aligns with many on-chain metadata constraints.
328
537
  */
329
538
  PerpetualsVault.isValidLpCoinName = (value) => {
330
539
  return /^[\x00-\x7F]+$/.test(value);
331
540
  };
332
541
  /**
333
- * Checks if a string is a valid LP coin type.
542
+ * Checks if a string is a valid LP coin type symbol.
334
543
  *
335
544
  * @param value - The string to check.
336
- * @returns `true` if `value` is can be used as a valid LP coin type, otherwise `false`.
545
+ * @returns `true` if `value` can be used as a valid LP coin type symbol, otherwise `false`.
546
+ *
547
+ * @remarks
548
+ * Current rule: uppercase A–Z plus underscore.
337
549
  */
338
550
  PerpetualsVault.isValidLpCoinTypeSymbol = (value) => {
339
551
  return /^[A-Z_]+$/.test(value);
@@ -341,6 +553,17 @@ PerpetualsVault.isValidLpCoinTypeSymbol = (value) => {
341
553
  // =========================================================================
342
554
  // Calculations
343
555
  // =========================================================================
556
+ /**
557
+ * Compute the implied slippage tolerance for a withdraw request.
558
+ *
559
+ * Defined as:
560
+ * ```text
561
+ * (lpAmountInUsd - minCollateralAmountOutUsd) / lpAmountInUsd
562
+ * ```
563
+ *
564
+ * @param inputs.withdrawRequest - Withdraw request to analyze.
565
+ * @returns Slippage fraction (0..1). Returns `0` if `lpAmountInUsd` is missing/zero.
566
+ */
344
567
  PerpetualsVault.calcWithdrawRequestSlippage = (inputs) => {
345
568
  const { withdrawRequest } = inputs;
346
569
  return withdrawRequest.lpAmountInUsd
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aftermath-ts-sdk",
3
- "version": "1.3.23-perps.35",
3
+ "version": "1.3.23-perps.37",
4
4
  "description": "Aftermath TypeScript SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",