@nightlylabs/dex-sdk 0.3.37 → 0.3.39

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
@@ -23934,7 +23934,7 @@ var AccountSequenceNumber = class {
23934
23934
  // src/client.ts
23935
23935
  var getRandomId = () => (0, import_uuid.v7)();
23936
23936
  var Client = class _Client {
23937
- constructor(connection, enableWs, url, apiKey, chainId, params, networkMode = "testnet", wsDebug = false, timeout = 5e3) {
23937
+ constructor(connection, config = {}) {
23938
23938
  this._apiKeySequenceNumber = 0;
23939
23939
  this._subscriptions = /* @__PURE__ */ new Map();
23940
23940
  this._gasUnitPrice = 100;
@@ -24380,39 +24380,27 @@ var Client = class _Client {
24380
24380
  const response = await this.sendGetJson("/time" /* Time */);
24381
24381
  return response.time;
24382
24382
  };
24383
+ const networkMode = config.networkMode || "testnet";
24383
24384
  const networkConfig = getNetworkConfig(networkMode);
24384
24385
  this._aptos = connection;
24385
- this._chainId = chainId || networkConfig.chainId;
24386
- this._apiKey = apiKey || generateApiKey();
24386
+ this._chainId = config.chainId || networkConfig.chainId;
24387
+ this._apiKey = config.apiKey || generateApiKey();
24387
24388
  this._subscriptions = /* @__PURE__ */ new Map();
24388
- this._serverUrl = url || networkConfig.apiUrl;
24389
+ this._serverUrl = config.url || networkConfig.apiUrl;
24389
24390
  this._sequenceNumberManager = new AccountSequenceNumber(this._aptos, this._apiKey);
24390
24391
  this._abis = getABIsForNetwork(networkMode);
24391
24392
  this._contractAddress = Object.values(this._abis)[0].address;
24392
- this._maxGas = params?.maxGas || 2e4;
24393
- this._gasUnitPrice = params?.gasUnitPrice || 100;
24394
- this._expirationTimestampDelay = params?.expirationTimestampSecs || 20;
24395
- this.wsDebug = wsDebug;
24396
- this.timeout = timeout;
24397
- if (enableWs) {
24398
- this.connectWebSocket();
24399
- }
24393
+ this._maxGas = config.params?.maxGas || 2e4;
24394
+ this._gasUnitPrice = config.params?.gasUnitPrice || 100;
24395
+ this._expirationTimestampDelay = config.params?.expirationTimestampSecs || 20;
24396
+ this.wsDebug = config.wsDebug || false;
24397
+ this.timeout = config.timeout || 5e3;
24400
24398
  }
24401
- static async init(connection, enableWs = true, url, apiKey, chainId, params, networkMode = "testnet", wsDebug = false, timeout = 5e3) {
24402
- 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
- );
24414
- if (enableWs) {
24415
- client.connectWebSocket();
24399
+ static async init(connection, config = {}) {
24400
+ const id = config.chainId || await connection.getChainId();
24401
+ const client = new _Client(connection, { ...config, chainId: id });
24402
+ if (config.enableWs !== false) {
24403
+ await client.connectWebSocket();
24416
24404
  }
24417
24405
  return client;
24418
24406
  }
@@ -24420,10 +24408,7 @@ var Client = class _Client {
24420
24408
  * Create a new Client instance
24421
24409
  *
24422
24410
  * @param connection - Aptos connection instance
24423
- * @param networkMode - Network mode ('testnet' or 'mainnet'). Defaults to 'testnet'
24424
- * @param enableWs - Enable WebSocket connection. Defaults to true
24425
- * @param url - Custom API URL. If not provided, uses default URL based on network mode
24426
- * @param apiKey - API key account. If not provided, generates a new one
24411
+ * @param config - Client configuration options
24427
24412
  * @returns Promise<Client>
24428
24413
  *
24429
24414
  * @example
@@ -24432,33 +24417,24 @@ var Client = class _Client {
24432
24417
  *
24433
24418
  * @example
24434
24419
  * // Create a mainnet client
24435
- * const client = await Client.create(aptos, 'mainnet')
24420
+ * const client = await Client.create(aptos, { networkMode: 'mainnet' })
24421
+ *
24422
+ * @example
24423
+ * // Create an HTTP-only client (no WebSocket)
24424
+ * const client = await Client.create(aptos, { enableWs: false })
24436
24425
  *
24437
24426
  * @example
24438
24427
  * // Create a client with custom settings
24439
- * const client = await Client.create(
24440
- * aptos,
24441
- * 'mainnet',
24442
- * true, // enable WebSocket
24443
- * 'https://custom-api.example.com', // custom API URL
24444
- * myApiKeyAccount // custom API key
24445
- * )
24428
+ * const client = await Client.create(aptos, {
24429
+ * networkMode: 'mainnet',
24430
+ * url: 'https://custom-api.example.com',
24431
+ * apiKey: myApiKeyAccount,
24432
+ * wsDebug: true,
24433
+ * timeout: 10000,
24434
+ * })
24446
24435
  */
24447
- static async create(connection, networkMode = "testnet", enableWs = true, url, apiKey, wsDebug = false, timeout = 5e3) {
24448
- const networkConfig = getNetworkConfig(networkMode);
24449
- const apiUrl = url || networkConfig.apiUrl;
24450
- 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
+ static async create(connection, config = {}) {
24437
+ return _Client.init(connection, config);
24462
24438
  }
24463
24439
  async setApiKey(apiKey) {
24464
24440
  this._apiKey = apiKey;
@@ -24496,48 +24472,38 @@ var Client = class _Client {
24496
24472
  return;
24497
24473
  }
24498
24474
  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);
24475
+ this._wsLog("Connecting to", this._serverUrl);
24476
+ this._ws = await this._initWebSocket(this._serverUrl, this.timeout);
24502
24477
  this._setupWebSocketHandlers();
24503
- await this._waitForOpen(this.timeout);
24504
24478
  this._wsLog("Connected");
24505
24479
  } catch (error) {
24506
24480
  this._wsLog("Connection failed:", error);
24507
- this._ws = void 0;
24508
24481
  throw new Error(`Failed to connect WebSocket: ${error}`);
24509
24482
  }
24510
24483
  }
24511
- _waitForOpen(timeout) {
24484
+ _initWebSocket(url, timeout) {
24512
24485
  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
- }
24486
+ const wsUrl = `${url.replace("http", "ws").replace("https", "wss")}` + "/v1/ws" /* Ws */;
24487
+ this._wsLog("initWebSocket url:", wsUrl, "timeout:", timeout);
24488
+ const ws = new WebSocket(wsUrl);
24517
24489
  const timer = setTimeout(() => {
24518
- this._wsLog("Connection timeout after", timeout, "ms");
24490
+ this._wsLog("initWebSocket timeout after", timeout, "ms");
24519
24491
  reject(new Error("WebSocket connection timeout"));
24520
24492
  }, timeout);
24521
- const ws = this._ws;
24522
- const origOnOpen = ws.onopen;
24523
- ws.onopen = (event) => {
24493
+ ws.onopen = () => {
24524
24494
  clearTimeout(timer);
24525
- origOnOpen?.call(ws, event);
24526
- resolve();
24495
+ this._wsLog("initWebSocket opened");
24496
+ resolve(ws);
24527
24497
  };
24528
- const origOnError = ws.onerror;
24529
24498
  ws.onerror = (error) => {
24530
24499
  clearTimeout(timer);
24531
- origOnError?.call(ws, error);
24500
+ this._wsLog("initWebSocket error:", error);
24532
24501
  reject(error);
24533
24502
  };
24534
24503
  });
24535
24504
  }
24536
24505
  _setupWebSocketHandlers() {
24537
24506
  if (!this._ws) return;
24538
- this._ws.onopen = () => {
24539
- this._wsLog("Opened");
24540
- };
24541
24507
  this._ws.onmessage = async (msg) => {
24542
24508
  let data;
24543
24509
  if (msg.data.arrayBuffer) {
@@ -25522,11 +25488,11 @@ function parseEntryFunctionAbi(args) {
25522
25488
  // src/testFaucet.ts
25523
25489
  var import_ts_sdk4 = require("@aptos-labs/ts-sdk");
25524
25490
  var TestFaucet = class _TestFaucet extends client_default {
25525
- constructor(connection, enableWs, url, apiKey, networkMode = "testnet") {
25526
- super(connection, enableWs, url, apiKey, void 0, void 0, networkMode);
25491
+ constructor(connection, config = {}) {
25492
+ super(connection, config);
25527
25493
  }
25528
- static async create(connection, networkMode = "testnet", enableWs = false, url = "https://api.dev.neony.exchange", apiKey) {
25529
- return new _TestFaucet(connection, enableWs, url, apiKey, networkMode);
25494
+ static async create(connection, config = {}) {
25495
+ return new _TestFaucet(connection, { enableWs: false, ...config });
25530
25496
  }
25531
25497
  async initFaucetPayload() {
25532
25498
  const abi = this._abis.FaucetEntrypointsABI;
package/dist/index.d.cts CHANGED
@@ -5458,6 +5458,16 @@ interface TxParams {
5458
5458
  gasUnitPrice: number;
5459
5459
  expirationTimestampSecs: number;
5460
5460
  }
5461
+ interface ClientConfig {
5462
+ enableWs?: boolean;
5463
+ url?: string;
5464
+ apiKey?: Account;
5465
+ chainId?: number;
5466
+ params?: TxParams;
5467
+ networkMode?: NetworkMode;
5468
+ wsDebug?: boolean;
5469
+ timeout?: number;
5470
+ }
5461
5471
  interface ChangePerpOrderParams {
5462
5472
  userId: string;
5463
5473
  market: string;
@@ -5778,16 +5788,13 @@ declare class Client {
5778
5788
  onWsClose: ((event: CloseEvent) => void) | undefined;
5779
5789
  _abis: ReturnType<typeof getABIsForNetwork>;
5780
5790
  _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);
5791
+ static init(connection: Aptos, config?: ClientConfig): Promise<Client>;
5792
+ constructor(connection: Aptos, config?: ClientConfig);
5783
5793
  /**
5784
5794
  * Create a new Client instance
5785
5795
  *
5786
5796
  * @param connection - Aptos connection instance
5787
- * @param networkMode - Network mode ('testnet' or 'mainnet'). Defaults to 'testnet'
5788
- * @param enableWs - Enable WebSocket connection. Defaults to true
5789
- * @param url - Custom API URL. If not provided, uses default URL based on network mode
5790
- * @param apiKey - API key account. If not provided, generates a new one
5797
+ * @param config - Client configuration options
5791
5798
  * @returns Promise<Client>
5792
5799
  *
5793
5800
  * @example
@@ -5796,19 +5803,23 @@ declare class Client {
5796
5803
  *
5797
5804
  * @example
5798
5805
  * // Create a mainnet client
5799
- * const client = await Client.create(aptos, 'mainnet')
5806
+ * const client = await Client.create(aptos, { networkMode: 'mainnet' })
5807
+ *
5808
+ * @example
5809
+ * // Create an HTTP-only client (no WebSocket)
5810
+ * const client = await Client.create(aptos, { enableWs: false })
5800
5811
  *
5801
5812
  * @example
5802
5813
  * // Create a client with custom settings
5803
- * const client = await Client.create(
5804
- * aptos,
5805
- * 'mainnet',
5806
- * true, // enable WebSocket
5807
- * 'https://custom-api.example.com', // custom API URL
5808
- * myApiKeyAccount // custom API key
5809
- * )
5814
+ * const client = await Client.create(aptos, {
5815
+ * networkMode: 'mainnet',
5816
+ * url: 'https://custom-api.example.com',
5817
+ * apiKey: myApiKeyAccount,
5818
+ * wsDebug: true,
5819
+ * timeout: 10000,
5820
+ * })
5810
5821
  */
5811
- static create(connection: Aptos, networkMode?: NetworkMode, enableWs?: boolean, url?: string, apiKey?: Account, wsDebug?: boolean, timeout?: number): Promise<Client>;
5822
+ static create(connection: Aptos, config?: ClientConfig): Promise<Client>;
5812
5823
  setApiKey(apiKey: Account): Promise<void>;
5813
5824
  getContractAddress(): string;
5814
5825
  getApiKeySequenceNumber(): Promise<bigint | null>;
@@ -5817,7 +5828,7 @@ declare class Client {
5817
5828
  private _wsLog;
5818
5829
  setWsDebugActive(active: boolean): void;
5819
5830
  connectWebSocket(): Promise<void>;
5820
- private _waitForOpen;
5831
+ private _initWebSocket;
5821
5832
  private _setupWebSocketHandlers;
5822
5833
  disconnectWebSocket(): Promise<void>;
5823
5834
  isWebSocketConnected(): boolean;
@@ -5962,8 +5973,8 @@ declare const ExchangeProxies: {
5962
5973
  declare const GLOBAL_DENOMINATOR = 100000000;
5963
5974
 
5964
5975
  declare class TestFaucet extends Client {
5965
- constructor(connection: Aptos, enableWs: boolean, url?: string, apiKey?: Account, networkMode?: NetworkMode);
5966
- static create(connection: Aptos, networkMode?: NetworkMode, enableWs?: boolean, url?: string, apiKey?: Account): Promise<TestFaucet>;
5976
+ constructor(connection: Aptos, config?: ClientConfig);
5977
+ static create(connection: Aptos, config?: ClientConfig): Promise<TestFaucet>;
5967
5978
  initFaucetPayload(): Promise<_aptos_labs_ts_sdk.TransactionPayloadEntryFunction>;
5968
5979
  initFaucet(): Promise<SubmitSponsoredTransactionResponse>;
5969
5980
  mintTokenPayload(receiver: Address, token: string, amount: number): Promise<_aptos_labs_ts_sdk.TransactionPayloadEntryFunction>;
@@ -5977,4 +5988,4 @@ declare const generateApiKey: () => _aptos_labs_ts_sdk.Ed25519Account;
5977
5988
  declare const getTopicFromCommand: (data: WsCommand) => string;
5978
5989
  declare const getTopicFromMessage: (data: WsMessage) => string;
5979
5990
 
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 };
5991
+ 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 ClientConfig, 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 };
package/dist/index.d.ts CHANGED
@@ -5458,6 +5458,16 @@ interface TxParams {
5458
5458
  gasUnitPrice: number;
5459
5459
  expirationTimestampSecs: number;
5460
5460
  }
5461
+ interface ClientConfig {
5462
+ enableWs?: boolean;
5463
+ url?: string;
5464
+ apiKey?: Account;
5465
+ chainId?: number;
5466
+ params?: TxParams;
5467
+ networkMode?: NetworkMode;
5468
+ wsDebug?: boolean;
5469
+ timeout?: number;
5470
+ }
5461
5471
  interface ChangePerpOrderParams {
5462
5472
  userId: string;
5463
5473
  market: string;
@@ -5778,16 +5788,13 @@ declare class Client {
5778
5788
  onWsClose: ((event: CloseEvent) => void) | undefined;
5779
5789
  _abis: ReturnType<typeof getABIsForNetwork>;
5780
5790
  _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);
5791
+ static init(connection: Aptos, config?: ClientConfig): Promise<Client>;
5792
+ constructor(connection: Aptos, config?: ClientConfig);
5783
5793
  /**
5784
5794
  * Create a new Client instance
5785
5795
  *
5786
5796
  * @param connection - Aptos connection instance
5787
- * @param networkMode - Network mode ('testnet' or 'mainnet'). Defaults to 'testnet'
5788
- * @param enableWs - Enable WebSocket connection. Defaults to true
5789
- * @param url - Custom API URL. If not provided, uses default URL based on network mode
5790
- * @param apiKey - API key account. If not provided, generates a new one
5797
+ * @param config - Client configuration options
5791
5798
  * @returns Promise<Client>
5792
5799
  *
5793
5800
  * @example
@@ -5796,19 +5803,23 @@ declare class Client {
5796
5803
  *
5797
5804
  * @example
5798
5805
  * // Create a mainnet client
5799
- * const client = await Client.create(aptos, 'mainnet')
5806
+ * const client = await Client.create(aptos, { networkMode: 'mainnet' })
5807
+ *
5808
+ * @example
5809
+ * // Create an HTTP-only client (no WebSocket)
5810
+ * const client = await Client.create(aptos, { enableWs: false })
5800
5811
  *
5801
5812
  * @example
5802
5813
  * // Create a client with custom settings
5803
- * const client = await Client.create(
5804
- * aptos,
5805
- * 'mainnet',
5806
- * true, // enable WebSocket
5807
- * 'https://custom-api.example.com', // custom API URL
5808
- * myApiKeyAccount // custom API key
5809
- * )
5814
+ * const client = await Client.create(aptos, {
5815
+ * networkMode: 'mainnet',
5816
+ * url: 'https://custom-api.example.com',
5817
+ * apiKey: myApiKeyAccount,
5818
+ * wsDebug: true,
5819
+ * timeout: 10000,
5820
+ * })
5810
5821
  */
5811
- static create(connection: Aptos, networkMode?: NetworkMode, enableWs?: boolean, url?: string, apiKey?: Account, wsDebug?: boolean, timeout?: number): Promise<Client>;
5822
+ static create(connection: Aptos, config?: ClientConfig): Promise<Client>;
5812
5823
  setApiKey(apiKey: Account): Promise<void>;
5813
5824
  getContractAddress(): string;
5814
5825
  getApiKeySequenceNumber(): Promise<bigint | null>;
@@ -5817,7 +5828,7 @@ declare class Client {
5817
5828
  private _wsLog;
5818
5829
  setWsDebugActive(active: boolean): void;
5819
5830
  connectWebSocket(): Promise<void>;
5820
- private _waitForOpen;
5831
+ private _initWebSocket;
5821
5832
  private _setupWebSocketHandlers;
5822
5833
  disconnectWebSocket(): Promise<void>;
5823
5834
  isWebSocketConnected(): boolean;
@@ -5962,8 +5973,8 @@ declare const ExchangeProxies: {
5962
5973
  declare const GLOBAL_DENOMINATOR = 100000000;
5963
5974
 
5964
5975
  declare class TestFaucet extends Client {
5965
- constructor(connection: Aptos, enableWs: boolean, url?: string, apiKey?: Account, networkMode?: NetworkMode);
5966
- static create(connection: Aptos, networkMode?: NetworkMode, enableWs?: boolean, url?: string, apiKey?: Account): Promise<TestFaucet>;
5976
+ constructor(connection: Aptos, config?: ClientConfig);
5977
+ static create(connection: Aptos, config?: ClientConfig): Promise<TestFaucet>;
5967
5978
  initFaucetPayload(): Promise<_aptos_labs_ts_sdk.TransactionPayloadEntryFunction>;
5968
5979
  initFaucet(): Promise<SubmitSponsoredTransactionResponse>;
5969
5980
  mintTokenPayload(receiver: Address, token: string, amount: number): Promise<_aptos_labs_ts_sdk.TransactionPayloadEntryFunction>;
@@ -5977,4 +5988,4 @@ declare const generateApiKey: () => _aptos_labs_ts_sdk.Ed25519Account;
5977
5988
  declare const getTopicFromCommand: (data: WsCommand) => string;
5978
5989
  declare const getTopicFromMessage: (data: WsMessage) => string;
5979
5990
 
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 };
5991
+ 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 ClientConfig, 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 };
package/dist/index.js CHANGED
@@ -23892,7 +23892,7 @@ var AccountSequenceNumber = class {
23892
23892
  // src/client.ts
23893
23893
  var getRandomId = () => uuidv7();
23894
23894
  var Client = class _Client {
23895
- constructor(connection, enableWs, url, apiKey, chainId, params, networkMode = "testnet", wsDebug = false, timeout = 5e3) {
23895
+ constructor(connection, config = {}) {
23896
23896
  this._apiKeySequenceNumber = 0;
23897
23897
  this._subscriptions = /* @__PURE__ */ new Map();
23898
23898
  this._gasUnitPrice = 100;
@@ -24338,39 +24338,27 @@ var Client = class _Client {
24338
24338
  const response = await this.sendGetJson("/time" /* Time */);
24339
24339
  return response.time;
24340
24340
  };
24341
+ const networkMode = config.networkMode || "testnet";
24341
24342
  const networkConfig = getNetworkConfig(networkMode);
24342
24343
  this._aptos = connection;
24343
- this._chainId = chainId || networkConfig.chainId;
24344
- this._apiKey = apiKey || generateApiKey();
24344
+ this._chainId = config.chainId || networkConfig.chainId;
24345
+ this._apiKey = config.apiKey || generateApiKey();
24345
24346
  this._subscriptions = /* @__PURE__ */ new Map();
24346
- this._serverUrl = url || networkConfig.apiUrl;
24347
+ this._serverUrl = config.url || networkConfig.apiUrl;
24347
24348
  this._sequenceNumberManager = new AccountSequenceNumber(this._aptos, this._apiKey);
24348
24349
  this._abis = getABIsForNetwork(networkMode);
24349
24350
  this._contractAddress = Object.values(this._abis)[0].address;
24350
- this._maxGas = params?.maxGas || 2e4;
24351
- this._gasUnitPrice = params?.gasUnitPrice || 100;
24352
- this._expirationTimestampDelay = params?.expirationTimestampSecs || 20;
24353
- this.wsDebug = wsDebug;
24354
- this.timeout = timeout;
24355
- if (enableWs) {
24356
- this.connectWebSocket();
24357
- }
24351
+ this._maxGas = config.params?.maxGas || 2e4;
24352
+ this._gasUnitPrice = config.params?.gasUnitPrice || 100;
24353
+ this._expirationTimestampDelay = config.params?.expirationTimestampSecs || 20;
24354
+ this.wsDebug = config.wsDebug || false;
24355
+ this.timeout = config.timeout || 5e3;
24358
24356
  }
24359
- static async init(connection, enableWs = true, url, apiKey, chainId, params, networkMode = "testnet", wsDebug = false, timeout = 5e3) {
24360
- 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
- );
24372
- if (enableWs) {
24373
- client.connectWebSocket();
24357
+ static async init(connection, config = {}) {
24358
+ const id = config.chainId || await connection.getChainId();
24359
+ const client = new _Client(connection, { ...config, chainId: id });
24360
+ if (config.enableWs !== false) {
24361
+ await client.connectWebSocket();
24374
24362
  }
24375
24363
  return client;
24376
24364
  }
@@ -24378,10 +24366,7 @@ var Client = class _Client {
24378
24366
  * Create a new Client instance
24379
24367
  *
24380
24368
  * @param connection - Aptos connection instance
24381
- * @param networkMode - Network mode ('testnet' or 'mainnet'). Defaults to 'testnet'
24382
- * @param enableWs - Enable WebSocket connection. Defaults to true
24383
- * @param url - Custom API URL. If not provided, uses default URL based on network mode
24384
- * @param apiKey - API key account. If not provided, generates a new one
24369
+ * @param config - Client configuration options
24385
24370
  * @returns Promise<Client>
24386
24371
  *
24387
24372
  * @example
@@ -24390,33 +24375,24 @@ var Client = class _Client {
24390
24375
  *
24391
24376
  * @example
24392
24377
  * // Create a mainnet client
24393
- * const client = await Client.create(aptos, 'mainnet')
24378
+ * const client = await Client.create(aptos, { networkMode: 'mainnet' })
24379
+ *
24380
+ * @example
24381
+ * // Create an HTTP-only client (no WebSocket)
24382
+ * const client = await Client.create(aptos, { enableWs: false })
24394
24383
  *
24395
24384
  * @example
24396
24385
  * // Create a client with custom settings
24397
- * const client = await Client.create(
24398
- * aptos,
24399
- * 'mainnet',
24400
- * true, // enable WebSocket
24401
- * 'https://custom-api.example.com', // custom API URL
24402
- * myApiKeyAccount // custom API key
24403
- * )
24386
+ * const client = await Client.create(aptos, {
24387
+ * networkMode: 'mainnet',
24388
+ * url: 'https://custom-api.example.com',
24389
+ * apiKey: myApiKeyAccount,
24390
+ * wsDebug: true,
24391
+ * timeout: 10000,
24392
+ * })
24404
24393
  */
24405
- static async create(connection, networkMode = "testnet", enableWs = true, url, apiKey, wsDebug = false, timeout = 5e3) {
24406
- const networkConfig = getNetworkConfig(networkMode);
24407
- const apiUrl = url || networkConfig.apiUrl;
24408
- 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
+ static async create(connection, config = {}) {
24395
+ return _Client.init(connection, config);
24420
24396
  }
24421
24397
  async setApiKey(apiKey) {
24422
24398
  this._apiKey = apiKey;
@@ -24454,48 +24430,38 @@ var Client = class _Client {
24454
24430
  return;
24455
24431
  }
24456
24432
  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);
24433
+ this._wsLog("Connecting to", this._serverUrl);
24434
+ this._ws = await this._initWebSocket(this._serverUrl, this.timeout);
24460
24435
  this._setupWebSocketHandlers();
24461
- await this._waitForOpen(this.timeout);
24462
24436
  this._wsLog("Connected");
24463
24437
  } catch (error) {
24464
24438
  this._wsLog("Connection failed:", error);
24465
- this._ws = void 0;
24466
24439
  throw new Error(`Failed to connect WebSocket: ${error}`);
24467
24440
  }
24468
24441
  }
24469
- _waitForOpen(timeout) {
24442
+ _initWebSocket(url, timeout) {
24470
24443
  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
- }
24444
+ const wsUrl = `${url.replace("http", "ws").replace("https", "wss")}` + "/v1/ws" /* Ws */;
24445
+ this._wsLog("initWebSocket url:", wsUrl, "timeout:", timeout);
24446
+ const ws = new WebSocket(wsUrl);
24475
24447
  const timer = setTimeout(() => {
24476
- this._wsLog("Connection timeout after", timeout, "ms");
24448
+ this._wsLog("initWebSocket timeout after", timeout, "ms");
24477
24449
  reject(new Error("WebSocket connection timeout"));
24478
24450
  }, timeout);
24479
- const ws = this._ws;
24480
- const origOnOpen = ws.onopen;
24481
- ws.onopen = (event) => {
24451
+ ws.onopen = () => {
24482
24452
  clearTimeout(timer);
24483
- origOnOpen?.call(ws, event);
24484
- resolve();
24453
+ this._wsLog("initWebSocket opened");
24454
+ resolve(ws);
24485
24455
  };
24486
- const origOnError = ws.onerror;
24487
24456
  ws.onerror = (error) => {
24488
24457
  clearTimeout(timer);
24489
- origOnError?.call(ws, error);
24458
+ this._wsLog("initWebSocket error:", error);
24490
24459
  reject(error);
24491
24460
  };
24492
24461
  });
24493
24462
  }
24494
24463
  _setupWebSocketHandlers() {
24495
24464
  if (!this._ws) return;
24496
- this._ws.onopen = () => {
24497
- this._wsLog("Opened");
24498
- };
24499
24465
  this._ws.onmessage = async (msg) => {
24500
24466
  let data;
24501
24467
  if (msg.data.arrayBuffer) {
@@ -25485,11 +25451,11 @@ import {
25485
25451
  SimpleTransaction as SimpleTransaction2
25486
25452
  } from "@aptos-labs/ts-sdk";
25487
25453
  var TestFaucet = class _TestFaucet extends client_default {
25488
- constructor(connection, enableWs, url, apiKey, networkMode = "testnet") {
25489
- super(connection, enableWs, url, apiKey, void 0, void 0, networkMode);
25454
+ constructor(connection, config = {}) {
25455
+ super(connection, config);
25490
25456
  }
25491
- static async create(connection, networkMode = "testnet", enableWs = false, url = "https://api.dev.neony.exchange", apiKey) {
25492
- return new _TestFaucet(connection, enableWs, url, apiKey, networkMode);
25457
+ static async create(connection, config = {}) {
25458
+ return new _TestFaucet(connection, { enableWs: false, ...config });
25493
25459
  }
25494
25460
  async initFaucetPayload() {
25495
25461
  const abi = this._abis.FaucetEntrypointsABI;
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.39",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {