@nightlylabs/dex-sdk 0.3.37 → 0.3.38

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/index.cjs CHANGED
@@ -23578,7 +23578,6 @@ var EndpointsV1 = /* @__PURE__ */ ((EndpointsV12) => {
23578
23578
  EndpointsV12["GetIndexPrices"] = "/v1/get_index_prices";
23579
23579
  EndpointsV12["GetAccountValueRanking"] = "/v1/get_account_value_ranking";
23580
23580
  EndpointsV12["GetUserAccountValueRanking"] = "/v1/get_user_account_value_ranking";
23581
- EndpointsV12["GetExchangeStatsHistory"] = "/v1/get_exchange_stats_history";
23582
23581
  return EndpointsV12;
23583
23582
  })(EndpointsV1 || {});
23584
23583
  var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
@@ -23934,15 +23933,13 @@ var AccountSequenceNumber = class {
23934
23933
  // src/client.ts
23935
23934
  var getRandomId = () => (0, import_uuid.v7)();
23936
23935
  var Client = class _Client {
23937
- constructor(connection, enableWs, url, apiKey, chainId, params, networkMode = "testnet", wsDebug = false, timeout = 5e3) {
23936
+ constructor(connection, enableWs, url, apiKey, chainId, params, networkMode = "testnet") {
23938
23937
  this._apiKeySequenceNumber = 0;
23939
23938
  this._subscriptions = /* @__PURE__ */ new Map();
23940
23939
  this._gasUnitPrice = 100;
23941
23940
  this._expirationTimestampDelay = 20;
23942
23941
  // 20 seconds
23943
23942
  this.timeout = 5e3;
23944
- // Same as below in init
23945
- this.wsDebug = false;
23946
23943
  /////////////////////////////////// Sponsored transactions
23947
23944
  this.submitSponsoredTransaction = async (tx, signature) => {
23948
23945
  const payload = {
@@ -24392,25 +24389,13 @@ var Client = class _Client {
24392
24389
  this._maxGas = params?.maxGas || 2e4;
24393
24390
  this._gasUnitPrice = params?.gasUnitPrice || 100;
24394
24391
  this._expirationTimestampDelay = params?.expirationTimestampSecs || 20;
24395
- this.wsDebug = wsDebug;
24396
- this.timeout = timeout;
24397
24392
  if (enableWs) {
24398
24393
  this.connectWebSocket();
24399
24394
  }
24400
24395
  }
24401
- static async init(connection, enableWs = true, url, apiKey, chainId, params, networkMode = "testnet", wsDebug = false, timeout = 5e3) {
24396
+ static async init(connection, enableWs = true, url, apiKey, chainId, params, networkMode = "testnet") {
24402
24397
  const id = chainId || await connection.getChainId();
24403
- const client = new _Client(
24404
- connection,
24405
- enableWs,
24406
- url,
24407
- apiKey,
24408
- id,
24409
- params,
24410
- networkMode,
24411
- wsDebug,
24412
- timeout
24413
- );
24398
+ const client = new _Client(connection, enableWs, url, apiKey, id, params, networkMode);
24414
24399
  if (enableWs) {
24415
24400
  client.connectWebSocket();
24416
24401
  }
@@ -24444,21 +24429,11 @@ var Client = class _Client {
24444
24429
  * myApiKeyAccount // custom API key
24445
24430
  * )
24446
24431
  */
24447
- static async create(connection, networkMode = "testnet", enableWs = true, url, apiKey, wsDebug = false, timeout = 5e3) {
24432
+ static async create(connection, networkMode = "testnet", enableWs = true, url, apiKey) {
24448
24433
  const networkConfig = getNetworkConfig(networkMode);
24449
24434
  const apiUrl = url || networkConfig.apiUrl;
24450
24435
  const chainId = networkConfig.chainId;
24451
- return _Client.init(
24452
- connection,
24453
- enableWs,
24454
- apiUrl,
24455
- apiKey,
24456
- chainId,
24457
- void 0,
24458
- networkMode,
24459
- wsDebug,
24460
- timeout
24461
- );
24436
+ return _Client.init(connection, enableWs, apiUrl, apiKey, chainId, void 0, networkMode);
24462
24437
  }
24463
24438
  async setApiKey(apiKey) {
24464
24439
  this._apiKey = apiKey;
@@ -24484,60 +24459,21 @@ var Client = class _Client {
24484
24459
  this._expirationTimestampDelay = params.expirationTimestampSecs;
24485
24460
  }
24486
24461
  //////////////////////////////////////// Websocket functions
24487
- _wsLog(...args) {
24488
- if (this.wsDebug) console.log("[WS]", ...args);
24489
- }
24490
- setWsDebugActive(active) {
24491
- this.wsDebug = active;
24492
- }
24493
24462
  async connectWebSocket() {
24494
24463
  if (this._ws) {
24495
24464
  console.warn("WebSocket is already connected");
24496
24465
  return;
24497
24466
  }
24498
24467
  try {
24499
- const wsUrl = `${this._serverUrl.replace("http", "ws").replace("https", "wss")}` + "/v1/ws" /* Ws */;
24500
- this._wsLog("Connecting to", wsUrl);
24501
- this._ws = new WebSocket(wsUrl);
24468
+ this._ws = await _Client.initWebSocket(this._serverUrl, this.timeout);
24502
24469
  this._setupWebSocketHandlers();
24503
- await this._waitForOpen(this.timeout);
24504
- this._wsLog("Connected");
24470
+ return;
24505
24471
  } catch (error) {
24506
- this._wsLog("Connection failed:", error);
24507
- this._ws = void 0;
24508
24472
  throw new Error(`Failed to connect WebSocket: ${error}`);
24509
24473
  }
24510
24474
  }
24511
- _waitForOpen(timeout) {
24512
- return new Promise((resolve, reject) => {
24513
- if (!this._ws) return reject(new Error("No WebSocket"));
24514
- if (this._ws.readyState === WebSocket.OPEN) {
24515
- return resolve();
24516
- }
24517
- const timer = setTimeout(() => {
24518
- this._wsLog("Connection timeout after", timeout, "ms");
24519
- reject(new Error("WebSocket connection timeout"));
24520
- }, timeout);
24521
- const ws = this._ws;
24522
- const origOnOpen = ws.onopen;
24523
- ws.onopen = (event) => {
24524
- clearTimeout(timer);
24525
- origOnOpen?.call(ws, event);
24526
- resolve();
24527
- };
24528
- const origOnError = ws.onerror;
24529
- ws.onerror = (error) => {
24530
- clearTimeout(timer);
24531
- origOnError?.call(ws, error);
24532
- reject(error);
24533
- };
24534
- });
24535
- }
24536
24475
  _setupWebSocketHandlers() {
24537
24476
  if (!this._ws) return;
24538
- this._ws.onopen = () => {
24539
- this._wsLog("Opened");
24540
- };
24541
24477
  this._ws.onmessage = async (msg) => {
24542
24478
  let data;
24543
24479
  if (msg.data.arrayBuffer) {
@@ -24546,52 +24482,49 @@ var Client = class _Client {
24546
24482
  data = msg.data;
24547
24483
  }
24548
24484
  const decodedMsg = JSON.parse(data);
24549
- this._wsLog("Received:", decodedMsg.type, decodedMsg.content);
24550
24485
  const topic = getTopicFromMessage(decodedMsg);
24551
24486
  const callback = this._subscriptions.get(topic);
24552
24487
  if (callback) {
24553
24488
  callback(decodedMsg);
24554
- } else {
24555
- this._wsLog("No handler for topic:", topic);
24556
24489
  }
24557
24490
  };
24558
- this._ws.onclose = (event) => {
24559
- this._wsLog(
24560
- "Closed: code=" + event.code,
24561
- "reason=" + event.reason,
24562
- "clean=" + event.wasClean
24491
+ }
24492
+ static async initWebSocket(url, timeout = 5e3) {
24493
+ return new Promise((resolve, reject) => {
24494
+ const ws = new WebSocket(
24495
+ `${url.replace("http", "ws").replace("https", "wss")}` + "/v1/ws" /* Ws */
24563
24496
  );
24564
- this._ws = void 0;
24565
- this._subscriptions.clear();
24566
- this.onWsClose?.(event);
24567
- };
24568
- this._ws.onerror = (error) => {
24569
- this._wsLog("Error:", error);
24570
- };
24497
+ const timer = setTimeout(() => {
24498
+ reject(new Error("WebSocket connection timeout"));
24499
+ }, timeout);
24500
+ ws.onopen = () => {
24501
+ clearTimeout(timer);
24502
+ resolve(ws);
24503
+ };
24504
+ ws.onerror = (error) => {
24505
+ clearTimeout(timer);
24506
+ reject(error);
24507
+ };
24508
+ });
24571
24509
  }
24572
24510
  async disconnectWebSocket() {
24573
24511
  if (!this._ws) {
24574
24512
  console.warn("WebSocket is not connected");
24575
24513
  return;
24576
24514
  }
24577
- this._wsLog("Disconnecting, clearing", this._subscriptions.size, "subscriptions");
24578
24515
  this._subscriptions.clear();
24579
24516
  this._ws.close();
24580
24517
  this._ws = void 0;
24581
24518
  }
24582
24519
  // Method to check if WebSocket is connected
24583
24520
  isWebSocketConnected() {
24584
- const connected = this._ws !== void 0 && this._ws.readyState === WebSocket.OPEN;
24585
- this._wsLog("isWebSocketConnected:", connected);
24586
- return connected;
24521
+ return this._ws !== void 0 && this._ws.readyState === WebSocket.OPEN;
24587
24522
  }
24588
24523
  sendWsMessage(message) {
24589
24524
  if (!this._ws) throw new Error("WebSocket is not connected");
24590
24525
  return new Promise((resolve, reject) => {
24591
24526
  const topic = message.content.id;
24592
- this._wsLog("Sending:", message.type, "id=" + topic);
24593
24527
  const timer = setTimeout(() => {
24594
- this._wsLog("Timeout waiting for response:", message.type, "id=" + topic);
24595
24528
  reject(new Error(`Connection timed out after ${this.timeout} ms`));
24596
24529
  }, this.timeout);
24597
24530
  let handler = (response) => {
@@ -24599,13 +24532,11 @@ var Client = class _Client {
24599
24532
  this._subscriptions.delete(topic);
24600
24533
  if (response.type === "Error") {
24601
24534
  const errorMessage = response.content.message || "Unknown websocket error without message";
24602
- this._wsLog("Error response:", errorMessage, "id=" + topic);
24603
24535
  reject(
24604
24536
  new Error(`WebSocket error (id: ${response.content.id}): ${errorMessage}`)
24605
24537
  );
24606
24538
  return;
24607
24539
  }
24608
- this._wsLog("Ack received for:", message.type, "id=" + topic);
24609
24540
  resolve(response);
24610
24541
  };
24611
24542
  this._subscriptions.set(topic, handler);
package/dist/index.d.cts CHANGED
@@ -3682,7 +3682,6 @@ interface TokenConfigEntry {
3682
3682
  contractAddress: string;
3683
3683
  tokenDecimals: number;
3684
3684
  vaultId?: string;
3685
- createdAt?: string;
3686
3685
  }
3687
3686
  interface MarginStep {
3688
3687
  initialMarginRatio: string;
@@ -3710,7 +3709,6 @@ interface PerpMarketConfigEntry {
3710
3709
  fundingRate: FundingRate;
3711
3710
  basicMakerFee: string;
3712
3711
  basicTakerFee: string;
3713
- createdAt?: string;
3714
3712
  }
3715
3713
  interface SpotMarketConfigEntry {
3716
3714
  marketName: string;
@@ -3720,7 +3718,6 @@ interface SpotMarketConfigEntry {
3720
3718
  tickSize: string;
3721
3719
  basicMakerFee: string;
3722
3720
  basicTakerFee: string;
3723
- createdAt?: string;
3724
3721
  }
3725
3722
  interface FeeData {
3726
3723
  feeToVaultAccount: string;
@@ -3734,19 +3731,6 @@ interface ExchangeConfig {
3734
3731
  feeData: FeeData;
3735
3732
  systemHaircut: string;
3736
3733
  }
3737
- interface TvlTokenEntry {
3738
- tokenAddress: string;
3739
- amount: string;
3740
- valueUsd: string;
3741
- }
3742
- interface ExchangeStatsEntry {
3743
- timestampOpen: string;
3744
- timestampClose: string;
3745
- tvlBreakdown: TvlTokenEntry[];
3746
- perpVolumeUsd: string;
3747
- spotVolumeUsd: string;
3748
- openInterestUsd: string;
3749
- }
3750
3734
  interface FeeTier {
3751
3735
  volume: string;
3752
3736
  cashback: string;
@@ -3778,6 +3762,13 @@ interface GetAccountValueRankingResponse {
3778
3762
  usersRanking: AccountValueRankingEntry[];
3779
3763
  paginationCursor?: PaginationCursor;
3780
3764
  }
3765
+ interface GetUserAccountValueRankingRequest {
3766
+ userId?: string;
3767
+ userAddress?: string;
3768
+ }
3769
+ interface GetUserAccountValueRankingResponse {
3770
+ usersRanking: AccountValueRankingEntry[];
3771
+ }
3781
3772
  interface GetAllVaultsIdsResponse {
3782
3773
  vaultsIds: string[];
3783
3774
  }
@@ -3820,15 +3811,6 @@ interface GetChartCandlesInRangeResponse {
3820
3811
  chartCandles: ChartCandle[];
3821
3812
  paginationCursor?: PaginationCursor;
3822
3813
  }
3823
- interface GetExchangeStatsHistoryRequest {
3824
- olderTimestampMs?: string;
3825
- newerTimestampMs?: string;
3826
- paginationCursor?: PaginationCursor;
3827
- }
3828
- interface GetExchangeStatsHistoryResponse {
3829
- data: ExchangeStatsEntry[];
3830
- paginationCursor?: PaginationCursor;
3831
- }
3832
3814
  interface GetIndexPriceHistoryRequest {
3833
3815
  priceIndex: string;
3834
3816
  olderTimestampMs?: string;
@@ -4172,13 +4154,6 @@ interface PointsRankingEntry {
4172
4154
  interface GetTopPointsRankingResponse {
4173
4155
  usersRanking: PointsRankingEntry[];
4174
4156
  }
4175
- interface GetUserAccountValueRankingRequest {
4176
- userId?: string;
4177
- userAddress?: string;
4178
- }
4179
- interface GetUserAccountValueRankingResponse {
4180
- usersRanking: AccountValueRankingEntry[];
4181
- }
4182
4157
  interface GetUserAggregatedBoxRewardsStatsRequest {
4183
4158
  userId: string;
4184
4159
  }
@@ -5184,8 +5159,7 @@ declare enum EndpointsV1 {
5184
5159
  GetUserPersonalPointsRanking = "/v1/get_user_personal_points_ranking",
5185
5160
  GetIndexPrices = "/v1/get_index_prices",
5186
5161
  GetAccountValueRanking = "/v1/get_account_value_ranking",
5187
- GetUserAccountValueRanking = "/v1/get_user_account_value_ranking",
5188
- GetExchangeStatsHistory = "/v1/get_exchange_stats_history"
5162
+ GetUserAccountValueRanking = "/v1/get_user_account_value_ranking"
5189
5163
  }
5190
5164
  type Topic = {
5191
5165
  type: "PerpMarket";
@@ -5774,12 +5748,10 @@ declare class Client {
5774
5748
  _gasUnitPrice: number;
5775
5749
  _expirationTimestampDelay: number;
5776
5750
  timeout: number;
5777
- wsDebug: boolean;
5778
- onWsClose: ((event: CloseEvent) => void) | undefined;
5779
5751
  _abis: ReturnType<typeof getABIsForNetwork>;
5780
5752
  _contractAddress: string;
5781
- static init(connection: Aptos, enableWs?: boolean, url?: string, apiKey?: Account, chainId?: number, params?: TxParams, networkMode?: NetworkMode, wsDebug?: boolean, timeout?: number): Promise<Client>;
5782
- constructor(connection: Aptos, enableWs: boolean, url?: string, apiKey?: Account, chainId?: number, params?: TxParams, networkMode?: NetworkMode, wsDebug?: boolean, timeout?: number);
5753
+ static init(connection: Aptos, enableWs?: boolean, url?: string, apiKey?: Account, chainId?: number, params?: TxParams, networkMode?: NetworkMode): Promise<Client>;
5754
+ constructor(connection: Aptos, enableWs: boolean, url?: string, apiKey?: Account, chainId?: number, params?: TxParams, networkMode?: NetworkMode);
5783
5755
  /**
5784
5756
  * Create a new Client instance
5785
5757
  *
@@ -5808,17 +5780,15 @@ declare class Client {
5808
5780
  * myApiKeyAccount // custom API key
5809
5781
  * )
5810
5782
  */
5811
- static create(connection: Aptos, networkMode?: NetworkMode, enableWs?: boolean, url?: string, apiKey?: Account, wsDebug?: boolean, timeout?: number): Promise<Client>;
5783
+ static create(connection: Aptos, networkMode?: NetworkMode, enableWs?: boolean, url?: string, apiKey?: Account): Promise<Client>;
5812
5784
  setApiKey(apiKey: Account): Promise<void>;
5813
5785
  getContractAddress(): string;
5814
5786
  getApiKeySequenceNumber(): Promise<bigint | null>;
5815
5787
  fetchApiKeySequenceNumber(): Promise<number>;
5816
5788
  setTxParams(params: TxParams): void;
5817
- private _wsLog;
5818
- setWsDebugActive(active: boolean): void;
5819
5789
  connectWebSocket(): Promise<void>;
5820
- private _waitForOpen;
5821
5790
  private _setupWebSocketHandlers;
5791
+ static initWebSocket(url: string, timeout?: number): Promise<WebSocket>;
5822
5792
  disconnectWebSocket(): Promise<void>;
5823
5793
  isWebSocketConnected(): boolean;
5824
5794
  sendWsMessage(message: WsCommand): Promise<WsMessage>;
@@ -5977,4 +5947,4 @@ declare const generateApiKey: () => _aptos_labs_ts_sdk.Ed25519Account;
5977
5947
  declare const getTopicFromCommand: (data: WsCommand) => string;
5978
5948
  declare const getTopicFromMessage: (data: WsMessage) => string;
5979
5949
 
5980
- export { ABIs, type AccountValueRankingEntry, type AddApiCreditsParams, type AddApiKey, type AddApiKeyParams, type Address, AdminEndpoints, type ApiCreditsChange, type ApiStatus, type BalanceChange, BaseEndpoints, type Borrow, type BorrowLendUpdate, type BorrowLending, type BorrowLendingAggregatedData, type BorrowLendingHistoricalData, type BoxOpeningEvent, type BoxReward, BoxRewardTier, type CancelAllPerpOrdersParams, type CancelAllSpotOrdersParams, type CancelPerpOrdersParams, type CancelSpotOrdersParams, type CanceledPerpOrderData, type CanceledPerpOrders, type CanceledPerpTriggerOrderData, type CanceledPerpTriggerOrders, type CanceledSpotOrderData, type CanceledSpotOrders, type ChangePerpOrderParams, type ChangeSpotOrderParams, type ChartCandle, ChartInterval, type CheckReferralCodeRequest, type CheckReferralCodeResponse, type ClaimDepositParams, type ClaimKickbackFeeParams, type ClaimReferralFee, type ClaimReferralFeesParams, type ClaimUserKickbackFee, type ClaimedKickback, type ClaimedReferralKickback, Client, type Content, type CreateUserParams, type Deposit, type DepositToVaultParams, type DepositTokenParams, EndpointsV1, type ErrorResponse, type ExchangeConfig, ExchangeProxies, type ExchangeStatsEntry, type FeeData, type FeeTier, type Fees, type FundingCheckpoint, type FundingPayment, type FundingRate, GLOBAL_DENOMINATOR, type GetAccountValueRankingRequest, type GetAccountValueRankingResponse, type GetAllVaultsIdsResponse, type GetBorrowLendingAggregatedStatsRequest, type GetBorrowLendingAggregatedStatsResponse, type GetBorrowLendingDataResponse, type GetBorrowLendingHistoricalDataRequest, type GetBorrowLendingHistoricalDataResponse, type GetChartCandlesInRangeRequest, type GetChartCandlesInRangeResponse, type GetExchangeStatsHistoryRequest, type GetExchangeStatsHistoryResponse, type GetIndexPriceHistoryRequest, type GetIndexPriceHistoryResponse, type GetIndexPricesResponse, type GetIndexerStatusResponse, type GetOrderBookDataRequest, type GetOrderBookDataResponse, type GetPerpMarketsConfigResponse, type GetPerpMarketsDataRequest, type GetPerpMarketsDataResponse, type GetPerpRecentTradesRequest, type GetPerpRecentTradesResponse, type GetPerpUserFillsRequest, type GetPerpUserFillsResponse, type GetPerpUserOrdersRequest, type GetPerpUserOrdersResponse, type GetPerpUserTriggerOrdersRequest, type GetPerpUserTriggerOrdersResponse, type GetPriceIndexesResponse, type GetServicesStatusResponse, type GetSpotMarketsConfigResponse, type GetSpotMarketsDataRequest, type GetSpotMarketsDataResponse, type GetSpotRecentTradesRequest, type GetSpotRecentTradesResponse, type GetSpotUserFillsRequest, type GetSpotUserFillsResponse, type GetSpotUserOrdersRequest, type GetSpotUserOrdersResponse, type GetTokenAggregatedStatsRequest, type GetTokenAggregatedStatsResponse, type GetTokenStatsHistoryRequest, type GetTokenStatsHistoryResponse, type GetTokensConfigResponse, type GetTopPointsRankingResponse, type GetUserAccountValueRankingRequest, type GetUserAccountValueRankingResponse, type GetUserAggregatedBoxRewardsStatsRequest, type GetUserAggregatedBoxRewardsStatsResponse, type GetUserAggregatedReferralStatsRequest, type GetUserAggregatedReferralStatsResponse, type GetUserAggregatedStatsRequest, type GetUserAggregatedStatsResponse, type GetUserAggregatedVaultStatsRequest, type GetUserAggregatedVaultStatsResponse, type GetUserBoxRewardsStatsHistoryRequest, type GetUserBoxRewardsStatsHistoryResponse, type GetUserBoxesHistoryRequest, type GetUserBoxesHistoryResponse, type GetUserClaimedKickbackHistoryRequest, type GetUserClaimedKickbackHistoryResponse, type GetUserClaimedReferralKickbackHistoryRequest, type GetUserClaimedReferralKickbackHistoryResponse, type GetUserDataRequest, type GetUserDataResponse, type GetUserDepositsRequest, type GetUserDepositsResponse, type GetUserFullLiquidationsHistoryRequest, type GetUserFundingHistoryRequest, type GetUserFundingHistoryResponse, type GetUserLiquidationsCancelHistoryResponse, type GetUserLiquidationsCancelOrdersHistoryRequest, type GetUserLiquidationsHistoryResponse, type GetUserPartialLiquidationsHistoryRequest, type GetUserPartialLiquidationsHistoryResponse, type GetUserPersonalPointsRankingRequest, type GetUserPersonalPointsRankingResponse, type GetUserPointsHistoryRequest, type GetUserPointsHistoryResponse, type GetUserPortfolioValueRequest, type GetUserPortfolioValueResponse, type GetUserReferralStatsHistoryRequest, type GetUserReferralStatsHistoryResponse, type GetUserRewardsValueRequest, type GetUserRewardsValueResponse, type GetUserTradeStatsHistoryRequest, type GetUserTradeStatsHistoryResponse, type GetUserTransferHistoryRequest, type GetUserTransferHistoryResponse, type GetUserVaultDepositsRequest, type GetUserVaultDepositsResponse, type GetUserVaultWithdrawsRequest, type GetUserVaultWithdrawsResponse, type GetUserVolumeForReferralRequest, type GetUserVolumeForReferralResponse, type GetUserWithdrawalsRequest, type GetUserWithdrawalsResponse, type GetUsersByAddressRequest, type GetUsersByAddressResponse, type GetVaultDepositsRequest, type GetVaultDepositsResponse, type GetVaultHistoricalDataRequest, type GetVaultHistoricalDataResponse, type GetVaultWithdrawalsRequest, type GetVaultWithdrawalsResponse, type GlobalLiquidation, type GlobalPartialLiquidation, type HistoricBoxReward, type HistoricalBoxRewardsStats, type HistoricalDeposit, type HistoricalFullLiquidation, type HistoricalFunding, type HistoricalLiquidatedBorrow, type HistoricalLiquidatedCollateral, type HistoricalLiquidatedLend, type HistoricalLiquidatedPosition, type HistoricalLiquidationCancelOrders, type HistoricalPartialLiquidatedPosition, type HistoricalPartialLiquidation, type HistoricalPerpOrder, type HistoricalPoints, type HistoricalReferralStats, type HistoricalSpotOrder, type HistoricalTokenStats, type HistoricalTradeStats, type HistoricalUserTransfer, type HistoricalVaultDeposit, type HistoricalVaultWithdraw, type HistoricalWithdraw, type IndexPriceHistory, type IndexPriceLive, type Lend, type LendTokenParams, type Liquidation, type LiquidationCancelledOrderData, type LiquidationCancelledTriggerOrderData, MAINNET_CONFIG, type MarginStep, Network, type NetworkConfig, type NetworkMode, type NodeStatus, type OpenBoxesRequest, type OpenBoxesResponse, type OpenBoxesSignRequest, type OracleUpdate, type OracleUpdates, type OrderBookData, OrderSide, OrderStatus, OrderType, type PaginationCursor, type PartialLiquidation, type PerpFill, type PerpMarketConfigEntry, type PerpMarketData, type PerpOrder, type PerpOrderData, type PerpOrderDataForMarket, type PerpOrderFills, type PerpOrderbookState, type PerpOrderbookUpdate, type PerpPosition, type PerpTrade, type PerpTradesUpdate, type PerpTriggerOrder, type PerpTriggerOrderTriggered, type PlaceMultiplePerpOrdersParams, type PlaceMultipleSpotOrdersParams, type PlacePerpLimitOrder, type PlacePerpMarketOrder, type PlacePerpOrderParams, type PlacePerpTriggerOrder, type PlacePerpTriggerOrderParams, type PlaceSpotLimitOrder, type PlaceSpotMarketOrder, type PlaceSpotOrderParams, type PointsRankingEntry, type PriceIndex, type RedeemTokenParams, type Referral, type ReferralUpdate, type RemoveApiKey, type RemoveApiKeyParams, type RemoveApiKeySignerParams, type RepayBorrow, type ReplaceMultipleOrdersParams, type ReplaceMultipleSpotOrdersParams, type SetAlias, type SetAliasNameParams, type SetAutoLend, type SetAutolendParams, type SetReferralCodeParams, type SetReferralParamsRequest, type SetReferralParamsResponse, type SpotFill, type SpotMarketConfigEntry, type SpotMarketData, type SpotOrder, type SpotOrderData, type SpotOrderDataForMarket, type SpotOrderFills, type SpotOrderbookState, type SpotOrderbookUpdate, type SpotTrade, type SpotTradesUpdate, Status, type StatusResponse, type SubServiceStatus, type SubmitSponsoredTransactionRequest, type SubmitSponsoredTransactionResponse, TESTNET_CONFIG, TestFaucet, type TimeResponse, type TokenAggregatedStats, type TokenConfigEntry, type TokenizeUserVaultInvestmentParams, type Topic, type Trade, TradeRole, TransferAction, type TransferToUserParams, type TriggerOrder, type TvlTokenEntry, type TxParams, type UpdateUserFeeTier, type User, type UserAggregatedBoxRewardsStats, type UserAggregatedReferralStats, type UserAggregatedStats, type UserAggregatedVaultStats, type UserBoxOpeningEvent, type UserPointsBreakdown, type UserPortfolioValue, type UserRewardsValue, UserStatus, type UserTransfer, type UtilizationCurve, type Vault, type VaultDeposit, type VaultHistoricalData, type VaultInvestment, type VaultWithdraw, type Withdraw, type WithdrawFromVaultParams, type WithdrawLend, type WithdrawTokenParams, type WsBorrowLendUpdate, type WsBoxOpeningUpdate, type WsCommand, type WsFill, type WsLiquidatedBorrow, type WsLiquidatedCollateral, type WsLiquidatedLend, type WsLiquidatedPosition, type WsLiquidationUpdate, type WsMessage, type WsOracleUpdates, type WsPartialLiquidatedPosition, type WsPerpMarketUpdates, type WsSpotMarketUpdates, type WsUserUpdates, createAptosClient, createAptosClientFromEnv, generateApiKey, getABIsForNetwork, getNetworkConfig, getNetworkModeFromEnv, getRandomId, getTopicFromCommand, getTopicFromMessage, nowInMiliseconds, parseEntryFunctionAbi, sleep, toSystemValue };
5950
+ export { ABIs, type AccountValueRankingEntry, type AddApiCreditsParams, type AddApiKey, type AddApiKeyParams, type Address, AdminEndpoints, type ApiCreditsChange, type ApiStatus, type BalanceChange, BaseEndpoints, type Borrow, type BorrowLendUpdate, type BorrowLending, type BorrowLendingAggregatedData, type BorrowLendingHistoricalData, type BoxOpeningEvent, type BoxReward, BoxRewardTier, type CancelAllPerpOrdersParams, type CancelAllSpotOrdersParams, type CancelPerpOrdersParams, type CancelSpotOrdersParams, type CanceledPerpOrderData, type CanceledPerpOrders, type CanceledPerpTriggerOrderData, type CanceledPerpTriggerOrders, type CanceledSpotOrderData, type CanceledSpotOrders, type ChangePerpOrderParams, type ChangeSpotOrderParams, type ChartCandle, ChartInterval, type CheckReferralCodeRequest, type CheckReferralCodeResponse, type ClaimDepositParams, type ClaimKickbackFeeParams, type ClaimReferralFee, type ClaimReferralFeesParams, type ClaimUserKickbackFee, type ClaimedKickback, type ClaimedReferralKickback, Client, type Content, type CreateUserParams, type Deposit, type DepositToVaultParams, type DepositTokenParams, EndpointsV1, type ErrorResponse, type ExchangeConfig, ExchangeProxies, type FeeData, type FeeTier, type Fees, type FundingCheckpoint, type FundingPayment, type FundingRate, GLOBAL_DENOMINATOR, type GetAccountValueRankingRequest, type GetAccountValueRankingResponse, type GetAllVaultsIdsResponse, type GetBorrowLendingAggregatedStatsRequest, type GetBorrowLendingAggregatedStatsResponse, type GetBorrowLendingDataResponse, type GetBorrowLendingHistoricalDataRequest, type GetBorrowLendingHistoricalDataResponse, type GetChartCandlesInRangeRequest, type GetChartCandlesInRangeResponse, type GetIndexPriceHistoryRequest, type GetIndexPriceHistoryResponse, type GetIndexPricesResponse, type GetIndexerStatusResponse, type GetOrderBookDataRequest, type GetOrderBookDataResponse, type GetPerpMarketsConfigResponse, type GetPerpMarketsDataRequest, type GetPerpMarketsDataResponse, type GetPerpRecentTradesRequest, type GetPerpRecentTradesResponse, type GetPerpUserFillsRequest, type GetPerpUserFillsResponse, type GetPerpUserOrdersRequest, type GetPerpUserOrdersResponse, type GetPerpUserTriggerOrdersRequest, type GetPerpUserTriggerOrdersResponse, type GetPriceIndexesResponse, type GetServicesStatusResponse, type GetSpotMarketsConfigResponse, type GetSpotMarketsDataRequest, type GetSpotMarketsDataResponse, type GetSpotRecentTradesRequest, type GetSpotRecentTradesResponse, type GetSpotUserFillsRequest, type GetSpotUserFillsResponse, type GetSpotUserOrdersRequest, type GetSpotUserOrdersResponse, type GetTokenAggregatedStatsRequest, type GetTokenAggregatedStatsResponse, type GetTokenStatsHistoryRequest, type GetTokenStatsHistoryResponse, type GetTokensConfigResponse, type GetTopPointsRankingResponse, type GetUserAccountValueRankingRequest, type GetUserAccountValueRankingResponse, type GetUserAggregatedBoxRewardsStatsRequest, type GetUserAggregatedBoxRewardsStatsResponse, type GetUserAggregatedReferralStatsRequest, type GetUserAggregatedReferralStatsResponse, type GetUserAggregatedStatsRequest, type GetUserAggregatedStatsResponse, type GetUserAggregatedVaultStatsRequest, type GetUserAggregatedVaultStatsResponse, type GetUserBoxRewardsStatsHistoryRequest, type GetUserBoxRewardsStatsHistoryResponse, type GetUserBoxesHistoryRequest, type GetUserBoxesHistoryResponse, type GetUserClaimedKickbackHistoryRequest, type GetUserClaimedKickbackHistoryResponse, type GetUserClaimedReferralKickbackHistoryRequest, type GetUserClaimedReferralKickbackHistoryResponse, type GetUserDataRequest, type GetUserDataResponse, type GetUserDepositsRequest, type GetUserDepositsResponse, type GetUserFullLiquidationsHistoryRequest, type GetUserFundingHistoryRequest, type GetUserFundingHistoryResponse, type GetUserLiquidationsCancelHistoryResponse, type GetUserLiquidationsCancelOrdersHistoryRequest, type GetUserLiquidationsHistoryResponse, type GetUserPartialLiquidationsHistoryRequest, type GetUserPartialLiquidationsHistoryResponse, type GetUserPersonalPointsRankingRequest, type GetUserPersonalPointsRankingResponse, type GetUserPointsHistoryRequest, type GetUserPointsHistoryResponse, type GetUserPortfolioValueRequest, type GetUserPortfolioValueResponse, type GetUserReferralStatsHistoryRequest, type GetUserReferralStatsHistoryResponse, type GetUserRewardsValueRequest, type GetUserRewardsValueResponse, type GetUserTradeStatsHistoryRequest, type GetUserTradeStatsHistoryResponse, type GetUserTransferHistoryRequest, type GetUserTransferHistoryResponse, type GetUserVaultDepositsRequest, type GetUserVaultDepositsResponse, type GetUserVaultWithdrawsRequest, type GetUserVaultWithdrawsResponse, type GetUserVolumeForReferralRequest, type GetUserVolumeForReferralResponse, type GetUserWithdrawalsRequest, type GetUserWithdrawalsResponse, type GetUsersByAddressRequest, type GetUsersByAddressResponse, type GetVaultDepositsRequest, type GetVaultDepositsResponse, type GetVaultHistoricalDataRequest, type GetVaultHistoricalDataResponse, type GetVaultWithdrawalsRequest, type GetVaultWithdrawalsResponse, type GlobalLiquidation, type GlobalPartialLiquidation, type HistoricBoxReward, type HistoricalBoxRewardsStats, type HistoricalDeposit, type HistoricalFullLiquidation, type HistoricalFunding, type HistoricalLiquidatedBorrow, type HistoricalLiquidatedCollateral, type HistoricalLiquidatedLend, type HistoricalLiquidatedPosition, type HistoricalLiquidationCancelOrders, type HistoricalPartialLiquidatedPosition, type HistoricalPartialLiquidation, type HistoricalPerpOrder, type HistoricalPoints, type HistoricalReferralStats, type HistoricalSpotOrder, type HistoricalTokenStats, type HistoricalTradeStats, type HistoricalUserTransfer, type HistoricalVaultDeposit, type HistoricalVaultWithdraw, type HistoricalWithdraw, type IndexPriceHistory, type IndexPriceLive, type Lend, type LendTokenParams, type Liquidation, type LiquidationCancelledOrderData, type LiquidationCancelledTriggerOrderData, MAINNET_CONFIG, type MarginStep, Network, type NetworkConfig, type NetworkMode, type NodeStatus, type OpenBoxesRequest, type OpenBoxesResponse, type OpenBoxesSignRequest, type OracleUpdate, type OracleUpdates, type OrderBookData, OrderSide, OrderStatus, OrderType, type PaginationCursor, type PartialLiquidation, type PerpFill, type PerpMarketConfigEntry, type PerpMarketData, type PerpOrder, type PerpOrderData, type PerpOrderDataForMarket, type PerpOrderFills, type PerpOrderbookState, type PerpOrderbookUpdate, type PerpPosition, type PerpTrade, type PerpTradesUpdate, type PerpTriggerOrder, type PerpTriggerOrderTriggered, type PlaceMultiplePerpOrdersParams, type PlaceMultipleSpotOrdersParams, type PlacePerpLimitOrder, type PlacePerpMarketOrder, type PlacePerpOrderParams, type PlacePerpTriggerOrder, type PlacePerpTriggerOrderParams, type PlaceSpotLimitOrder, type PlaceSpotMarketOrder, type PlaceSpotOrderParams, type PointsRankingEntry, type PriceIndex, type RedeemTokenParams, type Referral, type ReferralUpdate, type RemoveApiKey, type RemoveApiKeyParams, type RemoveApiKeySignerParams, type RepayBorrow, type ReplaceMultipleOrdersParams, type ReplaceMultipleSpotOrdersParams, type SetAlias, type SetAliasNameParams, type SetAutoLend, type SetAutolendParams, type SetReferralCodeParams, type SetReferralParamsRequest, type SetReferralParamsResponse, type SpotFill, type SpotMarketConfigEntry, type SpotMarketData, type SpotOrder, type SpotOrderData, type SpotOrderDataForMarket, type SpotOrderFills, type SpotOrderbookState, type SpotOrderbookUpdate, type SpotTrade, type SpotTradesUpdate, Status, type StatusResponse, type SubServiceStatus, type SubmitSponsoredTransactionRequest, type SubmitSponsoredTransactionResponse, TESTNET_CONFIG, TestFaucet, type TimeResponse, type TokenAggregatedStats, type TokenConfigEntry, type TokenizeUserVaultInvestmentParams, type Topic, type Trade, TradeRole, TransferAction, type TransferToUserParams, type TriggerOrder, type TxParams, type UpdateUserFeeTier, type User, type UserAggregatedBoxRewardsStats, type UserAggregatedReferralStats, type UserAggregatedStats, type UserAggregatedVaultStats, type UserBoxOpeningEvent, type UserPointsBreakdown, type UserPortfolioValue, type UserRewardsValue, UserStatus, type UserTransfer, type UtilizationCurve, type Vault, type VaultDeposit, type VaultHistoricalData, type VaultInvestment, type VaultWithdraw, type Withdraw, type WithdrawFromVaultParams, type WithdrawLend, type WithdrawTokenParams, type WsBorrowLendUpdate, type WsBoxOpeningUpdate, type WsCommand, type WsFill, type WsLiquidatedBorrow, type WsLiquidatedCollateral, type WsLiquidatedLend, type WsLiquidatedPosition, type WsLiquidationUpdate, type WsMessage, type WsOracleUpdates, type WsPartialLiquidatedPosition, type WsPerpMarketUpdates, type WsSpotMarketUpdates, type WsUserUpdates, createAptosClient, createAptosClientFromEnv, generateApiKey, getABIsForNetwork, getNetworkConfig, getNetworkModeFromEnv, getRandomId, getTopicFromCommand, getTopicFromMessage, nowInMiliseconds, parseEntryFunctionAbi, sleep, toSystemValue };
package/dist/index.d.ts CHANGED
@@ -3682,7 +3682,6 @@ interface TokenConfigEntry {
3682
3682
  contractAddress: string;
3683
3683
  tokenDecimals: number;
3684
3684
  vaultId?: string;
3685
- createdAt?: string;
3686
3685
  }
3687
3686
  interface MarginStep {
3688
3687
  initialMarginRatio: string;
@@ -3710,7 +3709,6 @@ interface PerpMarketConfigEntry {
3710
3709
  fundingRate: FundingRate;
3711
3710
  basicMakerFee: string;
3712
3711
  basicTakerFee: string;
3713
- createdAt?: string;
3714
3712
  }
3715
3713
  interface SpotMarketConfigEntry {
3716
3714
  marketName: string;
@@ -3720,7 +3718,6 @@ interface SpotMarketConfigEntry {
3720
3718
  tickSize: string;
3721
3719
  basicMakerFee: string;
3722
3720
  basicTakerFee: string;
3723
- createdAt?: string;
3724
3721
  }
3725
3722
  interface FeeData {
3726
3723
  feeToVaultAccount: string;
@@ -3734,19 +3731,6 @@ interface ExchangeConfig {
3734
3731
  feeData: FeeData;
3735
3732
  systemHaircut: string;
3736
3733
  }
3737
- interface TvlTokenEntry {
3738
- tokenAddress: string;
3739
- amount: string;
3740
- valueUsd: string;
3741
- }
3742
- interface ExchangeStatsEntry {
3743
- timestampOpen: string;
3744
- timestampClose: string;
3745
- tvlBreakdown: TvlTokenEntry[];
3746
- perpVolumeUsd: string;
3747
- spotVolumeUsd: string;
3748
- openInterestUsd: string;
3749
- }
3750
3734
  interface FeeTier {
3751
3735
  volume: string;
3752
3736
  cashback: string;
@@ -3778,6 +3762,13 @@ interface GetAccountValueRankingResponse {
3778
3762
  usersRanking: AccountValueRankingEntry[];
3779
3763
  paginationCursor?: PaginationCursor;
3780
3764
  }
3765
+ interface GetUserAccountValueRankingRequest {
3766
+ userId?: string;
3767
+ userAddress?: string;
3768
+ }
3769
+ interface GetUserAccountValueRankingResponse {
3770
+ usersRanking: AccountValueRankingEntry[];
3771
+ }
3781
3772
  interface GetAllVaultsIdsResponse {
3782
3773
  vaultsIds: string[];
3783
3774
  }
@@ -3820,15 +3811,6 @@ interface GetChartCandlesInRangeResponse {
3820
3811
  chartCandles: ChartCandle[];
3821
3812
  paginationCursor?: PaginationCursor;
3822
3813
  }
3823
- interface GetExchangeStatsHistoryRequest {
3824
- olderTimestampMs?: string;
3825
- newerTimestampMs?: string;
3826
- paginationCursor?: PaginationCursor;
3827
- }
3828
- interface GetExchangeStatsHistoryResponse {
3829
- data: ExchangeStatsEntry[];
3830
- paginationCursor?: PaginationCursor;
3831
- }
3832
3814
  interface GetIndexPriceHistoryRequest {
3833
3815
  priceIndex: string;
3834
3816
  olderTimestampMs?: string;
@@ -4172,13 +4154,6 @@ interface PointsRankingEntry {
4172
4154
  interface GetTopPointsRankingResponse {
4173
4155
  usersRanking: PointsRankingEntry[];
4174
4156
  }
4175
- interface GetUserAccountValueRankingRequest {
4176
- userId?: string;
4177
- userAddress?: string;
4178
- }
4179
- interface GetUserAccountValueRankingResponse {
4180
- usersRanking: AccountValueRankingEntry[];
4181
- }
4182
4157
  interface GetUserAggregatedBoxRewardsStatsRequest {
4183
4158
  userId: string;
4184
4159
  }
@@ -5184,8 +5159,7 @@ declare enum EndpointsV1 {
5184
5159
  GetUserPersonalPointsRanking = "/v1/get_user_personal_points_ranking",
5185
5160
  GetIndexPrices = "/v1/get_index_prices",
5186
5161
  GetAccountValueRanking = "/v1/get_account_value_ranking",
5187
- GetUserAccountValueRanking = "/v1/get_user_account_value_ranking",
5188
- GetExchangeStatsHistory = "/v1/get_exchange_stats_history"
5162
+ GetUserAccountValueRanking = "/v1/get_user_account_value_ranking"
5189
5163
  }
5190
5164
  type Topic = {
5191
5165
  type: "PerpMarket";
@@ -5774,12 +5748,10 @@ declare class Client {
5774
5748
  _gasUnitPrice: number;
5775
5749
  _expirationTimestampDelay: number;
5776
5750
  timeout: number;
5777
- wsDebug: boolean;
5778
- onWsClose: ((event: CloseEvent) => void) | undefined;
5779
5751
  _abis: ReturnType<typeof getABIsForNetwork>;
5780
5752
  _contractAddress: string;
5781
- static init(connection: Aptos, enableWs?: boolean, url?: string, apiKey?: Account, chainId?: number, params?: TxParams, networkMode?: NetworkMode, wsDebug?: boolean, timeout?: number): Promise<Client>;
5782
- constructor(connection: Aptos, enableWs: boolean, url?: string, apiKey?: Account, chainId?: number, params?: TxParams, networkMode?: NetworkMode, wsDebug?: boolean, timeout?: number);
5753
+ static init(connection: Aptos, enableWs?: boolean, url?: string, apiKey?: Account, chainId?: number, params?: TxParams, networkMode?: NetworkMode): Promise<Client>;
5754
+ constructor(connection: Aptos, enableWs: boolean, url?: string, apiKey?: Account, chainId?: number, params?: TxParams, networkMode?: NetworkMode);
5783
5755
  /**
5784
5756
  * Create a new Client instance
5785
5757
  *
@@ -5808,17 +5780,15 @@ declare class Client {
5808
5780
  * myApiKeyAccount // custom API key
5809
5781
  * )
5810
5782
  */
5811
- static create(connection: Aptos, networkMode?: NetworkMode, enableWs?: boolean, url?: string, apiKey?: Account, wsDebug?: boolean, timeout?: number): Promise<Client>;
5783
+ static create(connection: Aptos, networkMode?: NetworkMode, enableWs?: boolean, url?: string, apiKey?: Account): Promise<Client>;
5812
5784
  setApiKey(apiKey: Account): Promise<void>;
5813
5785
  getContractAddress(): string;
5814
5786
  getApiKeySequenceNumber(): Promise<bigint | null>;
5815
5787
  fetchApiKeySequenceNumber(): Promise<number>;
5816
5788
  setTxParams(params: TxParams): void;
5817
- private _wsLog;
5818
- setWsDebugActive(active: boolean): void;
5819
5789
  connectWebSocket(): Promise<void>;
5820
- private _waitForOpen;
5821
5790
  private _setupWebSocketHandlers;
5791
+ static initWebSocket(url: string, timeout?: number): Promise<WebSocket>;
5822
5792
  disconnectWebSocket(): Promise<void>;
5823
5793
  isWebSocketConnected(): boolean;
5824
5794
  sendWsMessage(message: WsCommand): Promise<WsMessage>;
@@ -5977,4 +5947,4 @@ declare const generateApiKey: () => _aptos_labs_ts_sdk.Ed25519Account;
5977
5947
  declare const getTopicFromCommand: (data: WsCommand) => string;
5978
5948
  declare const getTopicFromMessage: (data: WsMessage) => string;
5979
5949
 
5980
- export { ABIs, type AccountValueRankingEntry, type AddApiCreditsParams, type AddApiKey, type AddApiKeyParams, type Address, AdminEndpoints, type ApiCreditsChange, type ApiStatus, type BalanceChange, BaseEndpoints, type Borrow, type BorrowLendUpdate, type BorrowLending, type BorrowLendingAggregatedData, type BorrowLendingHistoricalData, type BoxOpeningEvent, type BoxReward, BoxRewardTier, type CancelAllPerpOrdersParams, type CancelAllSpotOrdersParams, type CancelPerpOrdersParams, type CancelSpotOrdersParams, type CanceledPerpOrderData, type CanceledPerpOrders, type CanceledPerpTriggerOrderData, type CanceledPerpTriggerOrders, type CanceledSpotOrderData, type CanceledSpotOrders, type ChangePerpOrderParams, type ChangeSpotOrderParams, type ChartCandle, ChartInterval, type CheckReferralCodeRequest, type CheckReferralCodeResponse, type ClaimDepositParams, type ClaimKickbackFeeParams, type ClaimReferralFee, type ClaimReferralFeesParams, type ClaimUserKickbackFee, type ClaimedKickback, type ClaimedReferralKickback, Client, type Content, type CreateUserParams, type Deposit, type DepositToVaultParams, type DepositTokenParams, EndpointsV1, type ErrorResponse, type ExchangeConfig, ExchangeProxies, type ExchangeStatsEntry, type FeeData, type FeeTier, type Fees, type FundingCheckpoint, type FundingPayment, type FundingRate, GLOBAL_DENOMINATOR, type GetAccountValueRankingRequest, type GetAccountValueRankingResponse, type GetAllVaultsIdsResponse, type GetBorrowLendingAggregatedStatsRequest, type GetBorrowLendingAggregatedStatsResponse, type GetBorrowLendingDataResponse, type GetBorrowLendingHistoricalDataRequest, type GetBorrowLendingHistoricalDataResponse, type GetChartCandlesInRangeRequest, type GetChartCandlesInRangeResponse, type GetExchangeStatsHistoryRequest, type GetExchangeStatsHistoryResponse, type GetIndexPriceHistoryRequest, type GetIndexPriceHistoryResponse, type GetIndexPricesResponse, type GetIndexerStatusResponse, type GetOrderBookDataRequest, type GetOrderBookDataResponse, type GetPerpMarketsConfigResponse, type GetPerpMarketsDataRequest, type GetPerpMarketsDataResponse, type GetPerpRecentTradesRequest, type GetPerpRecentTradesResponse, type GetPerpUserFillsRequest, type GetPerpUserFillsResponse, type GetPerpUserOrdersRequest, type GetPerpUserOrdersResponse, type GetPerpUserTriggerOrdersRequest, type GetPerpUserTriggerOrdersResponse, type GetPriceIndexesResponse, type GetServicesStatusResponse, type GetSpotMarketsConfigResponse, type GetSpotMarketsDataRequest, type GetSpotMarketsDataResponse, type GetSpotRecentTradesRequest, type GetSpotRecentTradesResponse, type GetSpotUserFillsRequest, type GetSpotUserFillsResponse, type GetSpotUserOrdersRequest, type GetSpotUserOrdersResponse, type GetTokenAggregatedStatsRequest, type GetTokenAggregatedStatsResponse, type GetTokenStatsHistoryRequest, type GetTokenStatsHistoryResponse, type GetTokensConfigResponse, type GetTopPointsRankingResponse, type GetUserAccountValueRankingRequest, type GetUserAccountValueRankingResponse, type GetUserAggregatedBoxRewardsStatsRequest, type GetUserAggregatedBoxRewardsStatsResponse, type GetUserAggregatedReferralStatsRequest, type GetUserAggregatedReferralStatsResponse, type GetUserAggregatedStatsRequest, type GetUserAggregatedStatsResponse, type GetUserAggregatedVaultStatsRequest, type GetUserAggregatedVaultStatsResponse, type GetUserBoxRewardsStatsHistoryRequest, type GetUserBoxRewardsStatsHistoryResponse, type GetUserBoxesHistoryRequest, type GetUserBoxesHistoryResponse, type GetUserClaimedKickbackHistoryRequest, type GetUserClaimedKickbackHistoryResponse, type GetUserClaimedReferralKickbackHistoryRequest, type GetUserClaimedReferralKickbackHistoryResponse, type GetUserDataRequest, type GetUserDataResponse, type GetUserDepositsRequest, type GetUserDepositsResponse, type GetUserFullLiquidationsHistoryRequest, type GetUserFundingHistoryRequest, type GetUserFundingHistoryResponse, type GetUserLiquidationsCancelHistoryResponse, type GetUserLiquidationsCancelOrdersHistoryRequest, type GetUserLiquidationsHistoryResponse, type GetUserPartialLiquidationsHistoryRequest, type GetUserPartialLiquidationsHistoryResponse, type GetUserPersonalPointsRankingRequest, type GetUserPersonalPointsRankingResponse, type GetUserPointsHistoryRequest, type GetUserPointsHistoryResponse, type GetUserPortfolioValueRequest, type GetUserPortfolioValueResponse, type GetUserReferralStatsHistoryRequest, type GetUserReferralStatsHistoryResponse, type GetUserRewardsValueRequest, type GetUserRewardsValueResponse, type GetUserTradeStatsHistoryRequest, type GetUserTradeStatsHistoryResponse, type GetUserTransferHistoryRequest, type GetUserTransferHistoryResponse, type GetUserVaultDepositsRequest, type GetUserVaultDepositsResponse, type GetUserVaultWithdrawsRequest, type GetUserVaultWithdrawsResponse, type GetUserVolumeForReferralRequest, type GetUserVolumeForReferralResponse, type GetUserWithdrawalsRequest, type GetUserWithdrawalsResponse, type GetUsersByAddressRequest, type GetUsersByAddressResponse, type GetVaultDepositsRequest, type GetVaultDepositsResponse, type GetVaultHistoricalDataRequest, type GetVaultHistoricalDataResponse, type GetVaultWithdrawalsRequest, type GetVaultWithdrawalsResponse, type GlobalLiquidation, type GlobalPartialLiquidation, type HistoricBoxReward, type HistoricalBoxRewardsStats, type HistoricalDeposit, type HistoricalFullLiquidation, type HistoricalFunding, type HistoricalLiquidatedBorrow, type HistoricalLiquidatedCollateral, type HistoricalLiquidatedLend, type HistoricalLiquidatedPosition, type HistoricalLiquidationCancelOrders, type HistoricalPartialLiquidatedPosition, type HistoricalPartialLiquidation, type HistoricalPerpOrder, type HistoricalPoints, type HistoricalReferralStats, type HistoricalSpotOrder, type HistoricalTokenStats, type HistoricalTradeStats, type HistoricalUserTransfer, type HistoricalVaultDeposit, type HistoricalVaultWithdraw, type HistoricalWithdraw, type IndexPriceHistory, type IndexPriceLive, type Lend, type LendTokenParams, type Liquidation, type LiquidationCancelledOrderData, type LiquidationCancelledTriggerOrderData, MAINNET_CONFIG, type MarginStep, Network, type NetworkConfig, type NetworkMode, type NodeStatus, type OpenBoxesRequest, type OpenBoxesResponse, type OpenBoxesSignRequest, type OracleUpdate, type OracleUpdates, type OrderBookData, OrderSide, OrderStatus, OrderType, type PaginationCursor, type PartialLiquidation, type PerpFill, type PerpMarketConfigEntry, type PerpMarketData, type PerpOrder, type PerpOrderData, type PerpOrderDataForMarket, type PerpOrderFills, type PerpOrderbookState, type PerpOrderbookUpdate, type PerpPosition, type PerpTrade, type PerpTradesUpdate, type PerpTriggerOrder, type PerpTriggerOrderTriggered, type PlaceMultiplePerpOrdersParams, type PlaceMultipleSpotOrdersParams, type PlacePerpLimitOrder, type PlacePerpMarketOrder, type PlacePerpOrderParams, type PlacePerpTriggerOrder, type PlacePerpTriggerOrderParams, type PlaceSpotLimitOrder, type PlaceSpotMarketOrder, type PlaceSpotOrderParams, type PointsRankingEntry, type PriceIndex, type RedeemTokenParams, type Referral, type ReferralUpdate, type RemoveApiKey, type RemoveApiKeyParams, type RemoveApiKeySignerParams, type RepayBorrow, type ReplaceMultipleOrdersParams, type ReplaceMultipleSpotOrdersParams, type SetAlias, type SetAliasNameParams, type SetAutoLend, type SetAutolendParams, type SetReferralCodeParams, type SetReferralParamsRequest, type SetReferralParamsResponse, type SpotFill, type SpotMarketConfigEntry, type SpotMarketData, type SpotOrder, type SpotOrderData, type SpotOrderDataForMarket, type SpotOrderFills, type SpotOrderbookState, type SpotOrderbookUpdate, type SpotTrade, type SpotTradesUpdate, Status, type StatusResponse, type SubServiceStatus, type SubmitSponsoredTransactionRequest, type SubmitSponsoredTransactionResponse, TESTNET_CONFIG, TestFaucet, type TimeResponse, type TokenAggregatedStats, type TokenConfigEntry, type TokenizeUserVaultInvestmentParams, type Topic, type Trade, TradeRole, TransferAction, type TransferToUserParams, type TriggerOrder, type TvlTokenEntry, type TxParams, type UpdateUserFeeTier, type User, type UserAggregatedBoxRewardsStats, type UserAggregatedReferralStats, type UserAggregatedStats, type UserAggregatedVaultStats, type UserBoxOpeningEvent, type UserPointsBreakdown, type UserPortfolioValue, type UserRewardsValue, UserStatus, type UserTransfer, type UtilizationCurve, type Vault, type VaultDeposit, type VaultHistoricalData, type VaultInvestment, type VaultWithdraw, type Withdraw, type WithdrawFromVaultParams, type WithdrawLend, type WithdrawTokenParams, type WsBorrowLendUpdate, type WsBoxOpeningUpdate, type WsCommand, type WsFill, type WsLiquidatedBorrow, type WsLiquidatedCollateral, type WsLiquidatedLend, type WsLiquidatedPosition, type WsLiquidationUpdate, type WsMessage, type WsOracleUpdates, type WsPartialLiquidatedPosition, type WsPerpMarketUpdates, type WsSpotMarketUpdates, type WsUserUpdates, createAptosClient, createAptosClientFromEnv, generateApiKey, getABIsForNetwork, getNetworkConfig, getNetworkModeFromEnv, getRandomId, getTopicFromCommand, getTopicFromMessage, nowInMiliseconds, parseEntryFunctionAbi, sleep, toSystemValue };
5950
+ export { ABIs, type AccountValueRankingEntry, type AddApiCreditsParams, type AddApiKey, type AddApiKeyParams, type Address, AdminEndpoints, type ApiCreditsChange, type ApiStatus, type BalanceChange, BaseEndpoints, type Borrow, type BorrowLendUpdate, type BorrowLending, type BorrowLendingAggregatedData, type BorrowLendingHistoricalData, type BoxOpeningEvent, type BoxReward, BoxRewardTier, type CancelAllPerpOrdersParams, type CancelAllSpotOrdersParams, type CancelPerpOrdersParams, type CancelSpotOrdersParams, type CanceledPerpOrderData, type CanceledPerpOrders, type CanceledPerpTriggerOrderData, type CanceledPerpTriggerOrders, type CanceledSpotOrderData, type CanceledSpotOrders, type ChangePerpOrderParams, type ChangeSpotOrderParams, type ChartCandle, ChartInterval, type CheckReferralCodeRequest, type CheckReferralCodeResponse, type ClaimDepositParams, type ClaimKickbackFeeParams, type ClaimReferralFee, type ClaimReferralFeesParams, type ClaimUserKickbackFee, type ClaimedKickback, type ClaimedReferralKickback, Client, type Content, type CreateUserParams, type Deposit, type DepositToVaultParams, type DepositTokenParams, EndpointsV1, type ErrorResponse, type ExchangeConfig, ExchangeProxies, type FeeData, type FeeTier, type Fees, type FundingCheckpoint, type FundingPayment, type FundingRate, GLOBAL_DENOMINATOR, type GetAccountValueRankingRequest, type GetAccountValueRankingResponse, type GetAllVaultsIdsResponse, type GetBorrowLendingAggregatedStatsRequest, type GetBorrowLendingAggregatedStatsResponse, type GetBorrowLendingDataResponse, type GetBorrowLendingHistoricalDataRequest, type GetBorrowLendingHistoricalDataResponse, type GetChartCandlesInRangeRequest, type GetChartCandlesInRangeResponse, type GetIndexPriceHistoryRequest, type GetIndexPriceHistoryResponse, type GetIndexPricesResponse, type GetIndexerStatusResponse, type GetOrderBookDataRequest, type GetOrderBookDataResponse, type GetPerpMarketsConfigResponse, type GetPerpMarketsDataRequest, type GetPerpMarketsDataResponse, type GetPerpRecentTradesRequest, type GetPerpRecentTradesResponse, type GetPerpUserFillsRequest, type GetPerpUserFillsResponse, type GetPerpUserOrdersRequest, type GetPerpUserOrdersResponse, type GetPerpUserTriggerOrdersRequest, type GetPerpUserTriggerOrdersResponse, type GetPriceIndexesResponse, type GetServicesStatusResponse, type GetSpotMarketsConfigResponse, type GetSpotMarketsDataRequest, type GetSpotMarketsDataResponse, type GetSpotRecentTradesRequest, type GetSpotRecentTradesResponse, type GetSpotUserFillsRequest, type GetSpotUserFillsResponse, type GetSpotUserOrdersRequest, type GetSpotUserOrdersResponse, type GetTokenAggregatedStatsRequest, type GetTokenAggregatedStatsResponse, type GetTokenStatsHistoryRequest, type GetTokenStatsHistoryResponse, type GetTokensConfigResponse, type GetTopPointsRankingResponse, type GetUserAccountValueRankingRequest, type GetUserAccountValueRankingResponse, type GetUserAggregatedBoxRewardsStatsRequest, type GetUserAggregatedBoxRewardsStatsResponse, type GetUserAggregatedReferralStatsRequest, type GetUserAggregatedReferralStatsResponse, type GetUserAggregatedStatsRequest, type GetUserAggregatedStatsResponse, type GetUserAggregatedVaultStatsRequest, type GetUserAggregatedVaultStatsResponse, type GetUserBoxRewardsStatsHistoryRequest, type GetUserBoxRewardsStatsHistoryResponse, type GetUserBoxesHistoryRequest, type GetUserBoxesHistoryResponse, type GetUserClaimedKickbackHistoryRequest, type GetUserClaimedKickbackHistoryResponse, type GetUserClaimedReferralKickbackHistoryRequest, type GetUserClaimedReferralKickbackHistoryResponse, type GetUserDataRequest, type GetUserDataResponse, type GetUserDepositsRequest, type GetUserDepositsResponse, type GetUserFullLiquidationsHistoryRequest, type GetUserFundingHistoryRequest, type GetUserFundingHistoryResponse, type GetUserLiquidationsCancelHistoryResponse, type GetUserLiquidationsCancelOrdersHistoryRequest, type GetUserLiquidationsHistoryResponse, type GetUserPartialLiquidationsHistoryRequest, type GetUserPartialLiquidationsHistoryResponse, type GetUserPersonalPointsRankingRequest, type GetUserPersonalPointsRankingResponse, type GetUserPointsHistoryRequest, type GetUserPointsHistoryResponse, type GetUserPortfolioValueRequest, type GetUserPortfolioValueResponse, type GetUserReferralStatsHistoryRequest, type GetUserReferralStatsHistoryResponse, type GetUserRewardsValueRequest, type GetUserRewardsValueResponse, type GetUserTradeStatsHistoryRequest, type GetUserTradeStatsHistoryResponse, type GetUserTransferHistoryRequest, type GetUserTransferHistoryResponse, type GetUserVaultDepositsRequest, type GetUserVaultDepositsResponse, type GetUserVaultWithdrawsRequest, type GetUserVaultWithdrawsResponse, type GetUserVolumeForReferralRequest, type GetUserVolumeForReferralResponse, type GetUserWithdrawalsRequest, type GetUserWithdrawalsResponse, type GetUsersByAddressRequest, type GetUsersByAddressResponse, type GetVaultDepositsRequest, type GetVaultDepositsResponse, type GetVaultHistoricalDataRequest, type GetVaultHistoricalDataResponse, type GetVaultWithdrawalsRequest, type GetVaultWithdrawalsResponse, type GlobalLiquidation, type GlobalPartialLiquidation, type HistoricBoxReward, type HistoricalBoxRewardsStats, type HistoricalDeposit, type HistoricalFullLiquidation, type HistoricalFunding, type HistoricalLiquidatedBorrow, type HistoricalLiquidatedCollateral, type HistoricalLiquidatedLend, type HistoricalLiquidatedPosition, type HistoricalLiquidationCancelOrders, type HistoricalPartialLiquidatedPosition, type HistoricalPartialLiquidation, type HistoricalPerpOrder, type HistoricalPoints, type HistoricalReferralStats, type HistoricalSpotOrder, type HistoricalTokenStats, type HistoricalTradeStats, type HistoricalUserTransfer, type HistoricalVaultDeposit, type HistoricalVaultWithdraw, type HistoricalWithdraw, type IndexPriceHistory, type IndexPriceLive, type Lend, type LendTokenParams, type Liquidation, type LiquidationCancelledOrderData, type LiquidationCancelledTriggerOrderData, MAINNET_CONFIG, type MarginStep, Network, type NetworkConfig, type NetworkMode, type NodeStatus, type OpenBoxesRequest, type OpenBoxesResponse, type OpenBoxesSignRequest, type OracleUpdate, type OracleUpdates, type OrderBookData, OrderSide, OrderStatus, OrderType, type PaginationCursor, type PartialLiquidation, type PerpFill, type PerpMarketConfigEntry, type PerpMarketData, type PerpOrder, type PerpOrderData, type PerpOrderDataForMarket, type PerpOrderFills, type PerpOrderbookState, type PerpOrderbookUpdate, type PerpPosition, type PerpTrade, type PerpTradesUpdate, type PerpTriggerOrder, type PerpTriggerOrderTriggered, type PlaceMultiplePerpOrdersParams, type PlaceMultipleSpotOrdersParams, type PlacePerpLimitOrder, type PlacePerpMarketOrder, type PlacePerpOrderParams, type PlacePerpTriggerOrder, type PlacePerpTriggerOrderParams, type PlaceSpotLimitOrder, type PlaceSpotMarketOrder, type PlaceSpotOrderParams, type PointsRankingEntry, type PriceIndex, type RedeemTokenParams, type Referral, type ReferralUpdate, type RemoveApiKey, type RemoveApiKeyParams, type RemoveApiKeySignerParams, type RepayBorrow, type ReplaceMultipleOrdersParams, type ReplaceMultipleSpotOrdersParams, type SetAlias, type SetAliasNameParams, type SetAutoLend, type SetAutolendParams, type SetReferralCodeParams, type SetReferralParamsRequest, type SetReferralParamsResponse, type SpotFill, type SpotMarketConfigEntry, type SpotMarketData, type SpotOrder, type SpotOrderData, type SpotOrderDataForMarket, type SpotOrderFills, type SpotOrderbookState, type SpotOrderbookUpdate, type SpotTrade, type SpotTradesUpdate, Status, type StatusResponse, type SubServiceStatus, type SubmitSponsoredTransactionRequest, type SubmitSponsoredTransactionResponse, TESTNET_CONFIG, TestFaucet, type TimeResponse, type TokenAggregatedStats, type TokenConfigEntry, type TokenizeUserVaultInvestmentParams, type Topic, type Trade, TradeRole, TransferAction, type TransferToUserParams, type TriggerOrder, type TxParams, type UpdateUserFeeTier, type User, type UserAggregatedBoxRewardsStats, type UserAggregatedReferralStats, type UserAggregatedStats, type UserAggregatedVaultStats, type UserBoxOpeningEvent, type UserPointsBreakdown, type UserPortfolioValue, type UserRewardsValue, UserStatus, type UserTransfer, type UtilizationCurve, type Vault, type VaultDeposit, type VaultHistoricalData, type VaultInvestment, type VaultWithdraw, type Withdraw, type WithdrawFromVaultParams, type WithdrawLend, type WithdrawTokenParams, type WsBorrowLendUpdate, type WsBoxOpeningUpdate, type WsCommand, type WsFill, type WsLiquidatedBorrow, type WsLiquidatedCollateral, type WsLiquidatedLend, type WsLiquidatedPosition, type WsLiquidationUpdate, type WsMessage, type WsOracleUpdates, type WsPartialLiquidatedPosition, type WsPerpMarketUpdates, type WsSpotMarketUpdates, type WsUserUpdates, createAptosClient, createAptosClientFromEnv, generateApiKey, getABIsForNetwork, getNetworkConfig, getNetworkModeFromEnv, getRandomId, getTopicFromCommand, getTopicFromMessage, nowInMiliseconds, parseEntryFunctionAbi, sleep, toSystemValue };
package/dist/index.js CHANGED
@@ -23536,7 +23536,6 @@ var EndpointsV1 = /* @__PURE__ */ ((EndpointsV12) => {
23536
23536
  EndpointsV12["GetIndexPrices"] = "/v1/get_index_prices";
23537
23537
  EndpointsV12["GetAccountValueRanking"] = "/v1/get_account_value_ranking";
23538
23538
  EndpointsV12["GetUserAccountValueRanking"] = "/v1/get_user_account_value_ranking";
23539
- EndpointsV12["GetExchangeStatsHistory"] = "/v1/get_exchange_stats_history";
23540
23539
  return EndpointsV12;
23541
23540
  })(EndpointsV1 || {});
23542
23541
  var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
@@ -23892,15 +23891,13 @@ var AccountSequenceNumber = class {
23892
23891
  // src/client.ts
23893
23892
  var getRandomId = () => uuidv7();
23894
23893
  var Client = class _Client {
23895
- constructor(connection, enableWs, url, apiKey, chainId, params, networkMode = "testnet", wsDebug = false, timeout = 5e3) {
23894
+ constructor(connection, enableWs, url, apiKey, chainId, params, networkMode = "testnet") {
23896
23895
  this._apiKeySequenceNumber = 0;
23897
23896
  this._subscriptions = /* @__PURE__ */ new Map();
23898
23897
  this._gasUnitPrice = 100;
23899
23898
  this._expirationTimestampDelay = 20;
23900
23899
  // 20 seconds
23901
23900
  this.timeout = 5e3;
23902
- // Same as below in init
23903
- this.wsDebug = false;
23904
23901
  /////////////////////////////////// Sponsored transactions
23905
23902
  this.submitSponsoredTransaction = async (tx, signature) => {
23906
23903
  const payload = {
@@ -24350,25 +24347,13 @@ var Client = class _Client {
24350
24347
  this._maxGas = params?.maxGas || 2e4;
24351
24348
  this._gasUnitPrice = params?.gasUnitPrice || 100;
24352
24349
  this._expirationTimestampDelay = params?.expirationTimestampSecs || 20;
24353
- this.wsDebug = wsDebug;
24354
- this.timeout = timeout;
24355
24350
  if (enableWs) {
24356
24351
  this.connectWebSocket();
24357
24352
  }
24358
24353
  }
24359
- static async init(connection, enableWs = true, url, apiKey, chainId, params, networkMode = "testnet", wsDebug = false, timeout = 5e3) {
24354
+ static async init(connection, enableWs = true, url, apiKey, chainId, params, networkMode = "testnet") {
24360
24355
  const id = chainId || await connection.getChainId();
24361
- const client = new _Client(
24362
- connection,
24363
- enableWs,
24364
- url,
24365
- apiKey,
24366
- id,
24367
- params,
24368
- networkMode,
24369
- wsDebug,
24370
- timeout
24371
- );
24356
+ const client = new _Client(connection, enableWs, url, apiKey, id, params, networkMode);
24372
24357
  if (enableWs) {
24373
24358
  client.connectWebSocket();
24374
24359
  }
@@ -24402,21 +24387,11 @@ var Client = class _Client {
24402
24387
  * myApiKeyAccount // custom API key
24403
24388
  * )
24404
24389
  */
24405
- static async create(connection, networkMode = "testnet", enableWs = true, url, apiKey, wsDebug = false, timeout = 5e3) {
24390
+ static async create(connection, networkMode = "testnet", enableWs = true, url, apiKey) {
24406
24391
  const networkConfig = getNetworkConfig(networkMode);
24407
24392
  const apiUrl = url || networkConfig.apiUrl;
24408
24393
  const chainId = networkConfig.chainId;
24409
- return _Client.init(
24410
- connection,
24411
- enableWs,
24412
- apiUrl,
24413
- apiKey,
24414
- chainId,
24415
- void 0,
24416
- networkMode,
24417
- wsDebug,
24418
- timeout
24419
- );
24394
+ return _Client.init(connection, enableWs, apiUrl, apiKey, chainId, void 0, networkMode);
24420
24395
  }
24421
24396
  async setApiKey(apiKey) {
24422
24397
  this._apiKey = apiKey;
@@ -24442,60 +24417,21 @@ var Client = class _Client {
24442
24417
  this._expirationTimestampDelay = params.expirationTimestampSecs;
24443
24418
  }
24444
24419
  //////////////////////////////////////// Websocket functions
24445
- _wsLog(...args) {
24446
- if (this.wsDebug) console.log("[WS]", ...args);
24447
- }
24448
- setWsDebugActive(active) {
24449
- this.wsDebug = active;
24450
- }
24451
24420
  async connectWebSocket() {
24452
24421
  if (this._ws) {
24453
24422
  console.warn("WebSocket is already connected");
24454
24423
  return;
24455
24424
  }
24456
24425
  try {
24457
- const wsUrl = `${this._serverUrl.replace("http", "ws").replace("https", "wss")}` + "/v1/ws" /* Ws */;
24458
- this._wsLog("Connecting to", wsUrl);
24459
- this._ws = new WebSocket(wsUrl);
24426
+ this._ws = await _Client.initWebSocket(this._serverUrl, this.timeout);
24460
24427
  this._setupWebSocketHandlers();
24461
- await this._waitForOpen(this.timeout);
24462
- this._wsLog("Connected");
24428
+ return;
24463
24429
  } catch (error) {
24464
- this._wsLog("Connection failed:", error);
24465
- this._ws = void 0;
24466
24430
  throw new Error(`Failed to connect WebSocket: ${error}`);
24467
24431
  }
24468
24432
  }
24469
- _waitForOpen(timeout) {
24470
- return new Promise((resolve, reject) => {
24471
- if (!this._ws) return reject(new Error("No WebSocket"));
24472
- if (this._ws.readyState === WebSocket.OPEN) {
24473
- return resolve();
24474
- }
24475
- const timer = setTimeout(() => {
24476
- this._wsLog("Connection timeout after", timeout, "ms");
24477
- reject(new Error("WebSocket connection timeout"));
24478
- }, timeout);
24479
- const ws = this._ws;
24480
- const origOnOpen = ws.onopen;
24481
- ws.onopen = (event) => {
24482
- clearTimeout(timer);
24483
- origOnOpen?.call(ws, event);
24484
- resolve();
24485
- };
24486
- const origOnError = ws.onerror;
24487
- ws.onerror = (error) => {
24488
- clearTimeout(timer);
24489
- origOnError?.call(ws, error);
24490
- reject(error);
24491
- };
24492
- });
24493
- }
24494
24433
  _setupWebSocketHandlers() {
24495
24434
  if (!this._ws) return;
24496
- this._ws.onopen = () => {
24497
- this._wsLog("Opened");
24498
- };
24499
24435
  this._ws.onmessage = async (msg) => {
24500
24436
  let data;
24501
24437
  if (msg.data.arrayBuffer) {
@@ -24504,52 +24440,49 @@ var Client = class _Client {
24504
24440
  data = msg.data;
24505
24441
  }
24506
24442
  const decodedMsg = JSON.parse(data);
24507
- this._wsLog("Received:", decodedMsg.type, decodedMsg.content);
24508
24443
  const topic = getTopicFromMessage(decodedMsg);
24509
24444
  const callback = this._subscriptions.get(topic);
24510
24445
  if (callback) {
24511
24446
  callback(decodedMsg);
24512
- } else {
24513
- this._wsLog("No handler for topic:", topic);
24514
24447
  }
24515
24448
  };
24516
- this._ws.onclose = (event) => {
24517
- this._wsLog(
24518
- "Closed: code=" + event.code,
24519
- "reason=" + event.reason,
24520
- "clean=" + event.wasClean
24449
+ }
24450
+ static async initWebSocket(url, timeout = 5e3) {
24451
+ return new Promise((resolve, reject) => {
24452
+ const ws = new WebSocket(
24453
+ `${url.replace("http", "ws").replace("https", "wss")}` + "/v1/ws" /* Ws */
24521
24454
  );
24522
- this._ws = void 0;
24523
- this._subscriptions.clear();
24524
- this.onWsClose?.(event);
24525
- };
24526
- this._ws.onerror = (error) => {
24527
- this._wsLog("Error:", error);
24528
- };
24455
+ const timer = setTimeout(() => {
24456
+ reject(new Error("WebSocket connection timeout"));
24457
+ }, timeout);
24458
+ ws.onopen = () => {
24459
+ clearTimeout(timer);
24460
+ resolve(ws);
24461
+ };
24462
+ ws.onerror = (error) => {
24463
+ clearTimeout(timer);
24464
+ reject(error);
24465
+ };
24466
+ });
24529
24467
  }
24530
24468
  async disconnectWebSocket() {
24531
24469
  if (!this._ws) {
24532
24470
  console.warn("WebSocket is not connected");
24533
24471
  return;
24534
24472
  }
24535
- this._wsLog("Disconnecting, clearing", this._subscriptions.size, "subscriptions");
24536
24473
  this._subscriptions.clear();
24537
24474
  this._ws.close();
24538
24475
  this._ws = void 0;
24539
24476
  }
24540
24477
  // Method to check if WebSocket is connected
24541
24478
  isWebSocketConnected() {
24542
- const connected = this._ws !== void 0 && this._ws.readyState === WebSocket.OPEN;
24543
- this._wsLog("isWebSocketConnected:", connected);
24544
- return connected;
24479
+ return this._ws !== void 0 && this._ws.readyState === WebSocket.OPEN;
24545
24480
  }
24546
24481
  sendWsMessage(message) {
24547
24482
  if (!this._ws) throw new Error("WebSocket is not connected");
24548
24483
  return new Promise((resolve, reject) => {
24549
24484
  const topic = message.content.id;
24550
- this._wsLog("Sending:", message.type, "id=" + topic);
24551
24485
  const timer = setTimeout(() => {
24552
- this._wsLog("Timeout waiting for response:", message.type, "id=" + topic);
24553
24486
  reject(new Error(`Connection timed out after ${this.timeout} ms`));
24554
24487
  }, this.timeout);
24555
24488
  let handler = (response) => {
@@ -24557,13 +24490,11 @@ var Client = class _Client {
24557
24490
  this._subscriptions.delete(topic);
24558
24491
  if (response.type === "Error") {
24559
24492
  const errorMessage = response.content.message || "Unknown websocket error without message";
24560
- this._wsLog("Error response:", errorMessage, "id=" + topic);
24561
24493
  reject(
24562
24494
  new Error(`WebSocket error (id: ${response.content.id}): ${errorMessage}`)
24563
24495
  );
24564
24496
  return;
24565
24497
  }
24566
- this._wsLog("Ack received for:", message.type, "id=" + topic);
24567
24498
  resolve(response);
24568
24499
  };
24569
24500
  this._subscriptions.set(topic, handler);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nightlylabs/dex-sdk",
3
- "version": "0.3.37",
3
+ "version": "0.3.38",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {