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.
- 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 +246 -6
- package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsVault.d.ts +273 -7
- package/dist/packages/perpetuals/perpetualsVault.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsVault.js +287 -64
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Caller } from "../../general/utils/caller";
|
|
2
|
-
import { PerpetualsMarketId, ApiPerpetualsOwnedAccountCapsBody, PerpetualsOrderSide, CoinType, PerpetualsOrderId, FilledTakerOrderEvent, ApiPerpetualsMarketCandleHistoryResponse, PerpetualsAccountCap, PerpetualsAccountId, CallerConfig, SuiAddress, ObjectId, ApiPerpetualsMarkets24hrStatsResponse, ApiPerpetualsAccountCapsBody, Percentage, Balance, ApiPerpetualsVaultOwnedWithdrawRequestsBody, PerpetualsOrderPrice, ApiTransactionResponse, PerpetualsWsUpdatesResponseMessage, PerpetualsWsCandleResponseMessage, ApiPerpetualsCreateVaultCapBody, PerpetualsPartialVaultCap, ApiPerpetualsMarketCandleHistoryBody, ApiPerpetualsAccountCapsResponse, ApiPerpetualsOwnedAccountCapsResponse, ApiPerpetualsAccountPositionsResponse, ApiPerpetualsAccountPositionsBody, ApiPerpetualsMarketsPricesResponse, ApiPerpetualsVaultLpCoinPricesResponse, ApiPerpetualsVaultLpCoinPricesBody, ApiPerpetualsVaultOwnedLpCoinsResponse, ApiPerpetualsVaultOwnedLpCoinsBody, ApiPerpetualsOwnedVaultCapsBody, ApiPerpetualsOwnedVaultCapsResponse, ApiPerpetualsVaultOwnedWithdrawRequestsResponse } from "../../types";
|
|
2
|
+
import { PerpetualsMarketId, ApiPerpetualsOwnedAccountCapsBody, PerpetualsOrderSide, CoinType, PerpetualsOrderId, FilledTakerOrderEvent, ApiPerpetualsMarketCandleHistoryResponse, PerpetualsAccountCap, PerpetualsAccountId, CallerConfig, SuiAddress, ObjectId, ApiPerpetualsMarkets24hrStatsResponse, ApiPerpetualsAccountCapsBody, Percentage, Balance, ApiPerpetualsVaultOwnedWithdrawRequestsBody, PerpetualsOrderPrice, ApiTransactionResponse, PerpetualsWsUpdatesResponseMessage, PerpetualsWsCandleResponseMessage, ApiPerpetualsCreateVaultCapBody, PerpetualsPartialVaultCap, ApiPerpetualsMarketCandleHistoryBody, ApiPerpetualsAccountCapsResponse, ApiPerpetualsOwnedAccountCapsResponse, ApiPerpetualsAccountPositionsResponse, ApiPerpetualsAccountPositionsBody, ApiPerpetualsMarketsPricesResponse, ApiPerpetualsVaultLpCoinPricesResponse, ApiPerpetualsVaultLpCoinPricesBody, ApiPerpetualsVaultOwnedLpCoinsResponse, ApiPerpetualsVaultOwnedLpCoinsBody, ApiPerpetualsOwnedVaultCapsBody, ApiPerpetualsOwnedVaultCapsResponse, ApiPerpetualsVaultOwnedWithdrawRequestsResponse, SdkTransactionResponse } from "../../types";
|
|
3
3
|
import { PerpetualsMarket } from "./perpetualsMarket";
|
|
4
4
|
import { PerpetualsAccount } from "./perpetualsAccount";
|
|
5
5
|
import { PerpetualsOrderUtils } from "./utils";
|
|
@@ -64,19 +64,28 @@ export declare class Perpetuals extends Caller {
|
|
|
64
64
|
*
|
|
65
65
|
* @param config - Optional caller configuration (network, auth token, etc.).
|
|
66
66
|
* @param Provider - Optional shared {@link AftermathApi} provider instance. When
|
|
67
|
-
* provided, transaction-building helpers
|
|
68
|
-
*
|
|
67
|
+
* provided, transaction-building helpers can derive serialized `txKind`
|
|
68
|
+
* from a {@link Transaction} object via `Provider.Transactions().fetchBase64TxKindFromTx`.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* This class extends {@link Caller} with the `"perpetuals"` route prefix, meaning:
|
|
72
|
+
* - HTTP calls resolve under `/perpetuals/...`
|
|
73
|
+
* - Websocket calls resolve under `/perpetuals/ws/...`
|
|
69
74
|
*/
|
|
70
75
|
constructor(config?: CallerConfig, Provider?: AftermathApi | undefined);
|
|
71
76
|
/**
|
|
72
77
|
* Fetch all perpetual markets for a given collateral coin type.
|
|
73
78
|
*
|
|
79
|
+
* This method returns *wrapped* {@link PerpetualsMarket} instances, not the raw
|
|
80
|
+
* market structs. Each instance provides additional helpers for pricing, margin,
|
|
81
|
+
* and order parsing.
|
|
82
|
+
*
|
|
74
83
|
* @param inputs.collateralCoinType - Coin type used as collateral, e.g. `"0x2::sui::SUI"`.
|
|
75
|
-
* @returns
|
|
84
|
+
* @returns Object containing `markets`.
|
|
76
85
|
*
|
|
77
86
|
* @example
|
|
78
87
|
* ```ts
|
|
79
|
-
* const markets = await perps.getAllMarkets({
|
|
88
|
+
* const { markets } = await perps.getAllMarkets({
|
|
80
89
|
* collateralCoinType: "0x2::sui::SUI",
|
|
81
90
|
* });
|
|
82
91
|
* ```
|
|
@@ -92,11 +101,15 @@ export declare class Perpetuals extends Caller {
|
|
|
92
101
|
* Internally calls {@link getMarkets} and returns the first entry.
|
|
93
102
|
*
|
|
94
103
|
* @param inputs.marketId - The market (clearing house) object ID.
|
|
95
|
-
* @returns
|
|
104
|
+
* @returns Object containing `market`.
|
|
105
|
+
*
|
|
106
|
+
* @throws If the backend returns an empty list for the given `marketId`,
|
|
107
|
+
* this will still attempt to return `markets[0]` (which would be `undefined`).
|
|
108
|
+
* Callers may want to validate the result.
|
|
96
109
|
*
|
|
97
110
|
* @example
|
|
98
111
|
* ```ts
|
|
99
|
-
* const market = await perps.getMarket({ marketId: "0x..." });
|
|
112
|
+
* const { market } = await perps.getMarket({ marketId: "0x..." });
|
|
100
113
|
* ```
|
|
101
114
|
*/
|
|
102
115
|
getMarket(inputs: {
|
|
@@ -107,16 +120,17 @@ export declare class Perpetuals extends Caller {
|
|
|
107
120
|
/**
|
|
108
121
|
* Fetch multiple markets by ID.
|
|
109
122
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* {@link PerpetualsMarket}
|
|
123
|
+
* Backend note:
|
|
124
|
+
* - The API supports returning orderbooks. This SDK currently forces
|
|
125
|
+
* `withOrderbook: false` and constructs {@link PerpetualsMarket} from
|
|
126
|
+
* the returned `marketDatas[].market`.
|
|
113
127
|
*
|
|
114
128
|
* @param inputs.marketIds - Array of market object IDs to fetch.
|
|
115
|
-
* @returns
|
|
129
|
+
* @returns Object containing `markets` in the same order as `marketIds`.
|
|
116
130
|
*
|
|
117
131
|
* @example
|
|
118
132
|
* ```ts
|
|
119
|
-
* const
|
|
133
|
+
* const { markets } = await perps.getMarkets({
|
|
120
134
|
* marketIds: ["0x..A", "0x..B"],
|
|
121
135
|
* });
|
|
122
136
|
* ```
|
|
@@ -129,11 +143,14 @@ export declare class Perpetuals extends Caller {
|
|
|
129
143
|
/**
|
|
130
144
|
* Fetch all vaults on the current network.
|
|
131
145
|
*
|
|
132
|
-
*
|
|
146
|
+
* Vaults are managed accounts that can hold positions; LPs deposit collateral
|
|
147
|
+
* and receive an LP coin (see pricing helpers like {@link getLpCoinPrices}).
|
|
148
|
+
*
|
|
149
|
+
* @returns Object containing `vaults`.
|
|
133
150
|
*
|
|
134
151
|
* @example
|
|
135
152
|
* ```ts
|
|
136
|
-
* const vaults = await perps.getAllVaults();
|
|
153
|
+
* const { vaults } = await perps.getAllVaults();
|
|
137
154
|
* ```
|
|
138
155
|
*/
|
|
139
156
|
getAllVaults(): Promise<{
|
|
@@ -144,13 +161,12 @@ export declare class Perpetuals extends Caller {
|
|
|
144
161
|
*
|
|
145
162
|
* Internally calls {@link getVaults} and returns the first entry.
|
|
146
163
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
164
|
+
* Naming note:
|
|
165
|
+
* - This method’s parameter is named `marketId` for historical reasons,
|
|
166
|
+
* but it refers to a vault object ID.
|
|
149
167
|
*
|
|
150
|
-
* @
|
|
151
|
-
*
|
|
152
|
-
* const vault = await perps.getVault({ marketId: "0x..." });
|
|
153
|
-
* ```
|
|
168
|
+
* @param inputs.marketId - Vault object ID.
|
|
169
|
+
* @returns Object containing `vault`.
|
|
154
170
|
*/
|
|
155
171
|
getVault(inputs: {
|
|
156
172
|
marketId: ObjectId;
|
|
@@ -161,14 +177,7 @@ export declare class Perpetuals extends Caller {
|
|
|
161
177
|
* Fetch multiple vaults by ID.
|
|
162
178
|
*
|
|
163
179
|
* @param inputs.vaultIds - Array of vault object IDs.
|
|
164
|
-
* @returns
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```ts
|
|
168
|
-
* const [vaultA, vaultB] = await perps.getVaults({
|
|
169
|
-
* vaultIds: ["0x..A", "0x..B"],
|
|
170
|
-
* });
|
|
171
|
-
* ```
|
|
180
|
+
* @returns Object containing `vaults` in the same order as `vaultIds`.
|
|
172
181
|
*/
|
|
173
182
|
getVaults(inputs: {
|
|
174
183
|
vaultIds: ObjectId[];
|
|
@@ -182,12 +191,12 @@ export declare class Perpetuals extends Caller {
|
|
|
182
191
|
*
|
|
183
192
|
* @param inputs.accountCap - Account-cap or vault-cap-extended object to derive account metadata from.
|
|
184
193
|
* @param inputs.marketIds - Optional list of markets to filter positions by.
|
|
185
|
-
* @returns
|
|
194
|
+
* @returns Object containing `account`.
|
|
186
195
|
*
|
|
187
196
|
* @example
|
|
188
197
|
* ```ts
|
|
189
198
|
* const [accountCap] = await perps.getOwnedAccountCaps({ walletAddress: "0x..." });
|
|
190
|
-
* const account = await perps.getAccount({ accountCap });
|
|
199
|
+
* const { account } = await perps.getAccount({ accountCap });
|
|
191
200
|
* ```
|
|
192
201
|
*/
|
|
193
202
|
getAccount(inputs: {
|
|
@@ -199,22 +208,20 @@ export declare class Perpetuals extends Caller {
|
|
|
199
208
|
/**
|
|
200
209
|
* Fetch one or more accounts (positions + account objects) from account caps.
|
|
201
210
|
*
|
|
202
|
-
* This composes
|
|
203
|
-
*
|
|
204
|
-
*
|
|
211
|
+
* This composes:
|
|
212
|
+
* 1) {@link getAccountObjects} to fetch {@link PerpetualsAccountObject}s by account ID
|
|
213
|
+
* 2) Local pairing of returned account objects with `accountCaps`
|
|
205
214
|
*
|
|
206
|
-
* The
|
|
207
|
-
*
|
|
215
|
+
* The returned {@link PerpetualsAccount} instances encapsulate:
|
|
216
|
+
* - The account snapshot (positions, balances, etc.)
|
|
217
|
+
* - The ownership/cap metadata (accountId, collateral type, vaultId, etc.)
|
|
208
218
|
*
|
|
209
219
|
* @param inputs.accountCaps - Array of account caps or vault-cap-extended objects.
|
|
210
220
|
* @param inputs.marketIds - Optional list of market IDs to filter positions by.
|
|
211
|
-
* @returns
|
|
221
|
+
* @returns Object containing `accounts` in the same order as `accountCaps`.
|
|
212
222
|
*
|
|
213
|
-
* @
|
|
214
|
-
*
|
|
215
|
-
* const accountCaps = await perps.getOwnedAccountCaps({ walletAddress: "0x..." });
|
|
216
|
-
* const accounts = await perps.getAccounts({ accountCaps });
|
|
217
|
-
* ```
|
|
223
|
+
* @remarks
|
|
224
|
+
* If `accountCaps` is empty, this returns `{ accounts: [] }` without making an API call.
|
|
218
225
|
*/
|
|
219
226
|
getAccounts(inputs: {
|
|
220
227
|
accountCaps: (PerpetualsAccountCap | PerpetualsPartialVaultCap)[];
|
|
@@ -225,33 +232,31 @@ export declare class Perpetuals extends Caller {
|
|
|
225
232
|
/**
|
|
226
233
|
* Fetch raw account objects (including positions) for one or more account IDs.
|
|
227
234
|
*
|
|
228
|
-
*
|
|
235
|
+
* This is the lower-level primitive used by {@link getAccounts}.
|
|
229
236
|
*
|
|
230
237
|
* @param inputs.accountIds - List of account IDs to query.
|
|
231
238
|
* @param inputs.marketIds - Optional list of market IDs to filter positions by.
|
|
232
|
-
* @returns Array of {@link PerpetualsAccountObject}.
|
|
233
239
|
*
|
|
234
|
-
* @
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* });
|
|
239
|
-
* ```
|
|
240
|
+
* @returns {@link ApiPerpetualsAccountPositionsResponse} containing `accounts`.
|
|
241
|
+
*
|
|
242
|
+
* @remarks
|
|
243
|
+
* If `accountIds` is empty, this returns `{ accounts: [] }` without making an API call.
|
|
240
244
|
*/
|
|
241
245
|
getAccountObjects(inputs: ApiPerpetualsAccountPositionsBody): Promise<ApiPerpetualsAccountPositionsResponse>;
|
|
242
246
|
/**
|
|
243
247
|
* Fetch all account caps (perpetuals accounts) owned by a wallet, optionally
|
|
244
248
|
* filtered by collateral coin types.
|
|
245
249
|
*
|
|
246
|
-
*
|
|
250
|
+
* Returned values are “caps” (ownership objects), not full account snapshots.
|
|
251
|
+
* To fetch account positions, use {@link getAccount} or {@link getAccounts}.
|
|
247
252
|
*
|
|
248
253
|
* @param inputs.walletAddress - Owner wallet address.
|
|
249
254
|
* @param inputs.collateralCoinTypes - Optional list of collateral coin types to filter by.
|
|
250
|
-
* @returns
|
|
255
|
+
* @returns {@link ApiPerpetualsOwnedAccountCapsResponse} containing `accounts`.
|
|
251
256
|
*
|
|
252
257
|
* @example
|
|
253
258
|
* ```ts
|
|
254
|
-
* const
|
|
259
|
+
* const { accounts } = await perps.getOwnedAccountCaps({
|
|
255
260
|
* walletAddress: "0x...",
|
|
256
261
|
* collateralCoinTypes: ["0x2::sui::SUI"],
|
|
257
262
|
* });
|
|
@@ -261,44 +266,37 @@ export declare class Perpetuals extends Caller {
|
|
|
261
266
|
/**
|
|
262
267
|
* Fetch all vault caps owned by a wallet.
|
|
263
268
|
*
|
|
264
|
-
*
|
|
265
|
-
* @returns Array of {@link PerpetualsVaultCap} objects.
|
|
269
|
+
* Vault caps represent ownership/administrative authority over a vault.
|
|
266
270
|
*
|
|
267
|
-
* @
|
|
268
|
-
*
|
|
269
|
-
* const vaultCaps = await perps.getOwnedVaultCaps({
|
|
270
|
-
* walletAddress: "0x...",
|
|
271
|
-
* });
|
|
272
|
-
* ```
|
|
271
|
+
* @param inputs.walletAddress - Owner wallet address.
|
|
272
|
+
* @returns {@link ApiPerpetualsOwnedVaultCapsResponse} containing vault caps.
|
|
273
273
|
*/
|
|
274
274
|
getOwnedVaultCaps(inputs: ApiPerpetualsOwnedVaultCapsBody): Promise<ApiPerpetualsOwnedVaultCapsResponse>;
|
|
275
275
|
/**
|
|
276
276
|
* Fetch all pending vault withdrawal requests created by a given wallet.
|
|
277
277
|
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
278
|
+
* Withdraw requests are typically created when LPs request to exit a vault
|
|
279
|
+
* and may be subject to lock periods / delays depending on vault configuration.
|
|
280
280
|
*
|
|
281
|
-
* @
|
|
282
|
-
*
|
|
283
|
-
* const withdrawRequests = await perps.getOwnedVaultWithdrawRequests({
|
|
284
|
-
* walletAddress: "0x...",
|
|
285
|
-
* });
|
|
286
|
-
* ```
|
|
281
|
+
* @param inputs.walletAddress - Wallet address that created the withdraw requests.
|
|
282
|
+
* @returns {@link ApiPerpetualsVaultOwnedWithdrawRequestsResponse} containing requests.
|
|
287
283
|
*/
|
|
288
284
|
getOwnedVaultWithdrawRequests(inputs: ApiPerpetualsVaultOwnedWithdrawRequestsBody): Promise<ApiPerpetualsVaultOwnedWithdrawRequestsResponse>;
|
|
285
|
+
/**
|
|
286
|
+
* Fetch all Perpetuals vault LP coins owned by a wallet.
|
|
287
|
+
*
|
|
288
|
+
* This returns coin objects (or summaries) representing LP token holdings.
|
|
289
|
+
* Use {@link getLpCoinPrices} to value them in collateral units.
|
|
290
|
+
*
|
|
291
|
+
* @param inputs - {@link ApiPerpetualsVaultOwnedLpCoinsBody}.
|
|
292
|
+
* @returns {@link ApiPerpetualsVaultOwnedLpCoinsResponse}.
|
|
293
|
+
*/
|
|
289
294
|
getOwnedVaultLpCoins(inputs: ApiPerpetualsVaultOwnedLpCoinsBody): Promise<ApiPerpetualsVaultOwnedLpCoinsResponse>;
|
|
290
295
|
/**
|
|
291
296
|
* Fetch account caps by their cap object IDs.
|
|
292
297
|
*
|
|
293
298
|
* @param inputs.accountCapIds - List of account cap object IDs.
|
|
294
|
-
* @returns
|
|
295
|
-
*
|
|
296
|
-
* @example
|
|
297
|
-
* ```ts
|
|
298
|
-
* const caps = await perps.getAccountCaps({
|
|
299
|
-
* accountCapIds: ["0xcap1", "0xcap2"],
|
|
300
|
-
* });
|
|
301
|
-
* ```
|
|
299
|
+
* @returns {@link ApiPerpetualsAccountCapsResponse} containing caps.
|
|
302
300
|
*/
|
|
303
301
|
getAccountCaps(inputs: ApiPerpetualsAccountCapsBody): Promise<ApiPerpetualsAccountCapsResponse>;
|
|
304
302
|
/**
|
|
@@ -308,31 +306,19 @@ export declare class Perpetuals extends Caller {
|
|
|
308
306
|
* @param inputs.fromTimestamp - Start timestamp (inclusive).
|
|
309
307
|
* @param inputs.toTimestamp - End timestamp (exclusive).
|
|
310
308
|
* @param inputs.intervalMs - Candle interval in milliseconds.
|
|
311
|
-
* @returns Array of {@link PerpetualsMarketCandleDataPoint}.
|
|
312
309
|
*
|
|
313
|
-
* @
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
* toTimestamp: Date.now(),
|
|
319
|
-
* intervalMs: 60_000, // 1 minute
|
|
320
|
-
* });
|
|
321
|
-
* ```
|
|
310
|
+
* @returns {@link ApiPerpetualsMarketCandleHistoryResponse} containing candle points.
|
|
311
|
+
*
|
|
312
|
+
* @remarks
|
|
313
|
+
* This is currently implemented on the Perpetuals root client, but it may be
|
|
314
|
+
* relocated to {@link PerpetualsMarket} in the future.
|
|
322
315
|
*/
|
|
323
316
|
getMarketCandleHistory(inputs: ApiPerpetualsMarketCandleHistoryBody): Promise<ApiPerpetualsMarketCandleHistoryResponse>;
|
|
324
317
|
/**
|
|
325
318
|
* Fetch 24-hour stats for multiple markets.
|
|
326
319
|
*
|
|
327
320
|
* @param inputs.marketIds - Market IDs to query.
|
|
328
|
-
* @returns
|
|
329
|
-
*
|
|
330
|
-
* @example
|
|
331
|
-
* ```ts
|
|
332
|
-
* const stats = await perps.getMarkets24hrStats({
|
|
333
|
-
* marketIds: ["0x...", "0x..."],
|
|
334
|
-
* });
|
|
335
|
-
* ```
|
|
321
|
+
* @returns {@link ApiPerpetualsMarkets24hrStatsResponse}.
|
|
336
322
|
*/
|
|
337
323
|
getMarkets24hrStats(inputs: {
|
|
338
324
|
marketIds: PerpetualsMarketId[];
|
|
@@ -341,14 +327,10 @@ export declare class Perpetuals extends Caller {
|
|
|
341
327
|
* Fetch the latest oracle prices (base & collateral) for one or more markets.
|
|
342
328
|
*
|
|
343
329
|
* @param inputs.marketIds - List of market IDs to query.
|
|
344
|
-
* @returns
|
|
345
|
-
* Returns `[]` if `marketIds` is empty.
|
|
330
|
+
* @returns {@link ApiPerpetualsMarketsPricesResponse} containing `marketsPrices`.
|
|
346
331
|
*
|
|
347
|
-
* @
|
|
348
|
-
*
|
|
349
|
-
* const prices = await perps.getPrices({ marketIds: ["0x..."] });
|
|
350
|
-
* const { basePrice, collateralPrice } = prices[0];
|
|
351
|
-
* ```
|
|
332
|
+
* @remarks
|
|
333
|
+
* If `marketIds` is empty, returns `{ marketsPrices: [] }` without making an API call.
|
|
352
334
|
*/
|
|
353
335
|
getPrices(inputs: {
|
|
354
336
|
marketIds: ObjectId[];
|
|
@@ -357,116 +339,90 @@ export declare class Perpetuals extends Caller {
|
|
|
357
339
|
* Fetch LP coin prices (in collateral units) for a set of vaults.
|
|
358
340
|
*
|
|
359
341
|
* @param inputs.vaultIds - List of vault IDs to query.
|
|
360
|
-
* @returns
|
|
342
|
+
* @returns {@link ApiPerpetualsVaultLpCoinPricesResponse} containing `lpCoinPrices`.
|
|
361
343
|
*
|
|
362
|
-
* @
|
|
363
|
-
*
|
|
364
|
-
* const [price] = await perps.getLpCoinPrices({ vaultIds: ["0x..."] });
|
|
365
|
-
* ```
|
|
344
|
+
* @remarks
|
|
345
|
+
* If `vaultIds` is empty, returns `{ lpCoinPrices: [] }` without making an API call.
|
|
366
346
|
*/
|
|
367
347
|
getLpCoinPrices(inputs: ApiPerpetualsVaultLpCoinPricesBody): Promise<ApiPerpetualsVaultLpCoinPricesResponse>;
|
|
368
348
|
/**
|
|
369
349
|
* Build a `create-account` transaction for Aftermath Perpetuals.
|
|
370
350
|
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
* - Returns a serialized transaction (`txKind`) that you can sign and execute.
|
|
376
|
-
*
|
|
377
|
-
* @param inputs.walletAddress - The wallet address that will own the new account.
|
|
378
|
-
* @param inputs.collateralCoinType - Collateral coin type to be used with this account.
|
|
379
|
-
* @param inputs.tx - Optional {@link Transaction} to extend; if provided,
|
|
380
|
-
* the create-account commands are appended to this transaction.
|
|
351
|
+
* @param inputs.walletAddress - Wallet address that will own the new account.
|
|
352
|
+
* @param inputs.collateralCoinType - Collateral coin type used by the account.
|
|
353
|
+
* @param inputs.tx - Optional {@link Transaction} to extend; if provided, the
|
|
354
|
+
* create-account commands are appended to this transaction.
|
|
381
355
|
*
|
|
382
|
-
* @returns
|
|
383
|
-
*
|
|
384
|
-
* @example
|
|
385
|
-
* ```ts
|
|
386
|
-
* const { txKind } = await perps.getCreateAccountTx({
|
|
387
|
-
* walletAddress: "0x...",
|
|
388
|
-
* collateralCoinType: "0x2::sui::SUI",
|
|
389
|
-
* });
|
|
390
|
-
* // sign + execute txKind with your wallet adapter
|
|
391
|
-
* ```
|
|
356
|
+
* @returns {@link SdkTransactionResponse} with `tx`.
|
|
392
357
|
*/
|
|
393
358
|
getCreateAccountTx(inputs: {
|
|
394
359
|
walletAddress: SuiAddress;
|
|
395
360
|
collateralCoinType: CoinType;
|
|
396
361
|
tx?: Transaction;
|
|
397
|
-
}): Promise<
|
|
398
|
-
|
|
399
|
-
|
|
362
|
+
}): Promise<SdkTransactionResponse>;
|
|
363
|
+
/**
|
|
364
|
+
* Build a `create-vault-cap` transaction.
|
|
365
|
+
*
|
|
366
|
+
* A vault cap is an ownership/admin object for interacting with vault management
|
|
367
|
+
* flows. This method returns a transaction kind that mints/creates that cap.
|
|
368
|
+
*
|
|
369
|
+
* @param inputs - {@link ApiPerpetualsCreateVaultCapBody}.
|
|
370
|
+
* @returns {@link SdkTransactionResponse} with `tx`.
|
|
371
|
+
*/
|
|
400
372
|
getCreateVaultCapTx(inputs: ApiPerpetualsCreateVaultCapBody): Promise<Omit<ApiTransactionResponse, "txKind"> & {
|
|
401
373
|
tx: Transaction;
|
|
402
374
|
}>;
|
|
403
375
|
/**
|
|
404
376
|
* Build a `create-vault` transaction.
|
|
405
377
|
*
|
|
406
|
-
* This
|
|
407
|
-
*
|
|
408
|
-
* via the shared `Provider` (if present).
|
|
409
|
-
* - Calls `/perpetuals/vault/transactions/create-vault`.
|
|
410
|
-
* - Returns a serialized transaction (`txKind`) that you can sign and execute.
|
|
378
|
+
* This creates a new vault plus its on-chain metadata and initial LP supply
|
|
379
|
+
* seeded by the initial deposit.
|
|
411
380
|
*
|
|
412
|
-
*
|
|
413
|
-
* `
|
|
381
|
+
* Deposit input:
|
|
382
|
+
* - Use `initialDepositAmount` to have the API select/merge coins as needed, OR
|
|
383
|
+
* - Use `initialDepositCoinArg` if you already have a coin argument in a larger tx.
|
|
414
384
|
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
385
|
+
* Metadata:
|
|
386
|
+
* - Stored on-chain (or in a referenced object) as part of vault creation.
|
|
387
|
+
* - `extraFields` allows forward-compatible additions (e.g. social links).
|
|
388
|
+
*
|
|
389
|
+
* @param inputs.walletAddress - Address of vault owner/curator.
|
|
390
|
+
* @param inputs.metadata - Vault display metadata (name, description, curator info).
|
|
391
|
+
* @param inputs.metadata - Vault display metadata (name, description, curator info).
|
|
392
|
+
* @param inputs.coinMetadataId - Coin metadata object id obtained from create vault cap tx
|
|
393
|
+
* @param inputs.treasuryCapId - Treasury cap object id obtained from create vault cap tx
|
|
394
|
+
* @param inputs.collateralCoinType - Collateral coin type for deposits.
|
|
418
395
|
* @param inputs.lockPeriodMs - Lock-in period for deposits in milliseconds.
|
|
419
|
-
* @param inputs.performanceFeePercentage -
|
|
420
|
-
* @param inputs.forceWithdrawDelayMs - Delay before forced withdrawals
|
|
421
|
-
* @param inputs.isSponsoredTx - Whether this
|
|
396
|
+
* @param inputs.performanceFeePercentage - Fraction of profits taken as curator fee.
|
|
397
|
+
* @param inputs.forceWithdrawDelayMs - Delay before forced withdrawals can be processed.
|
|
398
|
+
* @param inputs.isSponsoredTx - Whether this tx is sponsored (gas paid by another party).
|
|
422
399
|
* @param inputs.initialDepositAmount - Initial deposit amount (mutually exclusive with `initialDepositCoinArg`).
|
|
423
400
|
* @param inputs.initialDepositCoinArg - Transaction object argument referencing the deposit coin.
|
|
424
401
|
* @param inputs.tx - Optional {@link Transaction} to extend.
|
|
425
402
|
*
|
|
426
|
-
* @returns
|
|
427
|
-
*
|
|
428
|
-
* @example
|
|
429
|
-
* ```ts
|
|
430
|
-
* const { txKind } = await perps.getCreateVaultTx({
|
|
431
|
-
* walletAddress: "0x...",
|
|
432
|
-
* lpCoinType: "0x...::lp::LP",
|
|
433
|
-
* collateralCoinType: "0x2::sui::SUI",
|
|
434
|
-
* lockPeriodMs: BigInt(7 * 24 * 60 * 60 * 1000),
|
|
435
|
-
* performanceFeePercentage: 0.2,
|
|
436
|
-
* forceWithdrawDelayMs: BigInt(24 * 60 * 60 * 1000),
|
|
437
|
-
* initialDepositAmount: BigInt("1000000000"),
|
|
438
|
-
* });
|
|
439
|
-
* ```
|
|
403
|
+
* @returns {@link SdkTransactionResponse} with `tx`.
|
|
440
404
|
*/
|
|
441
405
|
getCreateVaultTx(inputs: {
|
|
442
406
|
walletAddress: SuiAddress;
|
|
443
407
|
metadata: {
|
|
444
|
-
/**
|
|
445
|
-
* A human-readable name for the `Vault`.
|
|
446
|
-
*/
|
|
408
|
+
/** A human-readable name for the `Vault`. */
|
|
447
409
|
name: string;
|
|
448
|
-
/**
|
|
449
|
-
* A verbose description of the `Vault`.
|
|
450
|
-
*/
|
|
410
|
+
/** A verbose description of the `Vault`. */
|
|
451
411
|
description: string;
|
|
452
|
-
/**
|
|
453
|
-
* The `Vault` curator's name.
|
|
454
|
-
*/
|
|
412
|
+
/** The `Vault` curator's name. */
|
|
455
413
|
curatorName?: string;
|
|
456
|
-
/**
|
|
457
|
-
* A url for the `Vault`'s curator. Ideally their website.
|
|
458
|
-
*/
|
|
414
|
+
/** A url for the `Vault`'s curator. Ideally their website. */
|
|
459
415
|
curatorUrl?: string;
|
|
460
|
-
/**
|
|
461
|
-
* An image url for the `Vault`'s curator. Ideally their logo.
|
|
462
|
-
*/
|
|
416
|
+
/** An image url for the `Vault`'s curator. Ideally their logo. */
|
|
463
417
|
curatorLogoUrl?: string;
|
|
464
418
|
/**
|
|
465
|
-
* Extra / optional fields for future extensibility.
|
|
419
|
+
* Extra / optional fields for future extensibility.
|
|
420
|
+
* Recommended keys include: `twitter_url`.
|
|
466
421
|
*/
|
|
467
422
|
extraFields?: Record<string, string>;
|
|
468
423
|
};
|
|
469
|
-
|
|
424
|
+
coinMetadataId: ObjectId;
|
|
425
|
+
treasuryCapId: ObjectId;
|
|
470
426
|
collateralCoinType: CoinType;
|
|
471
427
|
lockPeriodMs: bigint;
|
|
472
428
|
performanceFeePercentage: Percentage;
|
|
@@ -483,37 +439,31 @@ export declare class Perpetuals extends Caller {
|
|
|
483
439
|
/**
|
|
484
440
|
* Determine the logical order side (Bid/Ask) from a signed base asset amount.
|
|
485
441
|
*
|
|
486
|
-
* @param inputs.baseAssetAmount - Position base size. Positive => Bid (long), negative => Ask (short).
|
|
487
|
-
* @returns
|
|
488
|
-
*
|
|
489
|
-
* @example
|
|
490
|
-
* ```ts
|
|
491
|
-
* const side = Perpetuals.positionSide({ baseAssetAmount: -1 });
|
|
492
|
-
* // side === PerpetualsOrderSide.Ask
|
|
493
|
-
* ```
|
|
442
|
+
* @param inputs.baseAssetAmount - Position base size. Positive/zero => Bid (long), negative => Ask (short).
|
|
443
|
+
* @returns {@link PerpetualsOrderSide}.
|
|
494
444
|
*/
|
|
495
445
|
static positionSide(inputs: {
|
|
496
446
|
baseAssetAmount: number;
|
|
497
447
|
}): PerpetualsOrderSide;
|
|
498
448
|
/**
|
|
499
|
-
* Compute the effective price from a {@link FilledTakerOrderEvent}.
|
|
449
|
+
* Compute the effective trade price from a {@link FilledTakerOrderEvent}.
|
|
500
450
|
*
|
|
501
|
-
* Uses `quoteAssetDelta / baseAssetDelta`.
|
|
451
|
+
* Uses the ratio: `quoteAssetDelta / baseAssetDelta`.
|
|
502
452
|
*
|
|
503
453
|
* @param inputs.orderEvent - Filled taker order event.
|
|
504
|
-
* @returns Trade price
|
|
454
|
+
* @returns Trade price.
|
|
505
455
|
*/
|
|
506
456
|
static orderPriceFromEvent(inputs: {
|
|
507
457
|
orderEvent: FilledTakerOrderEvent;
|
|
508
458
|
}): number;
|
|
509
459
|
/**
|
|
510
|
-
* Extract the
|
|
460
|
+
* Extract the floating-point price from an encoded order ID.
|
|
511
461
|
*
|
|
512
|
-
* Internally uses {@link PerpetualsOrderUtils.price} and converts the
|
|
513
|
-
*
|
|
462
|
+
* Internally uses {@link PerpetualsOrderUtils.price} and converts the fixed-point
|
|
463
|
+
* {@link PerpetualsOrderPrice} into a `number`.
|
|
514
464
|
*
|
|
515
465
|
* @param inputs.orderId - Encoded order ID.
|
|
516
|
-
* @returns
|
|
466
|
+
* @returns Price as a `number`.
|
|
517
467
|
*/
|
|
518
468
|
static orderPriceFromOrderId(inputs: {
|
|
519
469
|
orderId: PerpetualsOrderId;
|
|
@@ -522,62 +472,51 @@ export declare class Perpetuals extends Caller {
|
|
|
522
472
|
* Convert a floating-point price into a fixed-point {@link PerpetualsOrderPrice}
|
|
523
473
|
* using 9 decimal places of precision.
|
|
524
474
|
*
|
|
525
|
-
* @param inputs.price -
|
|
526
|
-
* @returns
|
|
475
|
+
* @param inputs.price - Price as a float.
|
|
476
|
+
* @returns Fixed-point order price.
|
|
527
477
|
*/
|
|
528
478
|
static priceToOrderPrice: (inputs: {
|
|
529
479
|
price: number;
|
|
530
480
|
}) => PerpetualsOrderPrice;
|
|
531
481
|
/**
|
|
532
|
-
* Convert a fixed-point {@link PerpetualsOrderPrice} to a
|
|
482
|
+
* Convert a fixed-point {@link PerpetualsOrderPrice} to a float price.
|
|
533
483
|
*
|
|
534
|
-
* @param inputs.orderPrice -
|
|
535
|
-
* @returns
|
|
484
|
+
* @param inputs.orderPrice - Fixed-point order price.
|
|
485
|
+
* @returns Price as a float.
|
|
536
486
|
*/
|
|
537
487
|
static orderPriceToPrice: (inputs: {
|
|
538
488
|
orderPrice: PerpetualsOrderPrice;
|
|
539
489
|
}) => number;
|
|
540
490
|
/**
|
|
541
|
-
* Convert a fixed-point lot
|
|
491
|
+
* Convert a fixed-point lot/tick size (9 decimals) to a `number`.
|
|
542
492
|
*
|
|
543
493
|
* @param lotOrTickSize - Fixed-point size as `bigint`.
|
|
544
|
-
* @returns Floating-point
|
|
494
|
+
* @returns Floating-point size.
|
|
545
495
|
*/
|
|
546
496
|
static lotOrTickSizeToNumber(lotOrTickSize: bigint): number;
|
|
547
497
|
/**
|
|
548
|
-
* Convert a floating-point lot
|
|
498
|
+
* Convert a floating-point lot/tick size to its fixed-point representation (9 decimals).
|
|
549
499
|
*
|
|
550
500
|
* @param lotOrTickSize - Floating-point size.
|
|
551
|
-
* @returns Fixed-point
|
|
501
|
+
* @returns Fixed-point size as `bigint`.
|
|
552
502
|
*/
|
|
553
503
|
static lotOrTickSizeToBigInt(lotOrTickSize: number): bigint;
|
|
554
504
|
/**
|
|
555
|
-
* Infer the order side from an order ID.
|
|
556
|
-
*
|
|
557
|
-
* Uses {@link PerpetualsOrderUtils.isAsk} under the hood.
|
|
505
|
+
* Infer the order side from an encoded order ID.
|
|
558
506
|
*
|
|
559
507
|
* @param orderId - Encoded order ID.
|
|
560
|
-
* @returns {@link PerpetualsOrderSide
|
|
508
|
+
* @returns {@link PerpetualsOrderSide}.
|
|
561
509
|
*/
|
|
562
510
|
static orderIdToSide: (orderId: PerpetualsOrderId) => PerpetualsOrderSide;
|
|
563
511
|
/**
|
|
564
|
-
* Construct a
|
|
512
|
+
* Construct a collateral-specialized Move event type string.
|
|
565
513
|
*
|
|
566
|
-
* Many Move events are generic over a collateral coin type. This helper
|
|
567
|
-
*
|
|
514
|
+
* Many Move events are generic over a collateral coin type. This helper appends
|
|
515
|
+
* `<collateralCoinType>` to a base `eventType`.
|
|
568
516
|
*
|
|
569
517
|
* @param inputs.eventType - Base event type without type parameters.
|
|
570
|
-
* @param inputs.collateralCoinType - Collateral coin type
|
|
518
|
+
* @param inputs.collateralCoinType - Collateral coin type (e.g. `"0x2::sui::SUI"`).
|
|
571
519
|
* @returns Fully-qualified event type string.
|
|
572
|
-
*
|
|
573
|
-
* @example
|
|
574
|
-
* ```ts
|
|
575
|
-
* const fullType = Perpetuals.eventTypeForCollateral({
|
|
576
|
-
* eventType: "0x1::perps::DepositedCollateral",
|
|
577
|
-
* collateralCoinType: "0x2::sui::SUI",
|
|
578
|
-
* });
|
|
579
|
-
* // "0x1::perps::DepositedCollateral<0x2::sui::SUI>"
|
|
580
|
-
* ```
|
|
581
520
|
*/
|
|
582
521
|
static eventTypeForCollateral: (inputs: {
|
|
583
522
|
eventType: string;
|
|
@@ -586,48 +525,28 @@ export declare class Perpetuals extends Caller {
|
|
|
586
525
|
/**
|
|
587
526
|
* Open the main updates websocket: `/perpetuals/ws/updates`.
|
|
588
527
|
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
* -
|
|
595
|
-
* -
|
|
596
|
-
* -
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
* @param args.
|
|
603
|
-
* @param args.
|
|
604
|
-
* @param args.
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
* -
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
* - `subscribeOracle` / `unsubscribeOracle`
|
|
612
|
-
* - `subscribeOrderbook` / `unsubscribeOrderbook`
|
|
613
|
-
* - `subscribeMarketOrders` / `unsubscribeMarketOrders`
|
|
614
|
-
* - `subscribeUserOrders` / `unsubscribeUserOrders`
|
|
615
|
-
* - `subscribeUserCollateralChanges` / `unsubscribeUserCollateralChanges`
|
|
616
|
-
* - `close`: function to close the websocket
|
|
617
|
-
*
|
|
618
|
-
* @example
|
|
619
|
-
* ```ts
|
|
620
|
-
* const stream = perps.openUpdatesWebsocketStream({
|
|
621
|
-
* onMessage: (msg) => {
|
|
622
|
-
* if ("market" in msg) {
|
|
623
|
-
* console.log("Market update", msg.market);
|
|
624
|
-
* }
|
|
625
|
-
* },
|
|
626
|
-
* });
|
|
627
|
-
*
|
|
628
|
-
* stream.subscribeMarket({ marketId: "0x..." });
|
|
629
|
-
* stream.subscribeUser({ accountId: 123n, withStopOrders: undefined });
|
|
630
|
-
* ```
|
|
528
|
+
* The stream emits {@link PerpetualsWsUpdatesResponseMessage} envelopes and supports
|
|
529
|
+
* multiple subscription types. This method returns a small controller with
|
|
530
|
+
* convenience subscribe/unsubscribe functions.
|
|
531
|
+
*
|
|
532
|
+
* Subscription types supported by the controller:
|
|
533
|
+
* - `market`: market state updates
|
|
534
|
+
* - `user`: user account updates (optionally including stop orders)
|
|
535
|
+
* - `oracle`: oracle price updates
|
|
536
|
+
* - `orderbook`: orderbook deltas
|
|
537
|
+
* - `marketOrders`: public market trades/orders
|
|
538
|
+
* - `userOrders`: user trade/order events
|
|
539
|
+
* - `userCollateralChanges`: user collateral change events
|
|
540
|
+
*
|
|
541
|
+
* @param args.onMessage - Handler for parsed messages from the websocket.
|
|
542
|
+
* @param args.onOpen - Optional handler for the `open` event.
|
|
543
|
+
* @param args.onError - Optional handler for the `error` event.
|
|
544
|
+
* @param args.onClose - Optional handler for the `close` event.
|
|
545
|
+
*
|
|
546
|
+
* @returns A controller object containing:
|
|
547
|
+
* - `ws`: underlying {@link WebSocket}
|
|
548
|
+
* - subscribe/unsubscribe helpers for each subscription type
|
|
549
|
+
* - `close()`: closes the websocket
|
|
631
550
|
*/
|
|
632
551
|
openUpdatesWebsocketStream(args: {
|
|
633
552
|
onMessage: (env: PerpetualsWsUpdatesResponseMessage) => void;
|
|
@@ -704,18 +623,14 @@ export declare class Perpetuals extends Caller {
|
|
|
704
623
|
* @param args.onError - Optional hook called on websocket error.
|
|
705
624
|
* @param args.onClose - Optional hook called when the websocket closes.
|
|
706
625
|
*
|
|
707
|
-
* @returns
|
|
708
|
-
* - `ws`: the underlying `WebSocket` instance
|
|
709
|
-
* - `close`: function to close the websocket
|
|
626
|
+
* @returns A controller containing the raw websocket and a `close()` helper.
|
|
710
627
|
*
|
|
711
628
|
* @example
|
|
712
629
|
* ```ts
|
|
713
630
|
* const stream = perps.openMarketCandlesWebsocketStream({
|
|
714
631
|
* marketId: "0x...",
|
|
715
632
|
* intervalMs: 60_000,
|
|
716
|
-
* onMessage: ({ lastCandle }) =>
|
|
717
|
-
* console.log("New candle:", lastCandle);
|
|
718
|
-
* },
|
|
633
|
+
* onMessage: ({ lastCandle }) => console.log(lastCandle),
|
|
719
634
|
* });
|
|
720
635
|
* ```
|
|
721
636
|
*/
|