@pear-protocol/symmio-client 0.2.8 → 0.2.10
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 +16 -17
- package/dist/react/index.d.ts +16 -17
- package/dist/react/index.js +45 -44
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +45 -44
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/{provider-xhUge8b7.d.mts → provider-BoNiSPy9.d.mts} +2 -8
- package/dist/react/{provider-xhUge8b7.d.ts → provider-BoNiSPy9.d.ts} +2 -8
- package/dist/react/provider.d.mts +1 -1
- package/dist/react/provider.d.ts +1 -1
- package/dist/react/provider.js +14 -20
- package/dist/react/provider.js.map +1 -1
- package/dist/react/provider.mjs +15 -21
- package/dist/react/provider.mjs.map +1 -1
- package/package.json +3 -3
package/dist/react/index.mjs
CHANGED
|
@@ -62,11 +62,14 @@ var useSymmWsStore = create((set) => ({
|
|
|
62
62
|
function asUnsubscribeFn(value) {
|
|
63
63
|
return typeof value === "function" ? value : null;
|
|
64
64
|
}
|
|
65
|
-
function useSymmWs(params) {
|
|
65
|
+
function useSymmWs(params = {}) {
|
|
66
|
+
const { symmCoreClient: ctxClient, address: ctxAddress, chainId: ctxChainId } = useSymmContext();
|
|
66
67
|
const queryClient = useQueryClient();
|
|
67
68
|
const isConnected = useSymmWsStore((state) => state.isConnected);
|
|
68
69
|
const setConnected = useSymmWsStore((state) => state.setConnected);
|
|
69
|
-
const
|
|
70
|
+
const symmCoreClient = params.symmCoreClient ?? ctxClient;
|
|
71
|
+
const accountAddress = params.accountAddress ?? ctxAddress;
|
|
72
|
+
const chainId = params.chainId ?? ctxChainId;
|
|
70
73
|
useEffect(() => {
|
|
71
74
|
if (!symmCoreClient || !accountAddress) {
|
|
72
75
|
setConnected(false);
|
|
@@ -150,13 +153,9 @@ function useSymmWs(params) {
|
|
|
150
153
|
}, [symmCoreClient, accountAddress, chainId, queryClient, setConnected]);
|
|
151
154
|
return { isConnected };
|
|
152
155
|
}
|
|
153
|
-
var noopRefreshAuth = async () => null;
|
|
154
156
|
function SymmProvider({
|
|
155
157
|
chainId = 42161,
|
|
156
158
|
address,
|
|
157
|
-
accessToken = null,
|
|
158
|
-
authToken,
|
|
159
|
-
refreshAuth = noopRefreshAuth,
|
|
160
159
|
symmCoreConfig,
|
|
161
160
|
symmioConfig,
|
|
162
161
|
children
|
|
@@ -168,27 +167,15 @@ function SymmProvider({
|
|
|
168
167
|
defaultChainId: chainId
|
|
169
168
|
});
|
|
170
169
|
}, [chainId, symmCoreConfig.apiUrl, symmCoreConfig.wsUrl]);
|
|
171
|
-
const resolvedAuthToken = authToken ?? accessToken;
|
|
172
170
|
useSymmWs({ symmCoreClient, accountAddress: address, chainId });
|
|
173
171
|
const value = useMemo(
|
|
174
172
|
() => ({
|
|
175
173
|
symmCoreClient,
|
|
176
174
|
chainId,
|
|
177
175
|
address,
|
|
178
|
-
symmioConfig
|
|
179
|
-
accessToken,
|
|
180
|
-
authToken: resolvedAuthToken,
|
|
181
|
-
refreshAuth
|
|
176
|
+
symmioConfig
|
|
182
177
|
}),
|
|
183
|
-
[
|
|
184
|
-
symmCoreClient,
|
|
185
|
-
chainId,
|
|
186
|
-
address,
|
|
187
|
-
symmioConfig,
|
|
188
|
-
accessToken,
|
|
189
|
-
resolvedAuthToken,
|
|
190
|
-
refreshAuth
|
|
191
|
-
]
|
|
178
|
+
[symmCoreClient, chainId, address, symmioConfig]
|
|
192
179
|
);
|
|
193
180
|
return /* @__PURE__ */ jsx(SymmContext.Provider, { value, children });
|
|
194
181
|
}
|
|
@@ -409,10 +396,17 @@ var useSymmAuthStore = create((set, get) => ({
|
|
|
409
396
|
|
|
410
397
|
// src/react/hooks/use-symm-auth.ts
|
|
411
398
|
function useSymmAuth(params) {
|
|
412
|
-
const
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
|
|
399
|
+
const ctx = useSymmContext();
|
|
400
|
+
const address = params?.address ?? ctx.address;
|
|
401
|
+
const chainId = params?.chainId ?? ctx.chainId ?? 42161;
|
|
402
|
+
const walletClient = params?.walletClient ?? ctx.walletClient;
|
|
403
|
+
const siweDomain = params?.siweDomain;
|
|
404
|
+
const accessToken = useSymmAuthStore((state) => {
|
|
405
|
+
if (address) {
|
|
406
|
+
return state.tokensByKey[symmAuthTokenKey(address, chainId)] ?? null;
|
|
407
|
+
}
|
|
408
|
+
return ctx.accessToken ?? ctx.authToken ?? null;
|
|
409
|
+
});
|
|
416
410
|
const setToken = useSymmAuthStore((state) => state.setToken);
|
|
417
411
|
const getToken = useSymmAuthStore((state) => state.getToken);
|
|
418
412
|
const clearToken = useSymmAuthStore((state) => state.clearToken);
|
|
@@ -1061,8 +1055,7 @@ function useSymmInstantTrade(params) {
|
|
|
1061
1055
|
symmCoreClient,
|
|
1062
1056
|
chainId,
|
|
1063
1057
|
address,
|
|
1064
|
-
symmioConfig
|
|
1065
|
-
refreshAuth
|
|
1058
|
+
symmioConfig
|
|
1066
1059
|
} = useSymmContext();
|
|
1067
1060
|
const { publicClient, walletClient } = params;
|
|
1068
1061
|
const queryClient = useQueryClient();
|
|
@@ -1088,9 +1081,9 @@ function useSymmInstantTrade(params) {
|
|
|
1088
1081
|
if (selectors.length === 0) {
|
|
1089
1082
|
throw new Error("at least one delegation selector is required");
|
|
1090
1083
|
}
|
|
1091
|
-
const accessToken = useSymmAuthStore.getState().getToken(accountAddress, chainId)
|
|
1084
|
+
const accessToken = useSymmAuthStore.getState().getToken(accountAddress, chainId);
|
|
1092
1085
|
if (!accessToken) {
|
|
1093
|
-
throw new Error("
|
|
1086
|
+
throw new Error("auth token is required for instant trading");
|
|
1094
1087
|
}
|
|
1095
1088
|
const accessStates = await Promise.all(
|
|
1096
1089
|
selectors.map(
|
|
@@ -1204,7 +1197,7 @@ async function getAccounts(publicClient, multiAccount, user, start = 0, size = 1
|
|
|
1204
1197
|
|
|
1205
1198
|
// src/react/hooks/use-symm-accounts.ts
|
|
1206
1199
|
var EMPTY_ACCOUNTS = [];
|
|
1207
|
-
function useSymmAccounts(params, options) {
|
|
1200
|
+
function useSymmAccounts(params = {}, options) {
|
|
1208
1201
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1209
1202
|
const { userAddress, publicClient, walletClient } = params;
|
|
1210
1203
|
const queryClient = useQueryClient();
|
|
@@ -1475,7 +1468,7 @@ function useSymmApproval(params) {
|
|
|
1475
1468
|
};
|
|
1476
1469
|
}
|
|
1477
1470
|
function useSymmCancelClose() {
|
|
1478
|
-
const { symmCoreClient,
|
|
1471
|
+
const { symmCoreClient, chainId, address } = useSymmContext();
|
|
1479
1472
|
const queryClient = useQueryClient();
|
|
1480
1473
|
const cancelClose = useMutation({
|
|
1481
1474
|
mutationFn: async ({
|
|
@@ -1487,14 +1480,16 @@ function useSymmCancelClose() {
|
|
|
1487
1480
|
if (!symmCoreClient) {
|
|
1488
1481
|
throw new Error("symm-core client not available");
|
|
1489
1482
|
}
|
|
1490
|
-
const
|
|
1483
|
+
const resolvedAccountAddress = accountAddress ?? address;
|
|
1484
|
+
const resolvedChainId = overrideChainId ?? chainId;
|
|
1485
|
+
const resolvedAuthToken = authToken ?? (resolvedAccountAddress ? useSymmAuthStore.getState().getToken(resolvedAccountAddress, resolvedChainId) : null);
|
|
1491
1486
|
if (!resolvedAuthToken) {
|
|
1492
1487
|
throw new Error("auth token is required to cancel a pending close");
|
|
1493
1488
|
}
|
|
1494
1489
|
return symmCoreClient.orders.cancelClose({
|
|
1495
1490
|
quoteId,
|
|
1496
1491
|
authToken: resolvedAuthToken,
|
|
1497
|
-
chainId:
|
|
1492
|
+
chainId: resolvedChainId
|
|
1498
1493
|
});
|
|
1499
1494
|
},
|
|
1500
1495
|
onSuccess: () => {
|
|
@@ -1505,7 +1500,7 @@ function useSymmCancelClose() {
|
|
|
1505
1500
|
return { cancelClose };
|
|
1506
1501
|
}
|
|
1507
1502
|
function useSymmCloseOrder() {
|
|
1508
|
-
const { symmCoreClient,
|
|
1503
|
+
const { symmCoreClient, address, chainId } = useSymmContext();
|
|
1509
1504
|
const queryClient = useQueryClient();
|
|
1510
1505
|
const closeOrder = useMutation({
|
|
1511
1506
|
mutationFn: async (request) => {
|
|
@@ -1515,7 +1510,7 @@ function useSymmCloseOrder() {
|
|
|
1515
1510
|
return symmCoreClient.orders.close(request.id, {
|
|
1516
1511
|
kind: request.kind,
|
|
1517
1512
|
type: request.type,
|
|
1518
|
-
authToken: request.authToken ??
|
|
1513
|
+
authToken: request.authToken ?? (address ? useSymmAuthStore.getState().getToken(address, chainId) ?? void 0 : void 0)
|
|
1519
1514
|
});
|
|
1520
1515
|
},
|
|
1521
1516
|
onSuccess: () => {
|
|
@@ -1577,7 +1572,7 @@ async function depositAndAllocate(walletClient, publicClient, multiAccount, para
|
|
|
1577
1572
|
}
|
|
1578
1573
|
|
|
1579
1574
|
// src/react/hooks/use-symm-deposit.ts
|
|
1580
|
-
function useSymmDeposit(params) {
|
|
1575
|
+
function useSymmDeposit(params = {}) {
|
|
1581
1576
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1582
1577
|
const { publicClient, walletClient } = params;
|
|
1583
1578
|
const queryClient = useQueryClient();
|
|
@@ -1637,7 +1632,7 @@ async function withdraw(walletClient, publicClient, multiAccount, params) {
|
|
|
1637
1632
|
}
|
|
1638
1633
|
|
|
1639
1634
|
// src/react/hooks/use-symm-withdraw.ts
|
|
1640
|
-
function useSymmWithdraw(params) {
|
|
1635
|
+
function useSymmWithdraw(params = {}) {
|
|
1641
1636
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1642
1637
|
const { publicClient, walletClient } = params;
|
|
1643
1638
|
const queryClient = useQueryClient();
|
|
@@ -24305,7 +24300,7 @@ var MuonClient = class {
|
|
|
24305
24300
|
};
|
|
24306
24301
|
|
|
24307
24302
|
// src/react/hooks/use-symm-collateral.ts
|
|
24308
|
-
function useSymmCollateral(params) {
|
|
24303
|
+
function useSymmCollateral(params = {}) {
|
|
24309
24304
|
const { chainId, symmioConfig } = useSymmContext();
|
|
24310
24305
|
const { publicClient, walletClient } = params;
|
|
24311
24306
|
const queryClient = useQueryClient();
|
|
@@ -24458,7 +24453,7 @@ async function hasSignedCurrentVersion(publicClient, signatureStore, user) {
|
|
|
24458
24453
|
}
|
|
24459
24454
|
|
|
24460
24455
|
// src/react/hooks/use-symm-signature.ts
|
|
24461
|
-
function useSymmSignature(params, options) {
|
|
24456
|
+
function useSymmSignature(params = {}, options) {
|
|
24462
24457
|
const { chainId, symmioConfig } = useSymmContext();
|
|
24463
24458
|
const { userAddress, publicClient, walletClient } = params;
|
|
24464
24459
|
const queryClient = useQueryClient();
|
|
@@ -24691,6 +24686,13 @@ function useSymmPositions(params) {
|
|
|
24691
24686
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
24692
24687
|
const chainId = params.chainId ?? ctxChainId;
|
|
24693
24688
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
24689
|
+
console.log({
|
|
24690
|
+
symmCoreClient,
|
|
24691
|
+
accountAddress,
|
|
24692
|
+
resolvedAddress,
|
|
24693
|
+
chainId,
|
|
24694
|
+
internalEnabled
|
|
24695
|
+
});
|
|
24694
24696
|
const query = useQuery({
|
|
24695
24697
|
...params.query,
|
|
24696
24698
|
queryKey: symmKeys.positions({
|
|
@@ -24945,10 +24947,11 @@ function useSymmMarkets(params) {
|
|
|
24945
24947
|
...params?.query,
|
|
24946
24948
|
queryKey: symmKeys.markets(chainId, searchText),
|
|
24947
24949
|
queryFn: () => {
|
|
24950
|
+
const marketsApi = symmCoreClient.markets;
|
|
24948
24951
|
if (searchText) {
|
|
24949
|
-
return
|
|
24952
|
+
return marketsApi.search(searchText, chainId);
|
|
24950
24953
|
}
|
|
24951
|
-
return
|
|
24954
|
+
return marketsApi.list({ pageSize: "500", chainId });
|
|
24952
24955
|
},
|
|
24953
24956
|
enabled: internalEnabled && (params?.query?.enabled ?? true)
|
|
24954
24957
|
});
|
|
@@ -25237,9 +25240,7 @@ function useSymmPendingIds(params) {
|
|
|
25237
25240
|
function useSymmPendingInstantOpens(params) {
|
|
25238
25241
|
const {
|
|
25239
25242
|
symmCoreClient,
|
|
25240
|
-
chainId: ctxChainId
|
|
25241
|
-
authToken: ctxAuthToken,
|
|
25242
|
-
refreshAuth
|
|
25243
|
+
chainId: ctxChainId
|
|
25243
25244
|
} = useSymmContext();
|
|
25244
25245
|
const { accountAddress, authToken: providedAuthToken } = params;
|
|
25245
25246
|
const chainId = params.chainId ?? ctxChainId;
|
|
@@ -25248,7 +25249,7 @@ function useSymmPendingInstantOpens(params) {
|
|
|
25248
25249
|
...params.query,
|
|
25249
25250
|
queryKey: symmKeys.pendingInstantOpens(accountAddress, chainId),
|
|
25250
25251
|
queryFn: async () => {
|
|
25251
|
-
const authToken = providedAuthToken ?? useSymmAuthStore.getState().getToken(accountAddress, chainId)
|
|
25252
|
+
const authToken = providedAuthToken ?? useSymmAuthStore.getState().getToken(accountAddress, chainId);
|
|
25252
25253
|
if (!authToken) {
|
|
25253
25254
|
throw new Error("failed to acquire auth token for pending instant opens");
|
|
25254
25255
|
}
|