@basedone/core 0.1.2 → 0.1.4

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.
Files changed (46) hide show
  1. package/dist/index.d.mts +3 -0
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +634 -53
  4. package/dist/index.mjs +19 -14
  5. package/dist/{meta-UUXKK7IB.mjs → meta-CDVVRMMG.mjs} +19 -13
  6. package/dist/{meta-52Q5UUQ4.mjs → meta-HEOHBPHS.mjs} +24 -18
  7. package/dist/{perpDexs-S3TK25EU.mjs → perpDexs-G5YWV3II.mjs} +6 -1
  8. package/dist/{perpDexs-TZIQ57IW.mjs → perpDexs-PGY6VMYS.mjs} +145 -3
  9. package/dist/{spotMeta-ZVBZNUUE.mjs → spotMeta-4LMKHJUT.mjs} +251 -3
  10. package/dist/{spotMeta-7IJT3W6H.mjs → spotMeta-NK626IKQ.mjs} +176 -7
  11. package/lib/meta/data/mainnet/meta.json +24 -18
  12. package/lib/meta/data/mainnet/perpDexs.json +6 -1
  13. package/lib/meta/data/mainnet/spotMeta.json +176 -7
  14. package/lib/meta/data/testnet/meta.json +19 -13
  15. package/lib/meta/data/testnet/perpDexs.json +145 -3
  16. package/lib/meta/data/testnet/spotMeta.json +251 -3
  17. package/lib/meta/metadata.ts +2 -0
  18. package/package.json +4 -3
  19. package/dist/chunk-KH53SPJC.mjs +0 -13
  20. package/dist/index.d.ts.map +0 -1
  21. package/dist/index.js.map +0 -1
  22. package/dist/lib/cloid.d.ts +0 -36
  23. package/dist/lib/cloid.d.ts.map +0 -1
  24. package/dist/lib/cloid.js +0 -169
  25. package/dist/lib/cloid.js.map +0 -1
  26. package/dist/meta-44Z4QO5K.mjs +0 -1474
  27. package/dist/meta-FTWJX4LV.mjs +0 -1445
  28. package/dist/meta-IKWYLG3Q.mjs +0 -1316
  29. package/dist/meta-VES4BWNR.mjs +0 -1355
  30. package/dist/perpDexs-BE7YAC5W.mjs +0 -17
  31. package/dist/perpDexs-F3JQZZLH.mjs +0 -537
  32. package/dist/perpDexs-PSE3LEVV.mjs +0 -9
  33. package/dist/perpDexs-YNEAJ3R5.mjs +0 -7
  34. package/dist/perpDexs-YS3QQSHW.mjs +0 -338
  35. package/dist/spotMeta-HRQNZMVY.mjs +0 -6442
  36. package/dist/spotMeta-LEO5QFNS.mjs +0 -26392
  37. package/dist/spotMeta-MC5UYLQ7.mjs +0 -6335
  38. package/dist/spotMeta-SHXGTDWD.mjs +0 -26559
  39. package/dist/spotMeta-TXJWYTKI.mjs +0 -26403
  40. package/dist/spotMeta-VAANYV77.mjs +0 -6346
  41. package/dist/staticMeta-2HYATSVU.mjs +0 -25
  42. package/dist/staticMeta-D2V74GCG.mjs +0 -23
  43. package/dist/staticMeta-HRXST42O.mjs +0 -24
  44. package/dist/staticMeta-OKNVBUQ5.mjs +0 -25
  45. package/dist/staticMeta-PLKPPG23.mjs +0 -23
  46. package/dist/staticMeta-QWPQK3MD.mjs +0 -22
@@ -9072,6 +9072,15 @@
9072
9072
  "index": 1167,
9073
9073
  "isCanonical": false
9074
9074
  },
9075
+ {
9076
+ "tokens": [
9077
+ 1283,
9078
+ 0
9079
+ ],
9080
+ "name": "@1169",
9081
+ "index": 1169,
9082
+ "isCanonical": false
9083
+ },
9075
9084
  {
9076
9085
  "tokens": [
9077
9086
  1284,
@@ -10260,6 +10269,15 @@
10260
10269
  "index": 1330,
10261
10270
  "isCanonical": false
10262
10271
  },
10272
+ {
10273
+ "tokens": [
10274
+ 1430,
10275
+ 0
10276
+ ],
10277
+ "name": "@1331",
10278
+ "index": 1331,
10279
+ "isCanonical": false
10280
+ },
10263
10281
  {
10264
10282
  "tokens": [
10265
10283
  1448,
@@ -10268,6 +10286,105 @@
10268
10286
  "name": "@1332",
10269
10287
  "index": 1332,
10270
10288
  "isCanonical": false
10289
+ },
10290
+ {
10291
+ "tokens": [
10292
+ 1325,
10293
+ 0
10294
+ ],
10295
+ "name": "@1333",
10296
+ "index": 1333,
10297
+ "isCanonical": false
10298
+ },
10299
+ {
10300
+ "tokens": [
10301
+ 1446,
10302
+ 0
10303
+ ],
10304
+ "name": "@1334",
10305
+ "index": 1334,
10306
+ "isCanonical": false
10307
+ },
10308
+ {
10309
+ "tokens": [
10310
+ 1449,
10311
+ 0
10312
+ ],
10313
+ "name": "@1335",
10314
+ "index": 1335,
10315
+ "isCanonical": false
10316
+ },
10317
+ {
10318
+ "tokens": [
10319
+ 1451,
10320
+ 0
10321
+ ],
10322
+ "name": "@1336",
10323
+ "index": 1336,
10324
+ "isCanonical": false
10325
+ },
10326
+ {
10327
+ "tokens": [
10328
+ 1450,
10329
+ 0
10330
+ ],
10331
+ "name": "@1337",
10332
+ "index": 1337,
10333
+ "isCanonical": false
10334
+ },
10335
+ {
10336
+ "tokens": [
10337
+ 1452,
10338
+ 0
10339
+ ],
10340
+ "name": "@1338",
10341
+ "index": 1338,
10342
+ "isCanonical": false
10343
+ },
10344
+ {
10345
+ "tokens": [
10346
+ 1105,
10347
+ 1452
10348
+ ],
10349
+ "name": "@1339",
10350
+ "index": 1339,
10351
+ "isCanonical": false
10352
+ },
10353
+ {
10354
+ "tokens": [
10355
+ 1455,
10356
+ 0
10357
+ ],
10358
+ "name": "@1340",
10359
+ "index": 1340,
10360
+ "isCanonical": false
10361
+ },
10362
+ {
10363
+ "tokens": [
10364
+ 1105,
10365
+ 1446
10366
+ ],
10367
+ "name": "@1341",
10368
+ "index": 1341,
10369
+ "isCanonical": false
10370
+ },
10371
+ {
10372
+ "tokens": [
10373
+ 1441,
10374
+ 0
10375
+ ],
10376
+ "name": "@1342",
10377
+ "index": 1342,
10378
+ "isCanonical": false
10379
+ },
10380
+ {
10381
+ "tokens": [
10382
+ 1457,
10383
+ 0
10384
+ ],
10385
+ "name": "@1343",
10386
+ "index": 1343,
10387
+ "isCanonical": false
10271
10388
  }
10272
10389
  ],
10273
10390
  "tokens": [
@@ -26188,7 +26305,10 @@
26188
26305
  "index": 1418,
26189
26306
  "tokenId": "0xd46146306d848200a11e35caa517b7a3",
26190
26307
  "isCanonical": false,
26191
- "evmContract": null,
26308
+ "evmContract": {
26309
+ "address": "0x736f02643fb7222c0ab56cb33e22f413b71f2c29",
26310
+ "evm_extra_wei_decimals": 10
26311
+ },
26192
26312
  "fullName": "Loco Host 3000",
26193
26313
  "deployerTradingFeeShare": "1.0"
26194
26314
  },
@@ -26517,7 +26637,10 @@
26517
26637
  "index": 1446,
26518
26638
  "tokenId": "0xccefbbd2667d35d5052bd6809e17b572",
26519
26639
  "isCanonical": false,
26520
- "evmContract": null,
26640
+ "evmContract": {
26641
+ "address": "0xfa485d47b2c5fff327520f3672648704e1a31e70",
26642
+ "evm_extra_wei_decimals": -2
26643
+ },
26521
26644
  "fullName": "Global Dollar",
26522
26645
  "deployerTradingFeeShare": "0.0"
26523
26646
  },
@@ -26539,9 +26662,134 @@
26539
26662
  "index": 1448,
26540
26663
  "tokenId": "0xbad0cd3ca4b2b4c8838270eef2396c71",
26541
26664
  "isCanonical": false,
26542
- "evmContract": null,
26665
+ "evmContract": {
26666
+ "address": "0xbb6f7d711e86adc0f44dade218dcf55277e73d56",
26667
+ "evm_extra_wei_decimals": 0
26668
+ },
26543
26669
  "fullName": "Xion Testnet",
26544
26670
  "deployerTradingFeeShare": "1.0"
26671
+ },
26672
+ {
26673
+ "name": "SCOOBY",
26674
+ "szDecimals": 2,
26675
+ "weiDecimals": 8,
26676
+ "index": 1449,
26677
+ "tokenId": "0x007c75e3641f78d670b6d4c483c479f2",
26678
+ "isCanonical": false,
26679
+ "evmContract": {
26680
+ "address": "0xa9b68a573a43e16a68a38ef72cdd62a43aae441f",
26681
+ "evm_extra_wei_decimals": 10
26682
+ },
26683
+ "fullName": "ScoobyDoo",
26684
+ "deployerTradingFeeShare": "1.0"
26685
+ },
26686
+ {
26687
+ "name": "MACHA",
26688
+ "szDecimals": 2,
26689
+ "weiDecimals": 8,
26690
+ "index": 1450,
26691
+ "tokenId": "0x06485391c533e55546216394b1a59163",
26692
+ "isCanonical": false,
26693
+ "evmContract": {
26694
+ "address": "0xe70d8386d63ba825f9e23d30775db95cfef8329d",
26695
+ "evm_extra_wei_decimals": 10
26696
+ },
26697
+ "fullName": null,
26698
+ "deployerTradingFeeShare": "1.0"
26699
+ },
26700
+ {
26701
+ "name": "SEDA",
26702
+ "szDecimals": 2,
26703
+ "weiDecimals": 8,
26704
+ "index": 1451,
26705
+ "tokenId": "0xd7c4e302b9fbc915e69ea62c75992d13",
26706
+ "isCanonical": false,
26707
+ "evmContract": {
26708
+ "address": "0x47e16b197d6d85e8cc28a56702db935930942be2",
26709
+ "evm_extra_wei_decimals": 10
26710
+ },
26711
+ "fullName": "SEDA",
26712
+ "deployerTradingFeeShare": "1.0"
26713
+ },
26714
+ {
26715
+ "name": "USDH",
26716
+ "szDecimals": 2,
26717
+ "weiDecimals": 8,
26718
+ "index": 1452,
26719
+ "tokenId": "0x471fd4480bb9943a1fe080ab0d4ff36c",
26720
+ "isCanonical": false,
26721
+ "evmContract": {
26722
+ "address": "0x22222245c52c817f95b74664ae8546b490222222",
26723
+ "evm_extra_wei_decimals": -2
26724
+ },
26725
+ "fullName": "USDH",
26726
+ "deployerTradingFeeShare": "0.0"
26727
+ },
26728
+ {
26729
+ "name": "VJSLNL",
26730
+ "szDecimals": 1,
26731
+ "weiDecimals": 10,
26732
+ "index": 1453,
26733
+ "tokenId": "0x46c4e9190f9bc9cfa0f8e7c93d4f08df",
26734
+ "isCanonical": false,
26735
+ "evmContract": null,
26736
+ "fullName": "$WASH launchpad 2025-10-18T21:15:42.786Z",
26737
+ "deployerTradingFeeShare": "1.0"
26738
+ },
26739
+ {
26740
+ "name": "CEXMMA",
26741
+ "szDecimals": 0,
26742
+ "weiDecimals": 5,
26743
+ "index": 1454,
26744
+ "tokenId": "0x3b5a1db81853262b0dd7b77b458b4ff0",
26745
+ "isCanonical": false,
26746
+ "evmContract": null,
26747
+ "fullName": "$WASH launchpad 2025-10-19T22:15:45.139Z",
26748
+ "deployerTradingFeeShare": "1.0"
26749
+ },
26750
+ {
26751
+ "name": "BUSDC",
26752
+ "szDecimals": 2,
26753
+ "weiDecimals": 8,
26754
+ "index": 1455,
26755
+ "tokenId": "0x511a92b0ad8dcba0433338d80b23e201",
26756
+ "isCanonical": false,
26757
+ "evmContract": null,
26758
+ "fullName": "Basis USDC",
26759
+ "deployerTradingFeeShare": "1.0"
26760
+ },
26761
+ {
26762
+ "name": "CHEESE",
26763
+ "szDecimals": 2,
26764
+ "weiDecimals": 8,
26765
+ "index": 1456,
26766
+ "tokenId": "0x9739c25f3a7cec4260360d6c9f14d654",
26767
+ "isCanonical": false,
26768
+ "evmContract": null,
26769
+ "fullName": "Grilled Cheese",
26770
+ "deployerTradingFeeShare": "1.0"
26771
+ },
26772
+ {
26773
+ "name": "HTEST",
26774
+ "szDecimals": 2,
26775
+ "weiDecimals": 8,
26776
+ "index": 1457,
26777
+ "tokenId": "0x2ac8c59c35af9db24f43f57d240855b4",
26778
+ "isCanonical": false,
26779
+ "evmContract": null,
26780
+ "fullName": null,
26781
+ "deployerTradingFeeShare": "0.0"
26782
+ },
26783
+ {
26784
+ "name": "LMYY",
26785
+ "szDecimals": 2,
26786
+ "weiDecimals": 8,
26787
+ "index": 1458,
26788
+ "tokenId": "0x09881a9e9aa5fd36ffb5638d5d14d73d",
26789
+ "isCanonical": false,
26790
+ "evmContract": null,
26791
+ "fullName": "LMYY",
26792
+ "deployerTradingFeeShare": "1.0"
26545
26793
  }
26546
26794
  ]
26547
26795
  }
@@ -47,6 +47,7 @@ export interface MarketInfo {
47
47
  dexIndex?: number; // DEX index for asset ID calculation
48
48
  dexDisplayName?: string; // Display name override for the DEX
49
49
  dexImageUrl?: string; // Image URL override for the DEX
50
+ dexCollateralTokenSymbol?: string; // Collateral token symbol for HIP-3 markets
50
51
  }
51
52
 
52
53
  export interface DexInfo {
@@ -512,6 +513,7 @@ export class MetadataClient {
512
513
  dexIndex: dexInfo.dexIndex,
513
514
  dexDisplayName: dexInfo.displayName,
514
515
  dexImageUrl: dexInfo.imageUrl,
516
+ dexCollateralTokenSymbol: dexInfo.collateralTokenSymbol,
515
517
  };
516
518
 
517
519
  // Apply static metadata overrides for HIP-3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basedone/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Core utilities for Based One",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -12,10 +12,11 @@
12
12
  "lib"
13
13
  ],
14
14
  "scripts": {
15
- "build": "tsup index.ts --format cjs,esm --dts",
15
+ "build": "rm -rf dist && tsup index.ts --format cjs,esm --dts",
16
16
  "dev": "tsup index.ts --format cjs,esm --dts --watch",
17
17
  "test": "vitest",
18
- "update-meta": "tsx scripts/update-static-meta.ts"
18
+ "update-meta": "tsx scripts/update-static-meta.ts",
19
+ "prepublishOnly": "pnpm build"
19
20
  },
20
21
  "keywords": [],
21
22
  "author": "",
@@ -1,13 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __glob = (map) => (path) => {
4
- var fn = map[path];
5
- if (fn) return fn();
6
- throw new Error("Module not found in bundle: " + path);
7
- };
8
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
-
10
- export {
11
- __glob,
12
- __publicField
13
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -1,36 +0,0 @@
1
- export declare function encodeSlug(slug: string): number;
2
- export declare function decodeSlug(value: number): string;
3
- export declare function buildCloid(version: number, slug: string, clientId: number, oid: bigint): `0x${string}`;
4
- export declare function parseCloid(cloidHex: `0x${string}`): {
5
- prefix: string;
6
- version: number;
7
- slug: string;
8
- clientId: number;
9
- oid: bigint;
10
- clientName: string;
11
- } | null;
12
- export declare function isBasedCloid(cloidHex?: `0x${string}` | null): boolean;
13
- export declare function isTenantCloid(tenantTrackingSlug: string, cloidHex?: `0x${string}` | null): boolean;
14
- type ClientCode = string;
15
- export declare const CloidClientCode: {
16
- readonly Unset: 0;
17
- readonly Web: 1;
18
- readonly App: 2;
19
- readonly TgBot: 3;
20
- readonly TSL: 4;
21
- readonly Grid: 5;
22
- readonly Chase: 6;
23
- };
24
- type ClientCodeType = keyof typeof CloidClientCode;
25
- export type CloidClientCodeId = (typeof CloidClientCode)[ClientCodeType];
26
- export declare const CloidClientCodeNameById: Record<number, ClientCodeType>;
27
- export declare function getClientCodeNameById(id: number): string;
28
- /**
29
- * @param tenantCode - The tenant code (max 5 characters, truncated if longer) default: "BASED"
30
- * @param clientCode CloidClientCode - The client code (max 5 characters, truncated if longer) default: "Unset"
31
- * @param oid - The oid (64 bits) used for identifying unique orders, default: 0xBA5ED10000BA5ED1
32
- * @returns The cloid
33
- */
34
- export declare function getCloid(tenantCode?: ClientCode | null, clientCode?: ClientCodeType | number, oid?: bigint): `0x${string}`;
35
- export {};
36
- //# sourceMappingURL=cloid.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cloid.d.ts","sourceRoot":"","sources":["../../lib/cloid.ts"],"names":[],"mappings":"AAgCA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgB/C;AAGD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWhD;AAGD,wBAAgB,UAAU,CACxB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,GACV,KAAK,MAAM,EAAE,CAkBf;AAGD,wBAAgB,UAAU,CAAC,QAAQ,EAAE,KAAK,MAAM,EAAE;;;;;;;SAoCjD;AAGD,wBAAgB,YAAY,CAAC,QAAQ,CAAC,EAAE,KAAK,MAAM,EAAE,GAAG,IAAI,GAAG,OAAO,CAIrE;AAED,wBAAgB,aAAa,CAC3B,kBAAkB,EAAE,MAAM,EAC1B,QAAQ,CAAC,EAAE,KAAK,MAAM,EAAE,GAAG,IAAI,GAC9B,OAAO,CAST;AAED,KAAK,UAAU,GAAG,MAAM,CAAC;AAGzB,eAAO,MAAM,eAAe;;;;;;;;CAQlB,CAAC;AACX,KAAK,cAAc,GAAG,MAAM,OAAO,eAAe,CAAC;AAGnD,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,cAAc,CAAC,CAAC;AACzE,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAQlE,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI,EAC9B,UAAU,CAAC,EAAE,cAAc,GAAG,MAAM,EACpC,GAAG,CAAC,EAAE,MAAM,GACX,KAAK,MAAM,EAAE,CAoBf"}
package/dist/lib/cloid.js DELETED
@@ -1,169 +0,0 @@
1
- // Client Order ID (cloid) is an optional 128 bit hex string
2
- // 32 hex characters or 16 utf8 characters
3
- // Bit layout:
4
- // [ Prefix (24) | Version (4) | Slug (26) | Client ID (10) | OID (64) ]
5
- const LEGACY_CLOID = "0x62baee7262baee7262baee7262baee72";
6
- const BASED_VERSION = 1;
7
- const DEFAULT_TENANT_CODE = "BASED";
8
- const DEFAULT_OID = 0xba5ed10000ba5ed1n;
9
- // CloID bit layout (128 bits total):
10
- // [ Prefix (24) | Version (4) | Slug (26) | Client ID (10) | OID (64) ]
11
- // Constants
12
- const BASED_HEX_PREFIX = 0xba5ed1; // 24-bit prefix
13
- const BASED_HEX_PREFIX_STR = "0xba5ed1"; // 24-bit prefix
14
- const PREFIX_BITS = 24n;
15
- const VERSION_BITS = 4n;
16
- const SLUG_BITS = 26n;
17
- const CLIENT_BITS = 10n;
18
- const OID_BITS = 64n;
19
- const TOTAL_BITS = 128n;
20
- // Slug alphabet [A-Z0-9] (36 symbols)
21
- const SLUG_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
22
- const SLUG_BASE = SLUG_ALPHABET.length; // 36
23
- // Utility: mask for n bits
24
- const mask = (bits) => (1n << bits) - 1n;
25
- // Encode a 5-char slug into a 26-bit integer
26
- export function encodeSlug(slug) {
27
- if (!slug)
28
- slug = DEFAULT_TENANT_CODE;
29
- slug = slug.toUpperCase();
30
- if (slug.length > 5) {
31
- slug = slug.slice(0, 5);
32
- }
33
- let value = 0;
34
- for (const ch of slug) {
35
- const idx = SLUG_ALPHABET.indexOf(ch);
36
- if (idx === -1)
37
- throw new Error(`Invalid slug character: ${ch}`);
38
- value = value * SLUG_BASE + idx;
39
- }
40
- if (value > Number(mask(SLUG_BITS))) {
41
- throw new Error("Encoded slug exceeds 26 bits");
42
- }
43
- return value;
44
- }
45
- // Decode a 26-bit integer back into a 5-char slug
46
- export function decodeSlug(value) {
47
- if (value < 0 || value > Number(mask(SLUG_BITS))) {
48
- throw new Error("Slug value out of range (must fit in 26 bits)");
49
- }
50
- let slug = "";
51
- for (let i = 0; i < 5; i++) {
52
- const idx = value % SLUG_BASE;
53
- slug = SLUG_ALPHABET[idx] + slug;
54
- value = Math.floor(value / SLUG_BASE);
55
- }
56
- return slug;
57
- }
58
- // Build a CloID as a 0x-prefixed 32-char hex string
59
- export function buildCloid(version, slug, clientId, oid) {
60
- if (version > 0xf)
61
- version = BASED_VERSION;
62
- if (clientId > Number(mask(CLIENT_BITS))) {
63
- clientId = CloidClientCode.Unset;
64
- }
65
- if (oid > mask(OID_BITS)) {
66
- oid = DEFAULT_OID;
67
- }
68
- const slugVal = encodeSlug(slug);
69
- let cloid = BigInt(BASED_HEX_PREFIX) << (TOTAL_BITS - PREFIX_BITS);
70
- cloid |= BigInt(version & 0xf) << (TOTAL_BITS - PREFIX_BITS - VERSION_BITS);
71
- cloid |= BigInt(slugVal) << (OID_BITS + CLIENT_BITS);
72
- cloid |= BigInt(clientId) << OID_BITS;
73
- cloid |= oid & mask(OID_BITS);
74
- return `0x${cloid.toString(16)}`;
75
- }
76
- // Parse a CloID hex string back into fields
77
- export function parseCloid(cloidHex) {
78
- if (cloidHex === LEGACY_CLOID) {
79
- return {
80
- prefix: LEGACY_CLOID,
81
- version: 0,
82
- slug: "BASED",
83
- clientId: CloidClientCode.Unset,
84
- oid: 0xba5ed10000ba5ed1n,
85
- clientName: "Unset",
86
- };
87
- }
88
- try {
89
- const cloid = BigInt(cloidHex);
90
- const prefix = Number(cloid >> (TOTAL_BITS - PREFIX_BITS));
91
- const version = Number((cloid >> (TOTAL_BITS - PREFIX_BITS - VERSION_BITS)) & mask(VERSION_BITS));
92
- const slugVal = Number((cloid >> (OID_BITS + CLIENT_BITS)) & mask(SLUG_BITS));
93
- const clientId = Number((cloid >> OID_BITS) & mask(CLIENT_BITS));
94
- const oid = cloid & mask(OID_BITS);
95
- return {
96
- prefix: `0x${prefix.toString(16)}`, // should equal 0xBA5ED1
97
- version,
98
- slug: decodeSlug(slugVal),
99
- clientId,
100
- oid,
101
- clientName: getClientCodeNameById(clientId),
102
- };
103
- }
104
- catch (error) {
105
- console.error("Invalid cloid", { cloidHex });
106
- return null;
107
- }
108
- }
109
- // Quick prefix check
110
- export function isBasedCloid(cloidHex) {
111
- if (!cloidHex)
112
- return false;
113
- if (cloidHex === LEGACY_CLOID)
114
- return true;
115
- return cloidHex.toLowerCase().startsWith(BASED_HEX_PREFIX_STR);
116
- }
117
- export function isTenantCloid(tenantTrackingSlug, cloidHex) {
118
- if (!cloidHex || !isBasedCloid(cloidHex))
119
- return false;
120
- const cloidData = parseCloid(cloidHex);
121
- if (!cloidData)
122
- return false;
123
- const { slug } = cloidData;
124
- if (tenantTrackingSlug.length > 5) {
125
- tenantTrackingSlug = tenantTrackingSlug.slice(0, 5);
126
- }
127
- return slug === tenantTrackingSlug;
128
- }
129
- // Client code type 0 - 10 reserved
130
- export const CloidClientCode = {
131
- Unset: 0, // 0x00
132
- Web: 1,
133
- App: 2,
134
- TgBot: 3,
135
- TSL: 4, // Trailing Stop Loss
136
- Grid: 5,
137
- Chase: 6,
138
- };
139
- export const CloidClientCodeNameById = {
140
- [CloidClientCode.Unset]: "Unset",
141
- [CloidClientCode.Web]: "Web",
142
- [CloidClientCode.App]: "App",
143
- [CloidClientCode.TgBot]: "TgBot",
144
- [CloidClientCode.TSL]: "TSL",
145
- [CloidClientCode.Grid]: "Grid",
146
- [CloidClientCode.Chase]: "Chase",
147
- };
148
- export function getClientCodeNameById(id) {
149
- return CloidClientCodeNameById[id] ?? `client_${id}`;
150
- }
151
- /**
152
- * @param tenantCode - The tenant code (max 5 characters, truncated if longer) default: "BASED"
153
- * @param clientCode CloidClientCode - The client code (max 5 characters, truncated if longer) default: "Unset"
154
- * @param oid - The oid (64 bits) used for identifying unique orders, default: 0xBA5ED10000BA5ED1
155
- * @returns The cloid
156
- */
157
- export function getCloid(tenantCode, clientCode, oid) {
158
- try {
159
- const clientIdx = typeof clientCode === "number"
160
- ? clientCode
161
- : CloidClientCode[clientCode ?? "Unset"];
162
- return buildCloid(BASED_VERSION, tenantCode ?? DEFAULT_TENANT_CODE, clientIdx, oid ?? DEFAULT_OID);
163
- }
164
- catch (error) {
165
- console.error("Invalid cloid parameters, defaulting to legacy cloid", error, { tenantCode, clientCode, oid });
166
- return LEGACY_CLOID;
167
- }
168
- }
169
- //# sourceMappingURL=cloid.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cloid.js","sourceRoot":"","sources":["../../lib/cloid.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,0CAA0C;AAC1C,cAAc;AACd,wEAAwE;AAExE,MAAM,YAA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