@nightlylabs/dex-sdk 0.3.38 → 0.3.40
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 +118 -57
- package/dist/index.d.cts +72 -27
- package/dist/index.d.ts +72 -27
- package/dist/index.js +118 -57
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23578,6 +23578,7 @@ 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";
|
|
23581
23582
|
return EndpointsV12;
|
|
23582
23583
|
})(EndpointsV1 || {});
|
|
23583
23584
|
var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
|
|
@@ -23933,13 +23934,17 @@ var AccountSequenceNumber = class {
|
|
|
23933
23934
|
// src/client.ts
|
|
23934
23935
|
var getRandomId = () => (0, import_uuid.v7)();
|
|
23935
23936
|
var Client = class _Client {
|
|
23936
|
-
constructor(connection,
|
|
23937
|
+
constructor(connection, config = {}) {
|
|
23937
23938
|
this._apiKeySequenceNumber = 0;
|
|
23939
|
+
this._pingIntervalMs = 3e4;
|
|
23940
|
+
this._lastPongAt = 0;
|
|
23938
23941
|
this._subscriptions = /* @__PURE__ */ new Map();
|
|
23939
23942
|
this._gasUnitPrice = 100;
|
|
23940
23943
|
this._expirationTimestampDelay = 20;
|
|
23941
23944
|
// 20 seconds
|
|
23942
23945
|
this.timeout = 5e3;
|
|
23946
|
+
// Same as below in init
|
|
23947
|
+
this.wsDebug = false;
|
|
23943
23948
|
/////////////////////////////////// Sponsored transactions
|
|
23944
23949
|
this.submitSponsoredTransaction = async (tx, signature) => {
|
|
23945
23950
|
const payload = {
|
|
@@ -24377,27 +24382,28 @@ var Client = class _Client {
|
|
|
24377
24382
|
const response = await this.sendGetJson("/time" /* Time */);
|
|
24378
24383
|
return response.time;
|
|
24379
24384
|
};
|
|
24385
|
+
const networkMode = config.networkMode || "testnet";
|
|
24380
24386
|
const networkConfig = getNetworkConfig(networkMode);
|
|
24381
24387
|
this._aptos = connection;
|
|
24382
|
-
this._chainId = chainId || networkConfig.chainId;
|
|
24383
|
-
this._apiKey = apiKey || generateApiKey();
|
|
24388
|
+
this._chainId = config.chainId || networkConfig.chainId;
|
|
24389
|
+
this._apiKey = config.apiKey || generateApiKey();
|
|
24384
24390
|
this._subscriptions = /* @__PURE__ */ new Map();
|
|
24385
|
-
this._serverUrl = url || networkConfig.apiUrl;
|
|
24391
|
+
this._serverUrl = config.url || networkConfig.apiUrl;
|
|
24386
24392
|
this._sequenceNumberManager = new AccountSequenceNumber(this._aptos, this._apiKey);
|
|
24387
24393
|
this._abis = getABIsForNetwork(networkMode);
|
|
24388
24394
|
this._contractAddress = Object.values(this._abis)[0].address;
|
|
24389
|
-
this._maxGas = params?.maxGas || 2e4;
|
|
24390
|
-
this._gasUnitPrice = params?.gasUnitPrice || 100;
|
|
24391
|
-
this._expirationTimestampDelay = params?.expirationTimestampSecs || 20;
|
|
24392
|
-
|
|
24393
|
-
|
|
24394
|
-
|
|
24395
|
+
this._maxGas = config.params?.maxGas || 2e4;
|
|
24396
|
+
this._gasUnitPrice = config.params?.gasUnitPrice || 100;
|
|
24397
|
+
this._expirationTimestampDelay = config.params?.expirationTimestampSecs || 20;
|
|
24398
|
+
this.wsDebug = config.wsDebug || false;
|
|
24399
|
+
this.timeout = config.timeout || 5e3;
|
|
24400
|
+
this._pingIntervalMs = config.pingIntervalMs || 3e4;
|
|
24395
24401
|
}
|
|
24396
|
-
static async init(connection,
|
|
24397
|
-
const id = chainId || await connection.getChainId();
|
|
24398
|
-
const client = new _Client(connection,
|
|
24399
|
-
if (enableWs) {
|
|
24400
|
-
client.connectWebSocket();
|
|
24402
|
+
static async init(connection, config = {}) {
|
|
24403
|
+
const id = config.chainId || await connection.getChainId();
|
|
24404
|
+
const client = new _Client(connection, { ...config, chainId: id });
|
|
24405
|
+
if (config.enableWs !== false) {
|
|
24406
|
+
await client.connectWebSocket();
|
|
24401
24407
|
}
|
|
24402
24408
|
return client;
|
|
24403
24409
|
}
|
|
@@ -24405,10 +24411,7 @@ var Client = class _Client {
|
|
|
24405
24411
|
* Create a new Client instance
|
|
24406
24412
|
*
|
|
24407
24413
|
* @param connection - Aptos connection instance
|
|
24408
|
-
* @param
|
|
24409
|
-
* @param enableWs - Enable WebSocket connection. Defaults to true
|
|
24410
|
-
* @param url - Custom API URL. If not provided, uses default URL based on network mode
|
|
24411
|
-
* @param apiKey - API key account. If not provided, generates a new one
|
|
24414
|
+
* @param config - Client configuration options
|
|
24412
24415
|
* @returns Promise<Client>
|
|
24413
24416
|
*
|
|
24414
24417
|
* @example
|
|
@@ -24417,23 +24420,24 @@ var Client = class _Client {
|
|
|
24417
24420
|
*
|
|
24418
24421
|
* @example
|
|
24419
24422
|
* // Create a mainnet client
|
|
24420
|
-
* const client = await Client.create(aptos, 'mainnet')
|
|
24423
|
+
* const client = await Client.create(aptos, { networkMode: 'mainnet' })
|
|
24424
|
+
*
|
|
24425
|
+
* @example
|
|
24426
|
+
* // Create an HTTP-only client (no WebSocket)
|
|
24427
|
+
* const client = await Client.create(aptos, { enableWs: false })
|
|
24421
24428
|
*
|
|
24422
24429
|
* @example
|
|
24423
24430
|
* // Create a client with custom settings
|
|
24424
|
-
* const client = await Client.create(
|
|
24425
|
-
*
|
|
24426
|
-
* '
|
|
24427
|
-
*
|
|
24428
|
-
*
|
|
24429
|
-
*
|
|
24430
|
-
* )
|
|
24431
|
+
* const client = await Client.create(aptos, {
|
|
24432
|
+
* networkMode: 'mainnet',
|
|
24433
|
+
* url: 'https://custom-api.example.com',
|
|
24434
|
+
* apiKey: myApiKeyAccount,
|
|
24435
|
+
* wsDebug: true,
|
|
24436
|
+
* timeout: 10000,
|
|
24437
|
+
* })
|
|
24431
24438
|
*/
|
|
24432
|
-
static async create(connection,
|
|
24433
|
-
|
|
24434
|
-
const apiUrl = url || networkConfig.apiUrl;
|
|
24435
|
-
const chainId = networkConfig.chainId;
|
|
24436
|
-
return _Client.init(connection, enableWs, apiUrl, apiKey, chainId, void 0, networkMode);
|
|
24439
|
+
static async create(connection, config = {}) {
|
|
24440
|
+
return _Client.init(connection, config);
|
|
24437
24441
|
}
|
|
24438
24442
|
async setApiKey(apiKey) {
|
|
24439
24443
|
this._apiKey = apiKey;
|
|
@@ -24459,21 +24463,56 @@ var Client = class _Client {
|
|
|
24459
24463
|
this._expirationTimestampDelay = params.expirationTimestampSecs;
|
|
24460
24464
|
}
|
|
24461
24465
|
//////////////////////////////////////// Websocket functions
|
|
24466
|
+
_wsLog(...args) {
|
|
24467
|
+
if (this.wsDebug) console.log("[WS]", ...args);
|
|
24468
|
+
}
|
|
24469
|
+
setWsDebugActive(active) {
|
|
24470
|
+
this.wsDebug = active;
|
|
24471
|
+
}
|
|
24462
24472
|
async connectWebSocket() {
|
|
24463
24473
|
if (this._ws) {
|
|
24464
24474
|
console.warn("WebSocket is already connected");
|
|
24465
24475
|
return;
|
|
24466
24476
|
}
|
|
24467
24477
|
try {
|
|
24468
|
-
this.
|
|
24478
|
+
this._wsLog("Connecting to", this._serverUrl);
|
|
24479
|
+
this._ws = await this._initWebSocket(this._serverUrl, this.timeout);
|
|
24469
24480
|
this._setupWebSocketHandlers();
|
|
24470
|
-
|
|
24481
|
+
this._wsLog("Connected");
|
|
24471
24482
|
} catch (error) {
|
|
24483
|
+
this._wsLog("Connection failed:", error);
|
|
24472
24484
|
throw new Error(`Failed to connect WebSocket: ${error}`);
|
|
24473
24485
|
}
|
|
24474
24486
|
}
|
|
24487
|
+
_initWebSocket(url, timeout) {
|
|
24488
|
+
return new Promise((resolve, reject) => {
|
|
24489
|
+
const wsUrl = `${url.replace("http", "ws").replace("https", "wss")}` + "/v1/ws" /* Ws */;
|
|
24490
|
+
this._wsLog("initWebSocket url:", wsUrl, "timeout:", timeout);
|
|
24491
|
+
const ws = new WebSocket(wsUrl);
|
|
24492
|
+
const timer = setTimeout(() => {
|
|
24493
|
+
this._wsLog("initWebSocket timeout after", timeout, "ms");
|
|
24494
|
+
reject(new Error("WebSocket connection timeout"));
|
|
24495
|
+
}, timeout);
|
|
24496
|
+
ws.onopen = () => {
|
|
24497
|
+
clearTimeout(timer);
|
|
24498
|
+
this._wsLog("initWebSocket opened");
|
|
24499
|
+
resolve(ws);
|
|
24500
|
+
};
|
|
24501
|
+
ws.onerror = (error) => {
|
|
24502
|
+
clearTimeout(timer);
|
|
24503
|
+
this._wsLog("initWebSocket error:", error);
|
|
24504
|
+
reject(error);
|
|
24505
|
+
};
|
|
24506
|
+
});
|
|
24507
|
+
}
|
|
24475
24508
|
_setupWebSocketHandlers() {
|
|
24476
24509
|
if (!this._ws) return;
|
|
24510
|
+
this._lastPongAt = Date.now();
|
|
24511
|
+
this._pingInterval = setInterval(() => {
|
|
24512
|
+
if (this._ws && this._ws.readyState === WebSocket.OPEN) {
|
|
24513
|
+
this._ws.send(JSON.stringify({ type: "Ping" }));
|
|
24514
|
+
}
|
|
24515
|
+
}, this._pingIntervalMs);
|
|
24477
24516
|
this._ws.onmessage = async (msg) => {
|
|
24478
24517
|
let data;
|
|
24479
24518
|
if (msg.data.arrayBuffer) {
|
|
@@ -24481,50 +24520,70 @@ var Client = class _Client {
|
|
|
24481
24520
|
} else {
|
|
24482
24521
|
data = msg.data;
|
|
24483
24522
|
}
|
|
24523
|
+
if (data === '{"type":"Pong"}') {
|
|
24524
|
+
this._lastPongAt = Date.now();
|
|
24525
|
+
return;
|
|
24526
|
+
}
|
|
24484
24527
|
const decodedMsg = JSON.parse(data);
|
|
24528
|
+
this._wsLog("Received:", decodedMsg.type, decodedMsg.content);
|
|
24485
24529
|
const topic = getTopicFromMessage(decodedMsg);
|
|
24486
24530
|
const callback = this._subscriptions.get(topic);
|
|
24487
24531
|
if (callback) {
|
|
24488
24532
|
callback(decodedMsg);
|
|
24533
|
+
} else {
|
|
24534
|
+
this._wsLog("No handler for topic:", topic);
|
|
24489
24535
|
}
|
|
24490
24536
|
};
|
|
24491
|
-
|
|
24492
|
-
|
|
24493
|
-
|
|
24494
|
-
|
|
24495
|
-
|
|
24537
|
+
this._ws.onclose = (event) => {
|
|
24538
|
+
this._wsLog(
|
|
24539
|
+
"Closed: code=" + event.code,
|
|
24540
|
+
"reason=" + event.reason,
|
|
24541
|
+
"clean=" + event.wasClean
|
|
24496
24542
|
);
|
|
24497
|
-
|
|
24498
|
-
|
|
24499
|
-
|
|
24500
|
-
|
|
24501
|
-
|
|
24502
|
-
|
|
24503
|
-
|
|
24504
|
-
|
|
24505
|
-
|
|
24506
|
-
|
|
24507
|
-
|
|
24508
|
-
});
|
|
24543
|
+
this._ws = void 0;
|
|
24544
|
+
if (this._pingInterval) {
|
|
24545
|
+
clearInterval(this._pingInterval);
|
|
24546
|
+
this._pingInterval = void 0;
|
|
24547
|
+
}
|
|
24548
|
+
this._subscriptions.clear();
|
|
24549
|
+
this.onWsClose?.(event);
|
|
24550
|
+
};
|
|
24551
|
+
this._ws.onerror = (error) => {
|
|
24552
|
+
this._wsLog("Error:", error);
|
|
24553
|
+
};
|
|
24509
24554
|
}
|
|
24510
24555
|
async disconnectWebSocket() {
|
|
24511
24556
|
if (!this._ws) {
|
|
24512
24557
|
console.warn("WebSocket is not connected");
|
|
24513
24558
|
return;
|
|
24514
24559
|
}
|
|
24560
|
+
this._wsLog("Disconnecting, clearing", this._subscriptions.size, "subscriptions");
|
|
24561
|
+
if (this._pingInterval) {
|
|
24562
|
+
clearInterval(this._pingInterval);
|
|
24563
|
+
this._pingInterval = void 0;
|
|
24564
|
+
}
|
|
24515
24565
|
this._subscriptions.clear();
|
|
24516
24566
|
this._ws.close();
|
|
24517
24567
|
this._ws = void 0;
|
|
24518
24568
|
}
|
|
24519
|
-
// Method to check if WebSocket is connected
|
|
24569
|
+
// Method to check if WebSocket is connected and responsive
|
|
24520
24570
|
isWebSocketConnected() {
|
|
24521
|
-
|
|
24571
|
+
if (!this._ws || this._ws.readyState !== WebSocket.OPEN) {
|
|
24572
|
+
this._wsLog("isWebSocketConnected: false (not open)");
|
|
24573
|
+
return false;
|
|
24574
|
+
}
|
|
24575
|
+
const pongTimeout = this._pingIntervalMs * 2;
|
|
24576
|
+
const alive = Date.now() - this._lastPongAt < pongTimeout;
|
|
24577
|
+
this._wsLog("isWebSocketConnected:", alive, "lastPong:", Date.now() - this._lastPongAt, "ms ago");
|
|
24578
|
+
return alive;
|
|
24522
24579
|
}
|
|
24523
24580
|
sendWsMessage(message) {
|
|
24524
24581
|
if (!this._ws) throw new Error("WebSocket is not connected");
|
|
24525
24582
|
return new Promise((resolve, reject) => {
|
|
24526
24583
|
const topic = message.content.id;
|
|
24584
|
+
this._wsLog("Sending:", message.type, "id=" + topic);
|
|
24527
24585
|
const timer = setTimeout(() => {
|
|
24586
|
+
this._wsLog("Timeout waiting for response:", message.type, "id=" + topic);
|
|
24528
24587
|
reject(new Error(`Connection timed out after ${this.timeout} ms`));
|
|
24529
24588
|
}, this.timeout);
|
|
24530
24589
|
let handler = (response) => {
|
|
@@ -24532,11 +24591,13 @@ var Client = class _Client {
|
|
|
24532
24591
|
this._subscriptions.delete(topic);
|
|
24533
24592
|
if (response.type === "Error") {
|
|
24534
24593
|
const errorMessage = response.content.message || "Unknown websocket error without message";
|
|
24594
|
+
this._wsLog("Error response:", errorMessage, "id=" + topic);
|
|
24535
24595
|
reject(
|
|
24536
24596
|
new Error(`WebSocket error (id: ${response.content.id}): ${errorMessage}`)
|
|
24537
24597
|
);
|
|
24538
24598
|
return;
|
|
24539
24599
|
}
|
|
24600
|
+
this._wsLog("Ack received for:", message.type, "id=" + topic);
|
|
24540
24601
|
resolve(response);
|
|
24541
24602
|
};
|
|
24542
24603
|
this._subscriptions.set(topic, handler);
|
|
@@ -25453,11 +25514,11 @@ function parseEntryFunctionAbi(args) {
|
|
|
25453
25514
|
// src/testFaucet.ts
|
|
25454
25515
|
var import_ts_sdk4 = require("@aptos-labs/ts-sdk");
|
|
25455
25516
|
var TestFaucet = class _TestFaucet extends client_default {
|
|
25456
|
-
constructor(connection,
|
|
25457
|
-
super(connection,
|
|
25517
|
+
constructor(connection, config = {}) {
|
|
25518
|
+
super(connection, config);
|
|
25458
25519
|
}
|
|
25459
|
-
static async create(connection,
|
|
25460
|
-
return new _TestFaucet(connection, enableWs
|
|
25520
|
+
static async create(connection, config = {}) {
|
|
25521
|
+
return new _TestFaucet(connection, { enableWs: false, ...config });
|
|
25461
25522
|
}
|
|
25462
25523
|
async initFaucetPayload() {
|
|
25463
25524
|
const abi = this._abis.FaucetEntrypointsABI;
|
package/dist/index.d.cts
CHANGED
|
@@ -3682,6 +3682,7 @@ interface TokenConfigEntry {
|
|
|
3682
3682
|
contractAddress: string;
|
|
3683
3683
|
tokenDecimals: number;
|
|
3684
3684
|
vaultId?: string;
|
|
3685
|
+
createdAt?: string;
|
|
3685
3686
|
}
|
|
3686
3687
|
interface MarginStep {
|
|
3687
3688
|
initialMarginRatio: string;
|
|
@@ -3709,6 +3710,7 @@ interface PerpMarketConfigEntry {
|
|
|
3709
3710
|
fundingRate: FundingRate;
|
|
3710
3711
|
basicMakerFee: string;
|
|
3711
3712
|
basicTakerFee: string;
|
|
3713
|
+
createdAt?: string;
|
|
3712
3714
|
}
|
|
3713
3715
|
interface SpotMarketConfigEntry {
|
|
3714
3716
|
marketName: string;
|
|
@@ -3718,6 +3720,7 @@ interface SpotMarketConfigEntry {
|
|
|
3718
3720
|
tickSize: string;
|
|
3719
3721
|
basicMakerFee: string;
|
|
3720
3722
|
basicTakerFee: string;
|
|
3723
|
+
createdAt?: string;
|
|
3721
3724
|
}
|
|
3722
3725
|
interface FeeData {
|
|
3723
3726
|
feeToVaultAccount: string;
|
|
@@ -3731,6 +3734,19 @@ interface ExchangeConfig {
|
|
|
3731
3734
|
feeData: FeeData;
|
|
3732
3735
|
systemHaircut: string;
|
|
3733
3736
|
}
|
|
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
|
+
}
|
|
3734
3750
|
interface FeeTier {
|
|
3735
3751
|
volume: string;
|
|
3736
3752
|
cashback: string;
|
|
@@ -3762,13 +3778,6 @@ interface GetAccountValueRankingResponse {
|
|
|
3762
3778
|
usersRanking: AccountValueRankingEntry[];
|
|
3763
3779
|
paginationCursor?: PaginationCursor;
|
|
3764
3780
|
}
|
|
3765
|
-
interface GetUserAccountValueRankingRequest {
|
|
3766
|
-
userId?: string;
|
|
3767
|
-
userAddress?: string;
|
|
3768
|
-
}
|
|
3769
|
-
interface GetUserAccountValueRankingResponse {
|
|
3770
|
-
usersRanking: AccountValueRankingEntry[];
|
|
3771
|
-
}
|
|
3772
3781
|
interface GetAllVaultsIdsResponse {
|
|
3773
3782
|
vaultsIds: string[];
|
|
3774
3783
|
}
|
|
@@ -3811,6 +3820,15 @@ interface GetChartCandlesInRangeResponse {
|
|
|
3811
3820
|
chartCandles: ChartCandle[];
|
|
3812
3821
|
paginationCursor?: PaginationCursor;
|
|
3813
3822
|
}
|
|
3823
|
+
interface GetExchangeStatsHistoryRequest {
|
|
3824
|
+
olderTimestampMs?: string;
|
|
3825
|
+
newerTimestampMs?: string;
|
|
3826
|
+
paginationCursor?: PaginationCursor;
|
|
3827
|
+
}
|
|
3828
|
+
interface GetExchangeStatsHistoryResponse {
|
|
3829
|
+
data: ExchangeStatsEntry[];
|
|
3830
|
+
paginationCursor?: PaginationCursor;
|
|
3831
|
+
}
|
|
3814
3832
|
interface GetIndexPriceHistoryRequest {
|
|
3815
3833
|
priceIndex: string;
|
|
3816
3834
|
olderTimestampMs?: string;
|
|
@@ -4154,6 +4172,13 @@ interface PointsRankingEntry {
|
|
|
4154
4172
|
interface GetTopPointsRankingResponse {
|
|
4155
4173
|
usersRanking: PointsRankingEntry[];
|
|
4156
4174
|
}
|
|
4175
|
+
interface GetUserAccountValueRankingRequest {
|
|
4176
|
+
userId?: string;
|
|
4177
|
+
userAddress?: string;
|
|
4178
|
+
}
|
|
4179
|
+
interface GetUserAccountValueRankingResponse {
|
|
4180
|
+
usersRanking: AccountValueRankingEntry[];
|
|
4181
|
+
}
|
|
4157
4182
|
interface GetUserAggregatedBoxRewardsStatsRequest {
|
|
4158
4183
|
userId: string;
|
|
4159
4184
|
}
|
|
@@ -5159,7 +5184,8 @@ declare enum EndpointsV1 {
|
|
|
5159
5184
|
GetUserPersonalPointsRanking = "/v1/get_user_personal_points_ranking",
|
|
5160
5185
|
GetIndexPrices = "/v1/get_index_prices",
|
|
5161
5186
|
GetAccountValueRanking = "/v1/get_account_value_ranking",
|
|
5162
|
-
GetUserAccountValueRanking = "/v1/get_user_account_value_ranking"
|
|
5187
|
+
GetUserAccountValueRanking = "/v1/get_user_account_value_ranking",
|
|
5188
|
+
GetExchangeStatsHistory = "/v1/get_exchange_stats_history"
|
|
5163
5189
|
}
|
|
5164
5190
|
type Topic = {
|
|
5165
5191
|
type: "PerpMarket";
|
|
@@ -5432,6 +5458,17 @@ interface TxParams {
|
|
|
5432
5458
|
gasUnitPrice: number;
|
|
5433
5459
|
expirationTimestampSecs: number;
|
|
5434
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
|
+
pingIntervalMs?: number;
|
|
5471
|
+
}
|
|
5435
5472
|
interface ChangePerpOrderParams {
|
|
5436
5473
|
userId: string;
|
|
5437
5474
|
market: string;
|
|
@@ -5741,6 +5778,9 @@ declare class Client {
|
|
|
5741
5778
|
_apiKey: Account;
|
|
5742
5779
|
_apiKeySequenceNumber: number;
|
|
5743
5780
|
_ws: WebSocket | undefined;
|
|
5781
|
+
_pingInterval: ReturnType<typeof setInterval> | undefined;
|
|
5782
|
+
_pingIntervalMs: number;
|
|
5783
|
+
_lastPongAt: number;
|
|
5744
5784
|
_serverUrl: string;
|
|
5745
5785
|
_subscriptions: Map<string, (data: WsMessage) => void>;
|
|
5746
5786
|
_sequenceNumberManager: AccountSequenceNumber;
|
|
@@ -5748,18 +5788,17 @@ declare class Client {
|
|
|
5748
5788
|
_gasUnitPrice: number;
|
|
5749
5789
|
_expirationTimestampDelay: number;
|
|
5750
5790
|
timeout: number;
|
|
5791
|
+
wsDebug: boolean;
|
|
5792
|
+
onWsClose: ((event: CloseEvent) => void) | undefined;
|
|
5751
5793
|
_abis: ReturnType<typeof getABIsForNetwork>;
|
|
5752
5794
|
_contractAddress: string;
|
|
5753
|
-
static init(connection: Aptos,
|
|
5754
|
-
constructor(connection: Aptos,
|
|
5795
|
+
static init(connection: Aptos, config?: ClientConfig): Promise<Client>;
|
|
5796
|
+
constructor(connection: Aptos, config?: ClientConfig);
|
|
5755
5797
|
/**
|
|
5756
5798
|
* Create a new Client instance
|
|
5757
5799
|
*
|
|
5758
5800
|
* @param connection - Aptos connection instance
|
|
5759
|
-
* @param
|
|
5760
|
-
* @param enableWs - Enable WebSocket connection. Defaults to true
|
|
5761
|
-
* @param url - Custom API URL. If not provided, uses default URL based on network mode
|
|
5762
|
-
* @param apiKey - API key account. If not provided, generates a new one
|
|
5801
|
+
* @param config - Client configuration options
|
|
5763
5802
|
* @returns Promise<Client>
|
|
5764
5803
|
*
|
|
5765
5804
|
* @example
|
|
@@ -5768,27 +5807,33 @@ declare class Client {
|
|
|
5768
5807
|
*
|
|
5769
5808
|
* @example
|
|
5770
5809
|
* // Create a mainnet client
|
|
5771
|
-
* const client = await Client.create(aptos, 'mainnet')
|
|
5810
|
+
* const client = await Client.create(aptos, { networkMode: 'mainnet' })
|
|
5811
|
+
*
|
|
5812
|
+
* @example
|
|
5813
|
+
* // Create an HTTP-only client (no WebSocket)
|
|
5814
|
+
* const client = await Client.create(aptos, { enableWs: false })
|
|
5772
5815
|
*
|
|
5773
5816
|
* @example
|
|
5774
5817
|
* // Create a client with custom settings
|
|
5775
|
-
* const client = await Client.create(
|
|
5776
|
-
*
|
|
5777
|
-
* '
|
|
5778
|
-
*
|
|
5779
|
-
*
|
|
5780
|
-
*
|
|
5781
|
-
* )
|
|
5818
|
+
* const client = await Client.create(aptos, {
|
|
5819
|
+
* networkMode: 'mainnet',
|
|
5820
|
+
* url: 'https://custom-api.example.com',
|
|
5821
|
+
* apiKey: myApiKeyAccount,
|
|
5822
|
+
* wsDebug: true,
|
|
5823
|
+
* timeout: 10000,
|
|
5824
|
+
* })
|
|
5782
5825
|
*/
|
|
5783
|
-
static create(connection: Aptos,
|
|
5826
|
+
static create(connection: Aptos, config?: ClientConfig): Promise<Client>;
|
|
5784
5827
|
setApiKey(apiKey: Account): Promise<void>;
|
|
5785
5828
|
getContractAddress(): string;
|
|
5786
5829
|
getApiKeySequenceNumber(): Promise<bigint | null>;
|
|
5787
5830
|
fetchApiKeySequenceNumber(): Promise<number>;
|
|
5788
5831
|
setTxParams(params: TxParams): void;
|
|
5832
|
+
private _wsLog;
|
|
5833
|
+
setWsDebugActive(active: boolean): void;
|
|
5789
5834
|
connectWebSocket(): Promise<void>;
|
|
5835
|
+
private _initWebSocket;
|
|
5790
5836
|
private _setupWebSocketHandlers;
|
|
5791
|
-
static initWebSocket(url: string, timeout?: number): Promise<WebSocket>;
|
|
5792
5837
|
disconnectWebSocket(): Promise<void>;
|
|
5793
5838
|
isWebSocketConnected(): boolean;
|
|
5794
5839
|
sendWsMessage(message: WsCommand): Promise<WsMessage>;
|
|
@@ -5932,8 +5977,8 @@ declare const ExchangeProxies: {
|
|
|
5932
5977
|
declare const GLOBAL_DENOMINATOR = 100000000;
|
|
5933
5978
|
|
|
5934
5979
|
declare class TestFaucet extends Client {
|
|
5935
|
-
constructor(connection: Aptos,
|
|
5936
|
-
static create(connection: Aptos,
|
|
5980
|
+
constructor(connection: Aptos, config?: ClientConfig);
|
|
5981
|
+
static create(connection: Aptos, config?: ClientConfig): Promise<TestFaucet>;
|
|
5937
5982
|
initFaucetPayload(): Promise<_aptos_labs_ts_sdk.TransactionPayloadEntryFunction>;
|
|
5938
5983
|
initFaucet(): Promise<SubmitSponsoredTransactionResponse>;
|
|
5939
5984
|
mintTokenPayload(receiver: Address, token: string, amount: number): Promise<_aptos_labs_ts_sdk.TransactionPayloadEntryFunction>;
|
|
@@ -5947,4 +5992,4 @@ declare const generateApiKey: () => _aptos_labs_ts_sdk.Ed25519Account;
|
|
|
5947
5992
|
declare const getTopicFromCommand: (data: WsCommand) => string;
|
|
5948
5993
|
declare const getTopicFromMessage: (data: WsMessage) => string;
|
|
5949
5994
|
|
|
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 };
|
|
5995
|
+
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
|
@@ -3682,6 +3682,7 @@ interface TokenConfigEntry {
|
|
|
3682
3682
|
contractAddress: string;
|
|
3683
3683
|
tokenDecimals: number;
|
|
3684
3684
|
vaultId?: string;
|
|
3685
|
+
createdAt?: string;
|
|
3685
3686
|
}
|
|
3686
3687
|
interface MarginStep {
|
|
3687
3688
|
initialMarginRatio: string;
|
|
@@ -3709,6 +3710,7 @@ interface PerpMarketConfigEntry {
|
|
|
3709
3710
|
fundingRate: FundingRate;
|
|
3710
3711
|
basicMakerFee: string;
|
|
3711
3712
|
basicTakerFee: string;
|
|
3713
|
+
createdAt?: string;
|
|
3712
3714
|
}
|
|
3713
3715
|
interface SpotMarketConfigEntry {
|
|
3714
3716
|
marketName: string;
|
|
@@ -3718,6 +3720,7 @@ interface SpotMarketConfigEntry {
|
|
|
3718
3720
|
tickSize: string;
|
|
3719
3721
|
basicMakerFee: string;
|
|
3720
3722
|
basicTakerFee: string;
|
|
3723
|
+
createdAt?: string;
|
|
3721
3724
|
}
|
|
3722
3725
|
interface FeeData {
|
|
3723
3726
|
feeToVaultAccount: string;
|
|
@@ -3731,6 +3734,19 @@ interface ExchangeConfig {
|
|
|
3731
3734
|
feeData: FeeData;
|
|
3732
3735
|
systemHaircut: string;
|
|
3733
3736
|
}
|
|
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
|
+
}
|
|
3734
3750
|
interface FeeTier {
|
|
3735
3751
|
volume: string;
|
|
3736
3752
|
cashback: string;
|
|
@@ -3762,13 +3778,6 @@ interface GetAccountValueRankingResponse {
|
|
|
3762
3778
|
usersRanking: AccountValueRankingEntry[];
|
|
3763
3779
|
paginationCursor?: PaginationCursor;
|
|
3764
3780
|
}
|
|
3765
|
-
interface GetUserAccountValueRankingRequest {
|
|
3766
|
-
userId?: string;
|
|
3767
|
-
userAddress?: string;
|
|
3768
|
-
}
|
|
3769
|
-
interface GetUserAccountValueRankingResponse {
|
|
3770
|
-
usersRanking: AccountValueRankingEntry[];
|
|
3771
|
-
}
|
|
3772
3781
|
interface GetAllVaultsIdsResponse {
|
|
3773
3782
|
vaultsIds: string[];
|
|
3774
3783
|
}
|
|
@@ -3811,6 +3820,15 @@ interface GetChartCandlesInRangeResponse {
|
|
|
3811
3820
|
chartCandles: ChartCandle[];
|
|
3812
3821
|
paginationCursor?: PaginationCursor;
|
|
3813
3822
|
}
|
|
3823
|
+
interface GetExchangeStatsHistoryRequest {
|
|
3824
|
+
olderTimestampMs?: string;
|
|
3825
|
+
newerTimestampMs?: string;
|
|
3826
|
+
paginationCursor?: PaginationCursor;
|
|
3827
|
+
}
|
|
3828
|
+
interface GetExchangeStatsHistoryResponse {
|
|
3829
|
+
data: ExchangeStatsEntry[];
|
|
3830
|
+
paginationCursor?: PaginationCursor;
|
|
3831
|
+
}
|
|
3814
3832
|
interface GetIndexPriceHistoryRequest {
|
|
3815
3833
|
priceIndex: string;
|
|
3816
3834
|
olderTimestampMs?: string;
|
|
@@ -4154,6 +4172,13 @@ interface PointsRankingEntry {
|
|
|
4154
4172
|
interface GetTopPointsRankingResponse {
|
|
4155
4173
|
usersRanking: PointsRankingEntry[];
|
|
4156
4174
|
}
|
|
4175
|
+
interface GetUserAccountValueRankingRequest {
|
|
4176
|
+
userId?: string;
|
|
4177
|
+
userAddress?: string;
|
|
4178
|
+
}
|
|
4179
|
+
interface GetUserAccountValueRankingResponse {
|
|
4180
|
+
usersRanking: AccountValueRankingEntry[];
|
|
4181
|
+
}
|
|
4157
4182
|
interface GetUserAggregatedBoxRewardsStatsRequest {
|
|
4158
4183
|
userId: string;
|
|
4159
4184
|
}
|
|
@@ -5159,7 +5184,8 @@ declare enum EndpointsV1 {
|
|
|
5159
5184
|
GetUserPersonalPointsRanking = "/v1/get_user_personal_points_ranking",
|
|
5160
5185
|
GetIndexPrices = "/v1/get_index_prices",
|
|
5161
5186
|
GetAccountValueRanking = "/v1/get_account_value_ranking",
|
|
5162
|
-
GetUserAccountValueRanking = "/v1/get_user_account_value_ranking"
|
|
5187
|
+
GetUserAccountValueRanking = "/v1/get_user_account_value_ranking",
|
|
5188
|
+
GetExchangeStatsHistory = "/v1/get_exchange_stats_history"
|
|
5163
5189
|
}
|
|
5164
5190
|
type Topic = {
|
|
5165
5191
|
type: "PerpMarket";
|
|
@@ -5432,6 +5458,17 @@ interface TxParams {
|
|
|
5432
5458
|
gasUnitPrice: number;
|
|
5433
5459
|
expirationTimestampSecs: number;
|
|
5434
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
|
+
pingIntervalMs?: number;
|
|
5471
|
+
}
|
|
5435
5472
|
interface ChangePerpOrderParams {
|
|
5436
5473
|
userId: string;
|
|
5437
5474
|
market: string;
|
|
@@ -5741,6 +5778,9 @@ declare class Client {
|
|
|
5741
5778
|
_apiKey: Account;
|
|
5742
5779
|
_apiKeySequenceNumber: number;
|
|
5743
5780
|
_ws: WebSocket | undefined;
|
|
5781
|
+
_pingInterval: ReturnType<typeof setInterval> | undefined;
|
|
5782
|
+
_pingIntervalMs: number;
|
|
5783
|
+
_lastPongAt: number;
|
|
5744
5784
|
_serverUrl: string;
|
|
5745
5785
|
_subscriptions: Map<string, (data: WsMessage) => void>;
|
|
5746
5786
|
_sequenceNumberManager: AccountSequenceNumber;
|
|
@@ -5748,18 +5788,17 @@ declare class Client {
|
|
|
5748
5788
|
_gasUnitPrice: number;
|
|
5749
5789
|
_expirationTimestampDelay: number;
|
|
5750
5790
|
timeout: number;
|
|
5791
|
+
wsDebug: boolean;
|
|
5792
|
+
onWsClose: ((event: CloseEvent) => void) | undefined;
|
|
5751
5793
|
_abis: ReturnType<typeof getABIsForNetwork>;
|
|
5752
5794
|
_contractAddress: string;
|
|
5753
|
-
static init(connection: Aptos,
|
|
5754
|
-
constructor(connection: Aptos,
|
|
5795
|
+
static init(connection: Aptos, config?: ClientConfig): Promise<Client>;
|
|
5796
|
+
constructor(connection: Aptos, config?: ClientConfig);
|
|
5755
5797
|
/**
|
|
5756
5798
|
* Create a new Client instance
|
|
5757
5799
|
*
|
|
5758
5800
|
* @param connection - Aptos connection instance
|
|
5759
|
-
* @param
|
|
5760
|
-
* @param enableWs - Enable WebSocket connection. Defaults to true
|
|
5761
|
-
* @param url - Custom API URL. If not provided, uses default URL based on network mode
|
|
5762
|
-
* @param apiKey - API key account. If not provided, generates a new one
|
|
5801
|
+
* @param config - Client configuration options
|
|
5763
5802
|
* @returns Promise<Client>
|
|
5764
5803
|
*
|
|
5765
5804
|
* @example
|
|
@@ -5768,27 +5807,33 @@ declare class Client {
|
|
|
5768
5807
|
*
|
|
5769
5808
|
* @example
|
|
5770
5809
|
* // Create a mainnet client
|
|
5771
|
-
* const client = await Client.create(aptos, 'mainnet')
|
|
5810
|
+
* const client = await Client.create(aptos, { networkMode: 'mainnet' })
|
|
5811
|
+
*
|
|
5812
|
+
* @example
|
|
5813
|
+
* // Create an HTTP-only client (no WebSocket)
|
|
5814
|
+
* const client = await Client.create(aptos, { enableWs: false })
|
|
5772
5815
|
*
|
|
5773
5816
|
* @example
|
|
5774
5817
|
* // Create a client with custom settings
|
|
5775
|
-
* const client = await Client.create(
|
|
5776
|
-
*
|
|
5777
|
-
* '
|
|
5778
|
-
*
|
|
5779
|
-
*
|
|
5780
|
-
*
|
|
5781
|
-
* )
|
|
5818
|
+
* const client = await Client.create(aptos, {
|
|
5819
|
+
* networkMode: 'mainnet',
|
|
5820
|
+
* url: 'https://custom-api.example.com',
|
|
5821
|
+
* apiKey: myApiKeyAccount,
|
|
5822
|
+
* wsDebug: true,
|
|
5823
|
+
* timeout: 10000,
|
|
5824
|
+
* })
|
|
5782
5825
|
*/
|
|
5783
|
-
static create(connection: Aptos,
|
|
5826
|
+
static create(connection: Aptos, config?: ClientConfig): Promise<Client>;
|
|
5784
5827
|
setApiKey(apiKey: Account): Promise<void>;
|
|
5785
5828
|
getContractAddress(): string;
|
|
5786
5829
|
getApiKeySequenceNumber(): Promise<bigint | null>;
|
|
5787
5830
|
fetchApiKeySequenceNumber(): Promise<number>;
|
|
5788
5831
|
setTxParams(params: TxParams): void;
|
|
5832
|
+
private _wsLog;
|
|
5833
|
+
setWsDebugActive(active: boolean): void;
|
|
5789
5834
|
connectWebSocket(): Promise<void>;
|
|
5835
|
+
private _initWebSocket;
|
|
5790
5836
|
private _setupWebSocketHandlers;
|
|
5791
|
-
static initWebSocket(url: string, timeout?: number): Promise<WebSocket>;
|
|
5792
5837
|
disconnectWebSocket(): Promise<void>;
|
|
5793
5838
|
isWebSocketConnected(): boolean;
|
|
5794
5839
|
sendWsMessage(message: WsCommand): Promise<WsMessage>;
|
|
@@ -5932,8 +5977,8 @@ declare const ExchangeProxies: {
|
|
|
5932
5977
|
declare const GLOBAL_DENOMINATOR = 100000000;
|
|
5933
5978
|
|
|
5934
5979
|
declare class TestFaucet extends Client {
|
|
5935
|
-
constructor(connection: Aptos,
|
|
5936
|
-
static create(connection: Aptos,
|
|
5980
|
+
constructor(connection: Aptos, config?: ClientConfig);
|
|
5981
|
+
static create(connection: Aptos, config?: ClientConfig): Promise<TestFaucet>;
|
|
5937
5982
|
initFaucetPayload(): Promise<_aptos_labs_ts_sdk.TransactionPayloadEntryFunction>;
|
|
5938
5983
|
initFaucet(): Promise<SubmitSponsoredTransactionResponse>;
|
|
5939
5984
|
mintTokenPayload(receiver: Address, token: string, amount: number): Promise<_aptos_labs_ts_sdk.TransactionPayloadEntryFunction>;
|
|
@@ -5947,4 +5992,4 @@ declare const generateApiKey: () => _aptos_labs_ts_sdk.Ed25519Account;
|
|
|
5947
5992
|
declare const getTopicFromCommand: (data: WsCommand) => string;
|
|
5948
5993
|
declare const getTopicFromMessage: (data: WsMessage) => string;
|
|
5949
5994
|
|
|
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 };
|
|
5995
|
+
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
|
@@ -23536,6 +23536,7 @@ 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";
|
|
23539
23540
|
return EndpointsV12;
|
|
23540
23541
|
})(EndpointsV1 || {});
|
|
23541
23542
|
var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
|
|
@@ -23891,13 +23892,17 @@ var AccountSequenceNumber = class {
|
|
|
23891
23892
|
// src/client.ts
|
|
23892
23893
|
var getRandomId = () => uuidv7();
|
|
23893
23894
|
var Client = class _Client {
|
|
23894
|
-
constructor(connection,
|
|
23895
|
+
constructor(connection, config = {}) {
|
|
23895
23896
|
this._apiKeySequenceNumber = 0;
|
|
23897
|
+
this._pingIntervalMs = 3e4;
|
|
23898
|
+
this._lastPongAt = 0;
|
|
23896
23899
|
this._subscriptions = /* @__PURE__ */ new Map();
|
|
23897
23900
|
this._gasUnitPrice = 100;
|
|
23898
23901
|
this._expirationTimestampDelay = 20;
|
|
23899
23902
|
// 20 seconds
|
|
23900
23903
|
this.timeout = 5e3;
|
|
23904
|
+
// Same as below in init
|
|
23905
|
+
this.wsDebug = false;
|
|
23901
23906
|
/////////////////////////////////// Sponsored transactions
|
|
23902
23907
|
this.submitSponsoredTransaction = async (tx, signature) => {
|
|
23903
23908
|
const payload = {
|
|
@@ -24335,27 +24340,28 @@ var Client = class _Client {
|
|
|
24335
24340
|
const response = await this.sendGetJson("/time" /* Time */);
|
|
24336
24341
|
return response.time;
|
|
24337
24342
|
};
|
|
24343
|
+
const networkMode = config.networkMode || "testnet";
|
|
24338
24344
|
const networkConfig = getNetworkConfig(networkMode);
|
|
24339
24345
|
this._aptos = connection;
|
|
24340
|
-
this._chainId = chainId || networkConfig.chainId;
|
|
24341
|
-
this._apiKey = apiKey || generateApiKey();
|
|
24346
|
+
this._chainId = config.chainId || networkConfig.chainId;
|
|
24347
|
+
this._apiKey = config.apiKey || generateApiKey();
|
|
24342
24348
|
this._subscriptions = /* @__PURE__ */ new Map();
|
|
24343
|
-
this._serverUrl = url || networkConfig.apiUrl;
|
|
24349
|
+
this._serverUrl = config.url || networkConfig.apiUrl;
|
|
24344
24350
|
this._sequenceNumberManager = new AccountSequenceNumber(this._aptos, this._apiKey);
|
|
24345
24351
|
this._abis = getABIsForNetwork(networkMode);
|
|
24346
24352
|
this._contractAddress = Object.values(this._abis)[0].address;
|
|
24347
|
-
this._maxGas = params?.maxGas || 2e4;
|
|
24348
|
-
this._gasUnitPrice = params?.gasUnitPrice || 100;
|
|
24349
|
-
this._expirationTimestampDelay = params?.expirationTimestampSecs || 20;
|
|
24350
|
-
|
|
24351
|
-
|
|
24352
|
-
|
|
24353
|
+
this._maxGas = config.params?.maxGas || 2e4;
|
|
24354
|
+
this._gasUnitPrice = config.params?.gasUnitPrice || 100;
|
|
24355
|
+
this._expirationTimestampDelay = config.params?.expirationTimestampSecs || 20;
|
|
24356
|
+
this.wsDebug = config.wsDebug || false;
|
|
24357
|
+
this.timeout = config.timeout || 5e3;
|
|
24358
|
+
this._pingIntervalMs = config.pingIntervalMs || 3e4;
|
|
24353
24359
|
}
|
|
24354
|
-
static async init(connection,
|
|
24355
|
-
const id = chainId || await connection.getChainId();
|
|
24356
|
-
const client = new _Client(connection,
|
|
24357
|
-
if (enableWs) {
|
|
24358
|
-
client.connectWebSocket();
|
|
24360
|
+
static async init(connection, config = {}) {
|
|
24361
|
+
const id = config.chainId || await connection.getChainId();
|
|
24362
|
+
const client = new _Client(connection, { ...config, chainId: id });
|
|
24363
|
+
if (config.enableWs !== false) {
|
|
24364
|
+
await client.connectWebSocket();
|
|
24359
24365
|
}
|
|
24360
24366
|
return client;
|
|
24361
24367
|
}
|
|
@@ -24363,10 +24369,7 @@ var Client = class _Client {
|
|
|
24363
24369
|
* Create a new Client instance
|
|
24364
24370
|
*
|
|
24365
24371
|
* @param connection - Aptos connection instance
|
|
24366
|
-
* @param
|
|
24367
|
-
* @param enableWs - Enable WebSocket connection. Defaults to true
|
|
24368
|
-
* @param url - Custom API URL. If not provided, uses default URL based on network mode
|
|
24369
|
-
* @param apiKey - API key account. If not provided, generates a new one
|
|
24372
|
+
* @param config - Client configuration options
|
|
24370
24373
|
* @returns Promise<Client>
|
|
24371
24374
|
*
|
|
24372
24375
|
* @example
|
|
@@ -24375,23 +24378,24 @@ var Client = class _Client {
|
|
|
24375
24378
|
*
|
|
24376
24379
|
* @example
|
|
24377
24380
|
* // Create a mainnet client
|
|
24378
|
-
* const client = await Client.create(aptos, 'mainnet')
|
|
24381
|
+
* const client = await Client.create(aptos, { networkMode: 'mainnet' })
|
|
24382
|
+
*
|
|
24383
|
+
* @example
|
|
24384
|
+
* // Create an HTTP-only client (no WebSocket)
|
|
24385
|
+
* const client = await Client.create(aptos, { enableWs: false })
|
|
24379
24386
|
*
|
|
24380
24387
|
* @example
|
|
24381
24388
|
* // Create a client with custom settings
|
|
24382
|
-
* const client = await Client.create(
|
|
24383
|
-
*
|
|
24384
|
-
* '
|
|
24385
|
-
*
|
|
24386
|
-
*
|
|
24387
|
-
*
|
|
24388
|
-
* )
|
|
24389
|
+
* const client = await Client.create(aptos, {
|
|
24390
|
+
* networkMode: 'mainnet',
|
|
24391
|
+
* url: 'https://custom-api.example.com',
|
|
24392
|
+
* apiKey: myApiKeyAccount,
|
|
24393
|
+
* wsDebug: true,
|
|
24394
|
+
* timeout: 10000,
|
|
24395
|
+
* })
|
|
24389
24396
|
*/
|
|
24390
|
-
static async create(connection,
|
|
24391
|
-
|
|
24392
|
-
const apiUrl = url || networkConfig.apiUrl;
|
|
24393
|
-
const chainId = networkConfig.chainId;
|
|
24394
|
-
return _Client.init(connection, enableWs, apiUrl, apiKey, chainId, void 0, networkMode);
|
|
24397
|
+
static async create(connection, config = {}) {
|
|
24398
|
+
return _Client.init(connection, config);
|
|
24395
24399
|
}
|
|
24396
24400
|
async setApiKey(apiKey) {
|
|
24397
24401
|
this._apiKey = apiKey;
|
|
@@ -24417,21 +24421,56 @@ var Client = class _Client {
|
|
|
24417
24421
|
this._expirationTimestampDelay = params.expirationTimestampSecs;
|
|
24418
24422
|
}
|
|
24419
24423
|
//////////////////////////////////////// Websocket functions
|
|
24424
|
+
_wsLog(...args) {
|
|
24425
|
+
if (this.wsDebug) console.log("[WS]", ...args);
|
|
24426
|
+
}
|
|
24427
|
+
setWsDebugActive(active) {
|
|
24428
|
+
this.wsDebug = active;
|
|
24429
|
+
}
|
|
24420
24430
|
async connectWebSocket() {
|
|
24421
24431
|
if (this._ws) {
|
|
24422
24432
|
console.warn("WebSocket is already connected");
|
|
24423
24433
|
return;
|
|
24424
24434
|
}
|
|
24425
24435
|
try {
|
|
24426
|
-
this.
|
|
24436
|
+
this._wsLog("Connecting to", this._serverUrl);
|
|
24437
|
+
this._ws = await this._initWebSocket(this._serverUrl, this.timeout);
|
|
24427
24438
|
this._setupWebSocketHandlers();
|
|
24428
|
-
|
|
24439
|
+
this._wsLog("Connected");
|
|
24429
24440
|
} catch (error) {
|
|
24441
|
+
this._wsLog("Connection failed:", error);
|
|
24430
24442
|
throw new Error(`Failed to connect WebSocket: ${error}`);
|
|
24431
24443
|
}
|
|
24432
24444
|
}
|
|
24445
|
+
_initWebSocket(url, timeout) {
|
|
24446
|
+
return new Promise((resolve, reject) => {
|
|
24447
|
+
const wsUrl = `${url.replace("http", "ws").replace("https", "wss")}` + "/v1/ws" /* Ws */;
|
|
24448
|
+
this._wsLog("initWebSocket url:", wsUrl, "timeout:", timeout);
|
|
24449
|
+
const ws = new WebSocket(wsUrl);
|
|
24450
|
+
const timer = setTimeout(() => {
|
|
24451
|
+
this._wsLog("initWebSocket timeout after", timeout, "ms");
|
|
24452
|
+
reject(new Error("WebSocket connection timeout"));
|
|
24453
|
+
}, timeout);
|
|
24454
|
+
ws.onopen = () => {
|
|
24455
|
+
clearTimeout(timer);
|
|
24456
|
+
this._wsLog("initWebSocket opened");
|
|
24457
|
+
resolve(ws);
|
|
24458
|
+
};
|
|
24459
|
+
ws.onerror = (error) => {
|
|
24460
|
+
clearTimeout(timer);
|
|
24461
|
+
this._wsLog("initWebSocket error:", error);
|
|
24462
|
+
reject(error);
|
|
24463
|
+
};
|
|
24464
|
+
});
|
|
24465
|
+
}
|
|
24433
24466
|
_setupWebSocketHandlers() {
|
|
24434
24467
|
if (!this._ws) return;
|
|
24468
|
+
this._lastPongAt = Date.now();
|
|
24469
|
+
this._pingInterval = setInterval(() => {
|
|
24470
|
+
if (this._ws && this._ws.readyState === WebSocket.OPEN) {
|
|
24471
|
+
this._ws.send(JSON.stringify({ type: "Ping" }));
|
|
24472
|
+
}
|
|
24473
|
+
}, this._pingIntervalMs);
|
|
24435
24474
|
this._ws.onmessage = async (msg) => {
|
|
24436
24475
|
let data;
|
|
24437
24476
|
if (msg.data.arrayBuffer) {
|
|
@@ -24439,50 +24478,70 @@ var Client = class _Client {
|
|
|
24439
24478
|
} else {
|
|
24440
24479
|
data = msg.data;
|
|
24441
24480
|
}
|
|
24481
|
+
if (data === '{"type":"Pong"}') {
|
|
24482
|
+
this._lastPongAt = Date.now();
|
|
24483
|
+
return;
|
|
24484
|
+
}
|
|
24442
24485
|
const decodedMsg = JSON.parse(data);
|
|
24486
|
+
this._wsLog("Received:", decodedMsg.type, decodedMsg.content);
|
|
24443
24487
|
const topic = getTopicFromMessage(decodedMsg);
|
|
24444
24488
|
const callback = this._subscriptions.get(topic);
|
|
24445
24489
|
if (callback) {
|
|
24446
24490
|
callback(decodedMsg);
|
|
24491
|
+
} else {
|
|
24492
|
+
this._wsLog("No handler for topic:", topic);
|
|
24447
24493
|
}
|
|
24448
24494
|
};
|
|
24449
|
-
|
|
24450
|
-
|
|
24451
|
-
|
|
24452
|
-
|
|
24453
|
-
|
|
24495
|
+
this._ws.onclose = (event) => {
|
|
24496
|
+
this._wsLog(
|
|
24497
|
+
"Closed: code=" + event.code,
|
|
24498
|
+
"reason=" + event.reason,
|
|
24499
|
+
"clean=" + event.wasClean
|
|
24454
24500
|
);
|
|
24455
|
-
|
|
24456
|
-
|
|
24457
|
-
|
|
24458
|
-
|
|
24459
|
-
|
|
24460
|
-
|
|
24461
|
-
|
|
24462
|
-
|
|
24463
|
-
|
|
24464
|
-
|
|
24465
|
-
|
|
24466
|
-
});
|
|
24501
|
+
this._ws = void 0;
|
|
24502
|
+
if (this._pingInterval) {
|
|
24503
|
+
clearInterval(this._pingInterval);
|
|
24504
|
+
this._pingInterval = void 0;
|
|
24505
|
+
}
|
|
24506
|
+
this._subscriptions.clear();
|
|
24507
|
+
this.onWsClose?.(event);
|
|
24508
|
+
};
|
|
24509
|
+
this._ws.onerror = (error) => {
|
|
24510
|
+
this._wsLog("Error:", error);
|
|
24511
|
+
};
|
|
24467
24512
|
}
|
|
24468
24513
|
async disconnectWebSocket() {
|
|
24469
24514
|
if (!this._ws) {
|
|
24470
24515
|
console.warn("WebSocket is not connected");
|
|
24471
24516
|
return;
|
|
24472
24517
|
}
|
|
24518
|
+
this._wsLog("Disconnecting, clearing", this._subscriptions.size, "subscriptions");
|
|
24519
|
+
if (this._pingInterval) {
|
|
24520
|
+
clearInterval(this._pingInterval);
|
|
24521
|
+
this._pingInterval = void 0;
|
|
24522
|
+
}
|
|
24473
24523
|
this._subscriptions.clear();
|
|
24474
24524
|
this._ws.close();
|
|
24475
24525
|
this._ws = void 0;
|
|
24476
24526
|
}
|
|
24477
|
-
// Method to check if WebSocket is connected
|
|
24527
|
+
// Method to check if WebSocket is connected and responsive
|
|
24478
24528
|
isWebSocketConnected() {
|
|
24479
|
-
|
|
24529
|
+
if (!this._ws || this._ws.readyState !== WebSocket.OPEN) {
|
|
24530
|
+
this._wsLog("isWebSocketConnected: false (not open)");
|
|
24531
|
+
return false;
|
|
24532
|
+
}
|
|
24533
|
+
const pongTimeout = this._pingIntervalMs * 2;
|
|
24534
|
+
const alive = Date.now() - this._lastPongAt < pongTimeout;
|
|
24535
|
+
this._wsLog("isWebSocketConnected:", alive, "lastPong:", Date.now() - this._lastPongAt, "ms ago");
|
|
24536
|
+
return alive;
|
|
24480
24537
|
}
|
|
24481
24538
|
sendWsMessage(message) {
|
|
24482
24539
|
if (!this._ws) throw new Error("WebSocket is not connected");
|
|
24483
24540
|
return new Promise((resolve, reject) => {
|
|
24484
24541
|
const topic = message.content.id;
|
|
24542
|
+
this._wsLog("Sending:", message.type, "id=" + topic);
|
|
24485
24543
|
const timer = setTimeout(() => {
|
|
24544
|
+
this._wsLog("Timeout waiting for response:", message.type, "id=" + topic);
|
|
24486
24545
|
reject(new Error(`Connection timed out after ${this.timeout} ms`));
|
|
24487
24546
|
}, this.timeout);
|
|
24488
24547
|
let handler = (response) => {
|
|
@@ -24490,11 +24549,13 @@ var Client = class _Client {
|
|
|
24490
24549
|
this._subscriptions.delete(topic);
|
|
24491
24550
|
if (response.type === "Error") {
|
|
24492
24551
|
const errorMessage = response.content.message || "Unknown websocket error without message";
|
|
24552
|
+
this._wsLog("Error response:", errorMessage, "id=" + topic);
|
|
24493
24553
|
reject(
|
|
24494
24554
|
new Error(`WebSocket error (id: ${response.content.id}): ${errorMessage}`)
|
|
24495
24555
|
);
|
|
24496
24556
|
return;
|
|
24497
24557
|
}
|
|
24558
|
+
this._wsLog("Ack received for:", message.type, "id=" + topic);
|
|
24498
24559
|
resolve(response);
|
|
24499
24560
|
};
|
|
24500
24561
|
this._subscriptions.set(topic, handler);
|
|
@@ -25416,11 +25477,11 @@ import {
|
|
|
25416
25477
|
SimpleTransaction as SimpleTransaction2
|
|
25417
25478
|
} from "@aptos-labs/ts-sdk";
|
|
25418
25479
|
var TestFaucet = class _TestFaucet extends client_default {
|
|
25419
|
-
constructor(connection,
|
|
25420
|
-
super(connection,
|
|
25480
|
+
constructor(connection, config = {}) {
|
|
25481
|
+
super(connection, config);
|
|
25421
25482
|
}
|
|
25422
|
-
static async create(connection,
|
|
25423
|
-
return new _TestFaucet(connection, enableWs
|
|
25483
|
+
static async create(connection, config = {}) {
|
|
25484
|
+
return new _TestFaucet(connection, { enableWs: false, ...config });
|
|
25424
25485
|
}
|
|
25425
25486
|
async initFaucetPayload() {
|
|
25426
25487
|
const abi = this._abis.FaucetEntrypointsABI;
|