@basedone/core 0.0.7 → 0.0.9

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.mjs CHANGED
@@ -208,7 +208,8 @@ var CloidClientCode = {
208
208
  Grid: 5,
209
209
  Chase: 6,
210
210
  Desktop: 7,
211
- API: 8
211
+ API: 8,
212
+ Stream: 9
212
213
  };
213
214
  var CloidClientCodeNameById = {
214
215
  [CloidClientCode.Unset]: "Unset",
@@ -219,7 +220,8 @@ var CloidClientCodeNameById = {
219
220
  [CloidClientCode.Grid]: "Grid",
220
221
  [CloidClientCode.Chase]: "Chase",
221
222
  [CloidClientCode.Desktop]: "Desktop",
222
- [CloidClientCode.API]: "API"
223
+ [CloidClientCode.API]: "API",
224
+ [CloidClientCode.Stream]: "Stream"
223
225
  };
224
226
  function getClientCodeNameById(id) {
225
227
  return CloidClientCodeNameById[id] ?? `client_${id}`;
@@ -229,13 +231,15 @@ var WidgetType = {
229
231
  // 0x00
230
232
  SidePanel: 1,
231
233
  Widget: 2,
232
- FloatingWidget: 3
234
+ FloatingWidget: 3,
235
+ Stream: 4
233
236
  };
234
237
  var WidgetTypeById = {
235
238
  [WidgetType.Unset]: "Unset",
236
239
  [WidgetType.SidePanel]: "SidePanel",
237
240
  [WidgetType.Widget]: "Widget",
238
- [WidgetType.FloatingWidget]: "FloatingWidget"
241
+ [WidgetType.FloatingWidget]: "FloatingWidget",
242
+ [WidgetType.Stream]: "Stream"
239
243
  };
240
244
  function getWidgetTypeById(id) {
241
245
  return WidgetTypeById[id] ?? `widget_${id}`;
@@ -537,15 +541,76 @@ import {
537
541
  } from "@nktkas/hyperliquid";
538
542
 
539
543
  // lib/hip3/utils.ts
544
+ import {
545
+ signL1Action,
546
+ signUserSignedAction
547
+ } from "@nktkas/hyperliquid/signing";
540
548
  function isHip3Symbol(symbol) {
541
549
  if (!symbol) return false;
542
550
  return symbol.includes(":");
543
551
  }
552
+ function getHip3Dex(symbol) {
553
+ if (!symbol) return null;
554
+ return symbol.split(":")[0];
555
+ }
556
+ async function enableHip3DexAbstractionWithAgent(client) {
557
+ const nonce = Date.now();
558
+ const action = {
559
+ type: "agentEnableDexAbstraction"
560
+ };
561
+ const signature = await signL1Action({
562
+ wallet: client.wallet,
563
+ action,
564
+ isTestnet: client.isTestnet,
565
+ nonce
566
+ });
567
+ return await client.transport.request("exchange", {
568
+ action,
569
+ signature,
570
+ nonce
571
+ });
572
+ }
573
+ var UserDexAbstractionTypes = {
574
+ "HyperliquidTransaction:UserDexAbstraction": [
575
+ { name: "hyperliquidChain", type: "string" },
576
+ { name: "user", type: "address" },
577
+ { name: "enabled", type: "bool" },
578
+ { name: "nonce", type: "uint64" }
579
+ ]
580
+ };
581
+ async function setHip3DexAbstraction(client, enabled, user) {
582
+ const nonce = Date.now();
583
+ const isTestnet = client.isTestnet;
584
+ const action = {
585
+ type: "userDexAbstraction",
586
+ hyperliquidChain: isTestnet ? "Testnet" : "Mainnet",
587
+ signatureChainId: isTestnet ? "0x66eee" : "0xa4b1",
588
+ user,
589
+ enabled,
590
+ nonce
591
+ };
592
+ const signature = await signUserSignedAction({
593
+ wallet: client.wallet,
594
+ action,
595
+ types: UserDexAbstractionTypes
596
+ });
597
+ return await client.transport.request("exchange", {
598
+ action,
599
+ signature,
600
+ nonce: action.nonce
601
+ });
602
+ }
603
+ async function getHip3DexAbstraction(client, user) {
604
+ return await client.transport.request("info", {
605
+ type: "userDexAbstraction",
606
+ user
607
+ });
608
+ }
544
609
 
545
610
  // import("./data/**/*/staticMeta.json") in lib/meta/metadata.ts
546
611
  var globImport_data_staticMeta_json = __glob({
547
- "./data/mainnet/staticMeta.json": () => import("./staticMeta-HRXST42O.mjs"),
548
- "./data/testnet/staticMeta.json": () => import("./staticMeta-QWPQK3MD.mjs")
612
+ "./data/mainnet/staticMeta.json": () => import("./staticMeta-QV2KMX57.mjs"),
613
+ "./data/testnet/staticMeta.json": () => import("./staticMeta-GM7T3OYL.mjs")
549
614
  });
550
615
 
551
616
  // import("./data/**/*/spotMeta.json") in lib/meta/metadata.ts
@@ -593,6 +658,7 @@ var MetadataClient = class {
593
658
  this.dexNameToIndex = /* @__PURE__ */ new Map();
594
659
  // Lazy init flag
595
660
  this.initialized = false;
661
+ this.initializing = null;
596
662
  const transport = new HttpTransport({
597
663
  isTestnet: config.isTestnet ?? false
598
664
  });
@@ -610,44 +676,54 @@ var MetadataClient = class {
610
676
  */
611
677
  async initialize() {
612
678
  if (this.initialized) return;
613
- await this.loadStaticMetaOverrides();
614
- if (this.config.onlyUseStaticFallback) {
615
- await this.loadStaticMetadata();
616
- this.buildLookupMaps();
617
- if (this.config.hip3Dexs && this.config.hip3Dexs.length > 0) {
618
- await Promise.all(
619
- this.config.hip3Dexs.map((dex) => this.loadHip3Metadata(dex))
620
- );
621
- }
622
- this.initialized = true;
623
- return;
624
- }
625
- try {
626
- [this.spotMeta, this.perpsMeta, this.perpDexs] = await Promise.all([
627
- this.infoClient.spotMeta(),
628
- this.infoClient.meta(),
629
- this.infoClient.perpDexs()
630
- ]);
631
- this.buildLookupMaps();
632
- if (this.config.hip3Dexs && this.config.hip3Dexs.length > 0) {
633
- await Promise.all(
634
- this.config.hip3Dexs.map((dex) => this.loadHip3Metadata(dex))
635
- );
636
- }
637
- this.initialized = true;
638
- } catch (error) {
639
- if (this.config.useStaticFallback) {
640
- console.warn(
641
- "Failed to fetch metadata from API, using static fallback data",
642
- error
643
- );
679
+ if (this.initializing) return this.initializing;
680
+ this.initializing = new Promise(async (resolve, reject) => {
681
+ await this.loadStaticMetaOverrides();
682
+ if (this.config.onlyUseStaticFallback) {
644
683
  await this.loadStaticMetadata();
645
684
  this.buildLookupMaps();
685
+ if (this.config.hip3Dexs && this.config.hip3Dexs.length > 0) {
686
+ await Promise.all(
687
+ this.config.hip3Dexs.map((dex) => this.loadHip3Metadata(dex))
688
+ );
689
+ }
690
+ resolve();
646
691
  this.initialized = true;
647
- } else {
648
- throw error;
692
+ return;
649
693
  }
650
- }
694
+ try {
695
+ [this.spotMeta, this.perpsMeta, this.perpDexs] = await Promise.all([
696
+ this.infoClient.spotMeta(),
697
+ this.infoClient.meta(),
698
+ this.infoClient.perpDexs()
699
+ ]);
700
+ this.buildLookupMaps();
701
+ if (this.config.hip3Dexs && this.config.hip3Dexs.length > 0) {
702
+ await Promise.all(
703
+ this.config.hip3Dexs.map((dex) => this.loadHip3Metadata(dex))
704
+ );
705
+ }
706
+ this.initialized = true;
707
+ resolve();
708
+ } catch (error) {
709
+ if (this.config.useStaticFallback) {
710
+ console.warn(
711
+ "Failed to fetch metadata from API, using static fallback data",
712
+ error
713
+ );
714
+ await this.loadStaticMetadata();
715
+ this.buildLookupMaps();
716
+ this.initialized = true;
717
+ resolve();
718
+ } else {
719
+ reject(error);
720
+ }
721
+ } finally {
722
+ this.initialized = true;
723
+ resolve();
724
+ }
725
+ });
726
+ return this.initializing;
651
727
  }
652
728
  /**
653
729
  * Load staticMeta.json for display overrides
@@ -700,9 +776,14 @@ var MetadataClient = class {
700
776
  this.spotPairToMarket.clear();
701
777
  this.baseTokenToMarkets.clear();
702
778
  this.coinToMarket.clear();
703
- this.hip3SymbolToMarket.clear();
704
779
  this.dexNameToIndex.clear();
705
780
  this.quoteAssets = [];
781
+ console.info(
782
+ "[MetadataClient] Building lookup maps",
783
+ this.perpDexs,
784
+ this.perpsMeta,
785
+ this.spotMeta
786
+ );
706
787
  if (this.perpDexs) {
707
788
  this.perpDexs.forEach((dex, index) => {
708
789
  if (dex && dex.name) {
@@ -813,6 +894,9 @@ var MetadataClient = class {
813
894
  if (staticDexOverrides.imageUrl) {
814
895
  dexInfo.imageUrl = staticDexOverrides.imageUrl;
815
896
  }
897
+ if (staticDexOverrides.accountName) {
898
+ dexInfo.accountName = staticDexOverrides.accountName;
899
+ }
816
900
  }
817
901
  this.hip3DexsMeta.set(dexName, dexInfo);
818
902
  this.buildHip3MarketsForDex(dexName, dexInfo);
@@ -849,6 +933,7 @@ var MetadataClient = class {
849
933
  marketInfo.imageUrl = staticOverrides.imageUrl;
850
934
  }
851
935
  }
936
+ console.info("[MetadataClient] caching market", symbol, marketInfo);
852
937
  this.coinToMarket.set(symbol, marketInfo);
853
938
  this.hip3SymbolToMarket.set(symbol, marketInfo);
854
939
  });
@@ -937,6 +1022,7 @@ var MetadataClient = class {
937
1022
  if (!dexName || !coinName) return null;
938
1023
  let cachedMarket = this.hip3SymbolToMarket.get(symbol);
939
1024
  if (cachedMarket) return cachedMarket;
1025
+ console.warn("Missing market", symbol, this.hip3SymbolToMarket);
940
1026
  const dexMeta = this.hip3DexsMeta.get(dexName);
941
1027
  if (!dexMeta && this.config.lazyInit) {
942
1028
  await this.loadHip3Metadata(dexName);
@@ -995,7 +1081,9 @@ var MetadataClient = class {
995
1081
  spotMeta: this.spotMeta,
996
1082
  perpsMeta: this.perpsMeta,
997
1083
  perpDexs: this.perpDexs,
998
- hip3DexsMeta: Object.fromEntries(this.hip3DexsMeta)
1084
+ hip3DexsMeta: Object.fromEntries(this.hip3DexsMeta),
1085
+ coinToMarket: Object.fromEntries(this.coinToMarket),
1086
+ hip3SymbolToMarket: Object.fromEntries(this.hip3SymbolToMarket)
999
1087
  };
1000
1088
  }
1001
1089
  /**
@@ -1066,6 +1154,7 @@ export {
1066
1154
  TARGET_APPROVED_MAX_BUILDER_FEE_PERCENT,
1067
1155
  TESTNET_USDC_SPOT_TOKEN,
1068
1156
  USDC_SPOT_TOKEN,
1157
+ UserDexAbstractionTypes,
1069
1158
  WidgetType,
1070
1159
  WidgetTypeById,
1071
1160
  XP_BOOST_PERCENTAGES,
@@ -1073,6 +1162,7 @@ export {
1073
1162
  calculateBoostPercentage,
1074
1163
  calculateTotalPupAmount,
1075
1164
  decodeSlug,
1165
+ enableHip3DexAbstractionWithAgent,
1076
1166
  encodeSlug,
1077
1167
  formatPriceAndSize,
1078
1168
  formatPriceForOrder,
@@ -1080,11 +1170,14 @@ export {
1080
1170
  getApprovalAmount,
1081
1171
  getClientCodeNameById,
1082
1172
  getCloid,
1173
+ getHip3Dex,
1174
+ getHip3DexAbstraction,
1083
1175
  getNextTierInfo,
1084
1176
  getPriceDecimals,
1085
1177
  getWidgetTypeById,
1086
1178
  isBasedCloid,
1087
1179
  isClientCode,
1180
+ isHip3Symbol,
1088
1181
  isMiniAppCloid,
1089
1182
  isMiniAppTriggeredCloid,
1090
1183
  isTenantCloid,
@@ -1093,5 +1186,6 @@ export {
1093
1186
  normaliseSlug,
1094
1187
  normaliseTrackingId,
1095
1188
  normalizeAirdropAmount,
1096
- parseCloid
1189
+ parseCloid,
1190
+ setHip3DexAbstraction
1097
1191
  };