@basedone/core 0.1.4 → 0.1.6

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.d.mts CHANGED
@@ -471,6 +471,18 @@ declare const formatPriceForOrder: ({ px, szDecimals, isSpot, }: {
471
471
  szDecimals: number;
472
472
  isSpot: boolean;
473
473
  }) => number;
474
+ /**
475
+ * Formats price for order placement following Hyperliquid rules
476
+ * - Rounded to priceDecimals of the asset
477
+ * @param px - The price to format
478
+ * @param priceDecimals - Price decimals for the asset
479
+ * @returns Formatted price as number (rounded to priceDecimals if exceeds)
480
+ */
481
+ declare const formatPriceForDisplay: ({ px, szDecimals, isSpot, }: {
482
+ px: number;
483
+ szDecimals: number;
484
+ isSpot: boolean;
485
+ }) => string;
474
486
  /**
475
487
  * Formats size for order placement following Hyperliquid rules
476
488
  * - Rounded to szDecimals of the asset
@@ -482,6 +494,17 @@ declare const formatSizeForOrder: ({ sz, szDecimals, }: {
482
494
  sz: number;
483
495
  szDecimals: number;
484
496
  }) => number;
497
+ /**
498
+ * Formats size for order placement following Hyperliquid rules
499
+ * - Rounded to szDecimals of the asset
500
+ * @param sz - The size to format
501
+ * @param szDecimals - Size decimals for the asset
502
+ * @returns Formatted size as number (rounded down to szDecimals if exceeds)
503
+ */
504
+ declare const formatSizeForDisplay: ({ sz, szDecimals, }: {
505
+ sz: number;
506
+ szDecimals: number;
507
+ }) => string;
485
508
  /**
486
509
  * Get minimum price decimals for tick size calculations
487
510
  * Uses the same logic as internal price formatting
@@ -498,7 +521,7 @@ declare const formatSizeForOrder: ({ sz, szDecimals, }: {
498
521
  */
499
522
  declare function getPriceDecimals(price: number, szDecimals: number, isSpot: boolean): number;
500
523
 
501
- declare function isHip3Symbol(symbol: string): boolean;
524
+ declare function isHip3Symbol(symbol: string | undefined): boolean;
502
525
  declare function getHip3Dex(symbol: string): string | null;
503
526
  /**
504
527
  * Enable HIP-3 DEX abstraction with the current agent wallet
@@ -521,5 +544,24 @@ declare const UserDexAbstractionTypes: {
521
544
  */
522
545
  declare function setHip3DexAbstraction(client: ExchangeClient, enabled: boolean, user: string): Promise<SuccessResponse>;
523
546
  declare function getHip3DexAbstraction(client: InfoClient, user: string): Promise<boolean | null>;
547
+ declare const isSpotSymbol: (coin: string | undefined) => boolean;
548
+ declare function getStaticCollateralTokenByDex(dex: string): string;
549
+ /**
550
+ * Get static collateral token symbol for a given coin
551
+ * @param coin - The coin symbol to get the collateral token symbol for eg. xyz:XYZ100
552
+ * @returns The collateral token symbol for the given coin
553
+ */
554
+ declare function getStaticCollateralTokenSymbol(coin: string | undefined): string;
555
+ /**
556
+ * Get display market symbol for a given coin
557
+ * @param coin - The coin symbol to get the display market symbol for eg. xyz:XYZ100
558
+ * @param showCollateralTokenSymbol - Whether to show the collateral token symbol. Default is true.
559
+ * @returns
560
+ * HIP-3 symbol: The display market symbol for the given coin eg. XYZ100-USDC, BTC-USDE, etc.
561
+ * If showCollateralTokenSymbol is false, returns the symbol without the collateral token symbol. eg. rrrrr:BTC -> BTC, hyena:BTC -> BTC
562
+ * Spot symbol: returns the coin argument itself
563
+ */
564
+ declare function getDisplayMarketSymbol(coin: string | undefined, showCollateralTokenSymbol?: boolean, collateralTokenSymbol?: string): string | undefined;
565
+ declare function getDexFromCollateralTokenSymbol(collateralTokenSymbol: string): string | undefined;
524
566
 
525
- export { type AirdropAllocationData, CloidClientCode, type CloidClientCodeId, CloidClientCodeNameById, type CloidData, type DexInfo, type ExtendedPerpsMeta, type MarketInfo, MetadataClient, PUP_TOKEN_ADDRESS, PUP_TOKEN_THRESHOLDS, type PerpDex, type PupEligibilityResult, ROOT_DEX, TARGET_APPROVED_MAX_BUILDER_FEE, TARGET_APPROVED_MAX_BUILDER_FEE_PERCENT, TESTNET_USDC_SPOT_TOKEN, type TokenInfo, USDC_SPOT_TOKEN, type UpheavalApiResponse, type UpheavalPosition, type UpheavalSnapshot, UserDexAbstractionTypes, type V3LPTokenInfo, WidgetType, WidgetTypeById, type WidgetTypeId, XP_BOOST_PERCENTAGES, buildCloid, calculateBoostPercentage, calculateTotalPupAmount, decodeSlug, enableHip3DexAbstractionWithAgent, encodeSlug, formatPriceAndSize, formatPriceForOrder, formatSizeForOrder, getApprovalAmount, getClientCodeNameById, getCloid, getHip3Dex, getHip3DexAbstraction, getNextTierInfo, getPriceDecimals, getWidgetTypeById, isBasedCloid, isClientCode, isHip3Symbol, isMiniAppCloid, isMiniAppTriggeredCloid, isTenantCloid, isTrackingIdCloid, isWidgetType, normaliseSlug, normaliseTrackingId, normalizeAirdropAmount, parseCloid, setHip3DexAbstraction };
567
+ export { type AirdropAllocationData, CloidClientCode, type CloidClientCodeId, CloidClientCodeNameById, type CloidData, type DexInfo, type ExtendedPerpsMeta, type MarketInfo, MetadataClient, PUP_TOKEN_ADDRESS, PUP_TOKEN_THRESHOLDS, type PerpDex, type PupEligibilityResult, ROOT_DEX, TARGET_APPROVED_MAX_BUILDER_FEE, TARGET_APPROVED_MAX_BUILDER_FEE_PERCENT, TESTNET_USDC_SPOT_TOKEN, type TokenInfo, USDC_SPOT_TOKEN, type UpheavalApiResponse, type UpheavalPosition, type UpheavalSnapshot, UserDexAbstractionTypes, type V3LPTokenInfo, WidgetType, WidgetTypeById, type WidgetTypeId, XP_BOOST_PERCENTAGES, buildCloid, calculateBoostPercentage, calculateTotalPupAmount, decodeSlug, enableHip3DexAbstractionWithAgent, encodeSlug, formatPriceAndSize, formatPriceForDisplay, formatPriceForOrder, formatSizeForDisplay, formatSizeForOrder, getApprovalAmount, getClientCodeNameById, getCloid, getDexFromCollateralTokenSymbol, getDisplayMarketSymbol, getHip3Dex, getHip3DexAbstraction, getNextTierInfo, getPriceDecimals, getStaticCollateralTokenByDex, getStaticCollateralTokenSymbol, getWidgetTypeById, isBasedCloid, isClientCode, isHip3Symbol, isMiniAppCloid, isMiniAppTriggeredCloid, isSpotSymbol, isTenantCloid, isTrackingIdCloid, isWidgetType, normaliseSlug, normaliseTrackingId, normalizeAirdropAmount, parseCloid, setHip3DexAbstraction };
package/dist/index.d.ts CHANGED
@@ -471,6 +471,18 @@ declare const formatPriceForOrder: ({ px, szDecimals, isSpot, }: {
471
471
  szDecimals: number;
472
472
  isSpot: boolean;
473
473
  }) => number;
474
+ /**
475
+ * Formats price for order placement following Hyperliquid rules
476
+ * - Rounded to priceDecimals of the asset
477
+ * @param px - The price to format
478
+ * @param priceDecimals - Price decimals for the asset
479
+ * @returns Formatted price as number (rounded to priceDecimals if exceeds)
480
+ */
481
+ declare const formatPriceForDisplay: ({ px, szDecimals, isSpot, }: {
482
+ px: number;
483
+ szDecimals: number;
484
+ isSpot: boolean;
485
+ }) => string;
474
486
  /**
475
487
  * Formats size for order placement following Hyperliquid rules
476
488
  * - Rounded to szDecimals of the asset
@@ -482,6 +494,17 @@ declare const formatSizeForOrder: ({ sz, szDecimals, }: {
482
494
  sz: number;
483
495
  szDecimals: number;
484
496
  }) => number;
497
+ /**
498
+ * Formats size for order placement following Hyperliquid rules
499
+ * - Rounded to szDecimals of the asset
500
+ * @param sz - The size to format
501
+ * @param szDecimals - Size decimals for the asset
502
+ * @returns Formatted size as number (rounded down to szDecimals if exceeds)
503
+ */
504
+ declare const formatSizeForDisplay: ({ sz, szDecimals, }: {
505
+ sz: number;
506
+ szDecimals: number;
507
+ }) => string;
485
508
  /**
486
509
  * Get minimum price decimals for tick size calculations
487
510
  * Uses the same logic as internal price formatting
@@ -498,7 +521,7 @@ declare const formatSizeForOrder: ({ sz, szDecimals, }: {
498
521
  */
499
522
  declare function getPriceDecimals(price: number, szDecimals: number, isSpot: boolean): number;
500
523
 
501
- declare function isHip3Symbol(symbol: string): boolean;
524
+ declare function isHip3Symbol(symbol: string | undefined): boolean;
502
525
  declare function getHip3Dex(symbol: string): string | null;
503
526
  /**
504
527
  * Enable HIP-3 DEX abstraction with the current agent wallet
@@ -521,5 +544,24 @@ declare const UserDexAbstractionTypes: {
521
544
  */
522
545
  declare function setHip3DexAbstraction(client: ExchangeClient, enabled: boolean, user: string): Promise<SuccessResponse>;
523
546
  declare function getHip3DexAbstraction(client: InfoClient, user: string): Promise<boolean | null>;
547
+ declare const isSpotSymbol: (coin: string | undefined) => boolean;
548
+ declare function getStaticCollateralTokenByDex(dex: string): string;
549
+ /**
550
+ * Get static collateral token symbol for a given coin
551
+ * @param coin - The coin symbol to get the collateral token symbol for eg. xyz:XYZ100
552
+ * @returns The collateral token symbol for the given coin
553
+ */
554
+ declare function getStaticCollateralTokenSymbol(coin: string | undefined): string;
555
+ /**
556
+ * Get display market symbol for a given coin
557
+ * @param coin - The coin symbol to get the display market symbol for eg. xyz:XYZ100
558
+ * @param showCollateralTokenSymbol - Whether to show the collateral token symbol. Default is true.
559
+ * @returns
560
+ * HIP-3 symbol: The display market symbol for the given coin eg. XYZ100-USDC, BTC-USDE, etc.
561
+ * If showCollateralTokenSymbol is false, returns the symbol without the collateral token symbol. eg. rrrrr:BTC -> BTC, hyena:BTC -> BTC
562
+ * Spot symbol: returns the coin argument itself
563
+ */
564
+ declare function getDisplayMarketSymbol(coin: string | undefined, showCollateralTokenSymbol?: boolean, collateralTokenSymbol?: string): string | undefined;
565
+ declare function getDexFromCollateralTokenSymbol(collateralTokenSymbol: string): string | undefined;
524
566
 
525
- export { type AirdropAllocationData, CloidClientCode, type CloidClientCodeId, CloidClientCodeNameById, type CloidData, type DexInfo, type ExtendedPerpsMeta, type MarketInfo, MetadataClient, PUP_TOKEN_ADDRESS, PUP_TOKEN_THRESHOLDS, type PerpDex, type PupEligibilityResult, ROOT_DEX, TARGET_APPROVED_MAX_BUILDER_FEE, TARGET_APPROVED_MAX_BUILDER_FEE_PERCENT, TESTNET_USDC_SPOT_TOKEN, type TokenInfo, USDC_SPOT_TOKEN, type UpheavalApiResponse, type UpheavalPosition, type UpheavalSnapshot, UserDexAbstractionTypes, type V3LPTokenInfo, WidgetType, WidgetTypeById, type WidgetTypeId, XP_BOOST_PERCENTAGES, buildCloid, calculateBoostPercentage, calculateTotalPupAmount, decodeSlug, enableHip3DexAbstractionWithAgent, encodeSlug, formatPriceAndSize, formatPriceForOrder, formatSizeForOrder, getApprovalAmount, getClientCodeNameById, getCloid, getHip3Dex, getHip3DexAbstraction, getNextTierInfo, getPriceDecimals, getWidgetTypeById, isBasedCloid, isClientCode, isHip3Symbol, isMiniAppCloid, isMiniAppTriggeredCloid, isTenantCloid, isTrackingIdCloid, isWidgetType, normaliseSlug, normaliseTrackingId, normalizeAirdropAmount, parseCloid, setHip3DexAbstraction };
567
+ export { type AirdropAllocationData, CloidClientCode, type CloidClientCodeId, CloidClientCodeNameById, type CloidData, type DexInfo, type ExtendedPerpsMeta, type MarketInfo, MetadataClient, PUP_TOKEN_ADDRESS, PUP_TOKEN_THRESHOLDS, type PerpDex, type PupEligibilityResult, ROOT_DEX, TARGET_APPROVED_MAX_BUILDER_FEE, TARGET_APPROVED_MAX_BUILDER_FEE_PERCENT, TESTNET_USDC_SPOT_TOKEN, type TokenInfo, USDC_SPOT_TOKEN, type UpheavalApiResponse, type UpheavalPosition, type UpheavalSnapshot, UserDexAbstractionTypes, type V3LPTokenInfo, WidgetType, WidgetTypeById, type WidgetTypeId, XP_BOOST_PERCENTAGES, buildCloid, calculateBoostPercentage, calculateTotalPupAmount, decodeSlug, enableHip3DexAbstractionWithAgent, encodeSlug, formatPriceAndSize, formatPriceForDisplay, formatPriceForOrder, formatSizeForDisplay, formatSizeForOrder, getApprovalAmount, getClientCodeNameById, getCloid, getDexFromCollateralTokenSymbol, getDisplayMarketSymbol, getHip3Dex, getHip3DexAbstraction, getNextTierInfo, getPriceDecimals, getStaticCollateralTokenByDex, getStaticCollateralTokenSymbol, getWidgetTypeById, isBasedCloid, isClientCode, isHip3Symbol, isMiniAppCloid, isMiniAppTriggeredCloid, isSpotSymbol, isTenantCloid, isTrackingIdCloid, isWidgetType, normaliseSlug, normaliseTrackingId, normalizeAirdropAmount, parseCloid, setHip3DexAbstraction };
package/dist/index.js CHANGED
@@ -37039,21 +37039,28 @@ __export(index_exports, {
37039
37039
  enableHip3DexAbstractionWithAgent: () => enableHip3DexAbstractionWithAgent,
37040
37040
  encodeSlug: () => encodeSlug,
37041
37041
  formatPriceAndSize: () => formatPriceAndSize,
37042
+ formatPriceForDisplay: () => formatPriceForDisplay,
37042
37043
  formatPriceForOrder: () => formatPriceForOrder,
37044
+ formatSizeForDisplay: () => formatSizeForDisplay,
37043
37045
  formatSizeForOrder: () => formatSizeForOrder,
37044
37046
  getApprovalAmount: () => getApprovalAmount,
37045
37047
  getClientCodeNameById: () => getClientCodeNameById,
37046
37048
  getCloid: () => getCloid,
37049
+ getDexFromCollateralTokenSymbol: () => getDexFromCollateralTokenSymbol,
37050
+ getDisplayMarketSymbol: () => getDisplayMarketSymbol,
37047
37051
  getHip3Dex: () => getHip3Dex,
37048
37052
  getHip3DexAbstraction: () => getHip3DexAbstraction,
37049
37053
  getNextTierInfo: () => getNextTierInfo,
37050
37054
  getPriceDecimals: () => getPriceDecimals,
37055
+ getStaticCollateralTokenByDex: () => getStaticCollateralTokenByDex,
37056
+ getStaticCollateralTokenSymbol: () => getStaticCollateralTokenSymbol,
37051
37057
  getWidgetTypeById: () => getWidgetTypeById,
37052
37058
  isBasedCloid: () => isBasedCloid,
37053
37059
  isClientCode: () => isClientCode,
37054
37060
  isHip3Symbol: () => isHip3Symbol,
37055
37061
  isMiniAppCloid: () => isMiniAppCloid,
37056
37062
  isMiniAppTriggeredCloid: () => isMiniAppTriggeredCloid,
37063
+ isSpotSymbol: () => isSpotSymbol,
37057
37064
  isTenantCloid: () => isTenantCloid,
37058
37065
  isTrackingIdCloid: () => isTrackingIdCloid,
37059
37066
  isWidgetType: () => isWidgetType,
@@ -37663,6 +37670,39 @@ async function getHip3DexAbstraction(client, user) {
37663
37670
  user
37664
37671
  });
37665
37672
  }
37673
+ var dexToCollateralTokenSymbol = {
37674
+ rrrrr: "USDEEE",
37675
+ hyena: "USDE"
37676
+ };
37677
+ var isSpotSymbol = (coin) => {
37678
+ if (!coin) return false;
37679
+ return coin.includes("/") || coin.includes("@");
37680
+ };
37681
+ function getStaticCollateralTokenByDex(dex) {
37682
+ return dexToCollateralTokenSymbol[dex] ?? "USDC";
37683
+ }
37684
+ function getStaticCollateralTokenSymbol(coin) {
37685
+ if (!coin) return "USDC";
37686
+ if (!isHip3Symbol(coin)) return "USDC";
37687
+ const dex = getHip3Dex(coin);
37688
+ if (!dex) return "USDC";
37689
+ return getStaticCollateralTokenByDex(dex);
37690
+ }
37691
+ function getDisplayMarketSymbol(coin, showCollateralTokenSymbol = true, collateralTokenSymbol) {
37692
+ if (!coin || isSpotSymbol(coin)) return coin;
37693
+ if (isHip3Symbol(coin)) {
37694
+ const [_, symbol] = coin.split(":");
37695
+ if (!showCollateralTokenSymbol) return symbol;
37696
+ return `${symbol}-${collateralTokenSymbol ?? getStaticCollateralTokenSymbol(coin)}`;
37697
+ }
37698
+ if (!showCollateralTokenSymbol) return coin;
37699
+ return `${coin}-USDC`;
37700
+ }
37701
+ function getDexFromCollateralTokenSymbol(collateralTokenSymbol) {
37702
+ return Object.keys(dexToCollateralTokenSymbol).find(
37703
+ (dex) => dexToCollateralTokenSymbol[dex] === collateralTokenSymbol
37704
+ );
37705
+ }
37666
37706
 
37667
37707
  // import("./data/**/*/staticMeta.json") in lib/meta/metadata.ts
37668
37708
  var globImport_data_staticMeta_json = __glob({
@@ -37735,6 +37775,9 @@ var MetadataClient = class {
37735
37775
  if (this.initialized) return;
37736
37776
  if (this.initializing) return this.initializing;
37737
37777
  this.initializing = new Promise(async (resolve, reject) => {
37778
+ if (this.config.debug) {
37779
+ console.info("[MetadataClient] Initializing...", this.config);
37780
+ }
37738
37781
  await this.loadStaticMetaOverrides();
37739
37782
  if (this.config.onlyUseStaticFallback) {
37740
37783
  await this.loadStaticMetadata();
@@ -37754,6 +37797,14 @@ var MetadataClient = class {
37754
37797
  this.infoClient.meta(),
37755
37798
  this.infoClient.perpDexs()
37756
37799
  ]);
37800
+ if (this.config.debug) {
37801
+ console.info(
37802
+ "[MetadataClient] Core metadata",
37803
+ this.spotMeta,
37804
+ this.perpsMeta,
37805
+ this.perpDexs
37806
+ );
37807
+ }
37757
37808
  this.buildLookupMaps();
37758
37809
  if (this.config.hip3Dexs && this.config.hip3Dexs.length > 0) {
37759
37810
  await Promise.all(
@@ -37761,6 +37812,9 @@ var MetadataClient = class {
37761
37812
  );
37762
37813
  }
37763
37814
  this.initialized = true;
37815
+ if (this.config.debug) {
37816
+ console.info("[MetadataClient] Initialized");
37817
+ }
37764
37818
  resolve();
37765
37819
  } catch (error) {
37766
37820
  if (this.config.useStaticFallback) {
@@ -37791,6 +37845,12 @@ var MetadataClient = class {
37791
37845
  try {
37792
37846
  const staticMetaModule = await globImport_data_staticMeta_json(`./data/${network}/staticMeta.json`);
37793
37847
  this.staticMeta = staticMetaModule.default;
37848
+ if (this.config.debug) {
37849
+ console.info(
37850
+ "[MetadataClient] Loaded static metadata overrides",
37851
+ this.staticMeta
37852
+ );
37853
+ }
37794
37854
  } catch (error) {
37795
37855
  console.warn(`Failed to load staticMeta.json for ${network}:`, error);
37796
37856
  this.staticMeta = null;
@@ -37817,7 +37877,7 @@ var MetadataClient = class {
37817
37877
  this.perpsMeta = perpsMetaModule.default;
37818
37878
  this.perpDexs = perpDexsModule.default;
37819
37879
  this.staticMeta = staticMetaModule.default;
37820
- console.warn(`Using static ${network} metadata`);
37880
+ console.warn(`[MetadataClient] Using static ${network} metadata`);
37821
37881
  } catch (error) {
37822
37882
  console.error(`Failed to load static ${network} metadata:`, error);
37823
37883
  throw new Error(`Could not load metadata for ${network}`);
@@ -37924,6 +37984,14 @@ var MetadataClient = class {
37924
37984
  const [meta, contexts] = await this.infoClient.metaAndAssetCtxs({
37925
37985
  dex: dexName
37926
37986
  });
37987
+ if (this.config.debug) {
37988
+ console.info(
37989
+ "[MetadataClient] Loaded HIP-3 metadata",
37990
+ dexName,
37991
+ meta,
37992
+ contexts
37993
+ );
37994
+ }
37927
37995
  let dexIndex = this.dexNameToIndex.get(dexName.toLowerCase());
37928
37996
  if (dexIndex === void 0) {
37929
37997
  dexIndex = this.perpDexs.findIndex(
@@ -38185,12 +38253,34 @@ var formatPriceForOrder = ({
38185
38253
  const price = new import_decimal.Decimal(px).toDP(priceDecimals).toNumber();
38186
38254
  return price;
38187
38255
  };
38256
+ var formatPriceForDisplay = ({
38257
+ px,
38258
+ szDecimals,
38259
+ isSpot
38260
+ }) => {
38261
+ const priceDecimals = getPriceDecimals(px, szDecimals, isSpot);
38262
+ return new Intl.NumberFormat("en-US", {
38263
+ style: "decimal",
38264
+ minimumFractionDigits: priceDecimals,
38265
+ maximumFractionDigits: priceDecimals
38266
+ }).format(px);
38267
+ };
38188
38268
  var formatSizeForOrder = ({
38189
38269
  sz,
38190
38270
  szDecimals
38191
38271
  }) => {
38192
38272
  return new import_decimal.Decimal(sz).toDP(szDecimals, import_decimal.Decimal.ROUND_DOWN).toNumber();
38193
38273
  };
38274
+ var formatSizeForDisplay = ({
38275
+ sz,
38276
+ szDecimals
38277
+ }) => {
38278
+ return new Intl.NumberFormat("en-US", {
38279
+ style: "decimal",
38280
+ minimumFractionDigits: szDecimals,
38281
+ maximumFractionDigits: szDecimals
38282
+ }).format(sz);
38283
+ };
38194
38284
  function getPriceDecimals(price, szDecimals, isSpot) {
38195
38285
  const baseDecimals = isSpot ? 8 : 6;
38196
38286
  const maxDP = Math.max(baseDecimals - szDecimals, 0);
@@ -38228,21 +38318,28 @@ function getPriceDecimals(price, szDecimals, isSpot) {
38228
38318
  enableHip3DexAbstractionWithAgent,
38229
38319
  encodeSlug,
38230
38320
  formatPriceAndSize,
38321
+ formatPriceForDisplay,
38231
38322
  formatPriceForOrder,
38323
+ formatSizeForDisplay,
38232
38324
  formatSizeForOrder,
38233
38325
  getApprovalAmount,
38234
38326
  getClientCodeNameById,
38235
38327
  getCloid,
38328
+ getDexFromCollateralTokenSymbol,
38329
+ getDisplayMarketSymbol,
38236
38330
  getHip3Dex,
38237
38331
  getHip3DexAbstraction,
38238
38332
  getNextTierInfo,
38239
38333
  getPriceDecimals,
38334
+ getStaticCollateralTokenByDex,
38335
+ getStaticCollateralTokenSymbol,
38240
38336
  getWidgetTypeById,
38241
38337
  isBasedCloid,
38242
38338
  isClientCode,
38243
38339
  isHip3Symbol,
38244
38340
  isMiniAppCloid,
38245
38341
  isMiniAppTriggeredCloid,
38342
+ isSpotSymbol,
38246
38343
  isTenantCloid,
38247
38344
  isTrackingIdCloid,
38248
38345
  isWidgetType,
package/dist/index.mjs CHANGED
@@ -606,6 +606,39 @@ async function getHip3DexAbstraction(client, user) {
606
606
  user
607
607
  });
608
608
  }
609
+ var dexToCollateralTokenSymbol = {
610
+ rrrrr: "USDEEE",
611
+ hyena: "USDE"
612
+ };
613
+ var isSpotSymbol = (coin) => {
614
+ if (!coin) return false;
615
+ return coin.includes("/") || coin.includes("@");
616
+ };
617
+ function getStaticCollateralTokenByDex(dex) {
618
+ return dexToCollateralTokenSymbol[dex] ?? "USDC";
619
+ }
620
+ function getStaticCollateralTokenSymbol(coin) {
621
+ if (!coin) return "USDC";
622
+ if (!isHip3Symbol(coin)) return "USDC";
623
+ const dex = getHip3Dex(coin);
624
+ if (!dex) return "USDC";
625
+ return getStaticCollateralTokenByDex(dex);
626
+ }
627
+ function getDisplayMarketSymbol(coin, showCollateralTokenSymbol = true, collateralTokenSymbol) {
628
+ if (!coin || isSpotSymbol(coin)) return coin;
629
+ if (isHip3Symbol(coin)) {
630
+ const [_, symbol] = coin.split(":");
631
+ if (!showCollateralTokenSymbol) return symbol;
632
+ return `${symbol}-${collateralTokenSymbol ?? getStaticCollateralTokenSymbol(coin)}`;
633
+ }
634
+ if (!showCollateralTokenSymbol) return coin;
635
+ return `${coin}-USDC`;
636
+ }
637
+ function getDexFromCollateralTokenSymbol(collateralTokenSymbol) {
638
+ return Object.keys(dexToCollateralTokenSymbol).find(
639
+ (dex) => dexToCollateralTokenSymbol[dex] === collateralTokenSymbol
640
+ );
641
+ }
609
642
 
610
643
  // import("./data/**/*/staticMeta.json") in lib/meta/metadata.ts
611
644
  var globImport_data_staticMeta_json = __glob({
@@ -678,6 +711,9 @@ var MetadataClient = class {
678
711
  if (this.initialized) return;
679
712
  if (this.initializing) return this.initializing;
680
713
  this.initializing = new Promise(async (resolve, reject) => {
714
+ if (this.config.debug) {
715
+ console.info("[MetadataClient] Initializing...", this.config);
716
+ }
681
717
  await this.loadStaticMetaOverrides();
682
718
  if (this.config.onlyUseStaticFallback) {
683
719
  await this.loadStaticMetadata();
@@ -697,6 +733,14 @@ var MetadataClient = class {
697
733
  this.infoClient.meta(),
698
734
  this.infoClient.perpDexs()
699
735
  ]);
736
+ if (this.config.debug) {
737
+ console.info(
738
+ "[MetadataClient] Core metadata",
739
+ this.spotMeta,
740
+ this.perpsMeta,
741
+ this.perpDexs
742
+ );
743
+ }
700
744
  this.buildLookupMaps();
701
745
  if (this.config.hip3Dexs && this.config.hip3Dexs.length > 0) {
702
746
  await Promise.all(
@@ -704,6 +748,9 @@ var MetadataClient = class {
704
748
  );
705
749
  }
706
750
  this.initialized = true;
751
+ if (this.config.debug) {
752
+ console.info("[MetadataClient] Initialized");
753
+ }
707
754
  resolve();
708
755
  } catch (error) {
709
756
  if (this.config.useStaticFallback) {
@@ -734,6 +781,12 @@ var MetadataClient = class {
734
781
  try {
735
782
  const staticMetaModule = await globImport_data_staticMeta_json(`./data/${network}/staticMeta.json`);
736
783
  this.staticMeta = staticMetaModule.default;
784
+ if (this.config.debug) {
785
+ console.info(
786
+ "[MetadataClient] Loaded static metadata overrides",
787
+ this.staticMeta
788
+ );
789
+ }
737
790
  } catch (error) {
738
791
  console.warn(`Failed to load staticMeta.json for ${network}:`, error);
739
792
  this.staticMeta = null;
@@ -760,7 +813,7 @@ var MetadataClient = class {
760
813
  this.perpsMeta = perpsMetaModule.default;
761
814
  this.perpDexs = perpDexsModule.default;
762
815
  this.staticMeta = staticMetaModule.default;
763
- console.warn(`Using static ${network} metadata`);
816
+ console.warn(`[MetadataClient] Using static ${network} metadata`);
764
817
  } catch (error) {
765
818
  console.error(`Failed to load static ${network} metadata:`, error);
766
819
  throw new Error(`Could not load metadata for ${network}`);
@@ -867,6 +920,14 @@ var MetadataClient = class {
867
920
  const [meta, contexts] = await this.infoClient.metaAndAssetCtxs({
868
921
  dex: dexName
869
922
  });
923
+ if (this.config.debug) {
924
+ console.info(
925
+ "[MetadataClient] Loaded HIP-3 metadata",
926
+ dexName,
927
+ meta,
928
+ contexts
929
+ );
930
+ }
870
931
  let dexIndex = this.dexNameToIndex.get(dexName.toLowerCase());
871
932
  if (dexIndex === void 0) {
872
933
  dexIndex = this.perpDexs.findIndex(
@@ -1128,12 +1189,34 @@ var formatPriceForOrder = ({
1128
1189
  const price = new Decimal(px).toDP(priceDecimals).toNumber();
1129
1190
  return price;
1130
1191
  };
1192
+ var formatPriceForDisplay = ({
1193
+ px,
1194
+ szDecimals,
1195
+ isSpot
1196
+ }) => {
1197
+ const priceDecimals = getPriceDecimals(px, szDecimals, isSpot);
1198
+ return new Intl.NumberFormat("en-US", {
1199
+ style: "decimal",
1200
+ minimumFractionDigits: priceDecimals,
1201
+ maximumFractionDigits: priceDecimals
1202
+ }).format(px);
1203
+ };
1131
1204
  var formatSizeForOrder = ({
1132
1205
  sz,
1133
1206
  szDecimals
1134
1207
  }) => {
1135
1208
  return new Decimal(sz).toDP(szDecimals, Decimal.ROUND_DOWN).toNumber();
1136
1209
  };
1210
+ var formatSizeForDisplay = ({
1211
+ sz,
1212
+ szDecimals
1213
+ }) => {
1214
+ return new Intl.NumberFormat("en-US", {
1215
+ style: "decimal",
1216
+ minimumFractionDigits: szDecimals,
1217
+ maximumFractionDigits: szDecimals
1218
+ }).format(sz);
1219
+ };
1137
1220
  function getPriceDecimals(price, szDecimals, isSpot) {
1138
1221
  const baseDecimals = isSpot ? 8 : 6;
1139
1222
  const maxDP = Math.max(baseDecimals - szDecimals, 0);
@@ -1170,21 +1253,28 @@ export {
1170
1253
  enableHip3DexAbstractionWithAgent,
1171
1254
  encodeSlug,
1172
1255
  formatPriceAndSize,
1256
+ formatPriceForDisplay,
1173
1257
  formatPriceForOrder,
1258
+ formatSizeForDisplay,
1174
1259
  formatSizeForOrder,
1175
1260
  getApprovalAmount,
1176
1261
  getClientCodeNameById,
1177
1262
  getCloid,
1263
+ getDexFromCollateralTokenSymbol,
1264
+ getDisplayMarketSymbol,
1178
1265
  getHip3Dex,
1179
1266
  getHip3DexAbstraction,
1180
1267
  getNextTierInfo,
1181
1268
  getPriceDecimals,
1269
+ getStaticCollateralTokenByDex,
1270
+ getStaticCollateralTokenSymbol,
1182
1271
  getWidgetTypeById,
1183
1272
  isBasedCloid,
1184
1273
  isClientCode,
1185
1274
  isHip3Symbol,
1186
1275
  isMiniAppCloid,
1187
1276
  isMiniAppTriggeredCloid,
1277
+ isSpotSymbol,
1188
1278
  isTenantCloid,
1189
1279
  isTrackingIdCloid,
1190
1280
  isWidgetType,
@@ -1,25 +1,17 @@
1
- // static HIP-3 market info
1
+ import { PerpsMeta, InfoClient } from "@nktkas/hyperliquid";
2
2
 
3
- import { SpotToken, PerpDex } from "@nktkas/hyperliquid";
4
- import { TESTNET_USDC_SPOT_TOKEN, USDC_SPOT_TOKEN } from "../constants/tokens";
5
-
6
- // currently /info type: perpDexs doesn't include collateral token
7
- interface HIP3DexInfo extends PerpDex {
8
- collateralToken: SpotToken;
9
- }
10
-
11
- export const HIP3_DEX_INFO: Record<string, HIP3DexInfo> = {};
12
-
13
- const TESTNET_DEX_INFO: Record<string, HIP3DexInfo> = {
14
- vtnls: {
15
- collateralToken: TESTNET_USDC_SPOT_TOKEN,
16
- name: "vntls",
17
- full_name: "Ventuals",
18
- deployer: "0xc65008a70f511ae0407d26022ff1516422acea94",
19
- oracle_updater: null,
20
- },
3
+ export type PerpsMetaWithCollateralToken = PerpsMeta & {
4
+ collateralToken?: number; // spot token index
21
5
  };
22
6
 
23
- function getHIP3DexInfo(dex: string, isTestnet: boolean) {
24
- return isTestnet ? TESTNET_DEX_INFO[dex] : HIP3_DEX_INFO[dex];
7
+ export type AllPerpsMeta = PerpsMetaWithCollateralToken[];
8
+
9
+ export async function getAllPerpsMeta(
10
+ infoClient: InfoClient,
11
+ ): Promise<AllPerpsMeta> {
12
+ return infoClient.transport.request<AllPerpsMeta>("info", {
13
+ action: {
14
+ type: "allPerpMetas",
15
+ },
16
+ });
25
17
  }
package/lib/hip3/utils.ts CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  signUserSignedAction,
9
9
  } from "@nktkas/hyperliquid/signing";
10
10
 
11
- export function isHip3Symbol(symbol: string) {
11
+ export function isHip3Symbol(symbol: string | undefined) {
12
12
  if (!symbol) return false;
13
13
  return symbol.includes(":");
14
14
  }
@@ -96,3 +96,69 @@ export async function getHip3DexAbstraction(client: InfoClient, user: string) {
96
96
  user,
97
97
  });
98
98
  }
99
+
100
+ const dexToCollateralTokenSymbol = {
101
+ rrrrr: "USDEEE",
102
+ hyena: "USDE",
103
+ };
104
+
105
+ export const isSpotSymbol = (coin: string | undefined) => {
106
+ if (!coin) return false;
107
+ return coin.includes("/") || coin.includes("@");
108
+ };
109
+
110
+ export function getStaticCollateralTokenByDex(dex: string) {
111
+ return (
112
+ dexToCollateralTokenSymbol[
113
+ dex as keyof typeof dexToCollateralTokenSymbol
114
+ ] ?? "USDC"
115
+ );
116
+ }
117
+
118
+ /**
119
+ * Get static collateral token symbol for a given coin
120
+ * @param coin - The coin symbol to get the collateral token symbol for eg. xyz:XYZ100
121
+ * @returns The collateral token symbol for the given coin
122
+ */
123
+ export function getStaticCollateralTokenSymbol(coin: string | undefined) {
124
+ if (!coin) return "USDC";
125
+ if (!isHip3Symbol(coin)) return "USDC";
126
+ const dex = getHip3Dex(coin);
127
+ if (!dex) return "USDC";
128
+ return getStaticCollateralTokenByDex(dex);
129
+ }
130
+
131
+ /**
132
+ * Get display market symbol for a given coin
133
+ * @param coin - The coin symbol to get the display market symbol for eg. xyz:XYZ100
134
+ * @param showCollateralTokenSymbol - Whether to show the collateral token symbol. Default is true.
135
+ * @returns
136
+ * HIP-3 symbol: The display market symbol for the given coin eg. XYZ100-USDC, BTC-USDE, etc.
137
+ * If showCollateralTokenSymbol is false, returns the symbol without the collateral token symbol. eg. rrrrr:BTC -> BTC, hyena:BTC -> BTC
138
+ * Spot symbol: returns the coin argument itself
139
+ */
140
+ export function getDisplayMarketSymbol(
141
+ coin: string | undefined,
142
+ showCollateralTokenSymbol: boolean = true,
143
+ collateralTokenSymbol?: string,
144
+ ) {
145
+ if (!coin || isSpotSymbol(coin)) return coin;
146
+
147
+ if (isHip3Symbol(coin)) {
148
+ const [_, symbol] = coin.split(":");
149
+ if (!showCollateralTokenSymbol) return symbol;
150
+ return `${symbol}-${collateralTokenSymbol ?? getStaticCollateralTokenSymbol(coin)}`;
151
+ }
152
+ if (!showCollateralTokenSymbol) return coin;
153
+
154
+ return `${coin}-USDC`;
155
+ }
156
+
157
+ export function getDexFromCollateralTokenSymbol(collateralTokenSymbol: string) {
158
+ return Object.keys(dexToCollateralTokenSymbol).find(
159
+ (dex) =>
160
+ dexToCollateralTokenSymbol[
161
+ dex as keyof typeof dexToCollateralTokenSymbol
162
+ ] === collateralTokenSymbol,
163
+ );
164
+ }
@@ -176,6 +176,7 @@ export class MetadataClient {
176
176
  useStaticFallback: config.useStaticFallback ?? true,
177
177
  };
178
178
  this.isTestnet = config.isTestnet ?? false;
179
+
179
180
  this.initialize();
180
181
  }
181
182
 
@@ -186,6 +187,9 @@ export class MetadataClient {
186
187
  if (this.initialized) return;
187
188
  if (this.initializing) return this.initializing;
188
189
  this.initializing = new Promise(async (resolve, reject) => {
190
+ if (this.config.debug) {
191
+ console.info("[MetadataClient] Initializing...", this.config);
192
+ }
189
193
  // Always load staticMeta.json regardless of config.useStaticFallback
190
194
  await this.loadStaticMetaOverrides();
191
195
 
@@ -212,6 +216,15 @@ export class MetadataClient {
212
216
  this.infoClient.perpDexs() as Promise<PerpDex[] | null[]>,
213
217
  ]);
214
218
 
219
+ if (this.config.debug) {
220
+ console.info(
221
+ "[MetadataClient] Core metadata",
222
+ this.spotMeta,
223
+ this.perpsMeta,
224
+ this.perpDexs,
225
+ );
226
+ }
227
+
215
228
  // Build optimized lookup maps
216
229
  this.buildLookupMaps();
217
230
 
@@ -222,6 +235,9 @@ export class MetadataClient {
222
235
  );
223
236
  }
224
237
  this.initialized = true;
238
+ if (this.config.debug) {
239
+ console.info("[MetadataClient] Initialized");
240
+ }
225
241
  resolve();
226
242
  } catch (error) {
227
243
  // Fall back to static data if API fetch fails and fallback is enabled
@@ -257,6 +273,12 @@ export class MetadataClient {
257
273
  `./data/${network}/staticMeta.json`
258
274
  );
259
275
  this.staticMeta = staticMetaModule.default as StaticMetadata;
276
+ if (this.config.debug) {
277
+ console.info(
278
+ "[MetadataClient] Loaded static metadata overrides",
279
+ this.staticMeta,
280
+ );
281
+ }
260
282
  } catch (error) {
261
283
  console.warn(`Failed to load staticMeta.json for ${network}:`, error);
262
284
  this.staticMeta = null;
@@ -288,7 +310,7 @@ export class MetadataClient {
288
310
  this.perpDexs = perpDexsModule.default as (PerpDex | null)[];
289
311
  this.staticMeta = staticMetaModule.default as StaticMetadata;
290
312
 
291
- console.warn(`Using static ${network} metadata`);
313
+ console.warn(`[MetadataClient] Using static ${network} metadata`);
292
314
  } catch (error) {
293
315
  console.error(`Failed to load static ${network} metadata:`, error);
294
316
  throw new Error(`Could not load metadata for ${network}`);
@@ -436,6 +458,15 @@ export class MetadataClient {
436
458
  dex: dexName,
437
459
  });
438
460
 
461
+ if (this.config.debug) {
462
+ console.info(
463
+ "[MetadataClient] Loaded HIP-3 metadata",
464
+ dexName,
465
+ meta,
466
+ contexts,
467
+ );
468
+ }
469
+
439
470
  // O(1) lookup using pre-computed map
440
471
  let dexIndex = this.dexNameToIndex.get(dexName.toLowerCase());
441
472
 
@@ -44,6 +44,31 @@ export const formatPriceForOrder = ({
44
44
  return price;
45
45
  };
46
46
 
47
+ /**
48
+ * Formats price for order placement following Hyperliquid rules
49
+ * - Rounded to priceDecimals of the asset
50
+ * @param px - The price to format
51
+ * @param priceDecimals - Price decimals for the asset
52
+ * @returns Formatted price as number (rounded to priceDecimals if exceeds)
53
+ */
54
+ export const formatPriceForDisplay = ({
55
+ px,
56
+ szDecimals,
57
+ isSpot,
58
+ }: {
59
+ px: number;
60
+ szDecimals: number;
61
+ isSpot: boolean;
62
+ }) => {
63
+ const priceDecimals = getPriceDecimals(px, szDecimals, isSpot);
64
+
65
+ return new Intl.NumberFormat("en-US", {
66
+ style: "decimal",
67
+ minimumFractionDigits: priceDecimals,
68
+ maximumFractionDigits: priceDecimals,
69
+ }).format(px);
70
+ };
71
+
47
72
  /**
48
73
  * Formats size for order placement following Hyperliquid rules
49
74
  * - Rounded to szDecimals of the asset
@@ -61,6 +86,27 @@ export const formatSizeForOrder = ({
61
86
  return new Decimal(sz).toDP(szDecimals, Decimal.ROUND_DOWN).toNumber();
62
87
  };
63
88
 
89
+ /**
90
+ * Formats size for order placement following Hyperliquid rules
91
+ * - Rounded to szDecimals of the asset
92
+ * @param sz - The size to format
93
+ * @param szDecimals - Size decimals for the asset
94
+ * @returns Formatted size as number (rounded down to szDecimals if exceeds)
95
+ */
96
+ export const formatSizeForDisplay = ({
97
+ sz,
98
+ szDecimals,
99
+ }: {
100
+ sz: number;
101
+ szDecimals: number;
102
+ }) => {
103
+ return new Intl.NumberFormat("en-US", {
104
+ style: "decimal",
105
+ minimumFractionDigits: szDecimals,
106
+ maximumFractionDigits: szDecimals,
107
+ }).format(sz);
108
+ };
109
+
64
110
  /**
65
111
  * Get minimum price decimals for tick size calculations
66
112
  * Uses the same logic as internal price formatting
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basedone/core",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Core utilities for Based One",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",