@chainstream-io/sdk 0.1.26 → 0.2.2

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