@nightlylabs/dex-sdk 0.0.1

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.
@@ -0,0 +1,590 @@
1
+ import * as _aptos_labs_ts_sdk from '@aptos-labs/ts-sdk';
2
+ import { Aptos, Account, SimpleTransaction, AccountAuthenticator } from '@aptos-labs/ts-sdk';
3
+ import * as _thalalabs_surf_build_types_core from '@thalalabs/surf/build/types/core';
4
+ import * as _thalalabs_surf from '@thalalabs/surf';
5
+ import WebSocket from 'isomorphic-ws';
6
+
7
+ interface StatusResponse {
8
+ status: string;
9
+ }
10
+ interface TimeResponse {
11
+ time: string;
12
+ }
13
+ interface UtilizationCurve {
14
+ base: string;
15
+ multiplier: string;
16
+ kink: string;
17
+ jump: string;
18
+ }
19
+ interface BorrowLending {
20
+ tokenAddress: string;
21
+ lendShares: string;
22
+ lendAmount: string;
23
+ borrowShares: string;
24
+ borrowAmount: string;
25
+ utilizationCurve: UtilizationCurve;
26
+ borrowEnabled: boolean;
27
+ lastUpdated: string;
28
+ }
29
+ interface GetBorrowLendingDataResponse {
30
+ data: Record<string, BorrowLending>;
31
+ }
32
+ interface GetPerpMarketsDataRequest {
33
+ markets: string[];
34
+ }
35
+ interface PerpMarketData {
36
+ price: string;
37
+ priceIndex: string;
38
+ change24: string;
39
+ high24: string;
40
+ low24: string;
41
+ baseVolume24: string;
42
+ quoteVolume24: string;
43
+ fundingRate: string;
44
+ openInterest24: string;
45
+ timestamp: string;
46
+ }
47
+ interface GetPerpMarketsDataResponse {
48
+ perpMarkets: Record<string, PerpMarketData>;
49
+ }
50
+ interface Content {
51
+ price: string;
52
+ size: string;
53
+ }
54
+ interface PerpOrderBookData {
55
+ timestamp: string;
56
+ bids: Content[];
57
+ asks: Content[];
58
+ }
59
+ interface GetPerpOrderBookDataRequest {
60
+ marketName: string;
61
+ }
62
+ interface GetPerpOrderBookDataResponse {
63
+ data: PerpOrderBookData;
64
+ }
65
+ interface MarginStep {
66
+ initialMarginRation: string;
67
+ initialAmount: string;
68
+ maintenanceMarginRatio: string;
69
+ maintenanceAmount: string;
70
+ maxPositionInUsd: string;
71
+ }
72
+ declare enum PerpetualMarketStatus {
73
+ Halted = "halted",
74
+ ReduceOnly = "reduceOnly",
75
+ PostOnly = "postOnly",
76
+ Live = "live"
77
+ }
78
+ interface FundingRate {
79
+ enabled: boolean;
80
+ interestRateHourly: string;
81
+ clampMin: string;
82
+ clampMax: string;
83
+ maxFundingRate: string;
84
+ minFundingRate: string;
85
+ }
86
+ interface PerpetualMarketConfigEntry {
87
+ name: string;
88
+ priceIndex: string;
89
+ marginSteps: MarginStep[];
90
+ liquidationPenalty: string;
91
+ lotSize: string;
92
+ tickSize: string;
93
+ status: PerpetualMarketStatus;
94
+ fundingRate: FundingRate;
95
+ }
96
+ interface GetPerpetualMarketsConfigResponse {
97
+ perpMarkets: Record<string, PerpetualMarketConfigEntry>;
98
+ }
99
+ interface PriceIndex {
100
+ name: string;
101
+ price: string;
102
+ lastUpdate: number;
103
+ }
104
+ interface GetPriceIndexesResponse {
105
+ prices: Record<string, PriceIndex>;
106
+ }
107
+ interface TokenConfigEntry {
108
+ name: string;
109
+ priceIndex: string;
110
+ collateralFactor: string;
111
+ borrowInitialFactor: string;
112
+ borrowMaintenanceFactor: string;
113
+ liquidationPenalty: string;
114
+ contractAddress: string;
115
+ enabled: boolean;
116
+ }
117
+ interface GetTokensConfigResponse {
118
+ tokens: Record<string, TokenConfigEntry>;
119
+ usdcAddress?: string;
120
+ }
121
+ interface GetUserDataRequest {
122
+ userId: string;
123
+ }
124
+ interface FundingCheckpoint {
125
+ index: string;
126
+ fundingPerLot: string;
127
+ }
128
+ interface PerpPosition {
129
+ size: string;
130
+ entryPrice: string;
131
+ fundingCheckpoint: FundingCheckpoint;
132
+ }
133
+ interface VaultInvestment {
134
+ sharesAmount: string;
135
+ sharePrice: string;
136
+ }
137
+ interface Fees {
138
+ tier: string;
139
+ perpTakerFee: string;
140
+ perpMakerFee: string;
141
+ spotTakerFee: string;
142
+ spotMakerFee: string;
143
+ discount: string;
144
+ referrerUserId?: string;
145
+ referrerKickback: string;
146
+ }
147
+ interface Referral {
148
+ discount: string;
149
+ kickback: string;
150
+ }
151
+ interface User {
152
+ userId: string;
153
+ alias: string;
154
+ autolendEnabled: boolean;
155
+ tokenBalances: Record<string, string>;
156
+ positions: Record<string, PerpPosition>;
157
+ perpOrders: Record<string, Order>;
158
+ lendingShares: Record<string, string>;
159
+ borrowShares: Record<string, string>;
160
+ apiKeys: Record<string, string>;
161
+ vaultInvestments: Record<string, VaultInvestment>;
162
+ fees: Fees;
163
+ referral: Referral;
164
+ vault?: string;
165
+ }
166
+ interface GetUserDataResponse {
167
+ userData: User;
168
+ perpOrdersCount: string;
169
+ }
170
+ interface SubmitSponsoredTransactionRequest {
171
+ sender: string;
172
+ sequenceNumber: string;
173
+ payload: number[];
174
+ maxGasAmount: string;
175
+ gasUnitPrice: string;
176
+ expirationTimestampSecs: string;
177
+ chainId: string;
178
+ authenticator: number[];
179
+ }
180
+ interface SubmitSponsoredTransactionResponse {
181
+ txHash: string;
182
+ }
183
+ interface ExchangeConfig {
184
+ tokens: Record<string, TokenConfigEntry>;
185
+ usdcAddress?: string;
186
+ perpetualsMarkets: Record<string, PerpetualMarketConfigEntry>;
187
+ }
188
+ declare enum OrderSide {
189
+ Bid = "Bid",
190
+ Ask = "Ask"
191
+ }
192
+ interface Order {
193
+ id: string;
194
+ size: string;
195
+ market: string;
196
+ price: string;
197
+ side: OrderSide;
198
+ sizeLeft: string;
199
+ timestamp: string;
200
+ }
201
+ interface OracleUpdate {
202
+ name: string;
203
+ price: string;
204
+ }
205
+ interface OracleUpdates {
206
+ updates: OracleUpdate[];
207
+ }
208
+ interface OrderbookUpdate {
209
+ market: string;
210
+ updates: Record<string, string>;
211
+ }
212
+ interface Trade {
213
+ id: string;
214
+ size: string;
215
+ price: string;
216
+ timestamp: string;
217
+ is_bid: boolean;
218
+ }
219
+ interface TradesUpdate {
220
+ market: string;
221
+ updates: Trade[];
222
+ }
223
+ interface BalanceChange {
224
+ user_id: string;
225
+ token_address: string;
226
+ amount: string;
227
+ }
228
+ interface Deposit {
229
+ user_id: string;
230
+ token_address: string;
231
+ amount: string;
232
+ }
233
+ interface Withdraw {
234
+ user_id: string;
235
+ token_address: string;
236
+ amount: string;
237
+ }
238
+ interface WithdrawLend {
239
+ user_id: string;
240
+ token_address: string;
241
+ shares_amount: string;
242
+ token_received: string;
243
+ }
244
+ interface Lend {
245
+ user_id: string;
246
+ token_address: string;
247
+ token_amount: string;
248
+ shares_received: string;
249
+ }
250
+ interface Borrow {
251
+ user_id: string;
252
+ token_address: string;
253
+ token_amount: string;
254
+ shares_received: string;
255
+ }
256
+ interface RepayBorrow {
257
+ user_id: string;
258
+ token_address: string;
259
+ shares_repaid: string;
260
+ token_repaid: string;
261
+ share_price: string;
262
+ }
263
+ interface WsFill {
264
+ id: string;
265
+ size: string;
266
+ price: string;
267
+ fee_paid: string;
268
+ }
269
+ interface PlacePerpLimitOrder {
270
+ market: string;
271
+ user_id: string;
272
+ is_bid: boolean;
273
+ price: string;
274
+ size: string;
275
+ post_only: boolean;
276
+ reduce_only: boolean;
277
+ order_id: string;
278
+ filled_size: string;
279
+ fills: WsFill[];
280
+ }
281
+ interface PlacePerpMarketOrder {
282
+ market: string;
283
+ user_id: string;
284
+ is_bid: boolean;
285
+ max_price: string;
286
+ size: string;
287
+ reduce_only: boolean;
288
+ order_id: string;
289
+ fills: WsFill[];
290
+ }
291
+ interface OrderFills {
292
+ market: string;
293
+ user_id: string;
294
+ order_id: string;
295
+ fills: WsFill[];
296
+ }
297
+ interface CanceledPerpOrders {
298
+ market: string;
299
+ user_id: string;
300
+ orders_ids: Array<string>;
301
+ }
302
+ interface ErrorResponse {
303
+ code: number;
304
+ variant: string;
305
+ message: string;
306
+ }
307
+ declare enum EndpointsV1 {
308
+ Ws = "/v1/ws",
309
+ GetConfig = "/v1/get_config",
310
+ GetTokensConfig = "/v1/get_tokens_config",
311
+ GetPerpMarketsConfig = "/v1/get_perp_markets_config",
312
+ GetUserData = "/v1/get_user_data",
313
+ GetPriceIndexes = "/v1/get_price_indexes",
314
+ GetPerpOrderBookData = "/v1/get_perp_orderbook_data",
315
+ GetPerpMarketsData = "/v1/get_perp_markets_data",
316
+ GetBorrowLendingData = "/v1/get_borrow_lending_data",
317
+ SubmitSponsoredTransactionRequest = "/v1/submit_sponsored_transaction"
318
+ }
319
+ declare enum AdminEndpoints {
320
+ Placeholder = "/admin/placeholder"
321
+ }
322
+ declare enum BaseEndpoints {
323
+ Time = "/time",
324
+ Status = "/app_status"
325
+ }
326
+ type Topic = {
327
+ type: "Market";
328
+ content: string;
329
+ } | {
330
+ type: "User";
331
+ content: {
332
+ id: string;
333
+ };
334
+ } | {
335
+ type: "Oracle";
336
+ content?: undefined;
337
+ };
338
+ type WsCommand = {
339
+ type: "SubscribeMarket";
340
+ content: {
341
+ id: string;
342
+ market: string;
343
+ };
344
+ } | {
345
+ type: "UnsubscribeMarket";
346
+ content: {
347
+ id: string;
348
+ market: string;
349
+ };
350
+ } | {
351
+ type: "SubscribeUser";
352
+ content: {
353
+ id: string;
354
+ user_id: string;
355
+ };
356
+ } | {
357
+ type: "UnsubscribeUser";
358
+ content: {
359
+ id: string;
360
+ user_id: string;
361
+ };
362
+ } | {
363
+ type: "SubscribeOracle";
364
+ content: {
365
+ id: string;
366
+ };
367
+ } | {
368
+ type: "UnsubscribeOracle";
369
+ content: {
370
+ id: string;
371
+ };
372
+ };
373
+ type WsMessage = {
374
+ type: "Ack";
375
+ content: {
376
+ id: string;
377
+ };
378
+ } | {
379
+ type: "Error";
380
+ content: {
381
+ id: string;
382
+ message: string;
383
+ };
384
+ } | {
385
+ type: "OracleUpdates";
386
+ content: OracleUpdates;
387
+ } | {
388
+ type: "OrderbookUpdate";
389
+ content: OrderbookUpdate;
390
+ } | {
391
+ type: "TradesUpdate";
392
+ content: TradesUpdate;
393
+ } | {
394
+ type: "BalanceChange";
395
+ content: BalanceChange;
396
+ } | {
397
+ type: "Deposit";
398
+ content: Deposit;
399
+ } | {
400
+ type: "Withdraw";
401
+ content: Withdraw;
402
+ } | {
403
+ type: "WithdrawLend";
404
+ content: WithdrawLend;
405
+ } | {
406
+ type: "Lend";
407
+ content: Lend;
408
+ } | {
409
+ type: "Borrow";
410
+ content: Borrow;
411
+ } | {
412
+ type: "RepayBorrow";
413
+ content: RepayBorrow;
414
+ } | {
415
+ type: "PlacePerpLimitOrder";
416
+ content: PlacePerpLimitOrder;
417
+ } | {
418
+ type: "PlacePerpMarketOrder";
419
+ content: PlacePerpMarketOrder;
420
+ } | {
421
+ type: "CanceledPerpOrders";
422
+ content: CanceledPerpOrders;
423
+ } | {
424
+ type: "OrderFills";
425
+ content: OrderFills;
426
+ };
427
+ declare enum OrderStatus {
428
+ Placed = "Placed",
429
+ Cancelled = "Cancelled",
430
+ Filled = "Filled",
431
+ PartiallyFilled = "PartiallyFilled",
432
+ Rejected = "Rejected",
433
+ Executed = "Executed"
434
+ }
435
+ declare enum OrderType {
436
+ Limit = "Limit",
437
+ Market = "Market"
438
+ }
439
+ declare enum TradeRole {
440
+ Maker = "Maker",
441
+ Taker = "Taker"
442
+ }
443
+ declare enum UserStatus {
444
+ Active = "Active",
445
+ Locked = "Locked"
446
+ }
447
+
448
+ type Address = `0x${string}`;
449
+ declare enum Status {
450
+ Halted = 0,
451
+ ReduceOnly = 1,
452
+ PostOnly = 2,
453
+ Live = 3
454
+ }
455
+ declare enum Network {
456
+ Devnet = "Devnet"
457
+ }
458
+
459
+ declare const getRandomId: () => string;
460
+ declare class Client {
461
+ _aptos: Aptos;
462
+ _surf: _thalalabs_surf_build_types_core.MoveTsClient<_thalalabs_surf.DefaultABITable>;
463
+ _apiKey: Account;
464
+ _ws: WebSocket;
465
+ _serverUrl: string;
466
+ _subscriptions: Map<string, (data: WsMessage) => void>;
467
+ timeout: number;
468
+ static init(connection: Aptos, apiKey?: Account, url?: string): Promise<Client>;
469
+ constructor(connection: Aptos, ws: WebSocket, url: string, apiKey?: Account);
470
+ static initWebSocket(url: string, timeout?: number): Promise<WebSocket>;
471
+ sendWsMessage(message: WsCommand): Promise<WsMessage>;
472
+ static create(connection: Aptos, apiKey?: Account, url?: string): Promise<Client>;
473
+ setApiKey(apiKey: Account): void;
474
+ createUser(params: CreateUserParams): Promise<{
475
+ tx: SimpleTransaction;
476
+ signature: AccountAuthenticator;
477
+ apiKey: _aptos_labs_ts_sdk.Ed25519Account;
478
+ }>;
479
+ subscribeToUserUpdates(userId: string, callback: (data: WsMessage) => void): Promise<void>;
480
+ unsubscribeFromUserUpdates(userId: string): Promise<void>;
481
+ addApiKey(params: AddApiKeyParams): Promise<_thalalabs_surf.EntryPayload>;
482
+ removeApiKey(params: RemoveApiKeyParams): Promise<SubmitSponsoredTransactionResponse>;
483
+ setAliasName(params: SetAliasNameParams): Promise<SubmitSponsoredTransactionResponse>;
484
+ placePerpLimitOrder(params: PlacePerpLimitOrderParams): Promise<SubmitSponsoredTransactionResponse>;
485
+ placePerpMarketOrder(params: PlacePerpMarketOrderParams): Promise<SubmitSponsoredTransactionResponse>;
486
+ cancelPerpOrders(params: CancelPerpOrdersParams): Promise<SubmitSponsoredTransactionResponse>;
487
+ cancelAllPerpOrders(params: CancelAllPerpOrdersParams): Promise<SubmitSponsoredTransactionResponse>;
488
+ setAutolend(params: SetAutolendParams): Promise<SubmitSponsoredTransactionResponse>;
489
+ depositToVault(params: DepositToVaultParams): Promise<SubmitSponsoredTransactionResponse>;
490
+ withdrawFromVault(params: WithdrawFromVaultParams): Promise<SubmitSponsoredTransactionResponse>;
491
+ redeemToken(params: RedeemTokenParams): Promise<SubmitSponsoredTransactionResponse>;
492
+ lendToken(params: LendTokenParams): Promise<SubmitSponsoredTransactionResponse>;
493
+ sendGetJson: (endpoint: string, message?: {
494
+ [key: string]: any;
495
+ }) => Promise<any>;
496
+ sendPostJson: (message: object, endpoint: string) => Promise<any>;
497
+ submitSponsoredTransaction: (tx: SimpleTransaction, signature: AccountAuthenticator) => Promise<SubmitSponsoredTransactionResponse>;
498
+ getConfig: () => Promise<ExchangeConfig>;
499
+ getTokensConfig: () => Promise<GetTokensConfigResponse>;
500
+ getPerpetualMarketsConfig: () => Promise<GetPerpetualMarketsConfigResponse>;
501
+ getUserData: (userId: string) => Promise<GetUserDataResponse>;
502
+ getPerpOrderBookData: (marketName: string) => Promise<GetPerpOrderBookDataResponse>;
503
+ getPerpMarketsData: (markets: string[]) => Promise<GetPerpMarketsDataResponse>;
504
+ getBorrowLendingData: () => Promise<GetBorrowLendingDataResponse>;
505
+ }
506
+ interface PlacePerpLimitOrderParams {
507
+ userId: string;
508
+ market: Uint8Array;
509
+ isBid: boolean;
510
+ price: string;
511
+ size: string;
512
+ postOnly: boolean;
513
+ }
514
+ interface PlacePerpMarketOrderParams {
515
+ userId: string;
516
+ market: Uint8Array;
517
+ isBid: boolean;
518
+ price: string;
519
+ size: string;
520
+ }
521
+ interface CancelAllPerpOrdersParams {
522
+ userId: string;
523
+ }
524
+ interface CancelPerpOrdersParams {
525
+ userId: string;
526
+ markets: Uint8Array[];
527
+ orderIds: string[][];
528
+ }
529
+ interface AddApiKeyParams {
530
+ apiKey: Address;
531
+ userId: string;
532
+ expiration: string;
533
+ }
534
+ interface RemoveApiKeyParams {
535
+ apiKey: Address;
536
+ userId: string;
537
+ }
538
+ interface CreateUserParams {
539
+ sender: Address;
540
+ name: string;
541
+ referralId: string;
542
+ }
543
+ interface SetAliasNameParams {
544
+ userId: string;
545
+ alias: string;
546
+ }
547
+ interface SetAutolendParams {
548
+ userId: string;
549
+ enabled: boolean;
550
+ }
551
+ interface DepositToVaultParams {
552
+ userId: string;
553
+ vaultId: string;
554
+ amount: string;
555
+ }
556
+ interface WithdrawFromVaultParams {
557
+ userId: string;
558
+ vaultId: string;
559
+ amount: string;
560
+ max: boolean;
561
+ }
562
+ interface RedeemTokenParams {
563
+ userId: string;
564
+ token: Address;
565
+ amount: string;
566
+ max: boolean;
567
+ }
568
+ interface LendTokenParams {
569
+ userId: string;
570
+ token: Address;
571
+ amount: string;
572
+ max: boolean;
573
+ }
574
+
575
+ declare const ExchangeProxies: {
576
+ [key in Network]: string[];
577
+ };
578
+ declare const GLOBAL_DENOMINATOR = 100000000;
579
+
580
+ declare class TestFaucet extends Client {
581
+ constructor(connection: Aptos, ws: WebSocket, url: string, apiKey?: Account);
582
+ static create(connection: Aptos, apiKey?: Account, url?: string): Promise<TestFaucet>;
583
+ initFaucetPayload(): _thalalabs_surf.EntryPayload;
584
+ initFaucet(): Promise<SubmitSponsoredTransactionResponse>;
585
+ mintTokenPayload(receiver: Address, token: string, amount: number): _thalalabs_surf.EntryPayload;
586
+ mintToken(receiver: Address, token: string, amount: number): Promise<SubmitSponsoredTransactionResponse>;
587
+ getUSDCAddress(): Promise<`0x${string}`>;
588
+ }
589
+
590
+ export { type AddApiKeyParams, type Address, AdminEndpoints, type BalanceChange, BaseEndpoints, type Borrow, type BorrowLending, type CancelAllPerpOrdersParams, type CancelPerpOrdersParams, type CanceledPerpOrders, Client, type Content, type CreateUserParams, type Deposit, type DepositToVaultParams, EndpointsV1, type ErrorResponse, type ExchangeConfig, ExchangeProxies, type Fees, type FundingCheckpoint, type FundingRate, GLOBAL_DENOMINATOR, type GetBorrowLendingDataResponse, type GetPerpMarketsDataRequest, type GetPerpMarketsDataResponse, type GetPerpOrderBookDataRequest, type GetPerpOrderBookDataResponse, type GetPerpetualMarketsConfigResponse, type GetPriceIndexesResponse, type GetTokensConfigResponse, type GetUserDataRequest, type GetUserDataResponse, type Lend, type LendTokenParams, type MarginStep, Network, type OracleUpdate, type OracleUpdates, type Order, type OrderFills, OrderSide, OrderStatus, OrderType, type OrderbookUpdate, type PerpMarketData, type PerpOrderBookData, type PerpPosition, type PerpetualMarketConfigEntry, PerpetualMarketStatus, type PlacePerpLimitOrder, type PlacePerpLimitOrderParams, type PlacePerpMarketOrder, type PlacePerpMarketOrderParams, type PriceIndex, type RedeemTokenParams, type Referral, type RemoveApiKeyParams, type RepayBorrow, type SetAliasNameParams, type SetAutolendParams, Status, type StatusResponse, type SubmitSponsoredTransactionRequest, type SubmitSponsoredTransactionResponse, TestFaucet, type TimeResponse, type TokenConfigEntry, type Topic, type Trade, TradeRole, type TradesUpdate, type User, UserStatus, type UtilizationCurve, type VaultInvestment, type Withdraw, type WithdrawFromVaultParams, type WithdrawLend, type WsCommand, type WsFill, type WsMessage, getRandomId };