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.
- package/dist/general/types/generalTypes.d.ts +4 -0
- package/dist/general/types/generalTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetuals.d.ts +177 -262
- package/dist/packages/perpetuals/perpetuals.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetuals.js +185 -256
- package/dist/packages/perpetuals/perpetualsAccount.d.ts +178 -34
- package/dist/packages/perpetuals/perpetualsAccount.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsAccount.js +183 -39
- package/dist/packages/perpetuals/perpetualsMarket.d.ts +116 -140
- package/dist/packages/perpetuals/perpetualsMarket.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsMarket.js +125 -159
- package/dist/packages/perpetuals/perpetualsTypes.d.ts +241 -5
- package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsVault.d.ts +273 -19
- package/dist/packages/perpetuals/perpetualsVault.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsVault.js +289 -78
- package/package.json +1 -1
|
@@ -81,25 +81,34 @@ class Perpetuals extends caller_1.Caller {
|
|
|
81
81
|
*
|
|
82
82
|
* @param config - Optional caller configuration (network, auth token, etc.).
|
|
83
83
|
* @param Provider - Optional shared {@link AftermathApi} provider instance. When
|
|
84
|
-
* provided, transaction-building helpers
|
|
85
|
-
*
|
|
84
|
+
* provided, transaction-building helpers can derive serialized `txKind`
|
|
85
|
+
* from a {@link Transaction} object via `Provider.Transactions().fetchBase64TxKindFromTx`.
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* This class extends {@link Caller} with the `"perpetuals"` route prefix, meaning:
|
|
89
|
+
* - HTTP calls resolve under `/perpetuals/...`
|
|
90
|
+
* - Websocket calls resolve under `/perpetuals/ws/...`
|
|
86
91
|
*/
|
|
87
92
|
constructor(config, Provider) {
|
|
88
93
|
super(config, "perpetuals");
|
|
89
94
|
this.Provider = Provider;
|
|
90
95
|
}
|
|
91
96
|
// =========================================================================
|
|
92
|
-
//
|
|
97
|
+
// Markets
|
|
93
98
|
// =========================================================================
|
|
94
99
|
/**
|
|
95
100
|
* Fetch all perpetual markets for a given collateral coin type.
|
|
96
101
|
*
|
|
102
|
+
* This method returns *wrapped* {@link PerpetualsMarket} instances, not the raw
|
|
103
|
+
* market structs. Each instance provides additional helpers for pricing, margin,
|
|
104
|
+
* and order parsing.
|
|
105
|
+
*
|
|
97
106
|
* @param inputs.collateralCoinType - Coin type used as collateral, e.g. `"0x2::sui::SUI"`.
|
|
98
|
-
* @returns
|
|
107
|
+
* @returns Object containing `markets`.
|
|
99
108
|
*
|
|
100
109
|
* @example
|
|
101
110
|
* ```ts
|
|
102
|
-
* const markets = await perps.getAllMarkets({
|
|
111
|
+
* const { markets } = await perps.getAllMarkets({
|
|
103
112
|
* collateralCoinType: "0x2::sui::SUI",
|
|
104
113
|
* });
|
|
105
114
|
* ```
|
|
@@ -118,11 +127,15 @@ class Perpetuals extends caller_1.Caller {
|
|
|
118
127
|
* Internally calls {@link getMarkets} and returns the first entry.
|
|
119
128
|
*
|
|
120
129
|
* @param inputs.marketId - The market (clearing house) object ID.
|
|
121
|
-
* @returns
|
|
130
|
+
* @returns Object containing `market`.
|
|
131
|
+
*
|
|
132
|
+
* @throws If the backend returns an empty list for the given `marketId`,
|
|
133
|
+
* this will still attempt to return `markets[0]` (which would be `undefined`).
|
|
134
|
+
* Callers may want to validate the result.
|
|
122
135
|
*
|
|
123
136
|
* @example
|
|
124
137
|
* ```ts
|
|
125
|
-
* const market = await perps.getMarket({ marketId: "0x..." });
|
|
138
|
+
* const { market } = await perps.getMarket({ marketId: "0x..." });
|
|
126
139
|
* ```
|
|
127
140
|
*/
|
|
128
141
|
getMarket(inputs) {
|
|
@@ -138,16 +151,17 @@ class Perpetuals extends caller_1.Caller {
|
|
|
138
151
|
/**
|
|
139
152
|
* Fetch multiple markets by ID.
|
|
140
153
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* {@link PerpetualsMarket}
|
|
154
|
+
* Backend note:
|
|
155
|
+
* - The API supports returning orderbooks. This SDK currently forces
|
|
156
|
+
* `withOrderbook: false` and constructs {@link PerpetualsMarket} from
|
|
157
|
+
* the returned `marketDatas[].market`.
|
|
144
158
|
*
|
|
145
159
|
* @param inputs.marketIds - Array of market object IDs to fetch.
|
|
146
|
-
* @returns
|
|
160
|
+
* @returns Object containing `markets` in the same order as `marketIds`.
|
|
147
161
|
*
|
|
148
162
|
* @example
|
|
149
163
|
* ```ts
|
|
150
|
-
* const
|
|
164
|
+
* const { markets } = await perps.getMarkets({
|
|
151
165
|
* marketIds: ["0x..A", "0x..B"],
|
|
152
166
|
* });
|
|
153
167
|
* ```
|
|
@@ -156,20 +170,24 @@ class Perpetuals extends caller_1.Caller {
|
|
|
156
170
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
171
|
const res = yield this.fetchApi("markets", Object.assign(Object.assign({}, inputs), { withOrderbook: false }));
|
|
158
172
|
return {
|
|
159
|
-
markets: res.marketDatas.map((marketData) =>
|
|
160
|
-
// TODO: make orderbook as input ?
|
|
161
|
-
new perpetualsMarket_1.PerpetualsMarket(marketData.market, this.config, this.Provider)),
|
|
173
|
+
markets: res.marketDatas.map((marketData) => new perpetualsMarket_1.PerpetualsMarket(marketData.market, this.config, this.Provider)),
|
|
162
174
|
};
|
|
163
175
|
});
|
|
164
176
|
}
|
|
177
|
+
// =========================================================================
|
|
178
|
+
// Vaults
|
|
179
|
+
// =========================================================================
|
|
165
180
|
/**
|
|
166
181
|
* Fetch all vaults on the current network.
|
|
167
182
|
*
|
|
168
|
-
*
|
|
183
|
+
* Vaults are managed accounts that can hold positions; LPs deposit collateral
|
|
184
|
+
* and receive an LP coin (see pricing helpers like {@link getLpCoinPrices}).
|
|
185
|
+
*
|
|
186
|
+
* @returns Object containing `vaults`.
|
|
169
187
|
*
|
|
170
188
|
* @example
|
|
171
189
|
* ```ts
|
|
172
|
-
* const vaults = await perps.getAllVaults();
|
|
190
|
+
* const { vaults } = await perps.getAllVaults();
|
|
173
191
|
* ```
|
|
174
192
|
*/
|
|
175
193
|
getAllVaults() {
|
|
@@ -185,13 +203,12 @@ class Perpetuals extends caller_1.Caller {
|
|
|
185
203
|
*
|
|
186
204
|
* Internally calls {@link getVaults} and returns the first entry.
|
|
187
205
|
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
206
|
+
* Naming note:
|
|
207
|
+
* - This method’s parameter is named `marketId` for historical reasons,
|
|
208
|
+
* but it refers to a vault object ID.
|
|
190
209
|
*
|
|
191
|
-
* @
|
|
192
|
-
*
|
|
193
|
-
* const vault = await perps.getVault({ marketId: "0x..." });
|
|
194
|
-
* ```
|
|
210
|
+
* @param inputs.marketId - Vault object ID.
|
|
211
|
+
* @returns Object containing `vault`.
|
|
195
212
|
*/
|
|
196
213
|
getVault(inputs) {
|
|
197
214
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -207,14 +224,7 @@ class Perpetuals extends caller_1.Caller {
|
|
|
207
224
|
* Fetch multiple vaults by ID.
|
|
208
225
|
*
|
|
209
226
|
* @param inputs.vaultIds - Array of vault object IDs.
|
|
210
|
-
* @returns
|
|
211
|
-
*
|
|
212
|
-
* @example
|
|
213
|
-
* ```ts
|
|
214
|
-
* const [vaultA, vaultB] = await perps.getVaults({
|
|
215
|
-
* vaultIds: ["0x..A", "0x..B"],
|
|
216
|
-
* });
|
|
217
|
-
* ```
|
|
227
|
+
* @returns Object containing `vaults` in the same order as `vaultIds`.
|
|
218
228
|
*/
|
|
219
229
|
getVaults(inputs) {
|
|
220
230
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -224,6 +234,9 @@ class Perpetuals extends caller_1.Caller {
|
|
|
224
234
|
};
|
|
225
235
|
});
|
|
226
236
|
}
|
|
237
|
+
// =========================================================================
|
|
238
|
+
// Accounts
|
|
239
|
+
// =========================================================================
|
|
227
240
|
/**
|
|
228
241
|
* Convenience helper to fetch a single account (positions + account object) from an account cap.
|
|
229
242
|
*
|
|
@@ -231,12 +244,12 @@ class Perpetuals extends caller_1.Caller {
|
|
|
231
244
|
*
|
|
232
245
|
* @param inputs.accountCap - Account-cap or vault-cap-extended object to derive account metadata from.
|
|
233
246
|
* @param inputs.marketIds - Optional list of markets to filter positions by.
|
|
234
|
-
* @returns
|
|
247
|
+
* @returns Object containing `account`.
|
|
235
248
|
*
|
|
236
249
|
* @example
|
|
237
250
|
* ```ts
|
|
238
251
|
* const [accountCap] = await perps.getOwnedAccountCaps({ walletAddress: "0x..." });
|
|
239
|
-
* const account = await perps.getAccount({ accountCap });
|
|
252
|
+
* const { account } = await perps.getAccount({ accountCap });
|
|
240
253
|
* ```
|
|
241
254
|
*/
|
|
242
255
|
// TODO: merge this with `getAccountObjects` as an option ?
|
|
@@ -254,24 +267,21 @@ class Perpetuals extends caller_1.Caller {
|
|
|
254
267
|
/**
|
|
255
268
|
* Fetch one or more accounts (positions + account objects) from account caps.
|
|
256
269
|
*
|
|
257
|
-
* This composes
|
|
258
|
-
*
|
|
259
|
-
*
|
|
270
|
+
* This composes:
|
|
271
|
+
* 1) {@link getAccountObjects} to fetch {@link PerpetualsAccountObject}s by account ID
|
|
272
|
+
* 2) Local pairing of returned account objects with `accountCaps`
|
|
260
273
|
*
|
|
261
|
-
* The
|
|
262
|
-
*
|
|
274
|
+
* The returned {@link PerpetualsAccount} instances encapsulate:
|
|
275
|
+
* - The account snapshot (positions, balances, etc.)
|
|
276
|
+
* - The ownership/cap metadata (accountId, collateral type, vaultId, etc.)
|
|
263
277
|
*
|
|
264
278
|
* @param inputs.accountCaps - Array of account caps or vault-cap-extended objects.
|
|
265
279
|
* @param inputs.marketIds - Optional list of market IDs to filter positions by.
|
|
266
|
-
* @returns
|
|
280
|
+
* @returns Object containing `accounts` in the same order as `accountCaps`.
|
|
267
281
|
*
|
|
268
|
-
* @
|
|
269
|
-
*
|
|
270
|
-
* const accountCaps = await perps.getOwnedAccountCaps({ walletAddress: "0x..." });
|
|
271
|
-
* const accounts = await perps.getAccounts({ accountCaps });
|
|
272
|
-
* ```
|
|
282
|
+
* @remarks
|
|
283
|
+
* If `accountCaps` is empty, this returns `{ accounts: [] }` without making an API call.
|
|
273
284
|
*/
|
|
274
|
-
// TODO: make account fetching get positions and account cap data all at once ?
|
|
275
285
|
getAccounts(inputs) {
|
|
276
286
|
return __awaiter(this, void 0, void 0, function* () {
|
|
277
287
|
const { accountCaps, marketIds } = inputs;
|
|
@@ -291,18 +301,15 @@ class Perpetuals extends caller_1.Caller {
|
|
|
291
301
|
/**
|
|
292
302
|
* Fetch raw account objects (including positions) for one or more account IDs.
|
|
293
303
|
*
|
|
294
|
-
*
|
|
304
|
+
* This is the lower-level primitive used by {@link getAccounts}.
|
|
295
305
|
*
|
|
296
306
|
* @param inputs.accountIds - List of account IDs to query.
|
|
297
307
|
* @param inputs.marketIds - Optional list of market IDs to filter positions by.
|
|
298
|
-
* @returns Array of {@link PerpetualsAccountObject}.
|
|
299
308
|
*
|
|
300
|
-
* @
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
* });
|
|
305
|
-
* ```
|
|
309
|
+
* @returns {@link ApiPerpetualsAccountPositionsResponse} containing `accounts`.
|
|
310
|
+
*
|
|
311
|
+
* @remarks
|
|
312
|
+
* If `accountIds` is empty, this returns `{ accounts: [] }` without making an API call.
|
|
306
313
|
*/
|
|
307
314
|
getAccountObjects(inputs) {
|
|
308
315
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -317,19 +324,23 @@ class Perpetuals extends caller_1.Caller {
|
|
|
317
324
|
});
|
|
318
325
|
});
|
|
319
326
|
}
|
|
327
|
+
// =========================================================================
|
|
328
|
+
// Ownership Queries
|
|
329
|
+
// =========================================================================
|
|
320
330
|
/**
|
|
321
331
|
* Fetch all account caps (perpetuals accounts) owned by a wallet, optionally
|
|
322
332
|
* filtered by collateral coin types.
|
|
323
333
|
*
|
|
324
|
-
*
|
|
334
|
+
* Returned values are “caps” (ownership objects), not full account snapshots.
|
|
335
|
+
* To fetch account positions, use {@link getAccount} or {@link getAccounts}.
|
|
325
336
|
*
|
|
326
337
|
* @param inputs.walletAddress - Owner wallet address.
|
|
327
338
|
* @param inputs.collateralCoinTypes - Optional list of collateral coin types to filter by.
|
|
328
|
-
* @returns
|
|
339
|
+
* @returns {@link ApiPerpetualsOwnedAccountCapsResponse} containing `accounts`.
|
|
329
340
|
*
|
|
330
341
|
* @example
|
|
331
342
|
* ```ts
|
|
332
|
-
* const
|
|
343
|
+
* const { accounts } = await perps.getOwnedAccountCaps({
|
|
333
344
|
* walletAddress: "0x...",
|
|
334
345
|
* collateralCoinTypes: ["0x2::sui::SUI"],
|
|
335
346
|
* });
|
|
@@ -347,15 +358,10 @@ class Perpetuals extends caller_1.Caller {
|
|
|
347
358
|
/**
|
|
348
359
|
* Fetch all vault caps owned by a wallet.
|
|
349
360
|
*
|
|
350
|
-
*
|
|
351
|
-
* @returns Array of {@link PerpetualsVaultCap} objects.
|
|
361
|
+
* Vault caps represent ownership/administrative authority over a vault.
|
|
352
362
|
*
|
|
353
|
-
* @
|
|
354
|
-
*
|
|
355
|
-
* const vaultCaps = await perps.getOwnedVaultCaps({
|
|
356
|
-
* walletAddress: "0x...",
|
|
357
|
-
* });
|
|
358
|
-
* ```
|
|
363
|
+
* @param inputs.walletAddress - Owner wallet address.
|
|
364
|
+
* @returns {@link ApiPerpetualsOwnedVaultCapsResponse} containing vault caps.
|
|
359
365
|
*/
|
|
360
366
|
getOwnedVaultCaps(inputs) {
|
|
361
367
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -365,22 +371,26 @@ class Perpetuals extends caller_1.Caller {
|
|
|
365
371
|
/**
|
|
366
372
|
* Fetch all pending vault withdrawal requests created by a given wallet.
|
|
367
373
|
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
374
|
+
* Withdraw requests are typically created when LPs request to exit a vault
|
|
375
|
+
* and may be subject to lock periods / delays depending on vault configuration.
|
|
370
376
|
*
|
|
371
|
-
* @
|
|
372
|
-
*
|
|
373
|
-
* const withdrawRequests = await perps.getOwnedVaultWithdrawRequests({
|
|
374
|
-
* walletAddress: "0x...",
|
|
375
|
-
* });
|
|
376
|
-
* ```
|
|
377
|
+
* @param inputs.walletAddress - Wallet address that created the withdraw requests.
|
|
378
|
+
* @returns {@link ApiPerpetualsVaultOwnedWithdrawRequestsResponse} containing requests.
|
|
377
379
|
*/
|
|
378
380
|
getOwnedVaultWithdrawRequests(inputs) {
|
|
379
381
|
return __awaiter(this, void 0, void 0, function* () {
|
|
380
382
|
return this.fetchApi("vaults/owned-withdraw-requests", Object.assign({}, inputs));
|
|
381
383
|
});
|
|
382
384
|
}
|
|
383
|
-
|
|
385
|
+
/**
|
|
386
|
+
* Fetch all Perpetuals vault LP coins owned by a wallet.
|
|
387
|
+
*
|
|
388
|
+
* This returns coin objects (or summaries) representing LP token holdings.
|
|
389
|
+
* Use {@link getLpCoinPrices} to value them in collateral units.
|
|
390
|
+
*
|
|
391
|
+
* @param inputs - {@link ApiPerpetualsVaultOwnedLpCoinsBody}.
|
|
392
|
+
* @returns {@link ApiPerpetualsVaultOwnedLpCoinsResponse}.
|
|
393
|
+
*/
|
|
384
394
|
getOwnedVaultLpCoins(inputs) {
|
|
385
395
|
return __awaiter(this, void 0, void 0, function* () {
|
|
386
396
|
return this.fetchApi("vaults/owned-lp-coins", inputs);
|
|
@@ -390,14 +400,7 @@ class Perpetuals extends caller_1.Caller {
|
|
|
390
400
|
* Fetch account caps by their cap object IDs.
|
|
391
401
|
*
|
|
392
402
|
* @param inputs.accountCapIds - List of account cap object IDs.
|
|
393
|
-
* @returns
|
|
394
|
-
*
|
|
395
|
-
* @example
|
|
396
|
-
* ```ts
|
|
397
|
-
* const caps = await perps.getAccountCaps({
|
|
398
|
-
* accountCapIds: ["0xcap1", "0xcap2"],
|
|
399
|
-
* });
|
|
400
|
-
* ```
|
|
403
|
+
* @returns {@link ApiPerpetualsAccountCapsResponse} containing caps.
|
|
401
404
|
*/
|
|
402
405
|
getAccountCaps(inputs) {
|
|
403
406
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -405,7 +408,7 @@ class Perpetuals extends caller_1.Caller {
|
|
|
405
408
|
});
|
|
406
409
|
}
|
|
407
410
|
// =========================================================================
|
|
408
|
-
// Data
|
|
411
|
+
// Historical Data & Stats
|
|
409
412
|
// =========================================================================
|
|
410
413
|
/**
|
|
411
414
|
* Fetch historical OHLCV candle data for a single market.
|
|
@@ -414,17 +417,12 @@ class Perpetuals extends caller_1.Caller {
|
|
|
414
417
|
* @param inputs.fromTimestamp - Start timestamp (inclusive).
|
|
415
418
|
* @param inputs.toTimestamp - End timestamp (exclusive).
|
|
416
419
|
* @param inputs.intervalMs - Candle interval in milliseconds.
|
|
417
|
-
* @returns Array of {@link PerpetualsMarketCandleDataPoint}.
|
|
418
420
|
*
|
|
419
|
-
* @
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
* toTimestamp: Date.now(),
|
|
425
|
-
* intervalMs: 60_000, // 1 minute
|
|
426
|
-
* });
|
|
427
|
-
* ```
|
|
421
|
+
* @returns {@link ApiPerpetualsMarketCandleHistoryResponse} containing candle points.
|
|
422
|
+
*
|
|
423
|
+
* @remarks
|
|
424
|
+
* This is currently implemented on the Perpetuals root client, but it may be
|
|
425
|
+
* relocated to {@link PerpetualsMarket} in the future.
|
|
428
426
|
*/
|
|
429
427
|
// TODO: move to market class ?
|
|
430
428
|
getMarketCandleHistory(inputs) {
|
|
@@ -440,14 +438,7 @@ class Perpetuals extends caller_1.Caller {
|
|
|
440
438
|
* Fetch 24-hour stats for multiple markets.
|
|
441
439
|
*
|
|
442
440
|
* @param inputs.marketIds - Market IDs to query.
|
|
443
|
-
* @returns
|
|
444
|
-
*
|
|
445
|
-
* @example
|
|
446
|
-
* ```ts
|
|
447
|
-
* const stats = await perps.getMarkets24hrStats({
|
|
448
|
-
* marketIds: ["0x...", "0x..."],
|
|
449
|
-
* });
|
|
450
|
-
* ```
|
|
441
|
+
* @returns {@link ApiPerpetualsMarkets24hrStatsResponse}.
|
|
451
442
|
*/
|
|
452
443
|
getMarkets24hrStats(inputs) {
|
|
453
444
|
return this.fetchApi("markets/24hr-stats", inputs);
|
|
@@ -459,14 +450,10 @@ class Perpetuals extends caller_1.Caller {
|
|
|
459
450
|
* Fetch the latest oracle prices (base & collateral) for one or more markets.
|
|
460
451
|
*
|
|
461
452
|
* @param inputs.marketIds - List of market IDs to query.
|
|
462
|
-
* @returns
|
|
463
|
-
* Returns `[]` if `marketIds` is empty.
|
|
453
|
+
* @returns {@link ApiPerpetualsMarketsPricesResponse} containing `marketsPrices`.
|
|
464
454
|
*
|
|
465
|
-
* @
|
|
466
|
-
*
|
|
467
|
-
* const prices = await perps.getPrices({ marketIds: ["0x..."] });
|
|
468
|
-
* const { basePrice, collateralPrice } = prices[0];
|
|
469
|
-
* ```
|
|
455
|
+
* @remarks
|
|
456
|
+
* If `marketIds` is empty, returns `{ marketsPrices: [] }` without making an API call.
|
|
470
457
|
*/
|
|
471
458
|
getPrices(inputs) {
|
|
472
459
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -481,12 +468,10 @@ class Perpetuals extends caller_1.Caller {
|
|
|
481
468
|
* Fetch LP coin prices (in collateral units) for a set of vaults.
|
|
482
469
|
*
|
|
483
470
|
* @param inputs.vaultIds - List of vault IDs to query.
|
|
484
|
-
* @returns
|
|
471
|
+
* @returns {@link ApiPerpetualsVaultLpCoinPricesResponse} containing `lpCoinPrices`.
|
|
485
472
|
*
|
|
486
|
-
* @
|
|
487
|
-
*
|
|
488
|
-
* const [price] = await perps.getLpCoinPrices({ vaultIds: ["0x..."] });
|
|
489
|
-
* ```
|
|
473
|
+
* @remarks
|
|
474
|
+
* If `vaultIds` is empty, returns `{ lpCoinPrices: [] }` without making an API call.
|
|
490
475
|
*/
|
|
491
476
|
getLpCoinPrices(inputs) {
|
|
492
477
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -503,27 +488,12 @@ class Perpetuals extends caller_1.Caller {
|
|
|
503
488
|
/**
|
|
504
489
|
* Build a `create-account` transaction for Aftermath Perpetuals.
|
|
505
490
|
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
* - Returns a serialized transaction (`txKind`) that you can sign and execute.
|
|
491
|
+
* @param inputs.walletAddress - Wallet address that will own the new account.
|
|
492
|
+
* @param inputs.collateralCoinType - Collateral coin type used by the account.
|
|
493
|
+
* @param inputs.tx - Optional {@link Transaction} to extend; if provided, the
|
|
494
|
+
* create-account commands are appended to this transaction.
|
|
511
495
|
*
|
|
512
|
-
* @
|
|
513
|
-
* @param inputs.collateralCoinType - Collateral coin type to be used with this account.
|
|
514
|
-
* @param inputs.tx - Optional {@link Transaction} to extend; if provided,
|
|
515
|
-
* the create-account commands are appended to this transaction.
|
|
516
|
-
*
|
|
517
|
-
* @returns API transaction response containing `txKind`.
|
|
518
|
-
*
|
|
519
|
-
* @example
|
|
520
|
-
* ```ts
|
|
521
|
-
* const { txKind } = await perps.getCreateAccountTx({
|
|
522
|
-
* walletAddress: "0x...",
|
|
523
|
-
* collateralCoinType: "0x2::sui::SUI",
|
|
524
|
-
* });
|
|
525
|
-
* // sign + execute txKind with your wallet adapter
|
|
526
|
-
* ```
|
|
496
|
+
* @returns {@link SdkTransactionResponse} with `tx`.
|
|
527
497
|
*/
|
|
528
498
|
getCreateAccountTx(inputs) {
|
|
529
499
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -538,7 +508,15 @@ class Perpetuals extends caller_1.Caller {
|
|
|
538
508
|
});
|
|
539
509
|
});
|
|
540
510
|
}
|
|
541
|
-
|
|
511
|
+
/**
|
|
512
|
+
* Build a `create-vault-cap` transaction.
|
|
513
|
+
*
|
|
514
|
+
* A vault cap is an ownership/admin object for interacting with vault management
|
|
515
|
+
* flows. This method returns a transaction kind that mints/creates that cap.
|
|
516
|
+
*
|
|
517
|
+
* @param inputs - {@link ApiPerpetualsCreateVaultCapBody}.
|
|
518
|
+
* @returns {@link SdkTransactionResponse} with `tx`.
|
|
519
|
+
*/
|
|
542
520
|
getCreateVaultCapTx(inputs) {
|
|
543
521
|
return __awaiter(this, void 0, void 0, function* () {
|
|
544
522
|
return this.fetchApiTxObject("vault/transactions/create-vault-cap", inputs, undefined, {
|
|
@@ -546,44 +524,35 @@ class Perpetuals extends caller_1.Caller {
|
|
|
546
524
|
});
|
|
547
525
|
});
|
|
548
526
|
}
|
|
549
|
-
// TODO: docs (for metadata)
|
|
550
527
|
/**
|
|
551
528
|
* Build a `create-vault` transaction.
|
|
552
529
|
*
|
|
553
|
-
* This
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
* -
|
|
530
|
+
* This creates a new vault plus its on-chain metadata and initial LP supply
|
|
531
|
+
* seeded by the initial deposit.
|
|
532
|
+
*
|
|
533
|
+
* Deposit input:
|
|
534
|
+
* - Use `initialDepositAmount` to have the API select/merge coins as needed, OR
|
|
535
|
+
* - Use `initialDepositCoinArg` if you already have a coin argument in a larger tx.
|
|
558
536
|
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
537
|
+
* Metadata:
|
|
538
|
+
* - Stored on-chain (or in a referenced object) as part of vault creation.
|
|
539
|
+
* - `extraFields` allows forward-compatible additions (e.g. social links).
|
|
561
540
|
*
|
|
562
|
-
* @param inputs.walletAddress - Address of vault owner.
|
|
563
|
-
* @param inputs.
|
|
564
|
-
* @param inputs.
|
|
541
|
+
* @param inputs.walletAddress - Address of vault owner/curator.
|
|
542
|
+
* @param inputs.metadata - Vault display metadata (name, description, curator info).
|
|
543
|
+
* @param inputs.metadata - Vault display metadata (name, description, curator info).
|
|
544
|
+
* @param inputs.coinMetadataId - Coin metadata object id obtained from create vault cap tx
|
|
545
|
+
* @param inputs.treasuryCapId - Treasury cap object id obtained from create vault cap tx
|
|
546
|
+
* @param inputs.collateralCoinType - Collateral coin type for deposits.
|
|
565
547
|
* @param inputs.lockPeriodMs - Lock-in period for deposits in milliseconds.
|
|
566
|
-
* @param inputs.performanceFeePercentage -
|
|
567
|
-
* @param inputs.forceWithdrawDelayMs - Delay before forced withdrawals
|
|
568
|
-
* @param inputs.isSponsoredTx - Whether this
|
|
548
|
+
* @param inputs.performanceFeePercentage - Fraction of profits taken as curator fee.
|
|
549
|
+
* @param inputs.forceWithdrawDelayMs - Delay before forced withdrawals can be processed.
|
|
550
|
+
* @param inputs.isSponsoredTx - Whether this tx is sponsored (gas paid by another party).
|
|
569
551
|
* @param inputs.initialDepositAmount - Initial deposit amount (mutually exclusive with `initialDepositCoinArg`).
|
|
570
552
|
* @param inputs.initialDepositCoinArg - Transaction object argument referencing the deposit coin.
|
|
571
553
|
* @param inputs.tx - Optional {@link Transaction} to extend.
|
|
572
554
|
*
|
|
573
|
-
* @returns
|
|
574
|
-
*
|
|
575
|
-
* @example
|
|
576
|
-
* ```ts
|
|
577
|
-
* const { txKind } = await perps.getCreateVaultTx({
|
|
578
|
-
* walletAddress: "0x...",
|
|
579
|
-
* lpCoinType: "0x...::lp::LP",
|
|
580
|
-
* collateralCoinType: "0x2::sui::SUI",
|
|
581
|
-
* lockPeriodMs: BigInt(7 * 24 * 60 * 60 * 1000),
|
|
582
|
-
* performanceFeePercentage: 0.2,
|
|
583
|
-
* forceWithdrawDelayMs: BigInt(24 * 60 * 60 * 1000),
|
|
584
|
-
* initialDepositAmount: BigInt("1000000000"),
|
|
585
|
-
* });
|
|
586
|
-
* ```
|
|
555
|
+
* @returns {@link SdkTransactionResponse} with `tx`.
|
|
587
556
|
*/
|
|
588
557
|
getCreateVaultTx(inputs) {
|
|
589
558
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -595,22 +564,13 @@ class Perpetuals extends caller_1.Caller {
|
|
|
595
564
|
});
|
|
596
565
|
}
|
|
597
566
|
// =========================================================================
|
|
598
|
-
// Public Static
|
|
599
|
-
// =========================================================================
|
|
600
|
-
// =========================================================================
|
|
601
|
-
// Helpers
|
|
567
|
+
// Public Static Helpers
|
|
602
568
|
// =========================================================================
|
|
603
569
|
/**
|
|
604
570
|
* Determine the logical order side (Bid/Ask) from a signed base asset amount.
|
|
605
571
|
*
|
|
606
|
-
* @param inputs.baseAssetAmount - Position base size. Positive => Bid (long), negative => Ask (short).
|
|
607
|
-
* @returns
|
|
608
|
-
*
|
|
609
|
-
* @example
|
|
610
|
-
* ```ts
|
|
611
|
-
* const side = Perpetuals.positionSide({ baseAssetAmount: -1 });
|
|
612
|
-
* // side === PerpetualsOrderSide.Ask
|
|
613
|
-
* ```
|
|
572
|
+
* @param inputs.baseAssetAmount - Position base size. Positive/zero => Bid (long), negative => Ask (short).
|
|
573
|
+
* @returns {@link PerpetualsOrderSide}.
|
|
614
574
|
*/
|
|
615
575
|
static positionSide(inputs) {
|
|
616
576
|
const baseAmount = inputs.baseAssetAmount;
|
|
@@ -619,25 +579,25 @@ class Perpetuals extends caller_1.Caller {
|
|
|
619
579
|
return side;
|
|
620
580
|
}
|
|
621
581
|
/**
|
|
622
|
-
* Compute the effective price from a {@link FilledTakerOrderEvent}.
|
|
582
|
+
* Compute the effective trade price from a {@link FilledTakerOrderEvent}.
|
|
623
583
|
*
|
|
624
|
-
* Uses `quoteAssetDelta / baseAssetDelta`.
|
|
584
|
+
* Uses the ratio: `quoteAssetDelta / baseAssetDelta`.
|
|
625
585
|
*
|
|
626
586
|
* @param inputs.orderEvent - Filled taker order event.
|
|
627
|
-
* @returns Trade price
|
|
587
|
+
* @returns Trade price.
|
|
628
588
|
*/
|
|
629
589
|
static orderPriceFromEvent(inputs) {
|
|
630
590
|
const { orderEvent } = inputs;
|
|
631
591
|
return orderEvent.quoteAssetDelta / orderEvent.baseAssetDelta;
|
|
632
592
|
}
|
|
633
593
|
/**
|
|
634
|
-
* Extract the
|
|
594
|
+
* Extract the floating-point price from an encoded order ID.
|
|
635
595
|
*
|
|
636
|
-
* Internally uses {@link PerpetualsOrderUtils.price} and converts the
|
|
637
|
-
*
|
|
596
|
+
* Internally uses {@link PerpetualsOrderUtils.price} and converts the fixed-point
|
|
597
|
+
* {@link PerpetualsOrderPrice} into a `number`.
|
|
638
598
|
*
|
|
639
599
|
* @param inputs.orderId - Encoded order ID.
|
|
640
|
-
* @returns
|
|
600
|
+
* @returns Price as a `number`.
|
|
641
601
|
*/
|
|
642
602
|
static orderPriceFromOrderId(inputs) {
|
|
643
603
|
const { orderId } = inputs;
|
|
@@ -645,19 +605,19 @@ class Perpetuals extends caller_1.Caller {
|
|
|
645
605
|
return this.orderPriceToPrice({ orderPrice });
|
|
646
606
|
}
|
|
647
607
|
/**
|
|
648
|
-
* Convert a fixed-point lot
|
|
608
|
+
* Convert a fixed-point lot/tick size (9 decimals) to a `number`.
|
|
649
609
|
*
|
|
650
610
|
* @param lotOrTickSize - Fixed-point size as `bigint`.
|
|
651
|
-
* @returns Floating-point
|
|
611
|
+
* @returns Floating-point size.
|
|
652
612
|
*/
|
|
653
613
|
static lotOrTickSizeToNumber(lotOrTickSize) {
|
|
654
614
|
return Number(lotOrTickSize) / fixedUtils_1.FixedUtils.fixedOneN9;
|
|
655
615
|
}
|
|
656
616
|
/**
|
|
657
|
-
* Convert a floating-point lot
|
|
617
|
+
* Convert a floating-point lot/tick size to its fixed-point representation (9 decimals).
|
|
658
618
|
*
|
|
659
619
|
* @param lotOrTickSize - Floating-point size.
|
|
660
|
-
* @returns Fixed-point
|
|
620
|
+
* @returns Fixed-point size as `bigint`.
|
|
661
621
|
*/
|
|
662
622
|
static lotOrTickSizeToBigInt(lotOrTickSize) {
|
|
663
623
|
return BigInt(Math.round(lotOrTickSize * fixedUtils_1.FixedUtils.fixedOneN9));
|
|
@@ -668,48 +628,28 @@ class Perpetuals extends caller_1.Caller {
|
|
|
668
628
|
/**
|
|
669
629
|
* Open the main updates websocket: `/perpetuals/ws/updates`.
|
|
670
630
|
*
|
|
671
|
-
*
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
* -
|
|
677
|
-
* -
|
|
678
|
-
* -
|
|
679
|
-
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
* @param args.
|
|
685
|
-
* @param args.
|
|
686
|
-
* @param args.
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
* -
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
* - `subscribeOracle` / `unsubscribeOracle`
|
|
694
|
-
* - `subscribeOrderbook` / `unsubscribeOrderbook`
|
|
695
|
-
* - `subscribeMarketOrders` / `unsubscribeMarketOrders`
|
|
696
|
-
* - `subscribeUserOrders` / `unsubscribeUserOrders`
|
|
697
|
-
* - `subscribeUserCollateralChanges` / `unsubscribeUserCollateralChanges`
|
|
698
|
-
* - `close`: function to close the websocket
|
|
699
|
-
*
|
|
700
|
-
* @example
|
|
701
|
-
* ```ts
|
|
702
|
-
* const stream = perps.openUpdatesWebsocketStream({
|
|
703
|
-
* onMessage: (msg) => {
|
|
704
|
-
* if ("market" in msg) {
|
|
705
|
-
* console.log("Market update", msg.market);
|
|
706
|
-
* }
|
|
707
|
-
* },
|
|
708
|
-
* });
|
|
709
|
-
*
|
|
710
|
-
* stream.subscribeMarket({ marketId: "0x..." });
|
|
711
|
-
* stream.subscribeUser({ accountId: 123n, withStopOrders: undefined });
|
|
712
|
-
* ```
|
|
631
|
+
* The stream emits {@link PerpetualsWsUpdatesResponseMessage} envelopes and supports
|
|
632
|
+
* multiple subscription types. This method returns a small controller with
|
|
633
|
+
* convenience subscribe/unsubscribe functions.
|
|
634
|
+
*
|
|
635
|
+
* Subscription types supported by the controller:
|
|
636
|
+
* - `market`: market state updates
|
|
637
|
+
* - `user`: user account updates (optionally including stop orders)
|
|
638
|
+
* - `oracle`: oracle price updates
|
|
639
|
+
* - `orderbook`: orderbook deltas
|
|
640
|
+
* - `marketOrders`: public market trades/orders
|
|
641
|
+
* - `userOrders`: user trade/order events
|
|
642
|
+
* - `userCollateralChanges`: user collateral change events
|
|
643
|
+
*
|
|
644
|
+
* @param args.onMessage - Handler for parsed messages from the websocket.
|
|
645
|
+
* @param args.onOpen - Optional handler for the `open` event.
|
|
646
|
+
* @param args.onError - Optional handler for the `error` event.
|
|
647
|
+
* @param args.onClose - Optional handler for the `close` event.
|
|
648
|
+
*
|
|
649
|
+
* @returns A controller object containing:
|
|
650
|
+
* - `ws`: underlying {@link WebSocket}
|
|
651
|
+
* - subscribe/unsubscribe helpers for each subscription type
|
|
652
|
+
* - `close()`: closes the websocket
|
|
713
653
|
*/
|
|
714
654
|
openUpdatesWebsocketStream(args) {
|
|
715
655
|
const { onMessage, onOpen, onError, onClose } = args;
|
|
@@ -720,7 +660,12 @@ class Perpetuals extends caller_1.Caller {
|
|
|
720
660
|
onError,
|
|
721
661
|
onClose,
|
|
722
662
|
});
|
|
723
|
-
|
|
663
|
+
/**
|
|
664
|
+
* Subscription helpers
|
|
665
|
+
*
|
|
666
|
+
* Each helper sends a structured subscription message of the form:
|
|
667
|
+
* `{ action: "subscribe" | "unsubscribe", subscriptionType: { ... } }`
|
|
668
|
+
*/
|
|
724
669
|
const subscribeMarket = ({ marketId, }) => ctl.send({
|
|
725
670
|
action: "subscribe",
|
|
726
671
|
subscriptionType: { market: { marketId } },
|
|
@@ -810,25 +755,20 @@ class Perpetuals extends caller_1.Caller {
|
|
|
810
755
|
* @param args.onError - Optional hook called on websocket error.
|
|
811
756
|
* @param args.onClose - Optional hook called when the websocket closes.
|
|
812
757
|
*
|
|
813
|
-
* @returns
|
|
814
|
-
* - `ws`: the underlying `WebSocket` instance
|
|
815
|
-
* - `close`: function to close the websocket
|
|
758
|
+
* @returns A controller containing the raw websocket and a `close()` helper.
|
|
816
759
|
*
|
|
817
760
|
* @example
|
|
818
761
|
* ```ts
|
|
819
762
|
* const stream = perps.openMarketCandlesWebsocketStream({
|
|
820
763
|
* marketId: "0x...",
|
|
821
764
|
* intervalMs: 60_000,
|
|
822
|
-
* onMessage: ({ lastCandle }) =>
|
|
823
|
-
* console.log("New candle:", lastCandle);
|
|
824
|
-
* },
|
|
765
|
+
* onMessage: ({ lastCandle }) => console.log(lastCandle),
|
|
825
766
|
* });
|
|
826
767
|
* ```
|
|
827
768
|
*/
|
|
828
769
|
openMarketCandlesWebsocketStream(args) {
|
|
829
770
|
const { marketId, intervalMs, onMessage, onOpen, onError, onClose } = args;
|
|
830
771
|
const path = `ws/market-candles/${encodeURIComponent(marketId)}/${intervalMs}`;
|
|
831
|
-
// Generic handler already BigInt-parses any "123n" in payloads
|
|
832
772
|
const ctl = this.openWsStream({
|
|
833
773
|
path,
|
|
834
774
|
onMessage,
|
|
@@ -857,30 +797,28 @@ Perpetuals.OrderUtils = utils_1.PerpetualsOrderUtils;
|
|
|
857
797
|
* Convert a floating-point price into a fixed-point {@link PerpetualsOrderPrice}
|
|
858
798
|
* using 9 decimal places of precision.
|
|
859
799
|
*
|
|
860
|
-
* @param inputs.price -
|
|
861
|
-
* @returns
|
|
800
|
+
* @param inputs.price - Price as a float.
|
|
801
|
+
* @returns Fixed-point order price.
|
|
862
802
|
*/
|
|
863
803
|
Perpetuals.priceToOrderPrice = (inputs) => {
|
|
864
804
|
const { price } = inputs;
|
|
865
805
|
return BigInt(Math.round(price * fixedUtils_1.FixedUtils.fixedOneN9));
|
|
866
806
|
};
|
|
867
807
|
/**
|
|
868
|
-
* Convert a fixed-point {@link PerpetualsOrderPrice} to a
|
|
808
|
+
* Convert a fixed-point {@link PerpetualsOrderPrice} to a float price.
|
|
869
809
|
*
|
|
870
|
-
* @param inputs.orderPrice -
|
|
871
|
-
* @returns
|
|
810
|
+
* @param inputs.orderPrice - Fixed-point order price.
|
|
811
|
+
* @returns Price as a float.
|
|
872
812
|
*/
|
|
873
813
|
Perpetuals.orderPriceToPrice = (inputs) => {
|
|
874
814
|
const { orderPrice } = inputs;
|
|
875
815
|
return Number(orderPrice) / fixedUtils_1.FixedUtils.fixedOneN9;
|
|
876
816
|
};
|
|
877
817
|
/**
|
|
878
|
-
* Infer the order side from an order ID.
|
|
879
|
-
*
|
|
880
|
-
* Uses {@link PerpetualsOrderUtils.isAsk} under the hood.
|
|
818
|
+
* Infer the order side from an encoded order ID.
|
|
881
819
|
*
|
|
882
820
|
* @param orderId - Encoded order ID.
|
|
883
|
-
* @returns {@link PerpetualsOrderSide
|
|
821
|
+
* @returns {@link PerpetualsOrderSide}.
|
|
884
822
|
*/
|
|
885
823
|
Perpetuals.orderIdToSide = (orderId) => {
|
|
886
824
|
return Perpetuals.OrderUtils.isAsk(orderId)
|
|
@@ -888,23 +826,14 @@ Perpetuals.orderIdToSide = (orderId) => {
|
|
|
888
826
|
: types_1.PerpetualsOrderSide.Bid;
|
|
889
827
|
};
|
|
890
828
|
/**
|
|
891
|
-
* Construct a
|
|
829
|
+
* Construct a collateral-specialized Move event type string.
|
|
892
830
|
*
|
|
893
|
-
* Many Move events are generic over a collateral coin type. This helper
|
|
894
|
-
*
|
|
831
|
+
* Many Move events are generic over a collateral coin type. This helper appends
|
|
832
|
+
* `<collateralCoinType>` to a base `eventType`.
|
|
895
833
|
*
|
|
896
834
|
* @param inputs.eventType - Base event type without type parameters.
|
|
897
|
-
* @param inputs.collateralCoinType - Collateral coin type
|
|
835
|
+
* @param inputs.collateralCoinType - Collateral coin type (e.g. `"0x2::sui::SUI"`).
|
|
898
836
|
* @returns Fully-qualified event type string.
|
|
899
|
-
*
|
|
900
|
-
* @example
|
|
901
|
-
* ```ts
|
|
902
|
-
* const fullType = Perpetuals.eventTypeForCollateral({
|
|
903
|
-
* eventType: "0x1::perps::DepositedCollateral",
|
|
904
|
-
* collateralCoinType: "0x2::sui::SUI",
|
|
905
|
-
* });
|
|
906
|
-
* // "0x1::perps::DepositedCollateral<0x2::sui::SUI>"
|
|
907
|
-
* ```
|
|
908
837
|
*/
|
|
909
838
|
Perpetuals.eventTypeForCollateral = (inputs) => {
|
|
910
839
|
return `${inputs.eventType}<${inputs.collateralCoinType}>`;
|