@basedone/core 0.0.7 → 0.0.9

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.
@@ -0,0 +1,25 @@
1
+ import "./chunk-KH53SPJC.mjs";
2
+
3
+ // lib/meta/data/mainnet/staticMeta.json
4
+ var coins = {
5
+ "xyz:XYZ100": {
6
+ imageUrl: "https://app.based.one/hip3/xyz/xyz100.webp",
7
+ displayName: "Nasdaq-100"
8
+ }
9
+ };
10
+ var dexs = {
11
+ xyz: {
12
+ imageUrl: "",
13
+ displayName: "Trade.xyz",
14
+ accountName: "Equities"
15
+ }
16
+ };
17
+ var staticMeta_default = {
18
+ coins,
19
+ dexs
20
+ };
21
+ export {
22
+ coins,
23
+ staticMeta_default as default,
24
+ dexs
25
+ };
@@ -0,0 +1,23 @@
1
+ import "./chunk-4UEJOM6W.mjs";
2
+
3
+ // lib/meta/data/testnet/staticMeta.json
4
+ var coins = {
5
+ "rrrrr:BTC": {
6
+ displayName: "BTCe"
7
+ }
8
+ };
9
+ var dexs = {
10
+ rrrrr: {
11
+ displayName: "Hyena",
12
+ accountName: "USDe Perps"
13
+ }
14
+ };
15
+ var staticMeta_default = {
16
+ coins,
17
+ dexs
18
+ };
19
+ export {
20
+ coins,
21
+ staticMeta_default as default,
22
+ dexs
23
+ };
@@ -0,0 +1,23 @@
1
+ import "./chunk-4UEJOM6W.mjs";
2
+
3
+ // lib/meta/data/testnet/staticMeta.json
4
+ var coins = {
5
+ "rrrrr:BTC": {
6
+ displayName: "BTCe"
7
+ }
8
+ };
9
+ var dexs = {
10
+ rrrrr: {
11
+ displayName: "Hyena",
12
+ accountName: "USDe"
13
+ }
14
+ };
15
+ var staticMeta_default = {
16
+ coins,
17
+ dexs
18
+ };
19
+ export {
20
+ coins,
21
+ staticMeta_default as default,
22
+ dexs
23
+ };
@@ -0,0 +1,25 @@
1
+ import "./chunk-4UEJOM6W.mjs";
2
+
3
+ // lib/meta/data/mainnet/staticMeta.json
4
+ var coins = {
5
+ "xyz:XYZ100": {
6
+ imageUrl: "https://app.based.one/hip3/xyz/xyz100.webp",
7
+ displayName: "Nasdaq-100"
8
+ }
9
+ };
10
+ var dexs = {
11
+ xyz: {
12
+ imageUrl: "",
13
+ displayName: "Trade.xyz",
14
+ tags: ["Equities"]
15
+ }
16
+ };
17
+ var staticMeta_default = {
18
+ coins,
19
+ dexs
20
+ };
21
+ export {
22
+ coins,
23
+ staticMeta_default as default,
24
+ dexs
25
+ };
@@ -0,0 +1,23 @@
1
+ import "./chunk-KH53SPJC.mjs";
2
+
3
+ // lib/meta/data/testnet/staticMeta.json
4
+ var coins = {
5
+ "rrrrr:BTC": {
6
+ displayName: "BTCe"
7
+ }
8
+ };
9
+ var dexs = {
10
+ rrrrr: {
11
+ displayName: "Hyena",
12
+ accountName: "USDe"
13
+ }
14
+ };
15
+ var staticMeta_default = {
16
+ coins,
17
+ dexs
18
+ };
19
+ export {
20
+ coins,
21
+ staticMeta_default as default,
22
+ dexs
23
+ };
@@ -0,0 +1,25 @@
1
+ import "./chunk-4UEJOM6W.mjs";
2
+
3
+ // lib/meta/data/mainnet/staticMeta.json
4
+ var coins = {
5
+ "xyz:XYZ100": {
6
+ imageUrl: "https://app.based.one/hip3/xyz/xyz100.webp",
7
+ displayName: "Nasdaq-100"
8
+ }
9
+ };
10
+ var dexs = {
11
+ xyz: {
12
+ imageUrl: "",
13
+ displayName: "Trade.xyz",
14
+ accountName: "Equities"
15
+ }
16
+ };
17
+ var staticMeta_default = {
18
+ coins,
19
+ dexs
20
+ };
21
+ export {
22
+ coins,
23
+ staticMeta_default as default,
24
+ dexs
25
+ };
package/index.ts CHANGED
@@ -4,3 +4,4 @@ export * from "./lib/pup";
4
4
  export * from "./lib/constants/tokens";
5
5
  export * from "./lib/meta/metadata";
6
6
  export * from "./lib/utils/formatter";
7
+ export * from "./lib/hip3/utils";
@@ -255,6 +255,7 @@ export const CloidClientCode = {
255
255
  Chase: 6,
256
256
  Desktop: 7,
257
257
  API: 8,
258
+ Stream: 9,
258
259
  } as const;
259
260
  type ClientCodeType = keyof typeof CloidClientCode;
260
261
 
@@ -270,6 +271,7 @@ export const CloidClientCodeNameById: Record<number, ClientCodeType> = {
270
271
  [CloidClientCode.Chase]: "Chase",
271
272
  [CloidClientCode.Desktop]: "Desktop",
272
273
  [CloidClientCode.API]: "API",
274
+ [CloidClientCode.Stream]: "Stream",
273
275
  };
274
276
 
275
277
  export function getClientCodeNameById(id: number): string {
@@ -282,6 +284,7 @@ export const WidgetType = {
282
284
  SidePanel: 1,
283
285
  Widget: 2,
284
286
  FloatingWidget: 3,
287
+ Stream: 4,
285
288
  } as const;
286
289
  type WidgetType = keyof typeof WidgetType;
287
290
 
@@ -292,6 +295,7 @@ export const WidgetTypeById: Record<number, WidgetType> = {
292
295
  [WidgetType.SidePanel]: "SidePanel",
293
296
  [WidgetType.Widget]: "Widget",
294
297
  [WidgetType.FloatingWidget]: "FloatingWidget",
298
+ [WidgetType.Stream]: "Stream",
295
299
  };
296
300
 
297
301
  export function getWidgetTypeById(id: number): string {
package/lib/hip3/utils.ts CHANGED
@@ -1,3 +1,13 @@
1
+ import {
2
+ ExchangeClient,
3
+ InfoClient,
4
+ SuccessResponse,
5
+ } from "@nktkas/hyperliquid";
6
+ import {
7
+ signL1Action,
8
+ signUserSignedAction,
9
+ } from "@nktkas/hyperliquid/signing";
10
+
1
11
  export function isHip3Symbol(symbol: string) {
2
12
  if (!symbol) return false;
3
13
  return symbol.includes(":");
@@ -7,3 +17,82 @@ export function getHip3Dex(symbol: string) {
7
17
  if (!symbol) return null;
8
18
  return symbol.split(":")[0];
9
19
  }
20
+
21
+ /**
22
+ * Enable HIP-3 DEX abstraction with the current agent wallet
23
+ * @param client Exchange client with agent wallet
24
+ * @returns Promise with success response
25
+ */
26
+ export async function enableHip3DexAbstractionWithAgent(
27
+ client: ExchangeClient,
28
+ ) {
29
+ const nonce = Date.now();
30
+ const action = {
31
+ type: "agentEnableDexAbstraction",
32
+ };
33
+ const signature = await signL1Action({
34
+ wallet: client.wallet,
35
+ action,
36
+ isTestnet: client.isTestnet,
37
+ nonce,
38
+ });
39
+ return await client.transport.request<SuccessResponse>("exchange", {
40
+ action,
41
+ signature,
42
+ nonce,
43
+ });
44
+ }
45
+
46
+ export const UserDexAbstractionTypes = {
47
+ "HyperliquidTransaction:UserDexAbstraction": [
48
+ { name: "hyperliquidChain", type: "string" },
49
+ { name: "user", type: "address" },
50
+ { name: "enabled", type: "bool" },
51
+ { name: "nonce", type: "uint64" },
52
+ ],
53
+ };
54
+
55
+ /**
56
+ * Set HIP-3 DEX abstraction for a user
57
+ * @param client Exchange client with owner wallet
58
+ * @param enabled Whether to enable HIP-3 DEX abstraction
59
+ * @param user User address
60
+ * @returns Promise with success response
61
+ */
62
+ export async function setHip3DexAbstraction(
63
+ client: ExchangeClient,
64
+ enabled: boolean,
65
+ user: string,
66
+ ) {
67
+ const nonce = Date.now();
68
+ const isTestnet = client.isTestnet;
69
+
70
+ const action = {
71
+ type: "userDexAbstraction",
72
+ hyperliquidChain: isTestnet ? "Testnet" : "Mainnet",
73
+ signatureChainId: isTestnet
74
+ ? ("0x66eee" as `0x${string}`)
75
+ : ("0xa4b1" as `0x${string}`),
76
+ user,
77
+ enabled,
78
+ nonce,
79
+ };
80
+
81
+ const signature = await signUserSignedAction({
82
+ wallet: client.wallet,
83
+ action,
84
+ types: UserDexAbstractionTypes,
85
+ });
86
+ return await client.transport.request<SuccessResponse>("exchange", {
87
+ action,
88
+ signature,
89
+ nonce: action.nonce,
90
+ });
91
+ }
92
+
93
+ export async function getHip3DexAbstraction(client: InfoClient, user: string) {
94
+ return await client.transport.request<boolean | null>("info", {
95
+ type: "userDexAbstraction",
96
+ user,
97
+ });
98
+ }
@@ -8,7 +8,8 @@
8
8
  "dexs": {
9
9
  "xyz": {
10
10
  "imageUrl": "",
11
- "displayName": "Stocks"
11
+ "displayName": "Trade.xyz",
12
+ "accountName": "Equities"
12
13
  }
13
14
  }
14
15
  }
@@ -6,7 +6,8 @@
6
6
  },
7
7
  "dexs": {
8
8
  "rrrrr": {
9
- "displayName": "Hyena"
9
+ "displayName": "Hyena",
10
+ "accountName": "USDe"
10
11
  }
11
12
  }
12
13
  }
@@ -7,7 +7,7 @@ import {
7
7
  SpotToken,
8
8
  } from "@nktkas/hyperliquid";
9
9
  import { isHip3Symbol } from "../hip3/utils";
10
- import { Hex } from "@nktkas/hyperliquid/script/src/types/mod";
10
+ import type { Hex } from "@nktkas/hyperliquid/types";
11
11
 
12
12
  export interface PerpDex {
13
13
  /** Short name of the perpetual dex. */
@@ -58,6 +58,7 @@ export interface DexInfo {
58
58
  collateralTokenSymbol: string;
59
59
  displayName?: string; // Display name override for the DEX
60
60
  imageUrl?: string; // Image URL override for the DEX
61
+ accountName?: string; // Account name override for the DEX
61
62
  }
62
63
 
63
64
  export type ExtendedPerpsMeta = PerpsMeta & {
@@ -89,6 +90,7 @@ interface StaticMetadata {
89
90
  [dexName: string]: {
90
91
  displayName?: string;
91
92
  imageUrl?: string;
93
+ accountName?: string;
92
94
  };
93
95
  };
94
96
  }
@@ -158,6 +160,7 @@ export class MetadataClient {
158
160
 
159
161
  // Lazy init flag
160
162
  private initialized: boolean = false;
163
+ private initializing: Promise<void> | null = null;
161
164
 
162
165
  constructor(config: MetadataClientConfig = {}) {
163
166
  const transport = new HttpTransport({
@@ -178,58 +181,65 @@ export class MetadataClient {
178
181
  */
179
182
  async initialize(): Promise<void> {
180
183
  if (this.initialized) return;
184
+ if (this.initializing) return this.initializing;
185
+ this.initializing = new Promise(async (resolve, reject) => {
186
+ // Always load staticMeta.json regardless of config.useStaticFallback
187
+ await this.loadStaticMetaOverrides();
181
188
 
182
- // Always load staticMeta.json regardless of config.useStaticFallback
183
- await this.loadStaticMetaOverrides();
184
-
185
- if (this.config.onlyUseStaticFallback) {
186
- await this.loadStaticMetadata();
187
- this.buildLookupMaps();
189
+ if (this.config.onlyUseStaticFallback) {
190
+ await this.loadStaticMetadata();
191
+ this.buildLookupMaps();
188
192
 
189
- // Fetch HIP-3 metadata if configured
190
- if (this.config.hip3Dexs && this.config.hip3Dexs.length > 0) {
191
- await Promise.all(
192
- this.config.hip3Dexs.map((dex) => this.loadHip3Metadata(dex)),
193
- );
193
+ // Fetch HIP-3 metadata if configured
194
+ if (this.config.hip3Dexs && this.config.hip3Dexs.length > 0) {
195
+ await Promise.all(
196
+ this.config.hip3Dexs.map((dex) => this.loadHip3Metadata(dex)),
197
+ );
198
+ }
199
+ resolve();
200
+ this.initialized = true;
201
+ return;
194
202
  }
195
203
 
196
- this.initialized = true;
197
- return;
198
- }
199
-
200
- try {
201
- // Fetch core metadata from API
202
- [this.spotMeta, this.perpsMeta, this.perpDexs] = await Promise.all([
203
- this.infoClient.spotMeta(),
204
- this.infoClient.meta(),
205
- this.infoClient.perpDexs() as Promise<PerpDex[] | null[]>,
206
- ]);
207
-
208
- // Build optimized lookup maps
209
- this.buildLookupMaps();
210
-
211
- // Fetch HIP-3 metadata if configured
212
- if (this.config.hip3Dexs && this.config.hip3Dexs.length > 0) {
213
- await Promise.all(
214
- this.config.hip3Dexs.map((dex) => this.loadHip3Metadata(dex)),
215
- );
216
- }
204
+ try {
205
+ // Fetch core metadata from API
206
+ [this.spotMeta, this.perpsMeta, this.perpDexs] = await Promise.all([
207
+ this.infoClient.spotMeta(),
208
+ this.infoClient.meta(),
209
+ this.infoClient.perpDexs() as Promise<PerpDex[] | null[]>,
210
+ ]);
217
211
 
218
- this.initialized = true;
219
- } catch (error) {
220
- // Fall back to static data if API fetch fails and fallback is enabled
221
- if (this.config.useStaticFallback) {
222
- console.warn(
223
- "Failed to fetch metadata from API, using static fallback data",
224
- error,
225
- );
226
- await this.loadStaticMetadata();
212
+ // Build optimized lookup maps
227
213
  this.buildLookupMaps();
214
+
215
+ // Fetch HIP-3 metadata if configured
216
+ if (this.config.hip3Dexs && this.config.hip3Dexs.length > 0) {
217
+ await Promise.all(
218
+ this.config.hip3Dexs.map((dex) => this.loadHip3Metadata(dex)),
219
+ );
220
+ }
228
221
  this.initialized = true;
229
- } else {
230
- throw error;
222
+ resolve();
223
+ } catch (error) {
224
+ // Fall back to static data if API fetch fails and fallback is enabled
225
+ if (this.config.useStaticFallback) {
226
+ console.warn(
227
+ "Failed to fetch metadata from API, using static fallback data",
228
+ error,
229
+ );
230
+ await this.loadStaticMetadata();
231
+ this.buildLookupMaps();
232
+ this.initialized = true;
233
+ resolve();
234
+ } else {
235
+ reject(error);
236
+ }
237
+ } finally {
238
+ this.initialized = true;
239
+ resolve();
231
240
  }
232
- }
241
+ });
242
+ return this.initializing;
233
243
  }
234
244
 
235
245
  /**
@@ -293,10 +303,16 @@ export class MetadataClient {
293
303
  this.spotPairToMarket.clear();
294
304
  this.baseTokenToMarkets.clear();
295
305
  this.coinToMarket.clear();
296
- this.hip3SymbolToMarket.clear();
297
306
  this.dexNameToIndex.clear();
298
307
  this.quoteAssets = [];
299
308
 
309
+ console.info(
310
+ "[MetadataClient] Building lookup maps",
311
+ this.perpDexs,
312
+ this.perpsMeta,
313
+ this.spotMeta,
314
+ );
315
+
300
316
  // Build dex name to index map
301
317
  if (this.perpDexs) {
302
318
  this.perpDexs.forEach((dex, index) => {
@@ -457,6 +473,9 @@ export class MetadataClient {
457
473
  if (staticDexOverrides.imageUrl) {
458
474
  dexInfo.imageUrl = staticDexOverrides.imageUrl;
459
475
  }
476
+ if (staticDexOverrides.accountName) {
477
+ dexInfo.accountName = staticDexOverrides.accountName;
478
+ }
460
479
  }
461
480
 
462
481
  this.hip3DexsMeta.set(dexName, dexInfo);
@@ -502,6 +521,8 @@ export class MetadataClient {
502
521
  }
503
522
  }
504
523
 
524
+ console.info("[MetadataClient] caching market", symbol, marketInfo);
525
+
505
526
  this.coinToMarket.set(symbol, marketInfo);
506
527
  this.hip3SymbolToMarket.set(symbol, marketInfo);
507
528
  });
@@ -624,6 +645,7 @@ export class MetadataClient {
624
645
  // Try O(1) lookup first (if DEX metadata already loaded)
625
646
  let cachedMarket = this.hip3SymbolToMarket.get(symbol);
626
647
  if (cachedMarket) return cachedMarket;
648
+ console.warn("Missing market", symbol, this.hip3SymbolToMarket);
627
649
 
628
650
  // If not found, check if we need to load DEX metadata
629
651
  const dexMeta = this.hip3DexsMeta.get(dexName);
@@ -701,6 +723,8 @@ export class MetadataClient {
701
723
  perpsMeta: this.perpsMeta,
702
724
  perpDexs: this.perpDexs,
703
725
  hip3DexsMeta: Object.fromEntries(this.hip3DexsMeta),
726
+ coinToMarket: Object.fromEntries(this.coinToMarket),
727
+ hip3SymbolToMarket: Object.fromEntries(this.hip3SymbolToMarket),
704
728
  };
705
729
  }
706
730
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basedone/core",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Core utilities for Based One",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",