@basedone/core 0.1.5 → 0.1.8

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
@@ -284,6 +284,9 @@ function isMiniAppTriggeredCloid(cloidHex) {
284
284
  return cloidData.miniAppTriggered;
285
285
  }
286
286
 
287
+ // lib/fee.ts
288
+ import Decimal from "decimal.js";
289
+
287
290
  // lib/constants/fee.ts
288
291
  var BASED_FEE_WALLET = "0x1924b8561eeF20e70Ede628A296175D358BE80e5";
289
292
  var BASED_REFERRAL_CODE = "SHIFU";
@@ -299,13 +302,19 @@ var TARGET_APPROVED_MAX_BUILDER_FEE_PERCENT = `0.1%`;
299
302
  var getApprovalAmount = ({
300
303
  customFeeEnabled,
301
304
  perpetualTradingFee,
302
- spotTradingFee
305
+ spotTradingFee,
306
+ feeDiscount
303
307
  }) => {
308
+ if (feeDiscount !== void 0 && (feeDiscount < 0 || feeDiscount > 1)) {
309
+ console.warn("Fee discount is not between 0 and 1, setting to 0");
310
+ feeDiscount = 0;
311
+ }
312
+ const discountMultiplier = feeDiscount ? new Decimal(1).sub(feeDiscount) : 1;
304
313
  if (!customFeeEnabled) {
305
314
  return {
306
- approvalAmount: TARGET_APPROVED_MAX_BUILDER_FEE,
307
- perpFee: TARGET_FUTURES_BUILDER_FEE,
308
- spotFee: TARGET_SPOT_BUILDER_FEE,
315
+ approvalAmount: new Decimal(TARGET_APPROVED_MAX_BUILDER_FEE).mul(discountMultiplier).floor().toNumber(),
316
+ perpFee: new Decimal(TARGET_FUTURES_BUILDER_FEE).mul(discountMultiplier).floor().toNumber(),
317
+ spotFee: new Decimal(TARGET_SPOT_BUILDER_FEE).mul(discountMultiplier).floor().toNumber(),
309
318
  approvalPercent: TARGET_APPROVED_MAX_BUILDER_FEE_PERCENT,
310
319
  builder: BASED_FEE_WALLET,
311
320
  referralCode: BASED_REFERRAL_CODE
@@ -315,6 +324,7 @@ var getApprovalAmount = ({
315
324
  if (validatedPerpFeePct === void 0) {
316
325
  validatedPerpFeePct = TARGET_FUTURES_BUILDER_FEE / 1e3;
317
326
  }
327
+ validatedPerpFeePct = new Decimal(validatedPerpFeePct).mul(discountMultiplier).toNumber();
318
328
  if (validatedPerpFeePct > 0 && validatedPerpFeePct < 0.01) {
319
329
  console.warn("Perp fee is less than 0.01%, setting to 0.01%");
320
330
  validatedPerpFeePct = 0.01;
@@ -331,6 +341,7 @@ var getApprovalAmount = ({
331
341
  if (validatedSpotFeePct === void 0) {
332
342
  validatedSpotFeePct = TARGET_SPOT_BUILDER_FEE / 1e3;
333
343
  }
344
+ validatedSpotFeePct = new Decimal(validatedSpotFeePct).mul(discountMultiplier).toNumber();
334
345
  if (validatedSpotFeePct > 0 && validatedSpotFeePct < 0.025) {
335
346
  console.warn("Spot fee is less than 0.025%, setting to 0.025%");
336
347
  validatedSpotFeePct = 0.025;
@@ -606,6 +617,45 @@ async function getHip3DexAbstraction(client, user) {
606
617
  user
607
618
  });
608
619
  }
620
+ var dexToCollateralTokenSymbol = {
621
+ rrrrr: "USDEEE",
622
+ hyena: "USDE",
623
+ flx: "USDH",
624
+ vntl: "USDH"
625
+ };
626
+ var isSpotSymbol = (coin) => {
627
+ if (!coin) return false;
628
+ return coin.includes("/") || coin.includes("@");
629
+ };
630
+ function getStaticCollateralTokenByDex(dex) {
631
+ return dexToCollateralTokenSymbol[dex] ?? "USDC";
632
+ }
633
+ function getStaticCollateralTokenSymbol(coin) {
634
+ if (!coin) return "USDC";
635
+ if (!isHip3Symbol(coin)) return "USDC";
636
+ const dex = getHip3Dex(coin);
637
+ if (!dex) return "USDC";
638
+ return getStaticCollateralTokenByDex(dex);
639
+ }
640
+ var stableQuoteTokens = ["USDC", "USDT0", "USDE", "USDEEE", "USDH"];
641
+ function isStableQuoteToken(coin) {
642
+ return stableQuoteTokens.includes(coin);
643
+ }
644
+ function getDisplayMarketSymbol(coin, showCollateralTokenSymbol = true, collateralTokenSymbol) {
645
+ if (!coin || isSpotSymbol(coin)) return coin;
646
+ if (isHip3Symbol(coin)) {
647
+ const [_, symbol] = coin.split(":");
648
+ if (!showCollateralTokenSymbol) return symbol;
649
+ return `${symbol}-${collateralTokenSymbol ?? getStaticCollateralTokenSymbol(coin)}`;
650
+ }
651
+ if (!showCollateralTokenSymbol) return coin;
652
+ return `${coin}-USDC`;
653
+ }
654
+ function getDexFromCollateralTokenSymbol(collateralTokenSymbol) {
655
+ return Object.keys(dexToCollateralTokenSymbol).find(
656
+ (dex) => dexToCollateralTokenSymbol[dex] === collateralTokenSymbol
657
+ );
658
+ }
609
659
 
610
660
  // import("./data/**/*/staticMeta.json") in lib/meta/metadata.ts
611
661
  var globImport_data_staticMeta_json = __glob({
@@ -615,20 +665,20 @@ var globImport_data_staticMeta_json = __glob({
615
665
 
616
666
  // import("./data/**/*/spotMeta.json") in lib/meta/metadata.ts
617
667
  var globImport_data_spotMeta_json = __glob({
618
- "./data/mainnet/spotMeta.json": () => import("./spotMeta-NK626IKQ.mjs"),
619
- "./data/testnet/spotMeta.json": () => import("./spotMeta-4LMKHJUT.mjs")
668
+ "./data/mainnet/spotMeta.json": () => import("./spotMeta-WQ4PXRNY.mjs"),
669
+ "./data/testnet/spotMeta.json": () => import("./spotMeta-Y7G2GI7B.mjs")
620
670
  });
621
671
 
622
672
  // import("./data/**/*/meta.json") in lib/meta/metadata.ts
623
673
  var globImport_data_meta_json = __glob({
624
- "./data/mainnet/meta.json": () => import("./meta-HEOHBPHS.mjs"),
625
- "./data/testnet/meta.json": () => import("./meta-CDVVRMMG.mjs")
674
+ "./data/mainnet/meta.json": () => import("./meta-RSZFFH63.mjs"),
675
+ "./data/testnet/meta.json": () => import("./meta-57AY44US.mjs")
626
676
  });
627
677
 
628
678
  // import("./data/**/*/perpDexs.json") in lib/meta/metadata.ts
629
679
  var globImport_data_perpDexs_json = __glob({
630
- "./data/mainnet/perpDexs.json": () => import("./perpDexs-G5YWV3II.mjs"),
631
- "./data/testnet/perpDexs.json": () => import("./perpDexs-PGY6VMYS.mjs")
680
+ "./data/mainnet/perpDexs.json": () => import("./perpDexs-PBKWKKQU.mjs"),
681
+ "./data/testnet/perpDexs.json": () => import("./perpDexs-XSB4Y2BP.mjs")
632
682
  });
633
683
 
634
684
  // lib/meta/metadata.ts
@@ -1132,7 +1182,7 @@ var MetadataClient = class {
1132
1182
  };
1133
1183
 
1134
1184
  // lib/utils/formatter.ts
1135
- import { Decimal } from "decimal.js";
1185
+ import { Decimal as Decimal2 } from "decimal.js";
1136
1186
  var formatPriceAndSize = ({
1137
1187
  px,
1138
1188
  sz,
@@ -1140,8 +1190,8 @@ var formatPriceAndSize = ({
1140
1190
  isSpot
1141
1191
  }) => {
1142
1192
  const priceDecimals = getPriceDecimals(px, szDecimals, isSpot);
1143
- const price = new Decimal(px).toDP(priceDecimals).toNumber();
1144
- const size = new Decimal(sz).toDP(szDecimals, Decimal.ROUND_DOWN).toNumber();
1193
+ const price = new Decimal2(px).toDP(priceDecimals).toNumber();
1194
+ const size = new Decimal2(sz).toDP(szDecimals, Decimal2.ROUND_DOWN).toNumber();
1145
1195
  return {
1146
1196
  price,
1147
1197
  size
@@ -1153,14 +1203,36 @@ var formatPriceForOrder = ({
1153
1203
  isSpot
1154
1204
  }) => {
1155
1205
  const priceDecimals = getPriceDecimals(px, szDecimals, isSpot);
1156
- const price = new Decimal(px).toDP(priceDecimals).toNumber();
1206
+ const price = new Decimal2(px).toDP(priceDecimals).toNumber();
1157
1207
  return price;
1158
1208
  };
1209
+ var formatPriceForDisplay = ({
1210
+ px,
1211
+ szDecimals,
1212
+ isSpot
1213
+ }) => {
1214
+ const priceDecimals = getPriceDecimals(px, szDecimals, isSpot);
1215
+ return new Intl.NumberFormat("en-US", {
1216
+ style: "decimal",
1217
+ minimumFractionDigits: priceDecimals,
1218
+ maximumFractionDigits: priceDecimals
1219
+ }).format(px);
1220
+ };
1159
1221
  var formatSizeForOrder = ({
1160
1222
  sz,
1161
1223
  szDecimals
1162
1224
  }) => {
1163
- return new Decimal(sz).toDP(szDecimals, Decimal.ROUND_DOWN).toNumber();
1225
+ return new Decimal2(sz).toDP(szDecimals, Decimal2.ROUND_DOWN).toNumber();
1226
+ };
1227
+ var formatSizeForDisplay = ({
1228
+ sz,
1229
+ szDecimals
1230
+ }) => {
1231
+ return new Intl.NumberFormat("en-US", {
1232
+ style: "decimal",
1233
+ minimumFractionDigits: szDecimals,
1234
+ maximumFractionDigits: szDecimals
1235
+ }).format(sz);
1164
1236
  };
1165
1237
  function getPriceDecimals(price, szDecimals, isSpot) {
1166
1238
  const baseDecimals = isSpot ? 8 : 6;
@@ -1198,21 +1270,29 @@ export {
1198
1270
  enableHip3DexAbstractionWithAgent,
1199
1271
  encodeSlug,
1200
1272
  formatPriceAndSize,
1273
+ formatPriceForDisplay,
1201
1274
  formatPriceForOrder,
1275
+ formatSizeForDisplay,
1202
1276
  formatSizeForOrder,
1203
1277
  getApprovalAmount,
1204
1278
  getClientCodeNameById,
1205
1279
  getCloid,
1280
+ getDexFromCollateralTokenSymbol,
1281
+ getDisplayMarketSymbol,
1206
1282
  getHip3Dex,
1207
1283
  getHip3DexAbstraction,
1208
1284
  getNextTierInfo,
1209
1285
  getPriceDecimals,
1286
+ getStaticCollateralTokenByDex,
1287
+ getStaticCollateralTokenSymbol,
1210
1288
  getWidgetTypeById,
1211
1289
  isBasedCloid,
1212
1290
  isClientCode,
1213
1291
  isHip3Symbol,
1214
1292
  isMiniAppCloid,
1215
1293
  isMiniAppTriggeredCloid,
1294
+ isSpotSymbol,
1295
+ isStableQuoteToken,
1216
1296
  isTenantCloid,
1217
1297
  isTrackingIdCloid,
1218
1298
  isWidgetType,
@@ -1220,5 +1300,6 @@ export {
1220
1300
  normaliseTrackingId,
1221
1301
  normalizeAirdropAmount,
1222
1302
  parseCloid,
1223
- setHip3DexAbstraction
1303
+ setHip3DexAbstraction,
1304
+ stableQuoteTokens
1224
1305
  };
@@ -113,7 +113,8 @@ var universe = [
113
113
  maxLeverage: 2,
114
114
  marginTableId: 2,
115
115
  onlyIsolated: true,
116
- isDelisted: true
116
+ isDelisted: true,
117
+ marginMode: "strictIsolated"
117
118
  },
118
119
  {
119
120
  szDecimals: 2,
@@ -196,7 +197,8 @@ var universe = [
196
197
  maxLeverage: 3,
197
198
  marginTableId: 3,
198
199
  onlyIsolated: true,
199
- isDelisted: true
200
+ isDelisted: true,
201
+ marginMode: "strictIsolated"
200
202
  },
201
203
  {
202
204
  szDecimals: 1,
@@ -204,14 +206,16 @@ var universe = [
204
206
  maxLeverage: 3,
205
207
  marginTableId: 3,
206
208
  onlyIsolated: true,
207
- isDelisted: true
209
+ isDelisted: true,
210
+ marginMode: "strictIsolated"
208
211
  },
209
212
  {
210
213
  szDecimals: 1,
211
214
  name: "ZRO",
212
215
  maxLeverage: 10,
213
216
  marginTableId: 55,
214
- onlyIsolated: true
217
+ onlyIsolated: true,
218
+ marginMode: "strictIsolated"
215
219
  },
216
220
  {
217
221
  szDecimals: 0,
@@ -225,7 +229,8 @@ var universe = [
225
229
  name: "BANANA",
226
230
  maxLeverage: 3,
227
231
  marginTableId: 3,
228
- onlyIsolated: true
232
+ onlyIsolated: true,
233
+ marginMode: "strictIsolated"
229
234
  },
230
235
  {
231
236
  szDecimals: 1,
@@ -245,7 +250,8 @@ var universe = [
245
250
  maxLeverage: 3,
246
251
  marginTableId: 3,
247
252
  onlyIsolated: true,
248
- isDelisted: true
253
+ isDelisted: true,
254
+ marginMode: "strictIsolated"
249
255
  },
250
256
  {
251
257
  szDecimals: 0,
@@ -293,8 +299,8 @@ var universe = [
293
299
  {
294
300
  szDecimals: 0,
295
301
  name: "ADA",
296
- maxLeverage: 3,
297
- marginTableId: 3
302
+ maxLeverage: 10,
303
+ marginTableId: 55
298
304
  },
299
305
  {
300
306
  szDecimals: 0,
@@ -439,7 +445,8 @@ var universe = [
439
445
  maxLeverage: 3,
440
446
  marginTableId: 3,
441
447
  onlyIsolated: true,
442
- isDelisted: true
448
+ isDelisted: true,
449
+ marginMode: "strictIsolated"
443
450
  },
444
451
  {
445
452
  szDecimals: 0,
@@ -501,7 +508,8 @@ var universe = [
501
508
  name: "WIF",
502
509
  maxLeverage: 5,
503
510
  marginTableId: 5,
504
- onlyIsolated: true
511
+ onlyIsolated: true,
512
+ marginMode: "strictIsolated"
505
513
  },
506
514
  {
507
515
  szDecimals: 1,
@@ -587,7 +595,8 @@ var universe = [
587
595
  name: "W",
588
596
  maxLeverage: 3,
589
597
  marginTableId: 3,
590
- onlyIsolated: true
598
+ onlyIsolated: true,
599
+ marginMode: "strictIsolated"
591
600
  },
592
601
  {
593
602
  szDecimals: 5,
@@ -595,7 +604,8 @@ var universe = [
595
604
  maxLeverage: 3,
596
605
  marginTableId: 3,
597
606
  onlyIsolated: true,
598
- isDelisted: true
607
+ isDelisted: true,
608
+ marginMode: "strictIsolated"
599
609
  },
600
610
  {
601
611
  szDecimals: 1,
@@ -701,7 +711,8 @@ var universe = [
701
711
  name: "ZK",
702
712
  maxLeverage: 3,
703
713
  marginTableId: 3,
704
- onlyIsolated: true
714
+ onlyIsolated: true,
715
+ marginMode: "strictIsolated"
705
716
  },
706
717
  {
707
718
  szDecimals: 0,
@@ -788,14 +799,16 @@ var universe = [
788
799
  {
789
800
  szDecimals: 0,
790
801
  name: "MOODENG",
791
- maxLeverage: 5,
792
- marginTableId: 5
802
+ maxLeverage: 3,
803
+ marginTableId: 3
793
804
  },
794
805
  {
795
806
  szDecimals: 0,
796
807
  name: "PURR",
797
808
  maxLeverage: 3,
798
- marginTableId: 3
809
+ marginTableId: 3,
810
+ onlyIsolated: true,
811
+ marginMode: "strictIsolated"
799
812
  },
800
813
  {
801
814
  szDecimals: 1,
@@ -856,7 +869,9 @@ var universe = [
856
869
  szDecimals: 2,
857
870
  name: "HYPE",
858
871
  maxLeverage: 10,
859
- marginTableId: 10
872
+ marginTableId: 10,
873
+ onlyIsolated: true,
874
+ marginMode: "strictIsolated"
860
875
  },
861
876
  {
862
877
  szDecimals: 1,
@@ -904,7 +919,8 @@ var universe = [
904
919
  szDecimals: 1,
905
920
  name: "AI16Z",
906
921
  maxLeverage: 5,
907
- marginTableId: 5
922
+ marginTableId: 5,
923
+ isDelisted: true
908
924
  },
909
925
  {
910
926
  szDecimals: 0,
@@ -953,14 +969,16 @@ var universe = [
953
969
  name: "ANIME",
954
970
  maxLeverage: 12,
955
971
  marginTableId: 12,
956
- onlyIsolated: true
972
+ onlyIsolated: true,
973
+ marginMode: "strictIsolated"
957
974
  },
958
975
  {
959
976
  szDecimals: 1,
960
977
  name: "MELANIA",
961
978
  maxLeverage: 3,
962
979
  marginTableId: 3,
963
- onlyIsolated: true
980
+ onlyIsolated: true,
981
+ marginMode: "strictIsolated"
964
982
  },
965
983
  {
966
984
  szDecimals: 0,
@@ -980,7 +998,8 @@ var universe = [
980
998
  maxLeverage: 3,
981
999
  marginTableId: 3,
982
1000
  onlyIsolated: true,
983
- isDelisted: true
1001
+ isDelisted: true,
1002
+ marginMode: "strictIsolated"
984
1003
  },
985
1004
  {
986
1005
  szDecimals: 0,
@@ -988,7 +1007,8 @@ var universe = [
988
1007
  maxLeverage: 3,
989
1008
  marginTableId: 3,
990
1009
  onlyIsolated: true,
991
- isDelisted: true
1010
+ isDelisted: true,
1011
+ marginMode: "strictIsolated"
992
1012
  },
993
1013
  {
994
1014
  szDecimals: 1,
@@ -1048,8 +1068,8 @@ var universe = [
1048
1068
  {
1049
1069
  szDecimals: 0,
1050
1070
  name: "PROMPT",
1051
- maxLeverage: 10,
1052
- marginTableId: 10
1071
+ maxLeverage: 3,
1072
+ marginTableId: 3
1053
1073
  },
1054
1074
  {
1055
1075
  szDecimals: 0,
@@ -1097,7 +1117,8 @@ var universe = [
1097
1117
  szDecimals: 0,
1098
1118
  name: "LAUNCHCOIN",
1099
1119
  maxLeverage: 3,
1100
- marginTableId: 3
1120
+ marginTableId: 3,
1121
+ isDelisted: true
1101
1122
  },
1102
1123
  {
1103
1124
  szDecimals: 0,
@@ -1170,7 +1191,8 @@ var universe = [
1170
1191
  name: "ASTER",
1171
1192
  maxLeverage: 5,
1172
1193
  marginTableId: 5,
1173
- onlyIsolated: true
1194
+ onlyIsolated: true,
1195
+ marginMode: "strictIsolated"
1174
1196
  },
1175
1197
  {
1176
1198
  szDecimals: 0,
@@ -1189,7 +1211,8 @@ var universe = [
1189
1211
  name: "0G",
1190
1212
  maxLeverage: 3,
1191
1213
  marginTableId: 3,
1192
- onlyIsolated: true
1214
+ onlyIsolated: true,
1215
+ marginMode: "strictIsolated"
1193
1216
  },
1194
1217
  {
1195
1218
  szDecimals: 0,
@@ -1221,7 +1244,8 @@ var universe = [
1221
1244
  name: "MON",
1222
1245
  maxLeverage: 3,
1223
1246
  marginTableId: 3,
1224
- onlyIsolated: true
1247
+ onlyIsolated: true,
1248
+ marginMode: "strictIsolated"
1225
1249
  },
1226
1250
  {
1227
1251
  szDecimals: 0,
@@ -1234,7 +1258,20 @@ var universe = [
1234
1258
  name: "MEGA",
1235
1259
  maxLeverage: 3,
1236
1260
  marginTableId: 3,
1237
- onlyIsolated: true
1261
+ onlyIsolated: true,
1262
+ marginMode: "strictIsolated"
1263
+ },
1264
+ {
1265
+ szDecimals: 0,
1266
+ name: "CC",
1267
+ maxLeverage: 3,
1268
+ marginTableId: 3
1269
+ },
1270
+ {
1271
+ szDecimals: 0,
1272
+ name: "AERO",
1273
+ maxLeverage: 3,
1274
+ marginTableId: 3
1238
1275
  }
1239
1276
  ];
1240
1277
  var marginTables = [