@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.d.mts
CHANGED
|
@@ -26,7 +26,7 @@ type UseSymmAuthParams = {
|
|
|
26
26
|
walletClient?: WalletClient;
|
|
27
27
|
siweDomain?: string;
|
|
28
28
|
};
|
|
29
|
-
declare function useSymmAuth(params
|
|
29
|
+
declare function useSymmAuth(params?: UseSymmAuthParams): {
|
|
30
30
|
accessToken: string | null;
|
|
31
31
|
authToken: string | null;
|
|
32
32
|
isAuthenticated: boolean;
|
|
@@ -120,7 +120,7 @@ type Account = {
|
|
|
120
120
|
name: string;
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
-
declare function useSymmAccounts(params
|
|
123
|
+
declare function useSymmAccounts(params?: {
|
|
124
124
|
userAddress?: Address;
|
|
125
125
|
publicClient?: PublicClient;
|
|
126
126
|
walletClient?: WalletClient;
|
|
@@ -210,7 +210,7 @@ declare function useSymmCloseOrder(): {
|
|
|
210
210
|
closeOrder: _tanstack_react_query.UseMutationResult<_pear_protocol_symm_core.CloseOrderResponse, Error, CloseOrderRequest, unknown>;
|
|
211
211
|
};
|
|
212
212
|
|
|
213
|
-
declare function useSymmDeposit(params
|
|
213
|
+
declare function useSymmDeposit(params?: {
|
|
214
214
|
publicClient?: PublicClient;
|
|
215
215
|
walletClient?: WalletClient;
|
|
216
216
|
}): {
|
|
@@ -224,7 +224,7 @@ declare function useSymmDeposit(params: {
|
|
|
224
224
|
}, unknown>;
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
-
declare function useSymmWithdraw(params
|
|
227
|
+
declare function useSymmWithdraw(params?: {
|
|
228
228
|
publicClient?: PublicClient;
|
|
229
229
|
walletClient?: WalletClient;
|
|
230
230
|
}): {
|
|
@@ -239,7 +239,7 @@ type InternalTransferParams = {
|
|
|
239
239
|
amount: bigint;
|
|
240
240
|
};
|
|
241
241
|
|
|
242
|
-
declare function useSymmCollateral(params
|
|
242
|
+
declare function useSymmCollateral(params?: {
|
|
243
243
|
publicClient?: PublicClient;
|
|
244
244
|
walletClient?: WalletClient;
|
|
245
245
|
}): {
|
|
@@ -257,7 +257,7 @@ declare function useSymmCollateral(params: {
|
|
|
257
257
|
}, unknown>;
|
|
258
258
|
};
|
|
259
259
|
|
|
260
|
-
declare function useSymmSignature(params
|
|
260
|
+
declare function useSymmSignature(params?: {
|
|
261
261
|
userAddress?: Address;
|
|
262
262
|
publicClient?: PublicClient;
|
|
263
263
|
walletClient?: WalletClient;
|
|
@@ -459,9 +459,11 @@ declare function useSymmMarkets(params?: {
|
|
|
459
459
|
searchText?: string;
|
|
460
460
|
query?: SymmQueryConfig;
|
|
461
461
|
}): {
|
|
462
|
-
markets:
|
|
462
|
+
markets: unknown[];
|
|
463
463
|
isLoading: boolean;
|
|
464
|
-
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<
|
|
464
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<{
|
|
465
|
+
markets?: unknown[];
|
|
466
|
+
}, Error>>;
|
|
465
467
|
};
|
|
466
468
|
|
|
467
469
|
declare function useSymmHedgerMarketById(params: {
|
|
@@ -650,10 +652,10 @@ declare function useSymmTwapOrder(params: {
|
|
|
650
652
|
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<node_modules__pear_protocol_symm_core_dist_types.TwapOrderResponse, Error>>;
|
|
651
653
|
};
|
|
652
654
|
|
|
653
|
-
declare function useSymmWs(params
|
|
654
|
-
symmCoreClient
|
|
655
|
+
declare function useSymmWs(params?: {
|
|
656
|
+
symmCoreClient?: SymmSDK | null;
|
|
655
657
|
accountAddress?: Address;
|
|
656
|
-
chainId
|
|
658
|
+
chainId?: number;
|
|
657
659
|
}): {
|
|
658
660
|
isConnected: boolean;
|
|
659
661
|
};
|
package/dist/react/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ type UseSymmAuthParams = {
|
|
|
26
26
|
walletClient?: WalletClient;
|
|
27
27
|
siweDomain?: string;
|
|
28
28
|
};
|
|
29
|
-
declare function useSymmAuth(params
|
|
29
|
+
declare function useSymmAuth(params?: UseSymmAuthParams): {
|
|
30
30
|
accessToken: string | null;
|
|
31
31
|
authToken: string | null;
|
|
32
32
|
isAuthenticated: boolean;
|
|
@@ -120,7 +120,7 @@ type Account = {
|
|
|
120
120
|
name: string;
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
-
declare function useSymmAccounts(params
|
|
123
|
+
declare function useSymmAccounts(params?: {
|
|
124
124
|
userAddress?: Address;
|
|
125
125
|
publicClient?: PublicClient;
|
|
126
126
|
walletClient?: WalletClient;
|
|
@@ -210,7 +210,7 @@ declare function useSymmCloseOrder(): {
|
|
|
210
210
|
closeOrder: _tanstack_react_query.UseMutationResult<_pear_protocol_symm_core.CloseOrderResponse, Error, CloseOrderRequest, unknown>;
|
|
211
211
|
};
|
|
212
212
|
|
|
213
|
-
declare function useSymmDeposit(params
|
|
213
|
+
declare function useSymmDeposit(params?: {
|
|
214
214
|
publicClient?: PublicClient;
|
|
215
215
|
walletClient?: WalletClient;
|
|
216
216
|
}): {
|
|
@@ -224,7 +224,7 @@ declare function useSymmDeposit(params: {
|
|
|
224
224
|
}, unknown>;
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
-
declare function useSymmWithdraw(params
|
|
227
|
+
declare function useSymmWithdraw(params?: {
|
|
228
228
|
publicClient?: PublicClient;
|
|
229
229
|
walletClient?: WalletClient;
|
|
230
230
|
}): {
|
|
@@ -239,7 +239,7 @@ type InternalTransferParams = {
|
|
|
239
239
|
amount: bigint;
|
|
240
240
|
};
|
|
241
241
|
|
|
242
|
-
declare function useSymmCollateral(params
|
|
242
|
+
declare function useSymmCollateral(params?: {
|
|
243
243
|
publicClient?: PublicClient;
|
|
244
244
|
walletClient?: WalletClient;
|
|
245
245
|
}): {
|
|
@@ -257,7 +257,7 @@ declare function useSymmCollateral(params: {
|
|
|
257
257
|
}, unknown>;
|
|
258
258
|
};
|
|
259
259
|
|
|
260
|
-
declare function useSymmSignature(params
|
|
260
|
+
declare function useSymmSignature(params?: {
|
|
261
261
|
userAddress?: Address;
|
|
262
262
|
publicClient?: PublicClient;
|
|
263
263
|
walletClient?: WalletClient;
|
|
@@ -459,9 +459,11 @@ declare function useSymmMarkets(params?: {
|
|
|
459
459
|
searchText?: string;
|
|
460
460
|
query?: SymmQueryConfig;
|
|
461
461
|
}): {
|
|
462
|
-
markets:
|
|
462
|
+
markets: unknown[];
|
|
463
463
|
isLoading: boolean;
|
|
464
|
-
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<
|
|
464
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<{
|
|
465
|
+
markets?: unknown[];
|
|
466
|
+
}, Error>>;
|
|
465
467
|
};
|
|
466
468
|
|
|
467
469
|
declare function useSymmHedgerMarketById(params: {
|
|
@@ -650,10 +652,10 @@ declare function useSymmTwapOrder(params: {
|
|
|
650
652
|
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<node_modules__pear_protocol_symm_core_dist_types.TwapOrderResponse, Error>>;
|
|
651
653
|
};
|
|
652
654
|
|
|
653
|
-
declare function useSymmWs(params
|
|
654
|
-
symmCoreClient
|
|
655
|
+
declare function useSymmWs(params?: {
|
|
656
|
+
symmCoreClient?: SymmSDK | null;
|
|
655
657
|
accountAddress?: Address;
|
|
656
|
-
chainId
|
|
658
|
+
chainId?: number;
|
|
657
659
|
}): {
|
|
658
660
|
isConnected: boolean;
|
|
659
661
|
};
|
package/dist/react/index.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
var react = require('react');
|
|
5
5
|
var symmCore = require('@pear-protocol/symm-core');
|
|
6
|
-
var reactQuery = require('@tanstack/react-query');
|
|
7
|
-
var zustand = require('zustand');
|
|
8
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var zustand = require('zustand');
|
|
8
|
+
var reactQuery = require('@tanstack/react-query');
|
|
9
9
|
var viem = require('viem');
|
|
10
10
|
|
|
11
11
|
var SymmContext = react.createContext(null);
|
|
@@ -16,142 +16,6 @@ function useSymmContext() {
|
|
|
16
16
|
}
|
|
17
17
|
return ctx;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
// src/react/query-keys.ts
|
|
21
|
-
var symmKeys = {
|
|
22
|
-
all: ["symm"],
|
|
23
|
-
accounts: (address, chainId) => ["symm", "accounts", address, chainId],
|
|
24
|
-
accountsApi: (address, chainId) => ["symm", "accountsApi", address, chainId],
|
|
25
|
-
accountsLength: (address, chainId) => ["symm", "accountsLength", address, chainId],
|
|
26
|
-
accountsWithPositions: (address, chainId) => ["symm", "accountsWithPositions", address, chainId],
|
|
27
|
-
accountSummary: (address, chainId) => ["symm", "accountSummary", address, chainId],
|
|
28
|
-
accountData: (address, chainId, upnl) => ["symm", "accountData", address, chainId, upnl],
|
|
29
|
-
signature: (address, chainId) => ["symm", "signature", address, chainId],
|
|
30
|
-
approval: (owner, spender, chainId, token) => ["symm", "approval", owner, spender, chainId, token],
|
|
31
|
-
balances: (address, chainId) => ["symm", "balances", address, chainId],
|
|
32
|
-
positions: (params) => ["symm", "positions", params],
|
|
33
|
-
openOrders: (params) => ["symm", "openOrders", params],
|
|
34
|
-
tradeHistory: (params) => ["symm", "tradeHistory", params],
|
|
35
|
-
tpslOrders: (address, chainId) => ["symm", "tpslOrders", address, chainId],
|
|
36
|
-
tpslOrdersList: (params) => ["symm", "tpslOrders", params],
|
|
37
|
-
twapOrders: (address, chainId) => ["symm", "twapOrders", address, chainId],
|
|
38
|
-
triggerOrders: (params) => ["symm", "triggerOrders", params],
|
|
39
|
-
triggerConfig: (orderId) => ["symm", "triggerConfig", orderId],
|
|
40
|
-
markets: (chainId, search) => ["symm", "markets", chainId, search],
|
|
41
|
-
hedgerMarketById: (id, chainId) => ["symm", "hedgerMarketById", id, chainId],
|
|
42
|
-
hedgerMarketBySymbol: (symbol, chainId) => ["symm", "hedgerMarketBySymbol", symbol, chainId],
|
|
43
|
-
lockedParams: (marketName, leverage, chainId) => ["symm", "lockedParams", marketName, leverage, chainId],
|
|
44
|
-
hedgerMarkets: (request) => ["symm", "hedgerMarkets", request],
|
|
45
|
-
fundingRates: (chainId) => ["symm", "fundingRates", chainId],
|
|
46
|
-
fundingPayments: (params) => ["symm", "fundingPayments", params],
|
|
47
|
-
fundingHistory: (params) => ["symm", "fundingHistory", params],
|
|
48
|
-
portfolio: (params) => ["symm", "portfolio", params],
|
|
49
|
-
notifications: (address, chainId) => ["symm", "notifications", address, chainId],
|
|
50
|
-
unreadCount: (address, chainId) => ["symm", "unreadCount", address, chainId],
|
|
51
|
-
availableMargin: (address, chainId) => ["symm", "availableMargin", address, chainId],
|
|
52
|
-
pendingIds: (address, chainId) => ["symm", "pendingIds", address, chainId],
|
|
53
|
-
pendingInstantOpens: (accountAddress, chainId) => ["symm", "pendingInstantOpens", accountAddress, chainId],
|
|
54
|
-
twapOrder: (orderId) => ["symm", "twapOrder", orderId],
|
|
55
|
-
delegation: (account, target, selectors, chainId) => ["symm", "delegation", account, target, selectors, chainId],
|
|
56
|
-
chartMetadata: (symbolsKey, positionKey) => ["symm", "chartMetadata", symbolsKey, positionKey]
|
|
57
|
-
};
|
|
58
|
-
var useSymmWsStore = zustand.create((set) => ({
|
|
59
|
-
isConnected: false,
|
|
60
|
-
setConnected: (isConnected) => set({ isConnected })
|
|
61
|
-
}));
|
|
62
|
-
|
|
63
|
-
// src/react/hooks/use-symm-ws.ts
|
|
64
|
-
function asUnsubscribeFn(value) {
|
|
65
|
-
return typeof value === "function" ? value : null;
|
|
66
|
-
}
|
|
67
|
-
function useSymmWs(params) {
|
|
68
|
-
const queryClient = reactQuery.useQueryClient();
|
|
69
|
-
const isConnected = useSymmWsStore((state) => state.isConnected);
|
|
70
|
-
const setConnected = useSymmWsStore((state) => state.setConnected);
|
|
71
|
-
const { symmCoreClient, accountAddress, chainId } = params;
|
|
72
|
-
react.useEffect(() => {
|
|
73
|
-
if (!symmCoreClient || !accountAddress) {
|
|
74
|
-
setConnected(false);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const ws = symmCoreClient.ws;
|
|
78
|
-
const addr = accountAddress;
|
|
79
|
-
const unsubscribers = [];
|
|
80
|
-
const removeOnConnect = ws.onConnect(() => setConnected(true));
|
|
81
|
-
const removeOnDisconnect = ws.onDisconnect(() => setConnected(false));
|
|
82
|
-
unsubscribers.push(removeOnConnect, removeOnDisconnect);
|
|
83
|
-
const positionsUnsub = asUnsubscribeFn(ws.subscribeToPositions(addr, chainId, () => {
|
|
84
|
-
queryClient.invalidateQueries({
|
|
85
|
-
queryKey: ["symm", "positions"]
|
|
86
|
-
});
|
|
87
|
-
}));
|
|
88
|
-
if (positionsUnsub) unsubscribers.push(positionsUnsub);
|
|
89
|
-
const openOrdersUnsub = asUnsubscribeFn(ws.subscribeToOpenOrders(addr, chainId, () => {
|
|
90
|
-
queryClient.invalidateQueries({
|
|
91
|
-
queryKey: ["symm", "openOrders"]
|
|
92
|
-
});
|
|
93
|
-
}));
|
|
94
|
-
if (openOrdersUnsub) unsubscribers.push(openOrdersUnsub);
|
|
95
|
-
const tradesUnsub = asUnsubscribeFn(ws.subscribeToTrades(addr, chainId, () => {
|
|
96
|
-
queryClient.invalidateQueries({
|
|
97
|
-
queryKey: ["symm", "tradeHistory"]
|
|
98
|
-
});
|
|
99
|
-
}));
|
|
100
|
-
if (tradesUnsub) unsubscribers.push(tradesUnsub);
|
|
101
|
-
const accountSummaryUnsub = asUnsubscribeFn(ws.subscribeToAccountSummary(addr, chainId, () => {
|
|
102
|
-
queryClient.invalidateQueries({
|
|
103
|
-
queryKey: symmKeys.balances(accountAddress, chainId)
|
|
104
|
-
});
|
|
105
|
-
queryClient.invalidateQueries({
|
|
106
|
-
queryKey: symmKeys.accountSummary(accountAddress, chainId)
|
|
107
|
-
});
|
|
108
|
-
}));
|
|
109
|
-
if (accountSummaryUnsub) unsubscribers.push(accountSummaryUnsub);
|
|
110
|
-
const notificationsUnsub = asUnsubscribeFn(ws.subscribeToNotifications(addr, chainId, () => {
|
|
111
|
-
queryClient.invalidateQueries({
|
|
112
|
-
queryKey: symmKeys.notifications(accountAddress, chainId)
|
|
113
|
-
});
|
|
114
|
-
queryClient.invalidateQueries({
|
|
115
|
-
queryKey: symmKeys.unreadCount(accountAddress, chainId)
|
|
116
|
-
});
|
|
117
|
-
}));
|
|
118
|
-
if (notificationsUnsub) unsubscribers.push(notificationsUnsub);
|
|
119
|
-
const tpslUnsub = asUnsubscribeFn(ws.subscribeToTpsl(addr, chainId, () => {
|
|
120
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "tpslOrders"] });
|
|
121
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
122
|
-
}));
|
|
123
|
-
if (tpslUnsub) unsubscribers.push(tpslUnsub);
|
|
124
|
-
const twapUnsub = asUnsubscribeFn(ws.subscribeToTwapOrders(addr, chainId, () => {
|
|
125
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "twapOrders"] });
|
|
126
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
127
|
-
}));
|
|
128
|
-
if (twapUnsub) unsubscribers.push(twapUnsub);
|
|
129
|
-
const triggerOrdersUnsub = asUnsubscribeFn(ws.subscribeToTriggerOrders(addr, chainId, () => {
|
|
130
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "triggerOrders"] });
|
|
131
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
132
|
-
}));
|
|
133
|
-
if (triggerOrdersUnsub) unsubscribers.push(triggerOrdersUnsub);
|
|
134
|
-
const executionsUnsub = asUnsubscribeFn(ws.subscribeToExecutions(addr, chainId, () => {
|
|
135
|
-
queryClient.invalidateQueries({
|
|
136
|
-
queryKey: ["symm", "positions"]
|
|
137
|
-
});
|
|
138
|
-
queryClient.invalidateQueries({
|
|
139
|
-
queryKey: ["symm", "portfolio"]
|
|
140
|
-
});
|
|
141
|
-
}));
|
|
142
|
-
if (executionsUnsub) unsubscribers.push(executionsUnsub);
|
|
143
|
-
return () => {
|
|
144
|
-
if (unsubscribers.length > 2) {
|
|
145
|
-
unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
146
|
-
} else {
|
|
147
|
-
removeOnConnect();
|
|
148
|
-
removeOnDisconnect();
|
|
149
|
-
ws.unsubscribeAll();
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
}, [symmCoreClient, accountAddress, chainId, queryClient, setConnected]);
|
|
153
|
-
return { isConnected };
|
|
154
|
-
}
|
|
155
19
|
function SymmProvider({
|
|
156
20
|
chainId = 42161,
|
|
157
21
|
address,
|
|
@@ -166,7 +30,6 @@ function SymmProvider({
|
|
|
166
30
|
defaultChainId: chainId
|
|
167
31
|
});
|
|
168
32
|
}, [chainId, symmCoreConfig.apiUrl, symmCoreConfig.wsUrl]);
|
|
169
|
-
useSymmWs({ symmCoreClient, accountAddress: address, chainId });
|
|
170
33
|
const value = react.useMemo(
|
|
171
34
|
() => ({
|
|
172
35
|
symmCoreClient,
|
|
@@ -395,10 +258,17 @@ var useSymmAuthStore = zustand.create((set, get) => ({
|
|
|
395
258
|
|
|
396
259
|
// src/react/hooks/use-symm-auth.ts
|
|
397
260
|
function useSymmAuth(params) {
|
|
398
|
-
const
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
261
|
+
const ctx = useSymmContext();
|
|
262
|
+
const address = params?.address ?? ctx.address;
|
|
263
|
+
const chainId = params?.chainId ?? ctx.chainId ?? 42161;
|
|
264
|
+
const walletClient = params?.walletClient ?? ctx.walletClient;
|
|
265
|
+
const siweDomain = params?.siweDomain;
|
|
266
|
+
const accessToken = useSymmAuthStore((state) => {
|
|
267
|
+
if (address) {
|
|
268
|
+
return state.tokensByKey[symmAuthTokenKey(address, chainId)] ?? null;
|
|
269
|
+
}
|
|
270
|
+
return ctx.accessToken ?? ctx.authToken ?? null;
|
|
271
|
+
});
|
|
402
272
|
const setToken = useSymmAuthStore((state) => state.setToken);
|
|
403
273
|
const getToken = useSymmAuthStore((state) => state.getToken);
|
|
404
274
|
const clearToken = useSymmAuthStore((state) => state.clearToken);
|
|
@@ -979,6 +849,45 @@ async function hasDelegatedAccess(publicClient, multiAccount, params) {
|
|
|
979
849
|
return Boolean(result);
|
|
980
850
|
}
|
|
981
851
|
|
|
852
|
+
// src/react/query-keys.ts
|
|
853
|
+
var symmKeys = {
|
|
854
|
+
all: ["symm"],
|
|
855
|
+
accounts: (address, chainId) => ["symm", "accounts", address, chainId],
|
|
856
|
+
accountsApi: (address, chainId) => ["symm", "accountsApi", address, chainId],
|
|
857
|
+
accountsLength: (address, chainId) => ["symm", "accountsLength", address, chainId],
|
|
858
|
+
accountsWithPositions: (address, chainId) => ["symm", "accountsWithPositions", address, chainId],
|
|
859
|
+
accountSummary: (address, chainId) => ["symm", "accountSummary", address, chainId],
|
|
860
|
+
accountData: (address, chainId, upnl) => ["symm", "accountData", address, chainId, upnl],
|
|
861
|
+
signature: (address, chainId) => ["symm", "signature", address, chainId],
|
|
862
|
+
approval: (owner, spender, chainId, token) => ["symm", "approval", owner, spender, chainId, token],
|
|
863
|
+
balances: (address, chainId) => ["symm", "balances", address, chainId],
|
|
864
|
+
positions: (params) => ["symm", "positions", params],
|
|
865
|
+
openOrders: (params) => ["symm", "openOrders", params],
|
|
866
|
+
tradeHistory: (params) => ["symm", "tradeHistory", params],
|
|
867
|
+
tpslOrders: (address, chainId) => ["symm", "tpslOrders", address, chainId],
|
|
868
|
+
tpslOrdersList: (params) => ["symm", "tpslOrders", params],
|
|
869
|
+
twapOrders: (address, chainId) => ["symm", "twapOrders", address, chainId],
|
|
870
|
+
triggerOrders: (params) => ["symm", "triggerOrders", params],
|
|
871
|
+
triggerConfig: (orderId) => ["symm", "triggerConfig", orderId],
|
|
872
|
+
markets: (chainId, search) => ["symm", "markets", chainId, search],
|
|
873
|
+
hedgerMarketById: (id, chainId) => ["symm", "hedgerMarketById", id, chainId],
|
|
874
|
+
hedgerMarketBySymbol: (symbol, chainId) => ["symm", "hedgerMarketBySymbol", symbol, chainId],
|
|
875
|
+
lockedParams: (marketName, leverage, chainId) => ["symm", "lockedParams", marketName, leverage, chainId],
|
|
876
|
+
hedgerMarkets: (request) => ["symm", "hedgerMarkets", request],
|
|
877
|
+
fundingRates: (chainId) => ["symm", "fundingRates", chainId],
|
|
878
|
+
fundingPayments: (params) => ["symm", "fundingPayments", params],
|
|
879
|
+
fundingHistory: (params) => ["symm", "fundingHistory", params],
|
|
880
|
+
portfolio: (params) => ["symm", "portfolio", params],
|
|
881
|
+
notifications: (address, chainId) => ["symm", "notifications", address, chainId],
|
|
882
|
+
unreadCount: (address, chainId) => ["symm", "unreadCount", address, chainId],
|
|
883
|
+
availableMargin: (address, chainId) => ["symm", "availableMargin", address, chainId],
|
|
884
|
+
pendingIds: (address, chainId) => ["symm", "pendingIds", address, chainId],
|
|
885
|
+
pendingInstantOpens: (accountAddress, chainId) => ["symm", "pendingInstantOpens", accountAddress, chainId],
|
|
886
|
+
twapOrder: (orderId) => ["symm", "twapOrder", orderId],
|
|
887
|
+
delegation: (account, target, selectors, chainId) => ["symm", "delegation", account, target, selectors, chainId],
|
|
888
|
+
chartMetadata: (symbolsKey, positionKey) => ["symm", "chartMetadata", symbolsKey, positionKey]
|
|
889
|
+
};
|
|
890
|
+
|
|
982
891
|
// src/react/hooks/use-symm-delegation.ts
|
|
983
892
|
function useSymmDelegation(params) {
|
|
984
893
|
const { chainId, address, symmioConfig } = useSymmContext();
|
|
@@ -1189,7 +1098,7 @@ async function getAccounts(publicClient, multiAccount, user, start = 0, size = 1
|
|
|
1189
1098
|
|
|
1190
1099
|
// src/react/hooks/use-symm-accounts.ts
|
|
1191
1100
|
var EMPTY_ACCOUNTS = [];
|
|
1192
|
-
function useSymmAccounts(params, options) {
|
|
1101
|
+
function useSymmAccounts(params = {}, options) {
|
|
1193
1102
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1194
1103
|
const { userAddress, publicClient, walletClient } = params;
|
|
1195
1104
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -1564,7 +1473,7 @@ async function depositAndAllocate(walletClient, publicClient, multiAccount, para
|
|
|
1564
1473
|
}
|
|
1565
1474
|
|
|
1566
1475
|
// src/react/hooks/use-symm-deposit.ts
|
|
1567
|
-
function useSymmDeposit(params) {
|
|
1476
|
+
function useSymmDeposit(params = {}) {
|
|
1568
1477
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1569
1478
|
const { publicClient, walletClient } = params;
|
|
1570
1479
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -1624,7 +1533,7 @@ async function withdraw(walletClient, publicClient, multiAccount, params) {
|
|
|
1624
1533
|
}
|
|
1625
1534
|
|
|
1626
1535
|
// src/react/hooks/use-symm-withdraw.ts
|
|
1627
|
-
function useSymmWithdraw(params) {
|
|
1536
|
+
function useSymmWithdraw(params = {}) {
|
|
1628
1537
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1629
1538
|
const { publicClient, walletClient } = params;
|
|
1630
1539
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -24292,7 +24201,7 @@ var MuonClient = class {
|
|
|
24292
24201
|
};
|
|
24293
24202
|
|
|
24294
24203
|
// src/react/hooks/use-symm-collateral.ts
|
|
24295
|
-
function useSymmCollateral(params) {
|
|
24204
|
+
function useSymmCollateral(params = {}) {
|
|
24296
24205
|
const { chainId, symmioConfig } = useSymmContext();
|
|
24297
24206
|
const { publicClient, walletClient } = params;
|
|
24298
24207
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -24445,7 +24354,7 @@ async function hasSignedCurrentVersion(publicClient, signatureStore, user) {
|
|
|
24445
24354
|
}
|
|
24446
24355
|
|
|
24447
24356
|
// src/react/hooks/use-symm-signature.ts
|
|
24448
|
-
function useSymmSignature(params, options) {
|
|
24357
|
+
function useSymmSignature(params = {}, options) {
|
|
24449
24358
|
const { chainId, symmioConfig } = useSymmContext();
|
|
24450
24359
|
const { userAddress, publicClient, walletClient } = params;
|
|
24451
24360
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -24678,6 +24587,13 @@ function useSymmPositions(params) {
|
|
|
24678
24587
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
24679
24588
|
const chainId = params.chainId ?? ctxChainId;
|
|
24680
24589
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
24590
|
+
console.log({
|
|
24591
|
+
symmCoreClient,
|
|
24592
|
+
accountAddress,
|
|
24593
|
+
resolvedAddress,
|
|
24594
|
+
chainId,
|
|
24595
|
+
internalEnabled
|
|
24596
|
+
});
|
|
24681
24597
|
const query = reactQuery.useQuery({
|
|
24682
24598
|
...params.query,
|
|
24683
24599
|
queryKey: symmKeys.positions({
|
|
@@ -24932,10 +24848,11 @@ function useSymmMarkets(params) {
|
|
|
24932
24848
|
...params?.query,
|
|
24933
24849
|
queryKey: symmKeys.markets(chainId, searchText),
|
|
24934
24850
|
queryFn: () => {
|
|
24851
|
+
const marketsApi = symmCoreClient.markets;
|
|
24935
24852
|
if (searchText) {
|
|
24936
|
-
return
|
|
24853
|
+
return marketsApi.search(searchText, chainId);
|
|
24937
24854
|
}
|
|
24938
|
-
return
|
|
24855
|
+
return marketsApi.list({ pageSize: "500", chainId });
|
|
24939
24856
|
},
|
|
24940
24857
|
enabled: internalEnabled && (params?.query?.enabled ?? true)
|
|
24941
24858
|
});
|
|
@@ -25268,6 +25185,128 @@ function useSymmTwapOrder(params) {
|
|
|
25268
25185
|
refetch: query.refetch
|
|
25269
25186
|
};
|
|
25270
25187
|
}
|
|
25188
|
+
var useSymmWsStore = zustand.create((set) => ({
|
|
25189
|
+
isConnected: false,
|
|
25190
|
+
setConnected: (isConnected) => set({ isConnected })
|
|
25191
|
+
}));
|
|
25192
|
+
|
|
25193
|
+
// src/react/hooks/use-symm-ws.ts
|
|
25194
|
+
function asUnsubscribeFn(value) {
|
|
25195
|
+
return typeof value === "function" ? value : null;
|
|
25196
|
+
}
|
|
25197
|
+
function useSymmWs(params = {}) {
|
|
25198
|
+
const {
|
|
25199
|
+
symmCoreClient: ctxClient,
|
|
25200
|
+
address: ctxAddress,
|
|
25201
|
+
chainId: ctxChainId
|
|
25202
|
+
} = useSymmContext();
|
|
25203
|
+
const queryClient = reactQuery.useQueryClient();
|
|
25204
|
+
const isConnected = useSymmWsStore((state) => state.isConnected);
|
|
25205
|
+
const setConnected = useSymmWsStore((state) => state.setConnected);
|
|
25206
|
+
const symmCoreClient = params.symmCoreClient ?? ctxClient;
|
|
25207
|
+
const accountAddress = params.accountAddress ?? ctxAddress;
|
|
25208
|
+
const chainId = params.chainId ?? ctxChainId;
|
|
25209
|
+
react.useEffect(() => {
|
|
25210
|
+
if (!symmCoreClient || !accountAddress) {
|
|
25211
|
+
setConnected(false);
|
|
25212
|
+
return;
|
|
25213
|
+
}
|
|
25214
|
+
const ws = symmCoreClient.ws;
|
|
25215
|
+
const addr = accountAddress;
|
|
25216
|
+
const unsubscribers = [];
|
|
25217
|
+
const removeOnConnect = ws.onConnect(() => setConnected(true));
|
|
25218
|
+
const removeOnDisconnect = ws.onDisconnect(() => setConnected(false));
|
|
25219
|
+
unsubscribers.push(removeOnConnect, removeOnDisconnect);
|
|
25220
|
+
const positionsUnsub = asUnsubscribeFn(
|
|
25221
|
+
ws.subscribeToPositions(addr, chainId, () => {
|
|
25222
|
+
queryClient.invalidateQueries({
|
|
25223
|
+
queryKey: ["symm", "positions"]
|
|
25224
|
+
});
|
|
25225
|
+
})
|
|
25226
|
+
);
|
|
25227
|
+
if (positionsUnsub) unsubscribers.push(positionsUnsub);
|
|
25228
|
+
const openOrdersUnsub = asUnsubscribeFn(
|
|
25229
|
+
ws.subscribeToOpenOrders(addr, chainId, () => {
|
|
25230
|
+
queryClient.invalidateQueries({
|
|
25231
|
+
queryKey: ["symm", "openOrders"]
|
|
25232
|
+
});
|
|
25233
|
+
})
|
|
25234
|
+
);
|
|
25235
|
+
if (openOrdersUnsub) unsubscribers.push(openOrdersUnsub);
|
|
25236
|
+
const tradesUnsub = asUnsubscribeFn(
|
|
25237
|
+
ws.subscribeToTrades(addr, chainId, () => {
|
|
25238
|
+
queryClient.invalidateQueries({
|
|
25239
|
+
queryKey: ["symm", "tradeHistory"]
|
|
25240
|
+
});
|
|
25241
|
+
})
|
|
25242
|
+
);
|
|
25243
|
+
if (tradesUnsub) unsubscribers.push(tradesUnsub);
|
|
25244
|
+
const accountSummaryUnsub = asUnsubscribeFn(
|
|
25245
|
+
ws.subscribeToAccountSummary(addr, chainId, () => {
|
|
25246
|
+
queryClient.invalidateQueries({
|
|
25247
|
+
queryKey: symmKeys.balances(accountAddress, chainId)
|
|
25248
|
+
});
|
|
25249
|
+
queryClient.invalidateQueries({
|
|
25250
|
+
queryKey: symmKeys.accountSummary(accountAddress, chainId)
|
|
25251
|
+
});
|
|
25252
|
+
})
|
|
25253
|
+
);
|
|
25254
|
+
if (accountSummaryUnsub) unsubscribers.push(accountSummaryUnsub);
|
|
25255
|
+
const notificationsUnsub = asUnsubscribeFn(
|
|
25256
|
+
ws.subscribeToNotifications(addr, chainId, () => {
|
|
25257
|
+
queryClient.invalidateQueries({
|
|
25258
|
+
queryKey: symmKeys.notifications(accountAddress, chainId)
|
|
25259
|
+
});
|
|
25260
|
+
queryClient.invalidateQueries({
|
|
25261
|
+
queryKey: symmKeys.unreadCount(accountAddress, chainId)
|
|
25262
|
+
});
|
|
25263
|
+
})
|
|
25264
|
+
);
|
|
25265
|
+
if (notificationsUnsub) unsubscribers.push(notificationsUnsub);
|
|
25266
|
+
const tpslUnsub = asUnsubscribeFn(
|
|
25267
|
+
ws.subscribeToTpsl(addr, chainId, () => {
|
|
25268
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "tpslOrders"] });
|
|
25269
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
25270
|
+
})
|
|
25271
|
+
);
|
|
25272
|
+
if (tpslUnsub) unsubscribers.push(tpslUnsub);
|
|
25273
|
+
const twapUnsub = asUnsubscribeFn(
|
|
25274
|
+
ws.subscribeToTwapOrders(addr, chainId, () => {
|
|
25275
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "twapOrders"] });
|
|
25276
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
25277
|
+
})
|
|
25278
|
+
);
|
|
25279
|
+
if (twapUnsub) unsubscribers.push(twapUnsub);
|
|
25280
|
+
const triggerOrdersUnsub = asUnsubscribeFn(
|
|
25281
|
+
ws.subscribeToTriggerOrders(addr, chainId, () => {
|
|
25282
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "triggerOrders"] });
|
|
25283
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
25284
|
+
})
|
|
25285
|
+
);
|
|
25286
|
+
if (triggerOrdersUnsub) unsubscribers.push(triggerOrdersUnsub);
|
|
25287
|
+
const executionsUnsub = asUnsubscribeFn(
|
|
25288
|
+
ws.subscribeToExecutions(addr, chainId, () => {
|
|
25289
|
+
queryClient.invalidateQueries({
|
|
25290
|
+
queryKey: ["symm", "positions"]
|
|
25291
|
+
});
|
|
25292
|
+
queryClient.invalidateQueries({
|
|
25293
|
+
queryKey: ["symm", "portfolio"]
|
|
25294
|
+
});
|
|
25295
|
+
})
|
|
25296
|
+
);
|
|
25297
|
+
if (executionsUnsub) unsubscribers.push(executionsUnsub);
|
|
25298
|
+
return () => {
|
|
25299
|
+
if (unsubscribers.length > 2) {
|
|
25300
|
+
unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
25301
|
+
} else {
|
|
25302
|
+
removeOnConnect();
|
|
25303
|
+
removeOnDisconnect();
|
|
25304
|
+
ws.unsubscribeAll();
|
|
25305
|
+
}
|
|
25306
|
+
};
|
|
25307
|
+
}, [symmCoreClient, accountAddress, chainId, queryClient, setConnected]);
|
|
25308
|
+
return { isConnected };
|
|
25309
|
+
}
|
|
25271
25310
|
var STABLE_SYMBOLS = /* @__PURE__ */ new Set(["USDC", "USD", "USDT", "USDE", "USDH", "USDT0"]);
|
|
25272
25311
|
function useSymmChartSelection(input) {
|
|
25273
25312
|
const {
|