@pear-protocol/exchanges-sdk 0.6.5 → 0.6.7

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 (92) hide show
  1. package/dist/client/base-ws.js +15 -6
  2. package/dist/client/binance/exchange-ws.js +22 -8
  3. package/dist/client/binance/rest.js +40 -27
  4. package/dist/client/binance/ws.js +21 -2
  5. package/dist/client/bybit/exchange-ws.js +13 -6
  6. package/dist/client/bybit/rest.js +30 -36
  7. package/dist/client/bybit/ws.js +16 -2
  8. package/dist/client/exchange-ws.js +5 -0
  9. package/dist/client/hmac.js +9 -1
  10. package/dist/client/hyperliquid/exchange-ws.js +13 -5
  11. package/dist/client/hyperliquid/rest.js +37 -7
  12. package/dist/client/hyperliquid/ws.js +10 -4
  13. package/dist/client/index.js +9 -2
  14. package/dist/client/lighter/constants.js +4 -0
  15. package/dist/client/lighter/exchange-ws.js +13 -5
  16. package/dist/client/lighter/rest.js +153 -18
  17. package/dist/client/lighter/ws.js +10 -4
  18. package/dist/client/okx/exchange-ws.js +13 -6
  19. package/dist/client/okx/rest.js +27 -24
  20. package/dist/client/okx/ws.js +5 -0
  21. package/dist/helper/factory.js +3 -0
  22. package/dist/helper/hyperliquid/helper.js +18 -23
  23. package/dist/helper/lighter/auth-token.helper.js +68 -0
  24. package/dist/helper/lighter/cctp-deposit.helper.js +297 -0
  25. package/dist/helper/lighter/ethereum/abi.js +55 -11
  26. package/dist/helper/lighter/ethereum/index.js +22 -3
  27. package/dist/helper/lighter/ethereum/usdc.helper.js +77 -0
  28. package/dist/helper/lighter/helper.js +116 -37
  29. package/dist/helper/lighter/index.js +1 -0
  30. package/dist/helper/lighter/onboarding.helper.js +28 -0
  31. package/dist/helper/lighter/types.js +6 -1
  32. package/dist/helper/subaccount.helper.js +20 -0
  33. package/dist/index.d.ts +202 -1
  34. package/dist/sdk.js +18 -7
  35. package/dist/status/base.js +16 -3
  36. package/dist/status/binance/status.js +3 -0
  37. package/dist/status/bybit/status.js +3 -0
  38. package/dist/status/factory.js +3 -0
  39. package/dist/status/hyperliquid/status.js +8 -6
  40. package/dist/status/lighter/status.js +11 -3
  41. package/dist/status/okx/status.js +3 -0
  42. package/dist/syncer/base.js +63 -24
  43. package/dist/syncer/binance/syncer.js +14 -13
  44. package/dist/syncer/bybit/syncer.js +10 -6
  45. package/dist/syncer/factory.js +3 -0
  46. package/dist/syncer/hyperliquid/funding.js +3 -0
  47. package/dist/syncer/hyperliquid/syncer.js +52 -66
  48. package/dist/syncer/lighter/funding.js +3 -0
  49. package/dist/syncer/lighter/syncer.js +26 -25
  50. package/dist/syncer/okx/syncer.js +15 -13
  51. package/dist/tracker/base.js +15 -5
  52. package/dist/tracker/binance/mapper.js +5 -1
  53. package/dist/tracker/binance/tracker.js +63 -23
  54. package/dist/tracker/binance/types.js +2 -2
  55. package/dist/tracker/bybit/mapper.js +7 -1
  56. package/dist/tracker/bybit/tracker.js +68 -24
  57. package/dist/tracker/bybit/types.js +2 -2
  58. package/dist/tracker/hyperliquid/const.js +3 -1
  59. package/dist/tracker/hyperliquid/mapper.js +36 -20
  60. package/dist/tracker/hyperliquid/tracker.js +147 -54
  61. package/dist/tracker/hyperliquid/types.js +2 -2
  62. package/dist/tracker/index.js +3 -0
  63. package/dist/tracker/lighter/mapper.js +41 -31
  64. package/dist/tracker/lighter/tracker.js +68 -27
  65. package/dist/tracker/lighter/types.js +4 -4
  66. package/dist/tracker/okx/mapper.js +8 -0
  67. package/dist/tracker/okx/tracker.js +69 -18
  68. package/dist/tracker/okx/types.js +2 -2
  69. package/dist/tracker/utils.js +4 -0
  70. package/package.json +3 -3
  71. package/dist/client/hyperliquid/client.test.js +0 -41
  72. package/dist/client/lighter/constants.test.js +0 -22
  73. package/dist/client/lighter/rest.test.js +0 -158
  74. package/dist/helper/hyperliquid/helper.test.js +0 -72
  75. package/dist/helper/lighter/helper.test.js +0 -289
  76. package/dist/sdk.test.js +0 -117
  77. package/dist/status/hyperliquid/status.test.js +0 -94
  78. package/dist/status/lighter/status.test.js +0 -86
  79. package/dist/syncer/base.test.js +0 -178
  80. package/dist/syncer/hyperliquid/funding.test.js +0 -63
  81. package/dist/syncer/hyperliquid/syncer.test.js +0 -271
  82. package/dist/syncer/lighter/funding.test.js +0 -48
  83. package/dist/syncer/lighter/syncer.test.js +0 -274
  84. package/dist/tracker/base.test.js +0 -132
  85. package/dist/tracker/binance/tracker.test.js +0 -138
  86. package/dist/tracker/bybit/tracker.test.js +0 -145
  87. package/dist/tracker/hyperliquid/mapper.test.js +0 -260
  88. package/dist/tracker/hyperliquid/tracker.test.js +0 -597
  89. package/dist/tracker/lighter/mapper.test.js +0 -199
  90. package/dist/tracker/lighter/tracker.test.js +0 -515
  91. package/dist/tracker/okx/tracker.test.js +0 -126
  92. package/dist/tracker/utils.test.js +0 -8
@@ -2,9 +2,12 @@ import BigNumber from 'bignumber.js';
2
2
  import { positionKey } from '../utils';
3
3
  import { COLLATERAL_TOKEN_MAP, HyperliquidAccountType } from './types';
4
4
 
5
- const LEGACY_COLLATERAL_TOKEN_MAP = new Map(
6
- Object.entries(COLLATERAL_TOKEN_MAP).map(([token, coin]) => [Number(token), coin])
7
- );
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ const LEGACY_COLLATERAL_TOKEN_MAP = new Map(Object.entries(COLLATERAL_TOKEN_MAP).map(([token, coin]) => [
8
+ Number(token),
9
+ coin
10
+ ]));
8
11
  const FULL_UTILIZATION_RATIO = "1.0000";
9
12
  const ZERO_COLLATERAL_SUMMARY = {
10
13
  accountValue: "0",
@@ -36,26 +39,25 @@ function aggregateClearinghouseStates(states) {
36
39
  if (position.position.leverage.type !== "isolated") {
37
40
  return [];
38
41
  }
39
- return [{ collateral: position.position.marginUsed, maintenance: isolatedMaintenanceMargin(dexState, position) }];
42
+ return [
43
+ {
44
+ collateral: position.position.marginUsed,
45
+ maintenance: isolatedMaintenanceMargin(dexState, position)
46
+ }
47
+ ];
40
48
  });
41
49
  const isolatedMaintenanceMarginUsed = sum(isolatedRisks.map((risk) => risk.maintenance));
42
50
  const isolatedMarginUsed = sum(isolatedRisks.map((risk) => risk.collateral));
43
51
  let dexMaximumMarginRatio = ratio(state.crossMaintenanceMarginUsed, state.crossMarginSummary.accountValue);
44
52
  for (const isolatedRisk of isolatedRisks) {
45
- dexMaximumMarginRatio = BigNumber.max(
46
- dexMaximumMarginRatio,
47
- ratio(isolatedRisk.maintenance, isolatedRisk.collateral)
48
- ).toFixed(4);
53
+ dexMaximumMarginRatio = BigNumber.max(dexMaximumMarginRatio, ratio(isolatedRisk.maintenance, isolatedRisk.collateral)).toFixed(4);
49
54
  }
50
55
  summary.accountValue = add(summary.accountValue, state.marginSummary.accountValue);
51
56
  summary.totalMarginUsed = add(summary.totalMarginUsed, state.marginSummary.totalMarginUsed);
52
57
  summary.totalRawUsd = add(summary.totalRawUsd, state.marginSummary.totalRawUsd);
53
58
  summary.crossMaintenanceMarginUsed = add(summary.crossMaintenanceMarginUsed, state.crossMaintenanceMarginUsed);
54
59
  summary.isolatedMaintenanceMarginUsed = add(summary.isolatedMaintenanceMarginUsed, isolatedMaintenanceMarginUsed);
55
- summary.maximumStandardMarginRatio = BigNumber.max(
56
- summary.maximumStandardMarginRatio,
57
- dexMaximumMarginRatio
58
- ).toFixed(4);
60
+ summary.maximumStandardMarginRatio = BigNumber.max(summary.maximumStandardMarginRatio, dexMaximumMarginRatio).toFixed(4);
59
61
  summary.withdrawable = add(summary.withdrawable, state.withdrawable);
60
62
  summary.totalUnrealizedPnl = add(summary.totalUnrealizedPnl, unrealizedPnl);
61
63
  assetPositions.push(...positions);
@@ -73,8 +75,12 @@ function aggregateClearinghouseStates(states) {
73
75
  totalUnrealizedPnl: add(collateral.totalUnrealizedPnl, unrealizedPnl)
74
76
  });
75
77
  }
76
- return { summary, assetPositions };
78
+ return {
79
+ summary,
80
+ assetPositions
81
+ };
77
82
  }
83
+ __name(aggregateClearinghouseStates, "aggregateClearinghouseStates");
78
84
  function mapBalance(summary, spotCoinBalances, accountType, collateralTokenMap = LEGACY_COLLATERAL_TOKEN_MAP) {
79
85
  if (!accountType) {
80
86
  return null;
@@ -88,6 +94,7 @@ function mapBalance(summary, spotCoinBalances, accountType, collateralTokenMap =
88
94
  return mapUnifiedBalance(summary, spotCoinBalances, accountType, collateralTokenMap);
89
95
  }
90
96
  }
97
+ __name(mapBalance, "mapBalance");
91
98
  function mapPositions(raw) {
92
99
  const positions = /* @__PURE__ */ new Map();
93
100
  for (const assetPosition of raw) {
@@ -111,6 +118,7 @@ function mapPositions(raw) {
111
118
  }
112
119
  return positions;
113
120
  }
121
+ __name(mapPositions, "mapPositions");
114
122
  function mapStandardBalance(summary, accountType, collateralTokenMap) {
115
123
  const free = {};
116
124
  const used = {};
@@ -150,6 +158,7 @@ function mapStandardBalance(summary, accountType, collateralTokenMap) {
150
158
  timestamp: Date.now()
151
159
  };
152
160
  }
161
+ __name(mapStandardBalance, "mapStandardBalance");
153
162
  function mapUnifiedBalance(summary, spotCoinBalances, accountType, collateralTokenMap) {
154
163
  const free = {};
155
164
  const used = {};
@@ -199,15 +208,19 @@ function mapUnifiedBalance(summary, spotCoinBalances, accountType, collateralTok
199
208
  timestamp: Date.now()
200
209
  };
201
210
  }
211
+ __name(mapUnifiedBalance, "mapUnifiedBalance");
202
212
  function unifiedMarginRatio(summary, spotCoinBalances) {
203
213
  let maximumRatio = new BigNumber(0);
204
214
  for (const [token, collateral] of summary.byCollateralToken) {
205
- const spotBalance = [...spotCoinBalances.values()].find((balance) => balance.token === token);
215
+ const spotBalance = [
216
+ ...spotCoinBalances.values()
217
+ ].find((balance) => balance.token === token);
206
218
  const available = new BigNumber(spotBalance?.total ?? "0").minus(collateral.isolatedMarginUsed);
207
219
  maximumRatio = BigNumber.max(maximumRatio, ratio(collateral.crossMaintenanceMarginUsed, available.toFixed()));
208
220
  }
209
221
  return maximumRatio.toFixed(4);
210
222
  }
223
+ __name(unifiedMarginRatio, "unifiedMarginRatio");
211
224
  function isolatedMaintenanceMargin(dexState, assetPosition) {
212
225
  const position = assetPosition.position;
213
226
  if (position.leverage.type !== "isolated" || position.maxLeverage <= 0) {
@@ -227,36 +240,38 @@ function isolatedMaintenanceMargin(dexState, assetPosition) {
227
240
  }
228
241
  const previousRate = maintenanceMarginRate(activeTier.maxLeverage);
229
242
  const nextRate = maintenanceMarginRate(nextTier.maxLeverage);
230
- maintenanceDeduction = maintenanceDeduction.plus(
231
- new BigNumber(nextTier.lowerBound).times(nextRate.minus(previousRate))
232
- );
243
+ maintenanceDeduction = maintenanceDeduction.plus(new BigNumber(nextTier.lowerBound).times(nextRate.minus(previousRate)));
233
244
  activeTier = nextTier;
234
245
  }
235
246
  return notional.times(maintenanceMarginRate(activeTier.maxLeverage)).minus(maintenanceDeduction).toFixed();
236
247
  }
248
+ __name(isolatedMaintenanceMargin, "isolatedMaintenanceMargin");
237
249
  function findMarginTiers(dexState, coin) {
238
250
  if (!dexState.meta) {
239
251
  return null;
240
252
  }
241
253
  const unprefixedCoin = dexState.dex && coin.startsWith(`${dexState.dex}:`) ? coin.slice(dexState.dex.length + 1) : coin;
242
- const asset = dexState.meta.universe.find(
243
- (candidate) => candidate.name === coin || candidate.name === unprefixedCoin
244
- );
254
+ const asset = dexState.meta.universe.find((candidate) => candidate.name === coin || candidate.name === unprefixedCoin);
245
255
  const marginTable = dexState.meta.marginTables.find(([id]) => id === asset?.marginTableId)?.[1];
246
256
  return marginTable?.marginTiers.length ? marginTable.marginTiers : null;
247
257
  }
258
+ __name(findMarginTiers, "findMarginTiers");
248
259
  function maintenanceMarginRate(maxLeverage) {
249
260
  return new BigNumber(1).div(maxLeverage).div(2);
250
261
  }
262
+ __name(maintenanceMarginRate, "maintenanceMarginRate");
251
263
  function add(left, right) {
252
264
  return new BigNumber(left || "0").plus(right || "0").toFixed();
253
265
  }
266
+ __name(add, "add");
254
267
  function subtract(left, right) {
255
268
  return new BigNumber(left || "0").minus(right || "0").toFixed();
256
269
  }
270
+ __name(subtract, "subtract");
257
271
  function sum(values) {
258
272
  return values.reduce((total, value) => total.plus(value || "0"), new BigNumber(0)).toFixed();
259
273
  }
274
+ __name(sum, "sum");
260
275
  function ratio(numerator, denominator) {
261
276
  const numeratorValue = new BigNumber(numerator || "0");
262
277
  const denominatorValue = new BigNumber(denominator || "0");
@@ -265,5 +280,6 @@ function ratio(numerator, denominator) {
265
280
  }
266
281
  return numeratorValue.gt(0) ? FULL_UTILIZATION_RATIO : "0.0000";
267
282
  }
283
+ __name(ratio, "ratio");
268
284
 
269
285
  export { aggregateClearinghouseStates, mapBalance, mapPositions };
@@ -6,7 +6,12 @@ import { LOCKED_TRACKED_COINS } from './const';
6
6
  import { aggregateClearinghouseStates, mapBalance, mapPositions } from './mapper';
7
7
  import { HyperliquidAccountType, COLLATERAL_TOKEN_MAP } from './types';
8
8
 
9
+ var __defProp = Object.defineProperty;
10
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
11
  class HyperliquidAccountTracker extends BaseAccountTracker {
12
+ static {
13
+ __name(this, "HyperliquidAccountTracker");
14
+ }
10
15
  address;
11
16
  ws = null;
12
17
  messageListenerId = null;
@@ -26,42 +31,45 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
26
31
  this.address = config.account.exchangeIdentifier;
27
32
  }
28
33
  /**
29
- * Reads account mode, collateral balances, per-DEX state, and positions without opening a socket.
30
- */
34
+ * Reads account mode, collateral balances, per-DEX state, and positions without opening a socket.
35
+ */
31
36
  async snapshot() {
32
37
  const user = this.addrLower();
33
38
  const [perpDexs, allMetas, spotMeta, abstraction, spotState] = await Promise.all([
34
39
  fetchPerpDexs(this.demo),
35
- fetchInfo({ type: "allPerpMetas" }, this.demo),
36
- fetchInfo({ type: "spotMeta" }, this.demo),
40
+ fetchInfo({
41
+ type: "allPerpMetas"
42
+ }, this.demo),
43
+ fetchInfo({
44
+ type: "spotMeta"
45
+ }, this.demo),
37
46
  fetchUserAbstraction(user, this.demo),
38
47
  fetchSpotClearinghouseState(user, this.demo)
39
48
  ]);
40
49
  const descriptors = uniqueDexDescriptors(perpDexs, allMetas);
41
- const clearinghouseStates = await Promise.all(
42
- descriptors.map(
43
- async ({ dex, meta }) => ({
44
- dex,
45
- collateralToken: meta?.collateralToken ?? null,
46
- meta,
47
- state: await fetchClearinghouseState(user, dex, this.demo)
48
- })
49
- )
50
- );
50
+ const clearinghouseStates = await Promise.all(descriptors.map(async ({ dex, meta }) => ({
51
+ dex,
52
+ collateralToken: meta?.collateralToken ?? null,
53
+ meta,
54
+ state: await fetchClearinghouseState(user, dex, this.demo)
55
+ })));
51
56
  const { summary, assetPositions } = aggregateClearinghouseStates(clearinghouseStates);
52
57
  const accountType = resolveHyperliquidAccountType(abstraction);
53
58
  const collateralTokenMap = buildCollateralTokenMap(allMetas, spotMeta);
54
59
  const spotCoinBalances = mapSpotBalances(spotState);
55
60
  const balance = mapBalance(summary, spotCoinBalances, accountType, collateralTokenMap);
56
61
  const positions = Array.from(mapPositions(assetPositions).values());
57
- return { balance, positions };
62
+ return {
63
+ balance,
64
+ positions
65
+ };
58
66
  }
59
67
  /**
60
- * Stateless one-shot per-asset settings read via the `activeAssetData` info request (the REST
61
- * twin of the live WS subscription), one request per coin fired in parallel — the info endpoint
62
- * has no batch form. Per-coin reads are tolerant (a failed coin maps to `null`); the read only
63
- * throws if every coin fetch fails.
64
- */
68
+ * Stateless one-shot per-asset settings read via the `activeAssetData` info request (the REST
69
+ * twin of the live WS subscription), one request per coin fired in parallel — the info endpoint
70
+ * has no batch form. Per-coin reads are tolerant (a failed coin maps to `null`); the read only
71
+ * throws if every coin fetch fails.
72
+ */
65
73
  async fetchAssetSnapshots(coins) {
66
74
  const user = this.addrLower();
67
75
  const settled = await Promise.allSettled(coins.map((coin) => fetchActiveAssetData(user, coin, this.demo)));
@@ -83,16 +91,23 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
83
91
  this.resetLiveAccountState();
84
92
  this.dexToMeta.clear();
85
93
  const [allMetas, perpDexs, spotMeta, abstraction] = await Promise.all([
86
- fetchInfo({ type: "allPerpMetas" }, this.demo),
94
+ fetchInfo({
95
+ type: "allPerpMetas"
96
+ }, this.demo),
87
97
  fetchPerpDexs(this.demo),
88
- fetchInfo({ type: "spotMeta" }, this.demo),
98
+ fetchInfo({
99
+ type: "spotMeta"
100
+ }, this.demo),
89
101
  fetchUserAbstraction(user, this.demo)
90
102
  ]);
91
103
  if (lifecycleVersion !== this.lifecycleVersion) return;
92
104
  this.loadPerpMetas(allMetas, perpDexs);
93
105
  this.collateralTokenMap = buildCollateralTokenMap(allMetas, spotMeta);
94
106
  this.accountType = resolveHyperliquidAccountType(abstraction);
95
- const ws = (await createExchangeWs("hyperliquid", { demo: this.demo, credentials: this.credentials })).main;
107
+ const ws = (await createExchangeWs("hyperliquid", {
108
+ demo: this.demo,
109
+ credentials: this.credentials
110
+ })).main;
96
111
  if (lifecycleVersion !== this.lifecycleVersion) {
97
112
  ws.destroy();
98
113
  return;
@@ -101,7 +116,10 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
101
116
  this.messageListenerId = this.ws.addMessageListener((raw) => this.routeRaw(raw));
102
117
  this.openListenerId = this.ws.addOpenListener(() => this.resubscribeAll());
103
118
  this.sendStaticSubs();
104
- const coinsToTrack = /* @__PURE__ */ new Set([...LOCKED_TRACKED_COINS, ...this.trackedCoins]);
119
+ const coinsToTrack = /* @__PURE__ */ new Set([
120
+ ...LOCKED_TRACKED_COINS,
121
+ ...this.trackedCoins
122
+ ]);
105
123
  for (const coin of coinsToTrack) {
106
124
  this.ensureAssetTracked(coin);
107
125
  }
@@ -132,7 +150,11 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
132
150
  this.subscribedCoins.add(coin);
133
151
  this.ws?.send({
134
152
  method: "subscribe",
135
- subscription: { type: "activeAssetData", coin, user: this.addrLower() }
153
+ subscription: {
154
+ type: "activeAssetData",
155
+ coin,
156
+ user: this.addrLower()
157
+ }
136
158
  });
137
159
  }
138
160
  releaseAsset(coin) {
@@ -141,10 +163,16 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
141
163
  this.subscribedCoins.delete(coin);
142
164
  this.ws?.send({
143
165
  method: "unsubscribe",
144
- subscription: { type: "activeAssetData", coin, user: this.addrLower() }
166
+ subscription: {
167
+ type: "activeAssetData",
168
+ coin,
169
+ user: this.addrLower()
170
+ }
145
171
  });
146
172
  this.trackedAssetData.delete(coin);
147
- this.onStateUpdate({ trackedAssets: this.buildTrackedAssetsMap() });
173
+ this.onStateUpdate({
174
+ trackedAssets: this.buildTrackedAssetsMap()
175
+ });
148
176
  }
149
177
  isLocked(coin) {
150
178
  return LOCKED_TRACKED_COINS.includes(coin);
@@ -154,15 +182,37 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
154
182
  }
155
183
  sendStaticSubs() {
156
184
  const user = this.addrLower();
157
- this.ws?.send({ method: "subscribe", subscription: { type: "allDexsClearinghouseState", user } });
185
+ this.ws?.send({
186
+ method: "subscribe",
187
+ subscription: {
188
+ type: "allDexsClearinghouseState",
189
+ user
190
+ }
191
+ });
158
192
  this.sendSpotStateSubscription("subscribe", this.accountType);
159
- this.ws?.send({ method: "subscribe", subscription: { type: "webData3", user } });
193
+ this.ws?.send({
194
+ method: "subscribe",
195
+ subscription: {
196
+ type: "webData3",
197
+ user
198
+ }
199
+ });
160
200
  }
161
201
  /** Subscribes to the spot state variant required by the active account mode. */
162
202
  sendSpotStateSubscription(method, accountType) {
163
203
  const user = this.addrLower();
164
- const subscription = accountType === HyperliquidAccountType.PORTFOLIO_MARGIN ? { type: "spotState", user, isPortfolioMargin: true } : { type: "spotState", user };
165
- this.ws?.send({ method, subscription });
204
+ const subscription = accountType === HyperliquidAccountType.PORTFOLIO_MARGIN ? {
205
+ type: "spotState",
206
+ user,
207
+ isPortfolioMargin: true
208
+ } : {
209
+ type: "spotState",
210
+ user
211
+ };
212
+ this.ws?.send({
213
+ method,
214
+ subscription
215
+ });
166
216
  }
167
217
  resubscribeAll() {
168
218
  this.resetLiveAccountState();
@@ -171,7 +221,11 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
171
221
  for (const coin of this.subscribedCoins) {
172
222
  this.ws?.send({
173
223
  method: "subscribe",
174
- subscription: { type: "activeAssetData", coin, user }
224
+ subscription: {
225
+ type: "activeAssetData",
226
+ coin,
227
+ user
228
+ }
175
229
  });
176
230
  }
177
231
  }
@@ -181,16 +235,28 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
181
235
  if (!msg.channel || !msg.data) return;
182
236
  switch (msg.channel) {
183
237
  case "allDexsClearinghouseState":
184
- this.handle({ kind: "clearinghouseState", data: msg.data });
238
+ this.handle({
239
+ kind: "clearinghouseState",
240
+ data: msg.data
241
+ });
185
242
  break;
186
243
  case "spotState":
187
- this.handle({ kind: "spotState", data: msg.data });
244
+ this.handle({
245
+ kind: "spotState",
246
+ data: msg.data
247
+ });
188
248
  break;
189
249
  case "webData3":
190
- this.handle({ kind: "webData3", data: msg.data });
250
+ this.handle({
251
+ kind: "webData3",
252
+ data: msg.data
253
+ });
191
254
  break;
192
255
  case "activeAssetData":
193
- this.handle({ kind: "activeAssetData", data: msg.data });
256
+ this.handle({
257
+ kind: "activeAssetData",
258
+ data: msg.data
259
+ });
194
260
  break;
195
261
  }
196
262
  } catch (err) {
@@ -220,23 +286,23 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
220
286
  });
221
287
  }
222
288
  onClearinghouseState(data) {
223
- const states = (data.clearinghouseStates || []).flatMap(
224
- ([dex, state]) => state ? [
225
- {
226
- dex,
227
- collateralToken: this.dexToMeta.get(dex)?.collateralToken ?? null,
228
- meta: this.dexToMeta.get(dex) ?? null,
229
- state
230
- }
231
- ] : []
232
- );
289
+ const states = (data.clearinghouseStates || []).flatMap(([dex, state]) => state ? [
290
+ {
291
+ dex,
292
+ collateralToken: this.dexToMeta.get(dex)?.collateralToken ?? null,
293
+ meta: this.dexToMeta.get(dex) ?? null,
294
+ state
295
+ }
296
+ ] : []);
233
297
  const { summary, assetPositions } = aggregateClearinghouseStates(states);
234
298
  this.lastSummary = summary;
235
299
  this.hasClearinghouseState = true;
236
300
  const balance = this.buildBalance();
237
301
  const positions = mapPositions(assetPositions);
238
302
  this.onStateUpdate({
239
- ...balance === void 0 ? {} : { balance },
303
+ ...balance === void 0 ? {} : {
304
+ balance
305
+ },
240
306
  positions,
241
307
  positionsMode: "replace"
242
308
  });
@@ -247,7 +313,9 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
247
313
  this.trackedAssetData.set(data.coin, data);
248
314
  const trackedAssets = /* @__PURE__ */ new Map();
249
315
  trackedAssets.set(data.coin, buildTrackedAssetInfo(data));
250
- this.onStateUpdate({ trackedAssets });
316
+ this.onStateUpdate({
317
+ trackedAssets
318
+ });
251
319
  }
252
320
  onWebData3(data) {
253
321
  const previousAccountType = this.accountType;
@@ -262,12 +330,16 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
262
330
  }
263
331
  this.accountType = nextAccountType;
264
332
  if (!nextAccountType) {
265
- this.onStateUpdate({ balance: null });
333
+ this.onStateUpdate({
334
+ balance: null
335
+ });
266
336
  return;
267
337
  }
268
338
  const balance = this.buildBalance();
269
339
  if (balance !== void 0) {
270
- this.onStateUpdate({ balance });
340
+ this.onStateUpdate({
341
+ balance
342
+ });
271
343
  }
272
344
  }
273
345
  onSpotState(data) {
@@ -277,7 +349,9 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
277
349
  this.hasSpotState = true;
278
350
  const balance = this.buildBalance();
279
351
  if (balance !== void 0) {
280
- this.onStateUpdate({ balance });
352
+ this.onStateUpdate({
353
+ balance
354
+ });
281
355
  }
282
356
  }
283
357
  buildBalance() {
@@ -312,6 +386,7 @@ function buildTrackedAssetInfo(data) {
312
386
  marginType: data.leverage?.type
313
387
  };
314
388
  }
389
+ __name(buildTrackedAssetInfo, "buildTrackedAssetInfo");
315
390
  const HYPERLIQUID_ACCOUNT_TYPES = Object.values(HyperliquidAccountType);
316
391
  function toHyperliquidAccountType(abstraction) {
317
392
  if (!abstraction) {
@@ -319,9 +394,11 @@ function toHyperliquidAccountType(abstraction) {
319
394
  }
320
395
  return HYPERLIQUID_ACCOUNT_TYPES.includes(abstraction) ? abstraction : null;
321
396
  }
397
+ __name(toHyperliquidAccountType, "toHyperliquidAccountType");
322
398
  function resolveHyperliquidAccountType(abstraction) {
323
399
  return toHyperliquidAccountType(abstraction);
324
400
  }
401
+ __name(resolveHyperliquidAccountType, "resolveHyperliquidAccountType");
325
402
  function uniqueDexDescriptors(perpDexs, allMetas) {
326
403
  const seen = /* @__PURE__ */ new Set();
327
404
  return perpDexs.flatMap((descriptor, index) => {
@@ -330,9 +407,15 @@ function uniqueDexDescriptors(perpDexs, allMetas) {
330
407
  return [];
331
408
  }
332
409
  seen.add(dex);
333
- return [{ dex, meta: allMetas[index] ?? null }];
410
+ return [
411
+ {
412
+ dex,
413
+ meta: allMetas[index] ?? null
414
+ }
415
+ ];
334
416
  });
335
417
  }
418
+ __name(uniqueDexDescriptors, "uniqueDexDescriptors");
336
419
  function mapSpotBalances(spotState) {
337
420
  const balances = /* @__PURE__ */ new Map();
338
421
  const availableAfterMaintenance = new Map(spotState.tokenToAvailableAfterMaintenance ?? []);
@@ -350,6 +433,7 @@ function mapSpotBalances(spotState) {
350
433
  }
351
434
  return balances;
352
435
  }
436
+ __name(mapSpotBalances, "mapSpotBalances");
353
437
  function emptySummary() {
354
438
  return {
355
439
  accountValue: "0",
@@ -363,8 +447,12 @@ function emptySummary() {
363
447
  byCollateralToken: /* @__PURE__ */ new Map()
364
448
  };
365
449
  }
450
+ __name(emptySummary, "emptySummary");
366
451
  function buildCollateralTokenMap(allMetas, spotMeta) {
367
- const spotTokenNames = new Map(spotMeta.tokens.map((token) => [token.index, token.name]));
452
+ const spotTokenNames = new Map(spotMeta.tokens.map((token) => [
453
+ token.index,
454
+ token.name
455
+ ]));
368
456
  const result = /* @__PURE__ */ new Map();
369
457
  for (const meta of allMetas) {
370
458
  const token = meta.collateralToken;
@@ -375,8 +463,13 @@ function buildCollateralTokenMap(allMetas, spotMeta) {
375
463
  }
376
464
  return result;
377
465
  }
466
+ __name(buildCollateralTokenMap, "buildCollateralTokenMap");
378
467
  function legacyCollateralTokenMap() {
379
- return new Map(Object.entries(COLLATERAL_TOKEN_MAP).map(([token, coin]) => [Number(token), coin]));
468
+ return new Map(Object.entries(COLLATERAL_TOKEN_MAP).map(([token, coin]) => [
469
+ Number(token),
470
+ coin
471
+ ]));
380
472
  }
473
+ __name(legacyCollateralTokenMap, "legacyCollateralTokenMap");
381
474
 
382
475
  export { HyperliquidAccountTracker };
@@ -1,10 +1,10 @@
1
- var HyperliquidAccountType = /* @__PURE__ */ ((HyperliquidAccountType2) => {
1
+ var HyperliquidAccountType = /* @__PURE__ */ (function(HyperliquidAccountType2) {
2
2
  HyperliquidAccountType2["DEFAULT"] = "default";
3
3
  HyperliquidAccountType2["DISABLED"] = "disabled";
4
4
  HyperliquidAccountType2["PORTFOLIO_MARGIN"] = "portfolioMargin";
5
5
  HyperliquidAccountType2["UNIFIED_ACCOUNT"] = "unifiedAccount";
6
6
  return HyperliquidAccountType2;
7
- })(HyperliquidAccountType || {});
7
+ })({});
8
8
  const COLLATERAL_TOKEN_MAP = {
9
9
  0: "USDC",
10
10
  235: "USDE",
@@ -16,6 +16,8 @@ export { LighterAccountType } from './lighter/types';
16
16
  export { OkxAccountType } from './okx/types';
17
17
  export * from './types';
18
18
 
19
+ var __defProp = Object.defineProperty;
20
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
19
21
  function createAccountTracker(exchange, config) {
20
22
  switch (exchange) {
21
23
  case "binance":
@@ -57,5 +59,6 @@ function createAccountTracker(exchange, config) {
57
59
  }
58
60
  }
59
61
  }
62
+ __name(createAccountTracker, "createAccountTracker");
60
63
 
61
64
  export { createAccountTracker };