@chainstream-io/sdk 0.1.25 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2234 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, { get: all[name], enumerable: true });
6
+ };
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+
9
+ // src/chainstream.ts
10
+ import { EventSourcePolyfill } from "event-source-polyfill";
11
+
12
+ // src/openapi-client/chainstreamApiClient.ts
13
+ import Axios from "axios";
14
+ import axiosRetry, { exponentialDelay } from "axios-retry";
15
+ var axiosInstance;
16
+ var currentOptions = void 0;
17
+ var configure = (options) => {
18
+ const baseURL = options.basePath || "https://api-dex.chainstream.io";
19
+ currentOptions = {
20
+ ...options,
21
+ basePath: baseURL
22
+ };
23
+ axiosInstance = Axios.create({
24
+ baseURL
25
+ });
26
+ axiosRetry(axiosInstance, {
27
+ retryDelay: exponentialDelay
28
+ });
29
+ axiosInstance.interceptors.request.use(async (config) => {
30
+ const token = typeof options.accessToken === "string" ? options.accessToken : await options.accessToken.getToken();
31
+ config.headers.Authorization = `Bearer ${token}`;
32
+ config.headers["Content-Type"] = "application/json";
33
+ if (options.source) {
34
+ config.headers["X-Source"] = options.source;
35
+ }
36
+ if (options.sourceVersion) {
37
+ config.headers["X-Source-Version"] = options.sourceVersion;
38
+ }
39
+ if (options.debugging) {
40
+ console.log(`[ChainStream API] ${config.method?.toUpperCase()} ${config.url}`);
41
+ }
42
+ return config;
43
+ });
44
+ if (options.debugging) {
45
+ axiosInstance.interceptors.response.use(
46
+ (response) => {
47
+ console.log(`[ChainStream API] Response:`, response.status, response.data);
48
+ return response;
49
+ },
50
+ (error) => {
51
+ console.error(`[ChainStream API] Error:`, error.response?.status, error.response?.data);
52
+ return Promise.reject(error);
53
+ }
54
+ );
55
+ }
56
+ };
57
+ var addIdempotencyKey = (config, idempotencyKey) => {
58
+ if (!idempotencyKey) {
59
+ return config;
60
+ }
61
+ return {
62
+ ...config,
63
+ headers: {
64
+ ...config.headers || {},
65
+ "X-Idempotency-Key": idempotencyKey
66
+ }
67
+ };
68
+ };
69
+ var chainstreamApiClient = async (config, idempotencyKey) => {
70
+ if (!axiosInstance) {
71
+ throw new Error("ChainStream API client not configured. Call configure() first.");
72
+ }
73
+ if (!config.url || config.url === "") {
74
+ throw new Error("AxiosRequestConfig URL is empty.");
75
+ }
76
+ if (!config.method || config.method === "") {
77
+ throw new Error("AxiosRequestConfig method is empty.");
78
+ }
79
+ const configWithIdempotencyKey = addIdempotencyKey(config, idempotencyKey);
80
+ try {
81
+ const response = await axiosInstance(configWithIdempotencyKey);
82
+ return response.data;
83
+ } catch (error) {
84
+ if (Axios.isAxiosError(error) && error.response) {
85
+ const statusCode = error.response.status;
86
+ const responseData = error.response.data;
87
+ throw new Error(
88
+ `ChainStream API error (${statusCode}): ${typeof responseData === "string" ? responseData : JSON.stringify(responseData)}`
89
+ );
90
+ }
91
+ throw error;
92
+ }
93
+ };
94
+
95
+ // src/stream/stream.ts
96
+ import { Centrifuge } from "@chainstream-io/centrifuge";
97
+
98
+ // src/stream/stream.fields.ts
99
+ var CEL_FIELD_MAPPINGS = {
100
+ // Wallet balance subscription fields
101
+ subscribeWalletBalance: {
102
+ walletAddress: "a",
103
+ tokenAddress: "ta",
104
+ tokenPriceInUsd: "tpiu",
105
+ balance: "b",
106
+ timestamp: "t"
107
+ },
108
+ // Token candles subscription fields
109
+ subscribeTokenCandles: {
110
+ open: "o",
111
+ close: "c",
112
+ high: "h",
113
+ low: "l",
114
+ volume: "v",
115
+ resolution: "r",
116
+ time: "t",
117
+ number: "n"
118
+ },
119
+ // Token stats subscription fields
120
+ subscribeTokenStats: {
121
+ address: "a",
122
+ timestamp: "t",
123
+ buys1m: "b1m",
124
+ sells1m: "s1m",
125
+ buyers1m: "be1m",
126
+ sellers1m: "se1m",
127
+ buyVolumeInUsd1m: "bviu1m",
128
+ sellVolumeInUsd1m: "sviu1m",
129
+ price1m: "p1m",
130
+ openInUsd1m: "oiu1m",
131
+ closeInUsd1m: "ciu1m",
132
+ buys5m: "b5m",
133
+ sells5m: "s5m",
134
+ buyers5m: "be5m",
135
+ sellers5m: "se5m",
136
+ buyVolumeInUsd5m: "bviu5m",
137
+ sellVolumeInUsd5m: "sviu5m",
138
+ price5m: "p5m",
139
+ openInUsd5m: "oiu5m",
140
+ closeInUsd5m: "ciu5m",
141
+ buys15m: "b15m",
142
+ sells15m: "s15m",
143
+ buyers15m: "be15m",
144
+ sellers15m: "se15m",
145
+ buyVolumeInUsd15m: "bviu15m",
146
+ sellVolumeInUsd15m: "sviu15m",
147
+ price15m: "p15m",
148
+ openInUsd15m: "oiu15m",
149
+ closeInUsd15m: "ciu15m",
150
+ buys30m: "b30m",
151
+ sells30m: "s30m",
152
+ buyers30m: "be30m",
153
+ sellers30m: "se30m",
154
+ buyVolumeInUsd30m: "bviu30m",
155
+ sellVolumeInUsd30m: "sviu30m",
156
+ price30m: "p30m",
157
+ openInUsd30m: "oiu30m",
158
+ closeInUsd30m: "ciu30m",
159
+ buys1h: "b1h",
160
+ sells1h: "s1h",
161
+ buyers1h: "be1h",
162
+ sellers1h: "se1h",
163
+ buyVolumeInUsd1h: "bviu1h",
164
+ sellVolumeInUsd1h: "sviu1h",
165
+ price1h: "p1h",
166
+ openInUsd1h: "oiu1h",
167
+ closeInUsd1h: "ciu1h",
168
+ buys4h: "b4h",
169
+ sells4h: "s4h",
170
+ buyers4h: "be4h",
171
+ sellers4h: "se4h",
172
+ buyVolumeInUsd4h: "bviu4h",
173
+ sellVolumeInUsd4h: "sviu4h",
174
+ price4h: "p4h",
175
+ openInUsd4h: "oiu4h",
176
+ closeInUsd4h: "ciu4h",
177
+ buys24h: "b24h",
178
+ sells24h: "s24h",
179
+ buyers24h: "be24h",
180
+ sellers24h: "se24h",
181
+ buyVolumeInUsd24h: "bviu24h",
182
+ sellVolumeInUsd24h: "sviu24h",
183
+ price24h: "p24h",
184
+ price: "p",
185
+ openInUsd24h: "oiu24h",
186
+ closeInUsd24h: "ciu24h"
187
+ },
188
+ // Token holder subscription fields
189
+ subscribeTokenHolders: {
190
+ tokenAddress: "a",
191
+ holders: "h",
192
+ top100HoldersAmount: "t100a",
193
+ top50HoldersAmount: "t50a",
194
+ top10HoldersAmount: "t10a",
195
+ top100Holders: "t100h",
196
+ top50Holders: "t50h",
197
+ top10Holders: "t10h",
198
+ top100HoldersRatio: "t100r",
199
+ top50HoldersRatio: "t50r",
200
+ top10HoldersRatio: "t10r",
201
+ creatorsHolders: "ch",
202
+ creatorsAmount: "ca",
203
+ creatorsRatio: "cr",
204
+ balanceTagFreshHolders: "btfh",
205
+ balanceTagFreshAmount: "btfa",
206
+ balanceTagFreshRatio: "btfr",
207
+ balanceTagSandwichHolders: "btsh",
208
+ balanceTagSandwichAmount: "btsa",
209
+ balanceTagSandwichRatio: "btsr",
210
+ balanceTagBundleHolders: "btbh",
211
+ balanceTagBundleAmount: "btba",
212
+ balanceTagBundleRatio: "btbr",
213
+ balanceTagSniperHolders: "btsnh",
214
+ balanceTagSniperAmount: "btsna",
215
+ balanceTagSniperRatio: "btsnr",
216
+ balanceTagDevHolders: "btdh",
217
+ balanceTagDevAmount: "btda",
218
+ balanceTagDevRatio: "btdr",
219
+ balanceTagProHolders: "btph",
220
+ balanceTagProAmount: "btpa",
221
+ balanceTagProRatio: "btpr",
222
+ balanceTagInsiderHolders: "btih",
223
+ balanceTagInsiderAmount: "btia",
224
+ balanceTagInsiderRatio: "btir",
225
+ balanceTagSmartHolders: "btsmh",
226
+ balanceTagSmartAmount: "btsma",
227
+ balanceTagSmartRatio: "btsmr",
228
+ balanceTagKolHolders: "btkh",
229
+ balanceTagKolAmount: "btka",
230
+ balanceTagKolRatio: "btkr",
231
+ balanceTagPhishingHolders: "btphh",
232
+ balanceTagPhishingAmount: "btpha",
233
+ balanceTagPhishingRatio: "btphr",
234
+ balanceTagBluechipHolders: "btblh",
235
+ balanceTagBluechipAmount: "btbla",
236
+ balanceTagBluechipRatio: "btblr",
237
+ balanceTagRatHolders: "btrh",
238
+ balanceTagRatAmount: "btra",
239
+ balanceTagRatRatio: "btrr",
240
+ timestamp: "ts"
241
+ },
242
+ // New token subscription fields
243
+ subscribeNewToken: {
244
+ tokenAddress: "a",
245
+ name: "n",
246
+ symbol: "s",
247
+ createdAtMs: "cts"
248
+ },
249
+ // Token supply subscription fields
250
+ subscribeTokenSupply: {
251
+ tokenAddress: "a",
252
+ supply: "s",
253
+ timestamp: "ts"
254
+ },
255
+ // Dex pool balance subscription fields
256
+ subscribeDexPoolBalance: {
257
+ poolAddress: "a",
258
+ tokenAAddress: "taa",
259
+ tokenALiquidityInUsd: "taliu",
260
+ tokenBAddress: "tba",
261
+ tokenBLiquidityInUsd: "tbliu"
262
+ },
263
+ // Token liquidity subscription fields
264
+ subscribeTokenLiquidity: {
265
+ tokenAddress: "a",
266
+ metricType: "t",
267
+ value: "v",
268
+ timestamp: "ts"
269
+ },
270
+ // New token metadata subscription fields
271
+ subscribeNewTokensMetadata: {
272
+ tokenAddress: "a",
273
+ name: "n",
274
+ symbol: "s",
275
+ imageUrl: "iu",
276
+ description: "de",
277
+ socialMedia: "sm",
278
+ createdAtMs: "cts"
279
+ },
280
+ // Token trades subscription fields
281
+ subscribeTokenTrades: {
282
+ tokenAddress: "a",
283
+ timestamp: "t",
284
+ kind: "k",
285
+ buyAmount: "ba",
286
+ buyAmountInUsd: "baiu",
287
+ buyTokenAddress: "btma",
288
+ buyTokenName: "btn",
289
+ buyTokenSymbol: "bts",
290
+ buyWalletAddress: "bwa",
291
+ sellAmount: "sa",
292
+ sellAmountInUsd: "saiu",
293
+ sellTokenAddress: "stma",
294
+ sellTokenName: "stn",
295
+ sellTokenSymbol: "sts",
296
+ sellWalletAddress: "swa",
297
+ txHash: "h"
298
+ },
299
+ // Wallet token PnL subscription fields
300
+ subscribeWalletPnl: {
301
+ walletAddress: "a",
302
+ tokenAddress: "ta",
303
+ tokenPriceInUsd: "tpiu",
304
+ timestamp: "t",
305
+ opentime: "ot",
306
+ lasttime: "lt",
307
+ closetime: "ct",
308
+ buyAmount: "ba",
309
+ buyAmountInUsd: "baiu",
310
+ buyCount: "bs",
311
+ buyCount30d: "bs30d",
312
+ buyCount7d: "bs7d",
313
+ sellAmount: "sa",
314
+ sellAmountInUsd: "saiu",
315
+ sellCount: "ss",
316
+ sellCount30d: "ss30d",
317
+ sellCount7d: "ss7d",
318
+ heldDurationTimestamp: "hdts",
319
+ averageBuyPriceInUsd: "abpiu",
320
+ averageSellPriceInUsd: "aspiu",
321
+ unrealizedProfitInUsd: "upiu",
322
+ unrealizedProfitRatio: "upr",
323
+ realizedProfitInUsd: "rpiu",
324
+ realizedProfitRatio: "rpr",
325
+ totalRealizedProfitInUsd: "trpiu",
326
+ totalRealizedProfitRatio: "trr"
327
+ },
328
+ // Token max liquidity subscription fields
329
+ subscribeTokenMaxLiquidity: {
330
+ tokenAddress: "a",
331
+ poolAddress: "p",
332
+ liquidityInUsd: "liu",
333
+ liquidityInNative: "lin",
334
+ timestamp: "ts"
335
+ },
336
+ // Token total liquidity subscription fields
337
+ subscribeTokenTotalLiquidity: {
338
+ tokenAddress: "a",
339
+ liquidityInUsd: "liu",
340
+ liquidityInNative: "lin",
341
+ poolCount: "pc",
342
+ timestamp: "ts"
343
+ }
344
+ };
345
+ function getFieldMappings(methodName) {
346
+ return CEL_FIELD_MAPPINGS[methodName] || {};
347
+ }
348
+ function replaceFilterFields(filter, methodName) {
349
+ if (!filter) {
350
+ return filter;
351
+ }
352
+ const fieldMappings = getFieldMappings(methodName);
353
+ let result = filter;
354
+ for (const [longField, shortField] of Object.entries(fieldMappings)) {
355
+ const patterns = [
356
+ // Pattern 1: fieldName (without meta. prefix)
357
+ new RegExp(`\\b${longField}\\b`, "g"),
358
+ // Pattern 2: meta.fieldName (with meta. prefix)
359
+ new RegExp(`\\bmeta\\.${longField}\\b`, "g")
360
+ ];
361
+ patterns.forEach((pattern) => {
362
+ result = result.replace(pattern, `meta.${shortField}`);
363
+ });
364
+ }
365
+ return result;
366
+ }
367
+
368
+ // src/stream/stream.ts
369
+ var StreamApi = class {
370
+ constructor(context) {
371
+ __publicField(this, "realtimeClient");
372
+ __publicField(this, "listenersMap");
373
+ __publicField(this, "context");
374
+ __publicField(this, "initPromise", null);
375
+ this.context = context;
376
+ this.listenersMap = /* @__PURE__ */ new Map();
377
+ }
378
+ /**
379
+ * Initialize Centrifuge client with current token
380
+ * This is called lazily when connect() is called
381
+ */
382
+ async initClient() {
383
+ if (this.realtimeClient) {
384
+ return;
385
+ }
386
+ const token = await this.getTokenValue();
387
+ const realtimeEndpoint = this.buildWsUrl(this.context.streamUrl, token);
388
+ this.realtimeClient = new Centrifuge(realtimeEndpoint, {
389
+ getToken: async (_ctx) => {
390
+ return this.getTokenValue();
391
+ }
392
+ });
393
+ this.realtimeClient.on("connected", () => {
394
+ console.log("[streaming] connected");
395
+ }).on("disconnected", (ctx) => {
396
+ console.warn("[streaming] disconnected", ctx);
397
+ }).on("error", (err) => {
398
+ console.error("[streaming] error: ", err);
399
+ });
400
+ }
401
+ /**
402
+ * Wait for initialization to complete
403
+ * If not initialized, auto-connect first
404
+ */
405
+ async ensureInitialized() {
406
+ if (!this.initPromise) {
407
+ this.connect();
408
+ }
409
+ await this.initPromise;
410
+ }
411
+ /**
412
+ * Get token value from string or TokenProvider
413
+ */
414
+ async getTokenValue() {
415
+ return typeof this.context.accessToken === "string" ? this.context.accessToken : await this.context.accessToken.getToken();
416
+ }
417
+ /**
418
+ * Build WebSocket URL with token as query parameter
419
+ */
420
+ buildWsUrl(endpoint, token) {
421
+ const url = new URL(endpoint);
422
+ url.searchParams.set("token", token);
423
+ return url.toString();
424
+ }
425
+ /**
426
+ * Connect to the WebSocket server.
427
+ * This is automatically called when you use subscribe methods if not already connected.
428
+ * You can also call this method manually for explicit control.
429
+ */
430
+ connect() {
431
+ this.initPromise = this.initClient().then(() => {
432
+ this.realtimeClient.connect();
433
+ });
434
+ }
435
+ /**
436
+ * Disconnect from the WebSocket server.
437
+ * All subscriptions will be automatically removed.
438
+ */
439
+ disconnect() {
440
+ if (this.realtimeClient) {
441
+ this.realtimeClient.disconnect();
442
+ }
443
+ }
444
+ /**
445
+ * Check if the WebSocket is currently connected.
446
+ */
447
+ isConnected() {
448
+ return this.realtimeClient?.state === "connected";
449
+ }
450
+ /**
451
+ * Start batching commands for efficient bulk operations
452
+ * All subscription commands after this call will be batched until stopBatching is called
453
+ */
454
+ startBatching() {
455
+ if (this.realtimeClient) {
456
+ this.realtimeClient.startBatching();
457
+ }
458
+ }
459
+ /**
460
+ * Stop batching and flush all collected commands to the server
461
+ * This will send all batched subscription commands in a single network request
462
+ */
463
+ stopBatching() {
464
+ if (this.realtimeClient) {
465
+ this.realtimeClient.stopBatching();
466
+ }
467
+ }
468
+ /**
469
+ * Batch subscribe method that accepts a function containing subscription calls
470
+ * All subscription methods called within the function will be batched
471
+ * @param batchFunction Function containing subscription method calls
472
+ * @returns Array of unsubscribe functions
473
+ */
474
+ batchSubscribe(batchFunction) {
475
+ this.startBatching();
476
+ const unsubscribables = batchFunction();
477
+ this.stopBatching();
478
+ return unsubscribables;
479
+ }
480
+ /**
481
+ * Batch unsubscribe method that accepts an array of unsubscribe functions
482
+ * All unsubscribe calls will be executed at once
483
+ * @param unsubscribables Array of unsubscribe functions to execute
484
+ */
485
+ batchUnsubscribe(unsubscribables) {
486
+ if (!unsubscribables || unsubscribables.length === 0) {
487
+ return;
488
+ }
489
+ unsubscribables.forEach((unsub) => {
490
+ if (unsub && typeof unsub.unsubscribe === "function") {
491
+ unsub.unsubscribe();
492
+ }
493
+ });
494
+ }
495
+ subscribe(channel, fn, filter, methodName) {
496
+ let listeners = this.listenersMap.get(channel);
497
+ if (!listeners) {
498
+ listeners = /* @__PURE__ */ new Set();
499
+ this.listenersMap.set(channel, listeners);
500
+ }
501
+ listeners.add(fn);
502
+ this.ensureInitialized().then(() => {
503
+ let sub = this.realtimeClient.getSubscription(channel);
504
+ if (!sub) {
505
+ console.log("[xrealtime] create new sub: ", channel);
506
+ const processedFilter = filter && methodName ? replaceFilterFields(filter, methodName) : filter;
507
+ sub = this.realtimeClient.newSubscription(channel, {
508
+ delta: "fossil",
509
+ ...processedFilter && { filter: processedFilter }
510
+ });
511
+ sub.on("subscribed", () => {
512
+ console.log("[xrealtime] subscribed", channel);
513
+ }).on("unsubscribed", () => {
514
+ console.log("[xrealtime] unsubscribed", channel);
515
+ }).on("publication", (ctx) => {
516
+ const currentListeners = this.listenersMap.get(channel);
517
+ currentListeners?.forEach((it) => it(ctx.data));
518
+ }).subscribe();
519
+ }
520
+ });
521
+ return new StreamUnsubscribable(this, channel, fn);
522
+ }
523
+ unsubscribe(channel, fn) {
524
+ const listeners = this.listenersMap.get(channel);
525
+ if (!listeners) {
526
+ return;
527
+ }
528
+ listeners.delete(fn);
529
+ console.log("unsubscribe, remain listeners: ", listeners.size);
530
+ if (listeners.size === 0) {
531
+ console.log("unsubscribe channel: ", channel);
532
+ this.listenersMap.delete(channel);
533
+ this.ensureInitialized().then(() => {
534
+ const sub = this.realtimeClient.getSubscription(channel);
535
+ if (sub) {
536
+ sub.unsubscribe();
537
+ this.realtimeClient.removeSubscription(sub);
538
+ }
539
+ });
540
+ }
541
+ }
542
+ formatScientificNotation(value) {
543
+ if (value === null || value === void 0) {
544
+ return "0";
545
+ }
546
+ const strValue = value.toString();
547
+ if (strValue.includes("e-") || strValue.includes("E-")) {
548
+ return Number(value).toFixed(20).replace(/\.?0+$/, "");
549
+ }
550
+ return strValue;
551
+ }
552
+ subscribeTokenCandles({
553
+ chain,
554
+ tokenAddress,
555
+ resolution,
556
+ callback,
557
+ filter
558
+ }) {
559
+ const channel = `dex-candle:${chain}_${tokenAddress}_${resolution}`;
560
+ return this.subscribe(
561
+ channel,
562
+ (data) => {
563
+ callback({
564
+ open: data.o,
565
+ close: data.c,
566
+ high: data.h,
567
+ low: data.l,
568
+ volume: data.v,
569
+ resolution: data.r,
570
+ time: data.t,
571
+ number: data.n
572
+ });
573
+ },
574
+ filter,
575
+ "subscribeTokenCandles"
576
+ );
577
+ }
578
+ subscribeTokenStats({
579
+ chain,
580
+ tokenAddress,
581
+ callback,
582
+ filter
583
+ }) {
584
+ const channel = `dex-token-stats:${chain}_${tokenAddress}`;
585
+ return this.subscribe(
586
+ channel,
587
+ (data) => callback({
588
+ address: data.a,
589
+ timestamp: data.t,
590
+ buys1m: data.b1m,
591
+ sells1m: data.s1m,
592
+ buyers1m: data.be1m,
593
+ sellers1m: data.se1m,
594
+ buyVolumeInUsd1m: this.formatScientificNotation(data.bviu1m),
595
+ sellVolumeInUsd1m: this.formatScientificNotation(data.sviu1m),
596
+ price1m: this.formatScientificNotation(data.p1m),
597
+ openInUsd1m: this.formatScientificNotation(data.oiu1m),
598
+ closeInUsd1m: this.formatScientificNotation(data.ciu1m),
599
+ buys5m: data.b5m,
600
+ sells5m: data.s5m,
601
+ buyers5m: data.be5m,
602
+ sellers5m: data.se5m,
603
+ buyVolumeInUsd5m: this.formatScientificNotation(data.bviu5m),
604
+ sellVolumeInUsd5m: this.formatScientificNotation(data.sviu5m),
605
+ price5m: this.formatScientificNotation(data.p5m),
606
+ openInUsd5m: this.formatScientificNotation(data.oiu5m),
607
+ closeInUsd5m: this.formatScientificNotation(data.ciu5m),
608
+ buys15m: data.b15m,
609
+ sells15m: data.s15m,
610
+ buyers15m: data.be15m,
611
+ sellers15m: data.se15m,
612
+ buyVolumeInUsd15m: this.formatScientificNotation(data.bviu15m),
613
+ sellVolumeInUsd15m: this.formatScientificNotation(data.sviu15m),
614
+ price15m: this.formatScientificNotation(data.p15m),
615
+ openInUsd15m: this.formatScientificNotation(data.oiu15m),
616
+ closeInUsd15m: this.formatScientificNotation(data.ciu15m),
617
+ buys30m: data.b30m,
618
+ sells30m: data.s30m,
619
+ buyers30m: data.be30m,
620
+ sellers30m: data.se30m,
621
+ buyVolumeInUsd30m: this.formatScientificNotation(data.bviu30m),
622
+ sellVolumeInUsd30m: this.formatScientificNotation(data.sviu30m),
623
+ price30m: this.formatScientificNotation(data.p30m),
624
+ openInUsd30m: this.formatScientificNotation(data.oiu30m),
625
+ closeInUsd30m: this.formatScientificNotation(data.ciu30m),
626
+ buys1h: data.b1h,
627
+ sells1h: data.s1h,
628
+ buyers1h: data.be1h,
629
+ sellers1h: data.se1h,
630
+ buyVolumeInUsd1h: this.formatScientificNotation(data.bviu1h),
631
+ sellVolumeInUsd1h: this.formatScientificNotation(data.sviu1h),
632
+ price1h: this.formatScientificNotation(data.p1h),
633
+ openInUsd1h: this.formatScientificNotation(data.oiu1h),
634
+ closeInUsd1h: this.formatScientificNotation(data.ciu1h),
635
+ buys4h: data.b4h,
636
+ sells4h: data.s4h,
637
+ buyers4h: data.be4h,
638
+ sellers4h: data.se4h,
639
+ buyVolumeInUsd4h: this.formatScientificNotation(data.bviu4h),
640
+ sellVolumeInUsd4h: this.formatScientificNotation(data.sviu4h),
641
+ price4h: this.formatScientificNotation(data.p4h),
642
+ openInUsd4h: this.formatScientificNotation(data.oiu4h),
643
+ closeInUsd4h: this.formatScientificNotation(data.ciu4h),
644
+ buys24h: data.b24h,
645
+ sells24h: data.s24h,
646
+ buyers24h: data.be24h,
647
+ sellers24h: data.se24h,
648
+ buyVolumeInUsd24h: this.formatScientificNotation(data.bviu24h),
649
+ sellVolumeInUsd24h: this.formatScientificNotation(data.sviu24h),
650
+ price24h: this.formatScientificNotation(data.p24h),
651
+ openInUsd24h: this.formatScientificNotation(data.oiu24h),
652
+ closeInUsd24h: this.formatScientificNotation(data.ciu24h),
653
+ price: this.formatScientificNotation(data.p)
654
+ }),
655
+ filter,
656
+ "subscribeTokenStats"
657
+ );
658
+ }
659
+ subscribeTokenHolders({
660
+ chain,
661
+ tokenAddress,
662
+ callback,
663
+ filter
664
+ }) {
665
+ const channel = `dex-token-holding:${chain}_${tokenAddress}`;
666
+ return this.subscribe(
667
+ channel,
668
+ (data) => callback({
669
+ tokenAddress: data.a,
670
+ holders: data.h,
671
+ top100HoldersAmount: this.formatScientificNotation(data.t100a),
672
+ top50HoldersAmount: this.formatScientificNotation(data.t50a),
673
+ top10HoldersAmount: this.formatScientificNotation(data.t10a),
674
+ top100Holders: data.t100h,
675
+ top50Holders: data.t50h,
676
+ top10Holders: data.t10h,
677
+ top100HoldersRatio: this.formatScientificNotation(data.t100r),
678
+ top50HoldersRatio: this.formatScientificNotation(data.t50r),
679
+ top10HoldersRatio: this.formatScientificNotation(data.t10r),
680
+ creatorsHolders: data.ch,
681
+ creatorsAmount: this.formatScientificNotation(data.ca),
682
+ creatorsRatio: this.formatScientificNotation(data.cr),
683
+ balanceTagFreshHolders: data.btfh,
684
+ balanceTagFreshAmount: this.formatScientificNotation(data.btfa),
685
+ balanceTagFreshRatio: this.formatScientificNotation(data.btfr),
686
+ balanceTagSandwichHolders: data.btsh,
687
+ balanceTagSandwichAmount: this.formatScientificNotation(data.btsa),
688
+ balanceTagSandwichRatio: this.formatScientificNotation(data.btsr),
689
+ balanceTagBundleHolders: data.btbh,
690
+ balanceTagBundleAmount: this.formatScientificNotation(data.btba),
691
+ balanceTagBundleRatio: this.formatScientificNotation(data.btbr),
692
+ balanceTagSniperHolders: data.btsnh,
693
+ balanceTagSniperAmount: this.formatScientificNotation(data.btsna),
694
+ balanceTagSniperRatio: this.formatScientificNotation(data.btsnr),
695
+ balanceTagDevHolders: data.btdh,
696
+ balanceTagDevAmount: this.formatScientificNotation(data.btda),
697
+ balanceTagDevRatio: this.formatScientificNotation(data.btdr),
698
+ balanceTagProHolders: data.btph,
699
+ balanceTagProAmount: this.formatScientificNotation(data.btpa),
700
+ balanceTagProRatio: this.formatScientificNotation(data.btpr),
701
+ balanceTagInsiderHolders: data.btih,
702
+ balanceTagInsiderAmount: this.formatScientificNotation(data.btia),
703
+ balanceTagInsiderRatio: this.formatScientificNotation(data.btir),
704
+ balanceTagSmartHolders: data.btsmh,
705
+ balanceTagSmartAmount: this.formatScientificNotation(data.btsma),
706
+ balanceTagSmartRatio: this.formatScientificNotation(data.btsmr),
707
+ balanceTagKolHolders: data.btkh,
708
+ balanceTagKolAmount: this.formatScientificNotation(data.btka),
709
+ balanceTagKolRatio: this.formatScientificNotation(data.btkr),
710
+ balanceTagPhishingHolders: data.btphh,
711
+ balanceTagPhishingAmount: this.formatScientificNotation(data.btpha),
712
+ balanceTagPhishingRatio: this.formatScientificNotation(data.btphr),
713
+ balanceTagBluechipHolders: data.btblh,
714
+ balanceTagBluechipAmount: this.formatScientificNotation(data.btbla),
715
+ balanceTagBluechipRatio: this.formatScientificNotation(data.btblr),
716
+ balanceTagRatHolders: data.btrh,
717
+ balanceTagRatAmount: this.formatScientificNotation(data.btra),
718
+ balanceTagRatRatio: this.formatScientificNotation(data.btrr),
719
+ timestamp: data.ts
720
+ }),
721
+ filter,
722
+ "subscribeTokenHolders"
723
+ );
724
+ }
725
+ subscribeNewToken({
726
+ chain,
727
+ callback,
728
+ filter
729
+ }) {
730
+ const channel = `dex-new-token:${chain}`;
731
+ return this.subscribe(
732
+ channel,
733
+ (data) => {
734
+ const result = {
735
+ tokenAddress: data.a,
736
+ name: data.n,
737
+ symbol: data.s,
738
+ createdAtMs: data.cts
739
+ };
740
+ if (data.dec) {
741
+ result.decimals = data.dec;
742
+ }
743
+ if (data.lf) {
744
+ const lf = data.lf;
745
+ result.launchFrom = {};
746
+ if (lf.pa) {
747
+ result.launchFrom.programAddress = lf.pa;
748
+ }
749
+ if (lf.pf) {
750
+ result.launchFrom.protocolFamily = lf.pf;
751
+ }
752
+ if (lf.pn) {
753
+ result.launchFrom.protocolName = lf.pn;
754
+ }
755
+ }
756
+ callback(result);
757
+ },
758
+ filter,
759
+ "subscribeNewToken"
760
+ );
761
+ }
762
+ subscribeNewTokensMetadata({
763
+ chain,
764
+ callback
765
+ }) {
766
+ const channel = `dex-new-tokens-metadata:${chain}`;
767
+ return this.subscribe(
768
+ channel,
769
+ (data) => callback(
770
+ data.map((it) => ({
771
+ tokenAddress: it.a,
772
+ name: it.n,
773
+ symbol: it.s,
774
+ imageUrl: it.iu,
775
+ description: it.de,
776
+ socialMedia: (() => {
777
+ const sm = it.sm;
778
+ if (!sm) return void 0;
779
+ return {
780
+ twitter: sm.tw,
781
+ telegram: sm.tg,
782
+ website: sm.w,
783
+ tiktok: sm.tt,
784
+ discord: sm.dc,
785
+ facebook: sm.fb,
786
+ github: sm.gh,
787
+ instagram: sm.ig,
788
+ linkedin: sm.li,
789
+ medium: sm.md,
790
+ reddit: sm.rd,
791
+ youtube: sm.yt,
792
+ bitbucket: sm.bb
793
+ };
794
+ })(),
795
+ createdAtMs: it.cts
796
+ }))
797
+ )
798
+ );
799
+ }
800
+ subscribeTokenSupply({
801
+ chain,
802
+ tokenAddress,
803
+ callback,
804
+ filter
805
+ }) {
806
+ const channel = `dex-token-supply:${chain}_${tokenAddress}`;
807
+ return this.subscribe(
808
+ channel,
809
+ (data) => callback({
810
+ tokenAddress: data.a,
811
+ supply: data.s,
812
+ marketCapInUsd: data.mc,
813
+ timestamp: data.ts
814
+ }),
815
+ filter,
816
+ "subscribeTokenSupply"
817
+ );
818
+ }
819
+ subscribeTokenLiquidity({
820
+ chain,
821
+ tokenAddress,
822
+ callback,
823
+ filter
824
+ }) {
825
+ const channel = `dex-token-general-stat-num:${chain}_${tokenAddress}`;
826
+ return this.subscribe(
827
+ channel,
828
+ (data) => callback({
829
+ tokenAddress: data.a,
830
+ metricType: data.t,
831
+ value: data.v,
832
+ timestamp: data.ts
833
+ }),
834
+ filter,
835
+ "subscribeTokenLiquidity"
836
+ );
837
+ }
838
+ /**
839
+ * Subscribe to token max liquidity updates
840
+ * Pushes the max liquidity info of a token in a single pool
841
+ * Channel: dex-token-liquidity:{chain}_{token_address}
842
+ */
843
+ subscribeTokenMaxLiquidity({
844
+ chain,
845
+ tokenAddress,
846
+ callback,
847
+ filter
848
+ }) {
849
+ const channel = `dex-token-liquidity:${chain}_${tokenAddress}`;
850
+ return this.subscribe(
851
+ channel,
852
+ (data) => callback({
853
+ tokenAddress: data.a,
854
+ poolAddress: data.p,
855
+ liquidityInUsd: data.liu,
856
+ liquidityInNative: data.lin,
857
+ timestamp: data.ts
858
+ }),
859
+ filter,
860
+ "subscribeTokenMaxLiquidity"
861
+ );
862
+ }
863
+ /**
864
+ * Subscribe to token total liquidity updates
865
+ * Pushes the total liquidity info of a token across all pools
866
+ * Channel: dex-token-total-liquidity:{chain}_{token_address}
867
+ */
868
+ subscribeTokenTotalLiquidity({
869
+ chain,
870
+ tokenAddress,
871
+ callback,
872
+ filter
873
+ }) {
874
+ const channel = `dex-token-total-liquidity:${chain}_${tokenAddress}`;
875
+ return this.subscribe(
876
+ channel,
877
+ (data) => callback({
878
+ tokenAddress: data.a,
879
+ liquidityInUsd: data.liu,
880
+ liquidityInNative: data.lin,
881
+ poolCount: data.pc,
882
+ timestamp: data.ts
883
+ }),
884
+ filter,
885
+ "subscribeTokenTotalLiquidity"
886
+ );
887
+ }
888
+ subscribeRankingTokensLiquidity({
889
+ chain,
890
+ channelType,
891
+ callback
892
+ }) {
893
+ const channel = `dex-ranking-token-general_stat_num-list:${chain}_${channelType}`;
894
+ return this.subscribe(
895
+ channel,
896
+ (data) => callback(
897
+ data?.map((it) => ({
898
+ tokenAddress: it.a,
899
+ metricType: it.t,
900
+ value: it.v,
901
+ timestamp: it.ts
902
+ }))
903
+ )
904
+ );
905
+ }
906
+ subscribeRankingTokensList({
907
+ chain,
908
+ ranking_type,
909
+ dex,
910
+ callback
911
+ }) {
912
+ const channel = dex ? `dex-ranking-list:${chain}_${ranking_type}_${dex}` : `dex-ranking-list:${chain}_${ranking_type}`;
913
+ return this.subscribe(
914
+ channel,
915
+ (data) => callback(
916
+ data?.map((item) => {
917
+ const result = {};
918
+ const t = item.t;
919
+ const bc = item.bc;
920
+ const h = item.h;
921
+ const s = item.s;
922
+ const ts = item.ts;
923
+ if (t) {
924
+ result.metadata = {
925
+ tokenAddress: t.a
926
+ };
927
+ if (t.n) {
928
+ result.metadata.name = t.n;
929
+ }
930
+ if (t.s) {
931
+ result.metadata.symbol = t.s;
932
+ }
933
+ if (t.iu) {
934
+ result.metadata.imageUrl = t.iu;
935
+ }
936
+ if (t.de) {
937
+ result.metadata.description = t.de;
938
+ }
939
+ if (t.dec) {
940
+ result.metadata.decimals = t.dec;
941
+ }
942
+ if (t.cts) {
943
+ result.metadata.createdAtMs = t.cts;
944
+ }
945
+ if (t.lf) {
946
+ const lf = t.lf;
947
+ result.metadata.launchFrom = {};
948
+ if (lf.pa) {
949
+ result.metadata.launchFrom.programAddress = lf.pa;
950
+ }
951
+ if (lf.pf) {
952
+ result.metadata.launchFrom.protocolFamily = lf.pf;
953
+ }
954
+ if (lf.pn) {
955
+ result.metadata.launchFrom.protocolName = lf.pn;
956
+ }
957
+ }
958
+ if (t.mt) {
959
+ const mt = t.mt;
960
+ result.metadata.migratedTo = {};
961
+ if (mt.pa) {
962
+ result.metadata.migratedTo.programAddress = mt.pa;
963
+ }
964
+ if (mt.pf) {
965
+ result.metadata.migratedTo.protocolFamily = mt.pf;
966
+ }
967
+ if (mt.pn) {
968
+ result.metadata.migratedTo.protocolName = mt.pn;
969
+ }
970
+ }
971
+ if (t.sm) {
972
+ const sm = t.sm;
973
+ result.metadata.socialMedia = {};
974
+ if (sm.tw) {
975
+ result.metadata.socialMedia.twitter = sm.tw;
976
+ }
977
+ if (sm.tg) {
978
+ result.metadata.socialMedia.telegram = sm.tg;
979
+ }
980
+ if (sm.w) {
981
+ result.metadata.socialMedia.website = sm.w;
982
+ }
983
+ if (sm.tt) {
984
+ result.metadata.socialMedia.tiktok = sm.tt;
985
+ }
986
+ if (sm.dc) {
987
+ result.metadata.socialMedia.discord = sm.dc;
988
+ }
989
+ if (sm.fb) {
990
+ result.metadata.socialMedia.facebook = sm.fb;
991
+ }
992
+ if (sm.gh) {
993
+ result.metadata.socialMedia.github = sm.gh;
994
+ }
995
+ if (sm.ig) {
996
+ result.metadata.socialMedia.instagram = sm.ig;
997
+ }
998
+ if (sm.li) {
999
+ result.metadata.socialMedia.linkedin = sm.li;
1000
+ }
1001
+ if (sm.md) {
1002
+ result.metadata.socialMedia.medium = sm.md;
1003
+ }
1004
+ if (sm.rd) {
1005
+ result.metadata.socialMedia.reddit = sm.rd;
1006
+ }
1007
+ if (sm.yt) {
1008
+ result.metadata.socialMedia.youtube = sm.yt;
1009
+ }
1010
+ if (sm.bb) {
1011
+ result.metadata.socialMedia.bitbucket = sm.bb;
1012
+ }
1013
+ }
1014
+ }
1015
+ if (bc) {
1016
+ result.bondingCurve = {};
1017
+ if (bc.pr) {
1018
+ result.bondingCurve.progressRatio = this.formatScientificNotation(bc.pr);
1019
+ }
1020
+ }
1021
+ if (h) {
1022
+ result.holder = {
1023
+ tokenAddress: h.a,
1024
+ timestamp: h.ts || 0
1025
+ };
1026
+ if (h.h) {
1027
+ result.holder.holders = h.h;
1028
+ }
1029
+ if (h.t100a) {
1030
+ result.holder.top100HoldersAmount = this.formatScientificNotation(h.t100a);
1031
+ }
1032
+ if (h.t50a) {
1033
+ result.holder.top50HoldersAmount = this.formatScientificNotation(h.t50a);
1034
+ }
1035
+ if (h.t10a) {
1036
+ result.holder.top10HoldersAmount = this.formatScientificNotation(h.t10a);
1037
+ }
1038
+ if (h.t100h) {
1039
+ result.holder.top100Holders = h.t100h;
1040
+ }
1041
+ if (h.t50h) {
1042
+ result.holder.top50Holders = h.t50h;
1043
+ }
1044
+ if (h.t10h) {
1045
+ result.holder.top10Holders = h.t10h;
1046
+ }
1047
+ if (h.t100r) {
1048
+ result.holder.top100HoldersRatio = this.formatScientificNotation(h.t100r);
1049
+ }
1050
+ if (h.t50r) {
1051
+ result.holder.top50HoldersRatio = this.formatScientificNotation(h.t50r);
1052
+ }
1053
+ if (h.t10r) {
1054
+ result.holder.top10HoldersRatio = this.formatScientificNotation(h.t10r);
1055
+ }
1056
+ }
1057
+ if (s) {
1058
+ result.supply = {
1059
+ tokenAddress: s.a,
1060
+ timestamp: s.ts || 0
1061
+ };
1062
+ if (s.s) {
1063
+ result.supply.supply = s.s;
1064
+ }
1065
+ if (s.mc) {
1066
+ result.supply.marketCapInUsd = s.mc;
1067
+ }
1068
+ }
1069
+ if (ts) {
1070
+ result.stat = {
1071
+ address: ts.a,
1072
+ timestamp: ts.t || 0
1073
+ };
1074
+ if (ts.b1m) {
1075
+ result.stat.buys1m = ts.b1m;
1076
+ }
1077
+ if (ts.s1m) {
1078
+ result.stat.sells1m = ts.s1m;
1079
+ }
1080
+ if (ts.be1m) {
1081
+ result.stat.buyers1m = ts.be1m;
1082
+ }
1083
+ if (ts.se1m) {
1084
+ result.stat.sellers1m = ts.se1m;
1085
+ }
1086
+ if (ts.bviu1m) {
1087
+ result.stat.buyVolumeInUsd1m = this.formatScientificNotation(ts.bviu1m);
1088
+ }
1089
+ if (ts.sviu1m) {
1090
+ result.stat.sellVolumeInUsd1m = this.formatScientificNotation(ts.sviu1m);
1091
+ }
1092
+ if (ts.p1m) {
1093
+ result.stat.price1m = this.formatScientificNotation(ts.p1m);
1094
+ }
1095
+ if (ts.p) {
1096
+ result.stat.price = this.formatScientificNotation(ts.p);
1097
+ }
1098
+ }
1099
+ return result;
1100
+ })
1101
+ )
1102
+ );
1103
+ }
1104
+ subscribeRankingTokensStats({
1105
+ chain,
1106
+ channelType,
1107
+ callback
1108
+ }) {
1109
+ const channel = `dex-ranking-token-stats-list:${chain}_${channelType}`;
1110
+ return this.subscribe(
1111
+ channel,
1112
+ (data) => callback(
1113
+ data?.map(
1114
+ (it) => ({
1115
+ address: it.a,
1116
+ timestamp: it.t,
1117
+ buys1m: it.b1m,
1118
+ sells1m: it.s1m,
1119
+ buyers1m: it.be1m,
1120
+ sellers1m: it.se1m,
1121
+ buyVolumeInUsd1m: this.formatScientificNotation(it.bviu1m),
1122
+ sellVolumeInUsd1m: this.formatScientificNotation(it.sviu1m),
1123
+ price1m: this.formatScientificNotation(it.p1m),
1124
+ openInUsd1m: this.formatScientificNotation(it.oiu1m),
1125
+ closeInUsd1m: this.formatScientificNotation(it.ciu1m),
1126
+ buys5m: it.b5m,
1127
+ sells5m: it.s5m,
1128
+ buyers5m: it.be5m,
1129
+ sellers5m: it.se5m,
1130
+ buyVolumeInUsd5m: this.formatScientificNotation(it.bviu5m),
1131
+ sellVolumeInUsd5m: this.formatScientificNotation(it.sviu5m),
1132
+ price5m: this.formatScientificNotation(it.p5m),
1133
+ openInUsd5m: this.formatScientificNotation(it.oiu5m),
1134
+ closeInUsd5m: this.formatScientificNotation(it.ciu5m),
1135
+ price: this.formatScientificNotation(it.p)
1136
+ })
1137
+ )
1138
+ )
1139
+ );
1140
+ }
1141
+ subscribeRankingTokensHolders({
1142
+ chain,
1143
+ channelType,
1144
+ callback
1145
+ }) {
1146
+ const channel = `dex-ranking-token-holding-list:${chain}_${channelType}`;
1147
+ return this.subscribe(
1148
+ channel,
1149
+ (data) => callback(
1150
+ data?.map(
1151
+ (it) => ({
1152
+ tokenAddress: it.a,
1153
+ holders: it.h,
1154
+ top100HoldersAmount: this.formatScientificNotation(it.t100a),
1155
+ top50HoldersAmount: this.formatScientificNotation(it.t50a),
1156
+ top10HoldersAmount: this.formatScientificNotation(it.t10a),
1157
+ top100Holders: it.t100h,
1158
+ top50Holders: it.t50h,
1159
+ top10Holders: it.t10h,
1160
+ top100HoldersRatio: this.formatScientificNotation(it.t100r),
1161
+ top50HoldersRatio: this.formatScientificNotation(it.t50r),
1162
+ top10HoldersRatio: this.formatScientificNotation(it.t10r),
1163
+ timestamp: it.ts
1164
+ })
1165
+ )
1166
+ )
1167
+ );
1168
+ }
1169
+ subscribeRankingTokensSupply({
1170
+ chain,
1171
+ channelType,
1172
+ callback
1173
+ }) {
1174
+ const channel = `dex-ranking-token-supply-list:${chain}_${channelType}`;
1175
+ return this.subscribe(
1176
+ channel,
1177
+ (data) => callback(
1178
+ data?.map((it) => ({
1179
+ tokenAddress: it.a,
1180
+ supply: it.s,
1181
+ marketCapInUsd: it.mc,
1182
+ timestamp: it.ts
1183
+ }))
1184
+ )
1185
+ );
1186
+ }
1187
+ subscribeRankingTokensBondingCurve({
1188
+ chain,
1189
+ callback
1190
+ }) {
1191
+ const channel = `dex-ranking-token-bounding-curve-list:${chain}_new`;
1192
+ return this.subscribe(
1193
+ channel,
1194
+ (data) => callback(
1195
+ data?.map((it) => ({
1196
+ tokenAddress: it.a,
1197
+ progressRatio: it.pr
1198
+ }))
1199
+ )
1200
+ );
1201
+ }
1202
+ subscribeWalletBalance({
1203
+ chain,
1204
+ walletAddress,
1205
+ callback,
1206
+ filter
1207
+ }) {
1208
+ const channel = `dex-wallet-balance:${chain}_${walletAddress}`;
1209
+ return this.subscribe(
1210
+ channel,
1211
+ (data) => callback([
1212
+ {
1213
+ walletAddress: data.a,
1214
+ tokenAddress: data.ta,
1215
+ tokenPriceInUsd: data.tpiu,
1216
+ balance: data.b,
1217
+ timestamp: data.t
1218
+ }
1219
+ ]),
1220
+ filter,
1221
+ "subscribeWalletBalance"
1222
+ );
1223
+ }
1224
+ subscribeWalletPnl({
1225
+ chain,
1226
+ walletAddress,
1227
+ callback,
1228
+ filter
1229
+ }) {
1230
+ const channel = `dex-wallet-token-pnl:${chain}_${walletAddress}`;
1231
+ return this.subscribe(
1232
+ channel,
1233
+ (data) => callback({
1234
+ walletAddress: data.a,
1235
+ tokenAddress: data.ta,
1236
+ tokenPriceInUsd: data.tpiu,
1237
+ timestamp: data.t,
1238
+ opentime: data.ot,
1239
+ lasttime: data.lt,
1240
+ closetime: data.ct,
1241
+ buyAmount: data.ba,
1242
+ buyAmountInUsd: data.baiu,
1243
+ buyCount: data.bs,
1244
+ buyCount30d: data.bs30d,
1245
+ buyCount7d: data.bs7d,
1246
+ sellAmount: data.sa,
1247
+ sellAmountInUsd: data.saiu,
1248
+ sellCount: data.ss,
1249
+ sellCount30d: data.ss30d,
1250
+ sellCount7d: data.ss7d,
1251
+ heldDurationTimestamp: data.hdts,
1252
+ averageBuyPriceInUsd: data.abpiu,
1253
+ averageSellPriceInUsd: data.aspiu,
1254
+ unrealizedProfitInUsd: data.upiu,
1255
+ unrealizedProfitRatio: data.upr,
1256
+ realizedProfitInUsd: data.rpiu,
1257
+ realizedProfitRatio: data.rpr,
1258
+ totalRealizedProfitInUsd: data.trpiu,
1259
+ totalRealizedProfitRatio: data.trr
1260
+ }),
1261
+ filter,
1262
+ "subscribeWalletPnl"
1263
+ );
1264
+ }
1265
+ subscribeWalletPnlList({
1266
+ chain,
1267
+ walletAddress,
1268
+ callback
1269
+ }) {
1270
+ const channel = `dex-wallet-pnl-list:${chain}_${walletAddress}`;
1271
+ return this.subscribe(
1272
+ channel,
1273
+ (data) => callback(
1274
+ data?.map(
1275
+ (it) => ({
1276
+ walletAddress: it.a,
1277
+ buys: it.bs,
1278
+ buyAmount: it.ba,
1279
+ buyAmountInUsd: it.baiu,
1280
+ averageBuyPriceInUsd: it.abpiu,
1281
+ sellAmount: it.sa,
1282
+ sellAmountInUsd: it.saiu,
1283
+ sells: it.ss,
1284
+ wins: it.ws,
1285
+ winRatio: it.wr,
1286
+ pnlInUsd: it.piu,
1287
+ averagePnlInUsd: it.apiu,
1288
+ pnlRatio: it.pr,
1289
+ profitableDays: it.pd,
1290
+ losingDays: it.ld,
1291
+ tokens: it.ts,
1292
+ resolution: it.r
1293
+ })
1294
+ )
1295
+ )
1296
+ );
1297
+ }
1298
+ subscribeTokenTrade({
1299
+ chain,
1300
+ tokenAddress,
1301
+ callback,
1302
+ filter
1303
+ }) {
1304
+ const channel = `dex-trade:${chain}_${tokenAddress}`;
1305
+ return this.subscribe(
1306
+ channel,
1307
+ (data) => callback({
1308
+ tokenAddress: data.a,
1309
+ timestamp: data.t,
1310
+ kind: data.k,
1311
+ buyAmount: data.ba,
1312
+ buyAmountInUsd: data.baiu,
1313
+ buyTokenAddress: data.btma,
1314
+ buyTokenName: data.btn,
1315
+ buyTokenSymbol: data.bts,
1316
+ buyWalletAddress: data.bwa,
1317
+ sellAmount: data.sa,
1318
+ sellAmountInUsd: data.saiu,
1319
+ sellTokenAddress: data.stma,
1320
+ sellTokenName: data.stn,
1321
+ sellTokenSymbol: data.sts,
1322
+ sellWalletAddress: data.swa,
1323
+ txHash: data.h
1324
+ }),
1325
+ filter,
1326
+ "subscribeTokenTrades"
1327
+ );
1328
+ }
1329
+ subscribeWalletTrade({
1330
+ chain,
1331
+ walletAddress,
1332
+ callback,
1333
+ filter
1334
+ }) {
1335
+ const channel = `dex-wallet-trade:${chain}_${walletAddress}`;
1336
+ return this.subscribe(
1337
+ channel,
1338
+ (data) => callback({
1339
+ tokenAddress: data.a,
1340
+ timestamp: data.t,
1341
+ kind: data.k,
1342
+ buyAmount: data.ba,
1343
+ buyAmountInUsd: data.baiu,
1344
+ buyTokenAddress: data.btma,
1345
+ buyTokenName: data.btn,
1346
+ buyTokenSymbol: data.bts,
1347
+ buyWalletAddress: data.bwa,
1348
+ sellAmount: data.sa,
1349
+ sellAmountInUsd: data.saiu,
1350
+ sellTokenAddress: data.stma,
1351
+ sellTokenName: data.stn,
1352
+ sellTokenSymbol: data.sts,
1353
+ sellWalletAddress: data.swa,
1354
+ txHash: data.h
1355
+ }),
1356
+ filter,
1357
+ "subscribeTokenTrades"
1358
+ );
1359
+ }
1360
+ subscribeDexPoolBalance({
1361
+ chain,
1362
+ poolAddress,
1363
+ callback
1364
+ }) {
1365
+ const channel = `dex-pool-balance:${chain}_${poolAddress}`;
1366
+ return this.subscribe(
1367
+ channel,
1368
+ (data) => callback({
1369
+ poolAddress: data.a,
1370
+ tokenAAddress: data.taa,
1371
+ tokenALiquidityInUsd: data.taliu,
1372
+ tokenBAddress: data.tba,
1373
+ tokenBLiquidityInUsd: data.tbliu
1374
+ })
1375
+ );
1376
+ }
1377
+ };
1378
+ var StreamUnsubscribable = class {
1379
+ constructor(streamApi, channel, fn) {
1380
+ this.streamApi = streamApi;
1381
+ this.channel = channel;
1382
+ this.fn = fn;
1383
+ }
1384
+ unsubscribe() {
1385
+ this.streamApi.unsubscribe(this.channel, this.fn);
1386
+ }
1387
+ };
1388
+
1389
+ // src/openapi-client/generated/blockchain/blockchain.ts
1390
+ var blockchain_exports = {};
1391
+ __export(blockchain_exports, {
1392
+ getLatestBlock: () => getLatestBlock,
1393
+ getSupportedBlockchains: () => getSupportedBlockchains
1394
+ });
1395
+ var getSupportedBlockchains = (options) => {
1396
+ return chainstreamApiClient({ url: `/v1/blockchain`, method: "GET" }, options);
1397
+ };
1398
+ var getLatestBlock = (chain, options) => {
1399
+ return chainstreamApiClient(
1400
+ { url: `/v1/blockchain/${chain}/latest_block`, method: "GET" },
1401
+ options
1402
+ );
1403
+ };
1404
+
1405
+ // src/openapi-client/generated/defi-sol-moonshot/defi-sol-moonshot.ts
1406
+ var defi_sol_moonshot_exports = {};
1407
+ __export(defi_sol_moonshot_exports, {
1408
+ moonshotCreateToken: () => moonshotCreateToken,
1409
+ moonshotSubmitCreateToken: () => moonshotSubmitCreateToken
1410
+ });
1411
+ var moonshotCreateToken = (moonshotCreateTokenInput, options) => {
1412
+ return chainstreamApiClient(
1413
+ {
1414
+ url: `/v1/sol/moonshot/create`,
1415
+ method: "POST",
1416
+ headers: { "Content-Type": "application/json" },
1417
+ data: moonshotCreateTokenInput
1418
+ },
1419
+ options
1420
+ );
1421
+ };
1422
+ var moonshotSubmitCreateToken = (moonshotSubmitCreateTokenInput, options) => {
1423
+ return chainstreamApiClient(
1424
+ {
1425
+ url: `/v1/sol/moonshot/submitCreateToken`,
1426
+ method: "POST",
1427
+ headers: { "Content-Type": "application/json" },
1428
+ data: moonshotSubmitCreateTokenInput
1429
+ },
1430
+ options
1431
+ );
1432
+ };
1433
+
1434
+ // src/openapi-client/generated/defi-sol-pumpfun/defi-sol-pumpfun.ts
1435
+ var defi_sol_pumpfun_exports = {};
1436
+ __export(defi_sol_pumpfun_exports, {
1437
+ pumpfunCreateToken: () => pumpfunCreateToken
1438
+ });
1439
+ var pumpfunCreateToken = (pumpCreateTokenInput, options) => {
1440
+ return chainstreamApiClient(
1441
+ {
1442
+ url: `/v1/sol/pumpfun/create`,
1443
+ method: "POST",
1444
+ headers: { "Content-Type": "application/json" },
1445
+ data: pumpCreateTokenInput
1446
+ },
1447
+ options
1448
+ );
1449
+ };
1450
+
1451
+ // src/openapi-client/generated/dex-pool/dex-pool.ts
1452
+ var dex_pool_exports = {};
1453
+ __export(dex_pool_exports, {
1454
+ getDexpool: () => getDexpool,
1455
+ getDexpoolSnapshots: () => getDexpoolSnapshots
1456
+ });
1457
+ var getDexpool = (chain, poolAddress, options) => {
1458
+ return chainstreamApiClient(
1459
+ { url: `/v1/dexpools/${chain}/${poolAddress}`, method: "GET" },
1460
+ options
1461
+ );
1462
+ };
1463
+ var getDexpoolSnapshots = (chain, poolAddress, params, options) => {
1464
+ return chainstreamApiClient(
1465
+ { url: `/v1/dexpools/${chain}/${poolAddress}/snapshots`, method: "GET", params },
1466
+ options
1467
+ );
1468
+ };
1469
+
1470
+ // src/openapi-client/generated/dex/dex.ts
1471
+ var dex_exports = {};
1472
+ __export(dex_exports, {
1473
+ createToken: () => createToken,
1474
+ listDex: () => listDex,
1475
+ quote: () => quote,
1476
+ route: () => route,
1477
+ swap: () => swap
1478
+ });
1479
+ var swap = (chain, swapInput, options) => {
1480
+ return chainstreamApiClient(
1481
+ {
1482
+ url: `/v1/dex/${chain}/swap`,
1483
+ method: "POST",
1484
+ headers: { "Content-Type": "application/json" },
1485
+ data: swapInput
1486
+ },
1487
+ options
1488
+ );
1489
+ };
1490
+ var route = (chain, swapRouteInput, options) => {
1491
+ return chainstreamApiClient(
1492
+ {
1493
+ url: `/v1/dex/${chain}/route`,
1494
+ method: "POST",
1495
+ headers: { "Content-Type": "application/json" },
1496
+ data: swapRouteInput
1497
+ },
1498
+ options
1499
+ );
1500
+ };
1501
+ var quote = (chain, params, options) => {
1502
+ return chainstreamApiClient(
1503
+ { url: `/v1/dex/${chain}/quote`, method: "GET", params },
1504
+ options
1505
+ );
1506
+ };
1507
+ var createToken = (chain, createTokenInput, options) => {
1508
+ return chainstreamApiClient(
1509
+ {
1510
+ url: `/v1/dex/${chain}/create`,
1511
+ method: "POST",
1512
+ headers: { "Content-Type": "application/json" },
1513
+ data: createTokenInput
1514
+ },
1515
+ options
1516
+ );
1517
+ };
1518
+ var listDex = (params, options) => {
1519
+ return chainstreamApiClient({ url: `/v1/dex`, method: "GET", params }, options);
1520
+ };
1521
+
1522
+ // src/openapi-client/generated/endpoint/endpoint.ts
1523
+ var endpoint_exports = {};
1524
+ __export(endpoint_exports, {
1525
+ createEndpoint: () => createEndpoint,
1526
+ deleteEndpoint: () => deleteEndpoint,
1527
+ getEndpoint: () => getEndpoint,
1528
+ getEndpointSecret: () => getEndpointSecret,
1529
+ listEndpoints: () => listEndpoints,
1530
+ rotateEndpointSecret: () => rotateEndpointSecret,
1531
+ updateEndpoint: () => updateEndpoint
1532
+ });
1533
+ var listEndpoints = (params, options) => {
1534
+ return chainstreamApiClient(
1535
+ { url: `/v1/webhook/endpoint`, method: "GET", params },
1536
+ options
1537
+ );
1538
+ };
1539
+ var createEndpoint = (createEndpointInput, options) => {
1540
+ return chainstreamApiClient(
1541
+ {
1542
+ url: `/v1/webhook/endpoint`,
1543
+ method: "POST",
1544
+ headers: { "Content-Type": "application/json" },
1545
+ data: createEndpointInput
1546
+ },
1547
+ options
1548
+ );
1549
+ };
1550
+ var updateEndpoint = (updateEndpointInput, options) => {
1551
+ return chainstreamApiClient(
1552
+ {
1553
+ url: `/v1/webhook/endpoint`,
1554
+ method: "PATCH",
1555
+ headers: { "Content-Type": "application/json" },
1556
+ data: updateEndpointInput
1557
+ },
1558
+ options
1559
+ );
1560
+ };
1561
+ var getEndpoint = (id, options) => {
1562
+ return chainstreamApiClient(
1563
+ { url: `/v1/webhook/endpoint/${id}`, method: "GET" },
1564
+ options
1565
+ );
1566
+ };
1567
+ var deleteEndpoint = (id, options) => {
1568
+ return chainstreamApiClient(
1569
+ { url: `/v1/webhook/endpoint/${id}`, method: "DELETE" },
1570
+ options
1571
+ );
1572
+ };
1573
+ var getEndpointSecret = (id, options) => {
1574
+ return chainstreamApiClient(
1575
+ { url: `/v1/webhook/endpoint/${id}/secret`, method: "GET" },
1576
+ options
1577
+ );
1578
+ };
1579
+ var rotateEndpointSecret = (id, options) => {
1580
+ return chainstreamApiClient(
1581
+ { url: `/v1/webhook/endpoint/${id}/secret/rotate`, method: "POST" },
1582
+ options
1583
+ );
1584
+ };
1585
+
1586
+ // src/openapi-client/generated/ipfs/ipfs.ts
1587
+ var ipfs_exports = {};
1588
+ __export(ipfs_exports, {
1589
+ presign: () => presign
1590
+ });
1591
+ var presign = (options) => {
1592
+ return chainstreamApiClient({ url: `/v1/ipfs/presign`, method: "POST" }, options);
1593
+ };
1594
+
1595
+ // src/openapi-client/generated/jobs/jobs.ts
1596
+ var jobs_exports = {};
1597
+ __export(jobs_exports, {
1598
+ get: () => get,
1599
+ streaming: () => streaming
1600
+ });
1601
+ var get = (id, options) => {
1602
+ return chainstreamApiClient({ url: `/jobs/${id}`, method: "GET" }, options);
1603
+ };
1604
+ var streaming = (id, options) => {
1605
+ return chainstreamApiClient(
1606
+ { url: `/jobs/${id}/streaming`, method: "GET" },
1607
+ options
1608
+ );
1609
+ };
1610
+
1611
+ // src/openapi-client/generated/kyt/kyt.ts
1612
+ var kyt_exports = {};
1613
+ __export(kyt_exports, {
1614
+ getAddressRisk: () => getAddressRisk,
1615
+ getTransferAlerts: () => getTransferAlerts,
1616
+ getTransferDirectExposure: () => getTransferDirectExposure,
1617
+ getTransferNetworkIdentifications: () => getTransferNetworkIdentifications,
1618
+ getTransferSummary: () => getTransferSummary,
1619
+ getWithdrawalAddressIdentifications: () => getWithdrawalAddressIdentifications,
1620
+ getWithdrawalAlerts: () => getWithdrawalAlerts,
1621
+ getWithdrawalDirectExposure: () => getWithdrawalDirectExposure,
1622
+ getWithdrawalFraudAssessment: () => getWithdrawalFraudAssessment,
1623
+ getWithdrawalNetworkIdentifications: () => getWithdrawalNetworkIdentifications,
1624
+ getWithdrawalSummary: () => getWithdrawalSummary,
1625
+ registerAddress: () => registerAddress,
1626
+ registerTransfer: () => registerTransfer,
1627
+ registerWithdrawal: () => registerWithdrawal
1628
+ });
1629
+ var registerTransfer = (kYTRegisterTransferRequest, options) => {
1630
+ return chainstreamApiClient(
1631
+ {
1632
+ url: `/v1/kyt/transfer`,
1633
+ method: "POST",
1634
+ headers: { "Content-Type": "application/json" },
1635
+ data: kYTRegisterTransferRequest
1636
+ },
1637
+ options
1638
+ );
1639
+ };
1640
+ var getTransferSummary = (transferId, options) => {
1641
+ return chainstreamApiClient(
1642
+ { url: `/v1/kyt/transfers/${transferId}/summary`, method: "GET" },
1643
+ options
1644
+ );
1645
+ };
1646
+ var getTransferDirectExposure = (transferId, options) => {
1647
+ return chainstreamApiClient(
1648
+ { url: `/v1/kyt/transfers/${transferId}/exposures/direct`, method: "GET" },
1649
+ options
1650
+ );
1651
+ };
1652
+ var getTransferAlerts = (transferId, options) => {
1653
+ return chainstreamApiClient(
1654
+ { url: `/v1/kyt/transfers/${transferId}/alerts`, method: "GET" },
1655
+ options
1656
+ );
1657
+ };
1658
+ var getTransferNetworkIdentifications = (transferId, options) => {
1659
+ return chainstreamApiClient(
1660
+ { url: `/v1/kyt/transfers/${transferId}/network-identifications`, method: "GET" },
1661
+ options
1662
+ );
1663
+ };
1664
+ var registerWithdrawal = (kYTRegisterWithdrawalRequest, options) => {
1665
+ return chainstreamApiClient(
1666
+ {
1667
+ url: `/v1/kyt/withdrawal`,
1668
+ method: "POST",
1669
+ headers: { "Content-Type": "application/json" },
1670
+ data: kYTRegisterWithdrawalRequest
1671
+ },
1672
+ options
1673
+ );
1674
+ };
1675
+ var getWithdrawalSummary = (withdrawalId, options) => {
1676
+ return chainstreamApiClient(
1677
+ { url: `/v1/kyt/withdrawal/${withdrawalId}/summary`, method: "GET" },
1678
+ options
1679
+ );
1680
+ };
1681
+ var getWithdrawalDirectExposure = (withdrawalId, options) => {
1682
+ return chainstreamApiClient(
1683
+ { url: `/v1/kyt/withdrawal/${withdrawalId}/exposures/direct`, method: "GET" },
1684
+ options
1685
+ );
1686
+ };
1687
+ var getWithdrawalAlerts = (withdrawalId, options) => {
1688
+ return chainstreamApiClient(
1689
+ { url: `/v1/kyt/withdrawal/${withdrawalId}/alerts`, method: "GET" },
1690
+ options
1691
+ );
1692
+ };
1693
+ var getWithdrawalAddressIdentifications = (withdrawalId, options) => {
1694
+ return chainstreamApiClient(
1695
+ { url: `/v1/kyt/withdrawal/${withdrawalId}/address-identifications`, method: "GET" },
1696
+ options
1697
+ );
1698
+ };
1699
+ var getWithdrawalNetworkIdentifications = (withdrawalId, options) => {
1700
+ return chainstreamApiClient(
1701
+ { url: `/v1/kyt/withdrawal/${withdrawalId}/network-identifications`, method: "GET" },
1702
+ options
1703
+ );
1704
+ };
1705
+ var getWithdrawalFraudAssessment = (withdrawalId, options) => {
1706
+ return chainstreamApiClient(
1707
+ { url: `/v1/kyt/withdrawal/${withdrawalId}/fraud-assessment`, method: "GET" },
1708
+ options
1709
+ );
1710
+ };
1711
+ var registerAddress = (registerAddressRequest, options) => {
1712
+ return chainstreamApiClient(
1713
+ {
1714
+ url: `/v1/kyt/address`,
1715
+ method: "POST",
1716
+ headers: { "Content-Type": "application/json" },
1717
+ data: registerAddressRequest
1718
+ },
1719
+ options
1720
+ );
1721
+ };
1722
+ var getAddressRisk = (address, options) => {
1723
+ return chainstreamApiClient(
1724
+ { url: `/v1/kyt/addresses/${address}/risk`, method: "GET" },
1725
+ options
1726
+ );
1727
+ };
1728
+
1729
+ // src/openapi-client/generated/ranking/ranking.ts
1730
+ var ranking_exports = {};
1731
+ __export(ranking_exports, {
1732
+ getFinalStretchTokens: () => getFinalStretchTokens,
1733
+ getHotTokens: () => getHotTokens,
1734
+ getMigratedTokens: () => getMigratedTokens,
1735
+ getNewTokens: () => getNewTokens,
1736
+ getStocksTokens: () => getStocksTokens
1737
+ });
1738
+ var getHotTokens = (chain, duration, params, options) => {
1739
+ return chainstreamApiClient(
1740
+ { url: `/v1/ranking/${chain}/hotTokens/${duration}`, method: "GET", params },
1741
+ options
1742
+ );
1743
+ };
1744
+ var getNewTokens = (chain, params, options) => {
1745
+ return chainstreamApiClient(
1746
+ { url: `/v1/ranking/${chain}/newTokens`, method: "GET", params },
1747
+ options
1748
+ );
1749
+ };
1750
+ var getStocksTokens = (chain, params, options) => {
1751
+ return chainstreamApiClient(
1752
+ { url: `/v1/ranking/${chain}/stocks`, method: "GET", params },
1753
+ options
1754
+ );
1755
+ };
1756
+ var getFinalStretchTokens = (chain, params, options) => {
1757
+ return chainstreamApiClient(
1758
+ { url: `/v1/ranking/${chain}/finalStretch`, method: "GET", params },
1759
+ options
1760
+ );
1761
+ };
1762
+ var getMigratedTokens = (chain, params, options) => {
1763
+ return chainstreamApiClient(
1764
+ { url: `/v1/ranking/${chain}/migrated`, method: "GET", params },
1765
+ options
1766
+ );
1767
+ };
1768
+
1769
+ // src/openapi-client/generated/red-packet/red-packet.ts
1770
+ var red_packet_exports = {};
1771
+ __export(red_packet_exports, {
1772
+ claimRedpacket: () => claimRedpacket,
1773
+ createRedpacket: () => createRedpacket,
1774
+ getClaims: () => getClaims,
1775
+ getClaimsByAddress: () => getClaimsByAddress,
1776
+ getRedpacket: () => getRedpacket,
1777
+ getRedpackets: () => getRedpackets,
1778
+ getRedpacketsByAddress: () => getRedpacketsByAddress,
1779
+ redpacketSend: () => redpacketSend
1780
+ });
1781
+ var createRedpacket = (chain, createRedPacketInput, options) => {
1782
+ return chainstreamApiClient(
1783
+ {
1784
+ url: `/v1/redpacket/${chain}/create`,
1785
+ method: "POST",
1786
+ headers: { "Content-Type": "application/json" },
1787
+ data: createRedPacketInput
1788
+ },
1789
+ options
1790
+ );
1791
+ };
1792
+ var claimRedpacket = (chain, claimRedPacketInput, options) => {
1793
+ return chainstreamApiClient(
1794
+ {
1795
+ url: `/v1/redpacket/${chain}/claim`,
1796
+ method: "POST",
1797
+ headers: { "Content-Type": "application/json" },
1798
+ data: claimRedPacketInput
1799
+ },
1800
+ options
1801
+ );
1802
+ };
1803
+ var getRedpacket = (id, options) => {
1804
+ return chainstreamApiClient({ url: `/v1/redpacket/${id}`, method: "GET" }, options);
1805
+ };
1806
+ var getClaims = (id, params, options) => {
1807
+ return chainstreamApiClient(
1808
+ { url: `/v1/redpacket/${id}/claims`, method: "GET", params },
1809
+ options
1810
+ );
1811
+ };
1812
+ var getRedpackets = (params, options) => {
1813
+ return chainstreamApiClient(
1814
+ { url: `/v1/redpacket`, method: "GET", params },
1815
+ options
1816
+ );
1817
+ };
1818
+ var getClaimsByAddress = (address, params, options) => {
1819
+ return chainstreamApiClient(
1820
+ { url: `/v1/redpacket/wallet/${address}/claims`, method: "GET", params },
1821
+ options
1822
+ );
1823
+ };
1824
+ var getRedpacketsByAddress = (address, params, options) => {
1825
+ return chainstreamApiClient(
1826
+ { url: `/v1/redpacket/wallet/${address}/redpackets`, method: "GET", params },
1827
+ options
1828
+ );
1829
+ };
1830
+ var redpacketSend = (chain, redPacketSendTxInput, options) => {
1831
+ return chainstreamApiClient(
1832
+ {
1833
+ url: `/v1/redpacket/${chain}/send`,
1834
+ method: "POST",
1835
+ headers: { "Content-Type": "application/json" },
1836
+ data: redPacketSendTxInput
1837
+ },
1838
+ options
1839
+ );
1840
+ };
1841
+
1842
+ // src/openapi-client/generated/token/token.ts
1843
+ var token_exports = {};
1844
+ __export(token_exports, {
1845
+ getCandles: () => getCandles,
1846
+ getCreation: () => getCreation,
1847
+ getDevTokens: () => getDevTokens,
1848
+ getHolders: () => getHolders,
1849
+ getHoldersMulti: () => getHoldersMulti,
1850
+ getMarketData: () => getMarketData,
1851
+ getMarketDataMulti: () => getMarketDataMulti,
1852
+ getMetadata: () => getMetadata,
1853
+ getMetadataMulti: () => getMetadataMulti,
1854
+ getMintAndBurn: () => getMintAndBurn,
1855
+ getPools: () => getPools,
1856
+ getPriceByTime: () => getPriceByTime,
1857
+ getPrices: () => getPrices,
1858
+ getSecurity: () => getSecurity,
1859
+ getStats: () => getStats,
1860
+ getStatsMulti: () => getStatsMulti,
1861
+ getToken: () => getToken,
1862
+ getTokenLiquiditySnapshots: () => getTokenLiquiditySnapshots,
1863
+ getTokenTraders: () => getTokenTraders,
1864
+ getTokens: () => getTokens,
1865
+ getTopHolders: () => getTopHolders,
1866
+ listToken: () => listToken,
1867
+ search: () => search
1868
+ });
1869
+ var search = (params, options) => {
1870
+ return chainstreamApiClient(
1871
+ { url: `/v1/token/search`, method: "GET", params },
1872
+ options
1873
+ );
1874
+ };
1875
+ var getTokens = (chain, params, options) => {
1876
+ return chainstreamApiClient(
1877
+ { url: `/v1/token/${chain}/multi`, method: "GET", params },
1878
+ options
1879
+ );
1880
+ };
1881
+ var getToken = (chain, tokenAddress, options) => {
1882
+ return chainstreamApiClient(
1883
+ { url: `/v1/token/${chain}/${tokenAddress}`, method: "GET" },
1884
+ options
1885
+ );
1886
+ };
1887
+ var getMetadata = (chain, tokenAddress, options) => {
1888
+ return chainstreamApiClient(
1889
+ { url: `/v1/token/${chain}/${tokenAddress}/metadata`, method: "GET" },
1890
+ options
1891
+ );
1892
+ };
1893
+ var getMetadataMulti = (chain, params, options) => {
1894
+ return chainstreamApiClient(
1895
+ { url: `/v1/token/${chain}/metadata/multi`, method: "GET", params },
1896
+ options
1897
+ );
1898
+ };
1899
+ var getPools = (chain, tokenAddress, params, options) => {
1900
+ return chainstreamApiClient(
1901
+ { url: `/v1/token/${chain}/${tokenAddress}/pools`, method: "GET", params },
1902
+ options
1903
+ );
1904
+ };
1905
+ var getStats = (chain, tokenAddress, options) => {
1906
+ return chainstreamApiClient(
1907
+ { url: `/v1/token/${chain}/${tokenAddress}/stats`, method: "GET" },
1908
+ options
1909
+ );
1910
+ };
1911
+ var getStatsMulti = (chain, params, options) => {
1912
+ return chainstreamApiClient(
1913
+ { url: `/v1/token/${chain}/stats/multi`, method: "GET", params },
1914
+ options
1915
+ );
1916
+ };
1917
+ var getHolders = (chain, tokenAddress, params, options) => {
1918
+ return chainstreamApiClient(
1919
+ { url: `/v1/token/${chain}/${tokenAddress}/holders`, method: "GET", params },
1920
+ options
1921
+ );
1922
+ };
1923
+ var getHoldersMulti = (chain, tokenAddress, params, options) => {
1924
+ return chainstreamApiClient(
1925
+ { url: `/v1/token/${chain}/${tokenAddress}/holders/multi`, method: "GET", params },
1926
+ options
1927
+ );
1928
+ };
1929
+ var getCandles = (chain, tokenAddress, params, options) => {
1930
+ return chainstreamApiClient(
1931
+ { url: `/v1/token/${chain}/${tokenAddress}/candles`, method: "GET", params },
1932
+ options
1933
+ );
1934
+ };
1935
+ var getTopHolders = (chain, tokenAddress, options) => {
1936
+ return chainstreamApiClient(
1937
+ { url: `/v1/token/${chain}/${tokenAddress}/topHolders`, method: "GET" },
1938
+ options
1939
+ );
1940
+ };
1941
+ var getMarketData = (chain, tokenAddress, options) => {
1942
+ return chainstreamApiClient(
1943
+ { url: `/v1/token/${chain}/${tokenAddress}/marketData`, method: "GET" },
1944
+ options
1945
+ );
1946
+ };
1947
+ var getMarketDataMulti = (chain, params, options) => {
1948
+ return chainstreamApiClient(
1949
+ { url: `/v1/token/${chain}/marketData/multi`, method: "GET", params },
1950
+ options
1951
+ );
1952
+ };
1953
+ var getPrices = (chain, tokenAddress, params, options) => {
1954
+ return chainstreamApiClient(
1955
+ { url: `/v1/token/${chain}/${tokenAddress}/prices`, method: "GET", params },
1956
+ options
1957
+ );
1958
+ };
1959
+ var getPriceByTime = (chain, tokenAddress, params, options) => {
1960
+ return chainstreamApiClient(
1961
+ { url: `/v1/token/${chain}/${tokenAddress}/price`, method: "GET", params },
1962
+ options
1963
+ );
1964
+ };
1965
+ var getCreation = (chain, tokenAddress, options) => {
1966
+ return chainstreamApiClient(
1967
+ { url: `/v1/token/${chain}/${tokenAddress}/creation`, method: "GET" },
1968
+ options
1969
+ );
1970
+ };
1971
+ var getMintAndBurn = (chain, tokenAddress, params, options) => {
1972
+ return chainstreamApiClient(
1973
+ { url: `/v1/token/${chain}/${tokenAddress}/mintAndBurn`, method: "GET", params },
1974
+ options
1975
+ );
1976
+ };
1977
+ var listToken = (chain, params, options) => {
1978
+ return chainstreamApiClient(
1979
+ { url: `/v1/token/${chain}/list`, method: "GET", params },
1980
+ options
1981
+ );
1982
+ };
1983
+ var getSecurity = (chain, tokenAddress, options) => {
1984
+ return chainstreamApiClient(
1985
+ { url: `/v1/token/${chain}/${tokenAddress}/security`, method: "GET" },
1986
+ options
1987
+ );
1988
+ };
1989
+ var getDevTokens = (chain, devAddress, options) => {
1990
+ return chainstreamApiClient(
1991
+ { url: `/v1/token/${chain}/dev/${devAddress}/tokens`, method: "GET" },
1992
+ options
1993
+ );
1994
+ };
1995
+ var getTokenTraders = (chain, tokenAddress, tag, options) => {
1996
+ return chainstreamApiClient(
1997
+ { url: `/v1/token/${chain}/${tokenAddress}/traders/${tag}`, method: "GET" },
1998
+ options
1999
+ );
2000
+ };
2001
+ var getTokenLiquiditySnapshots = (chain, tokenAddress, params, options) => {
2002
+ return chainstreamApiClient(
2003
+ { url: `/v1/token/${chain}/${tokenAddress}/liquiditySnapshots`, method: "GET", params },
2004
+ options
2005
+ );
2006
+ };
2007
+
2008
+ // src/openapi-client/generated/trade/trade.ts
2009
+ var trade_exports = {};
2010
+ __export(trade_exports, {
2011
+ getActivities: () => getActivities,
2012
+ getTopTraders: () => getTopTraders,
2013
+ getTrades: () => getTrades
2014
+ });
2015
+ var getTrades = (chain, params, options) => {
2016
+ return chainstreamApiClient(
2017
+ { url: `/v1/trade/${chain}`, method: "GET", params },
2018
+ options
2019
+ );
2020
+ };
2021
+ var getActivities = (chain, params, options) => {
2022
+ return chainstreamApiClient(
2023
+ { url: `/v1/trade/${chain}/activities`, method: "GET", params },
2024
+ options
2025
+ );
2026
+ };
2027
+ var getTopTraders = (chain, params, options) => {
2028
+ return chainstreamApiClient(
2029
+ { url: `/v1/trade/${chain}/top-traders`, method: "GET", params },
2030
+ options
2031
+ );
2032
+ };
2033
+
2034
+ // src/openapi-client/generated/transaction/transaction.ts
2035
+ var transaction_exports = {};
2036
+ __export(transaction_exports, {
2037
+ getGasLimit: () => getGasLimit,
2038
+ getGasPrice: () => getGasPrice,
2039
+ send: () => send
2040
+ });
2041
+ var send = (chain, sendTxInput, options) => {
2042
+ return chainstreamApiClient(
2043
+ {
2044
+ url: `/v1/transaction/${chain}/send`,
2045
+ method: "POST",
2046
+ headers: { "Content-Type": "application/json" },
2047
+ data: sendTxInput
2048
+ },
2049
+ options
2050
+ );
2051
+ };
2052
+ var getGasPrice = (chain, options) => {
2053
+ return chainstreamApiClient(
2054
+ { url: `/v1/transaction/${chain}/gas-price`, method: "GET" },
2055
+ options
2056
+ );
2057
+ };
2058
+ var getGasLimit = (chain, estimateGasLimitInput, options) => {
2059
+ return chainstreamApiClient(
2060
+ {
2061
+ url: `/v1/transaction/${chain}/estimate-gas-limit`,
2062
+ method: "POST",
2063
+ headers: { "Content-Type": "application/json" },
2064
+ data: estimateGasLimitInput
2065
+ },
2066
+ options
2067
+ );
2068
+ };
2069
+
2070
+ // src/openapi-client/generated/wallet/wallet.ts
2071
+ var wallet_exports = {};
2072
+ __export(wallet_exports, {
2073
+ calculatePnl: () => calculatePnl,
2074
+ getBalance: () => getBalance,
2075
+ getBalanceUpdates: () => getBalanceUpdates,
2076
+ getPnl: () => getPnl,
2077
+ getPnlStats: () => getPnlStats
2078
+ });
2079
+ var getPnl = (chain, walletAddress, params, options) => {
2080
+ return chainstreamApiClient(
2081
+ { url: `/v1/wallet/${chain}/${walletAddress}`, method: "GET", params },
2082
+ options
2083
+ );
2084
+ };
2085
+ var getPnlStats = (chain, walletAddress, options) => {
2086
+ return chainstreamApiClient(
2087
+ { url: `/v1/wallet/${chain}/${walletAddress}/stats`, method: "GET" },
2088
+ options
2089
+ );
2090
+ };
2091
+ var getBalance = (chain, walletAddress, params, options) => {
2092
+ return chainstreamApiClient(
2093
+ { url: `/v1/wallet/${chain}/${walletAddress}/balance`, method: "GET", params },
2094
+ options
2095
+ );
2096
+ };
2097
+ var calculatePnl = (chain, walletAddress, calculatePnlInput, options) => {
2098
+ return chainstreamApiClient(
2099
+ {
2100
+ url: `/v1/wallet/${chain}/${walletAddress}/calculate-pnl`,
2101
+ method: "POST",
2102
+ headers: { "Content-Type": "application/json" },
2103
+ data: calculatePnlInput
2104
+ },
2105
+ options
2106
+ );
2107
+ };
2108
+ var getBalanceUpdates = (chain, walletAddress, params, options) => {
2109
+ return chainstreamApiClient(
2110
+ { url: `/v1/wallet/${chain}/${walletAddress}/balance-updates`, method: "GET", params },
2111
+ options
2112
+ );
2113
+ };
2114
+
2115
+ // src/openapi-client/generated/watchlist/watchlist.ts
2116
+ var watchlist_exports = {};
2117
+ __export(watchlist_exports, {
2118
+ watchlistAdd: () => watchlistAdd
2119
+ });
2120
+ var watchlistAdd = (chain, walletAddress, options) => {
2121
+ return chainstreamApiClient(
2122
+ { url: `/v1/watchlist/${chain}/${walletAddress}`, method: "POST" },
2123
+ options
2124
+ );
2125
+ };
2126
+
2127
+ // src/chainstream.ts
2128
+ var ChainStreamClient = class {
2129
+ constructor(accessToken, options = {}) {
2130
+ __publicField(this, "requestCtx");
2131
+ // WebSocket streaming client
2132
+ __publicField(this, "stream");
2133
+ // REST API modules
2134
+ __publicField(this, "token");
2135
+ __publicField(this, "dex");
2136
+ __publicField(this, "dexpool");
2137
+ __publicField(this, "trade");
2138
+ __publicField(this, "ranking");
2139
+ __publicField(this, "transaction");
2140
+ __publicField(this, "moonshot");
2141
+ __publicField(this, "pumpfun");
2142
+ __publicField(this, "wallet");
2143
+ __publicField(this, "redPacket");
2144
+ __publicField(this, "ipfs");
2145
+ __publicField(this, "blockchain");
2146
+ __publicField(this, "watchlist");
2147
+ __publicField(this, "jobs");
2148
+ __publicField(this, "kyt");
2149
+ __publicField(this, "endpoint");
2150
+ const baseUrl = options.serverUrl ?? "https://api-dex.chainstream.io";
2151
+ const streamUrl = options.streamUrl ?? "wss://realtime-dex.chainstream.io/connection/websocket";
2152
+ this.requestCtx = { baseUrl, streamUrl, accessToken };
2153
+ configure({
2154
+ accessToken,
2155
+ basePath: baseUrl,
2156
+ debugging: options.debug
2157
+ });
2158
+ this.token = token_exports;
2159
+ this.dex = dex_exports;
2160
+ this.dexpool = dex_pool_exports;
2161
+ this.trade = trade_exports;
2162
+ this.ranking = ranking_exports;
2163
+ this.transaction = transaction_exports;
2164
+ this.moonshot = defi_sol_moonshot_exports;
2165
+ this.pumpfun = defi_sol_pumpfun_exports;
2166
+ this.wallet = wallet_exports;
2167
+ this.redPacket = red_packet_exports;
2168
+ this.ipfs = ipfs_exports;
2169
+ this.blockchain = blockchain_exports;
2170
+ this.watchlist = watchlist_exports;
2171
+ this.jobs = jobs_exports;
2172
+ this.kyt = kyt_exports;
2173
+ this.endpoint = endpoint_exports;
2174
+ this.stream = new StreamApi(this.requestCtx);
2175
+ if (options.autoConnectWebSocket === true) {
2176
+ this.stream.connect();
2177
+ }
2178
+ }
2179
+ /**
2180
+ * Wait for a job to complete using Server-Sent Events (SSE)
2181
+ * @param jobId - The job ID to wait for
2182
+ * @param timeout - Timeout in milliseconds (default: 60000)
2183
+ * @returns Promise that resolves with the job result
2184
+ */
2185
+ async waitForJob(jobId, timeout = 6e4) {
2186
+ const accessToken = typeof this.requestCtx.accessToken === "string" ? this.requestCtx.accessToken : await this.requestCtx.accessToken.getToken();
2187
+ return new Promise((resolve, reject) => {
2188
+ const sse = new EventSourcePolyfill(`${this.requestCtx.baseUrl}/jobs/${jobId}/streaming`, {
2189
+ headers: {
2190
+ Authorization: `Bearer ${accessToken}`
2191
+ }
2192
+ });
2193
+ const timeoutId = setTimeout(() => {
2194
+ sse.close();
2195
+ reject(new Error(`Job ${jobId} timed out after ${timeout}ms`));
2196
+ }, timeout);
2197
+ sse.onmessage = (event) => {
2198
+ try {
2199
+ console.log("event.data: ", event.data);
2200
+ const data = JSON.parse(event.data);
2201
+ if (data.status === "error") {
2202
+ sse.close();
2203
+ reject(new Error(`Error: ${data.message}`));
2204
+ } else if (data.status === "completed") {
2205
+ clearTimeout(timeoutId);
2206
+ sse.close();
2207
+ resolve(data);
2208
+ }
2209
+ } catch {
2210
+ clearTimeout(timeoutId);
2211
+ sse.close();
2212
+ reject(new Error("Error parsing event data"));
2213
+ }
2214
+ };
2215
+ sse.onopen = () => {
2216
+ console.log("SSE connection opened");
2217
+ };
2218
+ sse.onerror = (error) => {
2219
+ const errorEvent = error;
2220
+ if (errorEvent.message?.includes("No activity within")) {
2221
+ console.log("SSE reconnecting due to inactivity...");
2222
+ return;
2223
+ }
2224
+ clearTimeout(timeoutId);
2225
+ sse.close();
2226
+ reject(new Error(`Error in SSE connection: ${error}`));
2227
+ };
2228
+ });
2229
+ }
2230
+ };
2231
+ export {
2232
+ ChainStreamClient
2233
+ };
2234
+ //# sourceMappingURL=chainstream.mjs.map