@pear-protocol/symmio-client 0.2.9 → 0.2.11
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/react/index.d.mts +13 -11
- package/dist/react/index.d.ts +13 -11
- package/dist/react/index.js +189 -150
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +190 -151
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/provider.js +0 -139
- package/dist/react/provider.js.map +1 -1
- package/dist/react/provider.mjs +1 -140
- package/dist/react/provider.mjs.map +1 -1
- package/package.json +3 -3
package/dist/react/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { createContext, useContext,
|
|
2
|
+
import { createContext, useContext, useMemo, useRef, useCallback, useEffect } from 'react';
|
|
3
3
|
import { createSymmSDK, isAuthExpiredError, isNetworkError, isInsufficientMarginError, isRateLimitedError, isTimeoutError } from '@pear-protocol/symm-core';
|
|
4
|
-
import { useQueryClient, useQuery, useMutation } from '@tanstack/react-query';
|
|
5
|
-
import { create } from 'zustand';
|
|
6
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
import { create } from 'zustand';
|
|
6
|
+
import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
7
7
|
import { isAddress, encodeFunctionData } from 'viem';
|
|
8
8
|
|
|
9
9
|
var SymmContext = createContext(null);
|
|
@@ -14,142 +14,6 @@ function useSymmContext() {
|
|
|
14
14
|
}
|
|
15
15
|
return ctx;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
// src/react/query-keys.ts
|
|
19
|
-
var symmKeys = {
|
|
20
|
-
all: ["symm"],
|
|
21
|
-
accounts: (address, chainId) => ["symm", "accounts", address, chainId],
|
|
22
|
-
accountsApi: (address, chainId) => ["symm", "accountsApi", address, chainId],
|
|
23
|
-
accountsLength: (address, chainId) => ["symm", "accountsLength", address, chainId],
|
|
24
|
-
accountsWithPositions: (address, chainId) => ["symm", "accountsWithPositions", address, chainId],
|
|
25
|
-
accountSummary: (address, chainId) => ["symm", "accountSummary", address, chainId],
|
|
26
|
-
accountData: (address, chainId, upnl) => ["symm", "accountData", address, chainId, upnl],
|
|
27
|
-
signature: (address, chainId) => ["symm", "signature", address, chainId],
|
|
28
|
-
approval: (owner, spender, chainId, token) => ["symm", "approval", owner, spender, chainId, token],
|
|
29
|
-
balances: (address, chainId) => ["symm", "balances", address, chainId],
|
|
30
|
-
positions: (params) => ["symm", "positions", params],
|
|
31
|
-
openOrders: (params) => ["symm", "openOrders", params],
|
|
32
|
-
tradeHistory: (params) => ["symm", "tradeHistory", params],
|
|
33
|
-
tpslOrders: (address, chainId) => ["symm", "tpslOrders", address, chainId],
|
|
34
|
-
tpslOrdersList: (params) => ["symm", "tpslOrders", params],
|
|
35
|
-
twapOrders: (address, chainId) => ["symm", "twapOrders", address, chainId],
|
|
36
|
-
triggerOrders: (params) => ["symm", "triggerOrders", params],
|
|
37
|
-
triggerConfig: (orderId) => ["symm", "triggerConfig", orderId],
|
|
38
|
-
markets: (chainId, search) => ["symm", "markets", chainId, search],
|
|
39
|
-
hedgerMarketById: (id, chainId) => ["symm", "hedgerMarketById", id, chainId],
|
|
40
|
-
hedgerMarketBySymbol: (symbol, chainId) => ["symm", "hedgerMarketBySymbol", symbol, chainId],
|
|
41
|
-
lockedParams: (marketName, leverage, chainId) => ["symm", "lockedParams", marketName, leverage, chainId],
|
|
42
|
-
hedgerMarkets: (request) => ["symm", "hedgerMarkets", request],
|
|
43
|
-
fundingRates: (chainId) => ["symm", "fundingRates", chainId],
|
|
44
|
-
fundingPayments: (params) => ["symm", "fundingPayments", params],
|
|
45
|
-
fundingHistory: (params) => ["symm", "fundingHistory", params],
|
|
46
|
-
portfolio: (params) => ["symm", "portfolio", params],
|
|
47
|
-
notifications: (address, chainId) => ["symm", "notifications", address, chainId],
|
|
48
|
-
unreadCount: (address, chainId) => ["symm", "unreadCount", address, chainId],
|
|
49
|
-
availableMargin: (address, chainId) => ["symm", "availableMargin", address, chainId],
|
|
50
|
-
pendingIds: (address, chainId) => ["symm", "pendingIds", address, chainId],
|
|
51
|
-
pendingInstantOpens: (accountAddress, chainId) => ["symm", "pendingInstantOpens", accountAddress, chainId],
|
|
52
|
-
twapOrder: (orderId) => ["symm", "twapOrder", orderId],
|
|
53
|
-
delegation: (account, target, selectors, chainId) => ["symm", "delegation", account, target, selectors, chainId],
|
|
54
|
-
chartMetadata: (symbolsKey, positionKey) => ["symm", "chartMetadata", symbolsKey, positionKey]
|
|
55
|
-
};
|
|
56
|
-
var useSymmWsStore = create((set) => ({
|
|
57
|
-
isConnected: false,
|
|
58
|
-
setConnected: (isConnected) => set({ isConnected })
|
|
59
|
-
}));
|
|
60
|
-
|
|
61
|
-
// src/react/hooks/use-symm-ws.ts
|
|
62
|
-
function asUnsubscribeFn(value) {
|
|
63
|
-
return typeof value === "function" ? value : null;
|
|
64
|
-
}
|
|
65
|
-
function useSymmWs(params) {
|
|
66
|
-
const queryClient = useQueryClient();
|
|
67
|
-
const isConnected = useSymmWsStore((state) => state.isConnected);
|
|
68
|
-
const setConnected = useSymmWsStore((state) => state.setConnected);
|
|
69
|
-
const { symmCoreClient, accountAddress, chainId } = params;
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (!symmCoreClient || !accountAddress) {
|
|
72
|
-
setConnected(false);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const ws = symmCoreClient.ws;
|
|
76
|
-
const addr = accountAddress;
|
|
77
|
-
const unsubscribers = [];
|
|
78
|
-
const removeOnConnect = ws.onConnect(() => setConnected(true));
|
|
79
|
-
const removeOnDisconnect = ws.onDisconnect(() => setConnected(false));
|
|
80
|
-
unsubscribers.push(removeOnConnect, removeOnDisconnect);
|
|
81
|
-
const positionsUnsub = asUnsubscribeFn(ws.subscribeToPositions(addr, chainId, () => {
|
|
82
|
-
queryClient.invalidateQueries({
|
|
83
|
-
queryKey: ["symm", "positions"]
|
|
84
|
-
});
|
|
85
|
-
}));
|
|
86
|
-
if (positionsUnsub) unsubscribers.push(positionsUnsub);
|
|
87
|
-
const openOrdersUnsub = asUnsubscribeFn(ws.subscribeToOpenOrders(addr, chainId, () => {
|
|
88
|
-
queryClient.invalidateQueries({
|
|
89
|
-
queryKey: ["symm", "openOrders"]
|
|
90
|
-
});
|
|
91
|
-
}));
|
|
92
|
-
if (openOrdersUnsub) unsubscribers.push(openOrdersUnsub);
|
|
93
|
-
const tradesUnsub = asUnsubscribeFn(ws.subscribeToTrades(addr, chainId, () => {
|
|
94
|
-
queryClient.invalidateQueries({
|
|
95
|
-
queryKey: ["symm", "tradeHistory"]
|
|
96
|
-
});
|
|
97
|
-
}));
|
|
98
|
-
if (tradesUnsub) unsubscribers.push(tradesUnsub);
|
|
99
|
-
const accountSummaryUnsub = asUnsubscribeFn(ws.subscribeToAccountSummary(addr, chainId, () => {
|
|
100
|
-
queryClient.invalidateQueries({
|
|
101
|
-
queryKey: symmKeys.balances(accountAddress, chainId)
|
|
102
|
-
});
|
|
103
|
-
queryClient.invalidateQueries({
|
|
104
|
-
queryKey: symmKeys.accountSummary(accountAddress, chainId)
|
|
105
|
-
});
|
|
106
|
-
}));
|
|
107
|
-
if (accountSummaryUnsub) unsubscribers.push(accountSummaryUnsub);
|
|
108
|
-
const notificationsUnsub = asUnsubscribeFn(ws.subscribeToNotifications(addr, chainId, () => {
|
|
109
|
-
queryClient.invalidateQueries({
|
|
110
|
-
queryKey: symmKeys.notifications(accountAddress, chainId)
|
|
111
|
-
});
|
|
112
|
-
queryClient.invalidateQueries({
|
|
113
|
-
queryKey: symmKeys.unreadCount(accountAddress, chainId)
|
|
114
|
-
});
|
|
115
|
-
}));
|
|
116
|
-
if (notificationsUnsub) unsubscribers.push(notificationsUnsub);
|
|
117
|
-
const tpslUnsub = asUnsubscribeFn(ws.subscribeToTpsl(addr, chainId, () => {
|
|
118
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "tpslOrders"] });
|
|
119
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
120
|
-
}));
|
|
121
|
-
if (tpslUnsub) unsubscribers.push(tpslUnsub);
|
|
122
|
-
const twapUnsub = asUnsubscribeFn(ws.subscribeToTwapOrders(addr, chainId, () => {
|
|
123
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "twapOrders"] });
|
|
124
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
125
|
-
}));
|
|
126
|
-
if (twapUnsub) unsubscribers.push(twapUnsub);
|
|
127
|
-
const triggerOrdersUnsub = asUnsubscribeFn(ws.subscribeToTriggerOrders(addr, chainId, () => {
|
|
128
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "triggerOrders"] });
|
|
129
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
130
|
-
}));
|
|
131
|
-
if (triggerOrdersUnsub) unsubscribers.push(triggerOrdersUnsub);
|
|
132
|
-
const executionsUnsub = asUnsubscribeFn(ws.subscribeToExecutions(addr, chainId, () => {
|
|
133
|
-
queryClient.invalidateQueries({
|
|
134
|
-
queryKey: ["symm", "positions"]
|
|
135
|
-
});
|
|
136
|
-
queryClient.invalidateQueries({
|
|
137
|
-
queryKey: ["symm", "portfolio"]
|
|
138
|
-
});
|
|
139
|
-
}));
|
|
140
|
-
if (executionsUnsub) unsubscribers.push(executionsUnsub);
|
|
141
|
-
return () => {
|
|
142
|
-
if (unsubscribers.length > 2) {
|
|
143
|
-
unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
144
|
-
} else {
|
|
145
|
-
removeOnConnect();
|
|
146
|
-
removeOnDisconnect();
|
|
147
|
-
ws.unsubscribeAll();
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
}, [symmCoreClient, accountAddress, chainId, queryClient, setConnected]);
|
|
151
|
-
return { isConnected };
|
|
152
|
-
}
|
|
153
17
|
function SymmProvider({
|
|
154
18
|
chainId = 42161,
|
|
155
19
|
address,
|
|
@@ -164,7 +28,6 @@ function SymmProvider({
|
|
|
164
28
|
defaultChainId: chainId
|
|
165
29
|
});
|
|
166
30
|
}, [chainId, symmCoreConfig.apiUrl, symmCoreConfig.wsUrl]);
|
|
167
|
-
useSymmWs({ symmCoreClient, accountAddress: address, chainId });
|
|
168
31
|
const value = useMemo(
|
|
169
32
|
() => ({
|
|
170
33
|
symmCoreClient,
|
|
@@ -393,10 +256,17 @@ var useSymmAuthStore = create((set, get) => ({
|
|
|
393
256
|
|
|
394
257
|
// src/react/hooks/use-symm-auth.ts
|
|
395
258
|
function useSymmAuth(params) {
|
|
396
|
-
const
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
259
|
+
const ctx = useSymmContext();
|
|
260
|
+
const address = params?.address ?? ctx.address;
|
|
261
|
+
const chainId = params?.chainId ?? ctx.chainId ?? 42161;
|
|
262
|
+
const walletClient = params?.walletClient ?? ctx.walletClient;
|
|
263
|
+
const siweDomain = params?.siweDomain;
|
|
264
|
+
const accessToken = useSymmAuthStore((state) => {
|
|
265
|
+
if (address) {
|
|
266
|
+
return state.tokensByKey[symmAuthTokenKey(address, chainId)] ?? null;
|
|
267
|
+
}
|
|
268
|
+
return ctx.accessToken ?? ctx.authToken ?? null;
|
|
269
|
+
});
|
|
400
270
|
const setToken = useSymmAuthStore((state) => state.setToken);
|
|
401
271
|
const getToken = useSymmAuthStore((state) => state.getToken);
|
|
402
272
|
const clearToken = useSymmAuthStore((state) => state.clearToken);
|
|
@@ -977,6 +847,45 @@ async function hasDelegatedAccess(publicClient, multiAccount, params) {
|
|
|
977
847
|
return Boolean(result);
|
|
978
848
|
}
|
|
979
849
|
|
|
850
|
+
// src/react/query-keys.ts
|
|
851
|
+
var symmKeys = {
|
|
852
|
+
all: ["symm"],
|
|
853
|
+
accounts: (address, chainId) => ["symm", "accounts", address, chainId],
|
|
854
|
+
accountsApi: (address, chainId) => ["symm", "accountsApi", address, chainId],
|
|
855
|
+
accountsLength: (address, chainId) => ["symm", "accountsLength", address, chainId],
|
|
856
|
+
accountsWithPositions: (address, chainId) => ["symm", "accountsWithPositions", address, chainId],
|
|
857
|
+
accountSummary: (address, chainId) => ["symm", "accountSummary", address, chainId],
|
|
858
|
+
accountData: (address, chainId, upnl) => ["symm", "accountData", address, chainId, upnl],
|
|
859
|
+
signature: (address, chainId) => ["symm", "signature", address, chainId],
|
|
860
|
+
approval: (owner, spender, chainId, token) => ["symm", "approval", owner, spender, chainId, token],
|
|
861
|
+
balances: (address, chainId) => ["symm", "balances", address, chainId],
|
|
862
|
+
positions: (params) => ["symm", "positions", params],
|
|
863
|
+
openOrders: (params) => ["symm", "openOrders", params],
|
|
864
|
+
tradeHistory: (params) => ["symm", "tradeHistory", params],
|
|
865
|
+
tpslOrders: (address, chainId) => ["symm", "tpslOrders", address, chainId],
|
|
866
|
+
tpslOrdersList: (params) => ["symm", "tpslOrders", params],
|
|
867
|
+
twapOrders: (address, chainId) => ["symm", "twapOrders", address, chainId],
|
|
868
|
+
triggerOrders: (params) => ["symm", "triggerOrders", params],
|
|
869
|
+
triggerConfig: (orderId) => ["symm", "triggerConfig", orderId],
|
|
870
|
+
markets: (chainId, search) => ["symm", "markets", chainId, search],
|
|
871
|
+
hedgerMarketById: (id, chainId) => ["symm", "hedgerMarketById", id, chainId],
|
|
872
|
+
hedgerMarketBySymbol: (symbol, chainId) => ["symm", "hedgerMarketBySymbol", symbol, chainId],
|
|
873
|
+
lockedParams: (marketName, leverage, chainId) => ["symm", "lockedParams", marketName, leverage, chainId],
|
|
874
|
+
hedgerMarkets: (request) => ["symm", "hedgerMarkets", request],
|
|
875
|
+
fundingRates: (chainId) => ["symm", "fundingRates", chainId],
|
|
876
|
+
fundingPayments: (params) => ["symm", "fundingPayments", params],
|
|
877
|
+
fundingHistory: (params) => ["symm", "fundingHistory", params],
|
|
878
|
+
portfolio: (params) => ["symm", "portfolio", params],
|
|
879
|
+
notifications: (address, chainId) => ["symm", "notifications", address, chainId],
|
|
880
|
+
unreadCount: (address, chainId) => ["symm", "unreadCount", address, chainId],
|
|
881
|
+
availableMargin: (address, chainId) => ["symm", "availableMargin", address, chainId],
|
|
882
|
+
pendingIds: (address, chainId) => ["symm", "pendingIds", address, chainId],
|
|
883
|
+
pendingInstantOpens: (accountAddress, chainId) => ["symm", "pendingInstantOpens", accountAddress, chainId],
|
|
884
|
+
twapOrder: (orderId) => ["symm", "twapOrder", orderId],
|
|
885
|
+
delegation: (account, target, selectors, chainId) => ["symm", "delegation", account, target, selectors, chainId],
|
|
886
|
+
chartMetadata: (symbolsKey, positionKey) => ["symm", "chartMetadata", symbolsKey, positionKey]
|
|
887
|
+
};
|
|
888
|
+
|
|
980
889
|
// src/react/hooks/use-symm-delegation.ts
|
|
981
890
|
function useSymmDelegation(params) {
|
|
982
891
|
const { chainId, address, symmioConfig } = useSymmContext();
|
|
@@ -1187,7 +1096,7 @@ async function getAccounts(publicClient, multiAccount, user, start = 0, size = 1
|
|
|
1187
1096
|
|
|
1188
1097
|
// src/react/hooks/use-symm-accounts.ts
|
|
1189
1098
|
var EMPTY_ACCOUNTS = [];
|
|
1190
|
-
function useSymmAccounts(params, options) {
|
|
1099
|
+
function useSymmAccounts(params = {}, options) {
|
|
1191
1100
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1192
1101
|
const { userAddress, publicClient, walletClient } = params;
|
|
1193
1102
|
const queryClient = useQueryClient();
|
|
@@ -1562,7 +1471,7 @@ async function depositAndAllocate(walletClient, publicClient, multiAccount, para
|
|
|
1562
1471
|
}
|
|
1563
1472
|
|
|
1564
1473
|
// src/react/hooks/use-symm-deposit.ts
|
|
1565
|
-
function useSymmDeposit(params) {
|
|
1474
|
+
function useSymmDeposit(params = {}) {
|
|
1566
1475
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1567
1476
|
const { publicClient, walletClient } = params;
|
|
1568
1477
|
const queryClient = useQueryClient();
|
|
@@ -1622,7 +1531,7 @@ async function withdraw(walletClient, publicClient, multiAccount, params) {
|
|
|
1622
1531
|
}
|
|
1623
1532
|
|
|
1624
1533
|
// src/react/hooks/use-symm-withdraw.ts
|
|
1625
|
-
function useSymmWithdraw(params) {
|
|
1534
|
+
function useSymmWithdraw(params = {}) {
|
|
1626
1535
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1627
1536
|
const { publicClient, walletClient } = params;
|
|
1628
1537
|
const queryClient = useQueryClient();
|
|
@@ -24290,7 +24199,7 @@ var MuonClient = class {
|
|
|
24290
24199
|
};
|
|
24291
24200
|
|
|
24292
24201
|
// src/react/hooks/use-symm-collateral.ts
|
|
24293
|
-
function useSymmCollateral(params) {
|
|
24202
|
+
function useSymmCollateral(params = {}) {
|
|
24294
24203
|
const { chainId, symmioConfig } = useSymmContext();
|
|
24295
24204
|
const { publicClient, walletClient } = params;
|
|
24296
24205
|
const queryClient = useQueryClient();
|
|
@@ -24443,7 +24352,7 @@ async function hasSignedCurrentVersion(publicClient, signatureStore, user) {
|
|
|
24443
24352
|
}
|
|
24444
24353
|
|
|
24445
24354
|
// src/react/hooks/use-symm-signature.ts
|
|
24446
|
-
function useSymmSignature(params, options) {
|
|
24355
|
+
function useSymmSignature(params = {}, options) {
|
|
24447
24356
|
const { chainId, symmioConfig } = useSymmContext();
|
|
24448
24357
|
const { userAddress, publicClient, walletClient } = params;
|
|
24449
24358
|
const queryClient = useQueryClient();
|
|
@@ -24676,6 +24585,13 @@ function useSymmPositions(params) {
|
|
|
24676
24585
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
24677
24586
|
const chainId = params.chainId ?? ctxChainId;
|
|
24678
24587
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
24588
|
+
console.log({
|
|
24589
|
+
symmCoreClient,
|
|
24590
|
+
accountAddress,
|
|
24591
|
+
resolvedAddress,
|
|
24592
|
+
chainId,
|
|
24593
|
+
internalEnabled
|
|
24594
|
+
});
|
|
24679
24595
|
const query = useQuery({
|
|
24680
24596
|
...params.query,
|
|
24681
24597
|
queryKey: symmKeys.positions({
|
|
@@ -24930,10 +24846,11 @@ function useSymmMarkets(params) {
|
|
|
24930
24846
|
...params?.query,
|
|
24931
24847
|
queryKey: symmKeys.markets(chainId, searchText),
|
|
24932
24848
|
queryFn: () => {
|
|
24849
|
+
const marketsApi = symmCoreClient.markets;
|
|
24933
24850
|
if (searchText) {
|
|
24934
|
-
return
|
|
24851
|
+
return marketsApi.search(searchText, chainId);
|
|
24935
24852
|
}
|
|
24936
|
-
return
|
|
24853
|
+
return marketsApi.list({ pageSize: "500", chainId });
|
|
24937
24854
|
},
|
|
24938
24855
|
enabled: internalEnabled && (params?.query?.enabled ?? true)
|
|
24939
24856
|
});
|
|
@@ -25266,6 +25183,128 @@ function useSymmTwapOrder(params) {
|
|
|
25266
25183
|
refetch: query.refetch
|
|
25267
25184
|
};
|
|
25268
25185
|
}
|
|
25186
|
+
var useSymmWsStore = create((set) => ({
|
|
25187
|
+
isConnected: false,
|
|
25188
|
+
setConnected: (isConnected) => set({ isConnected })
|
|
25189
|
+
}));
|
|
25190
|
+
|
|
25191
|
+
// src/react/hooks/use-symm-ws.ts
|
|
25192
|
+
function asUnsubscribeFn(value) {
|
|
25193
|
+
return typeof value === "function" ? value : null;
|
|
25194
|
+
}
|
|
25195
|
+
function useSymmWs(params = {}) {
|
|
25196
|
+
const {
|
|
25197
|
+
symmCoreClient: ctxClient,
|
|
25198
|
+
address: ctxAddress,
|
|
25199
|
+
chainId: ctxChainId
|
|
25200
|
+
} = useSymmContext();
|
|
25201
|
+
const queryClient = useQueryClient();
|
|
25202
|
+
const isConnected = useSymmWsStore((state) => state.isConnected);
|
|
25203
|
+
const setConnected = useSymmWsStore((state) => state.setConnected);
|
|
25204
|
+
const symmCoreClient = params.symmCoreClient ?? ctxClient;
|
|
25205
|
+
const accountAddress = params.accountAddress ?? ctxAddress;
|
|
25206
|
+
const chainId = params.chainId ?? ctxChainId;
|
|
25207
|
+
useEffect(() => {
|
|
25208
|
+
if (!symmCoreClient || !accountAddress) {
|
|
25209
|
+
setConnected(false);
|
|
25210
|
+
return;
|
|
25211
|
+
}
|
|
25212
|
+
const ws = symmCoreClient.ws;
|
|
25213
|
+
const addr = accountAddress;
|
|
25214
|
+
const unsubscribers = [];
|
|
25215
|
+
const removeOnConnect = ws.onConnect(() => setConnected(true));
|
|
25216
|
+
const removeOnDisconnect = ws.onDisconnect(() => setConnected(false));
|
|
25217
|
+
unsubscribers.push(removeOnConnect, removeOnDisconnect);
|
|
25218
|
+
const positionsUnsub = asUnsubscribeFn(
|
|
25219
|
+
ws.subscribeToPositions(addr, chainId, () => {
|
|
25220
|
+
queryClient.invalidateQueries({
|
|
25221
|
+
queryKey: ["symm", "positions"]
|
|
25222
|
+
});
|
|
25223
|
+
})
|
|
25224
|
+
);
|
|
25225
|
+
if (positionsUnsub) unsubscribers.push(positionsUnsub);
|
|
25226
|
+
const openOrdersUnsub = asUnsubscribeFn(
|
|
25227
|
+
ws.subscribeToOpenOrders(addr, chainId, () => {
|
|
25228
|
+
queryClient.invalidateQueries({
|
|
25229
|
+
queryKey: ["symm", "openOrders"]
|
|
25230
|
+
});
|
|
25231
|
+
})
|
|
25232
|
+
);
|
|
25233
|
+
if (openOrdersUnsub) unsubscribers.push(openOrdersUnsub);
|
|
25234
|
+
const tradesUnsub = asUnsubscribeFn(
|
|
25235
|
+
ws.subscribeToTrades(addr, chainId, () => {
|
|
25236
|
+
queryClient.invalidateQueries({
|
|
25237
|
+
queryKey: ["symm", "tradeHistory"]
|
|
25238
|
+
});
|
|
25239
|
+
})
|
|
25240
|
+
);
|
|
25241
|
+
if (tradesUnsub) unsubscribers.push(tradesUnsub);
|
|
25242
|
+
const accountSummaryUnsub = asUnsubscribeFn(
|
|
25243
|
+
ws.subscribeToAccountSummary(addr, chainId, () => {
|
|
25244
|
+
queryClient.invalidateQueries({
|
|
25245
|
+
queryKey: symmKeys.balances(accountAddress, chainId)
|
|
25246
|
+
});
|
|
25247
|
+
queryClient.invalidateQueries({
|
|
25248
|
+
queryKey: symmKeys.accountSummary(accountAddress, chainId)
|
|
25249
|
+
});
|
|
25250
|
+
})
|
|
25251
|
+
);
|
|
25252
|
+
if (accountSummaryUnsub) unsubscribers.push(accountSummaryUnsub);
|
|
25253
|
+
const notificationsUnsub = asUnsubscribeFn(
|
|
25254
|
+
ws.subscribeToNotifications(addr, chainId, () => {
|
|
25255
|
+
queryClient.invalidateQueries({
|
|
25256
|
+
queryKey: symmKeys.notifications(accountAddress, chainId)
|
|
25257
|
+
});
|
|
25258
|
+
queryClient.invalidateQueries({
|
|
25259
|
+
queryKey: symmKeys.unreadCount(accountAddress, chainId)
|
|
25260
|
+
});
|
|
25261
|
+
})
|
|
25262
|
+
);
|
|
25263
|
+
if (notificationsUnsub) unsubscribers.push(notificationsUnsub);
|
|
25264
|
+
const tpslUnsub = asUnsubscribeFn(
|
|
25265
|
+
ws.subscribeToTpsl(addr, chainId, () => {
|
|
25266
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "tpslOrders"] });
|
|
25267
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
25268
|
+
})
|
|
25269
|
+
);
|
|
25270
|
+
if (tpslUnsub) unsubscribers.push(tpslUnsub);
|
|
25271
|
+
const twapUnsub = asUnsubscribeFn(
|
|
25272
|
+
ws.subscribeToTwapOrders(addr, chainId, () => {
|
|
25273
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "twapOrders"] });
|
|
25274
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
25275
|
+
})
|
|
25276
|
+
);
|
|
25277
|
+
if (twapUnsub) unsubscribers.push(twapUnsub);
|
|
25278
|
+
const triggerOrdersUnsub = asUnsubscribeFn(
|
|
25279
|
+
ws.subscribeToTriggerOrders(addr, chainId, () => {
|
|
25280
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "triggerOrders"] });
|
|
25281
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
25282
|
+
})
|
|
25283
|
+
);
|
|
25284
|
+
if (triggerOrdersUnsub) unsubscribers.push(triggerOrdersUnsub);
|
|
25285
|
+
const executionsUnsub = asUnsubscribeFn(
|
|
25286
|
+
ws.subscribeToExecutions(addr, chainId, () => {
|
|
25287
|
+
queryClient.invalidateQueries({
|
|
25288
|
+
queryKey: ["symm", "positions"]
|
|
25289
|
+
});
|
|
25290
|
+
queryClient.invalidateQueries({
|
|
25291
|
+
queryKey: ["symm", "portfolio"]
|
|
25292
|
+
});
|
|
25293
|
+
})
|
|
25294
|
+
);
|
|
25295
|
+
if (executionsUnsub) unsubscribers.push(executionsUnsub);
|
|
25296
|
+
return () => {
|
|
25297
|
+
if (unsubscribers.length > 2) {
|
|
25298
|
+
unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
25299
|
+
} else {
|
|
25300
|
+
removeOnConnect();
|
|
25301
|
+
removeOnDisconnect();
|
|
25302
|
+
ws.unsubscribeAll();
|
|
25303
|
+
}
|
|
25304
|
+
};
|
|
25305
|
+
}, [symmCoreClient, accountAddress, chainId, queryClient, setConnected]);
|
|
25306
|
+
return { isConnected };
|
|
25307
|
+
}
|
|
25269
25308
|
var STABLE_SYMBOLS = /* @__PURE__ */ new Set(["USDC", "USD", "USDT", "USDE", "USDH", "USDT0"]);
|
|
25270
25309
|
function useSymmChartSelection(input) {
|
|
25271
25310
|
const {
|