@basedone/core 0.1.5 → 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({
@@ -38213,12 +38253,34 @@ var formatPriceForOrder = ({
38213
38253
  const price = new import_decimal.Decimal(px).toDP(priceDecimals).toNumber();
38214
38254
  return price;
38215
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
+ };
38216
38268
  var formatSizeForOrder = ({
38217
38269
  sz,
38218
38270
  szDecimals
38219
38271
  }) => {
38220
38272
  return new import_decimal.Decimal(sz).toDP(szDecimals, import_decimal.Decimal.ROUND_DOWN).toNumber();
38221
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
+ };
38222
38284
  function getPriceDecimals(price, szDecimals, isSpot) {
38223
38285
  const baseDecimals = isSpot ? 8 : 6;
38224
38286
  const maxDP = Math.max(baseDecimals - szDecimals, 0);
@@ -38256,21 +38318,28 @@ function getPriceDecimals(price, szDecimals, isSpot) {
38256
38318
  enableHip3DexAbstractionWithAgent,
38257
38319
  encodeSlug,
38258
38320
  formatPriceAndSize,
38321
+ formatPriceForDisplay,
38259
38322
  formatPriceForOrder,
38323
+ formatSizeForDisplay,
38260
38324
  formatSizeForOrder,
38261
38325
  getApprovalAmount,
38262
38326
  getClientCodeNameById,
38263
38327
  getCloid,
38328
+ getDexFromCollateralTokenSymbol,
38329
+ getDisplayMarketSymbol,
38264
38330
  getHip3Dex,
38265
38331
  getHip3DexAbstraction,
38266
38332
  getNextTierInfo,
38267
38333
  getPriceDecimals,
38334
+ getStaticCollateralTokenByDex,
38335
+ getStaticCollateralTokenSymbol,
38268
38336
  getWidgetTypeById,
38269
38337
  isBasedCloid,
38270
38338
  isClientCode,
38271
38339
  isHip3Symbol,
38272
38340
  isMiniAppCloid,
38273
38341
  isMiniAppTriggeredCloid,
38342
+ isSpotSymbol,
38274
38343
  isTenantCloid,
38275
38344
  isTrackingIdCloid,
38276
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({
@@ -1156,12 +1189,34 @@ var formatPriceForOrder = ({
1156
1189
  const price = new Decimal(px).toDP(priceDecimals).toNumber();
1157
1190
  return price;
1158
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
+ };
1159
1204
  var formatSizeForOrder = ({
1160
1205
  sz,
1161
1206
  szDecimals
1162
1207
  }) => {
1163
1208
  return new Decimal(sz).toDP(szDecimals, Decimal.ROUND_DOWN).toNumber();
1164
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
+ };
1165
1220
  function getPriceDecimals(price, szDecimals, isSpot) {
1166
1221
  const baseDecimals = isSpot ? 8 : 6;
1167
1222
  const maxDP = Math.max(baseDecimals - szDecimals, 0);
@@ -1198,21 +1253,28 @@ export {
1198
1253
  enableHip3DexAbstractionWithAgent,
1199
1254
  encodeSlug,
1200
1255
  formatPriceAndSize,
1256
+ formatPriceForDisplay,
1201
1257
  formatPriceForOrder,
1258
+ formatSizeForDisplay,
1202
1259
  formatSizeForOrder,
1203
1260
  getApprovalAmount,
1204
1261
  getClientCodeNameById,
1205
1262
  getCloid,
1263
+ getDexFromCollateralTokenSymbol,
1264
+ getDisplayMarketSymbol,
1206
1265
  getHip3Dex,
1207
1266
  getHip3DexAbstraction,
1208
1267
  getNextTierInfo,
1209
1268
  getPriceDecimals,
1269
+ getStaticCollateralTokenByDex,
1270
+ getStaticCollateralTokenSymbol,
1210
1271
  getWidgetTypeById,
1211
1272
  isBasedCloid,
1212
1273
  isClientCode,
1213
1274
  isHip3Symbol,
1214
1275
  isMiniAppCloid,
1215
1276
  isMiniAppTriggeredCloid,
1277
+ isSpotSymbol,
1216
1278
  isTenantCloid,
1217
1279
  isTrackingIdCloid,
1218
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
+ }
@@ -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.5",
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",