@rabby-wallet/hyperliquid-sdk 1.0.0-beta.1 → 1.0.0-beta.2

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.
@@ -5,9 +5,9 @@ import type { OrderResponse, CancelResponse, ExchangeClientConfig, PlaceOrderPar
5
5
  */
6
6
  export declare class ExchangeClient {
7
7
  private readonly httpClient;
8
- private agentPrivateKey;
9
- private agentPublicKey;
10
- private agentName;
8
+ private agentPrivateKey?;
9
+ private agentPublicKey?;
10
+ private agentName?;
11
11
  private readonly isTestnet;
12
12
  private readonly masterAddress;
13
13
  private builder?;
@@ -17,6 +17,8 @@ export declare class ExchangeClient {
17
17
  * Get the wallet address
18
18
  */
19
19
  get address(): string;
20
+ updateExchangeAgent(agentPrivateKey: string, agentPublicKey: string, agentName?: string): void;
21
+ private getAgentPrivateKey;
20
22
  updateBuilder(address: string, fee: number): Promise<any>;
21
23
  updateLeverage(params: UpdateLeverageParams): Promise<any>;
22
24
  /**
@@ -86,4 +88,5 @@ export declare class ExchangeClient {
86
88
  * Withdraw funds to L1 need use master wallet
87
89
  */
88
90
  prepareWithdraw(params: WithdrawParams): PrepareApproveBuilderFeeResult;
91
+ sendWithdraw(params: SendApproveParams): Promise<any>;
89
92
  }
@@ -47,6 +47,7 @@ const ethUtil = __importStar(require("@ethereumjs/util"));
47
47
  const http_client_1 = require("./http-client");
48
48
  const constants_1 = require("../types/constants");
49
49
  const signer_1 = require("../utils/signer");
50
+ const symbolConversion_1 = require("./symbolConversion");
50
51
  /**
51
52
  * Client for executing trades on Hyperliquid (perpetuals only)
52
53
  * Only includes essential trading APIs as specified
@@ -58,11 +59,25 @@ class ExchangeClient {
58
59
  isTestnet: config.isTestnet,
59
60
  timeout: config.timeout,
60
61
  });
61
- this.agentPrivateKey = config.agentPrivateKey.startsWith('0x') ? config.agentPrivateKey : ethUtil.addHexPrefix(config.agentPrivateKey);
62
- this.agentPublicKey = config.agentPublicKey.startsWith('0x') ? config.agentPublicKey : ethUtil.addHexPrefix(config.agentPublicKey);
63
- this.agentName = config.agentName || 'Rabby';
62
+ if (!config.symbolConversion) {
63
+ this.symbolConversion = new symbolConversion_1.SymbolConversion({
64
+ isTestnet: config.isTestnet,
65
+ timeout: config.timeout,
66
+ });
67
+ }
68
+ else {
69
+ this.symbolConversion = config.symbolConversion;
70
+ }
71
+ if (config.agentPrivateKey) {
72
+ this.agentPrivateKey = config.agentPrivateKey.startsWith('0x') ? config.agentPrivateKey : ethUtil.addHexPrefix(config.agentPrivateKey);
73
+ }
74
+ if (config.agentPublicKey) {
75
+ this.agentPublicKey = config.agentPublicKey.startsWith('0x') ? config.agentPublicKey : ethUtil.addHexPrefix(config.agentPublicKey);
76
+ }
77
+ if (config.agentName) {
78
+ this.agentName = config.agentName;
79
+ }
64
80
  this.isTestnet = config.isTestnet || false;
65
- this.symbolConversion = config.symbolConversion;
66
81
  }
67
82
  /**
68
83
  * Get the wallet address
@@ -70,6 +85,17 @@ class ExchangeClient {
70
85
  get address() {
71
86
  return this.masterAddress;
72
87
  }
88
+ updateExchangeAgent(agentPrivateKey, agentPublicKey, agentName) {
89
+ this.agentPrivateKey = agentPrivateKey.startsWith('0x') ? agentPrivateKey : ethUtil.addHexPrefix(agentPrivateKey);
90
+ this.agentPublicKey = agentPublicKey.startsWith('0x') ? agentPublicKey : ethUtil.addHexPrefix(agentPublicKey);
91
+ this.agentName = agentName || '';
92
+ }
93
+ getAgentPrivateKey() {
94
+ if (!this.agentPrivateKey) {
95
+ throw new Error('Agent private key is not set');
96
+ }
97
+ return this.agentPrivateKey;
98
+ }
73
99
  // 50 = '0.05%'
74
100
  updateBuilder(address, fee) {
75
101
  return __awaiter(this, void 0, void 0, function* () {
@@ -91,7 +117,7 @@ class ExchangeClient {
91
117
  isCross: params.isCross || false,
92
118
  leverage: params.leverage,
93
119
  };
94
- const signature = (0, signer_1.signL1AgentAction)(this.agentPrivateKey, action, this.isTestnet, nonce);
120
+ const signature = (0, signer_1.signL1AgentAction)(this.getAgentPrivateKey(), action, this.isTestnet, nonce);
95
121
  return this.httpClient.exchange({
96
122
  action,
97
123
  nonce,
@@ -124,7 +150,7 @@ class ExchangeClient {
124
150
  f: this.builder.fee,
125
151
  };
126
152
  }
127
- const signature = (0, signer_1.signL1AgentAction)(this.agentPrivateKey, action, this.isTestnet, nonce);
153
+ const signature = (0, signer_1.signL1AgentAction)(this.getAgentPrivateKey(), action, this.isTestnet, nonce);
128
154
  return this.httpClient.exchange({
129
155
  action,
130
156
  nonce,
@@ -257,7 +283,7 @@ class ExchangeClient {
257
283
  f: this.builder.fee,
258
284
  };
259
285
  }
260
- const signature = (0, signer_1.signL1AgentAction)(this.agentPrivateKey, action, this.isTestnet, nonce);
286
+ const signature = (0, signer_1.signL1AgentAction)(this.getAgentPrivateKey(), action, this.isTestnet, nonce);
261
287
  return this.httpClient.exchange({
262
288
  action,
263
289
  nonce,
@@ -326,7 +352,7 @@ class ExchangeClient {
326
352
  type: constants_1.ExchangeType.CANCEL,
327
353
  cancels: cancels,
328
354
  };
329
- const signature = (0, signer_1.signL1AgentAction)(this.agentPrivateKey, action, this.isTestnet, nonce);
355
+ const signature = (0, signer_1.signL1AgentAction)(this.getAgentPrivateKey(), action, this.isTestnet, nonce);
330
356
  return this.httpClient.exchange({
331
357
  action,
332
358
  nonce,
@@ -355,7 +381,7 @@ class ExchangeClient {
355
381
  type: constants_1.ExchangeType.MODIFY,
356
382
  modifies: [modify],
357
383
  };
358
- const signature = (0, signer_1.signL1AgentAction)(this.agentPrivateKey, action, this.isTestnet, nonce);
384
+ const signature = (0, signer_1.signL1AgentAction)(this.getAgentPrivateKey(), action, this.isTestnet, nonce);
359
385
  return this.httpClient.exchange({
360
386
  action,
361
387
  nonce,
@@ -374,7 +400,7 @@ class ExchangeClient {
374
400
  type: constants_1.ExchangeType.SET_REFERRER,
375
401
  code,
376
402
  };
377
- const signature = (0, signer_1.signL1AgentAction)(this.agentPrivateKey, action, this.isTestnet, nonce);
403
+ const signature = (0, signer_1.signL1AgentAction)(this.getAgentPrivateKey(), action, this.isTestnet, nonce);
378
404
  return this.httpClient.exchange({
379
405
  action,
380
406
  nonce,
@@ -517,5 +543,12 @@ class ExchangeClient {
517
543
  nonce,
518
544
  };
519
545
  }
546
+ sendWithdraw(params) {
547
+ return this.httpClient.exchange({
548
+ action: params.action,
549
+ nonce: params.nonce,
550
+ signature: params.signature,
551
+ });
552
+ }
520
553
  }
521
554
  exports.ExchangeClient = ExchangeClient;
@@ -41,6 +41,9 @@ class HttpClient {
41
41
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
42
42
  }
43
43
  const result = yield response.json();
44
+ if (result.status === 'error') {
45
+ throw new Error(JSON.stringify(result.response));
46
+ }
44
47
  return result;
45
48
  }
46
49
  catch (error) {
@@ -1,10 +1,8 @@
1
1
  import type { Meta, AssetCtx, ClearinghouseState, UserFills, CandleSnapshot, AllMids, ExtraAgent, OpenOrder, FeeResponse } from '../types';
2
- import { SymbolConversion } from './symbolConversion';
3
2
  export interface InfoClientConfig {
4
3
  isTestnet?: boolean;
5
4
  timeout?: number;
6
5
  masterAddress: string;
7
- symbolConversion: SymbolConversion;
8
6
  }
9
7
  /**
10
8
  * Client for querying Hyperliquid info endpoints (perpetuals only)
@@ -13,7 +11,6 @@ export interface InfoClientConfig {
13
11
  export declare class InfoClient {
14
12
  private readonly httpClient;
15
13
  private readonly masterAddress;
16
- private readonly symbolConversion;
17
14
  constructor(config: InfoClientConfig);
18
15
  /**
19
16
  * Get all mid prices for all assets
@@ -23,12 +20,12 @@ export declare class InfoClient {
23
20
  * Get metadata and asset contexts
24
21
  */
25
22
  metaAndAssetCtxs(): Promise<[Meta, AssetCtx[]]>;
26
- getClearingHouseState(): Promise<ClearinghouseState>;
27
- getFrontendOpenOrders(): Promise<OpenOrder[]>;
23
+ getClearingHouseState(address?: string): Promise<ClearinghouseState>;
24
+ getFrontendOpenOrders(address?: string): Promise<OpenOrder[]>;
28
25
  /**
29
26
  * Get user's fill history
30
27
  */
31
- getUserFills(): Promise<UserFills>;
28
+ getUserFills(address?: string): Promise<UserFills>;
32
29
  /**
33
30
  * Get candlestick data snapshot
34
31
  * Supported intervals: "1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "8h", "12h", "1d", "3d", "1w", "1M"
@@ -37,13 +34,19 @@ export declare class InfoClient {
37
34
  /**
38
35
  * Check builder fee approval status
39
36
  */
40
- checkBuilderFeeApproval(builder: string): Promise<any>;
37
+ checkBuilderFeeApproval(builder: string, address?: string): Promise<any>;
38
+ /**
39
+ * Get user role
40
+ */
41
+ getUserRole(address?: string): Promise<{
42
+ role: 'user' | 'agent' | 'vault' | 'subAccount' | 'missing';
43
+ }>;
41
44
  /**
42
45
  * Get user fees information
43
46
  */
44
- getUsersFees(): Promise<FeeResponse>;
47
+ getUsersFees(address?: string): Promise<FeeResponse>;
45
48
  /**
46
49
  * Get user's approved persistent agents
47
50
  */
48
- extraAgents(): Promise<ExtraAgent[]>;
51
+ extraAgents(address?: string): Promise<ExtraAgent[]>;
49
52
  }
@@ -23,7 +23,6 @@ class InfoClient {
23
23
  isTestnet: config.isTestnet,
24
24
  timeout: config.timeout,
25
25
  });
26
- this.symbolConversion = config.symbolConversion;
27
26
  }
28
27
  /**
29
28
  * Get all mid prices for all assets
@@ -45,20 +44,20 @@ class InfoClient {
45
44
  });
46
45
  });
47
46
  }
48
- getClearingHouseState() {
47
+ getClearingHouseState(address) {
49
48
  return __awaiter(this, void 0, void 0, function* () {
50
49
  return this.httpClient.info({
51
50
  type: constants_1.InfoType.CLEARINGHOUSE_STATE,
52
- user: this.masterAddress,
51
+ user: address || this.masterAddress,
53
52
  });
54
53
  });
55
54
  }
56
55
  // frontendOpenOrders
57
- getFrontendOpenOrders() {
56
+ getFrontendOpenOrders(address) {
58
57
  return __awaiter(this, void 0, void 0, function* () {
59
58
  return this.httpClient.info({
60
59
  type: constants_1.InfoType.FRONTEND_OPEN_ORDERS,
61
- user: this.masterAddress,
60
+ user: address || this.masterAddress,
62
61
  });
63
62
  });
64
63
  }
@@ -72,11 +71,11 @@ class InfoClient {
72
71
  /**
73
72
  * Get user's fill history
74
73
  */
75
- getUserFills() {
74
+ getUserFills(address) {
76
75
  return __awaiter(this, void 0, void 0, function* () {
77
76
  return this.httpClient.info({
78
77
  type: constants_1.InfoType.USER_FILLS,
79
- user: this.masterAddress,
78
+ user: address || this.masterAddress,
80
79
  });
81
80
  });
82
81
  }
@@ -103,23 +102,35 @@ class InfoClient {
103
102
  /**
104
103
  * Check builder fee approval status
105
104
  */
106
- checkBuilderFeeApproval(builder) {
105
+ checkBuilderFeeApproval(builder, address) {
107
106
  return __awaiter(this, void 0, void 0, function* () {
108
107
  return this.httpClient.info({
109
108
  type: constants_1.InfoType.CHECK_BUILDER_FEE_APPROVAL,
110
- user: this.masterAddress,
109
+ user: address || this.masterAddress,
111
110
  builder,
112
111
  });
113
112
  });
114
113
  }
114
+ /**
115
+ * Get user role
116
+ */
117
+ getUserRole(address) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const res = yield this.httpClient.info({
120
+ type: constants_1.InfoType.USER_ROLE,
121
+ user: address || this.masterAddress,
122
+ });
123
+ return res;
124
+ });
125
+ }
115
126
  /**
116
127
  * Get user fees information
117
128
  */
118
- getUsersFees() {
129
+ getUsersFees(address) {
119
130
  return __awaiter(this, void 0, void 0, function* () {
120
131
  const res = yield this.httpClient.info({
121
132
  type: constants_1.InfoType.USER_FEES,
122
- user: this.masterAddress,
133
+ user: address || this.masterAddress,
123
134
  });
124
135
  // const perpFee = Number(res.userCrossRate) * (1 - Number(res.activeReferralDiscount));
125
136
  return res;
@@ -128,11 +139,11 @@ class InfoClient {
128
139
  /**
129
140
  * Get user's approved persistent agents
130
141
  */
131
- extraAgents() {
142
+ extraAgents(address) {
132
143
  return __awaiter(this, void 0, void 0, function* () {
133
144
  return this.httpClient.info({
134
145
  type: constants_1.InfoType.EXTRA_AGENTS,
135
- user: this.masterAddress,
146
+ user: address || this.masterAddress,
136
147
  });
137
148
  });
138
149
  }
@@ -1,12 +1,10 @@
1
1
  import type { AllMids, L2Book, Candle, WsFill, WsOrder, WebData2 } from '../types';
2
- import { SymbolConversion } from './symbolConversion';
3
2
  export interface WebSocketClientConfig {
4
3
  masterAddress: string;
5
4
  isTestnet?: boolean;
6
5
  autoReconnect?: boolean;
7
6
  reconnectDelay?: number;
8
7
  maxReconnectAttempts?: number;
9
- symbolConversion: SymbolConversion;
10
8
  }
11
9
  export type SubscriptionCallback<T = any> = (data: T) => void;
12
10
  export interface Subscription {
@@ -24,7 +22,6 @@ export declare class WebSocketClient {
24
22
  private reconnectAttempts;
25
23
  private isConnecting;
26
24
  private pendingSubscriptions;
27
- private symbolConversion;
28
25
  constructor(config: WebSocketClientConfig);
29
26
  /**
30
27
  * Connect to the WebSocket
@@ -24,7 +24,6 @@ class WebSocketClient {
24
24
  this.pendingSubscriptions = [];
25
25
  this.config = Object.assign({ isTestnet: false, autoReconnect: true, reconnectDelay: 3000, maxReconnectAttempts: 5 }, config);
26
26
  this.url = this.config.isTestnet ? constants_1.WSS_URLS.TESTNET : constants_1.WSS_URLS.PRODUCTION;
27
- this.symbolConversion = config.symbolConversion;
28
27
  }
29
28
  /**
30
29
  * Connect to the WebSocket
@@ -29,7 +29,7 @@ export declare class HyperliquidSDK {
29
29
  * Get wallet address (only available if private key was provided)
30
30
  */
31
31
  get address(): string;
32
- updateExchangeAgent(agentPrivateKey: string, agentPublicKey: string, agentName: string): void;
32
+ updateExchangeAgent(agentPrivateKey: string, agentPublicKey: string, agentName?: string): void;
33
33
  /**
34
34
  * Connect to WebSocket for real-time data
35
35
  */
@@ -30,7 +30,6 @@ class HyperliquidSDK {
30
30
  masterAddress: config.masterAddress,
31
31
  isTestnet: config.isTestnet,
32
32
  timeout: config.timeout,
33
- symbolConversion: this.symbolConversion,
34
33
  });
35
34
  this.masterAddress = config.masterAddress;
36
35
  this.configParams = config;
@@ -47,7 +46,7 @@ class HyperliquidSDK {
47
46
  });
48
47
  }
49
48
  // Initialize WebSocket client (full functionality preserved)
50
- this.ws = new websocket_client_1.WebSocketClient(Object.assign({ masterAddress: config.masterAddress, isTestnet: config.isTestnet, symbolConversion: this.symbolConversion }, config.wsConfig));
49
+ this.ws = new websocket_client_1.WebSocketClient(Object.assign({ masterAddress: config.masterAddress, isTestnet: config.isTestnet }, config.wsConfig));
51
50
  }
52
51
  /**
53
52
  * Get wallet address (only available if private key was provided)
@@ -44,6 +44,7 @@ export declare enum InfoType {
44
44
  ACTIVE_ASSET_DATA = "activeAssetData",
45
45
  CHECK_BUILDER_FEE_APPROVAL = "checkBuilderFeeApproval",
46
46
  USER_FEES = "userFees",
47
+ USER_ROLE = "userRole",
47
48
  EXTRA_AGENTS = "extraAgents"
48
49
  }
49
50
  export declare enum OrderType {
@@ -52,6 +52,7 @@ var InfoType;
52
52
  InfoType["ACTIVE_ASSET_DATA"] = "activeAssetData";
53
53
  InfoType["CHECK_BUILDER_FEE_APPROVAL"] = "checkBuilderFeeApproval";
54
54
  InfoType["USER_FEES"] = "userFees";
55
+ InfoType["USER_ROLE"] = "userRole";
55
56
  InfoType["EXTRA_AGENTS"] = "extraAgents";
56
57
  })(InfoType || (exports.InfoType = InfoType = {}));
57
58
  // Order types
@@ -274,12 +274,12 @@ export interface ExtraAgent {
274
274
  }
275
275
  export interface ExchangeClientConfig {
276
276
  masterAddress: string;
277
- agentPrivateKey: string;
278
- agentPublicKey: string;
277
+ agentPrivateKey?: string;
278
+ agentPublicKey?: string;
279
279
  agentName?: string;
280
280
  isTestnet?: boolean;
281
281
  timeout?: number;
282
- symbolConversion: SymbolConversion;
282
+ symbolConversion?: SymbolConversion;
283
283
  }
284
284
  export interface PlaceOrderParams {
285
285
  coin: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/hyperliquid-sdk",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "Simplified Hyperliquid Perpetuals Trading SDK for Frontend Applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",