@basedone/core 0.1.6 → 0.1.10

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
@@ -209,7 +209,8 @@ var CloidClientCode = {
209
209
  Chase: 6,
210
210
  Desktop: 7,
211
211
  API: 8,
212
- Stream: 9
212
+ Stream: 9,
213
+ Pal: 10
213
214
  };
214
215
  var CloidClientCodeNameById = {
215
216
  [CloidClientCode.Unset]: "Unset",
@@ -221,7 +222,8 @@ var CloidClientCodeNameById = {
221
222
  [CloidClientCode.Chase]: "Chase",
222
223
  [CloidClientCode.Desktop]: "Desktop",
223
224
  [CloidClientCode.API]: "API",
224
- [CloidClientCode.Stream]: "Stream"
225
+ [CloidClientCode.Stream]: "Stream",
226
+ [CloidClientCode.Pal]: "Pal"
225
227
  };
226
228
  function getClientCodeNameById(id) {
227
229
  return CloidClientCodeNameById[id] ?? `client_${id}`;
@@ -284,6 +286,9 @@ function isMiniAppTriggeredCloid(cloidHex) {
284
286
  return cloidData.miniAppTriggered;
285
287
  }
286
288
 
289
+ // lib/fee.ts
290
+ import Decimal from "decimal.js";
291
+
287
292
  // lib/constants/fee.ts
288
293
  var BASED_FEE_WALLET = "0x1924b8561eeF20e70Ede628A296175D358BE80e5";
289
294
  var BASED_REFERRAL_CODE = "SHIFU";
@@ -299,13 +304,19 @@ var TARGET_APPROVED_MAX_BUILDER_FEE_PERCENT = `0.1%`;
299
304
  var getApprovalAmount = ({
300
305
  customFeeEnabled,
301
306
  perpetualTradingFee,
302
- spotTradingFee
307
+ spotTradingFee,
308
+ feeDiscount
303
309
  }) => {
310
+ if (feeDiscount !== void 0 && (feeDiscount < 0 || feeDiscount > 1)) {
311
+ console.warn("Fee discount is not between 0 and 1, setting to 0");
312
+ feeDiscount = 0;
313
+ }
314
+ const discountMultiplier = feeDiscount ? new Decimal(1).sub(feeDiscount) : 1;
304
315
  if (!customFeeEnabled) {
305
316
  return {
306
- approvalAmount: TARGET_APPROVED_MAX_BUILDER_FEE,
307
- perpFee: TARGET_FUTURES_BUILDER_FEE,
308
- spotFee: TARGET_SPOT_BUILDER_FEE,
317
+ approvalAmount: new Decimal(TARGET_APPROVED_MAX_BUILDER_FEE).mul(discountMultiplier).floor().toNumber(),
318
+ perpFee: new Decimal(TARGET_FUTURES_BUILDER_FEE).mul(discountMultiplier).floor().toNumber(),
319
+ spotFee: new Decimal(TARGET_SPOT_BUILDER_FEE).mul(discountMultiplier).floor().toNumber(),
309
320
  approvalPercent: TARGET_APPROVED_MAX_BUILDER_FEE_PERCENT,
310
321
  builder: BASED_FEE_WALLET,
311
322
  referralCode: BASED_REFERRAL_CODE
@@ -315,22 +326,24 @@ var getApprovalAmount = ({
315
326
  if (validatedPerpFeePct === void 0) {
316
327
  validatedPerpFeePct = TARGET_FUTURES_BUILDER_FEE / 1e3;
317
328
  }
318
- if (validatedPerpFeePct > 0 && validatedPerpFeePct < 0.01) {
319
- console.warn("Perp fee is less than 0.01%, setting to 0.01%");
320
- validatedPerpFeePct = 0.01;
321
- }
322
- if (validatedPerpFeePct < 0) {
323
- console.warn("Perp fee is less than 0, setting to 0");
324
- validatedPerpFeePct = 0;
329
+ validatedPerpFeePct = new Decimal(validatedPerpFeePct).mul(discountMultiplier).toNumber();
330
+ if (validatedPerpFeePct > 0 && validatedPerpFeePct < 1e-3) {
331
+ console.warn("Perp fee is less than 0.001%, setting to 0.001%");
332
+ validatedPerpFeePct = 1e-3;
325
333
  }
326
334
  if (validatedPerpFeePct > 0.1) {
327
335
  console.warn("Perp fee is greater than 0.1%, setting to 0.1%");
328
336
  validatedPerpFeePct = 0.1;
329
337
  }
338
+ if (validatedPerpFeePct < 0) {
339
+ console.warn("Perp fee is less than 0, setting to 0");
340
+ validatedPerpFeePct = 0;
341
+ }
330
342
  let validatedSpotFeePct = spotTradingFee;
331
343
  if (validatedSpotFeePct === void 0) {
332
344
  validatedSpotFeePct = TARGET_SPOT_BUILDER_FEE / 1e3;
333
345
  }
346
+ validatedSpotFeePct = new Decimal(validatedSpotFeePct).mul(discountMultiplier).toNumber();
334
347
  if (validatedSpotFeePct > 0 && validatedSpotFeePct < 0.025) {
335
348
  console.warn("Spot fee is less than 0.025%, setting to 0.025%");
336
349
  validatedSpotFeePct = 0.025;
@@ -608,7 +621,9 @@ async function getHip3DexAbstraction(client, user) {
608
621
  }
609
622
  var dexToCollateralTokenSymbol = {
610
623
  rrrrr: "USDEEE",
611
- hyena: "USDE"
624
+ hyna: "USDE",
625
+ flx: "USDH",
626
+ vntl: "USDH"
612
627
  };
613
628
  var isSpotSymbol = (coin) => {
614
629
  if (!coin) return false;
@@ -624,8 +639,23 @@ function getStaticCollateralTokenSymbol(coin) {
624
639
  if (!dex) return "USDC";
625
640
  return getStaticCollateralTokenByDex(dex);
626
641
  }
642
+ var stableQuoteTokens = ["USDC", "USDT0", "USDE", "USDEEE", "USDH"];
643
+ function isStableQuoteToken(coin) {
644
+ return stableQuoteTokens.includes(coin);
645
+ }
627
646
  function getDisplayMarketSymbol(coin, showCollateralTokenSymbol = true, collateralTokenSymbol) {
628
- if (!coin || isSpotSymbol(coin)) return coin;
647
+ if (!coin) return coin;
648
+ if (isSpotSymbol(coin)) {
649
+ if (coin.includes("/")) {
650
+ const [baseToken, quoteToken] = coin.split("/");
651
+ if (showCollateralTokenSymbol) {
652
+ return `${baseToken}/${collateralTokenSymbol ?? quoteToken}`;
653
+ } else {
654
+ return baseToken;
655
+ }
656
+ }
657
+ return coin;
658
+ }
629
659
  if (isHip3Symbol(coin)) {
630
660
  const [_, symbol] = coin.split(":");
631
661
  if (!showCollateralTokenSymbol) return symbol;
@@ -648,20 +678,20 @@ var globImport_data_staticMeta_json = __glob({
648
678
 
649
679
  // import("./data/**/*/spotMeta.json") in lib/meta/metadata.ts
650
680
  var globImport_data_spotMeta_json = __glob({
651
- "./data/mainnet/spotMeta.json": () => import("./spotMeta-NK626IKQ.mjs"),
652
- "./data/testnet/spotMeta.json": () => import("./spotMeta-4LMKHJUT.mjs")
681
+ "./data/mainnet/spotMeta.json": () => import("./spotMeta-OD7S6HGW.mjs"),
682
+ "./data/testnet/spotMeta.json": () => import("./spotMeta-PCN4Z4R3.mjs")
653
683
  });
654
684
 
655
685
  // import("./data/**/*/meta.json") in lib/meta/metadata.ts
656
686
  var globImport_data_meta_json = __glob({
657
- "./data/mainnet/meta.json": () => import("./meta-HEOHBPHS.mjs"),
658
- "./data/testnet/meta.json": () => import("./meta-CDVVRMMG.mjs")
687
+ "./data/mainnet/meta.json": () => import("./meta-UOGUG3OW.mjs"),
688
+ "./data/testnet/meta.json": () => import("./meta-FVJIMALT.mjs")
659
689
  });
660
690
 
661
691
  // import("./data/**/*/perpDexs.json") in lib/meta/metadata.ts
662
692
  var globImport_data_perpDexs_json = __glob({
663
- "./data/mainnet/perpDexs.json": () => import("./perpDexs-G5YWV3II.mjs"),
664
- "./data/testnet/perpDexs.json": () => import("./perpDexs-PGY6VMYS.mjs")
693
+ "./data/mainnet/perpDexs.json": () => import("./perpDexs-GGL32HT4.mjs"),
694
+ "./data/testnet/perpDexs.json": () => import("./perpDexs-G7V2QIM6.mjs")
665
695
  });
666
696
 
667
697
  // lib/meta/metadata.ts
@@ -854,7 +884,8 @@ var MetadataClient = class {
854
884
  assetId: index,
855
885
  szDecimals: market.szDecimals,
856
886
  type: "perps",
857
- maxLeverage: market.maxLeverage
887
+ maxLeverage: market.maxLeverage,
888
+ growthMode: market.growthMode === "enabled"
858
889
  };
859
890
  const staticOverrides = this.staticMeta?.coins?.[market.name];
860
891
  if (staticOverrides) {
@@ -887,7 +918,8 @@ var MetadataClient = class {
887
918
  szDecimals: baseToken.szDecimals,
888
919
  type: "spot",
889
920
  baseToken,
890
- quoteToken
921
+ quoteToken,
922
+ growthMode: false
891
923
  };
892
924
  const staticOverrides = this.staticMeta?.coins?.[coin];
893
925
  if (staticOverrides) {
@@ -986,7 +1018,8 @@ var MetadataClient = class {
986
1018
  dexIndex: dexInfo.dexIndex,
987
1019
  dexDisplayName: dexInfo.displayName,
988
1020
  dexImageUrl: dexInfo.imageUrl,
989
- dexCollateralTokenSymbol: dexInfo.collateralTokenSymbol
1021
+ dexCollateralTokenSymbol: dexInfo.collateralTokenSymbol,
1022
+ growthMode: market.growthMode === "enabled"
990
1023
  };
991
1024
  const staticOverrides = this.staticMeta?.coins?.[symbol];
992
1025
  if (staticOverrides) {
@@ -1061,7 +1094,8 @@ var MetadataClient = class {
1061
1094
  // Perps asset ID is just the index
1062
1095
  szDecimals: market.szDecimals,
1063
1096
  type: "perps",
1064
- maxLeverage: market.maxLeverage
1097
+ maxLeverage: market.maxLeverage,
1098
+ growthMode: market.growthMode === "enabled"
1065
1099
  };
1066
1100
  }
1067
1101
  /**
@@ -1165,7 +1199,7 @@ var MetadataClient = class {
1165
1199
  };
1166
1200
 
1167
1201
  // lib/utils/formatter.ts
1168
- import { Decimal } from "decimal.js";
1202
+ import { Decimal as Decimal2 } from "decimal.js";
1169
1203
  var formatPriceAndSize = ({
1170
1204
  px,
1171
1205
  sz,
@@ -1173,8 +1207,8 @@ var formatPriceAndSize = ({
1173
1207
  isSpot
1174
1208
  }) => {
1175
1209
  const priceDecimals = getPriceDecimals(px, szDecimals, isSpot);
1176
- const price = new Decimal(px).toDP(priceDecimals).toNumber();
1177
- const size = new Decimal(sz).toDP(szDecimals, Decimal.ROUND_DOWN).toNumber();
1210
+ const price = new Decimal2(px).toDP(priceDecimals).toNumber();
1211
+ const size = new Decimal2(sz).toDP(szDecimals, Decimal2.ROUND_DOWN).toNumber();
1178
1212
  return {
1179
1213
  price,
1180
1214
  size
@@ -1186,7 +1220,7 @@ var formatPriceForOrder = ({
1186
1220
  isSpot
1187
1221
  }) => {
1188
1222
  const priceDecimals = getPriceDecimals(px, szDecimals, isSpot);
1189
- const price = new Decimal(px).toDP(priceDecimals).toNumber();
1223
+ const price = new Decimal2(px).toDP(priceDecimals).toNumber();
1190
1224
  return price;
1191
1225
  };
1192
1226
  var formatPriceForDisplay = ({
@@ -1205,7 +1239,7 @@ var formatSizeForOrder = ({
1205
1239
  sz,
1206
1240
  szDecimals
1207
1241
  }) => {
1208
- return new Decimal(sz).toDP(szDecimals, Decimal.ROUND_DOWN).toNumber();
1242
+ return new Decimal2(sz).toDP(szDecimals, Decimal2.ROUND_DOWN).toNumber();
1209
1243
  };
1210
1244
  var formatSizeForDisplay = ({
1211
1245
  sz,
@@ -1231,6 +1265,13 @@ function getPriceDecimals(price, szDecimals, isSpot) {
1231
1265
  }
1232
1266
  return minDecimals;
1233
1267
  }
1268
+
1269
+ // lib/hip3/market-info.ts
1270
+ async function getAllPerpsMeta(infoClient) {
1271
+ return infoClient.transport.request("info", {
1272
+ type: "allPerpMetas"
1273
+ });
1274
+ }
1234
1275
  export {
1235
1276
  CloidClientCode,
1236
1277
  CloidClientCodeNameById,
@@ -1257,6 +1298,7 @@ export {
1257
1298
  formatPriceForOrder,
1258
1299
  formatSizeForDisplay,
1259
1300
  formatSizeForOrder,
1301
+ getAllPerpsMeta,
1260
1302
  getApprovalAmount,
1261
1303
  getClientCodeNameById,
1262
1304
  getCloid,
@@ -1275,6 +1317,7 @@ export {
1275
1317
  isMiniAppCloid,
1276
1318
  isMiniAppTriggeredCloid,
1277
1319
  isSpotSymbol,
1320
+ isStableQuoteToken,
1278
1321
  isTenantCloid,
1279
1322
  isTrackingIdCloid,
1280
1323
  isWidgetType,
@@ -1282,5 +1325,6 @@ export {
1282
1325
  normaliseTrackingId,
1283
1326
  normalizeAirdropAmount,
1284
1327
  parseCloid,
1285
- setHip3DexAbstraction
1328
+ setHip3DexAbstraction,
1329
+ stableQuoteTokens
1286
1330
  };
@@ -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,
@@ -1219,9 +1242,8 @@ var universe = [
1219
1242
  {
1220
1243
  szDecimals: 0,
1221
1244
  name: "MON",
1222
- maxLeverage: 3,
1223
- marginTableId: 3,
1224
- onlyIsolated: true
1245
+ maxLeverage: 5,
1246
+ marginTableId: 5
1225
1247
  },
1226
1248
  {
1227
1249
  szDecimals: 0,
@@ -1234,7 +1256,20 @@ var universe = [
1234
1256
  name: "MEGA",
1235
1257
  maxLeverage: 3,
1236
1258
  marginTableId: 3,
1237
- onlyIsolated: true
1259
+ onlyIsolated: true,
1260
+ marginMode: "strictIsolated"
1261
+ },
1262
+ {
1263
+ szDecimals: 0,
1264
+ name: "CC",
1265
+ maxLeverage: 3,
1266
+ marginTableId: 3
1267
+ },
1268
+ {
1269
+ szDecimals: 0,
1270
+ name: "AERO",
1271
+ maxLeverage: 3,
1272
+ marginTableId: 3
1238
1273
  }
1239
1274
  ];
1240
1275
  var marginTables = [