@chainstream-io/sdk 0.2.11 → 0.2.13

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.
@@ -1,2 +1,2 @@
1
- export { C as ChainStreamClient, y as ChainStreamClientOptions, z as ChainStreamRequestContext, ha as PostOptions, T as TokenProvider } from './chainstream-D_kgiAfE.cjs';
1
+ export { C as ChainStreamClient, y as ChainStreamClientOptions, z as ChainStreamRequestContext, he as PostOptions, T as TokenProvider } from './chainstream-DeYuVTgJ.cjs';
2
2
  import 'axios';
@@ -1,2 +1,2 @@
1
- export { C as ChainStreamClient, y as ChainStreamClientOptions, z as ChainStreamRequestContext, ha as PostOptions, T as TokenProvider } from './chainstream-D_kgiAfE.js';
1
+ export { C as ChainStreamClient, y as ChainStreamClientOptions, z as ChainStreamRequestContext, he as PostOptions, T as TokenProvider } from './chainstream-DeYuVTgJ.js';
2
2
  import 'axios';
@@ -15,7 +15,7 @@ import axiosRetry, { exponentialDelay } from "axios-retry";
15
15
  var axiosInstance;
16
16
  var currentOptions = void 0;
17
17
  var configure = (options) => {
18
- const baseURL = options.basePath || "https://api-dex.chainstream.io";
18
+ const baseURL = options.basePath || "https://api.chainstream.io";
19
19
  currentOptions = {
20
20
  ...options,
21
21
  basePath: baseURL
@@ -239,12 +239,35 @@ var CEL_FIELD_MAPPINGS = {
239
239
  balanceTagRatRatio: "btrr",
240
240
  timestamp: "ts"
241
241
  },
242
- // New token subscription fields
242
+ // New token subscription fields (dex-new-token, supports CEL filter)
243
243
  subscribeNewToken: {
244
244
  tokenAddress: "a",
245
245
  name: "n",
246
246
  symbol: "s",
247
- createdAtMs: "cts"
247
+ decimals: "dec",
248
+ imageUrl: "iu",
249
+ description: "de",
250
+ createdAtMs: "cts",
251
+ coingeckoCoinId: "cgi",
252
+ "socialMedia.twitter": "sm.tw",
253
+ "socialMedia.telegram": "sm.tg",
254
+ "socialMedia.website": "sm.w",
255
+ "socialMedia.tiktok": "sm.tt",
256
+ "socialMedia.discord": "sm.dc",
257
+ "socialMedia.facebook": "sm.fb",
258
+ "socialMedia.github": "sm.gh",
259
+ "socialMedia.instagram": "sm.ig",
260
+ "socialMedia.linkedin": "sm.li",
261
+ "socialMedia.medium": "sm.md",
262
+ "socialMedia.reddit": "sm.rd",
263
+ "socialMedia.youtube": "sm.yt",
264
+ "socialMedia.bitbucket": "sm.bb",
265
+ "launchFrom.programAddress": "lf.pa",
266
+ "launchFrom.protocolFamily": "lf.pf",
267
+ "launchFrom.protocolName": "lf.pn",
268
+ "migratedTo.programAddress": "mt.pa",
269
+ "migratedTo.protocolFamily": "mt.pf",
270
+ "migratedTo.protocolName": "mt.pn"
248
271
  },
249
272
  // Token supply subscription fields
250
273
  subscribeTokenSupply: {
@@ -267,15 +290,65 @@ var CEL_FIELD_MAPPINGS = {
267
290
  value: "v",
268
291
  timestamp: "ts"
269
292
  },
270
- // New token metadata subscription fields
293
+ // New token metadata subscription fields (dex-new-tokens-metadata)
271
294
  subscribeNewTokensMetadata: {
272
295
  tokenAddress: "a",
273
296
  name: "n",
297
+ decimals: "dec",
298
+ symbol: "s",
299
+ imageUrl: "iu",
300
+ description: "de",
301
+ createdAtMs: "cts",
302
+ coingeckoCoinId: "cgi",
303
+ "socialMedia.twitter": "sm.tw",
304
+ "socialMedia.telegram": "sm.tg",
305
+ "socialMedia.website": "sm.w",
306
+ "socialMedia.tiktok": "sm.tt",
307
+ "socialMedia.discord": "sm.dc",
308
+ "socialMedia.facebook": "sm.fb",
309
+ "socialMedia.github": "sm.gh",
310
+ "socialMedia.instagram": "sm.ig",
311
+ "socialMedia.linkedin": "sm.li",
312
+ "socialMedia.medium": "sm.md",
313
+ "socialMedia.reddit": "sm.rd",
314
+ "socialMedia.youtube": "sm.yt",
315
+ "socialMedia.bitbucket": "sm.bb",
316
+ "launchFrom.programAddress": "lf.pa",
317
+ "launchFrom.protocolFamily": "lf.pf",
318
+ "launchFrom.protocolName": "lf.pn",
319
+ "migratedTo.programAddress": "mt.pa",
320
+ "migratedTo.protocolFamily": "mt.pf",
321
+ "migratedTo.protocolName": "mt.pn"
322
+ },
323
+ // New tokens list subscription fields (dex-new-tokens)
324
+ subscribeNewTokens: {
325
+ tokenAddress: "a",
326
+ name: "n",
327
+ decimals: "dec",
274
328
  symbol: "s",
275
329
  imageUrl: "iu",
276
330
  description: "de",
277
- socialMedia: "sm",
278
- createdAtMs: "cts"
331
+ createdAtMs: "cts",
332
+ coingeckoCoinId: "cgi",
333
+ "socialMedia.twitter": "sm.tw",
334
+ "socialMedia.telegram": "sm.tg",
335
+ "socialMedia.website": "sm.w",
336
+ "socialMedia.tiktok": "sm.tt",
337
+ "socialMedia.discord": "sm.dc",
338
+ "socialMedia.facebook": "sm.fb",
339
+ "socialMedia.github": "sm.gh",
340
+ "socialMedia.instagram": "sm.ig",
341
+ "socialMedia.linkedin": "sm.li",
342
+ "socialMedia.medium": "sm.md",
343
+ "socialMedia.reddit": "sm.rd",
344
+ "socialMedia.youtube": "sm.yt",
345
+ "socialMedia.bitbucket": "sm.bb",
346
+ "launchFrom.programAddress": "lf.pa",
347
+ "launchFrom.protocolFamily": "lf.pf",
348
+ "launchFrom.protocolName": "lf.pn",
349
+ "migratedTo.programAddress": "mt.pa",
350
+ "migratedTo.protocolFamily": "mt.pf",
351
+ "migratedTo.protocolName": "mt.pn"
279
352
  },
280
353
  // Token trades subscription fields
281
354
  subscribeTokenTrades: {
@@ -351,12 +424,14 @@ function replaceFilterFields(filter, methodName) {
351
424
  }
352
425
  const fieldMappings = getFieldMappings(methodName);
353
426
  let result = filter;
354
- for (const [longField, shortField] of Object.entries(fieldMappings)) {
427
+ const sortedEntries = Object.entries(fieldMappings).sort(([a], [b]) => b.length - a.length);
428
+ for (const [longField, shortField] of sortedEntries) {
429
+ const escapedField = longField.replace(/\./g, "\\.");
355
430
  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")
431
+ // Pattern 1: meta.fieldName (with meta. prefix) — check first to avoid double meta.
432
+ new RegExp(`\\bmeta\\.${escapedField}\\b`, "g"),
433
+ // Pattern 2: fieldName (without meta. prefix)
434
+ new RegExp(`\\b${escapedField}\\b`, "g")
360
435
  ];
361
436
  patterns.forEach((pattern) => {
362
437
  result = result.replace(pattern, `meta.${shortField}`);
@@ -659,6 +734,57 @@ var StreamApi = class {
659
734
  [`liquidityChangeRatio${suffix}`]: this.formatScientificNotation(data[`lpc${suffix}`])
660
735
  };
661
736
  }
737
+ /**
738
+ * Parse social media data from short field names
739
+ */
740
+ parseSocialMedia(sm) {
741
+ if (!sm) return void 0;
742
+ return {
743
+ twitter: sm.tw,
744
+ telegram: sm.tg,
745
+ website: sm.w,
746
+ tiktok: sm.tt,
747
+ discord: sm.dc,
748
+ facebook: sm.fb,
749
+ github: sm.gh,
750
+ instagram: sm.ig,
751
+ linkedin: sm.li,
752
+ medium: sm.md,
753
+ reddit: sm.rd,
754
+ youtube: sm.yt,
755
+ bitbucket: sm.bb
756
+ };
757
+ }
758
+ /**
759
+ * Parse DEX protocol data from short field names
760
+ */
761
+ parseDexProtocol(lf) {
762
+ if (!lf) return void 0;
763
+ const result = {};
764
+ if (lf.pa) result.programAddress = lf.pa;
765
+ if (lf.pf) result.protocolFamily = lf.pf;
766
+ if (lf.pn) result.protocolName = lf.pn;
767
+ return result;
768
+ }
769
+ /**
770
+ * Parse a TokenMetadataTimeEvent from raw WebSocket data
771
+ */
772
+ parseTokenMetadata(data) {
773
+ const result = {
774
+ tokenAddress: data.a
775
+ };
776
+ if (data.n != null) result.name = data.n;
777
+ if (data.dec != null) result.decimals = data.dec;
778
+ if (data.s != null) result.symbol = data.s;
779
+ if (data.iu != null) result.imageUrl = data.iu;
780
+ if (data.de != null) result.description = data.de;
781
+ if (data.sm) result.socialMedia = this.parseSocialMedia(data.sm);
782
+ if (data.cts != null) result.createdAtMs = data.cts;
783
+ if (data.cgi != null) result.coingeckoCoinId = data.cgi;
784
+ if (data.lf) result.launchFrom = this.parseDexProtocol(data.lf);
785
+ if (data.mt) result.migratedTo = this.parseDexProtocol(data.mt);
786
+ return result;
787
+ }
662
788
  /**
663
789
  * Subscribe to token trade statistics
664
790
  * Channel: dex-token-stats:{chain}_{tokenAddress}
@@ -759,6 +885,10 @@ var StreamApi = class {
759
885
  "subscribeTokenHolders"
760
886
  );
761
887
  }
888
+ /**
889
+ * Subscribe to new token events (single token per event, supports CEL filter)
890
+ * Channel: dex-new-token:{chain}
891
+ */
762
892
  subscribeNewToken({
763
893
  chain,
764
894
  callback,
@@ -774,28 +904,24 @@ var StreamApi = class {
774
904
  symbol: data.s,
775
905
  createdAtMs: data.cts
776
906
  };
777
- if (data.dec) {
778
- result.decimals = data.dec;
779
- }
780
- if (data.lf) {
781
- const lf = data.lf;
782
- result.launchFrom = {};
783
- if (lf.pa) {
784
- result.launchFrom.programAddress = lf.pa;
785
- }
786
- if (lf.pf) {
787
- result.launchFrom.protocolFamily = lf.pf;
788
- }
789
- if (lf.pn) {
790
- result.launchFrom.protocolName = lf.pn;
791
- }
792
- }
907
+ if (data.dec != null) result.decimals = data.dec;
908
+ if (data.iu != null) result.imageUrl = data.iu;
909
+ if (data.de != null) result.description = data.de;
910
+ if (data.sm) result.socialMedia = this.parseSocialMedia(data.sm);
911
+ if (data.cgi != null) result.coingeckoCoinId = data.cgi;
912
+ if (data.lf) result.launchFrom = this.parseDexProtocol(data.lf);
913
+ if (data.mt) result.migratedTo = this.parseDexProtocol(data.mt);
793
914
  callback(result);
794
915
  },
795
916
  filter,
796
917
  "subscribeNewToken"
797
918
  );
798
919
  }
920
+ /**
921
+ * Subscribe to new tokens metadata (batch, aggregated every 1 second)
922
+ * Channel: dex-new-tokens-metadata:{chain}
923
+ * No CEL filter support
924
+ */
799
925
  subscribeNewTokensMetadata({
800
926
  chain,
801
927
  callback
@@ -803,35 +929,22 @@ var StreamApi = class {
803
929
  const channel = `dex-new-tokens-metadata:${chain}`;
804
930
  return this.subscribe(
805
931
  channel,
806
- (data) => callback(
807
- data.map((it) => ({
808
- tokenAddress: it.a,
809
- name: it.n,
810
- symbol: it.s,
811
- imageUrl: it.iu,
812
- description: it.de,
813
- socialMedia: (() => {
814
- const sm = it.sm;
815
- if (!sm) return void 0;
816
- return {
817
- twitter: sm.tw,
818
- telegram: sm.tg,
819
- website: sm.w,
820
- tiktok: sm.tt,
821
- discord: sm.dc,
822
- facebook: sm.fb,
823
- github: sm.gh,
824
- instagram: sm.ig,
825
- linkedin: sm.li,
826
- medium: sm.md,
827
- reddit: sm.rd,
828
- youtube: sm.yt,
829
- bitbucket: sm.bb
830
- };
831
- })(),
832
- createdAtMs: it.cts
833
- }))
834
- )
932
+ (data) => callback(data.map((it) => this.parseTokenMetadata(it)))
933
+ );
934
+ }
935
+ /**
936
+ * Subscribe to new tokens list (batch from token-created-to-realtime-pipeline)
937
+ * Channel: dex-new-tokens:{chain}
938
+ * No CEL filter support
939
+ */
940
+ subscribeNewTokens({
941
+ chain,
942
+ callback
943
+ }) {
944
+ const channel = `dex-new-tokens:${chain}`;
945
+ return this.subscribe(
946
+ channel,
947
+ (data) => callback(data.map((it) => this.parseTokenMetadata(it)))
835
948
  );
836
949
  }
837
950
  subscribeTokenSupply({
@@ -980,73 +1093,13 @@ var StreamApi = class {
980
1093
  result.metadata.createdAtMs = t.cts;
981
1094
  }
982
1095
  if (t.lf) {
983
- const lf = t.lf;
984
- result.metadata.launchFrom = {};
985
- if (lf.pa) {
986
- result.metadata.launchFrom.programAddress = lf.pa;
987
- }
988
- if (lf.pf) {
989
- result.metadata.launchFrom.protocolFamily = lf.pf;
990
- }
991
- if (lf.pn) {
992
- result.metadata.launchFrom.protocolName = lf.pn;
993
- }
1096
+ result.metadata.launchFrom = this.parseDexProtocol(t.lf);
994
1097
  }
995
1098
  if (t.mt) {
996
- const mt = t.mt;
997
- result.metadata.migratedTo = {};
998
- if (mt.pa) {
999
- result.metadata.migratedTo.programAddress = mt.pa;
1000
- }
1001
- if (mt.pf) {
1002
- result.metadata.migratedTo.protocolFamily = mt.pf;
1003
- }
1004
- if (mt.pn) {
1005
- result.metadata.migratedTo.protocolName = mt.pn;
1006
- }
1099
+ result.metadata.migratedTo = this.parseDexProtocol(t.mt);
1007
1100
  }
1008
1101
  if (t.sm) {
1009
- const sm = t.sm;
1010
- result.metadata.socialMedia = {};
1011
- if (sm.tw) {
1012
- result.metadata.socialMedia.twitter = sm.tw;
1013
- }
1014
- if (sm.tg) {
1015
- result.metadata.socialMedia.telegram = sm.tg;
1016
- }
1017
- if (sm.w) {
1018
- result.metadata.socialMedia.website = sm.w;
1019
- }
1020
- if (sm.tt) {
1021
- result.metadata.socialMedia.tiktok = sm.tt;
1022
- }
1023
- if (sm.dc) {
1024
- result.metadata.socialMedia.discord = sm.dc;
1025
- }
1026
- if (sm.fb) {
1027
- result.metadata.socialMedia.facebook = sm.fb;
1028
- }
1029
- if (sm.gh) {
1030
- result.metadata.socialMedia.github = sm.gh;
1031
- }
1032
- if (sm.ig) {
1033
- result.metadata.socialMedia.instagram = sm.ig;
1034
- }
1035
- if (sm.li) {
1036
- result.metadata.socialMedia.linkedin = sm.li;
1037
- }
1038
- if (sm.md) {
1039
- result.metadata.socialMedia.medium = sm.md;
1040
- }
1041
- if (sm.rd) {
1042
- result.metadata.socialMedia.reddit = sm.rd;
1043
- }
1044
- if (sm.yt) {
1045
- result.metadata.socialMedia.youtube = sm.yt;
1046
- }
1047
- if (sm.bb) {
1048
- result.metadata.socialMedia.bitbucket = sm.bb;
1049
- }
1102
+ result.metadata.socialMedia = this.parseSocialMedia(t.sm);
1050
1103
  }
1051
1104
  }
1052
1105
  if (bc) {
@@ -2145,6 +2198,7 @@ __export(wallet_exports, {
2145
2198
  calculatePnl: () => calculatePnl,
2146
2199
  getBalanceUpdates: () => getBalanceUpdates,
2147
2200
  getNetWorth: () => getNetWorth,
2201
+ getNetWorthByTokens: () => getNetWorthByTokens,
2148
2202
  getNetWorthChart: () => getNetWorthChart,
2149
2203
  getNetWorthDetails: () => getNetWorthDetails,
2150
2204
  getNetWorthSummary: () => getNetWorthSummary,
@@ -2192,6 +2246,12 @@ var getNetWorth = (chain, walletAddress, params, options) => {
2192
2246
  options
2193
2247
  );
2194
2248
  };
2249
+ var getNetWorthByTokens = (chain, walletAddress, params, options) => {
2250
+ return chainstreamApiClient(
2251
+ { url: `/v1/wallet/${chain}/${walletAddress}/net-worth/tokens`, method: "GET", params },
2252
+ options
2253
+ );
2254
+ };
2195
2255
  var getTokensBalance = (chain, walletAddress, params, options) => {
2196
2256
  return chainstreamApiClient(
2197
2257
  { url: `/v1/wallet/${chain}/${walletAddress}/tokens-balance`, method: "GET", params },
@@ -2282,7 +2342,7 @@ var ChainStreamClient = class {
2282
2342
  __publicField(this, "jobs");
2283
2343
  __publicField(this, "kyt");
2284
2344
  __publicField(this, "endpoint");
2285
- const baseUrl = options.serverUrl ?? "https://api-dex.chainstream.io";
2345
+ const baseUrl = options.serverUrl ?? "https://api.chainstream.io";
2286
2346
  const streamUrl = options.streamUrl ?? "wss://realtime-dex.chainstream.io/connection/websocket";
2287
2347
  this.requestCtx = { baseUrl, streamUrl, accessToken };
2288
2348
  configure({