@pear-protocol/exchanges-sdk 0.14.1 → 0.16.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 (36) hide show
  1. package/dist/client/hyperliquid/rest.js +14 -1
  2. package/dist/client/index.js +2 -0
  3. package/dist/client/lighter/constants.js +25 -5
  4. package/dist/client/lighter/exchange-ws.js +8 -7
  5. package/dist/client/lighter/rest.js +36 -36
  6. package/dist/client/lighter/ws.js +4 -3
  7. package/dist/helper/factory.js +3 -1
  8. package/dist/helper/lighter/asset-decimals.helper.js +1 -1
  9. package/dist/helper/lighter/auth-token.helper.js +10 -7
  10. package/dist/helper/lighter/cctp-deposit.helper.js +13 -13
  11. package/dist/helper/lighter/deposit-settlement.helper.js +4 -4
  12. package/dist/helper/lighter/funxyz-deposit.helper.js +3 -3
  13. package/dist/helper/lighter/helper.js +84 -59
  14. package/dist/helper/lighter/history.helper.js +6 -6
  15. package/dist/helper/lighter/misc-routes.helper.js +13 -0
  16. package/dist/helper/lighter/onboarding.helper.js +2 -2
  17. package/dist/helper/lighter/referral.helper.js +6 -6
  18. package/dist/helper/lighter/rhc-deposit.helper.js +91 -0
  19. package/dist/helper/lighter/types.js +12 -2
  20. package/dist/helper/subaccount.helper.js +10 -10
  21. package/dist/index.d.ts +223 -14
  22. package/dist/sdk.js +6 -0
  23. package/dist/status/factory.js +2 -1
  24. package/dist/status/lighter/status.js +5 -5
  25. package/dist/syncer/factory.js +5 -1
  26. package/dist/syncer/lighter/funding.js +2 -2
  27. package/dist/syncer/lighter/syncer.js +6 -6
  28. package/dist/tracker/hyperliquid/balance.js +37 -2
  29. package/dist/tracker/hyperliquid/borrow-lend.js +32 -0
  30. package/dist/tracker/hyperliquid/mapper.js +53 -1
  31. package/dist/tracker/hyperliquid/tracker.js +77 -2
  32. package/dist/tracker/index.js +4 -1
  33. package/dist/tracker/lighter/const.js +5 -2
  34. package/dist/tracker/lighter/mapper.js +12 -13
  35. package/dist/tracker/lighter/tracker.js +21 -15
  36. package/package.json +4 -4
@@ -86,6 +86,19 @@ async function fetchUserVaultEquities(user, demo = false) {
86
86
  }, demo);
87
87
  }
88
88
  __name(fetchUserVaultEquities, "fetchUserVaultEquities");
89
+ async function fetchBorrowLendUserState(user, demo = false) {
90
+ return fetchInfo({
91
+ type: "borrowLendUserState",
92
+ user
93
+ }, demo);
94
+ }
95
+ __name(fetchBorrowLendUserState, "fetchBorrowLendUserState");
96
+ async function fetchAllBorrowLendReserveStates(demo = false) {
97
+ return fetchInfo({
98
+ type: "allBorrowLendReserveStates"
99
+ }, demo);
100
+ }
101
+ __name(fetchAllBorrowLendReserveStates, "fetchAllBorrowLendReserveStates");
89
102
  async function fetchActiveAssetData(user, coin, demo = false) {
90
103
  return fetchInfo({
91
104
  type: "activeAssetData",
@@ -95,4 +108,4 @@ async function fetchActiveAssetData(user, coin, demo = false) {
95
108
  }
96
109
  __name(fetchActiveAssetData, "fetchActiveAssetData");
97
110
 
98
- export { HyperliquidInfoRequestError, fetchActiveAssetData, fetchAllMids, fetchClearinghouseState, fetchDelegatorSummary, fetchInfo, fetchPerpDexs, fetchSpotClearinghouseState, fetchUserAbstraction, fetchUserRole, fetchUserVaultEquities };
111
+ export { HyperliquidInfoRequestError, fetchActiveAssetData, fetchAllBorrowLendReserveStates, fetchAllMids, fetchBorrowLendUserState, fetchClearinghouseState, fetchDelegatorSummary, fetchInfo, fetchPerpDexs, fetchSpotClearinghouseState, fetchUserAbstraction, fetchUserRole, fetchUserVaultEquities };
@@ -40,7 +40,9 @@ async function createExchangeWs(exchange, config) {
40
40
  demo: config.demo
41
41
  });
42
42
  case "lighter":
43
+ case "lighter_rhc":
43
44
  return LighterExchangeWs.create({
45
+ connector: exchange,
44
46
  demo: config.demo
45
47
  });
46
48
  default: {
@@ -4,13 +4,33 @@ const LIGHTER_BASE_URL = "https://mainnet.zklighter.elliot.ai";
4
4
  const LIGHTER_BASE_URL_TESTNET = "https://testnet.zklighter.elliot.ai";
5
5
  const LIGHTER_WS_URL = "wss://mainnet.zklighter.elliot.ai/stream";
6
6
  const LIGHTER_WS_URL_TESTNET = "wss://testnet.zklighter.elliot.ai/stream";
7
- function getLighterBaseUrl(demo) {
8
- return demo ? LIGHTER_BASE_URL_TESTNET : LIGHTER_BASE_URL;
7
+ const LIGHTER_RHC_BASE_URL = "https://api.rh.lighter.xyz";
8
+ const LIGHTER_RHC_WS_URL = "wss://api.rh.lighter.xyz/stream";
9
+ function getLighterBaseUrl(connector, demo) {
10
+ switch (connector) {
11
+ case "lighter":
12
+ return demo ? LIGHTER_BASE_URL_TESTNET : LIGHTER_BASE_URL;
13
+ case "lighter_rhc":
14
+ assertRhcMainnet(demo);
15
+ return LIGHTER_RHC_BASE_URL;
16
+ }
9
17
  }
10
18
  __name(getLighterBaseUrl, "getLighterBaseUrl");
11
- function getLighterWsUrl(demo) {
12
- return demo ? LIGHTER_WS_URL_TESTNET : LIGHTER_WS_URL;
19
+ function getLighterWsUrl(connector, demo) {
20
+ switch (connector) {
21
+ case "lighter":
22
+ return demo ? LIGHTER_WS_URL_TESTNET : LIGHTER_WS_URL;
23
+ case "lighter_rhc":
24
+ assertRhcMainnet(demo);
25
+ return LIGHTER_RHC_WS_URL;
26
+ }
13
27
  }
14
28
  __name(getLighterWsUrl, "getLighterWsUrl");
29
+ function assertRhcMainnet(demo) {
30
+ if (demo) {
31
+ throw new Error("Lighter Robinhood Chain has no testnet deployment; demo mode is unavailable for lighter_rhc");
32
+ }
33
+ }
34
+ __name(assertRhcMainnet, "assertRhcMainnet");
15
35
 
16
- export { LIGHTER_BASE_URL, LIGHTER_BASE_URL_TESTNET, LIGHTER_WS_URL, LIGHTER_WS_URL_TESTNET, getLighterBaseUrl, getLighterWsUrl };
36
+ export { LIGHTER_BASE_URL, LIGHTER_BASE_URL_TESTNET, LIGHTER_RHC_BASE_URL, LIGHTER_RHC_WS_URL, LIGHTER_WS_URL, LIGHTER_WS_URL_TESTNET, getLighterBaseUrl, getLighterWsUrl };
@@ -8,21 +8,22 @@ class LighterExchangeWs extends ExchangeWs {
8
8
  __name(this, "LighterExchangeWs");
9
9
  }
10
10
  main;
11
- exchange = "lighter";
12
- constructor(main) {
11
+ exchange;
12
+ /** Binds the socket bundle to the deployment that opened it, so consumers can tell them apart. */
13
+ constructor(exchange, main) {
13
14
  super(), this.main = main;
15
+ this.exchange = exchange;
14
16
  }
15
17
  connections() {
16
18
  return [
17
19
  this.main
18
20
  ];
19
21
  }
20
- static async create(config = {
21
- demo: false
22
- }) {
23
- const main = new LighterWs(config.demo);
22
+ /** Opens the deployment's stream and returns the bundle only once it is connected. */
23
+ static async create(config) {
24
+ const main = new LighterWs(config.connector, config.demo);
24
25
  await main.connect();
25
- return new LighterExchangeWs(main);
26
+ return new LighterExchangeWs(config.connector, main);
26
27
  }
27
28
  }
28
29
 
@@ -20,8 +20,8 @@ const RETRYABLE_INTENT_STATUSES = /* @__PURE__ */ new Set([
20
20
  429,
21
21
  503
22
22
  ]);
23
- async function fetchDepositNetworks(demo = false) {
24
- const response = await proxyFetch(`${getLighterBaseUrl(demo)}/api/v1/deposit/networks`);
23
+ async function fetchDepositNetworks(connector, demo = false) {
24
+ const response = await proxyFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/deposit/networks`);
25
25
  const data = await readLighterResponse(response, "/deposit/networks");
26
26
  const networks = [];
27
27
  for (const network of data.networks ?? []) {
@@ -50,14 +50,14 @@ async function fetchDepositNetworks(demo = false) {
50
50
  return networks;
51
51
  }
52
52
  __name(fetchDepositNetworks, "fetchDepositNetworks");
53
- async function createCctpDepositIntentAddress(params, demo = false) {
53
+ async function createDepositIntentAddress(params, connector, demo = false) {
54
54
  const body = new URLSearchParams({
55
55
  chain_id: params.chainId.toString(),
56
56
  from_addr: params.fromAddress,
57
57
  amount: params.amount,
58
58
  is_external_deposit: params.external.toString()
59
59
  });
60
- const response = await fetchDepositIntentWithRetry(`${getLighterBaseUrl(demo)}/api/v1/createIntentAddress`, {
60
+ const response = await fetchDepositIntentWithRetry(`${getLighterBaseUrl(connector, demo)}/api/v1/createIntentAddress`, {
61
61
  method: "POST",
62
62
  headers: {
63
63
  "Content-Type": "application/x-www-form-urlencoded"
@@ -70,8 +70,8 @@ async function createCctpDepositIntentAddress(params, demo = false) {
70
70
  }
71
71
  return data.intent_address;
72
72
  }
73
- __name(createCctpDepositIntentAddress, "createCctpDepositIntentAddress");
74
- async function fetchDepositHistory(params, demo = false) {
73
+ __name(createDepositIntentAddress, "createDepositIntentAddress");
74
+ async function fetchDepositHistory(params, connector, demo = false) {
75
75
  const query = new URLSearchParams({
76
76
  account_index: params.accountIndex.toString(),
77
77
  l1_address: params.l1Address
@@ -79,7 +79,7 @@ async function fetchDepositHistory(params, demo = false) {
79
79
  if (params.cursor) {
80
80
  query.set("cursor", params.cursor);
81
81
  }
82
- const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/deposit/history?${query.toString()}`, params.authToken);
82
+ const response = await authenticatedLighterFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/deposit/history?${query.toString()}`, params.authToken);
83
83
  const data = await readLighterResponse(response, "/deposit/history");
84
84
  const deposits = [];
85
85
  for (const deposit of data.deposits ?? []) {
@@ -107,14 +107,14 @@ async function fetchDepositHistory(params, demo = false) {
107
107
  };
108
108
  }
109
109
  __name(fetchDepositHistory, "fetchDepositHistory");
110
- async function fetchWithdrawHistory(params, demo = false) {
110
+ async function fetchWithdrawHistory(params, connector, demo = false) {
111
111
  const query = new URLSearchParams({
112
112
  account_index: params.accountIndex.toString()
113
113
  });
114
114
  if (params.cursor) {
115
115
  query.set("cursor", params.cursor);
116
116
  }
117
- const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/withdraw/history?${query.toString()}`, params.authToken);
117
+ const response = await authenticatedLighterFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/withdraw/history?${query.toString()}`, params.authToken);
118
118
  const data = await readLighterResponse(response, "/withdraw/history");
119
119
  const withdraws = [];
120
120
  for (const withdraw of data.withdraws ?? []) {
@@ -143,14 +143,14 @@ async function fetchWithdrawHistory(params, demo = false) {
143
143
  };
144
144
  }
145
145
  __name(fetchWithdrawHistory, "fetchWithdrawHistory");
146
- async function fetchApiKeys(accountIndex, demo = false) {
147
- const url = `${getLighterBaseUrl(demo)}/api/v1/apikeys?account_index=${accountIndex}`;
146
+ async function fetchApiKeys(accountIndex, connector, demo = false) {
147
+ const url = `${getLighterBaseUrl(connector, demo)}/api/v1/apikeys?account_index=${accountIndex}`;
148
148
  const response = await proxyFetch(url);
149
149
  const data = await readLighterResponse(response, "/apikeys");
150
150
  return data.api_keys;
151
151
  }
152
152
  __name(fetchApiKeys, "fetchApiKeys");
153
- async function fetchAccountsByL1Address(l1Address, demo = false) {
153
+ async function fetchAccountsByL1Address(l1Address, connector, demo = false) {
154
154
  const subAccounts = /* @__PURE__ */ new Map();
155
155
  const seenCursors = /* @__PURE__ */ new Set();
156
156
  let cursor;
@@ -162,7 +162,7 @@ async function fetchAccountsByL1Address(l1Address, demo = false) {
162
162
  cursor
163
163
  } : {}
164
164
  });
165
- const response = await proxyFetch(`${getLighterBaseUrl(demo)}/api/v1/accountsByL1Address?${params.toString()}`);
165
+ const response = await proxyFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/accountsByL1Address?${params.toString()}`);
166
166
  const data = await readLighterResponse(response, "/accountsByL1Address", [
167
167
  200,
168
168
  21100
@@ -187,20 +187,20 @@ async function fetchAccountsByL1Address(l1Address, demo = false) {
187
187
  };
188
188
  }
189
189
  __name(fetchAccountsByL1Address, "fetchAccountsByL1Address");
190
- async function fetchAccount(accountIndex, authToken, demo = false, throttle) {
190
+ async function fetchAccount(accountIndex, authToken, connector, demo = false, throttle) {
191
191
  return gatedLighterRead(throttle, "account", async () => {
192
- const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/account?by=index&value=${accountIndex}`, authToken);
192
+ const response = await authenticatedLighterFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/account?by=index&value=${accountIndex}`, authToken);
193
193
  return readLighterResponse(response, "/account");
194
194
  }, () => 0);
195
195
  }
196
196
  __name(fetchAccount, "fetchAccount");
197
- async function fetchPublicAccount(accountIndex, demo = false) {
198
- const response = await proxyFetch(`${getLighterBaseUrl(demo)}/api/v1/account?by=index&value=${accountIndex}`);
197
+ async function fetchPublicAccount(accountIndex, connector, demo = false) {
198
+ const response = await proxyFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/account?by=index&value=${accountIndex}`);
199
199
  return readLighterResponse(response, "/account");
200
200
  }
201
201
  __name(fetchPublicAccount, "fetchPublicAccount");
202
- async function fetchAccountLimits(accountIndex, authToken, demo = false) {
203
- const response = await proxyFetch(`${getLighterBaseUrl(demo)}/api/v1/accountLimits?account_index=${accountIndex}`, {
202
+ async function fetchAccountLimits(accountIndex, authToken, connector, demo = false) {
203
+ const response = await proxyFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/accountLimits?account_index=${accountIndex}`, {
204
204
  headers: {
205
205
  authorization: authToken
206
206
  }
@@ -208,8 +208,8 @@ async function fetchAccountLimits(accountIndex, authToken, demo = false) {
208
208
  return readLighterResponse(response, "/accountLimits");
209
209
  }
210
210
  __name(fetchAccountLimits, "fetchAccountLimits");
211
- async function fetchAccountMetadata(accountIndex, authToken, demo = false) {
212
- const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/accountMetadata?by=index&value=${accountIndex}`, authToken, {
211
+ async function fetchAccountMetadata(accountIndex, authToken, connector, demo = false) {
212
+ const response = await authenticatedLighterFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/accountMetadata?by=index&value=${accountIndex}`, authToken, {
213
213
  headers: {
214
214
  accept: "application/json"
215
215
  }
@@ -221,8 +221,8 @@ async function fetchAccountMetadata(accountIndex, authToken, demo = false) {
221
221
  }
222
222
  }
223
223
  __name(fetchAccountMetadata, "fetchAccountMetadata");
224
- async function fetchOrderBookDetails(authToken, demo = false) {
225
- const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/orderBookDetails`, authToken);
224
+ async function fetchOrderBookDetails(authToken, connector, demo = false) {
225
+ const response = await authenticatedLighterFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/orderBookDetails`, authToken);
226
226
  const data = await readLighterResponse(response, "/orderBookDetails");
227
227
  return {
228
228
  perp: data.order_book_details ?? [],
@@ -230,8 +230,8 @@ async function fetchOrderBookDetails(authToken, demo = false) {
230
230
  };
231
231
  }
232
232
  __name(fetchOrderBookDetails, "fetchOrderBookDetails");
233
- async function fetchPublicOrderBookDetails(demo = false) {
234
- const response = await proxyFetch(`${getLighterBaseUrl(demo)}/api/v1/orderBookDetails`);
233
+ async function fetchPublicOrderBookDetails(connector, demo = false) {
234
+ const response = await proxyFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/orderBookDetails`);
235
235
  const data = await readLighterResponse(response, "/orderBookDetails");
236
236
  return {
237
237
  perp: data.order_book_details ?? [],
@@ -239,13 +239,13 @@ async function fetchPublicOrderBookDetails(demo = false) {
239
239
  };
240
240
  }
241
241
  __name(fetchPublicOrderBookDetails, "fetchPublicOrderBookDetails");
242
- async function fetchAssetDetails(demo) {
243
- const response = await proxyFetch(`${getLighterBaseUrl(demo)}/api/v1/assetDetails`);
242
+ async function fetchAssetDetails(connector, demo) {
243
+ const response = await proxyFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/assetDetails`);
244
244
  const data = await readLighterResponse(response, "/assetDetails");
245
245
  return data.asset_details;
246
246
  }
247
247
  __name(fetchAssetDetails, "fetchAssetDetails");
248
- async function fetchTradesSince(accountIndex, authToken, since, demo = false, throttle) {
248
+ async function fetchTradesSince(accountIndex, authToken, since, connector, demo = false, throttle) {
249
249
  const results = [];
250
250
  const seenCursors = /* @__PURE__ */ new Set();
251
251
  let cursor;
@@ -265,7 +265,7 @@ async function fetchTradesSince(accountIndex, authToken, since, demo = false, th
265
265
  } : {}
266
266
  });
267
267
  const data = await gatedLighterRead(throttle, "trades", async () => {
268
- const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/trades?${params.toString()}`, authToken);
268
+ const response = await authenticatedLighterFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/trades?${params.toString()}`, authToken);
269
269
  return readLighterResponse(response, "/trades");
270
270
  }, (page2) => (page2.trades ?? []).length);
271
271
  const page = data.trades ?? [];
@@ -284,7 +284,7 @@ async function fetchTradesSince(accountIndex, authToken, since, demo = false, th
284
284
  return Array.from(byId.values());
285
285
  }
286
286
  __name(fetchTradesSince, "fetchTradesSince");
287
- async function fetchPositionFundingSince(accountIndex, authToken, since, demo = false, throttle) {
287
+ async function fetchPositionFundingSince(accountIndex, authToken, since, connector, demo = false, throttle) {
288
288
  const results = /* @__PURE__ */ new Map();
289
289
  const seenCursors = /* @__PURE__ */ new Set();
290
290
  let cursor;
@@ -300,7 +300,7 @@ async function fetchPositionFundingSince(accountIndex, authToken, since, demo =
300
300
  } : {}
301
301
  });
302
302
  const data = await gatedLighterRead(throttle, "positionFunding", async () => {
303
- const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/positionFunding?${params.toString()}`, authToken);
303
+ const response = await authenticatedLighterFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/positionFunding?${params.toString()}`, authToken);
304
304
  return readLighterResponse(response, "/positionFunding");
305
305
  }, (page) => (page.position_fundings ?? []).length);
306
306
  for (const funding of data.position_fundings ?? []) {
@@ -317,7 +317,7 @@ async function fetchPositionFundingSince(accountIndex, authToken, since, demo =
317
317
  return Array.from(results.values());
318
318
  }
319
319
  __name(fetchPositionFundingSince, "fetchPositionFundingSince");
320
- async function submitReferralCode(params, demo = false) {
320
+ async function submitReferralCode(params, connector, demo = false) {
321
321
  const body = new URLSearchParams({
322
322
  l1_address: params.l1Address,
323
323
  referral_code: params.referralCode
@@ -334,7 +334,7 @@ async function submitReferralCode(params, demo = false) {
334
334
  if (params.signature) {
335
335
  body.set("signature", params.signature);
336
336
  }
337
- const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/referral/use`, params.authToken, {
337
+ const response = await authenticatedLighterFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/referral/use`, params.authToken, {
338
338
  method: "POST",
339
339
  headers: {
340
340
  "Content-Type": "application/x-www-form-urlencoded"
@@ -344,7 +344,7 @@ async function submitReferralCode(params, demo = false) {
344
344
  await readLighterResponse(response, "/referral/use");
345
345
  }
346
346
  __name(submitReferralCode, "submitReferralCode");
347
- async function fetchUserReferrals(params, demo = false) {
347
+ async function fetchUserReferrals(params, connector, demo = false) {
348
348
  const query = new URLSearchParams({
349
349
  l1_address: params.l1Address
350
350
  });
@@ -363,7 +363,7 @@ async function fetchUserReferrals(params, demo = false) {
363
363
  if (params.eligibleOnly) {
364
364
  query.set("is_eligible", "true");
365
365
  }
366
- const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/referral/userReferrals?${query.toString()}`, params.authToken);
366
+ const response = await authenticatedLighterFetch(`${getLighterBaseUrl(connector, demo)}/api/v1/referral/userReferrals?${query.toString()}`, params.authToken);
367
367
  const data = await readLighterResponse(response, "/referral/userReferrals");
368
368
  const referrals = [];
369
369
  for (const referral of data.referrals ?? []) {
@@ -525,4 +525,4 @@ function readReferralAmount(value) {
525
525
  }
526
526
  __name(readReferralAmount, "readReferralAmount");
527
527
 
528
- export { LighterRequestError, createCctpDepositIntentAddress, fetchAccount, fetchAccountLimits, fetchAccountMetadata, fetchAccountsByL1Address, fetchApiKeys, fetchAssetDetails, fetchDepositHistory, fetchDepositNetworks, fetchOrderBookDetails, fetchPositionFundingSince, fetchPublicAccount, fetchPublicOrderBookDetails, fetchTradesSince, fetchUserReferrals, fetchWithdrawHistory, submitReferralCode };
528
+ export { LighterRequestError, createDepositIntentAddress, fetchAccount, fetchAccountLimits, fetchAccountMetadata, fetchAccountsByL1Address, fetchApiKeys, fetchAssetDetails, fetchDepositHistory, fetchDepositNetworks, fetchOrderBookDetails, fetchPositionFundingSince, fetchPublicAccount, fetchPublicOrderBookDetails, fetchTradesSince, fetchUserReferrals, fetchWithdrawHistory, submitReferralCode };
@@ -8,12 +8,13 @@ class LighterWs extends BaseWs {
8
8
  static {
9
9
  __name(this, "LighterWs");
10
10
  }
11
+ connector;
11
12
  demo;
12
- constructor(demo = false) {
13
- super(), this.demo = demo;
13
+ constructor(connector, demo = false) {
14
+ super(), this.connector = connector, this.demo = demo;
14
15
  }
15
16
  getWsUrl() {
16
- return getLighterWsUrl(this.demo);
17
+ return getLighterWsUrl(this.connector, this.demo);
17
18
  }
18
19
  getPingIntervalMs() {
19
20
  return PING_INTERVAL_MS;
@@ -1,5 +1,5 @@
1
1
  import { createHyperliquidHelper } from './hyperliquid';
2
- import { createLighterHelper } from './lighter';
2
+ import { createLighterRhcHelper, createLighterHelper } from './lighter';
3
3
 
4
4
  var __defProp = Object.defineProperty;
5
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -9,6 +9,8 @@ function createExchangeHelper(config) {
9
9
  return createHyperliquidHelper(config.demo ?? false);
10
10
  case "lighter":
11
11
  return createLighterHelper(config.sdk, config.demo ?? false);
12
+ case "lighter_rhc":
13
+ return createLighterRhcHelper(config.sdk, config.demo ?? false);
12
14
  }
13
15
  }
14
16
  __name(createExchangeHelper, "createExchangeHelper");
@@ -6,7 +6,7 @@ async function resolveAssetDecimals(assetId, field, suppliedDecimals, demo) {
6
6
  if (suppliedDecimals !== void 0) {
7
7
  return validateDecimals(suppliedDecimals, field);
8
8
  }
9
- const assets = await fetchAssetDetails(demo);
9
+ const assets = await fetchAssetDetails("lighter", demo);
10
10
  const asset = assets.find((candidate) => candidate.asset_id === assetId);
11
11
  if (!asset) {
12
12
  throw new Error(`Lighter asset ${assetId} was not returned by assetDetails`);
@@ -1,17 +1,19 @@
1
+ import { selectLighterMiscRoutes } from './misc-routes.helper';
2
+
1
3
  var __defProp = Object.defineProperty;
2
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
5
  const ASSUMED_AUTH_TOKEN_TTL_SECONDS = 10 * 60;
4
6
  const AUTH_TOKEN_REFRESH_MARGIN_MS = 60 * 1e3;
5
7
  const cachedTokens = /* @__PURE__ */ new Map();
6
- async function retrieveLighterAuthToken(sdk, credentials, demo) {
7
- const cacheKey = buildCacheKey(credentials, demo);
8
+ async function retrieveLighterAuthToken(sdk, connector, credentials, demo) {
9
+ const cacheKey = buildCacheKey(connector, credentials, demo);
8
10
  evictLapsedTokens();
9
11
  const cached = cachedTokens.get(cacheKey);
10
12
  if (cached && cached.apiPrivateKey === credentials.apiPrivateKey) {
11
13
  return cached.token;
12
14
  }
13
15
  let entry;
14
- const token = signAuthToken(sdk, credentials).catch((error) => {
16
+ const token = signAuthToken(sdk, connector, credentials).catch((error) => {
15
17
  if (cachedTokens.get(cacheKey) === entry) {
16
18
  cachedTokens.delete(cacheKey);
17
19
  }
@@ -31,8 +33,9 @@ function _resetLighterAuthTokens() {
31
33
  cachedTokens.clear();
32
34
  }
33
35
  __name(_resetLighterAuthTokens, "_resetLighterAuthTokens");
34
- async function signAuthToken(sdk, credentials) {
35
- const { token } = await sdk.core.misc.lighter.createAuthToken({
36
+ async function signAuthToken(sdk, connector, credentials) {
37
+ const misc = selectLighterMiscRoutes(sdk, connector);
38
+ const { token } = await misc.createAuthToken({
36
39
  accountIndex: credentials.accountIndex,
37
40
  apiKeyIndex: credentials.apiKeyIndex,
38
41
  apiPrivateKey: credentials.apiPrivateKey
@@ -51,8 +54,8 @@ function alignExpiry(cacheKey, entry, token) {
51
54
  entry.expiresAt = Math.min(entry.expiresAt, deadlineSeconds * 1e3 - AUTH_TOKEN_REFRESH_MARGIN_MS);
52
55
  }
53
56
  __name(alignExpiry, "alignExpiry");
54
- function buildCacheKey(credentials, demo) {
55
- return `${demo ? "demo" : "live"}:${credentials.accountIndex}:${credentials.apiKeyIndex}`;
57
+ function buildCacheKey(connector, credentials, demo) {
58
+ return `${connector}:${demo ? "demo" : "live"}:${credentials.accountIndex}:${credentials.apiKeyIndex}`;
56
59
  }
57
60
  __name(buildCacheKey, "buildCacheKey");
58
61
  function evictLapsedTokens() {
@@ -1,6 +1,6 @@
1
1
  import { isAddress } from 'viem';
2
- import { fetchDepositNetworks, createCctpDepositIntentAddress, fetchAccountsByL1Address, fetchDepositHistory } from '../../client/lighter/rest';
3
- import { parseUsdcAmount } from '../subaccount.helper';
2
+ import { fetchDepositNetworks, createDepositIntentAddress, fetchAccountsByL1Address, fetchDepositHistory } from '../../client/lighter/rest';
3
+ import { parseCollateralAmount } from '../subaccount.helper';
4
4
  import { retrieveLighterAuthToken } from './auth-token.helper';
5
5
  import { assertOwnerWallet, readUsdcAmountSyntaxError, readDepositMinimumError, formatUsdcUnits, emitProgress, watchAccountRegistration, waitForDepositPoll, SETTLEMENT_WATCH_LIMIT_MS } from './deposit-settlement.helper';
6
6
  import { getLighterNativeUsdcAddress, writeUsdcTransfer } from './ethereum/usdc.helper';
@@ -11,17 +11,17 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
11
11
  const EXTERNAL_INTENT_LIFETIME_MS = 9 * 60 * 1e3;
12
12
  async function listCctpDepositNetworks(demo) {
13
13
  assertCctpEnvironment(demo);
14
- return fetchDepositNetworks(demo);
14
+ return fetchDepositNetworks("lighter", demo);
15
15
  }
16
16
  __name(listCctpDepositNetworks, "listCctpDepositNetworks");
17
17
  async function createCctpDepositAddress(params, demo) {
18
18
  await validateIntentRoute(params, demo);
19
- const intentAddress = await createCctpDepositIntentAddress({
19
+ const intentAddress = await createDepositIntentAddress({
20
20
  chainId: params.chainId,
21
21
  fromAddress: params.ownerAddress,
22
22
  amount: "0",
23
23
  external: true
24
- }, demo);
24
+ }, "lighter", demo);
25
25
  return {
26
26
  route: "cctp",
27
27
  intentAddress,
@@ -40,7 +40,7 @@ async function depositUsdcViaCctp(sdk, params, demo) {
40
40
  if (syntaxError) {
41
41
  throw new Error(syntaxError);
42
42
  }
43
- const units = parseUsdcAmount(params.amount);
43
+ const units = parseCollateralAmount(params.amount, "USDC");
44
44
  const minimumError = readDepositMinimumError(units, MIN_LIGHTER_CCTP_DEPOSIT_USDC);
45
45
  if (minimumError) {
46
46
  throw new Error(minimumError);
@@ -60,12 +60,12 @@ async function depositUsdcViaCctp(sdk, params, demo) {
60
60
  if (wallet.chain?.id !== params.chainId) {
61
61
  throw new Error(`Switch the wallet to chain ${params.chainId} before depositing.`);
62
62
  }
63
- const intentAddress = await createCctpDepositIntentAddress({
63
+ const intentAddress = await createDepositIntentAddress({
64
64
  chainId: params.chainId,
65
65
  fromAddress: params.ownerAddress,
66
66
  amount: units.toString(),
67
67
  external: false
68
- }, demo);
68
+ }, "lighter", demo);
69
69
  const txHash = await writeUsdcTransfer(wallet, {
70
70
  usdcAddress,
71
71
  to: intentAddress,
@@ -93,7 +93,7 @@ async function validateIntentRoute(params, demo) {
93
93
  if (!isAddress(params.ownerAddress)) {
94
94
  throw new Error(`Invalid Lighter CCTP owner address: ${params.ownerAddress}`);
95
95
  }
96
- const networks = await fetchDepositNetworks(demo);
96
+ const networks = await fetchDepositNetworks("lighter", demo);
97
97
  if (!networks.some((network) => network.chainId === params.chainId)) {
98
98
  const supported = networks.map((network) => `${network.name} (${network.chainId})`).join(", ");
99
99
  throw new Error(`Unsupported Lighter CCTP chain ID: ${params.chainId}. Lighter accepts ${supported}.`);
@@ -129,14 +129,14 @@ async function followDepositSettlement(params, txHash, sdk, demo) {
129
129
  return;
130
130
  }
131
131
  case "account-registration": {
132
- await watchAccountRegistration(params.ownerAddress, txHash, params.onProgress, params.signal, demo, params.settlementTimeoutMs);
132
+ await watchAccountRegistration(params.ownerAddress, "lighter", txHash, params.onProgress, params.signal, demo, params.settlementTimeoutMs);
133
133
  return;
134
134
  }
135
135
  }
136
136
  }
137
137
  __name(followDepositSettlement, "followDepositSettlement");
138
138
  async function resolveDepositWatch(ownerAddress, settlement, signal, demo) {
139
- const data = await fetchAccountsByL1Address(ownerAddress, demo);
139
+ const data = await fetchAccountsByL1Address(ownerAddress, "lighter", demo);
140
140
  const main = data.sub_accounts?.find((account) => account.account_type === 0);
141
141
  if (!main || main.index !== settlement.selectedAccountIndex) {
142
142
  return void 0;
@@ -166,12 +166,12 @@ async function watchCctpDeposit(ownerAddress, txHash, watch, onProgress, sdk, de
166
166
  }
167
167
  let deposits;
168
168
  try {
169
- const authToken = await retrieveLighterAuthToken(sdk, watch, demo);
169
+ const authToken = await retrieveLighterAuthToken(sdk, "lighter", watch, demo);
170
170
  const page = await fetchDepositHistory({
171
171
  accountIndex: watch.accountIndex,
172
172
  l1Address: ownerAddress,
173
173
  authToken
174
- }, demo);
174
+ }, "lighter", demo);
175
175
  deposits = page.deposits;
176
176
  } catch {
177
177
  continue;
@@ -1,4 +1,4 @@
1
- import { parseUsdcAmount } from '../subaccount.helper';
1
+ import { parseCollateralAmount } from '../subaccount.helper';
2
2
  import { readOnboardingStatus } from './onboarding.helper';
3
3
 
4
4
  var __defProp = Object.defineProperty;
@@ -14,7 +14,7 @@ function readUsdcAmountSyntaxError(amount) {
14
14
  }
15
15
  __name(readUsdcAmountSyntaxError, "readUsdcAmountSyntaxError");
16
16
  function readDepositMinimumError(units, minimumUsd) {
17
- if (units < parseUsdcAmount(minimumUsd)) {
17
+ if (units < parseCollateralAmount(minimumUsd, "USDC")) {
18
18
  return `Minimum deposit: $${minimumUsd} USDC.`;
19
19
  }
20
20
  return void 0;
@@ -26,7 +26,7 @@ function assertOwnerWallet(ownerAddress, connectedAddress) {
26
26
  }
27
27
  }
28
28
  __name(assertOwnerWallet, "assertOwnerWallet");
29
- async function watchAccountRegistration(ownerAddress, txHash, onProgress, signal, demo, timeoutMs) {
29
+ async function watchAccountRegistration(ownerAddress, connector, txHash, onProgress, signal, demo, timeoutMs) {
30
30
  const deadline = Date.now() + (timeoutMs ?? SETTLEMENT_WATCH_LIMIT_MS);
31
31
  while (!signal?.aborted) {
32
32
  await waitForDepositPoll(signal);
@@ -42,7 +42,7 @@ async function watchAccountRegistration(ownerAddress, txHash, onProgress, signal
42
42
  }
43
43
  let status;
44
44
  try {
45
- status = await readOnboardingStatus(ownerAddress, demo);
45
+ status = await readOnboardingStatus(ownerAddress, connector, demo);
46
46
  } catch {
47
47
  continue;
48
48
  }
@@ -1,5 +1,5 @@
1
1
  import { isAddress } from 'viem';
2
- import { parseUsdcAmount } from '../subaccount.helper';
2
+ import { parseCollateralAmount } from '../subaccount.helper';
3
3
  import { assertOwnerWallet, readUsdcAmountSyntaxError, formatUsdcUnits, readDepositMinimumError, emitProgress, watchAccountRegistration, waitForDepositPoll, SETTLEMENT_WATCH_LIMIT_MS } from './deposit-settlement.helper';
4
4
  import { getLighterNativeUsdcAddress, writeUsdcTransfer } from './ethereum/usdc.helper';
5
5
  import { FUNXYZ_DEPOSIT_MINIMUMS_USD, FUNXYZ_EVM_CHAIN_NAMES, FUNXYZ_ETHEREUM_MAINNET_CHAIN_ID } from './types';
@@ -42,7 +42,7 @@ async function depositUsdcViaFunxyz(sdk, params, demo) {
42
42
  if (syntaxError) {
43
43
  throw new Error(syntaxError);
44
44
  }
45
- const units = parseUsdcAmount(params.amount);
45
+ const units = parseCollateralAmount(params.amount, "USDC");
46
46
  const balance = await params.wallet.readUsdcBalance(params.chainId, params.ownerAddress);
47
47
  if (units > balance) {
48
48
  throw new Error(`Your wallet holds ${formatUsdcUnits(balance)} USDC.`);
@@ -188,7 +188,7 @@ async function followFunxyzSettlement(sdk, params, credits, bridgeUserId, transf
188
188
  return;
189
189
  }
190
190
  case "new": {
191
- await watchAccountRegistration(params.ownerAddress, transfer.txHash, params.onProgress, params.signal, demo);
191
+ await watchAccountRegistration(params.ownerAddress, "lighter", transfer.txHash, params.onProgress, params.signal, demo);
192
192
  return;
193
193
  }
194
194
  }