@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.
package/dist/index.cjs CHANGED
@@ -169,6 +169,7 @@ __export(index_exports, {
169
169
  getMigratedTokens: () => getMigratedTokens,
170
170
  getMintAndBurn: () => getMintAndBurn,
171
171
  getNetWorth: () => getNetWorth,
172
+ getNetWorthByTokens: () => getNetWorthByTokens,
172
173
  getNetWorthChart: () => getNetWorthChart,
173
174
  getNetWorthDetails: () => getNetWorthDetails,
174
175
  getNetWorthSummary: () => getNetWorthSummary,
@@ -247,7 +248,7 @@ var import_axios_retry = __toESM(require("axios-retry"), 1);
247
248
  var axiosInstance;
248
249
  var currentOptions = void 0;
249
250
  var configure = (options) => {
250
- const baseURL = options.basePath || "https://api-dex.chainstream.io";
251
+ const baseURL = options.basePath || "https://api.chainstream.io";
251
252
  currentOptions = {
252
253
  ...options,
253
254
  basePath: baseURL
@@ -471,12 +472,35 @@ var CEL_FIELD_MAPPINGS = {
471
472
  balanceTagRatRatio: "btrr",
472
473
  timestamp: "ts"
473
474
  },
474
- // New token subscription fields
475
+ // New token subscription fields (dex-new-token, supports CEL filter)
475
476
  subscribeNewToken: {
476
477
  tokenAddress: "a",
477
478
  name: "n",
478
479
  symbol: "s",
479
- createdAtMs: "cts"
480
+ decimals: "dec",
481
+ imageUrl: "iu",
482
+ description: "de",
483
+ createdAtMs: "cts",
484
+ coingeckoCoinId: "cgi",
485
+ "socialMedia.twitter": "sm.tw",
486
+ "socialMedia.telegram": "sm.tg",
487
+ "socialMedia.website": "sm.w",
488
+ "socialMedia.tiktok": "sm.tt",
489
+ "socialMedia.discord": "sm.dc",
490
+ "socialMedia.facebook": "sm.fb",
491
+ "socialMedia.github": "sm.gh",
492
+ "socialMedia.instagram": "sm.ig",
493
+ "socialMedia.linkedin": "sm.li",
494
+ "socialMedia.medium": "sm.md",
495
+ "socialMedia.reddit": "sm.rd",
496
+ "socialMedia.youtube": "sm.yt",
497
+ "socialMedia.bitbucket": "sm.bb",
498
+ "launchFrom.programAddress": "lf.pa",
499
+ "launchFrom.protocolFamily": "lf.pf",
500
+ "launchFrom.protocolName": "lf.pn",
501
+ "migratedTo.programAddress": "mt.pa",
502
+ "migratedTo.protocolFamily": "mt.pf",
503
+ "migratedTo.protocolName": "mt.pn"
480
504
  },
481
505
  // Token supply subscription fields
482
506
  subscribeTokenSupply: {
@@ -499,15 +523,65 @@ var CEL_FIELD_MAPPINGS = {
499
523
  value: "v",
500
524
  timestamp: "ts"
501
525
  },
502
- // New token metadata subscription fields
526
+ // New token metadata subscription fields (dex-new-tokens-metadata)
503
527
  subscribeNewTokensMetadata: {
504
528
  tokenAddress: "a",
505
529
  name: "n",
530
+ decimals: "dec",
531
+ symbol: "s",
532
+ imageUrl: "iu",
533
+ description: "de",
534
+ createdAtMs: "cts",
535
+ coingeckoCoinId: "cgi",
536
+ "socialMedia.twitter": "sm.tw",
537
+ "socialMedia.telegram": "sm.tg",
538
+ "socialMedia.website": "sm.w",
539
+ "socialMedia.tiktok": "sm.tt",
540
+ "socialMedia.discord": "sm.dc",
541
+ "socialMedia.facebook": "sm.fb",
542
+ "socialMedia.github": "sm.gh",
543
+ "socialMedia.instagram": "sm.ig",
544
+ "socialMedia.linkedin": "sm.li",
545
+ "socialMedia.medium": "sm.md",
546
+ "socialMedia.reddit": "sm.rd",
547
+ "socialMedia.youtube": "sm.yt",
548
+ "socialMedia.bitbucket": "sm.bb",
549
+ "launchFrom.programAddress": "lf.pa",
550
+ "launchFrom.protocolFamily": "lf.pf",
551
+ "launchFrom.protocolName": "lf.pn",
552
+ "migratedTo.programAddress": "mt.pa",
553
+ "migratedTo.protocolFamily": "mt.pf",
554
+ "migratedTo.protocolName": "mt.pn"
555
+ },
556
+ // New tokens list subscription fields (dex-new-tokens)
557
+ subscribeNewTokens: {
558
+ tokenAddress: "a",
559
+ name: "n",
560
+ decimals: "dec",
506
561
  symbol: "s",
507
562
  imageUrl: "iu",
508
563
  description: "de",
509
- socialMedia: "sm",
510
- createdAtMs: "cts"
564
+ createdAtMs: "cts",
565
+ coingeckoCoinId: "cgi",
566
+ "socialMedia.twitter": "sm.tw",
567
+ "socialMedia.telegram": "sm.tg",
568
+ "socialMedia.website": "sm.w",
569
+ "socialMedia.tiktok": "sm.tt",
570
+ "socialMedia.discord": "sm.dc",
571
+ "socialMedia.facebook": "sm.fb",
572
+ "socialMedia.github": "sm.gh",
573
+ "socialMedia.instagram": "sm.ig",
574
+ "socialMedia.linkedin": "sm.li",
575
+ "socialMedia.medium": "sm.md",
576
+ "socialMedia.reddit": "sm.rd",
577
+ "socialMedia.youtube": "sm.yt",
578
+ "socialMedia.bitbucket": "sm.bb",
579
+ "launchFrom.programAddress": "lf.pa",
580
+ "launchFrom.protocolFamily": "lf.pf",
581
+ "launchFrom.protocolName": "lf.pn",
582
+ "migratedTo.programAddress": "mt.pa",
583
+ "migratedTo.protocolFamily": "mt.pf",
584
+ "migratedTo.protocolName": "mt.pn"
511
585
  },
512
586
  // Token trades subscription fields
513
587
  subscribeTokenTrades: {
@@ -583,12 +657,14 @@ function replaceFilterFields(filter, methodName) {
583
657
  }
584
658
  const fieldMappings = getFieldMappings(methodName);
585
659
  let result = filter;
586
- for (const [longField, shortField] of Object.entries(fieldMappings)) {
660
+ const sortedEntries = Object.entries(fieldMappings).sort(([a], [b]) => b.length - a.length);
661
+ for (const [longField, shortField] of sortedEntries) {
662
+ const escapedField = longField.replace(/\./g, "\\.");
587
663
  const patterns = [
588
- // Pattern 1: fieldName (without meta. prefix)
589
- new RegExp(`\\b${longField}\\b`, "g"),
590
- // Pattern 2: meta.fieldName (with meta. prefix)
591
- new RegExp(`\\bmeta\\.${longField}\\b`, "g")
664
+ // Pattern 1: meta.fieldName (with meta. prefix) — check first to avoid double meta.
665
+ new RegExp(`\\bmeta\\.${escapedField}\\b`, "g"),
666
+ // Pattern 2: fieldName (without meta. prefix)
667
+ new RegExp(`\\b${escapedField}\\b`, "g")
592
668
  ];
593
669
  patterns.forEach((pattern) => {
594
670
  result = result.replace(pattern, `meta.${shortField}`);
@@ -895,6 +971,57 @@ var StreamApi = class {
895
971
  [`liquidityChangeRatio${suffix}`]: this.formatScientificNotation(data[`lpc${suffix}`])
896
972
  };
897
973
  }
974
+ /**
975
+ * Parse social media data from short field names
976
+ */
977
+ parseSocialMedia(sm) {
978
+ if (!sm) return void 0;
979
+ return {
980
+ twitter: sm.tw,
981
+ telegram: sm.tg,
982
+ website: sm.w,
983
+ tiktok: sm.tt,
984
+ discord: sm.dc,
985
+ facebook: sm.fb,
986
+ github: sm.gh,
987
+ instagram: sm.ig,
988
+ linkedin: sm.li,
989
+ medium: sm.md,
990
+ reddit: sm.rd,
991
+ youtube: sm.yt,
992
+ bitbucket: sm.bb
993
+ };
994
+ }
995
+ /**
996
+ * Parse DEX protocol data from short field names
997
+ */
998
+ parseDexProtocol(lf) {
999
+ if (!lf) return void 0;
1000
+ const result = {};
1001
+ if (lf.pa) result.programAddress = lf.pa;
1002
+ if (lf.pf) result.protocolFamily = lf.pf;
1003
+ if (lf.pn) result.protocolName = lf.pn;
1004
+ return result;
1005
+ }
1006
+ /**
1007
+ * Parse a TokenMetadataTimeEvent from raw WebSocket data
1008
+ */
1009
+ parseTokenMetadata(data) {
1010
+ const result = {
1011
+ tokenAddress: data.a
1012
+ };
1013
+ if (data.n != null) result.name = data.n;
1014
+ if (data.dec != null) result.decimals = data.dec;
1015
+ if (data.s != null) result.symbol = data.s;
1016
+ if (data.iu != null) result.imageUrl = data.iu;
1017
+ if (data.de != null) result.description = data.de;
1018
+ if (data.sm) result.socialMedia = this.parseSocialMedia(data.sm);
1019
+ if (data.cts != null) result.createdAtMs = data.cts;
1020
+ if (data.cgi != null) result.coingeckoCoinId = data.cgi;
1021
+ if (data.lf) result.launchFrom = this.parseDexProtocol(data.lf);
1022
+ if (data.mt) result.migratedTo = this.parseDexProtocol(data.mt);
1023
+ return result;
1024
+ }
898
1025
  /**
899
1026
  * Subscribe to token trade statistics
900
1027
  * Channel: dex-token-stats:{chain}_{tokenAddress}
@@ -995,6 +1122,10 @@ var StreamApi = class {
995
1122
  "subscribeTokenHolders"
996
1123
  );
997
1124
  }
1125
+ /**
1126
+ * Subscribe to new token events (single token per event, supports CEL filter)
1127
+ * Channel: dex-new-token:{chain}
1128
+ */
998
1129
  subscribeNewToken({
999
1130
  chain,
1000
1131
  callback,
@@ -1010,28 +1141,24 @@ var StreamApi = class {
1010
1141
  symbol: data.s,
1011
1142
  createdAtMs: data.cts
1012
1143
  };
1013
- if (data.dec) {
1014
- result.decimals = data.dec;
1015
- }
1016
- if (data.lf) {
1017
- const lf = data.lf;
1018
- result.launchFrom = {};
1019
- if (lf.pa) {
1020
- result.launchFrom.programAddress = lf.pa;
1021
- }
1022
- if (lf.pf) {
1023
- result.launchFrom.protocolFamily = lf.pf;
1024
- }
1025
- if (lf.pn) {
1026
- result.launchFrom.protocolName = lf.pn;
1027
- }
1028
- }
1144
+ if (data.dec != null) result.decimals = data.dec;
1145
+ if (data.iu != null) result.imageUrl = data.iu;
1146
+ if (data.de != null) result.description = data.de;
1147
+ if (data.sm) result.socialMedia = this.parseSocialMedia(data.sm);
1148
+ if (data.cgi != null) result.coingeckoCoinId = data.cgi;
1149
+ if (data.lf) result.launchFrom = this.parseDexProtocol(data.lf);
1150
+ if (data.mt) result.migratedTo = this.parseDexProtocol(data.mt);
1029
1151
  callback(result);
1030
1152
  },
1031
1153
  filter,
1032
1154
  "subscribeNewToken"
1033
1155
  );
1034
1156
  }
1157
+ /**
1158
+ * Subscribe to new tokens metadata (batch, aggregated every 1 second)
1159
+ * Channel: dex-new-tokens-metadata:{chain}
1160
+ * No CEL filter support
1161
+ */
1035
1162
  subscribeNewTokensMetadata({
1036
1163
  chain,
1037
1164
  callback
@@ -1039,35 +1166,22 @@ var StreamApi = class {
1039
1166
  const channel = `dex-new-tokens-metadata:${chain}`;
1040
1167
  return this.subscribe(
1041
1168
  channel,
1042
- (data) => callback(
1043
- data.map((it) => ({
1044
- tokenAddress: it.a,
1045
- name: it.n,
1046
- symbol: it.s,
1047
- imageUrl: it.iu,
1048
- description: it.de,
1049
- socialMedia: (() => {
1050
- const sm = it.sm;
1051
- if (!sm) return void 0;
1052
- return {
1053
- twitter: sm.tw,
1054
- telegram: sm.tg,
1055
- website: sm.w,
1056
- tiktok: sm.tt,
1057
- discord: sm.dc,
1058
- facebook: sm.fb,
1059
- github: sm.gh,
1060
- instagram: sm.ig,
1061
- linkedin: sm.li,
1062
- medium: sm.md,
1063
- reddit: sm.rd,
1064
- youtube: sm.yt,
1065
- bitbucket: sm.bb
1066
- };
1067
- })(),
1068
- createdAtMs: it.cts
1069
- }))
1070
- )
1169
+ (data) => callback(data.map((it) => this.parseTokenMetadata(it)))
1170
+ );
1171
+ }
1172
+ /**
1173
+ * Subscribe to new tokens list (batch from token-created-to-realtime-pipeline)
1174
+ * Channel: dex-new-tokens:{chain}
1175
+ * No CEL filter support
1176
+ */
1177
+ subscribeNewTokens({
1178
+ chain,
1179
+ callback
1180
+ }) {
1181
+ const channel = `dex-new-tokens:${chain}`;
1182
+ return this.subscribe(
1183
+ channel,
1184
+ (data) => callback(data.map((it) => this.parseTokenMetadata(it)))
1071
1185
  );
1072
1186
  }
1073
1187
  subscribeTokenSupply({
@@ -1216,73 +1330,13 @@ var StreamApi = class {
1216
1330
  result.metadata.createdAtMs = t.cts;
1217
1331
  }
1218
1332
  if (t.lf) {
1219
- const lf = t.lf;
1220
- result.metadata.launchFrom = {};
1221
- if (lf.pa) {
1222
- result.metadata.launchFrom.programAddress = lf.pa;
1223
- }
1224
- if (lf.pf) {
1225
- result.metadata.launchFrom.protocolFamily = lf.pf;
1226
- }
1227
- if (lf.pn) {
1228
- result.metadata.launchFrom.protocolName = lf.pn;
1229
- }
1333
+ result.metadata.launchFrom = this.parseDexProtocol(t.lf);
1230
1334
  }
1231
1335
  if (t.mt) {
1232
- const mt = t.mt;
1233
- result.metadata.migratedTo = {};
1234
- if (mt.pa) {
1235
- result.metadata.migratedTo.programAddress = mt.pa;
1236
- }
1237
- if (mt.pf) {
1238
- result.metadata.migratedTo.protocolFamily = mt.pf;
1239
- }
1240
- if (mt.pn) {
1241
- result.metadata.migratedTo.protocolName = mt.pn;
1242
- }
1336
+ result.metadata.migratedTo = this.parseDexProtocol(t.mt);
1243
1337
  }
1244
1338
  if (t.sm) {
1245
- const sm = t.sm;
1246
- result.metadata.socialMedia = {};
1247
- if (sm.tw) {
1248
- result.metadata.socialMedia.twitter = sm.tw;
1249
- }
1250
- if (sm.tg) {
1251
- result.metadata.socialMedia.telegram = sm.tg;
1252
- }
1253
- if (sm.w) {
1254
- result.metadata.socialMedia.website = sm.w;
1255
- }
1256
- if (sm.tt) {
1257
- result.metadata.socialMedia.tiktok = sm.tt;
1258
- }
1259
- if (sm.dc) {
1260
- result.metadata.socialMedia.discord = sm.dc;
1261
- }
1262
- if (sm.fb) {
1263
- result.metadata.socialMedia.facebook = sm.fb;
1264
- }
1265
- if (sm.gh) {
1266
- result.metadata.socialMedia.github = sm.gh;
1267
- }
1268
- if (sm.ig) {
1269
- result.metadata.socialMedia.instagram = sm.ig;
1270
- }
1271
- if (sm.li) {
1272
- result.metadata.socialMedia.linkedin = sm.li;
1273
- }
1274
- if (sm.md) {
1275
- result.metadata.socialMedia.medium = sm.md;
1276
- }
1277
- if (sm.rd) {
1278
- result.metadata.socialMedia.reddit = sm.rd;
1279
- }
1280
- if (sm.yt) {
1281
- result.metadata.socialMedia.youtube = sm.yt;
1282
- }
1283
- if (sm.bb) {
1284
- result.metadata.socialMedia.bitbucket = sm.bb;
1285
- }
1339
+ result.metadata.socialMedia = this.parseSocialMedia(t.sm);
1286
1340
  }
1287
1341
  }
1288
1342
  if (bc) {
@@ -2420,6 +2474,7 @@ __export(wallet_exports, {
2420
2474
  calculatePnl: () => calculatePnl,
2421
2475
  getBalanceUpdates: () => getBalanceUpdates,
2422
2476
  getNetWorth: () => getNetWorth,
2477
+ getNetWorthByTokens: () => getNetWorthByTokens,
2423
2478
  getNetWorthChart: () => getNetWorthChart,
2424
2479
  getNetWorthDetails: () => getNetWorthDetails,
2425
2480
  getNetWorthSummary: () => getNetWorthSummary,
@@ -2467,6 +2522,12 @@ var getNetWorth = (chain, walletAddress, params, options) => {
2467
2522
  options
2468
2523
  );
2469
2524
  };
2525
+ var getNetWorthByTokens = (chain, walletAddress, params, options) => {
2526
+ return chainstreamApiClient(
2527
+ { url: `/v1/wallet/${chain}/${walletAddress}/net-worth/tokens`, method: "GET", params },
2528
+ options
2529
+ );
2530
+ };
2470
2531
  var getTokensBalance = (chain, walletAddress, params, options) => {
2471
2532
  return chainstreamApiClient(
2472
2533
  { url: `/v1/wallet/${chain}/${walletAddress}/tokens-balance`, method: "GET", params },
@@ -2557,7 +2618,7 @@ var ChainStreamClient = class {
2557
2618
  __publicField(this, "jobs");
2558
2619
  __publicField(this, "kyt");
2559
2620
  __publicField(this, "endpoint");
2560
- const baseUrl = options.serverUrl ?? "https://api-dex.chainstream.io";
2621
+ const baseUrl = options.serverUrl ?? "https://api.chainstream.io";
2561
2622
  const streamUrl = options.streamUrl ?? "wss://realtime-dex.chainstream.io/connection/websocket";
2562
2623
  this.requestCtx = { baseUrl, streamUrl, accessToken };
2563
2624
  configure({
@@ -3611,6 +3672,7 @@ var ListEndpointsOrder = {
3611
3672
  getMigratedTokens,
3612
3673
  getMintAndBurn,
3613
3674
  getNetWorth,
3675
+ getNetWorthByTokens,
3614
3676
  getNetWorthChart,
3615
3677
  getNetWorthDetails,
3616
3678
  getNetWorthSummary,