@orderly.network/hooks 0.0.94 → 1.0.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.
package/dist/index.js CHANGED
@@ -1,49 +1,56 @@
1
1
  'use strict';
2
2
 
3
- var React2 = require('react');
4
3
  var useSWR = require('swr');
5
4
  var net = require('@orderly.network/net');
5
+ var React = require('react');
6
6
  var useSWRMutation = require('swr/mutation');
7
- var useConstant = require('use-constant');
7
+ var useConstant4 = require('use-constant');
8
8
  var core = require('@orderly.network/core');
9
9
  var types = require('@orderly.network/types');
10
10
  var utils = require('@orderly.network/utils');
11
11
  var useSWRSubscription = require('swr/subscription');
12
12
  var ramda = require('ramda');
13
- var futures = require('@orderly.network/futures');
13
+ var perp = require('@orderly.network/perp');
14
14
  var useSWRInfinite = require('swr/infinite');
15
15
  var useDebounce = require('use-debounce');
16
16
  var scanClient = require('@layerzerolabs/scan-client');
17
17
 
18
18
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
19
19
 
20
- var React2__default = /*#__PURE__*/_interopDefault(React2);
21
20
  var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);
21
+ var React__default = /*#__PURE__*/_interopDefault(React);
22
22
  var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
23
- var useConstant__default = /*#__PURE__*/_interopDefault(useConstant);
23
+ var useConstant4__default = /*#__PURE__*/_interopDefault(useConstant4);
24
24
  var useSWRSubscription__default = /*#__PURE__*/_interopDefault(useSWRSubscription);
25
25
  var useSWRInfinite__default = /*#__PURE__*/_interopDefault(useSWRInfinite);
26
26
 
27
- var __defProp = Object.defineProperty;
28
- var __export = (target, all) => {
29
- for (var name in all)
30
- __defProp(target, name, { get: all[name], enumerable: true });
31
- };
32
- var OrderlyContext = React2.createContext({
27
+ // src/useQuery.ts
28
+ var fetcher = (url, init = {}, queryOptions) => net.get(url, init, queryOptions?.formatter);
29
+ var OrderlyContext = React.createContext({
33
30
  // configStore: new MemoryConfigStore(),
34
31
  });
35
32
  var OrderlyProvider = OrderlyContext.Provider;
36
- var fetcher = (url, init = {}, queryOptions) => net.get(url, init, queryOptions?.formatter);
33
+
34
+ // src/useConfig.ts
35
+ var useConfig = (key, defaultValue) => {
36
+ const { configStore } = React.useContext(OrderlyContext);
37
+ if (typeof key !== "undefined") {
38
+ if (typeof defaultValue !== "undefined") {
39
+ return configStore.getOr(key, defaultValue);
40
+ }
41
+ return configStore.get(key);
42
+ }
43
+ return configStore;
44
+ };
37
45
 
38
46
  // src/useQuery.ts
39
47
  var useQuery = (query, options) => {
40
- const { apiBaseUrl } = React2.useContext(OrderlyContext);
48
+ const apiBaseUrl = useConfig("apiBaseUrl");
41
49
  const { formatter, ...swrOptions } = options || {};
42
50
  if (typeof apiBaseUrl === "undefined") {
43
- throw new Error("please add OrderlyProvider to your app");
51
+ throw new Error("please add OrderlyConfigProvider to your app");
44
52
  }
45
53
  return useSWR__default.default(
46
- // `${apiBaseUrl}${query}`,
47
54
  query,
48
55
  (url, init) => fetcher(url.startsWith("http") ? url : `${apiBaseUrl}${url}`, init, {
49
56
  formatter
@@ -52,10 +59,10 @@ var useQuery = (query, options) => {
52
59
  );
53
60
  };
54
61
  var useLazyQuery = (query, options) => {
55
- const { apiBaseUrl } = React2.useContext(OrderlyContext);
62
+ const apiBaseUrl = useConfig("apiBaseUrl");
56
63
  const { formatter, init, ...swrOptions } = options || {};
57
64
  if (typeof apiBaseUrl === "undefined") {
58
- throw new Error("please add OrderlyProvider to your app");
65
+ throw new Error("please add OrderlyConfigProvider to your app");
59
66
  }
60
67
  return useSWRMutation__default.default(
61
68
  query,
@@ -75,7 +82,7 @@ var useLazyQuery = (query, options) => {
75
82
  );
76
83
  };
77
84
  var useAccountInstance = () => {
78
- const { configStore, keyStore, contractManager, getWalletAdapter } = React2.useContext(OrderlyContext);
85
+ const { configStore, keyStore, getWalletAdapter } = React.useContext(OrderlyContext);
79
86
  if (!configStore)
80
87
  throw new Error("configStore is not defined, please use OrderlyProvider");
81
88
  if (!keyStore) {
@@ -83,13 +90,12 @@ var useAccountInstance = () => {
83
90
  "keyStore is not defined, please use OrderlyProvider and provide keyStore"
84
91
  );
85
92
  }
86
- const account5 = useConstant__default.default(() => {
93
+ const account5 = useConstant4__default.default(() => {
87
94
  let account6 = core.SimpleDI.get("account");
88
95
  if (!account6) {
89
96
  account6 = new core.Account(
90
97
  configStore,
91
98
  keyStore,
92
- contractManager,
93
99
  getWalletAdapter
94
100
  // walletAdapter
95
101
  );
@@ -118,7 +124,7 @@ var fetcher2 = (url, options) => {
118
124
  return net.mutate(url, init);
119
125
  };
120
126
  var useMutation = (url, method = "POST", options) => {
121
- const { apiBaseUrl } = React2.useContext(OrderlyContext);
127
+ const apiBaseUrl = useConfig("apiBaseUrl");
122
128
  let fullUrl = url;
123
129
  if (!url.startsWith("http")) {
124
130
  fullUrl = `${apiBaseUrl}${url}`;
@@ -164,7 +170,7 @@ var useMutation = (url, method = "POST", options) => {
164
170
  ];
165
171
  };
166
172
  var signatureMiddleware = (useSWRNext) => {
167
- const { apiBaseUrl } = React2.useContext(OrderlyContext);
173
+ const apiBaseUrl = useConfig("apiBaseUrl");
168
174
  return (key, fetcher3, config) => {
169
175
  try {
170
176
  const extendedFetcher = async (args) => {
@@ -177,6 +183,7 @@ var signatureMiddleware = (useSWRNext) => {
177
183
  url
178
184
  };
179
185
  const signature = await signer.sign(payload);
186
+ console.log("signature:", fullUrl);
180
187
  return fetcher3(fullUrl, {
181
188
  headers: {
182
189
  ...signature,
@@ -194,11 +201,11 @@ var signatureMiddleware = (useSWRNext) => {
194
201
  var useAccount = () => {
195
202
  const {
196
203
  configStore,
197
- keyStore,
198
- onWalletConnect,
199
- onWalletDisconnect,
200
- onSetChain
201
- } = React2.useContext(OrderlyContext);
204
+ keyStore
205
+ // onWalletConnect,
206
+ // onWalletDisconnect,
207
+ // onSetChain,
208
+ } = React.useContext(OrderlyContext);
202
209
  if (!configStore)
203
210
  throw new Error("configStore is not defined, please use OrderlyProvider");
204
211
  if (!keyStore) {
@@ -207,45 +214,35 @@ var useAccount = () => {
207
214
  );
208
215
  }
209
216
  const account5 = useAccountInstance();
210
- const [state, setState] = React2.useState(account5.stateValue);
217
+ const [state, setState] = React.useState(account5.stateValue);
211
218
  const statusChangeHandler = (nextState) => {
212
219
  setState(() => nextState);
213
220
  };
214
- React2.useEffect(() => {
221
+ React.useEffect(() => {
215
222
  account5.on("change:status", statusChangeHandler);
216
223
  return () => {
217
224
  account5.off("change:status", statusChangeHandler);
218
225
  };
219
226
  }, []);
220
- const createOrderlyKey = React2.useCallback(
227
+ const createOrderlyKey = React.useCallback(
221
228
  async (remember) => {
222
229
  return account5.createOrderlyKey(remember ? 365 : 30);
223
230
  },
224
231
  [account5]
225
232
  );
226
- const createAccount = React2.useCallback(async () => {
233
+ const createAccount = React.useCallback(async () => {
227
234
  return account5.createAccount();
228
235
  }, [account5]);
229
- const connect = React2.useCallback(async () => {
230
- return onWalletConnect?.();
231
- }, [account5]);
232
- const disconnect = async () => {
233
- return onWalletDisconnect?.();
234
- };
235
- const setChain = async (chainId) => {
236
- return onSetChain?.(chainId);
237
- };
238
236
  return {
239
- // account: state!,
240
237
  account: account5,
241
238
  state,
242
239
  // info: {},
243
240
  // login,
244
241
  createOrderlyKey,
245
- createAccount,
246
- disconnect,
247
- connect,
248
- setChain
242
+ createAccount
243
+ // disconnect,
244
+ // connect,
245
+ // setChain,
249
246
  // settlement,
250
247
  };
251
248
  };
@@ -255,7 +252,6 @@ var usePrivateQuery = (query, options) => {
255
252
  const middleware = Array.isArray(options?.use) ? options?.use ?? [] : [];
256
253
  return useSWR__default.default(
257
254
  () => account5.state.status >= types.AccountStatusEnum.EnableTrading ? [query, account5.state.accountId] : null,
258
- // query,
259
255
  (url, init) => {
260
256
  return fetcher(url, init, { formatter });
261
257
  },
@@ -268,36 +264,14 @@ var usePrivateQuery = (query, options) => {
268
264
  );
269
265
  };
270
266
  var useBoolean = (initialValue = false) => {
271
- const [value, setValue] = React2.useState(initialValue);
272
- const setTrue = React2.useCallback(() => setValue(true), []);
273
- const setFalse = React2.useCallback(() => setValue(false), []);
274
- const toggle = React2.useCallback(() => setValue((v) => !v), []);
267
+ const [value, setValue] = React.useState(initialValue);
268
+ const setTrue = React.useCallback(() => setValue(true), []);
269
+ const setFalse = React.useCallback(() => setValue(false), []);
270
+ const toggle = React.useCallback(() => setValue((v) => !v), []);
275
271
  return [value, { setTrue, setFalse, toggle }];
276
272
  };
277
-
278
- // src/useTradingView.ts
279
- var useTradingView = () => {
280
- return {};
281
- };
282
- var useTopicObserve = (topic) => {
283
- const [data, setData] = React2.useState();
284
- React2.useEffect(() => {
285
- return () => {
286
- };
287
- }, []);
288
- return {
289
- data
290
- };
291
- };
292
- var useAppState = () => {
293
- const { errors } = React2.useContext(OrderlyContext);
294
- return {
295
- errors
296
- // ready,
297
- };
298
- };
299
273
  var usePreLoadData = () => {
300
- const { configStore } = React2.useContext(OrderlyContext);
274
+ const { configStore } = React.useContext(OrderlyContext);
301
275
  const { error: swapSupportError, data: swapSupportData } = useSWR__default.default(
302
276
  `${configStore.get("swapSupportApiUrl")}/swap_support`,
303
277
  (url) => fetch(url).then((res) => res.json()),
@@ -308,7 +282,7 @@ var usePreLoadData = () => {
308
282
  const { error: tokenError, data: tokenData } = useQuery("/v1/public/token", {
309
283
  revalidateOnFocus: false
310
284
  });
311
- const isDone = React2.useMemo(() => {
285
+ const isDone = React.useMemo(() => {
312
286
  return !!swapSupportData && !!tokenData;
313
287
  }, [swapSupportData, tokenData]);
314
288
  return {
@@ -316,8 +290,8 @@ var usePreLoadData = () => {
316
290
  done: isDone
317
291
  };
318
292
  };
319
- var useEventEmitter = (channel) => {
320
- return useConstant__default.default(() => {
293
+ var useEventEmitter = () => {
294
+ return useConstant4__default.default(() => {
321
295
  let ee = core.SimpleDI.get("EE");
322
296
  if (!ee) {
323
297
  ee = new core.EventEmitter();
@@ -338,7 +312,7 @@ function parseJSON(value) {
338
312
 
339
313
  // src/useSessionStorage.ts
340
314
  function useSessionStorage(key, initialValue) {
341
- const readValue = React2.useCallback(() => {
315
+ const readValue = React.useCallback(() => {
342
316
  if (typeof window === "undefined") {
343
317
  return initialValue;
344
318
  }
@@ -350,7 +324,7 @@ function useSessionStorage(key, initialValue) {
350
324
  return initialValue;
351
325
  }
352
326
  }, [initialValue, key]);
353
- const [storedValue, setStoredValue] = React2.useState(readValue);
327
+ const [storedValue, setStoredValue] = React.useState(readValue);
354
328
  const setValue = (value) => {
355
329
  if (typeof window == "undefined") {
356
330
  console.warn(
@@ -365,10 +339,10 @@ function useSessionStorage(key, initialValue) {
365
339
  console.warn(`Error setting sessionStorage key \u201C${key}\u201D:`, error);
366
340
  }
367
341
  };
368
- React2.useEffect(() => {
342
+ React.useEffect(() => {
369
343
  setStoredValue(readValue());
370
344
  }, []);
371
- React2.useEffect(() => {
345
+ React.useEffect(() => {
372
346
  if (typeof window == "undefined") {
373
347
  return;
374
348
  }
@@ -377,7 +351,7 @@ function useSessionStorage(key, initialValue) {
377
351
  window.removeEventListener("storage", handleStorageChange);
378
352
  };
379
353
  });
380
- const handleStorageChange = React2.useCallback(
354
+ const handleStorageChange = React.useCallback(
381
355
  (event) => {
382
356
  if (event?.key && event.key !== key) {
383
357
  return;
@@ -389,7 +363,7 @@ function useSessionStorage(key, initialValue) {
389
363
  return [storedValue, setValue];
390
364
  }
391
365
  function useLocalStorage(key, initialValue) {
392
- const readValue = React2.useCallback(() => {
366
+ const readValue = React.useCallback(() => {
393
367
  if (typeof window === "undefined") {
394
368
  return initialValue;
395
369
  }
@@ -401,8 +375,8 @@ function useLocalStorage(key, initialValue) {
401
375
  return initialValue;
402
376
  }
403
377
  }, [initialValue, key]);
404
- const [storedValue, setStoredValue] = React2.useState(readValue);
405
- const setValue = React2.useCallback(
378
+ const [storedValue, setStoredValue] = React.useState(readValue);
379
+ const setValue = React.useCallback(
406
380
  (value) => {
407
381
  if (typeof window === "undefined") {
408
382
  console.warn(
@@ -419,37 +393,15 @@ function useLocalStorage(key, initialValue) {
419
393
  },
420
394
  [storedValue]
421
395
  );
422
- React2.useEffect(() => {
396
+ React.useEffect(() => {
423
397
  setStoredValue(readValue());
424
398
  }, []);
425
399
  return [storedValue, setValue];
426
400
  }
427
- var useRunOnce = ({ fn, sessionKey }) => {
428
- const triggered = React2.useRef(false);
429
- React2.useEffect(() => {
430
- const hasBeenTriggered = sessionKey ? sessionStorage.getItem(sessionKey) : triggered.current;
431
- if (!hasBeenTriggered) {
432
- fn();
433
- triggered.current = true;
434
- if (sessionKey) {
435
- sessionStorage.setItem(sessionKey, "true");
436
- }
437
- }
438
- }, [fn, sessionKey]);
439
- return null;
440
- };
441
- var DataSourceContext = React2.createContext({});
442
- var DataSourceProvider = (props) => {
443
- useAccountInstance();
444
- useConstant__default.default(() => {
445
- });
446
- return /* @__PURE__ */ React2__default.default.createElement(DataSourceContext.Provider, { value: {} }, props.children);
447
- };
448
401
  var WS_NAME = "nativeWebsocketClient";
449
402
  var useWS = () => {
450
- useAccount();
451
- const { configStore } = React2.useContext(OrderlyContext);
452
- const ws = useConstant__default.default(() => {
403
+ const { configStore } = React.useContext(OrderlyContext);
404
+ const ws = useConstant4__default.default(() => {
453
405
  let websocketClient = core.SimpleDI.get(WS_NAME);
454
406
  const account5 = core.SimpleDI.get(core.Account.instanceName);
455
407
  if (!websocketClient) {
@@ -476,9 +428,44 @@ var useWS = () => {
476
428
  });
477
429
  return ws;
478
430
  };
479
- var useConfig = () => {
480
- const { configStore } = React2.useContext(OrderlyContext);
481
- return configStore;
431
+ var OrderlyConfigProvider = (props) => {
432
+ const { configStore, keyStore, getWalletAdapter, brokerId, networkId } = props;
433
+ if (!brokerId && typeof configStore === "undefined") {
434
+ console.error("[OrderlyConfigProvider]: brokerId is required");
435
+ }
436
+ const innerConfigStore = useConstant4__default.default(() => {
437
+ return configStore || new core.MemoryConfigStore({ brokerId });
438
+ });
439
+ const innerKeyStore = useConstant4__default.default(() => {
440
+ return keyStore || new core.LocalStorageStore(networkId);
441
+ });
442
+ const innerGetWalletAdapter = useConstant4__default.default(() => {
443
+ return getWalletAdapter || ((options) => new core.EtherAdapter(options));
444
+ });
445
+ React.useEffect(() => {
446
+ let account5 = core.SimpleDI.get(core.Account.instanceName);
447
+ if (!account5) {
448
+ account5 = new core.Account(
449
+ innerConfigStore,
450
+ innerKeyStore,
451
+ innerGetWalletAdapter
452
+ );
453
+ core.SimpleDI.registerByName(core.Account.instanceName, account5);
454
+ }
455
+ }, []);
456
+ return /* @__PURE__ */ React__default.default.createElement(
457
+ OrderlyProvider,
458
+ {
459
+ value: {
460
+ configStore: innerConfigStore,
461
+ keyStore: innerKeyStore,
462
+ getWalletAdapter: innerGetWalletAdapter,
463
+ networkId
464
+ // apiBaseUrl,
465
+ }
466
+ },
467
+ props.children
468
+ );
482
469
  };
483
470
  var useMarkPrice = (symbol) => {
484
471
  const ws = useWS();
@@ -532,9 +519,9 @@ var useTickerStream = (symbol) => {
532
519
  revalidateOnFocus: false
533
520
  }
534
521
  );
535
- const [ticker, setTicker] = React2.useState();
522
+ const [ticker, setTicker] = React.useState();
536
523
  const ws = useWS();
537
- React2.useEffect(() => {
524
+ React.useEffect(() => {
538
525
  const unsubscribe = ws.subscribe(
539
526
  // { event: "subscribe", topic: "markprices" },
540
527
  `${symbol}@ticker`,
@@ -560,7 +547,7 @@ var useTickerStream = (symbol) => {
560
547
  const { data: markPrice } = useMarkPrice(symbol);
561
548
  const { data: indexPrice } = useIndexPrice(symbol);
562
549
  const { data: openInterest } = useOpenInterest(symbol);
563
- const value = React2.useMemo(() => {
550
+ const value = React.useMemo(() => {
564
551
  if (!info)
565
552
  return null;
566
553
  if (!ticker)
@@ -666,7 +653,7 @@ var reduceItems = (depth, level, data, asks = false) => {
666
653
  } else {
667
654
  priceKey = new utils.Decimal(Math.floor(price / depth)).mul(depth).toNumber();
668
655
  }
669
- if (depth < 1 && depth > 0) {
656
+ if (depth < 1 && depth > 0 && priceKey.toString().indexOf(".") !== -1) {
670
657
  const priceStr = price.toString();
671
658
  const index = priceStr.indexOf(".");
672
659
  const decimal = priceStr.slice(index + 1);
@@ -764,23 +751,23 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
764
751
  if (!symbol) {
765
752
  throw new Error("useOrderbookStream requires a symbol");
766
753
  }
767
- const [requestData, setRequestData] = React2.useState(null);
768
- const [data, setData] = React2.useState(initial);
769
- const [isLoading, setIsLoading] = React2.useState(true);
770
- const [level, setLevel] = React2.useState(() => options?.level ?? 10);
754
+ const [requestData, setRequestData] = React.useState(null);
755
+ const [data, setData] = React.useState(initial);
756
+ const [isLoading, setIsLoading] = React.useState(true);
757
+ const [level, setLevel] = React.useState(() => options?.level ?? 10);
771
758
  const config = useSymbolsInfo()[symbol];
772
- const [depth, setDepth] = React2.useState();
773
- const depths = React2.useMemo(() => {
759
+ const [depth, setDepth] = React.useState();
760
+ const depths = React.useMemo(() => {
774
761
  const tick = config("quote_tick");
775
762
  return [tick, tick * 10, tick * 100, tick * 1e3];
776
763
  }, [config("quote_tick")]);
777
- React2.useEffect(() => {
764
+ React.useEffect(() => {
778
765
  setDepth(config("quote_tick"));
779
766
  }, [config("quote_tick")]);
780
767
  const ws = useWS();
781
768
  const ticker = useTickerStream(symbol);
782
769
  const eventEmitter = useEventEmitter();
783
- React2.useEffect(() => {
770
+ React.useEffect(() => {
784
771
  setIsLoading(true);
785
772
  let ignore = false;
786
773
  ws.onceSubscribe(
@@ -815,7 +802,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
815
802
  };
816
803
  }, [symbol, depth]);
817
804
  const { data: markPrice } = useMarkPrice(symbol);
818
- React2.useEffect(() => {
805
+ React.useEffect(() => {
819
806
  if (!requestData)
820
807
  return;
821
808
  let ignore = false;
@@ -840,14 +827,14 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
840
827
  subscription?.();
841
828
  };
842
829
  }, [symbol, requestData]);
843
- const onItemClick = React2.useCallback((item) => {
830
+ const onItemClick = React.useCallback((item) => {
844
831
  eventEmitter.emit("orderbook:item:click", item);
845
832
  }, []);
846
- const onDepthChange = React2.useCallback((depth2) => {
833
+ const onDepthChange = React.useCallback((depth2) => {
847
834
  setDepth(() => depth2);
848
835
  }, []);
849
- const prevMiddlePrice = React2.useRef(0);
850
- const middlePrice = React2.useMemo(() => {
836
+ const prevMiddlePrice = React.useRef(0);
837
+ const middlePrice = React.useMemo(() => {
851
838
  let asksFrist = 0, bidsFirst = 0;
852
839
  if (data.asks.length > 0) {
853
840
  asksFrist = data.asks[data.asks.length - 1][0];
@@ -859,7 +846,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
859
846
  return 0;
860
847
  return [asksFrist, bidsFirst, ticker["24h_close"]].sort()[1];
861
848
  }, [ticker, data]);
862
- React2.useEffect(() => {
849
+ React.useEffect(() => {
863
850
  prevMiddlePrice.current = middlePrice;
864
851
  }, [middlePrice]);
865
852
  const reducedData = reduceOrderbook(depth, level, {
@@ -1104,7 +1091,7 @@ var usePositionStream = (symbol, options) => {
1104
1091
  }
1105
1092
  });
1106
1093
  const { data: markPrices } = useMarkPricesStream();
1107
- const formatedPositions = React2.useMemo(() => {
1094
+ const formatedPositions = React.useMemo(() => {
1108
1095
  if (!data?.rows || !symbolInfo || !accountInfo)
1109
1096
  return null;
1110
1097
  const filteredData = typeof symbol === "undefined" || symbol === "" ? data.rows : data.rows.filter((item) => {
@@ -1118,13 +1105,13 @@ var usePositionStream = (symbol, options) => {
1118
1105
  markPrices
1119
1106
  );
1120
1107
  const info = symbolInfo?.[item.symbol];
1121
- const notional = futures.positions.notional(item.position_qty, price);
1122
- const unrealPnl = futures.positions.unrealizedPnL({
1108
+ const notional = perp.positions.notional(item.position_qty, price);
1109
+ const unrealPnl = perp.positions.unrealizedPnL({
1123
1110
  qty: item.position_qty,
1124
1111
  openPrice: item.average_open_price,
1125
1112
  markPrice: price
1126
1113
  });
1127
- const imr = futures.account.IMR({
1114
+ const imr = perp.account.IMR({
1128
1115
  maxLeverage: accountInfo.max_leverage,
1129
1116
  baseIMR: info("base_imr"),
1130
1117
  IMR_Factor: accountInfo.imr_factor[item.symbol],
@@ -1132,13 +1119,13 @@ var usePositionStream = (symbol, options) => {
1132
1119
  ordersNotional: 0,
1133
1120
  IMR_factor_power: 4 / 5
1134
1121
  });
1135
- const unrealPnlROI = futures.positions.unrealizedPnLROI({
1122
+ const unrealPnlROI = perp.positions.unrealizedPnLROI({
1136
1123
  positionQty: item.position_qty,
1137
1124
  openPrice: item.average_open_price,
1138
1125
  IMR: imr,
1139
1126
  unrealizedPnL: unrealPnl
1140
1127
  });
1141
- const unsettlementPnL = futures.positions.unsettlementPnL({
1128
+ const unsettlementPnL = perp.positions.unsettlementPnL({
1142
1129
  positionQty: item.position_qty,
1143
1130
  markPrice: price,
1144
1131
  costPosition: item.cost_position,
@@ -1170,30 +1157,30 @@ var usePositionStream = (symbol, options) => {
1170
1157
  }
1171
1158
  ];
1172
1159
  }, [data?.rows, symbolInfo, accountInfo, markPrices, symbol, holding]);
1173
- const [totalCollateral, totalValue, totalUnrealizedROI] = React2.useMemo(() => {
1160
+ const [totalCollateral, totalValue, totalUnrealizedROI] = React.useMemo(() => {
1174
1161
  if (!holding || !markPrices) {
1175
1162
  return [utils.zero, utils.zero, 0];
1176
1163
  }
1177
1164
  const unsettlemnedPnL = ramda.pathOr(0, [1, "unsettledPnL"])(formatedPositions);
1178
1165
  const unrealizedPnL = ramda.pathOr(0, [1, "unrealPnL"])(formatedPositions);
1179
1166
  const [USDC_holding, nonUSDC] = parseHolding(holding, markPrices);
1180
- const totalCollateral2 = futures.account.totalCollateral({
1167
+ const totalCollateral2 = perp.account.totalCollateral({
1181
1168
  USDCHolding: USDC_holding,
1182
1169
  nonUSDCHolding: nonUSDC,
1183
1170
  unsettlementPnL: unsettlemnedPnL
1184
1171
  });
1185
- const totalValue2 = futures.account.totalValue({
1172
+ const totalValue2 = perp.account.totalValue({
1186
1173
  totalUnsettlementPnL: unsettlemnedPnL,
1187
1174
  USDCHolding: USDC_holding,
1188
1175
  nonUSDCHolding: nonUSDC
1189
1176
  });
1190
- const totalUnrealizedROI2 = futures.account.totalUnrealizedROI({
1177
+ const totalUnrealizedROI2 = perp.account.totalUnrealizedROI({
1191
1178
  totalUnrealizedPnL: unrealizedPnL,
1192
1179
  totalValue: totalValue2.toNumber()
1193
1180
  });
1194
1181
  return [totalCollateral2, totalValue2, totalUnrealizedROI2];
1195
1182
  }, [holding, formatedPositions, markPrices]);
1196
- const positionsRows = React2.useMemo(() => {
1183
+ const positionsRows = React.useMemo(() => {
1197
1184
  if (!formatedPositions)
1198
1185
  return null;
1199
1186
  if (!symbolInfo || !accountInfo)
@@ -1201,7 +1188,7 @@ var usePositionStream = (symbol, options) => {
1201
1188
  const total = totalCollateral.toNumber();
1202
1189
  return formatedPositions[0].filter((item) => item.position_qty !== 0).map((item) => {
1203
1190
  const info = symbolInfo?.[item.symbol];
1204
- const MMR = futures.positions.MMR({
1191
+ const MMR = perp.positions.MMR({
1205
1192
  baseMMR: info("base_mmr"),
1206
1193
  baseIMR: info("base_imr"),
1207
1194
  IMRFactor: accountInfo.imr_factor[item.symbol],
@@ -1210,12 +1197,12 @@ var usePositionStream = (symbol, options) => {
1210
1197
  });
1211
1198
  return {
1212
1199
  ...item,
1213
- mm: futures.positions.maintenanceMargin({
1200
+ mm: perp.positions.maintenanceMargin({
1214
1201
  positionQty: item.position_qty,
1215
1202
  markPrice: item.mark_price,
1216
1203
  MMR
1217
1204
  }),
1218
- est_liq_price: futures.positions.liqPrice({
1205
+ est_liq_price: perp.positions.liqPrice({
1219
1206
  markPrice: item.mark_price,
1220
1207
  totalCollateral: total,
1221
1208
  positionQty: item.position_qty,
@@ -1261,7 +1248,7 @@ var useHoldingStream = () => {
1261
1248
  }
1262
1249
  }
1263
1250
  );
1264
- const usdc = React2.useMemo(() => {
1251
+ const usdc = React.useMemo(() => {
1265
1252
  const usdc2 = data?.find((item) => item.token === "USDC");
1266
1253
  return usdc2;
1267
1254
  }, [data]);
@@ -1314,12 +1301,8 @@ var usePrivateInfiniteQuery = (getKey, options) => {
1314
1301
  );
1315
1302
  return result;
1316
1303
  };
1317
- var useOrderStream = ({
1318
- status,
1319
- symbol,
1320
- side,
1321
- size = 100
1322
- } = {}) => {
1304
+ var useOrderStream = (params) => {
1305
+ const { status, symbol, side, size = 100 } = params;
1323
1306
  const ws = useWS();
1324
1307
  const { data: markPrices = {} } = useMarkPricesStream();
1325
1308
  const [doCancelOrder] = useMutation("/v1/order", "DELETE");
@@ -1351,7 +1334,7 @@ var useOrderStream = ({
1351
1334
  formatter: (data) => data
1352
1335
  }
1353
1336
  );
1354
- const orders = React2.useMemo(() => {
1337
+ const orders = React.useMemo(() => {
1355
1338
  if (!ordersResponse.data) {
1356
1339
  return null;
1357
1340
  }
@@ -1362,10 +1345,10 @@ var useOrderStream = ({
1362
1345
  };
1363
1346
  });
1364
1347
  }, [ordersResponse.data, markPrices]);
1365
- const total = React2.useMemo(() => {
1348
+ const total = React.useMemo(() => {
1366
1349
  return ordersResponse.data?.[0]?.meta?.total || 0;
1367
1350
  }, [ordersResponse.data]);
1368
- React2.useEffect(() => {
1351
+ React.useEffect(() => {
1369
1352
  const unsubscribe = ws.privateSubscribe(
1370
1353
  {
1371
1354
  id: "executionreport_orders",
@@ -1426,12 +1409,12 @@ var useOrderStream = ({
1426
1409
  );
1427
1410
  return () => unsubscribe();
1428
1411
  }, []);
1429
- const cancelAllOrders = React2.useCallback(() => {
1412
+ const cancelAllOrders = React.useCallback(() => {
1430
1413
  }, [ordersResponse.data]);
1431
- const updateOrder = React2.useCallback((orderId, order2) => {
1414
+ const updateOrder = React.useCallback((orderId, order2) => {
1432
1415
  return doUpdateOrder({ ...order2, order_id: orderId });
1433
1416
  }, []);
1434
- const cancelOrder = React2.useCallback((orderId, symbol2) => {
1417
+ const cancelOrder = React.useCallback((orderId, symbol2) => {
1435
1418
  return doCancelOrder(null, {
1436
1419
  order_id: orderId,
1437
1420
  symbol: symbol2
@@ -1474,7 +1457,6 @@ function rePageData(list, total, pageSize) {
1474
1457
  rows = [];
1475
1458
  }
1476
1459
  }
1477
- console.log("rePageData", list, total, newData);
1478
1460
  return newData;
1479
1461
  }
1480
1462
  function editPageData(list, newOrder) {
@@ -1503,17 +1485,17 @@ var useCollateral = (options = { dp: 6 }) => {
1503
1485
  const symbolInfo = useSymbolsInfo();
1504
1486
  const { data: markPrices } = useMarkPricesStream();
1505
1487
  const { usdc } = useHoldingStream();
1506
- const [totalCollateral, totalValue] = React2.useMemo(() => {
1488
+ const [totalCollateral, totalValue] = React.useMemo(() => {
1507
1489
  return [
1508
1490
  ramda.pathOr(utils.zero, [0, "totalCollateral"], positions2),
1509
1491
  ramda.pathOr(utils.zero, [0, "totalValue"], positions2)
1510
1492
  ];
1511
1493
  }, [positions2, markPrices]);
1512
- const totalInitialMarginWithOrders = React2.useMemo(() => {
1494
+ const totalInitialMarginWithOrders = React.useMemo(() => {
1513
1495
  if (!accountInfo || !symbolInfo || !markPrices) {
1514
1496
  return 0;
1515
1497
  }
1516
- return futures.account.totalInitialMarginWithOrders({
1498
+ return perp.account.totalInitialMarginWithOrders({
1517
1499
  positions: positionsPath(positions2),
1518
1500
  orders: orders ?? [],
1519
1501
  markPrices,
@@ -1522,14 +1504,14 @@ var useCollateral = (options = { dp: 6 }) => {
1522
1504
  symbolInfo
1523
1505
  });
1524
1506
  }, [positions2, orders, markPrices, accountInfo, symbolInfo]);
1525
- const freeCollateral = React2.useMemo(() => {
1526
- return futures.account.freeCollateral({
1507
+ const freeCollateral = React.useMemo(() => {
1508
+ return perp.account.freeCollateral({
1527
1509
  totalCollateral,
1528
1510
  totalInitialMarginWithOrders
1529
1511
  });
1530
1512
  }, [totalCollateral, totalInitialMarginWithOrders]);
1531
- const availableBalance = React2.useMemo(() => {
1532
- return futures.account.availableBalance({
1513
+ const availableBalance = React.useMemo(() => {
1514
+ return perp.account.availableBalance({
1533
1515
  USDCHolding: usdc?.holding ?? 0,
1534
1516
  unsettlementPnL: pathOr_unsettledPnLPathOr(positions2)
1535
1517
  });
@@ -1550,11 +1532,11 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
1550
1532
  const symbolInfo = useSymbolsInfo();
1551
1533
  const { totalCollateral } = useCollateral();
1552
1534
  const { data: markPrices } = useMarkPricesStream();
1553
- const maxQty = React2.useMemo(() => {
1535
+ const maxQty = React.useMemo(() => {
1554
1536
  if (!symbol)
1555
1537
  return 0;
1556
1538
  const positions2 = positionsPath2(positionsData);
1557
- const positionQty = futures.account.getQtyFromPositions(positions2, symbol);
1539
+ const positionQty = perp.account.getQtyFromPositions(positions2, symbol);
1558
1540
  if (reduceOnly) {
1559
1541
  if (positionQty > 0) {
1560
1542
  if (side === types.OrderSide.BUY) {
@@ -1575,12 +1557,12 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
1575
1557
  if (!markPrices || !markPrices[symbol] || !orders || !accountInfo)
1576
1558
  return 0;
1577
1559
  const getSymbolInfo = symbolInfo[symbol];
1578
- const buyOrdersQty = futures.account.getQtyFromOrdersBySide(
1560
+ const buyOrdersQty = perp.account.getQtyFromOrdersBySide(
1579
1561
  orders,
1580
1562
  symbol,
1581
1563
  types.OrderSide.BUY
1582
1564
  );
1583
- const sellOrdersQty = futures.account.getQtyFromOrdersBySide(
1565
+ const sellOrdersQty = perp.account.getQtyFromOrdersBySide(
1584
1566
  orders,
1585
1567
  symbol,
1586
1568
  types.OrderSide.SELL
@@ -1591,7 +1573,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
1591
1573
  const otherOrders = orders.filter(
1592
1574
  (item) => item.symbol !== symbol
1593
1575
  );
1594
- const otherIMs = futures.account.otherIMs({
1576
+ const otherIMs = perp.account.otherIMs({
1595
1577
  orders: otherOrders,
1596
1578
  positions: otherPositions,
1597
1579
  symbolInfo,
@@ -1599,7 +1581,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
1599
1581
  IMR_Factors: accountInfo.imr_factor,
1600
1582
  maxLeverage: accountInfo.max_leverage
1601
1583
  });
1602
- return futures.account.maxQty(side, {
1584
+ return perp.account.maxQty(side, {
1603
1585
  markPrice: markPrices[symbol],
1604
1586
  symbol,
1605
1587
  baseMaxQty: getSymbolInfo("base_max"),
@@ -1626,7 +1608,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
1626
1608
  ]);
1627
1609
  return maxQty;
1628
1610
  };
1629
- var { maxPrice, minPrice } = futures.order;
1611
+ var { maxPrice, minPrice } = perp.order;
1630
1612
  var BaseOrderCreator = class {
1631
1613
  baseOrder(data) {
1632
1614
  const order2 = {
@@ -1787,11 +1769,11 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
1787
1769
  const [doCreateOrder] = useMutation("/v1/order");
1788
1770
  const { freeCollateral } = useCollateral();
1789
1771
  const symbolInfo = useSymbolsInfo();
1790
- const baseDP = React2.useMemo(
1772
+ const baseDP = React.useMemo(
1791
1773
  () => utils.getPrecisionByNumber(symbolInfo[symbol]("base_tick", 0)),
1792
1774
  [symbolInfo]
1793
1775
  );
1794
- const quoteDP = React2.useMemo(() => {
1776
+ const quoteDP = React.useMemo(() => {
1795
1777
  return utils.getPrecisionByNumber(symbolInfo[symbol]("quote_tick", 0));
1796
1778
  }, [symbolInfo]);
1797
1779
  const { data: markPrice } = useMarkPrice(symbol);
@@ -1830,7 +1812,7 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
1830
1812
  });
1831
1813
  });
1832
1814
  };
1833
- const calculate = React2.useCallback(
1815
+ const calculate = React.useCallback(
1834
1816
  (values, field, value) => {
1835
1817
  const fieldHandler = getCalculateHandler(field);
1836
1818
  const newValues = ramda.compose(
@@ -1864,65 +1846,11 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
1864
1846
  symbolConfig: symbolInfo[symbol]()
1865
1847
  };
1866
1848
  };
1867
- var useFetures = () => {
1868
- const { data, isLoading, error } = useQuery(
1869
- `/v1/public/futures`,
1870
- {
1871
- revalidateOnFocus: false
1872
- }
1873
- );
1874
- const [sortedData, setSortedData] = React2.useState(data);
1875
- useWS();
1876
- React2.useEffect(() => {
1877
- }, []);
1878
- React2.useEffect(() => {
1879
- if (data) {
1880
- const sortedData2 = data.sort((a, b) => {
1881
- return 0;
1882
- });
1883
- setSortedData(sortedData2);
1884
- }
1885
- }, [data]);
1886
- const sortBy = React2.useCallback((key) => {
1887
- }, [data]);
1888
- const filterBy = React2.useCallback((key) => {
1889
- }, [data]);
1890
- return {
1891
- // ...data,
1892
- data: sortedData,
1893
- sortBy,
1894
- filterBy,
1895
- isLoading,
1896
- error
1897
- };
1898
- };
1899
1849
 
1900
1850
  // src/orderly/useAccountInfo.ts
1901
1851
  var useAccountInfo = () => {
1902
1852
  return usePrivateQuery("/v1/client/info");
1903
1853
  };
1904
-
1905
- // src/orderly/useTokenInfo.ts
1906
- var useTokenInfo = () => {
1907
- const { data = {} } = useQuery(
1908
- "/v1/public/token",
1909
- {
1910
- focusThrottleInterval: 1e3 * 60 * 60 * 24,
1911
- revalidateOnFocus: false,
1912
- formatter(data2) {
1913
- if (!data2?.rows || !data2?.rows?.length) {
1914
- return {};
1915
- }
1916
- const obj = /* @__PURE__ */ Object.create(null);
1917
- for (let index = 0; index < data2.rows.length; index++) {
1918
- data2.rows[index];
1919
- }
1920
- return obj;
1921
- }
1922
- }
1923
- );
1924
- return createGetter(data);
1925
- };
1926
1854
  var useMarketsStream = () => {
1927
1855
  const ws = useWS();
1928
1856
  const { data: futures } = useQuery(`/v1/public/futures`, {
@@ -1948,7 +1876,7 @@ var useMarketsStream = () => {
1948
1876
  unsubscribe?.();
1949
1877
  };
1950
1878
  });
1951
- const value = React2.useMemo(() => {
1879
+ const value = React.useMemo(() => {
1952
1880
  if (!futures)
1953
1881
  return null;
1954
1882
  if (!tickers)
@@ -1975,7 +1903,7 @@ var useLeverage = () => {
1975
1903
  const { data, mutate: mutate2 } = usePrivateQuery("/v1/client/info");
1976
1904
  const [update] = useMutation("/v1/client/leverage");
1977
1905
  const { data: config } = useQuery("/v1/public/config");
1978
- const updateLeverage = React2.useCallback((data2) => {
1906
+ const updateLeverage = React.useCallback((data2) => {
1979
1907
  return update(data2).then((res) => {
1980
1908
  console.log(res);
1981
1909
  if (res.success) {
@@ -1998,7 +1926,7 @@ var useFundingRate = (symbol) => {
1998
1926
  if (!symbol) {
1999
1927
  throw new Error("useFuturesForSymbol requires a symbol");
2000
1928
  }
2001
- const [countDown, setCountDown] = React2.useState("00:00:00");
1929
+ const [countDown, setCountDown] = React.useState("00:00:00");
2002
1930
  const { data } = useQuery(
2003
1931
  `/v1/public/funding_rate/${symbol}`,
2004
1932
  {
@@ -2008,7 +1936,7 @@ var useFundingRate = (symbol) => {
2008
1936
  }
2009
1937
  }
2010
1938
  );
2011
- React2.useEffect(() => {
1939
+ React.useEffect(() => {
2012
1940
  if (!data)
2013
1941
  return;
2014
1942
  const { next_funding_time } = data;
@@ -2038,12 +1966,11 @@ var useMarketTradeStream = (symbol, options = {}) => {
2038
1966
  if (!symbol) {
2039
1967
  throw new Error("useTradeStream: symbol is required");
2040
1968
  }
2041
- const [trades, setTrades] = React2.useState([]);
2042
- const [isLoading, setIsLoading] = React2.useState(false);
2043
- React2.useState(() => symbol);
1969
+ const [trades, setTrades] = React.useState([]);
1970
+ const [isLoading, setIsLoading] = React.useState(false);
2044
1971
  const { limit = 50 } = options;
2045
1972
  const ws = useWS();
2046
- React2.useEffect(() => {
1973
+ React.useEffect(() => {
2047
1974
  setIsLoading(true);
2048
1975
  setTrades(() => []);
2049
1976
  ws.onceSubscribe(
@@ -2064,7 +1991,7 @@ var useMarketTradeStream = (symbol, options = {}) => {
2064
1991
  }
2065
1992
  );
2066
1993
  }, [symbol]);
2067
- React2.useEffect(() => {
1994
+ React.useEffect(() => {
2068
1995
  const unsubscript = ws.subscribe(
2069
1996
  {
2070
1997
  id: `${symbol}@trade`,
@@ -2094,19 +2021,19 @@ var useMarginRatio = () => {
2094
2021
  const [{ rows }] = usePositionStream();
2095
2022
  const { data: markPrices } = useMarkPricesStream();
2096
2023
  const { totalCollateral } = useCollateral();
2097
- const marginRatio = React2.useMemo(() => {
2024
+ const marginRatio = React.useMemo(() => {
2098
2025
  if (!rows || !markPrices || !totalCollateral || rows.length === 0) {
2099
2026
  return 0;
2100
2027
  }
2101
- const ratio = futures.account.totalMarginRatio({
2028
+ const ratio = perp.account.totalMarginRatio({
2102
2029
  totalCollateral,
2103
2030
  markPrices,
2104
2031
  positions: rows ?? []
2105
2032
  });
2106
2033
  return ratio;
2107
2034
  }, [rows, markPrices, totalCollateral]);
2108
- const currentLeverage = React2.useMemo(() => {
2109
- return futures.account.currentLeverage(marginRatio);
2035
+ const currentLeverage = React.useMemo(() => {
2036
+ return perp.account.currentLeverage(marginRatio);
2110
2037
  }, [marginRatio]);
2111
2038
  return { marginRatio, currentLeverage };
2112
2039
  };
@@ -3128,9 +3055,9 @@ var isNativeTokenChecker = (address) => address === nativeTokenAddress;
3128
3055
  // src/orderly/useChains.ts
3129
3056
  var useChains = (networkId, options = {}) => {
3130
3057
  const { filter, pick: pick3, crossEnabled, wooSwapEnabled, ...swrOptions } = options;
3131
- const { configStore, networkId: envNetworkId } = React2.useContext(OrderlyContext);
3058
+ const { configStore } = React.useContext(OrderlyContext);
3132
3059
  const field = options?.pick;
3133
- const map2 = React2.useRef(
3060
+ const map = React.useRef(
3134
3061
  /* @__PURE__ */ new Map()
3135
3062
  );
3136
3063
  const { data, error: swapSupportError } = useSWR__default.default(
@@ -3158,7 +3085,7 @@ var useChains = (networkId, options = {}) => {
3158
3085
  dedupingInterval: 36e5
3159
3086
  }
3160
3087
  );
3161
- const chains = React2.useMemo(() => {
3088
+ const chains = React.useMemo(() => {
3162
3089
  if (!orderlyChains)
3163
3090
  return void 0;
3164
3091
  let orderlyChainsArr = [];
@@ -3188,7 +3115,7 @@ var useChains = (networkId, options = {}) => {
3188
3115
  if (!options.filter(_chain))
3189
3116
  return;
3190
3117
  }
3191
- map2.current.set(chainId, _chain);
3118
+ map.current.set(chainId, _chain);
3192
3119
  orderlyChainsArr.push(_chain);
3193
3120
  });
3194
3121
  });
@@ -3237,7 +3164,7 @@ var useChains = (networkId, options = {}) => {
3237
3164
  });
3238
3165
  if (item.token_infos?.length === 0)
3239
3166
  return;
3240
- map2.current.set(item.network_infos.chain_id, item);
3167
+ map.current.set(item.network_infos.chain_id, item);
3241
3168
  if (typeof options?.filter === "function") {
3242
3169
  if (!options.filter(item))
3243
3170
  return;
@@ -3270,9 +3197,9 @@ var useChains = (networkId, options = {}) => {
3270
3197
  };
3271
3198
  }
3272
3199
  }, [data, networkId, field, options, orderlyChains, wooSwapEnabled]);
3273
- const findByChainId = React2.useCallback(
3200
+ const findByChainId = React.useCallback(
3274
3201
  (chainId, field2) => {
3275
- const chain = map2.current.get(chainId);
3202
+ const chain = map.current.get(chainId);
3276
3203
  if (chain) {
3277
3204
  chain.nativeToken = chain.token_infos?.find(
3278
3205
  (item) => item.address === nativeTokenAddress
@@ -3283,7 +3210,7 @@ var useChains = (networkId, options = {}) => {
3283
3210
  }
3284
3211
  return chain;
3285
3212
  },
3286
- [chains, map2.current]
3213
+ [chains, map.current]
3287
3214
  );
3288
3215
  return [
3289
3216
  chains,
@@ -3297,7 +3224,7 @@ var useChains = (networkId, options = {}) => {
3297
3224
  };
3298
3225
  var useChain = (token) => {
3299
3226
  const { data, isLoading } = useQuery("/v1/public/token");
3300
- const chains = React2.useMemo(() => {
3227
+ const chains = React.useMemo(() => {
3301
3228
  if (!data)
3302
3229
  return null;
3303
3230
  let item = data.find((chain) => chain.token === token);
@@ -3316,9 +3243,9 @@ var useChain = (token) => {
3316
3243
  };
3317
3244
  var useWithdraw = () => {
3318
3245
  const { account: account5, state } = useAccount();
3319
- const [isLoading, setIsLoading] = React2.useState(false);
3246
+ const [isLoading, setIsLoading] = React.useState(false);
3320
3247
  const { unsettledPnL, availableBalance } = useCollateral();
3321
- const withdraw = React2.useCallback(
3248
+ const withdraw = React.useCallback(
3322
3249
  (inputs) => {
3323
3250
  return account5.assetsManager.withdraw(inputs).then((res) => {
3324
3251
  return res;
@@ -3327,7 +3254,7 @@ var useWithdraw = () => {
3327
3254
  [state]
3328
3255
  );
3329
3256
  const { usdc } = useHoldingStream();
3330
- const maxAmount = React2.useMemo(() => {
3257
+ const maxAmount = React.useMemo(() => {
3331
3258
  if (!usdc || !usdc.holding)
3332
3259
  return 0;
3333
3260
  if (unsettledPnL >= 0)
@@ -3337,18 +3264,18 @@ var useWithdraw = () => {
3337
3264
  return { withdraw, isLoading, maxAmount, availableBalance, unsettledPnL };
3338
3265
  };
3339
3266
  var useDeposit = (options) => {
3340
- const { onlyTestnet } = React2.useContext(OrderlyContext);
3341
- const [balanceRevalidating, setBalanceRevalidating] = React2.useState(false);
3342
- const [allowanceRevalidating, setAllowanceRevalidating] = React2.useState(false);
3267
+ const { onlyTestnet } = React.useContext(OrderlyContext);
3268
+ const [balanceRevalidating, setBalanceRevalidating] = React.useState(false);
3269
+ const [allowanceRevalidating, setAllowanceRevalidating] = React.useState(false);
3343
3270
  const [_, { findByChainId }] = useChains(void 0, {
3344
3271
  wooSwapEnabled: true
3345
3272
  });
3346
- const [balance, setBalance] = React2.useState("0");
3347
- const [allowance, setAllowance] = React2.useState("0");
3273
+ const [balance, setBalance] = React.useState("0");
3274
+ const [allowance, setAllowance] = React.useState("0");
3348
3275
  const { account: account5, state } = useAccount();
3349
- const prevAddress = React2.useRef();
3350
- const getBalanceListener = React2.useRef();
3351
- const dst = React2.useMemo(() => {
3276
+ const prevAddress = React.useRef();
3277
+ const getBalanceListener = React.useRef();
3278
+ const dst = React.useMemo(() => {
3352
3279
  const chain = onlyTestnet ? findByChainId(types.ARBITRUM_TESTNET_CHAINID) : findByChainId(types.ARBITRUM_MAINNET_CHAINID);
3353
3280
  const USDC = chain?.token_infos.find((token) => token.symbol === "USDC");
3354
3281
  if (!chain) {
@@ -3363,11 +3290,11 @@ var useDeposit = (options) => {
3363
3290
  // chainId: 42161,
3364
3291
  };
3365
3292
  }, []);
3366
- const isNativeToken = React2.useMemo(
3293
+ const isNativeToken = React.useMemo(
3367
3294
  () => isNativeTokenChecker(options?.address || ""),
3368
3295
  [options?.address]
3369
3296
  );
3370
- const fetchBalanceHandler = React2.useCallback(
3297
+ const fetchBalanceHandler = React.useCallback(
3371
3298
  async (address, decimals) => {
3372
3299
  let balance2;
3373
3300
  if (!!address && isNativeTokenChecker(address)) {
@@ -3381,7 +3308,7 @@ var useDeposit = (options) => {
3381
3308
  },
3382
3309
  []
3383
3310
  );
3384
- const fetchBalance = React2.useCallback(
3311
+ const fetchBalance = React.useCallback(
3385
3312
  async (address, decimals) => {
3386
3313
  if (!address)
3387
3314
  return;
@@ -3400,7 +3327,7 @@ var useDeposit = (options) => {
3400
3327
  },
3401
3328
  [state, balanceRevalidating]
3402
3329
  );
3403
- const fetchBalances = React2.useCallback(async (tokens) => {
3330
+ const fetchBalances = React.useCallback(async (tokens) => {
3404
3331
  const tasks = [];
3405
3332
  for (const token of tokens) {
3406
3333
  if (isNativeTokenChecker(token.address)) {
@@ -3435,7 +3362,7 @@ var useDeposit = (options) => {
3435
3362
  const allowance2 = await account5.assetsManager.getAllowance(address);
3436
3363
  setAllowance(() => allowance2);
3437
3364
  };
3438
- const getVaultAddress = React2.useCallback(() => {
3365
+ const getVaultAddress = React.useCallback(() => {
3439
3366
  if (dst.chainId !== options?.srcChainId) {
3440
3367
  return options?.crossChainRouteAddress;
3441
3368
  } else {
@@ -3444,7 +3371,7 @@ var useDeposit = (options) => {
3444
3371
  }
3445
3372
  }
3446
3373
  }, [options, dst]);
3447
- React2.useEffect(() => {
3374
+ React.useEffect(() => {
3448
3375
  if (state.status < types.AccountStatusEnum.Connected)
3449
3376
  return;
3450
3377
  fetchBalance(options?.address, options?.decimals);
@@ -3467,7 +3394,7 @@ var useDeposit = (options) => {
3467
3394
  account5.address,
3468
3395
  dst
3469
3396
  ]);
3470
- const approve = React2.useCallback(
3397
+ const approve = React.useCallback(
3471
3398
  (amount) => {
3472
3399
  if (!options?.address) {
3473
3400
  throw new Error("address is required");
@@ -3482,7 +3409,7 @@ var useDeposit = (options) => {
3482
3409
  },
3483
3410
  [account5, getAllowance, options?.address]
3484
3411
  );
3485
- const deposit = React2.useCallback(
3412
+ const deposit = React.useCallback(
3486
3413
  (amount) => {
3487
3414
  return account5.assetsManager.deposit(amount).then((res) => {
3488
3415
  setAllowance((value) => new utils.Decimal(value).sub(amount).toString());
@@ -3503,7 +3430,7 @@ var useDeposit = (options) => {
3503
3430
  loopGetBalance();
3504
3431
  }, 3e3);
3505
3432
  };
3506
- React2.useEffect(() => {
3433
+ React.useEffect(() => {
3507
3434
  if (!options?.address) {
3508
3435
  return;
3509
3436
  }
@@ -3538,7 +3465,7 @@ var useWalletSubscription = (options) => {
3538
3465
  {
3539
3466
  onMessage: (data) => {
3540
3467
  options?.onMessage?.(data);
3541
- next(data);
3468
+ next(null, data);
3542
3469
  }
3543
3470
  }
3544
3471
  );
@@ -3565,22 +3492,11 @@ var useSettleSubscription = (options) => {
3565
3492
  return () => unsubscribe();
3566
3493
  });
3567
3494
  };
3568
- var useBalance = () => {
3569
- const ws = useWS();
3570
- const { data } = useSWRSubscription__default.default("balance", (_, { next }) => {
3571
- const unsubscribe = ws.privateSubscribe("balance", {
3572
- onMessage: (data2) => {
3573
- }
3574
- });
3575
- return () => unsubscribe();
3576
- });
3577
- return data;
3578
- };
3579
3495
  var usePrivateDataObserver = () => {
3580
3496
  const ws = useWS();
3581
3497
  const { mutate: mutate2 } = useSWR.useSWRConfig();
3582
3498
  const { state } = useAccount();
3583
- React2.useEffect(() => {
3499
+ React.useEffect(() => {
3584
3500
  if (!state.accountId)
3585
3501
  return;
3586
3502
  const key = ["/v1/positions", state.accountId];
@@ -3629,39 +3545,11 @@ var usePrivateDataObserver = () => {
3629
3545
  };
3630
3546
  }, [state.accountId]);
3631
3547
  };
3632
-
3633
- // src/apis/index.ts
3634
- var apis_exports = {};
3635
- __export(apis_exports, {
3636
- useFundingRateBySymbol: () => useFundingRateBySymbol,
3637
- useInfo: () => useInfo,
3638
- useToken: () => useToken
3639
- });
3640
-
3641
- // src/apis/useInfo.ts
3642
- var useInfo = () => {
3643
- return useQuery("/v1/public/info", {
3644
- // refreshInterval: 1000 * 60 * 60 * 24,
3645
- });
3646
- };
3647
-
3648
- // src/apis/useToken.ts
3649
- var useToken = () => {
3650
- return useQuery("/v1/public/token");
3651
- };
3652
-
3653
- // src/apis/useFundingRateBySymbol.ts
3654
- var useFundingRateBySymbol = (symbol) => {
3655
- if (!symbol) {
3656
- throw new Error("symbol is required");
3657
- }
3658
- return useQuery(`/public/funding_rate/${symbol}`);
3659
- };
3660
3548
  var useWooSwapQuery = () => {
3661
- const { configStore } = React2.useContext(OrderlyContext);
3549
+ const { configStore } = React.useContext(OrderlyContext);
3662
3550
  const account5 = useAccountInstance();
3663
3551
  const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
3664
- const query = React2.useCallback(
3552
+ const query = React.useCallback(
3665
3553
  (inputs) => {
3666
3554
  if (loading)
3667
3555
  return;
@@ -3702,17 +3590,17 @@ var useWooSwapQuery = () => {
3702
3590
  };
3703
3591
  };
3704
3592
  var useWooCrossSwapQuery = () => {
3705
- const { configStore } = React2.useContext(OrderlyContext);
3593
+ const { configStore } = React.useContext(OrderlyContext);
3706
3594
  const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
3707
3595
  const account5 = useAccountInstance();
3708
- const dstValutDeposit = React2.useCallback(() => {
3596
+ const dstValutDeposit = React.useCallback(() => {
3709
3597
  return {
3710
3598
  accountId: account5.accountIdHashStr,
3711
3599
  brokerHash: core.utils.parseBrokerHash(configStore.get("brokerId")),
3712
3600
  tokenHash: core.utils.parseTokenHash("USDC")
3713
3601
  };
3714
3602
  }, [account5]);
3715
- const queryDestinationFee = React2.useCallback(
3603
+ const queryDestinationFee = React.useCallback(
3716
3604
  async (crossChainRouteAddress, dst) => {
3717
3605
  if (!account5.walletClient) {
3718
3606
  throw new Error("walletClient is not ready");
@@ -3729,7 +3617,7 @@ var useWooCrossSwapQuery = () => {
3729
3617
  },
3730
3618
  []
3731
3619
  );
3732
- const query = React2.useCallback(
3620
+ const query = React.useCallback(
3733
3621
  (inputs) => {
3734
3622
  if (loading)
3735
3623
  return;
@@ -3790,20 +3678,21 @@ var useWooCrossSwapQuery = () => {
3790
3678
  };
3791
3679
  var useCrossSwap = () => {
3792
3680
  const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
3793
- const [layerStatus, setLayerStatus] = React2.useState(
3681
+ const [layerStatus, setLayerStatus] = React.useState(
3794
3682
  "WAITTING" /* INITIALIZING */
3795
3683
  );
3796
3684
  const ee = useEventEmitter();
3797
- const [bridgeMessage, setBridgeMessage] = React2.useState();
3798
- const [status, setStatus] = React2.useState(
3685
+ const [bridgeMessage, setBridgeMessage] = React.useState();
3686
+ const [status, setStatus] = React.useState(
3799
3687
  types.WS_WalletStatusEnum.NO
3800
3688
  );
3801
- const txHashFromBridge = React2.useRef();
3689
+ const txHashFromBridge = React.useRef();
3802
3690
  const account5 = useAccountInstance();
3803
- const { networkId, configStore } = React2.useContext(OrderlyContext);
3804
- const client = React2.useRef(scanClient.createClient(networkId)).current;
3805
- const timer = React2.useRef();
3806
- React2.useEffect(() => {
3691
+ const { configStore } = React.useContext(OrderlyContext);
3692
+ const networkId = useConfig("networkId");
3693
+ const client = React.useRef(scanClient.createClient(networkId)).current;
3694
+ const timer = React.useRef();
3695
+ React.useEffect(() => {
3807
3696
  const handler = (data) => {
3808
3697
  const { side, transStatus, trxId } = data;
3809
3698
  if (side === "DEPOSIT" && trxId === txHashFromBridge.current) {
@@ -3815,7 +3704,7 @@ var useCrossSwap = () => {
3815
3704
  ee.off("wallet:changed", handler);
3816
3705
  };
3817
3706
  }, [txHashFromBridge.current]);
3818
- const checkLayerStatus = React2.useCallback((txHash) => {
3707
+ const checkLayerStatus = React.useCallback((txHash) => {
3819
3708
  const check = async (txHash2) => {
3820
3709
  try {
3821
3710
  const { messages } = await client.getMessagesBySrcTxHash(txHash2);
@@ -3847,14 +3736,14 @@ var useCrossSwap = () => {
3847
3736
  };
3848
3737
  check(txHash);
3849
3738
  }, []);
3850
- React2.useEffect(() => {
3739
+ React.useEffect(() => {
3851
3740
  return () => {
3852
3741
  if (timer.current) {
3853
3742
  clearTimeout(timer.current);
3854
3743
  }
3855
3744
  };
3856
3745
  }, []);
3857
- const dstValutDeposit = React2.useCallback(() => {
3746
+ const dstValutDeposit = React.useCallback(() => {
3858
3747
  return {
3859
3748
  accountId: account5.accountIdHashStr,
3860
3749
  brokerHash: core.utils.parseBrokerHash(configStore.get("brokerId")),
@@ -4190,13 +4079,13 @@ var woofiDexDepositorAbi = [
4190
4079
  var useSwap = () => {
4191
4080
  const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
4192
4081
  const account5 = useAccountInstance();
4193
- const { configStore } = React2.useContext(OrderlyContext);
4194
- const [status, setStatus] = React2.useState(
4082
+ const { configStore } = React.useContext(OrderlyContext);
4083
+ const [status, setStatus] = React.useState(
4195
4084
  types.WS_WalletStatusEnum.NO
4196
4085
  );
4197
- const txHash = React2.useRef();
4086
+ const txHash = React.useRef();
4198
4087
  const ee = useEventEmitter();
4199
- React2.useEffect(() => {
4088
+ React.useEffect(() => {
4200
4089
  const handler = (data) => {
4201
4090
  const { side, transStatus, trxId } = data;
4202
4091
  if (side === "DEPOSIT" && trxId === txHash.current) {
@@ -4208,7 +4097,7 @@ var useSwap = () => {
4208
4097
  ee.off("wallet:changed", handler);
4209
4098
  };
4210
4099
  }, [txHash.current]);
4211
- const dstValutDeposit = React2.useCallback(() => {
4100
+ const dstValutDeposit = React.useCallback(() => {
4212
4101
  const brokerId = configStore.get("brokerId");
4213
4102
  return {
4214
4103
  accountId: account5.accountIdHashStr,
@@ -4216,7 +4105,7 @@ var useSwap = () => {
4216
4105
  tokenHash: core.utils.parseTokenHash("USDC")
4217
4106
  };
4218
4107
  }, [account5]);
4219
- const swap = React2.useCallback(
4108
+ const swap = React.useCallback(
4220
4109
  async (woofiDexDepositorAdress, inputs, config) => {
4221
4110
  if (!account5.walletClient) {
4222
4111
  throw new Error("walletClient is undefined");
@@ -4268,17 +4157,14 @@ Object.defineProperty(exports, 'useSWR', {
4268
4157
  });
4269
4158
  Object.defineProperty(exports, 'useConstant', {
4270
4159
  enumerable: true,
4271
- get: function () { return useConstant__default.default; }
4160
+ get: function () { return useConstant4__default.default; }
4272
4161
  });
4273
- exports.DataSourceProvider = DataSourceProvider;
4162
+ exports.OrderlyConfigProvider = OrderlyConfigProvider;
4274
4163
  exports.OrderlyContext = OrderlyContext;
4275
4164
  exports.OrderlyProvider = OrderlyProvider;
4276
- exports.apis = apis_exports;
4277
4165
  exports.useAccount = useAccount;
4278
4166
  exports.useAccountInfo = useAccountInfo;
4279
4167
  exports.useAccountInstance = useAccountInstance;
4280
- exports.useAppState = useAppState;
4281
- exports.useBalance = useBalance;
4282
4168
  exports.useBoolean = useBoolean;
4283
4169
  exports.useChain = useChain;
4284
4170
  exports.useChains = useChains;
@@ -4287,7 +4173,6 @@ exports.useConfig = useConfig;
4287
4173
  exports.useCrossSwap = useCrossSwap;
4288
4174
  exports.useDeposit = useDeposit;
4289
4175
  exports.useEventEmitter = useEventEmitter;
4290
- exports.useFetures = useFetures;
4291
4176
  exports.useFundingRate = useFundingRate;
4292
4177
  exports.useHoldingStream = useHoldingStream;
4293
4178
  exports.useIndexPrice = useIndexPrice;
@@ -4301,7 +4186,6 @@ exports.useMarketTradeStream = useMarketTradeStream;
4301
4186
  exports.useMarketsStream = useMarketsStream;
4302
4187
  exports.useMaxQty = useMaxQty;
4303
4188
  exports.useMutation = useMutation;
4304
- exports.useOpenInterest = useOpenInterest;
4305
4189
  exports.useOrderEntry = useOrderEntry;
4306
4190
  exports.useOrderStream = useOrderStream;
4307
4191
  exports.useOrderbookStream = useOrderbookStream;
@@ -4310,15 +4194,11 @@ exports.usePreLoadData = usePreLoadData;
4310
4194
  exports.usePrivateDataObserver = usePrivateDataObserver;
4311
4195
  exports.usePrivateQuery = usePrivateQuery;
4312
4196
  exports.useQuery = useQuery;
4313
- exports.useRunOnce = useRunOnce;
4314
4197
  exports.useSessionStorage = useSessionStorage;
4315
4198
  exports.useSettleSubscription = useSettleSubscription;
4316
4199
  exports.useSwap = useSwap;
4317
4200
  exports.useSymbolsInfo = useSymbolsInfo;
4318
4201
  exports.useTickerStream = useTickerStream;
4319
- exports.useTokenInfo = useTokenInfo;
4320
- exports.useTopicObserve = useTopicObserve;
4321
- exports.useTradingView = useTradingView;
4322
4202
  exports.useWS = useWS;
4323
4203
  exports.useWalletSubscription = useWalletSubscription;
4324
4204
  exports.useWithdraw = useWithdraw;