@pear-protocol/exchanges-sdk 0.6.4 → 0.6.6

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 +112 -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 +200 -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 +79 -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 +4 -4
  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 -148
  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
@@ -1,6 +1,11 @@
1
1
  import { WebSocket } from 'partysocket';
2
2
 
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
5
  class BaseWs {
6
+ static {
7
+ __name(this, "BaseWs");
8
+ }
4
9
  ws = null;
5
10
  pingTimer = null;
6
11
  messageListeners = /* @__PURE__ */ new Map();
@@ -46,16 +51,20 @@ class BaseWs {
46
51
  resolve();
47
52
  return;
48
53
  }
49
- const onOpen = () => {
54
+ const onOpen = /* @__PURE__ */ __name(() => {
50
55
  ws.removeEventListener("error", onError);
51
56
  resolve();
52
- };
53
- const onError = () => {
57
+ }, "onOpen");
58
+ const onError = /* @__PURE__ */ __name(() => {
54
59
  ws.removeEventListener("open", onOpen);
55
60
  reject(new Error("WebSocket connection failed"));
56
- };
57
- ws.addEventListener("open", onOpen, { once: true });
58
- ws.addEventListener("error", onError, { once: true });
61
+ }, "onError");
62
+ ws.addEventListener("open", onOpen, {
63
+ once: true
64
+ });
65
+ ws.addEventListener("error", onError, {
66
+ once: true
67
+ });
59
68
  });
60
69
  }
61
70
  disconnect() {
@@ -2,23 +2,37 @@ import { ExchangeWs } from '../exchange-ws';
2
2
  import { createListenKey } from './rest';
3
3
  import { BinanceUserDataWs, BinanceWsApi } from './ws';
4
4
 
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
7
  class BinanceExchangeWs extends ExchangeWs {
6
- constructor(userData, wsApi) {
7
- super();
8
- this.userData = userData;
9
- this.wsApi = wsApi;
8
+ static {
9
+ __name(this, "BinanceExchangeWs");
10
10
  }
11
11
  userData;
12
12
  wsApi;
13
13
  exchange = "binance";
14
+ constructor(userData, wsApi) {
15
+ super(), this.userData = userData, this.wsApi = wsApi;
16
+ }
14
17
  connections() {
15
- return [this.userData, this.wsApi];
18
+ return [
19
+ this.userData,
20
+ this.wsApi
21
+ ];
16
22
  }
17
23
  static async create(config) {
18
24
  const listenKey = await createListenKey(config.credentials.read.api_key, config.demo);
19
- const userData = new BinanceUserDataWs({ listenKey, demo: config.demo });
20
- const wsApi = new BinanceWsApi({ demo: config.demo });
21
- await Promise.all([userData.connect(), wsApi.connect()]);
25
+ const userData = new BinanceUserDataWs({
26
+ listenKey,
27
+ demo: config.demo
28
+ });
29
+ const wsApi = new BinanceWsApi({
30
+ demo: config.demo
31
+ });
32
+ await Promise.all([
33
+ userData.connect(),
34
+ wsApi.connect()
35
+ ]);
22
36
  return new BinanceExchangeWs(userData, wsApi);
23
37
  }
24
38
  }
@@ -1,16 +1,24 @@
1
1
  import { proxyFetch } from '@pear-protocol/utils';
2
2
  import { hmacSha256Hex } from '../hmac';
3
3
 
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
6
  const BASE_URL = "https://fapi.binance.com";
5
7
  const BASE_URL_TESTNET = "https://testnet.binancefuture.com";
6
8
  async function signedGet(creds, path, params, demo) {
7
9
  const baseUrl = demo ? BASE_URL_TESTNET : BASE_URL;
8
10
  const timestamp = Date.now().toString();
9
- const allParams = { ...params, timestamp, recvWindow: "5000" };
11
+ const allParams = {
12
+ ...params,
13
+ timestamp,
14
+ recvWindow: "5000"
15
+ };
10
16
  const queryString = new URLSearchParams(allParams).toString();
11
17
  const signature = await hmacSha256Hex(creds.read.api_secret, queryString);
12
18
  const response = await proxyFetch(`${baseUrl}${path}?${queryString}&signature=${signature}`, {
13
- headers: { "X-MBX-APIKEY": creds.read.api_key }
19
+ headers: {
20
+ "X-MBX-APIKEY": creds.read.api_key
21
+ }
14
22
  });
15
23
  if (!response.ok) {
16
24
  const body = await response.json().catch(() => null);
@@ -19,11 +27,14 @@ async function signedGet(creds, path, params, demo) {
19
27
  }
20
28
  return await response.json();
21
29
  }
30
+ __name(signedGet, "signedGet");
22
31
  async function createListenKey(apiKey, demo = false) {
23
32
  const baseUrl = demo ? BASE_URL_TESTNET : BASE_URL;
24
33
  const response = await proxyFetch(`${baseUrl}/fapi/v1/listenKey`, {
25
34
  method: "POST",
26
- headers: { "X-MBX-APIKEY": apiKey }
35
+ headers: {
36
+ "X-MBX-APIKEY": apiKey
37
+ }
27
38
  });
28
39
  if (!response.ok) {
29
40
  throw new Error(`Failed to create listenKey: ${response.status} ${response.statusText}`);
@@ -31,30 +42,40 @@ async function createListenKey(apiKey, demo = false) {
31
42
  const data = await response.json();
32
43
  return data.listenKey;
33
44
  }
45
+ __name(createListenKey, "createListenKey");
34
46
  async function keepAliveListenKey(apiKey, demo = false) {
35
47
  const baseUrl = demo ? BASE_URL_TESTNET : BASE_URL;
36
48
  const response = await proxyFetch(`${baseUrl}/fapi/v1/listenKey`, {
37
49
  method: "PUT",
38
- headers: { "X-MBX-APIKEY": apiKey }
50
+ headers: {
51
+ "X-MBX-APIKEY": apiKey
52
+ }
39
53
  });
40
54
  if (!response.ok) {
41
55
  throw new Error(`Failed to keep-alive listenKey: ${response.status} ${response.statusText}`);
42
56
  }
43
57
  }
58
+ __name(keepAliveListenKey, "keepAliveListenKey");
44
59
  async function fetchAccountStatus(creds, demo) {
45
60
  return signedGet(creds, "/fapi/v3/account", {}, demo);
46
61
  }
62
+ __name(fetchAccountStatus, "fetchAccountStatus");
47
63
  async function fetchPositionRisk(creds, symbol, demo) {
48
- const data = await signedGet(creds, "/fapi/v2/positionRisk", { symbol }, demo);
64
+ const data = await signedGet(creds, "/fapi/v2/positionRisk", {
65
+ symbol
66
+ }, demo);
49
67
  return data[0];
50
68
  }
69
+ __name(fetchPositionRisk, "fetchPositionRisk");
51
70
  async function fetchAllPositionRisk(creds, demo) {
52
71
  return signedGet(creds, "/fapi/v2/positionRisk", {}, demo);
53
72
  }
73
+ __name(fetchAllPositionRisk, "fetchAllPositionRisk");
54
74
  async function fetchMultiAssetsMargin(creds, demo) {
55
75
  const res = await signedGet(creds, "/fapi/v1/multiAssetsMargin", {}, demo);
56
76
  return res.multiAssetsMargin;
57
77
  }
78
+ __name(fetchMultiAssetsMargin, "fetchMultiAssetsMargin");
58
79
  const USER_TRADES_LIMIT = 1e3;
59
80
  const ALL_ORDERS_LIMIT = 1e3;
60
81
  const BINANCE_MAX_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
@@ -67,17 +88,12 @@ async function fetchUserTradesSince(creds, symbols, since, demo) {
67
88
  const windowEnd = Math.min(windowStart + BINANCE_MAX_WINDOW_MS - 1, now);
68
89
  let pageStart = windowStart;
69
90
  while (pageStart <= windowEnd) {
70
- const page = await signedGet(
71
- creds,
72
- "/fapi/v1/userTrades",
73
- {
74
- symbol,
75
- startTime: pageStart.toString(),
76
- endTime: windowEnd.toString(),
77
- limit: USER_TRADES_LIMIT.toString()
78
- },
79
- demo
80
- );
91
+ const page = await signedGet(creds, "/fapi/v1/userTrades", {
92
+ symbol,
93
+ startTime: pageStart.toString(),
94
+ endTime: windowEnd.toString(),
95
+ limit: USER_TRADES_LIMIT.toString()
96
+ }, demo);
81
97
  results.push(...page);
82
98
  if (page.length < USER_TRADES_LIMIT) break;
83
99
  const last = page[page.length - 1];
@@ -93,6 +109,7 @@ async function fetchUserTradesSince(creds, symbols, since, demo) {
93
109
  }
94
110
  return Array.from(byId.values());
95
111
  }
112
+ __name(fetchUserTradesSince, "fetchUserTradesSince");
96
113
  async function fetchAllOrdersSince(creds, symbols, since, demo) {
97
114
  const now = Date.now();
98
115
  const results = [];
@@ -102,17 +119,12 @@ async function fetchAllOrdersSince(creds, symbols, since, demo) {
102
119
  const windowEnd = Math.min(windowStart + BINANCE_MAX_WINDOW_MS - 1, now);
103
120
  let pageStart = windowStart;
104
121
  while (pageStart <= windowEnd) {
105
- const page = await signedGet(
106
- creds,
107
- "/fapi/v1/allOrders",
108
- {
109
- symbol,
110
- startTime: pageStart.toString(),
111
- endTime: windowEnd.toString(),
112
- limit: ALL_ORDERS_LIMIT.toString()
113
- },
114
- demo
115
- );
122
+ const page = await signedGet(creds, "/fapi/v1/allOrders", {
123
+ symbol,
124
+ startTime: pageStart.toString(),
125
+ endTime: windowEnd.toString(),
126
+ limit: ALL_ORDERS_LIMIT.toString()
127
+ }, demo);
116
128
  results.push(...page);
117
129
  if (page.length < ALL_ORDERS_LIMIT) break;
118
130
  const last = page[page.length - 1];
@@ -129,5 +141,6 @@ async function fetchAllOrdersSince(creds, symbols, since, demo) {
129
141
  }
130
142
  return Array.from(byId.values());
131
143
  }
144
+ __name(fetchAllOrdersSince, "fetchAllOrdersSince");
132
145
 
133
146
  export { createListenKey, fetchAccountStatus, fetchAllOrdersSince, fetchAllPositionRisk, fetchMultiAssetsMargin, fetchPositionRisk, fetchUserTradesSince, keepAliveListenKey };
@@ -1,11 +1,16 @@
1
1
  import { BaseWs } from '../base-ws';
2
2
  import { hmacSha256Hex } from '../hmac';
3
3
 
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
6
  const USER_DATA_URL = "wss://fstream.binance.com/ws";
5
7
  const USER_DATA_URL_TESTNET = "wss://stream.binancefuture.com/ws";
6
8
  const WS_API_URL = "wss://ws-fapi.binance.com/ws-fapi/v1";
7
9
  const WS_API_URL_TESTNET = "wss://testnet.binancefuture.com/ws-fapi/v1";
8
10
  class BinanceUserDataWs extends BaseWs {
11
+ static {
12
+ __name(this, "BinanceUserDataWs");
13
+ }
9
14
  listenKey;
10
15
  demo;
11
16
  constructor(config) {
@@ -25,6 +30,9 @@ class BinanceUserDataWs extends BaseWs {
25
30
  }
26
31
  }
27
32
  class BinanceWsApi extends BaseWs {
33
+ static {
34
+ __name(this, "BinanceWsApi");
35
+ }
28
36
  demo;
29
37
  requestId = 1;
30
38
  constructor(config) {
@@ -43,10 +51,21 @@ class BinanceWsApi extends BaseWs {
43
51
  async sendSignedRequest(creds, method, params = {}) {
44
52
  const id = this.requestId++;
45
53
  const timestamp = Date.now();
46
- const allParams = { ...params, apiKey: creds.read.api_key, timestamp };
54
+ const allParams = {
55
+ ...params,
56
+ apiKey: creds.read.api_key,
57
+ timestamp
58
+ };
47
59
  const queryString = Object.keys(allParams).sort().map((k) => `${k}=${allParams[k]}`).join("&");
48
60
  const signature = await hmacSha256Hex(creds.read.api_secret, queryString);
49
- this.send({ id, method, params: { ...allParams, signature } });
61
+ this.send({
62
+ id,
63
+ method,
64
+ params: {
65
+ ...allParams,
66
+ signature
67
+ }
68
+ });
50
69
  return id;
51
70
  }
52
71
  }
@@ -1,23 +1,30 @@
1
1
  import { ExchangeWs } from '../exchange-ws';
2
2
  import { BybitWs } from './ws';
3
3
 
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
6
  class BybitExchangeWs extends ExchangeWs {
5
- constructor(main, creds) {
6
- super();
7
- this.main = main;
8
- this.creds = creds;
7
+ static {
8
+ __name(this, "BybitExchangeWs");
9
9
  }
10
10
  main;
11
11
  creds;
12
12
  exchange = "bybit";
13
+ constructor(main, creds) {
14
+ super(), this.main = main, this.creds = creds;
15
+ }
13
16
  connections() {
14
- return [this.main];
17
+ return [
18
+ this.main
19
+ ];
15
20
  }
16
21
  authenticate() {
17
22
  return this.main.authenticate(this.creds);
18
23
  }
19
24
  static async create(config) {
20
- const main = new BybitWs({ demo: config.demo });
25
+ const main = new BybitWs({
26
+ demo: config.demo
27
+ });
21
28
  await main.connect();
22
29
  const wrapper = new BybitExchangeWs(main, config.credentials);
23
30
  await wrapper.authenticate();
@@ -1,6 +1,8 @@
1
1
  import { proxyFetch } from '@pear-protocol/utils';
2
2
  import { hmacSha256Hex } from '../hmac';
3
3
 
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
6
  const BASE_URL = "https://api.bybit.com";
5
7
  const BASE_URL_DEMO = "https://api-demo.bybit.com";
6
8
  async function signedGet(creds, path, params, demo) {
@@ -27,43 +29,36 @@ async function signedGet(creds, path, params, demo) {
27
29
  }
28
30
  return body.result;
29
31
  }
32
+ __name(signedGet, "signedGet");
30
33
  async function fetchWalletBalance(creds, demo) {
31
- const result = await signedGet(
32
- creds,
33
- "/v5/account/wallet-balance",
34
- { accountType: "UNIFIED" },
35
- demo
36
- );
34
+ const result = await signedGet(creds, "/v5/account/wallet-balance", {
35
+ accountType: "UNIFIED"
36
+ }, demo);
37
37
  return result.list[0];
38
38
  }
39
+ __name(fetchWalletBalance, "fetchWalletBalance");
39
40
  async function fetchPositions(creds, settleCoin, demo) {
40
- const result = await signedGet(
41
- creds,
42
- "/v5/position/list",
43
- { category: "linear", settleCoin },
44
- demo
45
- );
41
+ const result = await signedGet(creds, "/v5/position/list", {
42
+ category: "linear",
43
+ settleCoin
44
+ }, demo);
46
45
  return result.list;
47
46
  }
47
+ __name(fetchPositions, "fetchPositions");
48
48
  async function fetchPositionLeverage(creds, symbol, demo) {
49
- const result = await signedGet(
50
- creds,
51
- "/v5/position/list",
52
- { category: "linear", symbol },
53
- demo
54
- );
49
+ const result = await signedGet(creds, "/v5/position/list", {
50
+ category: "linear",
51
+ symbol
52
+ }, demo);
55
53
  return result.list[0];
56
54
  }
55
+ __name(fetchPositionLeverage, "fetchPositionLeverage");
57
56
  async function fetchAccountInfo(creds, demo) {
58
57
  return signedGet(creds, "/v5/account/info", {}, demo);
59
58
  }
59
+ __name(fetchAccountInfo, "fetchAccountInfo");
60
60
  async function fetchCollateralRatios(creds, demo) {
61
- const result = await signedGet(
62
- creds,
63
- "/v5/spot-margin-uta/tier-collateral-ratio",
64
- {},
65
- demo
66
- );
61
+ const result = await signedGet(creds, "/v5/spot-margin-uta/tier-collateral-ratio", {}, demo);
67
62
  const ratios = /* @__PURE__ */ new Map();
68
63
  for (const entry of result ?? []) {
69
64
  const first = entry.tiers?.[0];
@@ -73,6 +68,7 @@ async function fetchCollateralRatios(creds, demo) {
73
68
  }
74
69
  return ratios;
75
70
  }
71
+ __name(fetchCollateralRatios, "fetchCollateralRatios");
76
72
  const EXECUTIONS_LIMIT = 100;
77
73
  const BYBIT_MAX_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
78
74
  async function fetchExecutionsSince(creds, since, demo) {
@@ -83,18 +79,15 @@ async function fetchExecutionsSince(creds, since, demo) {
83
79
  const windowEnd = Math.min(windowStart + BYBIT_MAX_WINDOW_MS - 1, now);
84
80
  let cursor;
85
81
  do {
86
- const result = await signedGet(
87
- creds,
88
- "/v5/execution/list",
89
- {
90
- category: "linear",
91
- startTime: windowStart.toString(),
92
- endTime: windowEnd.toString(),
93
- limit: EXECUTIONS_LIMIT.toString(),
94
- ...cursor ? { cursor } : {}
95
- },
96
- demo
97
- );
82
+ const result = await signedGet(creds, "/v5/execution/list", {
83
+ category: "linear",
84
+ startTime: windowStart.toString(),
85
+ endTime: windowEnd.toString(),
86
+ limit: EXECUTIONS_LIMIT.toString(),
87
+ ...cursor ? {
88
+ cursor
89
+ } : {}
90
+ }, demo);
98
91
  results.push(...result.list ?? []);
99
92
  cursor = result.nextPageCursor || void 0;
100
93
  } while (cursor);
@@ -106,5 +99,6 @@ async function fetchExecutionsSince(creds, since, demo) {
106
99
  }
107
100
  return Array.from(byId.values());
108
101
  }
102
+ __name(fetchExecutionsSince, "fetchExecutionsSince");
109
103
 
110
104
  export { fetchAccountInfo, fetchCollateralRatios, fetchExecutionsSince, fetchPositionLeverage, fetchPositions, fetchWalletBalance };
@@ -1,11 +1,16 @@
1
1
  import { BaseWs } from '../base-ws';
2
2
  import { hmacSha256Hex } from '../hmac';
3
3
 
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
6
  const WS_URL = "wss://stream.bybit.com/v5/private";
5
7
  const WS_URL_DEMO = "wss://stream-demo.bybit.com/v5/private";
6
8
  const PING_INTERVAL_MS = 2e4;
7
9
  const AUTH_TIMEOUT_MS = 1e4;
8
10
  class BybitWs extends BaseWs {
11
+ static {
12
+ __name(this, "BybitWs");
13
+ }
9
14
  demo;
10
15
  constructor(config) {
11
16
  super();
@@ -18,7 +23,9 @@ class BybitWs extends BaseWs {
18
23
  return PING_INTERVAL_MS;
19
24
  }
20
25
  buildPingMessage() {
21
- return { op: "ping" };
26
+ return {
27
+ op: "ping"
28
+ };
22
29
  }
23
30
  async authenticate(creds) {
24
31
  const expires = Date.now() + AUTH_TIMEOUT_MS;
@@ -42,7 +49,14 @@ class BybitWs extends BaseWs {
42
49
  if (msg.success) resolve();
43
50
  else reject(new Error(`Bybit auth failed: ${msg.ret_msg}`));
44
51
  });
45
- this.send({ op: "auth", args: [creds.api_key, expires, signature] });
52
+ this.send({
53
+ op: "auth",
54
+ args: [
55
+ creds.api_key,
56
+ expires,
57
+ signature
58
+ ]
59
+ });
46
60
  });
47
61
  }
48
62
  }
@@ -1,4 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
3
  class ExchangeWs {
4
+ static {
5
+ __name(this, "ExchangeWs");
6
+ }
2
7
  destroy() {
3
8
  for (const c of this.connections()) c.destroy();
4
9
  }
@@ -1,14 +1,21 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
3
  const encoder = new TextEncoder();
2
4
  async function sign(secret, message) {
3
- const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, [
5
+ const key = await crypto.subtle.importKey("raw", encoder.encode(secret), {
6
+ name: "HMAC",
7
+ hash: "SHA-256"
8
+ }, false, [
4
9
  "sign"
5
10
  ]);
6
11
  return crypto.subtle.sign("HMAC", key, encoder.encode(message));
7
12
  }
13
+ __name(sign, "sign");
8
14
  async function hmacSha256Hex(secret, message) {
9
15
  const signature = await sign(secret, message);
10
16
  return Array.from(new Uint8Array(signature)).map((b) => b.toString(16).padStart(2, "0")).join("");
11
17
  }
18
+ __name(hmacSha256Hex, "hmacSha256Hex");
12
19
  async function hmacSha256Base64(secret, message) {
13
20
  const signature = await sign(secret, message);
14
21
  const bytes = new Uint8Array(signature);
@@ -16,5 +23,6 @@ async function hmacSha256Base64(secret, message) {
16
23
  for (const b of bytes) binary += String.fromCharCode(b);
17
24
  return btoa(binary);
18
25
  }
26
+ __name(hmacSha256Base64, "hmacSha256Base64");
19
27
 
20
28
  export { hmacSha256Base64, hmacSha256Hex };
@@ -1,18 +1,26 @@
1
1
  import { ExchangeWs } from '../exchange-ws';
2
2
  import { HyperliquidWs } from './ws';
3
3
 
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
6
  class HyperliquidExchangeWs extends ExchangeWs {
5
- constructor(main) {
6
- super();
7
- this.main = main;
7
+ static {
8
+ __name(this, "HyperliquidExchangeWs");
8
9
  }
9
10
  main;
10
11
  exchange = "hyperliquid";
12
+ constructor(main) {
13
+ super(), this.main = main;
14
+ }
11
15
  connections() {
12
- return [this.main];
16
+ return [
17
+ this.main
18
+ ];
13
19
  }
14
20
  /** Opens the Hyperliquid socket on the requested network. */
15
- static async create(config = { demo: false }) {
21
+ static async create(config = {
22
+ demo: false
23
+ }) {
16
24
  const main = new HyperliquidWs(config.demo);
17
25
  await main.connect();
18
26
  return new HyperliquidExchangeWs(main);
@@ -1,5 +1,7 @@
1
1
  import { proxyFetch } from '@pear-protocol/utils';
2
2
 
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
5
  const HL_INFO_URLS = {
4
6
  mainnet: "https://api.hyperliquid.xyz/info",
5
7
  testnet: "https://api.hyperliquid-testnet.xyz/info"
@@ -8,7 +10,9 @@ async function fetchInfo(body, demo = false) {
8
10
  const url = demo ? HL_INFO_URLS.testnet : HL_INFO_URLS.mainnet;
9
11
  const res = await proxyFetch(url, {
10
12
  method: "POST",
11
- headers: { "Content-Type": "application/json" },
13
+ headers: {
14
+ "Content-Type": "application/json"
15
+ },
12
16
  body: JSON.stringify(body)
13
17
  });
14
18
  if (!res.ok) {
@@ -16,23 +20,49 @@ async function fetchInfo(body, demo = false) {
16
20
  }
17
21
  return res.json();
18
22
  }
23
+ __name(fetchInfo, "fetchInfo");
19
24
  async function fetchPerpDexs(demo = false) {
20
- return fetchInfo({ type: "perpDexs" }, demo);
25
+ return fetchInfo({
26
+ type: "perpDexs"
27
+ }, demo);
21
28
  }
29
+ __name(fetchPerpDexs, "fetchPerpDexs");
22
30
  async function fetchClearinghouseState(user, dex, demo = false) {
23
- return fetchInfo({ type: "clearinghouseState", user, dex }, demo);
31
+ return fetchInfo({
32
+ type: "clearinghouseState",
33
+ user,
34
+ dex
35
+ }, demo);
24
36
  }
37
+ __name(fetchClearinghouseState, "fetchClearinghouseState");
25
38
  async function fetchUserAbstraction(user, demo = false) {
26
- return fetchInfo({ type: "userAbstraction", user }, demo);
39
+ return fetchInfo({
40
+ type: "userAbstraction",
41
+ user
42
+ }, demo);
27
43
  }
44
+ __name(fetchUserAbstraction, "fetchUserAbstraction");
28
45
  async function fetchUserRole(user, demo = false) {
29
- return fetchInfo({ type: "userRole", user }, demo);
46
+ return fetchInfo({
47
+ type: "userRole",
48
+ user
49
+ }, demo);
30
50
  }
51
+ __name(fetchUserRole, "fetchUserRole");
31
52
  async function fetchSpotClearinghouseState(user, demo = false) {
32
- return fetchInfo({ type: "spotClearinghouseState", user }, demo);
53
+ return fetchInfo({
54
+ type: "spotClearinghouseState",
55
+ user
56
+ }, demo);
33
57
  }
58
+ __name(fetchSpotClearinghouseState, "fetchSpotClearinghouseState");
34
59
  async function fetchActiveAssetData(user, coin, demo = false) {
35
- return fetchInfo({ type: "activeAssetData", user, coin }, demo);
60
+ return fetchInfo({
61
+ type: "activeAssetData",
62
+ user,
63
+ coin
64
+ }, demo);
36
65
  }
66
+ __name(fetchActiveAssetData, "fetchActiveAssetData");
37
67
 
38
68
  export { fetchActiveAssetData, fetchClearinghouseState, fetchInfo, fetchPerpDexs, fetchSpotClearinghouseState, fetchUserAbstraction, fetchUserRole };
@@ -1,16 +1,20 @@
1
1
  import { BaseWs } from '../base-ws';
2
2
 
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
5
  const HL_WS_URLS = {
4
6
  mainnet: "wss://api.hyperliquid.xyz/ws",
5
7
  testnet: "wss://api.hyperliquid-testnet.xyz/ws"
6
8
  };
7
9
  class HyperliquidWs extends BaseWs {
10
+ static {
11
+ __name(this, "HyperliquidWs");
12
+ }
13
+ demo;
8
14
  /** Creates a Hyperliquid socket for the selected network. */
9
15
  constructor(demo = false) {
10
- super();
11
- this.demo = demo;
16
+ super(), this.demo = demo;
12
17
  }
13
- demo;
14
18
  /** Selects the mainnet or testnet websocket origin. */
15
19
  getWsUrl() {
16
20
  return this.demo ? HL_WS_URLS.testnet : HL_WS_URLS.mainnet;
@@ -21,7 +25,9 @@ class HyperliquidWs extends BaseWs {
21
25
  }
22
26
  /** Builds Hyperliquid's documented application-level heartbeat. */
23
27
  buildPingMessage() {
24
- return { method: "ping" };
28
+ return {
29
+ method: "ping"
30
+ };
25
31
  }
26
32
  }
27
33