aftermath-ts-sdk 1.3.23-perps.26 → 1.3.23-perps.28

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.
@@ -1,73 +1,397 @@
1
1
  import { Caller } from "../../general/utils/caller";
2
- import { PerpetualsMarketId, ApiPerpetualsOwnedAccountCapsBody, PerpetualsOrderSide, CoinType, PerpetualsOrderId, FilledTakerOrderEvent, Timestamp, ApiPerpetualsHistoricalMarketDataResponse, PerpetualsAccountCap, PerpetualsAccountId, PerpetualsAccountObject, CallerConfig, SuiAddress, ObjectId, ApiPerpetualsMarkets24hrStatsResponse, ApiPerpetualsAccountCapsBody, Percentage, Balance, PerpetualsVaultCap, PerpetualsVaultWithdrawRequest, PerpetualsVaultCapExtended, PerpetualsOrderPrice, ApiTransactionResponse, PerpetualsWsUpdatesResponseMessage, PerpetualsWsCandleResponseMessage, ApiPerpetualsCreateVaultCapBody } from "../../types";
2
+ import { PerpetualsMarketId, ApiPerpetualsOwnedAccountCapsBody, PerpetualsOrderSide, CoinType, PerpetualsOrderId, FilledTakerOrderEvent, Timestamp, ApiPerpetualsHistoricalMarketDataResponse, PerpetualsAccountCap, PerpetualsAccountId, PerpetualsAccountObject, CallerConfig, SuiAddress, ObjectId, ApiPerpetualsMarkets24hrStatsResponse, ApiPerpetualsAccountCapsBody, Percentage, Balance, PerpetualsVaultCap, PerpetualsVaultWithdrawRequest, PerpetualsOrderPrice, ApiTransactionResponse, PerpetualsWsUpdatesResponseMessage, PerpetualsWsCandleResponseMessage, ApiPerpetualsCreateVaultCapBody, PerpetualsVaultLpCoin, PerpetualsPartialVaultCap } from "../../types";
3
3
  import { PerpetualsMarket } from "./perpetualsMarket";
4
4
  import { PerpetualsAccount } from "./perpetualsAccount";
5
5
  import { PerpetualsOrderUtils } from "./utils";
6
6
  import { AftermathApi } from "../../general/providers";
7
7
  import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
8
8
  import { PerpetualsVault } from "./perpetualsVault";
9
+ /**
10
+ * High-level client for interacting with Aftermath Perpetuals.
11
+ *
12
+ * This class exposes a typed, ergonomic interface over the Perpetuals HTTP API
13
+ * and websocket endpoints, including:
14
+ *
15
+ * - Market discovery (`getAllMarkets`, `getMarkets`, `getMarket`)
16
+ * - Vault discovery (`getAllVaults`, `getVaults`, `getVault`)
17
+ * - Account & position data (`getAccount`, `getAccounts`, `getAccountObjects`)
18
+ * - Ownership queries (`getOwnedAccountCaps`, `getOwnedVaultCaps`)
19
+ * - Historical data & stats (`getMarketHistoricalData`, `getMarkets24hrStats`)
20
+ * - Pricing helpers (`getPrices`, `getLpCoinPrices`)
21
+ * - Transaction builders (`getCreateAccountTx`, `getCreateVaultCapTx`, `getCreateVaultTx`)
22
+ * - Websocket feeds (`openUpdatesWebsocketStream`, `openMarketCandlesWebsocketStream`)
23
+ *
24
+ * Typical usage via the root SDK:
25
+ *
26
+ * ```ts
27
+ * import { Aftermath } from "@aftermath/sdk";
28
+ *
29
+ * const afSdk = new Aftermath("MAINNET");
30
+ * await afSdk.init();
31
+ *
32
+ * const perps = afSdk.Perpetuals();
33
+ *
34
+ * // Fetch markets for a given collateral coin type
35
+ * const markets = await perps.getAllMarkets({
36
+ * collateralCoinType: "0x2::sui::SUI",
37
+ * });
38
+ *
39
+ * // Fetch account + positions for a given account cap
40
+ * const [accountCap] = await perps.getOwnedAccountCaps({
41
+ * walletAddress: "0x...",
42
+ * });
43
+ *
44
+ * const account = await perps.getAccount({ accountCap });
45
+ *
46
+ * // Build a create-account transaction (not signed or sent)
47
+ * const createAccountTx = await perps.getCreateAccountTx({
48
+ * walletAddress: "0x...",
49
+ * collateralCoinType: "0x2::sui::SUI",
50
+ * });
51
+ * ```
52
+ */
9
53
  export declare class Perpetuals extends Caller {
10
54
  readonly Provider?: AftermathApi | undefined;
55
+ /**
56
+ * Helper namespace for order-specific utilities such as parsing order IDs,
57
+ * extracting price bits, etc.
58
+ *
59
+ * This is a direct alias of {@link PerpetualsOrderUtils}.
60
+ */
11
61
  static readonly OrderUtils: typeof PerpetualsOrderUtils;
12
- static readonly constants: {
13
- stopOrderGasCostSUI: bigint;
14
- };
62
+ /**
63
+ * Creates a new Perpetuals client.
64
+ *
65
+ * @param config - Optional caller configuration (network, auth token, etc.).
66
+ * @param Provider - Optional shared {@link AftermathApi} provider instance. When
67
+ * provided, transaction-building helpers (e.g. `getCreateAccountTx`) can
68
+ * derive serialized `txKind` from a `Transaction` object.
69
+ */
15
70
  constructor(config?: CallerConfig, Provider?: AftermathApi | undefined);
71
+ /**
72
+ * Fetch all perpetual markets for a given collateral coin type.
73
+ *
74
+ * @param inputs.collateralCoinType - Coin type used as collateral, e.g. `"0x2::sui::SUI"`.
75
+ * @returns Array of {@link PerpetualsMarket} instances, each wrapping the raw market data.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * const markets = await perps.getAllMarkets({
80
+ * collateralCoinType: "0x2::sui::SUI",
81
+ * });
82
+ * ```
83
+ */
16
84
  getAllMarkets(inputs: {
17
85
  collateralCoinType: CoinType;
18
86
  }): Promise<PerpetualsMarket[]>;
87
+ /**
88
+ * Fetch a single market by ID.
89
+ *
90
+ * Internally calls {@link getMarkets} and returns the first entry.
91
+ *
92
+ * @param inputs.marketId - The market (clearing house) object ID.
93
+ * @returns A {@link PerpetualsMarket} instance corresponding to the given ID.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * const market = await perps.getMarket({ marketId: "0x..." });
98
+ * ```
99
+ */
19
100
  getMarket(inputs: {
20
101
  marketId: PerpetualsMarketId;
21
102
  }): Promise<PerpetualsMarket>;
103
+ /**
104
+ * Fetch multiple markets by ID.
105
+ *
106
+ * NOTE: the backend currently always returns market data together with an
107
+ * orderbook object, but this SDK helper ignores the orderbook and constructs
108
+ * {@link PerpetualsMarket} instances from the `market` field only.
109
+ *
110
+ * @param inputs.marketIds - Array of market object IDs to fetch.
111
+ * @returns Array of {@link PerpetualsMarket} objects in the same order as `marketIds`.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * const [marketA, marketB] = await perps.getMarkets({
116
+ * marketIds: ["0x..A", "0x..B"],
117
+ * });
118
+ * ```
119
+ */
22
120
  getMarkets(inputs: {
23
121
  marketIds: PerpetualsMarketId[];
24
122
  }): Promise<PerpetualsMarket[]>;
123
+ /**
124
+ * Fetch all vaults on the current network.
125
+ *
126
+ * @returns Array of {@link PerpetualsVault} objects, each wrapping a vault on-chain object.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * const vaults = await perps.getAllVaults();
131
+ * ```
132
+ */
25
133
  getAllVaults(): Promise<PerpetualsVault[]>;
134
+ /**
135
+ * Fetch a single vault by ID.
136
+ *
137
+ * Internally calls {@link getVaults} and returns the first entry.
138
+ *
139
+ * @param inputs.marketId - The vault object ID (note: named `marketId` for historical reasons).
140
+ * @returns A {@link PerpetualsVault} instance.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * const vault = await perps.getVault({ marketId: "0x..." });
145
+ * ```
146
+ */
26
147
  getVault(inputs: {
27
148
  marketId: ObjectId;
28
149
  }): Promise<PerpetualsVault>;
150
+ /**
151
+ * Fetch multiple vaults by ID.
152
+ *
153
+ * @param inputs.vaultIds - Array of vault object IDs.
154
+ * @returns Array of {@link PerpetualsVault} objects in the same order as `vaultIds`.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * const [vaultA, vaultB] = await perps.getVaults({
159
+ * vaultIds: ["0x..A", "0x..B"],
160
+ * });
161
+ * ```
162
+ */
29
163
  getVaults(inputs: {
30
164
  vaultIds: ObjectId[];
31
165
  }): Promise<PerpetualsVault[]>;
166
+ /**
167
+ * Convenience helper to fetch a single account (positions + account object) from an account cap.
168
+ *
169
+ * Internally calls {@link getAccounts} and returns the first entry.
170
+ *
171
+ * @param inputs.accountCap - Account-cap or vault-cap-extended object to derive account metadata from.
172
+ * @param inputs.marketIds - Optional list of markets to filter positions by.
173
+ * @returns A {@link PerpetualsAccount} instance.
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * const [accountCap] = await perps.getOwnedAccountCaps({ walletAddress: "0x..." });
178
+ * const account = await perps.getAccount({ accountCap });
179
+ * ```
180
+ */
32
181
  getAccount(inputs: {
33
- accountCap: PerpetualsAccountCap | PerpetualsVaultCapExtended;
182
+ accountCap: PerpetualsAccountCap | PerpetualsPartialVaultCap;
34
183
  marketIds?: PerpetualsMarketId[];
35
184
  }): Promise<PerpetualsAccount>;
185
+ /**
186
+ * Fetch one or more accounts (positions + account objects) from account caps.
187
+ *
188
+ * This composes two API calls:
189
+ * - `/perpetuals/accounts/positions` to fetch {@link PerpetualsAccountObject}s
190
+ * - Local pairing with the provided `accountCaps`
191
+ *
192
+ * The resulting {@link PerpetualsAccount} objects wrap both the on-chain account
193
+ * data and the cap metadata in a single helper.
194
+ *
195
+ * @param inputs.accountCaps - Array of account caps or vault-cap-extended objects.
196
+ * @param inputs.marketIds - Optional list of market IDs to filter positions by.
197
+ * @returns Array of {@link PerpetualsAccount} instances in the same order as `accountCaps`.
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * const accountCaps = await perps.getOwnedAccountCaps({ walletAddress: "0x..." });
202
+ * const accounts = await perps.getAccounts({ accountCaps });
203
+ * ```
204
+ */
36
205
  getAccounts(inputs: {
37
- accountCaps: (PerpetualsAccountCap | PerpetualsVaultCapExtended)[];
206
+ accountCaps: (PerpetualsAccountCap | PerpetualsPartialVaultCap)[];
38
207
  marketIds?: PerpetualsMarketId[];
39
208
  }): Promise<PerpetualsAccount[]>;
209
+ /**
210
+ * Fetch raw account objects (including positions) for one or more account IDs.
211
+ *
212
+ * @param inputs.accountIds - List of account IDs to query.
213
+ * @param inputs.collateralCoinType - Collateral coin type to use for valuation.
214
+ * @param inputs.marketIds - Optional list of market IDs to filter positions by.
215
+ * @returns Array of {@link PerpetualsAccountObject} in the same order as `accountIds`.
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * const accountObjects = await perps.getAccountObjects({
220
+ * accountIds: [123n, 456n],
221
+ * collateralCoinType: "0x2::sui::SUI",
222
+ * });
223
+ * ```
224
+ */
40
225
  getAccountObjects(inputs: {
41
226
  accountIds: PerpetualsAccountId[];
42
227
  collateralCoinType: CoinType;
43
228
  marketIds?: PerpetualsMarketId[];
44
229
  }): Promise<PerpetualsAccountObject[]>;
230
+ /**
231
+ * Fetch all account caps (perpetuals accounts) owned by a wallet, optionally
232
+ * filtered by collateral coin types.
233
+ *
234
+ * @param inputs.walletAddress - Owner wallet address.
235
+ * @param inputs.collateralCoinTypes - Optional list of collateral coin types to filter by.
236
+ * @returns Array of {@link PerpetualsAccountCap} objects.
237
+ *
238
+ * @example
239
+ * ```ts
240
+ * const caps = await perps.getOwnedAccountCaps({
241
+ * walletAddress: "0x...",
242
+ * collateralCoinTypes: ["0x2::sui::SUI"],
243
+ * });
244
+ * ```
245
+ */
45
246
  getOwnedAccountCaps(inputs: ApiPerpetualsOwnedAccountCapsBody & {
46
247
  collateralCoinTypes?: CoinType[];
47
248
  }): Promise<PerpetualsAccountCap[]>;
249
+ /**
250
+ * Fetch all vault caps owned by a wallet.
251
+ *
252
+ * @param inputs.walletAddress - Owner wallet address.
253
+ * @returns Array of {@link PerpetualsVaultCap} objects.
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * const vaultCaps = await perps.getOwnedVaultCaps({
258
+ * walletAddress: "0x...",
259
+ * });
260
+ * ```
261
+ */
48
262
  getOwnedVaultCaps(inputs: ApiPerpetualsOwnedAccountCapsBody): Promise<PerpetualsVaultCap[]>;
49
- getOwnedWithdrawRequests(inputs: {
263
+ /**
264
+ * Fetch all pending vault withdrawal requests created by a given wallet.
265
+ *
266
+ * @param inputs.walletAddress - Wallet address that created the withdraw requests.
267
+ * @returns Array of {@link PerpetualsVaultWithdrawRequest}.
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * const withdrawRequests = await perps.getOwnedVaultWithdrawRequests({
272
+ * walletAddress: "0x...",
273
+ * });
274
+ * ```
275
+ */
276
+ getOwnedVaultWithdrawRequests(inputs: {
50
277
  walletAddress: SuiAddress;
51
278
  }): Promise<PerpetualsVaultWithdrawRequest[]>;
279
+ getOwnedVaultLpCoins(inputs: {
280
+ walletAddress: SuiAddress;
281
+ }): Promise<PerpetualsVaultLpCoin[]>;
282
+ /**
283
+ * Fetch account caps by their cap object IDs.
284
+ *
285
+ * @param inputs.accountCapIds - List of account cap object IDs.
286
+ * @returns Array of {@link PerpetualsAccountCap}.
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * const caps = await perps.getAccountCaps({
291
+ * accountCapIds: ["0xcap1", "0xcap2"],
292
+ * });
293
+ * ```
294
+ */
52
295
  getAccountCaps(inputs: ApiPerpetualsAccountCapsBody): Promise<PerpetualsAccountCap[]>;
296
+ /**
297
+ * Fetch historical OHLCV candle data for a single market.
298
+ *
299
+ * @param inputs.marketId - Market ID to query.
300
+ * @param inputs.fromTimestamp - Start timestamp (inclusive).
301
+ * @param inputs.toTimestamp - End timestamp (exclusive).
302
+ * @param inputs.intervalMs - Candle interval in milliseconds.
303
+ * @returns Array of {@link PerpetualsMarketCandleDataPoint}.
304
+ *
305
+ * @example
306
+ * ```ts
307
+ * const candles = await perps.getMarketHistoricalData({
308
+ * marketId: "0x...",
309
+ * fromTimestamp: Date.now() - 24 * 60 * 60 * 1000,
310
+ * toTimestamp: Date.now(),
311
+ * intervalMs: 60_000, // 1 minute
312
+ * });
313
+ * ```
314
+ */
53
315
  getMarketHistoricalData(inputs: {
54
316
  marketId: PerpetualsMarketId;
55
317
  fromTimestamp: Timestamp;
56
318
  toTimestamp: Timestamp;
57
319
  intervalMs: number;
58
320
  }): Promise<ApiPerpetualsHistoricalMarketDataResponse>;
321
+ /**
322
+ * Fetch 24-hour stats for multiple markets.
323
+ *
324
+ * @param inputs.marketIds - Market IDs to query.
325
+ * @returns Array of 24hr stats aligned with `marketIds`.
326
+ *
327
+ * @example
328
+ * ```ts
329
+ * const stats = await perps.getMarkets24hrStats({
330
+ * marketIds: ["0x...", "0x..."],
331
+ * });
332
+ * ```
333
+ */
59
334
  getMarkets24hrStats(inputs: {
60
335
  marketIds: PerpetualsMarketId[];
61
336
  }): Promise<ApiPerpetualsMarkets24hrStatsResponse>;
337
+ /**
338
+ * Fetch the latest oracle prices (base & collateral) for one or more markets.
339
+ *
340
+ * @param inputs.marketIds - List of market IDs to query.
341
+ * @returns Array of `{ basePrice, collateralPrice }` objects in the same order as `marketIds`.
342
+ * Returns `[]` if `marketIds` is empty.
343
+ *
344
+ * @example
345
+ * ```ts
346
+ * const prices = await perps.getPrices({ marketIds: ["0x..."] });
347
+ * const { basePrice, collateralPrice } = prices[0];
348
+ * ```
349
+ */
62
350
  getPrices(inputs: {
63
351
  marketIds: ObjectId[];
64
352
  }): Promise<{
65
353
  basePrice: number;
66
354
  collateralPrice: number;
67
355
  }[]>;
356
+ /**
357
+ * Fetch LP coin prices (in collateral units) for a set of vaults.
358
+ *
359
+ * @param inputs.vaultIds - List of vault IDs to query.
360
+ * @returns Array of LP prices corresponding to each vault ID; returns `[]` if none are provided.
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * const [price] = await perps.getLpCoinPrices({ vaultIds: ["0x..."] });
365
+ * ```
366
+ */
68
367
  getLpCoinPrices(inputs: {
69
368
  vaultIds: ObjectId[];
70
369
  }): Promise<number[]>;
370
+ /**
371
+ * Build a `create-account` transaction for Aftermath Perpetuals.
372
+ *
373
+ * This helper:
374
+ * - Optionally converts a {@link Transaction} into a serialized `txKind`
375
+ * via the shared `Provider` (if present).
376
+ * - Calls the `/perpetuals/transactions/create-account` endpoint.
377
+ * - Returns a serialized transaction (`txKind`) that you can sign and execute.
378
+ *
379
+ * @param inputs.walletAddress - The wallet address that will own the new account.
380
+ * @param inputs.collateralCoinType - Collateral coin type to be used with this account.
381
+ * @param inputs.tx - Optional {@link Transaction} to extend; if provided,
382
+ * the create-account commands are appended to this transaction.
383
+ *
384
+ * @returns API transaction response containing `txKind`.
385
+ *
386
+ * @example
387
+ * ```ts
388
+ * const { txKind } = await perps.getCreateAccountTx({
389
+ * walletAddress: "0x...",
390
+ * collateralCoinType: "0x2::sui::SUI",
391
+ * });
392
+ * // sign + execute txKind with your wallet adapter
393
+ * ```
394
+ */
71
395
  getCreateAccountTx(inputs: {
72
396
  walletAddress: SuiAddress;
73
397
  collateralCoinType: CoinType;
@@ -75,17 +399,71 @@ export declare class Perpetuals extends Caller {
75
399
  }): Promise<Omit<ApiTransactionResponse, "txKind"> & {
76
400
  tx: Transaction;
77
401
  }>;
402
+ /**
403
+ * Build a `create-vault-cap` transaction.
404
+ *
405
+ * This helper directly forwards the body through to the backend. If you wish
406
+ * to extend an existing {@link Transaction}, build the `txKind` yourself
407
+ * and pass it as part of {@link ApiPerpetualsCreateVaultCapBody}.
408
+ *
409
+ * @param inputs - Request body for the create-vault-cap endpoint.
410
+ * @returns API transaction response containing `txKind`.
411
+ *
412
+ * @example
413
+ * ```ts
414
+ * const { txKind } = await perps.getCreateVaultCapTx({
415
+ * walletAddress: "0x...",
416
+ * });
417
+ * ```
418
+ */
78
419
  getCreateVaultCapTx(inputs: ApiPerpetualsCreateVaultCapBody): Promise<Omit<ApiTransactionResponse, "txKind"> & {
79
420
  tx: Transaction;
80
421
  }>;
422
+ /**
423
+ * Build a `create-vault` transaction.
424
+ *
425
+ * This helper:
426
+ * - Optionally converts a {@link Transaction} into a serialized `txKind`
427
+ * via the shared `Provider` (if present).
428
+ * - Calls `/perpetuals/vault/transactions/create-vault`.
429
+ * - Returns a serialized transaction (`txKind`) that you can sign and execute.
430
+ *
431
+ * You can specify the initial deposit either as an explicit amount or as a
432
+ * `depositCoinArg` referring to an existing transaction argument.
433
+ *
434
+ * @param inputs.name - Human-readable vault name.
435
+ * @param inputs.walletAddress - Address of vault owner.
436
+ * @param inputs.lpCoinType - Coin type for the LP token.
437
+ * @param inputs.collateralCoinType - Collateral coin type for the vault.
438
+ * @param inputs.lockPeriodMs - Lock-in period for deposits in milliseconds.
439
+ * @param inputs.ownerFeePercentage - Percentage of user profits taken as owner fee.
440
+ * @param inputs.forceWithdrawDelayMs - Delay before forced withdrawals are processed.
441
+ * @param inputs.isSponsoredTx - Whether this transaction is sponsored (fees paid by another party).
442
+ * @param inputs.initialDepositAmount - Initial deposit amount (mutually exclusive with `initialDepositCoinArg`).
443
+ * @param inputs.initialDepositCoinArg - Transaction object argument referencing the deposit coin.
444
+ * @param inputs.tx - Optional {@link Transaction} to extend.
445
+ *
446
+ * @returns API transaction response containing `txKind`.
447
+ *
448
+ * @example
449
+ * ```ts
450
+ * const { txKind } = await perps.getCreateVaultTx({
451
+ * name: "My Vault",
452
+ * walletAddress: "0x...",
453
+ * lpCoinType: "0x...::lp::LP",
454
+ * collateralCoinType: "0x2::sui::SUI",
455
+ * lockPeriodMs: BigInt(7 * 24 * 60 * 60 * 1000),
456
+ * ownerFeePercentage: 0.2,
457
+ * forceWithdrawDelayMs: BigInt(24 * 60 * 60 * 1000),
458
+ * initialDepositAmount: BigInt("1000000000"),
459
+ * });
460
+ * ```
461
+ */
81
462
  getCreateVaultTx(inputs: {
82
463
  name: string;
83
464
  walletAddress: SuiAddress;
84
465
  lpCoinType: CoinType;
85
466
  collateralCoinType: CoinType;
86
- collateralOracleId: ObjectId;
87
- collateralPriceFeedId: ObjectId;
88
- collateralPriceFeedTolerance: bigint;
89
467
  lockPeriodMs: bigint;
90
468
  ownerFeePercentage: Percentage;
91
469
  forceWithdrawDelayMs: bigint;
@@ -98,32 +476,154 @@ export declare class Perpetuals extends Caller {
98
476
  })): Promise<Omit<ApiTransactionResponse, "txKind"> & {
99
477
  tx: Transaction;
100
478
  }>;
479
+ /**
480
+ * Determine the logical order side (Bid/Ask) from a signed base asset amount.
481
+ *
482
+ * @param inputs.baseAssetAmount - Position base size. Positive => Bid (long), negative => Ask (short).
483
+ * @returns Corresponding {@link PerpetualsOrderSide}.
484
+ *
485
+ * @example
486
+ * ```ts
487
+ * const side = Perpetuals.positionSide({ baseAssetAmount: -1 });
488
+ * // side === PerpetualsOrderSide.Ask
489
+ * ```
490
+ */
101
491
  static positionSide(inputs: {
102
492
  baseAssetAmount: number;
103
493
  }): PerpetualsOrderSide;
494
+ /**
495
+ * Compute the effective price from a {@link FilledTakerOrderEvent}.
496
+ *
497
+ * Uses `quoteAssetDelta / baseAssetDelta`.
498
+ *
499
+ * @param inputs.orderEvent - Filled taker order event.
500
+ * @returns Trade price as a `number`.
501
+ */
104
502
  static orderPriceFromEvent(inputs: {
105
503
  orderEvent: FilledTakerOrderEvent;
106
504
  }): number;
505
+ /**
506
+ * Extract the price (as floating-point) from an encoded order ID.
507
+ *
508
+ * Internally uses {@link PerpetualsOrderUtils.price} and converts the
509
+ * fixed-point `PerpetualsOrderPrice` into a `number`.
510
+ *
511
+ * @param inputs.orderId - Encoded order ID.
512
+ * @returns Floating-point price.
513
+ */
107
514
  static orderPriceFromOrderId(inputs: {
108
515
  orderId: PerpetualsOrderId;
109
516
  }): number;
517
+ /**
518
+ * Convert a floating-point price into a fixed-point {@link PerpetualsOrderPrice}
519
+ * using 9 decimal places of precision.
520
+ *
521
+ * @param inputs.price - Floating-point price.
522
+ * @returns Encoded {@link PerpetualsOrderPrice} as `bigint`.
523
+ */
110
524
  static priceToOrderPrice: (inputs: {
111
525
  price: number;
112
526
  }) => PerpetualsOrderPrice;
527
+ /**
528
+ * Convert a fixed-point {@link PerpetualsOrderPrice} to a human-friendly price.
529
+ *
530
+ * @param inputs.orderPrice - Encoded order price as `bigint`.
531
+ * @returns Floating-point price value.
532
+ */
113
533
  static orderPriceToPrice: (inputs: {
114
534
  orderPrice: PerpetualsOrderPrice;
115
535
  }) => number;
536
+ /**
537
+ * Convert a fixed-point lot or tick size (9 decimals) to a `number`.
538
+ *
539
+ * @param lotOrTickSize - Fixed-point size as `bigint`.
540
+ * @returns Floating-point representation.
541
+ */
116
542
  static lotOrTickSizeToNumber(lotOrTickSize: bigint): number;
543
+ /**
544
+ * Convert a floating-point lot or tick size to its fixed-point representation (9 decimals).
545
+ *
546
+ * @param lotOrTickSize - Floating-point size.
547
+ * @returns Fixed-point representation as `bigint`.
548
+ */
117
549
  static lotOrTickSizeToBigInt(lotOrTickSize: number): bigint;
550
+ /**
551
+ * Infer the order side from an order ID.
552
+ *
553
+ * Uses {@link PerpetualsOrderUtils.isAsk} under the hood.
554
+ *
555
+ * @param orderId - Encoded order ID.
556
+ * @returns {@link PerpetualsOrderSide.Ask} if ask, otherwise {@link PerpetualsOrderSide.Bid}.
557
+ */
118
558
  static orderIdToSide: (orderId: PerpetualsOrderId) => PerpetualsOrderSide;
559
+ /**
560
+ * Construct a full event type string for a collateral-specific event.
561
+ *
562
+ * Many Move events are generic over a collateral coin type. This helper
563
+ * appends `<collateralCoinType>` to a base `eventType`.
564
+ *
565
+ * @param inputs.eventType - Base event type without type parameters.
566
+ * @param inputs.collateralCoinType - Collateral coin type, e.g. `"0x2::sui::SUI"`.
567
+ * @returns Fully-qualified event type string.
568
+ *
569
+ * @example
570
+ * ```ts
571
+ * const fullType = Perpetuals.eventTypeForCollateral({
572
+ * eventType: "0x1::perps::DepositedCollateral",
573
+ * collateralCoinType: "0x2::sui::SUI",
574
+ * });
575
+ * // "0x1::perps::DepositedCollateral<0x2::sui::SUI>"
576
+ * ```
577
+ */
119
578
  static eventTypeForCollateral: (inputs: {
120
579
  eventType: string;
121
580
  collateralCoinType: CoinType;
122
581
  }) => string;
123
582
  /**
124
- * Open the main updates websocket: /perpetuals/ws/updates
583
+ * Open the main updates websocket: `/perpetuals/ws/updates`.
584
+ *
585
+ * This stream can deliver:
586
+ * - Market updates
587
+ * - User account + stop order updates
588
+ * - Oracle price updates
589
+ * - Orderbook deltas
590
+ * - Market trades
591
+ * - User trades
592
+ * - User collateral changes
125
593
  *
126
- * @returns controller with perps-specific subscribe/unsubscribe helpers
594
+ * The returned controller object includes a set of convenient subscribe /
595
+ * unsubscribe helpers for each stream type.
596
+ *
597
+ * @param args.onMessage - Handler for incoming messages from the ws.
598
+ * @param args.onOpen - Optional hook called when the websocket is opened.
599
+ * @param args.onError - Optional hook called on websocket error.
600
+ * @param args.onClose - Optional hook called when the websocket closes.
601
+ *
602
+ * @returns An object containing:
603
+ * - `ws`: the underlying `WebSocket` instance
604
+ * - subscribe/unsubscribe helpers:
605
+ * - `subscribeMarket` / `unsubscribeMarket`
606
+ * - `subscribeUser` / `unsubscribeUser`
607
+ * - `subscribeOracle` / `unsubscribeOracle`
608
+ * - `subscribeOrderbook` / `unsubscribeOrderbook`
609
+ * - `subscribeMarketTrades` / `unsubscribeMarketTrades`
610
+ * - `subscribeUserTrades` / `unsubscribeUserTrades`
611
+ * - `subscribeUserCollateralChanges` / `unsubscribeUserCollateralChanges`
612
+ * - `close`: function to close the websocket
613
+ *
614
+ * @example
615
+ * ```ts
616
+ * const stream = perps.openUpdatesWebsocketStream({
617
+ * onMessage: (msg) => {
618
+ * if ("market" in msg) {
619
+ * console.log("Market update", msg.market);
620
+ * }
621
+ * },
622
+ * });
623
+ *
624
+ * stream.subscribeMarket({ marketId: "0x..." });
625
+ * stream.subscribeUser({ accountId: 123n, withStopOrders: undefined });
626
+ * ```
127
627
  */
128
628
  openUpdatesWebsocketStream(args: {
129
629
  onMessage: (env: PerpetualsWsUpdatesResponseMessage) => void;
@@ -187,8 +687,33 @@ export declare class Perpetuals extends Caller {
187
687
  close: () => void;
188
688
  };
189
689
  /**
190
- * Open market-candles websocket for a single market/interval:
191
- * /perpetuals/ws/market-candles/{market_id}/{interval_ms}
690
+ * Open a market-candles websocket stream for a single market/interval:
691
+ * `/perpetuals/ws/market-candles/{market_id}/{interval_ms}`.
692
+ *
693
+ * The stream emits {@link PerpetualsWsCandleResponseMessage} messages,
694
+ * typically containing the latest candle for the specified interval.
695
+ *
696
+ * @param args.marketId - Market ID to subscribe to.
697
+ * @param args.intervalMs - Candle interval in milliseconds.
698
+ * @param args.onMessage - Handler for incoming candle updates.
699
+ * @param args.onOpen - Optional hook called when the websocket opens.
700
+ * @param args.onError - Optional hook called on websocket error.
701
+ * @param args.onClose - Optional hook called when the websocket closes.
702
+ *
703
+ * @returns An object containing:
704
+ * - `ws`: the underlying `WebSocket` instance
705
+ * - `close`: function to close the websocket
706
+ *
707
+ * @example
708
+ * ```ts
709
+ * const stream = perps.openMarketCandlesWebsocketStream({
710
+ * marketId: "0x...",
711
+ * intervalMs: 60_000,
712
+ * onMessage: ({ lastCandle }) => {
713
+ * console.log("New candle:", lastCandle);
714
+ * },
715
+ * });
716
+ * ```
192
717
  */
193
718
  openMarketCandlesWebsocketStream(args: {
194
719
  marketId: PerpetualsMarketId;