@basedone/core 0.1.8 → 0.2.0

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 (59) hide show
  1. package/dist/chunk-4GAKANLT.mjs +1987 -0
  2. package/dist/chunk-4UEJOM6W.mjs +1 -3
  3. package/dist/chunk-VBC6EQ7Q.mjs +235 -0
  4. package/dist/client-CgmiTuEX.d.mts +179 -0
  5. package/dist/client-CgmiTuEX.d.ts +179 -0
  6. package/dist/ecommerce.d.mts +3732 -0
  7. package/dist/ecommerce.d.ts +3732 -0
  8. package/dist/ecommerce.js +2031 -0
  9. package/dist/ecommerce.mjs +2 -0
  10. package/dist/index.d.mts +79 -4
  11. package/dist/index.d.ts +79 -4
  12. package/dist/index.js +3674 -331
  13. package/dist/index.mjs +107 -104
  14. package/dist/{meta-57AY44US.mjs → meta-JB5ITE27.mjs} +6 -14
  15. package/dist/{meta-RSZFFH63.mjs → meta-UOGUG3OW.mjs} +5 -11
  16. package/dist/{perpDexs-PBKWKKQU.mjs → perpDexs-3LRJ5ZHM.mjs} +100 -13
  17. package/dist/{perpDexs-XSB4Y2BP.mjs → perpDexs-4ISLD7NX.mjs} +798 -121
  18. package/dist/react.d.mts +39 -0
  19. package/dist/react.d.ts +39 -0
  20. package/dist/react.js +268 -0
  21. package/dist/react.mjs +31 -0
  22. package/dist/{spotMeta-WQ4PXRNY.mjs → spotMeta-GHXX7C5M.mjs} +85 -14
  23. package/dist/{spotMeta-Y7G2GI7B.mjs → spotMeta-IBBUP2SG.mjs} +249 -12
  24. package/dist/staticMeta-GM7T3OYL.mjs +3 -6
  25. package/dist/staticMeta-QV2KMX57.mjs +3 -6
  26. package/ecommerce.ts +15 -0
  27. package/index.ts +7 -0
  28. package/lib/cloid/cloid.ts +2 -0
  29. package/lib/ecommerce/QUICK_REFERENCE.md +211 -0
  30. package/lib/ecommerce/README.md +385 -0
  31. package/lib/ecommerce/USAGE_EXAMPLES.md +704 -0
  32. package/lib/ecommerce/client/base.ts +272 -0
  33. package/lib/ecommerce/client/customer.ts +522 -0
  34. package/lib/ecommerce/client/merchant.ts +1341 -0
  35. package/lib/ecommerce/index.ts +51 -0
  36. package/lib/ecommerce/types/entities.ts +722 -0
  37. package/lib/ecommerce/types/enums.ts +270 -0
  38. package/lib/ecommerce/types/index.ts +18 -0
  39. package/lib/ecommerce/types/requests.ts +525 -0
  40. package/lib/ecommerce/types/responses.ts +805 -0
  41. package/lib/ecommerce/utils/errors.ts +113 -0
  42. package/lib/ecommerce/utils/helpers.ts +131 -0
  43. package/lib/fee.ts +10 -10
  44. package/lib/hip3/market-info.ts +36 -8
  45. package/lib/hip3/utils.ts +15 -2
  46. package/lib/instrument/client.ts +351 -0
  47. package/lib/meta/data/mainnet/meta.json +2 -4
  48. package/lib/meta/data/mainnet/perpDexs.json +97 -9
  49. package/lib/meta/data/mainnet/spotMeta.json +82 -8
  50. package/lib/meta/data/testnet/meta.json +3 -7
  51. package/lib/meta/data/testnet/perpDexs.json +795 -117
  52. package/lib/meta/data/testnet/spotMeta.json +246 -6
  53. package/lib/meta/metadata.ts +8 -1
  54. package/lib/meta/types.ts +36 -0
  55. package/lib/react/InstrumentProvider.tsx +69 -0
  56. package/lib/utils/flooredDateTime.ts +55 -0
  57. package/lib/utils/time.ts +51 -0
  58. package/package.json +37 -11
  59. package/react.ts +1 -0
@@ -4,6 +4,4 @@ var __glob = (map) => (path) => {
4
4
  throw new Error("Module not found in bundle: " + path);
5
5
  };
6
6
 
7
- export {
8
- __glob
9
- };
7
+ export { __glob };
@@ -0,0 +1,235 @@
1
+ // lib/instrument/client.ts
2
+ var AssetIdUtils = {
3
+ /**
4
+ * Calculate perp asset ID
5
+ * - Root dex: assetIndex (0, 1, 2, ...)
6
+ * - HIP3 dex: 100000 + dexIndex * 10000 + assetIndex
7
+ */
8
+ calcPerpAssetId(dexIndex, assetIndex) {
9
+ if (dexIndex === 0) return assetIndex;
10
+ return 1e5 + dexIndex * 1e4 + assetIndex;
11
+ },
12
+ /**
13
+ * Calculate spot asset ID: 10000 + pairIndex
14
+ */
15
+ calcSpotAssetId(pairIndex) {
16
+ return 1e4 + pairIndex;
17
+ },
18
+ /**
19
+ * Check if symbol is HIP3 format (contains ":")
20
+ */
21
+ isHip3Symbol(symbol) {
22
+ return symbol?.includes(":") ?? false;
23
+ },
24
+ /**
25
+ * Extract dex name from HIP3 symbol (e.g., "xyz:MSTR" -> "xyz")
26
+ */
27
+ extractDexName(symbol) {
28
+ if (!this.isHip3Symbol(symbol)) return void 0;
29
+ return symbol.split(":")[0];
30
+ }
31
+ };
32
+ var InstrumentClient = class {
33
+ constructor(spotMeta, allPerpsMeta) {
34
+ this.spotMeta = spotMeta;
35
+ this.allPerpsMeta = allPerpsMeta;
36
+ this.instruments = [];
37
+ // O(1) lookup maps for efficient retrieval
38
+ this.instrumentsBySymbol = /* @__PURE__ */ new Map();
39
+ this.instrumentsByCoin = /* @__PURE__ */ new Map();
40
+ this.instrumentsByAssetId = /* @__PURE__ */ new Map();
41
+ // Additional spot lookups (base token -> instrument)
42
+ this.spotByBaseToken = /* @__PURE__ */ new Map();
43
+ // Dex metadata map (dex name -> PerpsMeta)
44
+ // Key: "" for root dex, dex name for HIP3 (e.g., "xyz")
45
+ this.dexMetaMap = /* @__PURE__ */ new Map();
46
+ // Token index lookup for spot
47
+ this.spotTokensByIndex = /* @__PURE__ */ new Map();
48
+ }
49
+ /**
50
+ * Initialize the client by processing meta into instruments.
51
+ * Call this after construction to populate the instrument registry.
52
+ * @returns this for chaining
53
+ */
54
+ init() {
55
+ if (!this.spotMeta || !this.allPerpsMeta) {
56
+ throw new Error("SpotMeta and allPerpsMeta are required");
57
+ }
58
+ this.indexSpotTokens();
59
+ this.processPerpsInstruments();
60
+ this.processSpotInstruments();
61
+ return this;
62
+ }
63
+ // ===== Perps Meta Accessors =====
64
+ getAllPerpsMeta() {
65
+ return this.allPerpsMeta;
66
+ }
67
+ /**
68
+ * Get PerpsMeta for a specific dex
69
+ * @param dex - Dex name ("" for root dex, or HIP3 dex name)
70
+ */
71
+ getPerpDex(dex) {
72
+ return this.dexMetaMap.get(dex);
73
+ }
74
+ /**
75
+ * Get PerpsMeta by dex index in allPerpsMeta array
76
+ */
77
+ getPerpDexByIndex(index) {
78
+ return this.allPerpsMeta[index];
79
+ }
80
+ // ===== Instrument Accessors =====
81
+ /**
82
+ * Get all instruments
83
+ */
84
+ getAllInstruments() {
85
+ return this.instruments;
86
+ }
87
+ /**
88
+ * Get all perps instruments
89
+ */
90
+ getPerpsInstruments() {
91
+ return this.instruments.filter(
92
+ (i) => i.type === "futures"
93
+ );
94
+ }
95
+ getHip3Instruments() {
96
+ return this.instruments.filter(
97
+ (i) => i.type === "futures" && !!i.dex
98
+ );
99
+ }
100
+ /**
101
+ * Get all spot instruments
102
+ */
103
+ getSpotInstruments() {
104
+ return this.instruments.filter(
105
+ (i) => i.type === "spot"
106
+ );
107
+ }
108
+ /**
109
+ * Get instrument by symbol or coin (tries both)
110
+ * @param coinOrSymbol - Symbol (e.g., "BTC", "BTC/USDC") or coin (e.g., "@107")
111
+ */
112
+ getInstrument(coinOrSymbol) {
113
+ return this.instrumentsByCoin.get(coinOrSymbol) ?? this.instrumentsBySymbol.get(coinOrSymbol);
114
+ }
115
+ /**
116
+ * Get instrument by display symbol
117
+ * @param symbol - Display symbol (e.g., "BTC", "BTC/USDC", "xyz:MSTR")
118
+ */
119
+ getInstrumentBySymbol(symbol) {
120
+ return this.instrumentsBySymbol.get(symbol);
121
+ }
122
+ /**
123
+ * Get instrument by Hyperliquid API coin format
124
+ * @param coin - API coin name (e.g., "BTC", "@107", "xyz:MSTR")
125
+ */
126
+ getInstrumentByCoin(coin) {
127
+ return this.instrumentsByCoin.get(coin);
128
+ }
129
+ /**
130
+ * Get instrument by asset ID
131
+ * @param assetId - Numeric asset ID (e.g., 1 for perps, 10001 for spot)
132
+ */
133
+ getInstrumentByAssetId(assetId) {
134
+ return this.instrumentsByAssetId.get(assetId);
135
+ }
136
+ /**
137
+ * Get spot instrument by base token symbol
138
+ * @param baseSymbol - Base token symbol (e.g., "HYPE" to find "HYPE/USDC")
139
+ */
140
+ getSpotInstrumentByBaseToken(baseSymbol) {
141
+ return this.spotByBaseToken.get(baseSymbol);
142
+ }
143
+ /** Search instruments by symbol, coin, or assetId */
144
+ searchInstruments(query, type) {
145
+ return this.instruments.filter((i) => {
146
+ if (type && i.type !== type) return false;
147
+ return i.symbol.toLowerCase().includes(query.toLowerCase()) || i.coin.toLowerCase().includes(query.toLowerCase());
148
+ });
149
+ }
150
+ /**
151
+ * Get spot token by index
152
+ */
153
+ getSpotToken(index) {
154
+ return this.spotTokensByIndex.get(index);
155
+ }
156
+ // ===== Internal Processing =====
157
+ indexSpotTokens() {
158
+ for (const token of this.spotMeta.tokens) {
159
+ this.spotTokensByIndex.set(token.index, token);
160
+ }
161
+ }
162
+ processPerpsInstruments() {
163
+ for (let dexIndex = 0; dexIndex < this.allPerpsMeta.length; dexIndex++) {
164
+ const perpMeta = this.allPerpsMeta[dexIndex];
165
+ const dexName = this.extractDexNameFromMeta(perpMeta, dexIndex);
166
+ this.dexMetaMap.set(dexName, perpMeta);
167
+ const collateralToken = this.spotTokensByIndex.get(
168
+ perpMeta.collateralToken
169
+ );
170
+ const collateralTokenSymbol = collateralToken?.name ?? "USDC";
171
+ for (let assetIndex = 0; assetIndex < perpMeta.universe.length; assetIndex++) {
172
+ const info = perpMeta.universe[assetIndex];
173
+ const assetId = AssetIdUtils.calcPerpAssetId(dexIndex, assetIndex);
174
+ const instrument = {
175
+ assetId,
176
+ symbol: info.name,
177
+ coin: info.name,
178
+ szDecimals: info.szDecimals,
179
+ leverage: info.maxLeverage,
180
+ collateralTokenSymbol,
181
+ type: "futures",
182
+ isDelisted: info.isDelisted,
183
+ dex: AssetIdUtils.extractDexName(info.name),
184
+ collateralTokenIndex: perpMeta.collateralToken
185
+ };
186
+ this.addInstrument(instrument);
187
+ }
188
+ }
189
+ }
190
+ processSpotInstruments() {
191
+ const seenSymbols = /* @__PURE__ */ new Set();
192
+ for (const pair of this.spotMeta.universe) {
193
+ const [baseTokenIndex, quoteTokenIndex] = pair.tokens;
194
+ const baseToken = this.spotTokensByIndex.get(baseTokenIndex);
195
+ const quoteToken = this.spotTokensByIndex.get(quoteTokenIndex);
196
+ if (!baseToken || !quoteToken) continue;
197
+ const symbol = `${baseToken.name}/${quoteToken.name}`;
198
+ if (seenSymbols.has(symbol)) continue;
199
+ seenSymbols.add(symbol);
200
+ const assetId = AssetIdUtils.calcSpotAssetId(pair.index);
201
+ const instrument = {
202
+ assetId,
203
+ symbol,
204
+ coin: pair.name,
205
+ // e.g., "@107"
206
+ szDecimals: baseToken.szDecimals,
207
+ type: "spot",
208
+ baseToken,
209
+ quoteToken
210
+ };
211
+ this.addInstrument(instrument);
212
+ if (!this.spotByBaseToken.has(baseToken.name)) {
213
+ this.spotByBaseToken.set(baseToken.name, instrument);
214
+ }
215
+ }
216
+ }
217
+ addInstrument(instrument) {
218
+ this.instruments.push(instrument);
219
+ this.instrumentsBySymbol.set(instrument.symbol, instrument);
220
+ this.instrumentsByCoin.set(instrument.coin, instrument);
221
+ this.instrumentsByAssetId.set(instrument.assetId, instrument);
222
+ }
223
+ /**
224
+ * Extract dex name from PerpsMeta
225
+ * Root dex (index 0) returns "", HIP3 dexes return the dex name (e.g., "xyz")
226
+ */
227
+ extractDexNameFromMeta(perpMeta, dexIndex) {
228
+ if (dexIndex === 0) return "";
229
+ const firstAsset = perpMeta.universe[0];
230
+ if (!firstAsset) return "";
231
+ return AssetIdUtils.extractDexName(firstAsset.name) ?? "";
232
+ }
233
+ };
234
+
235
+ export { AssetIdUtils, InstrumentClient };
@@ -0,0 +1,179 @@
1
+ import { MarginTables, PerpsAssetCtx, InfoClient, SpotToken, SpotMeta } from '@nktkas/hyperliquid';
2
+
3
+ interface PerpsMeta {
4
+ collateralToken: number;
5
+ /** Trading universes available for perpetual trading. */
6
+ universe: PerpsUniverse[];
7
+ /** Margin requirement tables for different leverage tiers. */
8
+ marginTables: MarginTables;
9
+ }
10
+ /** Metadata and context for perpetual assets. */
11
+ type PerpsMetaAndAssetCtxs = [
12
+ /** Metadata for assets. */
13
+ PerpsMeta,
14
+ /** Context for each perpetual asset. */
15
+ PerpsAssetCtx[]
16
+ ];
17
+ /** Trading universe parameters for perpetual assets. */
18
+ interface PerpsUniverse {
19
+ /** Minimum decimal places for order sizes. */
20
+ szDecimals: number;
21
+ /** Name of the universe. */
22
+ name: string;
23
+ /** Maximum allowed leverage. */
24
+ maxLeverage: number;
25
+ /** Unique identifier for the margin requirements table. */
26
+ marginTableId: number;
27
+ /** Indicates if only isolated margin trading is allowed. */
28
+ onlyIsolated?: true;
29
+ /** Indicates if the universe is delisted. */
30
+ isDelisted?: true;
31
+ /** Indicates if the universe is in growth mode, eligible for discounted fees */
32
+ growthMode?: "enabled";
33
+ /** Margin mode for the universe. */
34
+ marginMode?: "strictIsolated" | "noCross";
35
+ }
36
+ type AllPerpsMeta = PerpsMeta[];
37
+ declare function getAllPerpsMeta(infoClient: InfoClient): Promise<AllPerpsMeta>;
38
+
39
+ interface BaseInstrument {
40
+ assetId: number;
41
+ symbol: string;
42
+ coin: string;
43
+ szDecimals: number;
44
+ type: "spot" | "futures";
45
+ isDelisted?: boolean;
46
+ }
47
+ interface PerpsInstrument extends BaseInstrument {
48
+ type: "futures";
49
+ leverage: number;
50
+ collateralTokenSymbol: string;
51
+ dex?: string;
52
+ collateralTokenIndex?: number;
53
+ }
54
+ interface SpotInstrument extends BaseInstrument {
55
+ type: "spot";
56
+ baseToken: SpotToken;
57
+ quoteToken: SpotToken;
58
+ }
59
+ type MarketInstrument = PerpsInstrument | SpotInstrument;
60
+ /**
61
+ * Asset ID calculation utilities
62
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/asset-ids
63
+ */
64
+ declare const AssetIdUtils: {
65
+ /**
66
+ * Calculate perp asset ID
67
+ * - Root dex: assetIndex (0, 1, 2, ...)
68
+ * - HIP3 dex: 100000 + dexIndex * 10000 + assetIndex
69
+ */
70
+ calcPerpAssetId(dexIndex: number, assetIndex: number): number;
71
+ /**
72
+ * Calculate spot asset ID: 10000 + pairIndex
73
+ */
74
+ calcSpotAssetId(pairIndex: number): number;
75
+ /**
76
+ * Check if symbol is HIP3 format (contains ":")
77
+ */
78
+ isHip3Symbol(symbol: string): boolean;
79
+ /**
80
+ * Extract dex name from HIP3 symbol (e.g., "xyz:MSTR" -> "xyz")
81
+ */
82
+ extractDexName(symbol: string): string | undefined;
83
+ };
84
+ /**
85
+ * Hyperliquid Instrument Client
86
+ *
87
+ * Processes spotMeta and allPerpsMeta into a unified instrument registry
88
+ * with O(1) lookups by symbol, coin, or assetId.
89
+ *
90
+ * Usage:
91
+ * ```ts
92
+ * const client = new InstrumentClient(spotMeta, allPerpsMeta).init();
93
+ * const btc = client.getInstrument("BTC");
94
+ * const spot = client.getInstrumentByAssetId(10001);
95
+ * ```
96
+ */
97
+ declare class InstrumentClient {
98
+ spotMeta: SpotMeta;
99
+ allPerpsMeta: AllPerpsMeta;
100
+ private instruments;
101
+ private instrumentsBySymbol;
102
+ private instrumentsByCoin;
103
+ private instrumentsByAssetId;
104
+ private spotByBaseToken;
105
+ private dexMetaMap;
106
+ private spotTokensByIndex;
107
+ constructor(spotMeta: SpotMeta, allPerpsMeta: AllPerpsMeta);
108
+ /**
109
+ * Initialize the client by processing meta into instruments.
110
+ * Call this after construction to populate the instrument registry.
111
+ * @returns this for chaining
112
+ */
113
+ init(): this;
114
+ getAllPerpsMeta(): AllPerpsMeta;
115
+ /**
116
+ * Get PerpsMeta for a specific dex
117
+ * @param dex - Dex name ("" for root dex, or HIP3 dex name)
118
+ */
119
+ getPerpDex(dex: string): PerpsMeta | undefined;
120
+ /**
121
+ * Get PerpsMeta by dex index in allPerpsMeta array
122
+ */
123
+ getPerpDexByIndex(index: number): PerpsMeta | undefined;
124
+ /**
125
+ * Get all instruments
126
+ */
127
+ getAllInstruments(): MarketInstrument[];
128
+ /**
129
+ * Get all perps instruments
130
+ */
131
+ getPerpsInstruments(): PerpsInstrument[];
132
+ getHip3Instruments(): PerpsInstrument[];
133
+ /**
134
+ * Get all spot instruments
135
+ */
136
+ getSpotInstruments(): SpotInstrument[];
137
+ /**
138
+ * Get instrument by symbol or coin (tries both)
139
+ * @param coinOrSymbol - Symbol (e.g., "BTC", "BTC/USDC") or coin (e.g., "@107")
140
+ */
141
+ getInstrument(coinOrSymbol: string): MarketInstrument | undefined;
142
+ /**
143
+ * Get instrument by display symbol
144
+ * @param symbol - Display symbol (e.g., "BTC", "BTC/USDC", "xyz:MSTR")
145
+ */
146
+ getInstrumentBySymbol(symbol: string): MarketInstrument | undefined;
147
+ /**
148
+ * Get instrument by Hyperliquid API coin format
149
+ * @param coin - API coin name (e.g., "BTC", "@107", "xyz:MSTR")
150
+ */
151
+ getInstrumentByCoin(coin: string): MarketInstrument | undefined;
152
+ /**
153
+ * Get instrument by asset ID
154
+ * @param assetId - Numeric asset ID (e.g., 1 for perps, 10001 for spot)
155
+ */
156
+ getInstrumentByAssetId(assetId: number): MarketInstrument | undefined;
157
+ /**
158
+ * Get spot instrument by base token symbol
159
+ * @param baseSymbol - Base token symbol (e.g., "HYPE" to find "HYPE/USDC")
160
+ */
161
+ getSpotInstrumentByBaseToken(baseSymbol: string): SpotInstrument | undefined;
162
+ /** Search instruments by symbol, coin, or assetId */
163
+ searchInstruments(query: string, type?: "spot" | "futures"): MarketInstrument[];
164
+ /**
165
+ * Get spot token by index
166
+ */
167
+ getSpotToken(index: number): SpotToken | undefined;
168
+ private indexSpotTokens;
169
+ private processPerpsInstruments;
170
+ private processSpotInstruments;
171
+ private addInstrument;
172
+ /**
173
+ * Extract dex name from PerpsMeta
174
+ * Root dex (index 0) returns "", HIP3 dexes return the dex name (e.g., "xyz")
175
+ */
176
+ private extractDexNameFromMeta;
177
+ }
178
+
179
+ export { type AllPerpsMeta as A, type BaseInstrument as B, InstrumentClient as I, type MarketInstrument as M, type PerpsMeta as P, type SpotInstrument as S, type PerpsMetaAndAssetCtxs as a, type PerpsUniverse as b, type PerpsInstrument as c, AssetIdUtils as d, getAllPerpsMeta as g };
@@ -0,0 +1,179 @@
1
+ import { MarginTables, PerpsAssetCtx, InfoClient, SpotToken, SpotMeta } from '@nktkas/hyperliquid';
2
+
3
+ interface PerpsMeta {
4
+ collateralToken: number;
5
+ /** Trading universes available for perpetual trading. */
6
+ universe: PerpsUniverse[];
7
+ /** Margin requirement tables for different leverage tiers. */
8
+ marginTables: MarginTables;
9
+ }
10
+ /** Metadata and context for perpetual assets. */
11
+ type PerpsMetaAndAssetCtxs = [
12
+ /** Metadata for assets. */
13
+ PerpsMeta,
14
+ /** Context for each perpetual asset. */
15
+ PerpsAssetCtx[]
16
+ ];
17
+ /** Trading universe parameters for perpetual assets. */
18
+ interface PerpsUniverse {
19
+ /** Minimum decimal places for order sizes. */
20
+ szDecimals: number;
21
+ /** Name of the universe. */
22
+ name: string;
23
+ /** Maximum allowed leverage. */
24
+ maxLeverage: number;
25
+ /** Unique identifier for the margin requirements table. */
26
+ marginTableId: number;
27
+ /** Indicates if only isolated margin trading is allowed. */
28
+ onlyIsolated?: true;
29
+ /** Indicates if the universe is delisted. */
30
+ isDelisted?: true;
31
+ /** Indicates if the universe is in growth mode, eligible for discounted fees */
32
+ growthMode?: "enabled";
33
+ /** Margin mode for the universe. */
34
+ marginMode?: "strictIsolated" | "noCross";
35
+ }
36
+ type AllPerpsMeta = PerpsMeta[];
37
+ declare function getAllPerpsMeta(infoClient: InfoClient): Promise<AllPerpsMeta>;
38
+
39
+ interface BaseInstrument {
40
+ assetId: number;
41
+ symbol: string;
42
+ coin: string;
43
+ szDecimals: number;
44
+ type: "spot" | "futures";
45
+ isDelisted?: boolean;
46
+ }
47
+ interface PerpsInstrument extends BaseInstrument {
48
+ type: "futures";
49
+ leverage: number;
50
+ collateralTokenSymbol: string;
51
+ dex?: string;
52
+ collateralTokenIndex?: number;
53
+ }
54
+ interface SpotInstrument extends BaseInstrument {
55
+ type: "spot";
56
+ baseToken: SpotToken;
57
+ quoteToken: SpotToken;
58
+ }
59
+ type MarketInstrument = PerpsInstrument | SpotInstrument;
60
+ /**
61
+ * Asset ID calculation utilities
62
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/asset-ids
63
+ */
64
+ declare const AssetIdUtils: {
65
+ /**
66
+ * Calculate perp asset ID
67
+ * - Root dex: assetIndex (0, 1, 2, ...)
68
+ * - HIP3 dex: 100000 + dexIndex * 10000 + assetIndex
69
+ */
70
+ calcPerpAssetId(dexIndex: number, assetIndex: number): number;
71
+ /**
72
+ * Calculate spot asset ID: 10000 + pairIndex
73
+ */
74
+ calcSpotAssetId(pairIndex: number): number;
75
+ /**
76
+ * Check if symbol is HIP3 format (contains ":")
77
+ */
78
+ isHip3Symbol(symbol: string): boolean;
79
+ /**
80
+ * Extract dex name from HIP3 symbol (e.g., "xyz:MSTR" -> "xyz")
81
+ */
82
+ extractDexName(symbol: string): string | undefined;
83
+ };
84
+ /**
85
+ * Hyperliquid Instrument Client
86
+ *
87
+ * Processes spotMeta and allPerpsMeta into a unified instrument registry
88
+ * with O(1) lookups by symbol, coin, or assetId.
89
+ *
90
+ * Usage:
91
+ * ```ts
92
+ * const client = new InstrumentClient(spotMeta, allPerpsMeta).init();
93
+ * const btc = client.getInstrument("BTC");
94
+ * const spot = client.getInstrumentByAssetId(10001);
95
+ * ```
96
+ */
97
+ declare class InstrumentClient {
98
+ spotMeta: SpotMeta;
99
+ allPerpsMeta: AllPerpsMeta;
100
+ private instruments;
101
+ private instrumentsBySymbol;
102
+ private instrumentsByCoin;
103
+ private instrumentsByAssetId;
104
+ private spotByBaseToken;
105
+ private dexMetaMap;
106
+ private spotTokensByIndex;
107
+ constructor(spotMeta: SpotMeta, allPerpsMeta: AllPerpsMeta);
108
+ /**
109
+ * Initialize the client by processing meta into instruments.
110
+ * Call this after construction to populate the instrument registry.
111
+ * @returns this for chaining
112
+ */
113
+ init(): this;
114
+ getAllPerpsMeta(): AllPerpsMeta;
115
+ /**
116
+ * Get PerpsMeta for a specific dex
117
+ * @param dex - Dex name ("" for root dex, or HIP3 dex name)
118
+ */
119
+ getPerpDex(dex: string): PerpsMeta | undefined;
120
+ /**
121
+ * Get PerpsMeta by dex index in allPerpsMeta array
122
+ */
123
+ getPerpDexByIndex(index: number): PerpsMeta | undefined;
124
+ /**
125
+ * Get all instruments
126
+ */
127
+ getAllInstruments(): MarketInstrument[];
128
+ /**
129
+ * Get all perps instruments
130
+ */
131
+ getPerpsInstruments(): PerpsInstrument[];
132
+ getHip3Instruments(): PerpsInstrument[];
133
+ /**
134
+ * Get all spot instruments
135
+ */
136
+ getSpotInstruments(): SpotInstrument[];
137
+ /**
138
+ * Get instrument by symbol or coin (tries both)
139
+ * @param coinOrSymbol - Symbol (e.g., "BTC", "BTC/USDC") or coin (e.g., "@107")
140
+ */
141
+ getInstrument(coinOrSymbol: string): MarketInstrument | undefined;
142
+ /**
143
+ * Get instrument by display symbol
144
+ * @param symbol - Display symbol (e.g., "BTC", "BTC/USDC", "xyz:MSTR")
145
+ */
146
+ getInstrumentBySymbol(symbol: string): MarketInstrument | undefined;
147
+ /**
148
+ * Get instrument by Hyperliquid API coin format
149
+ * @param coin - API coin name (e.g., "BTC", "@107", "xyz:MSTR")
150
+ */
151
+ getInstrumentByCoin(coin: string): MarketInstrument | undefined;
152
+ /**
153
+ * Get instrument by asset ID
154
+ * @param assetId - Numeric asset ID (e.g., 1 for perps, 10001 for spot)
155
+ */
156
+ getInstrumentByAssetId(assetId: number): MarketInstrument | undefined;
157
+ /**
158
+ * Get spot instrument by base token symbol
159
+ * @param baseSymbol - Base token symbol (e.g., "HYPE" to find "HYPE/USDC")
160
+ */
161
+ getSpotInstrumentByBaseToken(baseSymbol: string): SpotInstrument | undefined;
162
+ /** Search instruments by symbol, coin, or assetId */
163
+ searchInstruments(query: string, type?: "spot" | "futures"): MarketInstrument[];
164
+ /**
165
+ * Get spot token by index
166
+ */
167
+ getSpotToken(index: number): SpotToken | undefined;
168
+ private indexSpotTokens;
169
+ private processPerpsInstruments;
170
+ private processSpotInstruments;
171
+ private addInstrument;
172
+ /**
173
+ * Extract dex name from PerpsMeta
174
+ * Root dex (index 0) returns "", HIP3 dexes return the dex name (e.g., "xyz")
175
+ */
176
+ private extractDexNameFromMeta;
177
+ }
178
+
179
+ export { type AllPerpsMeta as A, type BaseInstrument as B, InstrumentClient as I, type MarketInstrument as M, type PerpsMeta as P, type SpotInstrument as S, type PerpsMetaAndAssetCtxs as a, type PerpsUniverse as b, type PerpsInstrument as c, AssetIdUtils as d, getAllPerpsMeta as g };