@pear-protocol/symmio-client 0.2.3 → 0.2.5
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.d.mts +295 -4886
- package/dist/index.d.ts +295 -4886
- package/dist/index.js +1709 -2047
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1710 -2047
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +64 -4867
- package/dist/react/index.d.ts +64 -4867
- package/dist/react/index.js +5883 -6646
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +5887 -6649
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/provider-xhUge8b7.d.mts +34 -0
- package/dist/react/provider-xhUge8b7.d.ts +34 -0
- package/dist/react/provider.d.mts +3 -0
- package/dist/react/provider.d.ts +3 -0
- package/dist/react/provider.js +195 -0
- package/dist/react/provider.js.map +1 -0
- package/dist/react/provider.mjs +193 -0
- package/dist/react/provider.mjs.map +1 -0
- package/package.json +7 -2
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Address, PublicClient, WalletClient } from 'viem';
|
|
3
|
+
|
|
4
|
+
type ChainId = number;
|
|
5
|
+
type SymmioSDKConfig = {
|
|
6
|
+
chainId: ChainId;
|
|
7
|
+
multiAccountAddress?: Address;
|
|
8
|
+
symmioDiamondAddress?: Address;
|
|
9
|
+
collateralAddress?: Address;
|
|
10
|
+
clearingHouseAddress?: Address;
|
|
11
|
+
signatureStoreAddress?: Address;
|
|
12
|
+
muonBaseUrls?: string[];
|
|
13
|
+
muonAppName?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type RefreshAuth = (accountAddress?: Address) => Promise<string | null>;
|
|
17
|
+
type SymmProviderProps = {
|
|
18
|
+
chainId?: number;
|
|
19
|
+
address?: Address;
|
|
20
|
+
publicClient?: PublicClient;
|
|
21
|
+
walletClient?: WalletClient;
|
|
22
|
+
accessToken?: string | null;
|
|
23
|
+
authToken?: string | null;
|
|
24
|
+
refreshAuth?: RefreshAuth;
|
|
25
|
+
symmCoreConfig: {
|
|
26
|
+
apiUrl: string;
|
|
27
|
+
wsUrl?: string;
|
|
28
|
+
};
|
|
29
|
+
symmioConfig?: Partial<SymmioSDKConfig>;
|
|
30
|
+
children: React.ReactNode;
|
|
31
|
+
};
|
|
32
|
+
declare function SymmProvider({ chainId, address, accessToken, authToken, refreshAuth, symmCoreConfig, symmioConfig, children, }: SymmProviderProps): react_jsx_runtime.JSX.Element;
|
|
33
|
+
|
|
34
|
+
export { type SymmioSDKConfig as S, SymmProvider as a, type SymmProviderProps as b };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Address, PublicClient, WalletClient } from 'viem';
|
|
3
|
+
|
|
4
|
+
type ChainId = number;
|
|
5
|
+
type SymmioSDKConfig = {
|
|
6
|
+
chainId: ChainId;
|
|
7
|
+
multiAccountAddress?: Address;
|
|
8
|
+
symmioDiamondAddress?: Address;
|
|
9
|
+
collateralAddress?: Address;
|
|
10
|
+
clearingHouseAddress?: Address;
|
|
11
|
+
signatureStoreAddress?: Address;
|
|
12
|
+
muonBaseUrls?: string[];
|
|
13
|
+
muonAppName?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type RefreshAuth = (accountAddress?: Address) => Promise<string | null>;
|
|
17
|
+
type SymmProviderProps = {
|
|
18
|
+
chainId?: number;
|
|
19
|
+
address?: Address;
|
|
20
|
+
publicClient?: PublicClient;
|
|
21
|
+
walletClient?: WalletClient;
|
|
22
|
+
accessToken?: string | null;
|
|
23
|
+
authToken?: string | null;
|
|
24
|
+
refreshAuth?: RefreshAuth;
|
|
25
|
+
symmCoreConfig: {
|
|
26
|
+
apiUrl: string;
|
|
27
|
+
wsUrl?: string;
|
|
28
|
+
};
|
|
29
|
+
symmioConfig?: Partial<SymmioSDKConfig>;
|
|
30
|
+
children: React.ReactNode;
|
|
31
|
+
};
|
|
32
|
+
declare function SymmProvider({ chainId, address, accessToken, authToken, refreshAuth, symmCoreConfig, symmioConfig, children, }: SymmProviderProps): react_jsx_runtime.JSX.Element;
|
|
33
|
+
|
|
34
|
+
export { type SymmioSDKConfig as S, SymmProvider as a, type SymmProviderProps as b };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var symmCore = require('@pear-protocol/symm-core');
|
|
5
|
+
var reactQuery = require('@tanstack/react-query');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
// src/react/provider.tsx
|
|
9
|
+
var SymmContext = react.createContext(null);
|
|
10
|
+
function useSymmContext() {
|
|
11
|
+
const ctx = react.useContext(SymmContext);
|
|
12
|
+
if (!ctx) {
|
|
13
|
+
throw new Error("useSymmContext must be used within <SymmProvider>");
|
|
14
|
+
}
|
|
15
|
+
return ctx;
|
|
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) => ["symm", "accountData", address, chainId],
|
|
27
|
+
signature: (address, chainId) => ["symm", "signature", address, chainId],
|
|
28
|
+
approval: (owner, spender, chainId) => ["symm", "approval", owner, spender, chainId],
|
|
29
|
+
balances: (address, chainId) => ["symm", "balances", address, chainId],
|
|
30
|
+
positions: (address, chainId) => ["symm", "positions", address, chainId],
|
|
31
|
+
openOrders: (address, chainId) => ["symm", "openOrders", address, chainId],
|
|
32
|
+
tradeHistory: (address, chainId) => ["symm", "tradeHistory", address, chainId],
|
|
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: (address, chainId) => ["symm", "portfolio", address, chainId],
|
|
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
|
+
|
|
57
|
+
// src/react/hooks/use-symm-ws.ts
|
|
58
|
+
function asUnsubscribeFn(value) {
|
|
59
|
+
return typeof value === "function" ? value : null;
|
|
60
|
+
}
|
|
61
|
+
function useSymmWs(params) {
|
|
62
|
+
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
63
|
+
const queryClient = reactQuery.useQueryClient();
|
|
64
|
+
const { accountAddress } = params;
|
|
65
|
+
const chainId = params.chainId ?? ctxChainId;
|
|
66
|
+
const [isConnected, setIsConnected] = react.useState(false);
|
|
67
|
+
react.useEffect(() => {
|
|
68
|
+
if (!symmCoreClient || !accountAddress) {
|
|
69
|
+
setIsConnected(false);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const ws = symmCoreClient.ws;
|
|
73
|
+
const addr = accountAddress;
|
|
74
|
+
const unsubscribers = [];
|
|
75
|
+
const removeOnConnect = ws.onConnect(() => setIsConnected(true));
|
|
76
|
+
const removeOnDisconnect = ws.onDisconnect(() => setIsConnected(false));
|
|
77
|
+
unsubscribers.push(removeOnConnect, removeOnDisconnect);
|
|
78
|
+
const positionsUnsub = asUnsubscribeFn(ws.subscribeToPositions(addr, chainId, () => {
|
|
79
|
+
queryClient.invalidateQueries({
|
|
80
|
+
queryKey: symmKeys.positions(accountAddress, chainId)
|
|
81
|
+
});
|
|
82
|
+
}));
|
|
83
|
+
if (positionsUnsub) unsubscribers.push(positionsUnsub);
|
|
84
|
+
const openOrdersUnsub = asUnsubscribeFn(ws.subscribeToOpenOrders(addr, chainId, () => {
|
|
85
|
+
queryClient.invalidateQueries({
|
|
86
|
+
queryKey: symmKeys.openOrders(accountAddress, chainId)
|
|
87
|
+
});
|
|
88
|
+
}));
|
|
89
|
+
if (openOrdersUnsub) unsubscribers.push(openOrdersUnsub);
|
|
90
|
+
const tradesUnsub = asUnsubscribeFn(ws.subscribeToTrades(addr, chainId, () => {
|
|
91
|
+
queryClient.invalidateQueries({
|
|
92
|
+
queryKey: symmKeys.tradeHistory(accountAddress, chainId)
|
|
93
|
+
});
|
|
94
|
+
}));
|
|
95
|
+
if (tradesUnsub) unsubscribers.push(tradesUnsub);
|
|
96
|
+
const accountSummaryUnsub = asUnsubscribeFn(ws.subscribeToAccountSummary(addr, chainId, () => {
|
|
97
|
+
queryClient.invalidateQueries({
|
|
98
|
+
queryKey: symmKeys.balances(accountAddress, chainId)
|
|
99
|
+
});
|
|
100
|
+
queryClient.invalidateQueries({
|
|
101
|
+
queryKey: symmKeys.accountSummary(accountAddress, chainId)
|
|
102
|
+
});
|
|
103
|
+
}));
|
|
104
|
+
if (accountSummaryUnsub) unsubscribers.push(accountSummaryUnsub);
|
|
105
|
+
const notificationsUnsub = asUnsubscribeFn(ws.subscribeToNotifications(addr, chainId, () => {
|
|
106
|
+
queryClient.invalidateQueries({
|
|
107
|
+
queryKey: symmKeys.notifications(accountAddress, chainId)
|
|
108
|
+
});
|
|
109
|
+
queryClient.invalidateQueries({
|
|
110
|
+
queryKey: symmKeys.unreadCount(accountAddress, chainId)
|
|
111
|
+
});
|
|
112
|
+
}));
|
|
113
|
+
if (notificationsUnsub) unsubscribers.push(notificationsUnsub);
|
|
114
|
+
const tpslUnsub = asUnsubscribeFn(ws.subscribeToTpsl(addr, chainId, () => {
|
|
115
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "tpslOrders"] });
|
|
116
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
117
|
+
}));
|
|
118
|
+
if (tpslUnsub) unsubscribers.push(tpslUnsub);
|
|
119
|
+
const twapUnsub = asUnsubscribeFn(ws.subscribeToTwapOrders(addr, chainId, () => {
|
|
120
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "twapOrders"] });
|
|
121
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
122
|
+
}));
|
|
123
|
+
if (twapUnsub) unsubscribers.push(twapUnsub);
|
|
124
|
+
const triggerOrdersUnsub = asUnsubscribeFn(ws.subscribeToTriggerOrders(addr, chainId, () => {
|
|
125
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "triggerOrders"] });
|
|
126
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
127
|
+
}));
|
|
128
|
+
if (triggerOrdersUnsub) unsubscribers.push(triggerOrdersUnsub);
|
|
129
|
+
const executionsUnsub = asUnsubscribeFn(ws.subscribeToExecutions(addr, chainId, () => {
|
|
130
|
+
queryClient.invalidateQueries({
|
|
131
|
+
queryKey: symmKeys.positions(accountAddress, chainId)
|
|
132
|
+
});
|
|
133
|
+
queryClient.invalidateQueries({
|
|
134
|
+
queryKey: symmKeys.portfolio(accountAddress, chainId)
|
|
135
|
+
});
|
|
136
|
+
}));
|
|
137
|
+
if (executionsUnsub) unsubscribers.push(executionsUnsub);
|
|
138
|
+
return () => {
|
|
139
|
+
if (unsubscribers.length > 2) {
|
|
140
|
+
unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
141
|
+
} else {
|
|
142
|
+
removeOnConnect();
|
|
143
|
+
removeOnDisconnect();
|
|
144
|
+
ws.unsubscribeAll();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}, [symmCoreClient, accountAddress, chainId, queryClient]);
|
|
148
|
+
return { isConnected };
|
|
149
|
+
}
|
|
150
|
+
var noopRefreshAuth = async () => null;
|
|
151
|
+
function SymmProvider({
|
|
152
|
+
chainId = 42161,
|
|
153
|
+
address,
|
|
154
|
+
accessToken = null,
|
|
155
|
+
authToken,
|
|
156
|
+
refreshAuth = noopRefreshAuth,
|
|
157
|
+
symmCoreConfig,
|
|
158
|
+
symmioConfig,
|
|
159
|
+
children
|
|
160
|
+
}) {
|
|
161
|
+
const symmCoreClient = react.useMemo(() => {
|
|
162
|
+
return symmCore.createSymmSDK({
|
|
163
|
+
apiUrl: symmCoreConfig.apiUrl,
|
|
164
|
+
wsUrl: symmCoreConfig.wsUrl,
|
|
165
|
+
defaultChainId: chainId
|
|
166
|
+
});
|
|
167
|
+
}, [chainId, symmCoreConfig.apiUrl, symmCoreConfig.wsUrl]);
|
|
168
|
+
const resolvedAuthToken = authToken ?? accessToken;
|
|
169
|
+
useSymmWs({ chainId });
|
|
170
|
+
const value = react.useMemo(
|
|
171
|
+
() => ({
|
|
172
|
+
symmCoreClient,
|
|
173
|
+
chainId,
|
|
174
|
+
address,
|
|
175
|
+
symmioConfig,
|
|
176
|
+
accessToken,
|
|
177
|
+
authToken: resolvedAuthToken,
|
|
178
|
+
refreshAuth
|
|
179
|
+
}),
|
|
180
|
+
[
|
|
181
|
+
symmCoreClient,
|
|
182
|
+
chainId,
|
|
183
|
+
address,
|
|
184
|
+
symmioConfig,
|
|
185
|
+
accessToken,
|
|
186
|
+
resolvedAuthToken,
|
|
187
|
+
refreshAuth
|
|
188
|
+
]
|
|
189
|
+
);
|
|
190
|
+
return /* @__PURE__ */ jsxRuntime.jsx(SymmContext.Provider, { value, children });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
exports.SymmProvider = SymmProvider;
|
|
194
|
+
//# sourceMappingURL=provider.js.map
|
|
195
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react/context.ts","../../src/react/query-keys.ts","../../src/react/hooks/use-symm-ws.ts","../../src/react/provider.tsx"],"names":["createContext","useContext","useQueryClient","useState","useEffect","useMemo","createSymmSDK","jsx"],"mappings":";;;;;;;;AAeO,IAAM,WAAA,GAAcA,oBAAuC,IAAI,CAAA;AAE/D,SAAS,cAAA,GAAmC;AACjD,EAAA,MAAM,GAAA,GAAMC,iBAAW,WAAW,CAAA;AAClC,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,MAAM,mDAAmD,CAAA;AAAA,EACrE;AACA,EAAA,OAAO,GAAA;AACT;;;ACpBO,IAAM,QAAA,GAAW;AAAA,EACtB,GAAA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AgB;AAAA,KACjB,CAAA;AAAA,EACH,GAAG,CAAC,OAAA,EAAS,eAAe,MAAA,EAAQ,cAAA,CAAe,KAAK,CAAC,CAAA;AAEzD,EAAA,MAAM,oBAAoB,SAAA,IAAa,WAAA;AACvC,EAAA,SAAA,CAAU,EAAE,SAAS,CAAA;AAErB,EAAA,MAAM,KAAA,GAAQD,aAAA;AAAA,IACZ,OAAO;AAAA,MACL,cAAA;AAAA,MACA,OAAA;AAAA,MACA,OAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA;AAAA,MACA,SAAA,EAAW,iBAAA;AAAA,MACX;AAAA,KACF,CAAA;AAAA,IACA;AAAA,MACE,cAAA;AAAA,MACA,OAAA;AAAA,MACA,OAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA;AAAA,MACA,iBAAA;AAAA,MACA;AAAA;AACF,GACF;AAEA,EAAA,uBAAOE,cAAA,CAAC,WAAA,CAAY,QAAA,EAAZ,EAAqB,OAAe,QAAA,EAAS,CAAA;AACvD","file":"provider.js","sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { Address, PublicClient, WalletClient } from \"viem\";\nimport type { SymmSDK } from \"@pear-protocol/symm-core\";\nimport type { SymmioSDKConfig } from \"../types/common\";\n\nexport type SymmContextValue = {\n symmCoreClient: SymmSDK | null;\n chainId: number;\n address?: `0x${string}`;\n symmioConfig?: Partial<SymmioSDKConfig>;\n accessToken: string | null;\n authToken: string | null;\n refreshAuth: (accountAddress?: Address) => Promise<string | null>;\n};\n\nexport const SymmContext = createContext<SymmContextValue | null>(null);\n\nexport function useSymmContext(): SymmContextValue {\n const ctx = useContext(SymmContext);\n if (!ctx) {\n throw new Error(\"useSymmContext must be used within <SymmProvider>\");\n }\n return ctx;\n}\n","import type { GetSymmHedgerMarketsRequest } from '@pear-protocol/symm-core';\nimport type { Address, Hex } from 'viem';\n\nexport const symmKeys = {\n all: ['symm'] as const,\n accounts: (address?: Address, chainId?: number) =>\n ['symm', 'accounts', address, chainId] as const,\n accountsApi: (address?: Address, chainId?: number) =>\n ['symm', 'accountsApi', address, chainId] as const,\n accountsLength: (address?: Address, chainId?: number) =>\n ['symm', 'accountsLength', address, chainId] as const,\n accountsWithPositions: (address?: Address, chainId?: number) =>\n ['symm', 'accountsWithPositions', address, chainId] as const,\n accountSummary: (address?: Address, chainId?: number) =>\n ['symm', 'accountSummary', address, chainId] as const,\n accountData: (address?: Address, chainId?: number) =>\n ['symm', 'accountData', address, chainId] as const,\n signature: (address?: Address, chainId?: number) =>\n ['symm', 'signature', address, chainId] as const,\n approval: (owner?: Address, spender?: Address, chainId?: number) =>\n ['symm', 'approval', owner, spender, chainId] as const,\n balances: (address?: Address, chainId?: number) =>\n ['symm', 'balances', address, chainId] as const,\n positions: (address?: Address, chainId?: number) =>\n ['symm', 'positions', address, chainId] as const,\n openOrders: (address?: Address, chainId?: number) =>\n ['symm', 'openOrders', address, chainId] as const,\n tradeHistory: (address?: Address, chainId?: number) =>\n ['symm', 'tradeHistory', address, chainId] as const,\n tpslOrders: (address?: Address, chainId?: number) =>\n ['symm', 'tpslOrders', address, chainId] as const,\n tpslOrdersList: (params?: {\n accountAddress?: Address;\n mainAddress?: Address;\n positionId?: string;\n type?: string;\n status?: string;\n chainId?: number;\n }) => ['symm', 'tpslOrders', params] as const,\n twapOrders: (address?: Address, chainId?: number) =>\n ['symm', 'twapOrders', address, chainId] as const,\n triggerOrders: (params?: {\n accountAddress?: Address;\n mainAddress?: Address;\n status?: string;\n limit?: number;\n offset?: number;\n chainId?: number;\n }) => ['symm', 'triggerOrders', params] as const,\n triggerConfig: (orderId?: string) =>\n ['symm', 'triggerConfig', orderId] as const,\n markets: (chainId?: number, search?: string) =>\n ['symm', 'markets', chainId, search] as const,\n hedgerMarketById: (id?: number, chainId?: number) =>\n ['symm', 'hedgerMarketById', id, chainId] as const,\n hedgerMarketBySymbol: (symbol?: string, chainId?: number) =>\n ['symm', 'hedgerMarketBySymbol', symbol, chainId] as const,\n lockedParams: (marketName?: string, leverage?: number, chainId?: number) =>\n ['symm', 'lockedParams', marketName, leverage, chainId] as const,\n hedgerMarkets: (request?: GetSymmHedgerMarketsRequest) =>\n ['symm', 'hedgerMarkets', request] as const,\n fundingRates: (chainId?: number) => ['symm', 'fundingRates', chainId] as const,\n fundingPayments: (params?: {\n address?: Address;\n positionId?: string;\n chainId?: number;\n limit?: number;\n offset?: number;\n }) => ['symm', 'fundingPayments', params] as const,\n fundingHistory: (params?: {\n chainId?: number;\n period?: string;\n longSymbols?: string;\n shortSymbols?: string;\n interval?: string;\n weightMode?: string;\n includeContributions?: boolean;\n }) => ['symm', 'fundingHistory', params] as const,\n portfolio: (address?: Address, chainId?: number) =>\n ['symm', 'portfolio', address, chainId] as const,\n notifications: (address?: Address, chainId?: number) =>\n ['symm', 'notifications', address, chainId] as const,\n unreadCount: (address?: Address, chainId?: number) =>\n ['symm', 'unreadCount', address, chainId] as const,\n availableMargin: (address?: Address, chainId?: number) =>\n ['symm', 'availableMargin', address, chainId] as const,\n pendingIds: (address?: Address, chainId?: number) =>\n ['symm', 'pendingIds', address, chainId] as const,\n pendingInstantOpens: (accountAddress?: Address, chainId?: number) =>\n ['symm', 'pendingInstantOpens', accountAddress, chainId] as const,\n twapOrder: (orderId?: string) =>\n ['symm', 'twapOrder', orderId] as const,\n delegation: (\n account?: Address,\n target?: Address,\n selectors?: readonly Hex[],\n chainId?: number\n ) => ['symm', 'delegation', account, target, selectors, chainId] as const,\n chartMetadata: (symbolsKey: string, positionKey: string) =>\n ['symm', 'chartMetadata', symbolsKey, positionKey] as const,\n};\n","import { useEffect, useState } from 'react';\nimport { useQueryClient } from '@tanstack/react-query';\nimport type { Address } from 'viem';\nimport { useSymmContext } from '../context';\nimport { symmKeys } from '../query-keys';\n\ntype UnsubscribeFn = () => void;\n\nfunction asUnsubscribeFn(value: unknown): UnsubscribeFn | null {\n return typeof value === 'function' ? (value as UnsubscribeFn) : null;\n}\n\nexport function useSymmWs(params: {\n accountAddress?: Address;\n chainId?: number;\n}) {\n const { symmCoreClient, chainId: ctxChainId } = useSymmContext();\n const queryClient = useQueryClient();\n const { accountAddress } = params;\n const chainId = params.chainId ?? ctxChainId;\n const [isConnected, setIsConnected] = useState(false);\n\n useEffect(() => {\n if (!symmCoreClient || !accountAddress) {\n setIsConnected(false);\n return;\n }\n\n const ws = symmCoreClient.ws;\n const addr = accountAddress as string;\n const unsubscribers: UnsubscribeFn[] = [];\n\n const removeOnConnect = ws.onConnect(() => setIsConnected(true));\n const removeOnDisconnect = ws.onDisconnect(() => setIsConnected(false));\n\n // Subscribe to all relevant channels\n unsubscribers.push(removeOnConnect, removeOnDisconnect);\n const positionsUnsub = asUnsubscribeFn(ws.subscribeToPositions(addr, chainId, () => {\n queryClient.invalidateQueries({\n queryKey: symmKeys.positions(accountAddress, chainId),\n });\n }));\n if (positionsUnsub) unsubscribers.push(positionsUnsub);\n\n const openOrdersUnsub = asUnsubscribeFn(ws.subscribeToOpenOrders(addr, chainId, () => {\n queryClient.invalidateQueries({\n queryKey: symmKeys.openOrders(accountAddress, chainId),\n });\n }));\n if (openOrdersUnsub) unsubscribers.push(openOrdersUnsub);\n\n const tradesUnsub = asUnsubscribeFn(ws.subscribeToTrades(addr, chainId, () => {\n queryClient.invalidateQueries({\n queryKey: symmKeys.tradeHistory(accountAddress, chainId),\n });\n }));\n if (tradesUnsub) unsubscribers.push(tradesUnsub);\n\n const accountSummaryUnsub = asUnsubscribeFn(ws.subscribeToAccountSummary(addr, chainId, () => {\n queryClient.invalidateQueries({\n queryKey: symmKeys.balances(accountAddress, chainId),\n });\n queryClient.invalidateQueries({\n queryKey: symmKeys.accountSummary(accountAddress, chainId),\n });\n }));\n if (accountSummaryUnsub) unsubscribers.push(accountSummaryUnsub);\n\n const notificationsUnsub = asUnsubscribeFn(ws.subscribeToNotifications(addr, chainId, () => {\n queryClient.invalidateQueries({\n queryKey: symmKeys.notifications(accountAddress, chainId),\n });\n queryClient.invalidateQueries({\n queryKey: symmKeys.unreadCount(accountAddress, chainId),\n });\n }));\n if (notificationsUnsub) unsubscribers.push(notificationsUnsub);\n\n const tpslUnsub = asUnsubscribeFn(ws.subscribeToTpsl(addr, chainId, () => {\n queryClient.invalidateQueries({ queryKey: ['symm', 'tpslOrders'] });\n queryClient.invalidateQueries({ queryKey: ['symm', 'openOrders'] });\n }));\n if (tpslUnsub) unsubscribers.push(tpslUnsub);\n\n const twapUnsub = asUnsubscribeFn(ws.subscribeToTwapOrders(addr, chainId, () => {\n queryClient.invalidateQueries({ queryKey: ['symm', 'twapOrders'] });\n queryClient.invalidateQueries({ queryKey: ['symm', 'openOrders'] });\n }));\n if (twapUnsub) unsubscribers.push(twapUnsub);\n\n const triggerOrdersUnsub = asUnsubscribeFn(ws.subscribeToTriggerOrders(addr, chainId, () => {\n queryClient.invalidateQueries({ queryKey: ['symm', 'triggerOrders'] });\n queryClient.invalidateQueries({ queryKey: ['symm', 'openOrders'] });\n }));\n if (triggerOrdersUnsub) unsubscribers.push(triggerOrdersUnsub);\n\n const executionsUnsub = asUnsubscribeFn(ws.subscribeToExecutions(addr, chainId, () => {\n queryClient.invalidateQueries({\n queryKey: symmKeys.positions(accountAddress, chainId),\n });\n queryClient.invalidateQueries({\n queryKey: symmKeys.portfolio(accountAddress, chainId),\n });\n }));\n if (executionsUnsub) unsubscribers.push(executionsUnsub);\n\n return () => {\n if (unsubscribers.length > 2) {\n unsubscribers.forEach((unsubscribe) => unsubscribe());\n } else {\n removeOnConnect();\n removeOnDisconnect();\n ws.unsubscribeAll();\n }\n };\n }, [symmCoreClient, accountAddress, chainId, queryClient]);\n\n return { isConnected };\n}\n","import { useMemo } from \"react\";\nimport type { Address, PublicClient, WalletClient } from \"viem\";\nimport { createSymmSDK, type SymmSDK } from \"@pear-protocol/symm-core\";\n\nimport type { SymmioSDKConfig } from \"../types/common\";\nimport { SymmContext, type SymmContextValue } from \"./context\";\nimport { useSymmWs } from \"./hooks/use-symm-ws\";\n\ntype RefreshAuth = (accountAddress?: Address) => Promise<string | null>;\n\nexport type SymmProviderProps = {\n chainId?: number;\n address?: Address;\n publicClient?: PublicClient;\n walletClient?: WalletClient;\n accessToken?: string | null;\n authToken?: string | null;\n refreshAuth?: RefreshAuth;\n symmCoreConfig: {\n apiUrl: string;\n wsUrl?: string;\n };\n symmioConfig?: Partial<SymmioSDKConfig>;\n children: React.ReactNode;\n};\n\nconst noopRefreshAuth: RefreshAuth = async () => null;\n\nexport function SymmProvider({\n chainId = 42161,\n address,\n accessToken = null,\n authToken,\n refreshAuth = noopRefreshAuth,\n symmCoreConfig,\n symmioConfig,\n children,\n}: SymmProviderProps) {\n const symmCoreClient = useMemo((): SymmSDK => {\n return createSymmSDK({\n apiUrl: symmCoreConfig.apiUrl,\n wsUrl: symmCoreConfig.wsUrl,\n defaultChainId: chainId,\n });\n }, [chainId, symmCoreConfig.apiUrl, symmCoreConfig.wsUrl]);\n\n const resolvedAuthToken = authToken ?? accessToken;\n useSymmWs({ chainId });\n\n const value = useMemo<SymmContextValue>(\n () => ({\n symmCoreClient,\n chainId,\n address,\n symmioConfig,\n accessToken,\n authToken: resolvedAuthToken,\n refreshAuth,\n }),\n [\n symmCoreClient,\n chainId,\n address,\n symmioConfig,\n accessToken,\n resolvedAuthToken,\n refreshAuth,\n ]\n );\n\n return <SymmContext.Provider value={value}>{children}</SymmContext.Provider>;\n}\n"]}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { createContext, useMemo, useState, useEffect, useContext } from 'react';
|
|
2
|
+
import { createSymmSDK } from '@pear-protocol/symm-core';
|
|
3
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/react/provider.tsx
|
|
7
|
+
var SymmContext = createContext(null);
|
|
8
|
+
function useSymmContext() {
|
|
9
|
+
const ctx = useContext(SymmContext);
|
|
10
|
+
if (!ctx) {
|
|
11
|
+
throw new Error("useSymmContext must be used within <SymmProvider>");
|
|
12
|
+
}
|
|
13
|
+
return ctx;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/react/query-keys.ts
|
|
17
|
+
var symmKeys = {
|
|
18
|
+
all: ["symm"],
|
|
19
|
+
accounts: (address, chainId) => ["symm", "accounts", address, chainId],
|
|
20
|
+
accountsApi: (address, chainId) => ["symm", "accountsApi", address, chainId],
|
|
21
|
+
accountsLength: (address, chainId) => ["symm", "accountsLength", address, chainId],
|
|
22
|
+
accountsWithPositions: (address, chainId) => ["symm", "accountsWithPositions", address, chainId],
|
|
23
|
+
accountSummary: (address, chainId) => ["symm", "accountSummary", address, chainId],
|
|
24
|
+
accountData: (address, chainId) => ["symm", "accountData", address, chainId],
|
|
25
|
+
signature: (address, chainId) => ["symm", "signature", address, chainId],
|
|
26
|
+
approval: (owner, spender, chainId) => ["symm", "approval", owner, spender, chainId],
|
|
27
|
+
balances: (address, chainId) => ["symm", "balances", address, chainId],
|
|
28
|
+
positions: (address, chainId) => ["symm", "positions", address, chainId],
|
|
29
|
+
openOrders: (address, chainId) => ["symm", "openOrders", address, chainId],
|
|
30
|
+
tradeHistory: (address, chainId) => ["symm", "tradeHistory", address, chainId],
|
|
31
|
+
tpslOrders: (address, chainId) => ["symm", "tpslOrders", address, chainId],
|
|
32
|
+
tpslOrdersList: (params) => ["symm", "tpslOrders", params],
|
|
33
|
+
twapOrders: (address, chainId) => ["symm", "twapOrders", address, chainId],
|
|
34
|
+
triggerOrders: (params) => ["symm", "triggerOrders", params],
|
|
35
|
+
triggerConfig: (orderId) => ["symm", "triggerConfig", orderId],
|
|
36
|
+
markets: (chainId, search) => ["symm", "markets", chainId, search],
|
|
37
|
+
hedgerMarketById: (id, chainId) => ["symm", "hedgerMarketById", id, chainId],
|
|
38
|
+
hedgerMarketBySymbol: (symbol, chainId) => ["symm", "hedgerMarketBySymbol", symbol, chainId],
|
|
39
|
+
lockedParams: (marketName, leverage, chainId) => ["symm", "lockedParams", marketName, leverage, chainId],
|
|
40
|
+
hedgerMarkets: (request) => ["symm", "hedgerMarkets", request],
|
|
41
|
+
fundingRates: (chainId) => ["symm", "fundingRates", chainId],
|
|
42
|
+
fundingPayments: (params) => ["symm", "fundingPayments", params],
|
|
43
|
+
fundingHistory: (params) => ["symm", "fundingHistory", params],
|
|
44
|
+
portfolio: (address, chainId) => ["symm", "portfolio", address, chainId],
|
|
45
|
+
notifications: (address, chainId) => ["symm", "notifications", address, chainId],
|
|
46
|
+
unreadCount: (address, chainId) => ["symm", "unreadCount", address, chainId],
|
|
47
|
+
availableMargin: (address, chainId) => ["symm", "availableMargin", address, chainId],
|
|
48
|
+
pendingIds: (address, chainId) => ["symm", "pendingIds", address, chainId],
|
|
49
|
+
pendingInstantOpens: (accountAddress, chainId) => ["symm", "pendingInstantOpens", accountAddress, chainId],
|
|
50
|
+
twapOrder: (orderId) => ["symm", "twapOrder", orderId],
|
|
51
|
+
delegation: (account, target, selectors, chainId) => ["symm", "delegation", account, target, selectors, chainId],
|
|
52
|
+
chartMetadata: (symbolsKey, positionKey) => ["symm", "chartMetadata", symbolsKey, positionKey]
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/react/hooks/use-symm-ws.ts
|
|
56
|
+
function asUnsubscribeFn(value) {
|
|
57
|
+
return typeof value === "function" ? value : null;
|
|
58
|
+
}
|
|
59
|
+
function useSymmWs(params) {
|
|
60
|
+
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
61
|
+
const queryClient = useQueryClient();
|
|
62
|
+
const { accountAddress } = params;
|
|
63
|
+
const chainId = params.chainId ?? ctxChainId;
|
|
64
|
+
const [isConnected, setIsConnected] = useState(false);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!symmCoreClient || !accountAddress) {
|
|
67
|
+
setIsConnected(false);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const ws = symmCoreClient.ws;
|
|
71
|
+
const addr = accountAddress;
|
|
72
|
+
const unsubscribers = [];
|
|
73
|
+
const removeOnConnect = ws.onConnect(() => setIsConnected(true));
|
|
74
|
+
const removeOnDisconnect = ws.onDisconnect(() => setIsConnected(false));
|
|
75
|
+
unsubscribers.push(removeOnConnect, removeOnDisconnect);
|
|
76
|
+
const positionsUnsub = asUnsubscribeFn(ws.subscribeToPositions(addr, chainId, () => {
|
|
77
|
+
queryClient.invalidateQueries({
|
|
78
|
+
queryKey: symmKeys.positions(accountAddress, chainId)
|
|
79
|
+
});
|
|
80
|
+
}));
|
|
81
|
+
if (positionsUnsub) unsubscribers.push(positionsUnsub);
|
|
82
|
+
const openOrdersUnsub = asUnsubscribeFn(ws.subscribeToOpenOrders(addr, chainId, () => {
|
|
83
|
+
queryClient.invalidateQueries({
|
|
84
|
+
queryKey: symmKeys.openOrders(accountAddress, chainId)
|
|
85
|
+
});
|
|
86
|
+
}));
|
|
87
|
+
if (openOrdersUnsub) unsubscribers.push(openOrdersUnsub);
|
|
88
|
+
const tradesUnsub = asUnsubscribeFn(ws.subscribeToTrades(addr, chainId, () => {
|
|
89
|
+
queryClient.invalidateQueries({
|
|
90
|
+
queryKey: symmKeys.tradeHistory(accountAddress, chainId)
|
|
91
|
+
});
|
|
92
|
+
}));
|
|
93
|
+
if (tradesUnsub) unsubscribers.push(tradesUnsub);
|
|
94
|
+
const accountSummaryUnsub = asUnsubscribeFn(ws.subscribeToAccountSummary(addr, chainId, () => {
|
|
95
|
+
queryClient.invalidateQueries({
|
|
96
|
+
queryKey: symmKeys.balances(accountAddress, chainId)
|
|
97
|
+
});
|
|
98
|
+
queryClient.invalidateQueries({
|
|
99
|
+
queryKey: symmKeys.accountSummary(accountAddress, chainId)
|
|
100
|
+
});
|
|
101
|
+
}));
|
|
102
|
+
if (accountSummaryUnsub) unsubscribers.push(accountSummaryUnsub);
|
|
103
|
+
const notificationsUnsub = asUnsubscribeFn(ws.subscribeToNotifications(addr, chainId, () => {
|
|
104
|
+
queryClient.invalidateQueries({
|
|
105
|
+
queryKey: symmKeys.notifications(accountAddress, chainId)
|
|
106
|
+
});
|
|
107
|
+
queryClient.invalidateQueries({
|
|
108
|
+
queryKey: symmKeys.unreadCount(accountAddress, chainId)
|
|
109
|
+
});
|
|
110
|
+
}));
|
|
111
|
+
if (notificationsUnsub) unsubscribers.push(notificationsUnsub);
|
|
112
|
+
const tpslUnsub = asUnsubscribeFn(ws.subscribeToTpsl(addr, chainId, () => {
|
|
113
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "tpslOrders"] });
|
|
114
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
115
|
+
}));
|
|
116
|
+
if (tpslUnsub) unsubscribers.push(tpslUnsub);
|
|
117
|
+
const twapUnsub = asUnsubscribeFn(ws.subscribeToTwapOrders(addr, chainId, () => {
|
|
118
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "twapOrders"] });
|
|
119
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
120
|
+
}));
|
|
121
|
+
if (twapUnsub) unsubscribers.push(twapUnsub);
|
|
122
|
+
const triggerOrdersUnsub = asUnsubscribeFn(ws.subscribeToTriggerOrders(addr, chainId, () => {
|
|
123
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "triggerOrders"] });
|
|
124
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
|
|
125
|
+
}));
|
|
126
|
+
if (triggerOrdersUnsub) unsubscribers.push(triggerOrdersUnsub);
|
|
127
|
+
const executionsUnsub = asUnsubscribeFn(ws.subscribeToExecutions(addr, chainId, () => {
|
|
128
|
+
queryClient.invalidateQueries({
|
|
129
|
+
queryKey: symmKeys.positions(accountAddress, chainId)
|
|
130
|
+
});
|
|
131
|
+
queryClient.invalidateQueries({
|
|
132
|
+
queryKey: symmKeys.portfolio(accountAddress, chainId)
|
|
133
|
+
});
|
|
134
|
+
}));
|
|
135
|
+
if (executionsUnsub) unsubscribers.push(executionsUnsub);
|
|
136
|
+
return () => {
|
|
137
|
+
if (unsubscribers.length > 2) {
|
|
138
|
+
unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
139
|
+
} else {
|
|
140
|
+
removeOnConnect();
|
|
141
|
+
removeOnDisconnect();
|
|
142
|
+
ws.unsubscribeAll();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}, [symmCoreClient, accountAddress, chainId, queryClient]);
|
|
146
|
+
return { isConnected };
|
|
147
|
+
}
|
|
148
|
+
var noopRefreshAuth = async () => null;
|
|
149
|
+
function SymmProvider({
|
|
150
|
+
chainId = 42161,
|
|
151
|
+
address,
|
|
152
|
+
accessToken = null,
|
|
153
|
+
authToken,
|
|
154
|
+
refreshAuth = noopRefreshAuth,
|
|
155
|
+
symmCoreConfig,
|
|
156
|
+
symmioConfig,
|
|
157
|
+
children
|
|
158
|
+
}) {
|
|
159
|
+
const symmCoreClient = useMemo(() => {
|
|
160
|
+
return createSymmSDK({
|
|
161
|
+
apiUrl: symmCoreConfig.apiUrl,
|
|
162
|
+
wsUrl: symmCoreConfig.wsUrl,
|
|
163
|
+
defaultChainId: chainId
|
|
164
|
+
});
|
|
165
|
+
}, [chainId, symmCoreConfig.apiUrl, symmCoreConfig.wsUrl]);
|
|
166
|
+
const resolvedAuthToken = authToken ?? accessToken;
|
|
167
|
+
useSymmWs({ chainId });
|
|
168
|
+
const value = useMemo(
|
|
169
|
+
() => ({
|
|
170
|
+
symmCoreClient,
|
|
171
|
+
chainId,
|
|
172
|
+
address,
|
|
173
|
+
symmioConfig,
|
|
174
|
+
accessToken,
|
|
175
|
+
authToken: resolvedAuthToken,
|
|
176
|
+
refreshAuth
|
|
177
|
+
}),
|
|
178
|
+
[
|
|
179
|
+
symmCoreClient,
|
|
180
|
+
chainId,
|
|
181
|
+
address,
|
|
182
|
+
symmioConfig,
|
|
183
|
+
accessToken,
|
|
184
|
+
resolvedAuthToken,
|
|
185
|
+
refreshAuth
|
|
186
|
+
]
|
|
187
|
+
);
|
|
188
|
+
return /* @__PURE__ */ jsx(SymmContext.Provider, { value, children });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export { SymmProvider };
|
|
192
|
+
//# sourceMappingURL=provider.mjs.map
|
|
193
|
+
//# sourceMappingURL=provider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react/context.ts","../../src/react/query-keys.ts","../../src/react/hooks/use-symm-ws.ts","../../src/react/provider.tsx"],"names":[],"mappings":";;;;;;AAeO,IAAM,WAAA,GAAc,cAAuC,IAAI,CAAA;AAE/D,SAAS,cAAA,GAAmC;AACjD,EAAA,MAAM,GAAA,GAAM,WAAW,WAAW,CAAA;AAClC,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,MAAM,mDAAmD,CAAA;AAAA,EACrE;AACA,EAAA,OAAO,GAAA;AACT;;;ACpBO,IAAM,QAAA,GAAW;AAAA,EACtB,GAAA,EAAK,CAAC,MAAM,CAAA;AAAA,EACZ,QAAA,EAAU,CAAC,OAAA,EAAmB,OAAA,KAC5B,CAAC,MAAA,EAAQ,UAAA,EAAY,SAAS,OAAO,CAAA;AAAA,EACvC,WAAA,EAAa,CAAC,OAAA,EAAmB,OAAA,KAC/B,CAAC,MAAA,EAAQ,aAAA,EAAe,SAAS,OAAO,CAAA;AAAA,EAC1C,cAAA,EAAgB,CAAC,OAAA,EAAmB,OAAA,KAClC,CAAC,MAAA,EAAQ,gBAAA,EAAkB,SAAS,OAAO,CAAA;AAAA,EAC7C,qBAAA,EAAuB,CAAC,OAAA,EAAmB,OAAA,KACzC,CAAC,MAAA,EAAQ,uBAAA,EAAyB,SAAS,OAAO,CAAA;AAAA,EACpD,cAAA,EAAgB,CAAC,OAAA,EAAmB,OAAA,KAClC,CAAC,MAAA,EAAQ,gBAAA,EAAkB,SAAS,OAAO,CAAA;AAAA,EAC7C,WAAA,EAAa,CAAC,OAAA,EAAmB,OAAA,KAC/B,CAAC,MAAA,EAAQ,aAAA,EAAe,SAAS,OAAO,CAAA;AAAA,EAC1C,SAAA,EAAW,CAAC,OAAA,E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AAA,EAAgB,cAAA,EAAgB,OAAA,EAAS,WAAW,CAAC,CAAA;AAEzD,EAAA,OAAO,EAAE,WAAA,EAAY;AACvB;AC5FA,IAAM,kBAA+B,YAAY,IAAA;AAE1C,SAAS,YAAA,CAAa;AAAA,EAC3B,OAAA,GAAU,KAAA;AAAA,EACV,OAAA;AAAA,EACA,WAAA,GAAc,IAAA;AAAA,EACd,SAAA;AAAA,EACA,WAAA,GAAc,eAAA;AAAA,EACd,cAAA;AAAA,EACA,YAAA;AAAA,EACA;AACF,CAAA,EAAsB;AACpB,EAAA,MAAM,cAAA,GAAiB,QAAQ,MAAe;AAC5C,IAAA,OAAO,aAAA,CAAc;AAAA,MACnB,QAAQ,cAAA,CAAe,MAAA;AAAA,MACvB,OAAO,cAAA,CAAe,KAAA;AAAA,MACtB,cAAA,EAAgB;AAAA,KACjB,CAAA;AAAA,EACH,GAAG,CAAC,OAAA,EAAS,eAAe,MAAA,EAAQ,cAAA,CAAe,KAAK,CAAC,CAAA;AAEzD,EAAA,MAAM,oBAAoB,SAAA,IAAa,WAAA;AACvC,EAAA,SAAA,CAAU,EAAE,SAAS,CAAA;AAErB,EAAA,MAAM,KAAA,GAAQ,OAAA;AAAA,IACZ,OAAO;AAAA,MACL,cAAA;AAAA,MACA,OAAA;AAAA,MACA,OAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA;AAAA,MACA,SAAA,EAAW,iBAAA;AAAA,MACX;AAAA,KACF,CAAA;AAAA,IACA;AAAA,MACE,cAAA;AAAA,MACA,OAAA;AAAA,MACA,OAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA;AAAA,MACA,iBAAA;AAAA,MACA;AAAA;AACF,GACF;AAEA,EAAA,uBAAO,GAAA,CAAC,WAAA,CAAY,QAAA,EAAZ,EAAqB,OAAe,QAAA,EAAS,CAAA;AACvD","file":"provider.mjs","sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { Address, PublicClient, WalletClient } from \"viem\";\nimport type { SymmSDK } from \"@pear-protocol/symm-core\";\nimport type { SymmioSDKConfig } from \"../types/common\";\n\nexport type SymmContextValue = {\n symmCoreClient: SymmSDK | null;\n chainId: number;\n address?: `0x${string}`;\n symmioConfig?: Partial<SymmioSDKConfig>;\n accessToken: string | null;\n authToken: string | null;\n refreshAuth: (accountAddress?: Address) => Promise<string | null>;\n};\n\nexport const SymmContext = createContext<SymmContextValue | null>(null);\n\nexport function useSymmContext(): SymmContextValue {\n const ctx = useContext(SymmContext);\n if (!ctx) {\n throw new Error(\"useSymmContext must be used within <SymmProvider>\");\n }\n return ctx;\n}\n","import type { GetSymmHedgerMarketsRequest } from '@pear-protocol/symm-core';\nimport type { Address, Hex } from 'viem';\n\nexport const symmKeys = {\n all: ['symm'] as const,\n accounts: (address?: Address, chainId?: number) =>\n ['symm', 'accounts', address, chainId] as const,\n accountsApi: (address?: Address, chainId?: number) =>\n ['symm', 'accountsApi', address, chainId] as const,\n accountsLength: (address?: Address, chainId?: number) =>\n ['symm', 'accountsLength', address, chainId] as const,\n accountsWithPositions: (address?: Address, chainId?: number) =>\n ['symm', 'accountsWithPositions', address, chainId] as const,\n accountSummary: (address?: Address, chainId?: number) =>\n ['symm', 'accountSummary', address, chainId] as const,\n accountData: (address?: Address, chainId?: number) =>\n ['symm', 'accountData', address, chainId] as const,\n signature: (address?: Address, chainId?: number) =>\n ['symm', 'signature', address, chainId] as const,\n approval: (owner?: Address, spender?: Address, chainId?: number) =>\n ['symm', 'approval', owner, spender, chainId] as const,\n balances: (address?: Address, chainId?: number) =>\n ['symm', 'balances', address, chainId] as const,\n positions: (address?: Address, chainId?: number) =>\n ['symm', 'positions', address, chainId] as const,\n openOrders: (address?: Address, chainId?: number) =>\n ['symm', 'openOrders', address, chainId] as const,\n tradeHistory: (address?: Address, chainId?: number) =>\n ['symm', 'tradeHistory', address, chainId] as const,\n tpslOrders: (address?: Address, chainId?: number) =>\n ['symm', 'tpslOrders', address, chainId] as const,\n tpslOrdersList: (params?: {\n accountAddress?: Address;\n mainAddress?: Address;\n positionId?: string;\n type?: string;\n status?: string;\n chainId?: number;\n }) => ['symm', 'tpslOrders', params] as const,\n twapOrders: (address?: Address, chainId?: number) =>\n ['symm', 'twapOrders', address, chainId] as const,\n triggerOrders: (params?: {\n accountAddress?: Address;\n mainAddress?: Address;\n status?: string;\n limit?: number;\n offset?: number;\n chainId?: number;\n }) => ['symm', 'triggerOrders', params] as const,\n triggerConfig: (orderId?: string) =>\n ['symm', 'triggerConfig', orderId] as const,\n markets: (chainId?: number, search?: string) =>\n ['symm', 'markets', chainId, search] as const,\n hedgerMarketById: (id?: number, chainId?: number) =>\n ['symm', 'hedgerMarketById', id, chainId] as const,\n hedgerMarketBySymbol: (symbol?: string, chainId?: number) =>\n ['symm', 'hedgerMarketBySymbol', symbol, chainId] as const,\n lockedParams: (marketName?: string, leverage?: number, chainId?: number) =>\n ['symm', 'lockedParams', marketName, leverage, chainId] as const,\n hedgerMarkets: (request?: GetSymmHedgerMarketsRequest) =>\n ['symm', 'hedgerMarkets', request] as const,\n fundingRates: (chainId?: number) => ['symm', 'fundingRates', chainId] as const,\n fundingPayments: (params?: {\n address?: Address;\n positionId?: string;\n chainId?: number;\n limit?: number;\n offset?: number;\n }) => ['symm', 'fundingPayments', params] as const,\n fundingHistory: (params?: {\n chainId?: number;\n period?: string;\n longSymbols?: string;\n shortSymbols?: string;\n interval?: string;\n weightMode?: string;\n includeContributions?: boolean;\n }) => ['symm', 'fundingHistory', params] as const,\n portfolio: (address?: Address, chainId?: number) =>\n ['symm', 'portfolio', address, chainId] as const,\n notifications: (address?: Address, chainId?: number) =>\n ['symm', 'notifications', address, chainId] as const,\n unreadCount: (address?: Address, chainId?: number) =>\n ['symm', 'unreadCount', address, chainId] as const,\n availableMargin: (address?: Address, chainId?: number) =>\n ['symm', 'availableMargin', address, chainId] as const,\n pendingIds: (address?: Address, chainId?: number) =>\n ['symm', 'pendingIds', address, chainId] as const,\n pendingInstantOpens: (accountAddress?: Address, chainId?: number) =>\n ['symm', 'pendingInstantOpens', accountAddress, chainId] as const,\n twapOrder: (orderId?: string) =>\n ['symm', 'twapOrder', orderId] as const,\n delegation: (\n account?: Address,\n target?: Address,\n selectors?: readonly Hex[],\n chainId?: number\n ) => ['symm', 'delegation', account, target, selectors, chainId] as const,\n chartMetadata: (symbolsKey: string, positionKey: string) =>\n ['symm', 'chartMetadata', symbolsKey, positionKey] as const,\n};\n","import { useEffect, useState } from 'react';\nimport { useQueryClient } from '@tanstack/react-query';\nimport type { Address } from 'viem';\nimport { useSymmContext } from '../context';\nimport { symmKeys } from '../query-keys';\n\ntype UnsubscribeFn = () => void;\n\nfunction asUnsubscribeFn(value: unknown): UnsubscribeFn | null {\n return typeof value === 'function' ? (value as UnsubscribeFn) : null;\n}\n\nexport function useSymmWs(params: {\n accountAddress?: Address;\n chainId?: number;\n}) {\n const { symmCoreClient, chainId: ctxChainId } = useSymmContext();\n const queryClient = useQueryClient();\n const { accountAddress } = params;\n const chainId = params.chainId ?? ctxChainId;\n const [isConnected, setIsConnected] = useState(false);\n\n useEffect(() => {\n if (!symmCoreClient || !accountAddress) {\n setIsConnected(false);\n return;\n }\n\n const ws = symmCoreClient.ws;\n const addr = accountAddress as string;\n const unsubscribers: UnsubscribeFn[] = [];\n\n const removeOnConnect = ws.onConnect(() => setIsConnected(true));\n const removeOnDisconnect = ws.onDisconnect(() => setIsConnected(false));\n\n // Subscribe to all relevant channels\n unsubscribers.push(removeOnConnect, removeOnDisconnect);\n const positionsUnsub = asUnsubscribeFn(ws.subscribeToPositions(addr, chainId, () => {\n queryClient.invalidateQueries({\n queryKey: symmKeys.positions(accountAddress, chainId),\n });\n }));\n if (positionsUnsub) unsubscribers.push(positionsUnsub);\n\n const openOrdersUnsub = asUnsubscribeFn(ws.subscribeToOpenOrders(addr, chainId, () => {\n queryClient.invalidateQueries({\n queryKey: symmKeys.openOrders(accountAddress, chainId),\n });\n }));\n if (openOrdersUnsub) unsubscribers.push(openOrdersUnsub);\n\n const tradesUnsub = asUnsubscribeFn(ws.subscribeToTrades(addr, chainId, () => {\n queryClient.invalidateQueries({\n queryKey: symmKeys.tradeHistory(accountAddress, chainId),\n });\n }));\n if (tradesUnsub) unsubscribers.push(tradesUnsub);\n\n const accountSummaryUnsub = asUnsubscribeFn(ws.subscribeToAccountSummary(addr, chainId, () => {\n queryClient.invalidateQueries({\n queryKey: symmKeys.balances(accountAddress, chainId),\n });\n queryClient.invalidateQueries({\n queryKey: symmKeys.accountSummary(accountAddress, chainId),\n });\n }));\n if (accountSummaryUnsub) unsubscribers.push(accountSummaryUnsub);\n\n const notificationsUnsub = asUnsubscribeFn(ws.subscribeToNotifications(addr, chainId, () => {\n queryClient.invalidateQueries({\n queryKey: symmKeys.notifications(accountAddress, chainId),\n });\n queryClient.invalidateQueries({\n queryKey: symmKeys.unreadCount(accountAddress, chainId),\n });\n }));\n if (notificationsUnsub) unsubscribers.push(notificationsUnsub);\n\n const tpslUnsub = asUnsubscribeFn(ws.subscribeToTpsl(addr, chainId, () => {\n queryClient.invalidateQueries({ queryKey: ['symm', 'tpslOrders'] });\n queryClient.invalidateQueries({ queryKey: ['symm', 'openOrders'] });\n }));\n if (tpslUnsub) unsubscribers.push(tpslUnsub);\n\n const twapUnsub = asUnsubscribeFn(ws.subscribeToTwapOrders(addr, chainId, () => {\n queryClient.invalidateQueries({ queryKey: ['symm', 'twapOrders'] });\n queryClient.invalidateQueries({ queryKey: ['symm', 'openOrders'] });\n }));\n if (twapUnsub) unsubscribers.push(twapUnsub);\n\n const triggerOrdersUnsub = asUnsubscribeFn(ws.subscribeToTriggerOrders(addr, chainId, () => {\n queryClient.invalidateQueries({ queryKey: ['symm', 'triggerOrders'] });\n queryClient.invalidateQueries({ queryKey: ['symm', 'openOrders'] });\n }));\n if (triggerOrdersUnsub) unsubscribers.push(triggerOrdersUnsub);\n\n const executionsUnsub = asUnsubscribeFn(ws.subscribeToExecutions(addr, chainId, () => {\n queryClient.invalidateQueries({\n queryKey: symmKeys.positions(accountAddress, chainId),\n });\n queryClient.invalidateQueries({\n queryKey: symmKeys.portfolio(accountAddress, chainId),\n });\n }));\n if (executionsUnsub) unsubscribers.push(executionsUnsub);\n\n return () => {\n if (unsubscribers.length > 2) {\n unsubscribers.forEach((unsubscribe) => unsubscribe());\n } else {\n removeOnConnect();\n removeOnDisconnect();\n ws.unsubscribeAll();\n }\n };\n }, [symmCoreClient, accountAddress, chainId, queryClient]);\n\n return { isConnected };\n}\n","import { useMemo } from \"react\";\nimport type { Address, PublicClient, WalletClient } from \"viem\";\nimport { createSymmSDK, type SymmSDK } from \"@pear-protocol/symm-core\";\n\nimport type { SymmioSDKConfig } from \"../types/common\";\nimport { SymmContext, type SymmContextValue } from \"./context\";\nimport { useSymmWs } from \"./hooks/use-symm-ws\";\n\ntype RefreshAuth = (accountAddress?: Address) => Promise<string | null>;\n\nexport type SymmProviderProps = {\n chainId?: number;\n address?: Address;\n publicClient?: PublicClient;\n walletClient?: WalletClient;\n accessToken?: string | null;\n authToken?: string | null;\n refreshAuth?: RefreshAuth;\n symmCoreConfig: {\n apiUrl: string;\n wsUrl?: string;\n };\n symmioConfig?: Partial<SymmioSDKConfig>;\n children: React.ReactNode;\n};\n\nconst noopRefreshAuth: RefreshAuth = async () => null;\n\nexport function SymmProvider({\n chainId = 42161,\n address,\n accessToken = null,\n authToken,\n refreshAuth = noopRefreshAuth,\n symmCoreConfig,\n symmioConfig,\n children,\n}: SymmProviderProps) {\n const symmCoreClient = useMemo((): SymmSDK => {\n return createSymmSDK({\n apiUrl: symmCoreConfig.apiUrl,\n wsUrl: symmCoreConfig.wsUrl,\n defaultChainId: chainId,\n });\n }, [chainId, symmCoreConfig.apiUrl, symmCoreConfig.wsUrl]);\n\n const resolvedAuthToken = authToken ?? accessToken;\n useSymmWs({ chainId });\n\n const value = useMemo<SymmContextValue>(\n () => ({\n symmCoreClient,\n chainId,\n address,\n symmioConfig,\n accessToken,\n authToken: resolvedAuthToken,\n refreshAuth,\n }),\n [\n symmCoreClient,\n chainId,\n address,\n symmioConfig,\n accessToken,\n resolvedAuthToken,\n refreshAuth,\n ]\n );\n\n return <SymmContext.Provider value={value}>{children}</SymmContext.Provider>;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/symmio-client",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Standalone SDK for Symmio — account management, trading, deposits, withdrawals, and protocol interactions via MultiAccount",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
"types": "./dist/react/index.d.ts",
|
|
16
16
|
"import": "./dist/react/index.mjs",
|
|
17
17
|
"require": "./dist/react/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./react/provider": {
|
|
20
|
+
"types": "./dist/react/provider.d.ts",
|
|
21
|
+
"import": "./dist/react/provider.mjs",
|
|
22
|
+
"require": "./dist/react/provider.js"
|
|
18
23
|
}
|
|
19
24
|
},
|
|
20
25
|
"files": [
|
|
@@ -90,7 +95,7 @@
|
|
|
90
95
|
"node": ">=18"
|
|
91
96
|
},
|
|
92
97
|
"dependencies": {
|
|
93
|
-
"@pear-protocol/symm-core": "^0.1.
|
|
98
|
+
"@pear-protocol/symm-core": "^0.1.6",
|
|
94
99
|
"@pear-protocol/symm-shared": "^0.1.2"
|
|
95
100
|
}
|
|
96
101
|
}
|