@pear-protocol/symmio-client 0.2.13 → 0.2.15
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 +8478 -195
- package/dist/react/index.d.ts +8478 -195
- package/dist/react/index.js +526 -383
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +498 -373
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -950,95 +950,124 @@ function invalidateOrders(qc) {
|
|
|
950
950
|
qc.invalidateQueries({ queryKey: ["symm", "triggerOrders"] });
|
|
951
951
|
}
|
|
952
952
|
|
|
953
|
-
// src/react/
|
|
954
|
-
function
|
|
953
|
+
// src/react/mutation-config.ts
|
|
954
|
+
function withSymmMutationConfig(config, internal) {
|
|
955
955
|
const {
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
} =
|
|
961
|
-
|
|
962
|
-
|
|
956
|
+
onSuccess: configOnSuccess,
|
|
957
|
+
onError: configOnError,
|
|
958
|
+
onSettled: configOnSettled,
|
|
959
|
+
...rest
|
|
960
|
+
} = config ?? {};
|
|
961
|
+
return {
|
|
962
|
+
...rest,
|
|
963
|
+
onSuccess: async (...args) => {
|
|
964
|
+
await internal?.onSuccess?.(...args);
|
|
965
|
+
await configOnSuccess?.(...args);
|
|
966
|
+
},
|
|
967
|
+
onError: async (...args) => {
|
|
968
|
+
await internal?.onError?.(...args);
|
|
969
|
+
await configOnError?.(...args);
|
|
970
|
+
},
|
|
971
|
+
onSettled: async (...args) => {
|
|
972
|
+
await internal?.onSettled?.(...args);
|
|
973
|
+
await configOnSettled?.(...args);
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
// src/react/hooks/use-symm-instant-trade.ts
|
|
979
|
+
function useInstantTradeDeps(params) {
|
|
980
|
+
const { symmCoreClient, chainId, address, symmioConfig } = useSymmContext();
|
|
963
981
|
const multiAccount = symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
964
982
|
const defaultAccountAddress = params.accountAddress ?? address;
|
|
965
983
|
const defaultTarget = params.target ?? DEFAULT_PARTY_B_ADDRESS[chainId];
|
|
966
984
|
const defaultSelectors = params.selectors ?? ALL_TRADING_SELECTORS;
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
);
|
|
998
|
-
if (!accessStates.every(Boolean)) {
|
|
999
|
-
await delegateAccess(walletClient, publicClient, multiAccount, {
|
|
1000
|
-
account: accountAddress,
|
|
1001
|
-
target,
|
|
1002
|
-
selectors: [...selectors],
|
|
1003
|
-
activate: true
|
|
1004
|
-
});
|
|
1005
|
-
await queryClient.invalidateQueries({
|
|
1006
|
-
queryKey: symmKeys.delegation(accountAddress, target, selectors, chainId)
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
1009
|
-
return {
|
|
1010
|
-
accessToken,
|
|
1011
|
-
accountAddress,
|
|
985
|
+
return {
|
|
986
|
+
chainId,
|
|
987
|
+
defaultAccountAddress,
|
|
988
|
+
defaultSelectors,
|
|
989
|
+
defaultTarget,
|
|
990
|
+
multiAccount,
|
|
991
|
+
publicClient: params.publicClient,
|
|
992
|
+
symmCoreClient,
|
|
993
|
+
walletClient: params.walletClient
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
async function ensureInstantTradeReady(deps, queryClient, request) {
|
|
997
|
+
const { chainId, defaultAccountAddress, defaultSelectors, defaultTarget, multiAccount, publicClient, walletClient } = deps;
|
|
998
|
+
if (!publicClient || !walletClient) throw new Error("Clients not available");
|
|
999
|
+
const accountAddress = request?.accountAddress ?? defaultAccountAddress;
|
|
1000
|
+
const target = request?.target ?? defaultTarget;
|
|
1001
|
+
const selectors = request?.selectors ?? defaultSelectors;
|
|
1002
|
+
if (!accountAddress) throw new Error("account address is required");
|
|
1003
|
+
if (!target) throw new Error("delegation target is not configured");
|
|
1004
|
+
if (selectors.length === 0) {
|
|
1005
|
+
throw new Error("at least one delegation selector is required");
|
|
1006
|
+
}
|
|
1007
|
+
const accessToken = useSymmAuthStore.getState().getToken(accountAddress, chainId);
|
|
1008
|
+
if (!accessToken) {
|
|
1009
|
+
throw new Error("auth token is required for instant trading");
|
|
1010
|
+
}
|
|
1011
|
+
const accessStates = await Promise.all(
|
|
1012
|
+
selectors.map(
|
|
1013
|
+
(selector) => hasDelegatedAccess(publicClient, multiAccount, {
|
|
1014
|
+
account: accountAddress,
|
|
1012
1015
|
target,
|
|
1013
|
-
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
+
selector
|
|
1017
|
+
})
|
|
1018
|
+
)
|
|
1019
|
+
);
|
|
1020
|
+
if (!accessStates.every(Boolean)) {
|
|
1021
|
+
await delegateAccess(walletClient, publicClient, multiAccount, {
|
|
1022
|
+
account: accountAddress,
|
|
1023
|
+
target,
|
|
1024
|
+
selectors: [...selectors],
|
|
1025
|
+
activate: true
|
|
1026
|
+
});
|
|
1027
|
+
await queryClient.invalidateQueries({
|
|
1028
|
+
queryKey: symmKeys.delegation(accountAddress, target, selectors, chainId)
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
return {
|
|
1032
|
+
accessToken,
|
|
1033
|
+
accountAddress,
|
|
1034
|
+
target,
|
|
1035
|
+
selectors
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
function useSymmInstantTradeEnsureReadyMutation(params, options) {
|
|
1039
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1040
|
+
const deps = useInstantTradeDeps(params);
|
|
1041
|
+
return reactQuery.useMutation({
|
|
1042
|
+
...withSymmMutationConfig(options?.mutation),
|
|
1043
|
+
mutationFn: async (request) => ensureInstantTradeReady(deps, queryClient, request)
|
|
1016
1044
|
});
|
|
1017
|
-
|
|
1045
|
+
}
|
|
1046
|
+
function useSymmInstantTradeExecuteMutation(params, options) {
|
|
1047
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1048
|
+
const deps = useInstantTradeDeps(params);
|
|
1049
|
+
return reactQuery.useMutation({
|
|
1050
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1051
|
+
onSuccess: (_data, variables) => {
|
|
1052
|
+
if (variables.invalidatePositionsOnSuccess !== false) {
|
|
1053
|
+
invalidatePositions(queryClient);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}),
|
|
1018
1057
|
mutationFn: async (request) => {
|
|
1019
|
-
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
1020
|
-
const setup = await
|
|
1058
|
+
if (!deps.symmCoreClient) throw new Error("symm-core client not available");
|
|
1059
|
+
const setup = await ensureInstantTradeReady(deps, queryClient, {
|
|
1021
1060
|
accountAddress: request.accountAddress,
|
|
1022
1061
|
target: request.target,
|
|
1023
1062
|
selectors: request.selectors
|
|
1024
1063
|
});
|
|
1025
1064
|
return request.action({
|
|
1026
|
-
symmCoreClient,
|
|
1065
|
+
symmCoreClient: deps.symmCoreClient,
|
|
1027
1066
|
accessToken: setup.accessToken,
|
|
1028
1067
|
accountAddress: setup.accountAddress
|
|
1029
1068
|
});
|
|
1030
|
-
},
|
|
1031
|
-
onSuccess: (_data, variables) => {
|
|
1032
|
-
if (variables.invalidatePositionsOnSuccess !== false) {
|
|
1033
|
-
invalidatePositions(queryClient);
|
|
1034
|
-
}
|
|
1035
1069
|
}
|
|
1036
1070
|
});
|
|
1037
|
-
return {
|
|
1038
|
-
delegation,
|
|
1039
|
-
ensureReady,
|
|
1040
|
-
execute
|
|
1041
|
-
};
|
|
1042
1071
|
}
|
|
1043
1072
|
function prepareAddAccount(multiAccount, account, name) {
|
|
1044
1073
|
const data = viem.encodeFunctionData({
|
|
@@ -1097,51 +1126,65 @@ async function getAccounts(publicClient, multiAccount, user, start = 0, size = 1
|
|
|
1097
1126
|
}
|
|
1098
1127
|
|
|
1099
1128
|
// src/react/hooks/use-symm-accounts.ts
|
|
1100
|
-
function
|
|
1129
|
+
function useResolvedMultiAccount() {
|
|
1101
1130
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1131
|
+
return symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
1132
|
+
}
|
|
1133
|
+
function useSymmAccountsQuery(params = {}, options) {
|
|
1134
|
+
const { chainId } = useSymmContext();
|
|
1135
|
+
const multiAccount = useResolvedMultiAccount();
|
|
1136
|
+
const { userAddress, publicClient } = params;
|
|
1105
1137
|
const internalEnabled = !!publicClient && !!userAddress;
|
|
1106
|
-
|
|
1138
|
+
return reactQuery.useQuery({
|
|
1107
1139
|
...options?.query,
|
|
1108
1140
|
queryKey: symmKeys.accounts(userAddress, chainId),
|
|
1109
1141
|
queryFn: () => getAccounts(publicClient, multiAccount, userAddress),
|
|
1110
1142
|
enabled: internalEnabled && (options?.query?.enabled ?? true)
|
|
1111
1143
|
});
|
|
1112
|
-
|
|
1144
|
+
}
|
|
1145
|
+
function useSymmCreateAccountMutation(params = {}, options) {
|
|
1146
|
+
const { chainId } = useSymmContext();
|
|
1147
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1148
|
+
const multiAccount = useResolvedMultiAccount();
|
|
1149
|
+
const { userAddress, publicClient, walletClient } = params;
|
|
1150
|
+
return reactQuery.useMutation({
|
|
1151
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1152
|
+
onSuccess: () => {
|
|
1153
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.accounts(userAddress, chainId) });
|
|
1154
|
+
}
|
|
1155
|
+
}),
|
|
1113
1156
|
mutationFn: async ({ name }) => {
|
|
1114
1157
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
1115
1158
|
return addAccount(walletClient, publicClient, multiAccount, name);
|
|
1116
|
-
},
|
|
1117
|
-
onSuccess: () => {
|
|
1118
|
-
queryClient.invalidateQueries({ queryKey: symmKeys.accounts(userAddress, chainId) });
|
|
1119
1159
|
}
|
|
1120
1160
|
});
|
|
1121
|
-
|
|
1161
|
+
}
|
|
1162
|
+
function useSymmEditAccountNameMutation(params = {}, options) {
|
|
1163
|
+
const { chainId } = useSymmContext();
|
|
1164
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1165
|
+
const multiAccount = useResolvedMultiAccount();
|
|
1166
|
+
const { userAddress, publicClient, walletClient } = params;
|
|
1167
|
+
return reactQuery.useMutation({
|
|
1168
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1169
|
+
onSuccess: () => {
|
|
1170
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.accounts(userAddress, chainId) });
|
|
1171
|
+
}
|
|
1172
|
+
}),
|
|
1122
1173
|
mutationFn: async ({
|
|
1123
1174
|
accountAddress,
|
|
1124
1175
|
name
|
|
1125
1176
|
}) => {
|
|
1126
1177
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
1127
1178
|
return editAccountName(walletClient, publicClient, multiAccount, accountAddress, name);
|
|
1128
|
-
},
|
|
1129
|
-
onSuccess: () => {
|
|
1130
|
-
queryClient.invalidateQueries({ queryKey: symmKeys.accounts(userAddress, chainId) });
|
|
1131
1179
|
}
|
|
1132
1180
|
});
|
|
1133
|
-
return {
|
|
1134
|
-
query: accountsQuery,
|
|
1135
|
-
createAccount,
|
|
1136
|
-
editName
|
|
1137
|
-
};
|
|
1138
1181
|
}
|
|
1139
1182
|
function useSymmAccountsApi(params) {
|
|
1140
1183
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
1141
1184
|
const { userAddress } = params;
|
|
1142
1185
|
const chainId = params.chainId ?? ctxChainId;
|
|
1143
1186
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
1144
|
-
|
|
1187
|
+
return reactQuery.useQuery({
|
|
1145
1188
|
...params.query,
|
|
1146
1189
|
queryKey: symmKeys.accountsApi(userAddress, chainId),
|
|
1147
1190
|
queryFn: () => symmCoreClient.accounts.list({
|
|
@@ -1150,16 +1193,13 @@ function useSymmAccountsApi(params) {
|
|
|
1150
1193
|
}),
|
|
1151
1194
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
1152
1195
|
});
|
|
1153
|
-
return {
|
|
1154
|
-
query
|
|
1155
|
-
};
|
|
1156
1196
|
}
|
|
1157
1197
|
function useSymmAccountsLength(params) {
|
|
1158
1198
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
1159
1199
|
const { userAddress } = params;
|
|
1160
1200
|
const chainId = params.chainId ?? ctxChainId;
|
|
1161
1201
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
1162
|
-
|
|
1202
|
+
return reactQuery.useQuery({
|
|
1163
1203
|
...params.query,
|
|
1164
1204
|
queryKey: symmKeys.accountsLength(userAddress, chainId),
|
|
1165
1205
|
queryFn: () => symmCoreClient.accounts.getLength({
|
|
@@ -1168,16 +1208,13 @@ function useSymmAccountsLength(params) {
|
|
|
1168
1208
|
}),
|
|
1169
1209
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
1170
1210
|
});
|
|
1171
|
-
return {
|
|
1172
|
-
query
|
|
1173
|
-
};
|
|
1174
1211
|
}
|
|
1175
1212
|
function useSymmAccountsWithPositions(params) {
|
|
1176
1213
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
1177
1214
|
const { userAddress } = params;
|
|
1178
1215
|
const chainId = params.chainId ?? ctxChainId;
|
|
1179
1216
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
1180
|
-
|
|
1217
|
+
return reactQuery.useQuery({
|
|
1181
1218
|
...params.query,
|
|
1182
1219
|
queryKey: symmKeys.accountsWithPositions(userAddress, chainId),
|
|
1183
1220
|
queryFn: () => symmCoreClient.accounts.getWithPositions({
|
|
@@ -1186,9 +1223,6 @@ function useSymmAccountsWithPositions(params) {
|
|
|
1186
1223
|
}),
|
|
1187
1224
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
1188
1225
|
});
|
|
1189
|
-
return {
|
|
1190
|
-
query
|
|
1191
|
-
};
|
|
1192
1226
|
}
|
|
1193
1227
|
|
|
1194
1228
|
// src/abis/ERC20.ts
|
|
@@ -1306,14 +1340,22 @@ async function getBalance(publicClient, tokenAddress, account) {
|
|
|
1306
1340
|
}
|
|
1307
1341
|
|
|
1308
1342
|
// src/react/hooks/use-symm-approval.ts
|
|
1309
|
-
function
|
|
1343
|
+
function useResolvedApprovalConfig(params) {
|
|
1310
1344
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1311
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1312
|
-
const { owner, amount, publicClient, walletClient, spender, collateralToken } = params;
|
|
1313
1345
|
const multiAccount = symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
1314
1346
|
const collateral = symmioConfig?.collateralAddress ?? getAddress(COLLATERAL_ADDRESS, chainId, "Collateral");
|
|
1315
|
-
const resolvedSpender = spender ?? multiAccount;
|
|
1316
|
-
const resolvedToken = collateralToken ?? collateral;
|
|
1347
|
+
const resolvedSpender = params.spender ?? multiAccount;
|
|
1348
|
+
const resolvedToken = params.collateralToken ?? collateral;
|
|
1349
|
+
return {
|
|
1350
|
+
chainId,
|
|
1351
|
+
multiAccount,
|
|
1352
|
+
resolvedSpender,
|
|
1353
|
+
resolvedToken
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
function useSymmApprovalQuery(params) {
|
|
1357
|
+
const { owner, amount, publicClient } = params;
|
|
1358
|
+
const { chainId, resolvedSpender, resolvedToken } = useResolvedApprovalConfig(params);
|
|
1317
1359
|
const selectWithAmount = react.useCallback(
|
|
1318
1360
|
(data) => ({
|
|
1319
1361
|
...data,
|
|
@@ -1322,7 +1364,7 @@ function useSymmApproval(params) {
|
|
|
1322
1364
|
[amount]
|
|
1323
1365
|
);
|
|
1324
1366
|
const internalEnabled = !!publicClient && !!owner && !!resolvedSpender && !!resolvedToken;
|
|
1325
|
-
|
|
1367
|
+
return reactQuery.useQuery({
|
|
1326
1368
|
...params.query,
|
|
1327
1369
|
queryKey: symmKeys.approval(owner, resolvedSpender, chainId, resolvedToken),
|
|
1328
1370
|
queryFn: async () => {
|
|
@@ -1335,26 +1377,35 @@ function useSymmApproval(params) {
|
|
|
1335
1377
|
select: selectWithAmount,
|
|
1336
1378
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
1337
1379
|
});
|
|
1338
|
-
|
|
1380
|
+
}
|
|
1381
|
+
function useSymmApproveMutation(params, options) {
|
|
1382
|
+
const { owner, publicClient, walletClient } = params;
|
|
1383
|
+
const { chainId, multiAccount, resolvedSpender, resolvedToken } = useResolvedApprovalConfig(params);
|
|
1384
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1385
|
+
return reactQuery.useMutation({
|
|
1386
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1387
|
+
onSuccess: () => {
|
|
1388
|
+
queryClient.invalidateQueries({
|
|
1389
|
+
queryKey: symmKeys.approval(owner, resolvedSpender, chainId, resolvedToken)
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
}),
|
|
1339
1393
|
mutationFn: async (approveAmount) => {
|
|
1340
1394
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
1341
1395
|
return approve(walletClient, publicClient, resolvedToken, multiAccount, approveAmount);
|
|
1342
|
-
},
|
|
1343
|
-
onSuccess: () => {
|
|
1344
|
-
queryClient.invalidateQueries({
|
|
1345
|
-
queryKey: symmKeys.approval(owner, resolvedSpender, chainId, resolvedToken)
|
|
1346
|
-
});
|
|
1347
1396
|
}
|
|
1348
1397
|
});
|
|
1349
|
-
return {
|
|
1350
|
-
query: approvalQuery,
|
|
1351
|
-
approve: approveMutation
|
|
1352
|
-
};
|
|
1353
1398
|
}
|
|
1354
|
-
function useSymmCancelClose() {
|
|
1399
|
+
function useSymmCancelClose(options) {
|
|
1355
1400
|
const { symmCoreClient, chainId, address } = useSymmContext();
|
|
1356
1401
|
const queryClient = reactQuery.useQueryClient();
|
|
1357
|
-
|
|
1402
|
+
return reactQuery.useMutation({
|
|
1403
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1404
|
+
onSuccess: () => {
|
|
1405
|
+
invalidateOrders(queryClient);
|
|
1406
|
+
invalidatePositions(queryClient);
|
|
1407
|
+
}
|
|
1408
|
+
}),
|
|
1358
1409
|
mutationFn: async ({
|
|
1359
1410
|
quoteId,
|
|
1360
1411
|
authToken,
|
|
@@ -1375,18 +1426,19 @@ function useSymmCancelClose() {
|
|
|
1375
1426
|
authToken: resolvedAuthToken,
|
|
1376
1427
|
chainId: resolvedChainId
|
|
1377
1428
|
});
|
|
1378
|
-
},
|
|
1379
|
-
onSuccess: () => {
|
|
1380
|
-
invalidateOrders(queryClient);
|
|
1381
|
-
invalidatePositions(queryClient);
|
|
1382
1429
|
}
|
|
1383
1430
|
});
|
|
1384
|
-
return { cancelClose };
|
|
1385
1431
|
}
|
|
1386
|
-
function useSymmCloseOrder() {
|
|
1432
|
+
function useSymmCloseOrder(options) {
|
|
1387
1433
|
const { symmCoreClient, address, chainId } = useSymmContext();
|
|
1388
1434
|
const queryClient = reactQuery.useQueryClient();
|
|
1389
|
-
|
|
1435
|
+
return reactQuery.useMutation({
|
|
1436
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1437
|
+
onSuccess: () => {
|
|
1438
|
+
invalidateOrders(queryClient);
|
|
1439
|
+
invalidatePositions(queryClient);
|
|
1440
|
+
}
|
|
1441
|
+
}),
|
|
1390
1442
|
mutationFn: async (request) => {
|
|
1391
1443
|
if (!symmCoreClient) {
|
|
1392
1444
|
throw new Error("symm-core client not available");
|
|
@@ -1396,13 +1448,8 @@ function useSymmCloseOrder() {
|
|
|
1396
1448
|
type: request.type,
|
|
1397
1449
|
authToken: request.authToken ?? (address ? useSymmAuthStore.getState().getToken(address, chainId) ?? void 0 : void 0)
|
|
1398
1450
|
});
|
|
1399
|
-
},
|
|
1400
|
-
onSuccess: () => {
|
|
1401
|
-
invalidateOrders(queryClient);
|
|
1402
|
-
invalidatePositions(queryClient);
|
|
1403
1451
|
}
|
|
1404
1452
|
});
|
|
1405
|
-
return { closeOrder };
|
|
1406
1453
|
}
|
|
1407
1454
|
function prepareDeposit(multiAccount, account, params) {
|
|
1408
1455
|
validateAmount(params.amount, "deposit amount");
|
|
@@ -1456,38 +1503,52 @@ async function depositAndAllocate(walletClient, publicClient, multiAccount, para
|
|
|
1456
1503
|
}
|
|
1457
1504
|
|
|
1458
1505
|
// src/react/hooks/use-symm-deposit.ts
|
|
1459
|
-
function
|
|
1506
|
+
function useResolvedDepositParams(params = {}) {
|
|
1460
1507
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1461
|
-
const { publicClient, walletClient } = params;
|
|
1462
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1463
1508
|
const multiAccount = symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
1464
|
-
|
|
1509
|
+
return {
|
|
1510
|
+
multiAccount,
|
|
1511
|
+
publicClient: params.publicClient,
|
|
1512
|
+
walletClient: params.walletClient
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
function useSymmDepositMutation(params = {}, options) {
|
|
1516
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1517
|
+
const { multiAccount, publicClient, walletClient } = useResolvedDepositParams(params);
|
|
1518
|
+
return reactQuery.useMutation({
|
|
1519
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1520
|
+
onSuccess: () => {
|
|
1521
|
+
invalidateBalances(queryClient);
|
|
1522
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "approval"] });
|
|
1523
|
+
}
|
|
1524
|
+
}),
|
|
1465
1525
|
mutationFn: async ({
|
|
1466
1526
|
account,
|
|
1467
1527
|
amount
|
|
1468
1528
|
}) => {
|
|
1469
1529
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
1470
1530
|
return deposit(walletClient, publicClient, multiAccount, { account, amount });
|
|
1471
|
-
},
|
|
1472
|
-
onSuccess: () => {
|
|
1473
|
-
invalidateBalances(queryClient);
|
|
1474
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "approval"] });
|
|
1475
1531
|
}
|
|
1476
1532
|
});
|
|
1477
|
-
|
|
1533
|
+
}
|
|
1534
|
+
function useSymmDepositAndAllocateMutation(params = {}, options) {
|
|
1535
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1536
|
+
const { multiAccount, publicClient, walletClient } = useResolvedDepositParams(params);
|
|
1537
|
+
return reactQuery.useMutation({
|
|
1538
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1539
|
+
onSuccess: () => {
|
|
1540
|
+
invalidateBalances(queryClient);
|
|
1541
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "approval"] });
|
|
1542
|
+
}
|
|
1543
|
+
}),
|
|
1478
1544
|
mutationFn: async ({
|
|
1479
1545
|
account,
|
|
1480
1546
|
amount
|
|
1481
1547
|
}) => {
|
|
1482
1548
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
1483
1549
|
return depositAndAllocate(walletClient, publicClient, multiAccount, { account, amount });
|
|
1484
|
-
},
|
|
1485
|
-
onSuccess: () => {
|
|
1486
|
-
invalidateBalances(queryClient);
|
|
1487
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "approval"] });
|
|
1488
1550
|
}
|
|
1489
1551
|
});
|
|
1490
|
-
return { deposit: depositMutation, depositAndAllocate: depositAndAllocateMutation };
|
|
1491
1552
|
}
|
|
1492
1553
|
function prepareWithdraw(multiAccount, account, params) {
|
|
1493
1554
|
validateAmount(params.amount, "withdraw amount");
|
|
@@ -1516,24 +1577,25 @@ async function withdraw(walletClient, publicClient, multiAccount, params) {
|
|
|
1516
1577
|
}
|
|
1517
1578
|
|
|
1518
1579
|
// src/react/hooks/use-symm-withdraw.ts
|
|
1519
|
-
function useSymmWithdraw(params = {}) {
|
|
1580
|
+
function useSymmWithdraw(params = {}, options) {
|
|
1520
1581
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1521
1582
|
const { publicClient, walletClient } = params;
|
|
1522
1583
|
const queryClient = reactQuery.useQueryClient();
|
|
1523
1584
|
const multiAccount = symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
1524
|
-
|
|
1585
|
+
return reactQuery.useMutation({
|
|
1586
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1587
|
+
onSuccess: () => {
|
|
1588
|
+
invalidateBalances(queryClient);
|
|
1589
|
+
}
|
|
1590
|
+
}),
|
|
1525
1591
|
mutationFn: async ({
|
|
1526
1592
|
account,
|
|
1527
1593
|
amount
|
|
1528
1594
|
}) => {
|
|
1529
1595
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
1530
1596
|
return withdraw(walletClient, publicClient, multiAccount, { account, amount });
|
|
1531
|
-
},
|
|
1532
|
-
onSuccess: () => {
|
|
1533
|
-
invalidateBalances(queryClient);
|
|
1534
1597
|
}
|
|
1535
1598
|
});
|
|
1536
|
-
return { withdraw: withdrawMutation };
|
|
1537
1599
|
}
|
|
1538
1600
|
|
|
1539
1601
|
// src/abis/SymmioDiamond.ts
|
|
@@ -24184,10 +24246,8 @@ var MuonClient = class {
|
|
|
24184
24246
|
};
|
|
24185
24247
|
|
|
24186
24248
|
// src/react/hooks/use-symm-collateral.ts
|
|
24187
|
-
function
|
|
24249
|
+
function useResolvedCollateralDeps(params = {}) {
|
|
24188
24250
|
const { chainId, symmioConfig } = useSymmContext();
|
|
24189
|
-
const { publicClient, walletClient } = params;
|
|
24190
|
-
const queryClient = reactQuery.useQueryClient();
|
|
24191
24251
|
const multiAccount = symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
24192
24252
|
const symmioDiamond = symmioConfig?.symmioDiamondAddress ?? getAddress(SYMMIO_DIAMOND_ADDRESS, chainId, "SymmioDiamond");
|
|
24193
24253
|
const muon = react.useMemo(
|
|
@@ -24197,19 +24257,42 @@ function useSymmCollateral(params = {}) {
|
|
|
24197
24257
|
}),
|
|
24198
24258
|
[symmioConfig?.muonBaseUrls, symmioConfig?.muonAppName]
|
|
24199
24259
|
);
|
|
24200
|
-
|
|
24260
|
+
return {
|
|
24261
|
+
chainId,
|
|
24262
|
+
muon,
|
|
24263
|
+
multiAccount,
|
|
24264
|
+
publicClient: params.publicClient,
|
|
24265
|
+
symmioDiamond,
|
|
24266
|
+
walletClient: params.walletClient
|
|
24267
|
+
};
|
|
24268
|
+
}
|
|
24269
|
+
function useSymmAllocateCollateralMutation(params = {}, options) {
|
|
24270
|
+
const queryClient = reactQuery.useQueryClient();
|
|
24271
|
+
const { multiAccount, publicClient, walletClient } = useResolvedCollateralDeps(params);
|
|
24272
|
+
return reactQuery.useMutation({
|
|
24273
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24274
|
+
onSuccess: () => {
|
|
24275
|
+
invalidateBalances(queryClient);
|
|
24276
|
+
}
|
|
24277
|
+
}),
|
|
24201
24278
|
mutationFn: async ({
|
|
24202
24279
|
subAccount,
|
|
24203
24280
|
amount
|
|
24204
24281
|
}) => {
|
|
24205
24282
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
24206
24283
|
return allocate(walletClient, publicClient, multiAccount, subAccount, { amount });
|
|
24207
|
-
},
|
|
24208
|
-
onSuccess: () => {
|
|
24209
|
-
invalidateBalances(queryClient);
|
|
24210
24284
|
}
|
|
24211
24285
|
});
|
|
24212
|
-
|
|
24286
|
+
}
|
|
24287
|
+
function useSymmDeallocateCollateralMutation(params = {}, options) {
|
|
24288
|
+
const queryClient = reactQuery.useQueryClient();
|
|
24289
|
+
const { chainId, muon, multiAccount, publicClient, symmioDiamond, walletClient } = useResolvedCollateralDeps(params);
|
|
24290
|
+
return reactQuery.useMutation({
|
|
24291
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24292
|
+
onSuccess: () => {
|
|
24293
|
+
invalidateBalances(queryClient);
|
|
24294
|
+
}
|
|
24295
|
+
}),
|
|
24213
24296
|
mutationFn: async ({
|
|
24214
24297
|
subAccount,
|
|
24215
24298
|
amount
|
|
@@ -24224,28 +24307,26 @@ function useSymmCollateral(params = {}) {
|
|
|
24224
24307
|
amount,
|
|
24225
24308
|
upnlSig
|
|
24226
24309
|
});
|
|
24227
|
-
},
|
|
24228
|
-
onSuccess: () => {
|
|
24229
|
-
invalidateBalances(queryClient);
|
|
24230
24310
|
}
|
|
24231
24311
|
});
|
|
24232
|
-
|
|
24312
|
+
}
|
|
24313
|
+
function useSymmInternalTransferCollateralMutation(params = {}, options) {
|
|
24314
|
+
const queryClient = reactQuery.useQueryClient();
|
|
24315
|
+
const { multiAccount, publicClient, walletClient } = useResolvedCollateralDeps(params);
|
|
24316
|
+
return reactQuery.useMutation({
|
|
24317
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24318
|
+
onSuccess: () => {
|
|
24319
|
+
invalidateBalances(queryClient);
|
|
24320
|
+
}
|
|
24321
|
+
}),
|
|
24233
24322
|
mutationFn: async ({
|
|
24234
24323
|
subAccount,
|
|
24235
24324
|
params: transferParams
|
|
24236
24325
|
}) => {
|
|
24237
24326
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
24238
24327
|
return internalTransfer(walletClient, publicClient, multiAccount, subAccount, transferParams);
|
|
24239
|
-
},
|
|
24240
|
-
onSuccess: () => {
|
|
24241
|
-
invalidateBalances(queryClient);
|
|
24242
24328
|
}
|
|
24243
24329
|
});
|
|
24244
|
-
return {
|
|
24245
|
-
allocate: allocateMutation,
|
|
24246
|
-
deallocate: deallocateMutation,
|
|
24247
|
-
internalTransfer: internalTransferMutation
|
|
24248
|
-
};
|
|
24249
24330
|
}
|
|
24250
24331
|
|
|
24251
24332
|
// src/abis/SignatureStore.ts
|
|
@@ -24337,40 +24418,47 @@ async function hasSignedCurrentVersion(publicClient, signatureStore, user) {
|
|
|
24337
24418
|
}
|
|
24338
24419
|
|
|
24339
24420
|
// src/react/hooks/use-symm-signature.ts
|
|
24340
|
-
function
|
|
24421
|
+
function useResolvedSignatureStore() {
|
|
24341
24422
|
const { chainId, symmioConfig } = useSymmContext();
|
|
24342
|
-
const { userAddress, publicClient, walletClient } = params;
|
|
24343
|
-
const queryClient = reactQuery.useQueryClient();
|
|
24344
24423
|
let signatureStore;
|
|
24345
24424
|
try {
|
|
24346
24425
|
signatureStore = symmioConfig?.signatureStoreAddress ?? getAddress(SIGNATURE_STORE_ADDRESS, chainId, "SignatureStore");
|
|
24347
24426
|
} catch {
|
|
24427
|
+
signatureStore = void 0;
|
|
24348
24428
|
}
|
|
24429
|
+
return { chainId, signatureStore };
|
|
24430
|
+
}
|
|
24431
|
+
function useSymmSignatureQuery(params = {}, options) {
|
|
24432
|
+
const { userAddress, publicClient } = params;
|
|
24433
|
+
const { chainId, signatureStore } = useResolvedSignatureStore();
|
|
24349
24434
|
const internalEnabled = !!publicClient && !!userAddress && !!signatureStore;
|
|
24350
|
-
|
|
24435
|
+
return reactQuery.useQuery({
|
|
24351
24436
|
...options?.query,
|
|
24352
24437
|
queryKey: symmKeys.signature(userAddress, chainId),
|
|
24353
24438
|
queryFn: () => hasSignedCurrentVersion(publicClient, signatureStore, userAddress),
|
|
24354
24439
|
enabled: internalEnabled && (options?.query?.enabled ?? true)
|
|
24355
24440
|
});
|
|
24356
|
-
|
|
24441
|
+
}
|
|
24442
|
+
function useSymmSignTermsMutation(params = {}, options) {
|
|
24443
|
+
const { userAddress, publicClient, walletClient } = params;
|
|
24444
|
+
const { chainId, signatureStore } = useResolvedSignatureStore();
|
|
24445
|
+
const queryClient = reactQuery.useQueryClient();
|
|
24446
|
+
return reactQuery.useMutation({
|
|
24447
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24448
|
+
onSuccess: () => {
|
|
24449
|
+
queryClient.invalidateQueries({
|
|
24450
|
+
queryKey: symmKeys.signature(userAddress, chainId)
|
|
24451
|
+
});
|
|
24452
|
+
}
|
|
24453
|
+
}),
|
|
24357
24454
|
mutationFn: async () => {
|
|
24358
24455
|
if (!walletClient || !publicClient || !signatureStore) {
|
|
24359
24456
|
throw new Error("Clients or SignatureStore not available");
|
|
24360
24457
|
}
|
|
24361
24458
|
const sig = await signTermsMessage(walletClient, publicClient, signatureStore);
|
|
24362
24459
|
await storeSignature(walletClient, publicClient, signatureStore, sig);
|
|
24363
|
-
},
|
|
24364
|
-
onSuccess: () => {
|
|
24365
|
-
queryClient.invalidateQueries({
|
|
24366
|
-
queryKey: symmKeys.signature(userAddress, chainId)
|
|
24367
|
-
});
|
|
24368
24460
|
}
|
|
24369
24461
|
});
|
|
24370
|
-
return {
|
|
24371
|
-
query: signedQuery,
|
|
24372
|
-
signTerms
|
|
24373
|
-
};
|
|
24374
24462
|
}
|
|
24375
24463
|
|
|
24376
24464
|
// src/actions/stats.ts
|
|
@@ -24413,23 +24501,20 @@ function useSymmAvailableMargin(params) {
|
|
|
24413
24501
|
[resolvedUpnl]
|
|
24414
24502
|
);
|
|
24415
24503
|
const internalEnabled = !!publicClient && !!accountAddress;
|
|
24416
|
-
|
|
24504
|
+
return reactQuery.useQuery({
|
|
24417
24505
|
...params.query,
|
|
24418
24506
|
queryKey: symmKeys.availableMargin(accountAddress, chainId),
|
|
24419
24507
|
queryFn: () => getPartyAStats(publicClient, symmioDiamond, accountAddress),
|
|
24420
24508
|
select: selectWithUpnl,
|
|
24421
24509
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24422
24510
|
});
|
|
24423
|
-
return {
|
|
24424
|
-
query
|
|
24425
|
-
};
|
|
24426
24511
|
}
|
|
24427
24512
|
function useSymmAccountSummary(params) {
|
|
24428
24513
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24429
24514
|
const { userAddress } = params;
|
|
24430
24515
|
const chainId = params.chainId ?? ctxChainId;
|
|
24431
24516
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
24432
|
-
|
|
24517
|
+
return reactQuery.useQuery({
|
|
24433
24518
|
...params.query,
|
|
24434
24519
|
queryKey: symmKeys.accountSummary(userAddress, chainId),
|
|
24435
24520
|
queryFn: () => symmCoreClient.accounts.getSummary({
|
|
@@ -24438,16 +24523,13 @@ function useSymmAccountSummary(params) {
|
|
|
24438
24523
|
}),
|
|
24439
24524
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24440
24525
|
});
|
|
24441
|
-
return {
|
|
24442
|
-
query
|
|
24443
|
-
};
|
|
24444
24526
|
}
|
|
24445
24527
|
function useSymmAccountData(params) {
|
|
24446
24528
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24447
24529
|
const { address, upnl } = params;
|
|
24448
24530
|
const chainId = params.chainId ?? ctxChainId;
|
|
24449
24531
|
const internalEnabled = !!symmCoreClient && !!address;
|
|
24450
|
-
|
|
24532
|
+
return reactQuery.useQuery({
|
|
24451
24533
|
...params.query,
|
|
24452
24534
|
queryKey: symmKeys.accountData(address, chainId, upnl),
|
|
24453
24535
|
queryFn: () => symmCoreClient.accounts.getData({
|
|
@@ -24457,16 +24539,13 @@ function useSymmAccountData(params) {
|
|
|
24457
24539
|
}),
|
|
24458
24540
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24459
24541
|
});
|
|
24460
|
-
return {
|
|
24461
|
-
query
|
|
24462
|
-
};
|
|
24463
24542
|
}
|
|
24464
24543
|
function useSymmBalances(params) {
|
|
24465
24544
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24466
24545
|
const { userAddress, multiAccountAddress } = params;
|
|
24467
24546
|
const chainId = params.chainId ?? ctxChainId;
|
|
24468
24547
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
24469
|
-
|
|
24548
|
+
return reactQuery.useQuery({
|
|
24470
24549
|
...params.query,
|
|
24471
24550
|
queryKey: symmKeys.balances(userAddress, chainId),
|
|
24472
24551
|
queryFn: () => symmCoreClient.accounts.getBalanceInfo({
|
|
@@ -24476,62 +24555,134 @@ function useSymmBalances(params) {
|
|
|
24476
24555
|
}),
|
|
24477
24556
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24478
24557
|
});
|
|
24479
|
-
return {
|
|
24480
|
-
query
|
|
24481
|
-
};
|
|
24482
24558
|
}
|
|
24483
|
-
function
|
|
24559
|
+
function useResolveTradeAuthToken() {
|
|
24560
|
+
const context = useSymmContext();
|
|
24561
|
+
const { address, chainId } = context;
|
|
24562
|
+
const { refreshAuth } = useSymmAuth({ address, chainId });
|
|
24563
|
+
const refreshAuthFromContext = context.refreshAuth;
|
|
24564
|
+
return react.useCallback(
|
|
24565
|
+
async (providedAuthToken, accountAddress) => {
|
|
24566
|
+
if (providedAuthToken) {
|
|
24567
|
+
return providedAuthToken;
|
|
24568
|
+
}
|
|
24569
|
+
const resolvedAccountAddress = accountAddress ?? address;
|
|
24570
|
+
if (!resolvedAccountAddress) {
|
|
24571
|
+
return null;
|
|
24572
|
+
}
|
|
24573
|
+
const inMemoryToken = useSymmAuthStore.getState().getToken(resolvedAccountAddress, chainId);
|
|
24574
|
+
if (inMemoryToken) {
|
|
24575
|
+
return inMemoryToken;
|
|
24576
|
+
}
|
|
24577
|
+
if (refreshAuthFromContext) {
|
|
24578
|
+
return refreshAuthFromContext(resolvedAccountAddress);
|
|
24579
|
+
}
|
|
24580
|
+
return refreshAuth(resolvedAccountAddress);
|
|
24581
|
+
},
|
|
24582
|
+
[address, chainId, refreshAuth, refreshAuthFromContext]
|
|
24583
|
+
);
|
|
24584
|
+
}
|
|
24585
|
+
function useSymmOpenBasketMutation(options) {
|
|
24484
24586
|
const { symmCoreClient } = useSymmContext();
|
|
24485
24587
|
const queryClient = reactQuery.useQueryClient();
|
|
24486
|
-
|
|
24588
|
+
return reactQuery.useMutation({
|
|
24589
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24590
|
+
onSuccess: () => {
|
|
24591
|
+
invalidatePositions(queryClient);
|
|
24592
|
+
}
|
|
24593
|
+
}),
|
|
24487
24594
|
mutationFn: async (request) => {
|
|
24488
24595
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24489
24596
|
return symmCoreClient.positions.openBasket(request);
|
|
24490
|
-
},
|
|
24491
|
-
onSuccess: () => {
|
|
24492
|
-
invalidatePositions(queryClient);
|
|
24493
24597
|
}
|
|
24494
24598
|
});
|
|
24495
|
-
|
|
24599
|
+
}
|
|
24600
|
+
function useSymmClosePositionMutation(options) {
|
|
24601
|
+
const { symmCoreClient } = useSymmContext();
|
|
24602
|
+
const queryClient = reactQuery.useQueryClient();
|
|
24603
|
+
const resolveAuthToken = useResolveTradeAuthToken();
|
|
24604
|
+
return reactQuery.useMutation({
|
|
24605
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24606
|
+
onSuccess: () => {
|
|
24607
|
+
invalidatePositions(queryClient);
|
|
24608
|
+
}
|
|
24609
|
+
}),
|
|
24496
24610
|
mutationFn: async (request) => {
|
|
24497
24611
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24498
|
-
|
|
24499
|
-
|
|
24500
|
-
|
|
24501
|
-
|
|
24612
|
+
const typedRequest = request;
|
|
24613
|
+
const authToken = await resolveAuthToken(
|
|
24614
|
+
typedRequest.authToken,
|
|
24615
|
+
typedRequest.accountAddress
|
|
24616
|
+
);
|
|
24617
|
+
if (!authToken) {
|
|
24618
|
+
throw new Error("auth token is required to close a position");
|
|
24619
|
+
}
|
|
24620
|
+
return symmCoreClient.positions.close({
|
|
24621
|
+
...request,
|
|
24622
|
+
authToken
|
|
24623
|
+
});
|
|
24502
24624
|
}
|
|
24503
24625
|
});
|
|
24504
|
-
|
|
24626
|
+
}
|
|
24627
|
+
function useSymmCloseAllPositionsMutation(options) {
|
|
24628
|
+
const { symmCoreClient } = useSymmContext();
|
|
24629
|
+
const queryClient = reactQuery.useQueryClient();
|
|
24630
|
+
return reactQuery.useMutation({
|
|
24631
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24632
|
+
onSuccess: () => {
|
|
24633
|
+
invalidatePositions(queryClient);
|
|
24634
|
+
}
|
|
24635
|
+
}),
|
|
24505
24636
|
mutationFn: async (request) => {
|
|
24506
24637
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24507
24638
|
return symmCoreClient.positions.closeAll(request);
|
|
24508
|
-
},
|
|
24509
|
-
onSuccess: () => {
|
|
24510
|
-
invalidatePositions(queryClient);
|
|
24511
24639
|
}
|
|
24512
24640
|
});
|
|
24513
|
-
|
|
24641
|
+
}
|
|
24642
|
+
function useSymmCancelOpenMutation(options) {
|
|
24643
|
+
const { symmCoreClient } = useSymmContext();
|
|
24644
|
+
const queryClient = reactQuery.useQueryClient();
|
|
24645
|
+
return reactQuery.useMutation({
|
|
24646
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24647
|
+
onSuccess: () => {
|
|
24648
|
+
invalidatePositions(queryClient);
|
|
24649
|
+
}
|
|
24650
|
+
}),
|
|
24514
24651
|
mutationFn: async (request) => {
|
|
24515
24652
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24516
24653
|
return symmCoreClient.positions.cancelOpen(request);
|
|
24517
|
-
},
|
|
24518
|
-
onSuccess: () => {
|
|
24519
|
-
invalidatePositions(queryClient);
|
|
24520
24654
|
}
|
|
24521
24655
|
});
|
|
24522
|
-
|
|
24656
|
+
}
|
|
24657
|
+
function useSymmUpdatePositionMutation(options) {
|
|
24658
|
+
const { symmCoreClient } = useSymmContext();
|
|
24659
|
+
const queryClient = reactQuery.useQueryClient();
|
|
24660
|
+
const resolveAuthToken = useResolveTradeAuthToken();
|
|
24661
|
+
return reactQuery.useMutation({
|
|
24662
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24663
|
+
onSuccess: () => {
|
|
24664
|
+
invalidatePositions(queryClient);
|
|
24665
|
+
}
|
|
24666
|
+
}),
|
|
24523
24667
|
mutationFn: async ({
|
|
24524
24668
|
positionId,
|
|
24525
24669
|
request
|
|
24526
24670
|
}) => {
|
|
24527
24671
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24528
|
-
|
|
24529
|
-
|
|
24530
|
-
|
|
24531
|
-
|
|
24672
|
+
const typedRequest = request;
|
|
24673
|
+
const authToken = await resolveAuthToken(
|
|
24674
|
+
typedRequest.authToken,
|
|
24675
|
+
typedRequest.accountAddress
|
|
24676
|
+
);
|
|
24677
|
+
if (!authToken) {
|
|
24678
|
+
throw new Error("auth token is required to update a position");
|
|
24679
|
+
}
|
|
24680
|
+
return symmCoreClient.positions.update(positionId, {
|
|
24681
|
+
...request,
|
|
24682
|
+
authToken
|
|
24683
|
+
});
|
|
24532
24684
|
}
|
|
24533
24685
|
});
|
|
24534
|
-
return { openBasket, closePosition, closeAll, cancelOpen, updatePosition };
|
|
24535
24686
|
}
|
|
24536
24687
|
function useSymmPositions(params) {
|
|
24537
24688
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24539,14 +24690,7 @@ function useSymmPositions(params) {
|
|
|
24539
24690
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
24540
24691
|
const chainId = params.chainId ?? ctxChainId;
|
|
24541
24692
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
24542
|
-
|
|
24543
|
-
symmCoreClient,
|
|
24544
|
-
accountAddress,
|
|
24545
|
-
resolvedAddress,
|
|
24546
|
-
chainId,
|
|
24547
|
-
internalEnabled
|
|
24548
|
-
});
|
|
24549
|
-
const query = reactQuery.useQuery({
|
|
24693
|
+
return reactQuery.useQuery({
|
|
24550
24694
|
...params.query,
|
|
24551
24695
|
queryKey: symmKeys.positions({
|
|
24552
24696
|
accountAddress,
|
|
@@ -24560,10 +24704,6 @@ function useSymmPositions(params) {
|
|
|
24560
24704
|
}),
|
|
24561
24705
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24562
24706
|
});
|
|
24563
|
-
console.log("positions query", { data: query.data });
|
|
24564
|
-
return {
|
|
24565
|
-
query
|
|
24566
|
-
};
|
|
24567
24707
|
}
|
|
24568
24708
|
function useSymmOpenOrders(params) {
|
|
24569
24709
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24571,7 +24711,7 @@ function useSymmOpenOrders(params) {
|
|
|
24571
24711
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
24572
24712
|
const chainId = params.chainId ?? ctxChainId;
|
|
24573
24713
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
24574
|
-
|
|
24714
|
+
return reactQuery.useQuery({
|
|
24575
24715
|
...params.query,
|
|
24576
24716
|
queryKey: symmKeys.openOrders({
|
|
24577
24717
|
accountAddress,
|
|
@@ -24584,9 +24724,6 @@ function useSymmOpenOrders(params) {
|
|
|
24584
24724
|
}),
|
|
24585
24725
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24586
24726
|
});
|
|
24587
|
-
return {
|
|
24588
|
-
query
|
|
24589
|
-
};
|
|
24590
24727
|
}
|
|
24591
24728
|
function useSymmTradeHistory(params) {
|
|
24592
24729
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24594,7 +24731,7 @@ function useSymmTradeHistory(params) {
|
|
|
24594
24731
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
24595
24732
|
const chainId = params.chainId ?? ctxChainId;
|
|
24596
24733
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
24597
|
-
|
|
24734
|
+
return reactQuery.useQuery({
|
|
24598
24735
|
...params.query,
|
|
24599
24736
|
queryKey: symmKeys.tradeHistory({
|
|
24600
24737
|
accountAddress,
|
|
@@ -24611,34 +24748,38 @@ function useSymmTradeHistory(params) {
|
|
|
24611
24748
|
},
|
|
24612
24749
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24613
24750
|
});
|
|
24614
|
-
return {
|
|
24615
|
-
query
|
|
24616
|
-
};
|
|
24617
24751
|
}
|
|
24618
|
-
function
|
|
24752
|
+
function useSymmSetTpslMutation(options) {
|
|
24619
24753
|
const { symmCoreClient } = useSymmContext();
|
|
24620
24754
|
const queryClient = reactQuery.useQueryClient();
|
|
24621
|
-
|
|
24755
|
+
return reactQuery.useMutation({
|
|
24756
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24757
|
+
onSuccess: () => {
|
|
24758
|
+
invalidateOrders(queryClient);
|
|
24759
|
+
invalidatePositions(queryClient);
|
|
24760
|
+
}
|
|
24761
|
+
}),
|
|
24622
24762
|
mutationFn: async (request) => {
|
|
24623
24763
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24624
24764
|
return symmCoreClient.orders.setTpsl(request);
|
|
24625
|
-
},
|
|
24626
|
-
onSuccess: () => {
|
|
24627
|
-
invalidateOrders(queryClient);
|
|
24628
|
-
invalidatePositions(queryClient);
|
|
24629
24765
|
}
|
|
24630
24766
|
});
|
|
24631
|
-
|
|
24767
|
+
}
|
|
24768
|
+
function useSymmCancelTpslMutation(options) {
|
|
24769
|
+
const { symmCoreClient } = useSymmContext();
|
|
24770
|
+
const queryClient = reactQuery.useQueryClient();
|
|
24771
|
+
return reactQuery.useMutation({
|
|
24772
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24773
|
+
onSuccess: () => {
|
|
24774
|
+
invalidateOrders(queryClient);
|
|
24775
|
+
invalidatePositions(queryClient);
|
|
24776
|
+
}
|
|
24777
|
+
}),
|
|
24632
24778
|
mutationFn: async (request) => {
|
|
24633
24779
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24634
24780
|
return symmCoreClient.orders.cancelTpsl(request);
|
|
24635
|
-
},
|
|
24636
|
-
onSuccess: () => {
|
|
24637
|
-
invalidateOrders(queryClient);
|
|
24638
|
-
invalidatePositions(queryClient);
|
|
24639
24781
|
}
|
|
24640
24782
|
});
|
|
24641
|
-
return { setTpsl, cancelTpsl };
|
|
24642
24783
|
}
|
|
24643
24784
|
function useSymmTpslOrders(params) {
|
|
24644
24785
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24653,7 +24794,7 @@ function useSymmTpslOrders(params) {
|
|
|
24653
24794
|
status,
|
|
24654
24795
|
chainId
|
|
24655
24796
|
};
|
|
24656
|
-
|
|
24797
|
+
return reactQuery.useQuery({
|
|
24657
24798
|
...params.query,
|
|
24658
24799
|
queryKey: symmKeys.tpslOrdersList({
|
|
24659
24800
|
accountAddress,
|
|
@@ -24666,84 +24807,94 @@ function useSymmTpslOrders(params) {
|
|
|
24666
24807
|
queryFn: () => symmCoreClient.orders.getTpslOrders(request),
|
|
24667
24808
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24668
24809
|
});
|
|
24669
|
-
return {
|
|
24670
|
-
query
|
|
24671
|
-
};
|
|
24672
24810
|
}
|
|
24673
|
-
function
|
|
24811
|
+
function useResolvedTwapParams(params) {
|
|
24674
24812
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24675
|
-
const queryClient = reactQuery.useQueryClient();
|
|
24676
24813
|
const { accountAddress, address } = params;
|
|
24677
24814
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
24678
24815
|
const chainId = params.chainId ?? ctxChainId;
|
|
24816
|
+
return { symmCoreClient, accountAddress, resolvedAddress, chainId, query: params.query };
|
|
24817
|
+
}
|
|
24818
|
+
function useSymmTwapOrdersQuery(params) {
|
|
24819
|
+
const { symmCoreClient, accountAddress, resolvedAddress, chainId, query } = useResolvedTwapParams(params);
|
|
24679
24820
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
24680
|
-
|
|
24681
|
-
...
|
|
24821
|
+
return reactQuery.useQuery({
|
|
24822
|
+
...query,
|
|
24682
24823
|
queryKey: symmKeys.twapOrders(accountAddress ?? resolvedAddress, chainId),
|
|
24683
24824
|
queryFn: () => symmCoreClient.orders.getTwapOrders({
|
|
24684
24825
|
address: accountAddress ?? resolvedAddress,
|
|
24685
24826
|
chainId
|
|
24686
24827
|
}),
|
|
24687
|
-
enabled: internalEnabled && (
|
|
24828
|
+
enabled: internalEnabled && (query?.enabled ?? true)
|
|
24688
24829
|
});
|
|
24689
|
-
|
|
24830
|
+
}
|
|
24831
|
+
function useSymmCancelTwapOrderMutation(options) {
|
|
24832
|
+
const { symmCoreClient } = useSymmContext();
|
|
24833
|
+
const queryClient = reactQuery.useQueryClient();
|
|
24834
|
+
return reactQuery.useMutation({
|
|
24835
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24836
|
+
onSuccess: () => {
|
|
24837
|
+
invalidateOrders(queryClient);
|
|
24838
|
+
}
|
|
24839
|
+
}),
|
|
24690
24840
|
mutationFn: async (orderId) => {
|
|
24691
24841
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24692
24842
|
return symmCoreClient.orders.cancelTwapOrder(orderId);
|
|
24693
|
-
},
|
|
24694
|
-
onSuccess: () => {
|
|
24695
|
-
invalidateOrders(queryClient);
|
|
24696
24843
|
}
|
|
24697
24844
|
});
|
|
24698
|
-
return {
|
|
24699
|
-
query,
|
|
24700
|
-
cancelTwap
|
|
24701
|
-
};
|
|
24702
24845
|
}
|
|
24703
|
-
function
|
|
24846
|
+
function useSymmTriggerConfigQuery(params) {
|
|
24704
24847
|
const { symmCoreClient } = useSymmContext();
|
|
24705
|
-
const queryClient = reactQuery.useQueryClient();
|
|
24706
24848
|
const { orderId } = params;
|
|
24707
24849
|
const internalEnabled = !!symmCoreClient && !!orderId;
|
|
24708
|
-
|
|
24850
|
+
return reactQuery.useQuery({
|
|
24709
24851
|
...params.query,
|
|
24710
24852
|
queryKey: symmKeys.triggerConfig(orderId),
|
|
24711
24853
|
queryFn: () => symmCoreClient.orders.getTriggerConfig(orderId),
|
|
24712
24854
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24713
24855
|
});
|
|
24714
|
-
|
|
24856
|
+
}
|
|
24857
|
+
function useSymmSetTriggerConfigMutation(params, options) {
|
|
24858
|
+
const { symmCoreClient } = useSymmContext();
|
|
24859
|
+
const { orderId } = params;
|
|
24860
|
+
const queryClient = reactQuery.useQueryClient();
|
|
24861
|
+
return reactQuery.useMutation({
|
|
24862
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24863
|
+
onSuccess: () => {
|
|
24864
|
+
queryClient.invalidateQueries({
|
|
24865
|
+
queryKey: symmKeys.triggerConfig(orderId)
|
|
24866
|
+
});
|
|
24867
|
+
invalidateOrders(queryClient);
|
|
24868
|
+
}
|
|
24869
|
+
}),
|
|
24715
24870
|
mutationFn: async (request) => {
|
|
24716
24871
|
if (!symmCoreClient || !orderId) {
|
|
24717
24872
|
throw new Error("symm-core client or orderId not available");
|
|
24718
24873
|
}
|
|
24719
24874
|
return symmCoreClient.orders.setTriggerConfig(orderId, request);
|
|
24720
|
-
},
|
|
24721
|
-
onSuccess: () => {
|
|
24722
|
-
queryClient.invalidateQueries({
|
|
24723
|
-
queryKey: symmKeys.triggerConfig(orderId)
|
|
24724
|
-
});
|
|
24725
|
-
invalidateOrders(queryClient);
|
|
24726
24875
|
}
|
|
24727
24876
|
});
|
|
24728
|
-
|
|
24877
|
+
}
|
|
24878
|
+
function useSymmClearTriggerConfigMutation(params, options) {
|
|
24879
|
+
const { symmCoreClient } = useSymmContext();
|
|
24880
|
+
const { orderId } = params;
|
|
24881
|
+
const queryClient = reactQuery.useQueryClient();
|
|
24882
|
+
return reactQuery.useMutation({
|
|
24883
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24884
|
+
onSuccess: () => {
|
|
24885
|
+
queryClient.invalidateQueries({
|
|
24886
|
+
queryKey: symmKeys.triggerConfig(orderId)
|
|
24887
|
+
});
|
|
24888
|
+
invalidateOrders(queryClient);
|
|
24889
|
+
}
|
|
24890
|
+
}),
|
|
24729
24891
|
mutationFn: async () => {
|
|
24730
24892
|
if (!symmCoreClient || !orderId) {
|
|
24731
24893
|
throw new Error("symm-core client or orderId not available");
|
|
24732
24894
|
}
|
|
24733
24895
|
return symmCoreClient.orders.clearTriggerConfig(orderId);
|
|
24734
|
-
},
|
|
24735
|
-
onSuccess: () => {
|
|
24736
|
-
queryClient.invalidateQueries({
|
|
24737
|
-
queryKey: symmKeys.triggerConfig(orderId)
|
|
24738
|
-
});
|
|
24739
|
-
invalidateOrders(queryClient);
|
|
24740
24896
|
}
|
|
24741
24897
|
});
|
|
24742
|
-
return {
|
|
24743
|
-
query,
|
|
24744
|
-
setTriggerConfig,
|
|
24745
|
-
clearTriggerConfig
|
|
24746
|
-
};
|
|
24747
24898
|
}
|
|
24748
24899
|
function useSymmTriggerOrders(params) {
|
|
24749
24900
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24758,7 +24909,7 @@ function useSymmTriggerOrders(params) {
|
|
|
24758
24909
|
limit,
|
|
24759
24910
|
offset
|
|
24760
24911
|
};
|
|
24761
|
-
|
|
24912
|
+
return reactQuery.useQuery({
|
|
24762
24913
|
...params.query,
|
|
24763
24914
|
queryKey: symmKeys.triggerOrders({
|
|
24764
24915
|
accountAddress,
|
|
@@ -24771,16 +24922,13 @@ function useSymmTriggerOrders(params) {
|
|
|
24771
24922
|
queryFn: () => symmCoreClient.orders.listTriggerOrders(request),
|
|
24772
24923
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24773
24924
|
});
|
|
24774
|
-
return {
|
|
24775
|
-
query
|
|
24776
|
-
};
|
|
24777
24925
|
}
|
|
24778
24926
|
function useSymmMarkets(params) {
|
|
24779
24927
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24780
24928
|
const chainId = params?.chainId ?? ctxChainId;
|
|
24781
24929
|
const searchText = params?.searchText;
|
|
24782
24930
|
const internalEnabled = !!symmCoreClient;
|
|
24783
|
-
|
|
24931
|
+
return reactQuery.useQuery({
|
|
24784
24932
|
...params?.query,
|
|
24785
24933
|
queryKey: symmKeys.markets(chainId, searchText),
|
|
24786
24934
|
queryFn: () => {
|
|
@@ -24792,46 +24940,37 @@ function useSymmMarkets(params) {
|
|
|
24792
24940
|
},
|
|
24793
24941
|
enabled: internalEnabled && (params?.query?.enabled ?? true)
|
|
24794
24942
|
});
|
|
24795
|
-
return {
|
|
24796
|
-
query
|
|
24797
|
-
};
|
|
24798
24943
|
}
|
|
24799
24944
|
function useSymmHedgerMarketById(params) {
|
|
24800
24945
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24801
24946
|
const { id } = params;
|
|
24802
24947
|
const chainId = params.chainId ?? ctxChainId;
|
|
24803
24948
|
const internalEnabled = !!symmCoreClient && id != null;
|
|
24804
|
-
|
|
24949
|
+
return reactQuery.useQuery({
|
|
24805
24950
|
...params.query,
|
|
24806
24951
|
queryKey: symmKeys.hedgerMarketById(id, chainId),
|
|
24807
24952
|
queryFn: () => symmCoreClient.markets.getById(id, chainId),
|
|
24808
24953
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24809
24954
|
});
|
|
24810
|
-
return {
|
|
24811
|
-
query
|
|
24812
|
-
};
|
|
24813
24955
|
}
|
|
24814
24956
|
function useSymmHedgerMarketBySymbol(params) {
|
|
24815
24957
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24816
24958
|
const { symbol } = params;
|
|
24817
24959
|
const chainId = params.chainId ?? ctxChainId;
|
|
24818
24960
|
const internalEnabled = !!symmCoreClient && !!symbol;
|
|
24819
|
-
|
|
24961
|
+
return reactQuery.useQuery({
|
|
24820
24962
|
...params.query,
|
|
24821
24963
|
queryKey: symmKeys.hedgerMarketBySymbol(symbol, chainId),
|
|
24822
24964
|
queryFn: () => symmCoreClient.markets.getBySymbol(symbol, chainId),
|
|
24823
24965
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24824
24966
|
});
|
|
24825
|
-
return {
|
|
24826
|
-
query
|
|
24827
|
-
};
|
|
24828
24967
|
}
|
|
24829
24968
|
function useSymmLockedParams(params) {
|
|
24830
24969
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24831
24970
|
const { marketName, leverage } = params;
|
|
24832
24971
|
const chainId = params.chainId ?? ctxChainId;
|
|
24833
24972
|
const internalEnabled = !!symmCoreClient && !!marketName && leverage != null;
|
|
24834
|
-
|
|
24973
|
+
return reactQuery.useQuery({
|
|
24835
24974
|
...params.query,
|
|
24836
24975
|
queryKey: symmKeys.lockedParams(marketName, leverage, chainId),
|
|
24837
24976
|
queryFn: () => symmCoreClient.markets.getLockedParams({
|
|
@@ -24841,9 +24980,6 @@ function useSymmLockedParams(params) {
|
|
|
24841
24980
|
}),
|
|
24842
24981
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24843
24982
|
});
|
|
24844
|
-
return {
|
|
24845
|
-
query
|
|
24846
|
-
};
|
|
24847
24983
|
}
|
|
24848
24984
|
function useSymmHedgerMarkets(params) {
|
|
24849
24985
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24857,29 +24993,23 @@ function useSymmHedgerMarkets(params) {
|
|
|
24857
24993
|
searchText: searchText || void 0
|
|
24858
24994
|
};
|
|
24859
24995
|
const internalEnabled = !!symmCoreClient;
|
|
24860
|
-
|
|
24996
|
+
return reactQuery.useQuery({
|
|
24861
24997
|
...params?.query,
|
|
24862
24998
|
queryKey: symmKeys.hedgerMarkets(request),
|
|
24863
24999
|
queryFn: () => symmCoreClient.markets.listSymmHedger(request),
|
|
24864
25000
|
enabled: internalEnabled && consumerEnabled
|
|
24865
25001
|
});
|
|
24866
|
-
return {
|
|
24867
|
-
query
|
|
24868
|
-
};
|
|
24869
25002
|
}
|
|
24870
25003
|
function useSymmFunding(params) {
|
|
24871
25004
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24872
25005
|
const chainId = params?.chainId ?? ctxChainId;
|
|
24873
25006
|
const internalEnabled = !!symmCoreClient;
|
|
24874
|
-
|
|
25007
|
+
return reactQuery.useQuery({
|
|
24875
25008
|
...params?.query,
|
|
24876
25009
|
queryKey: symmKeys.fundingRates(chainId),
|
|
24877
25010
|
queryFn: () => symmCoreClient.funding.getRates({ chainId }),
|
|
24878
25011
|
enabled: internalEnabled && (params?.query?.enabled ?? true)
|
|
24879
25012
|
});
|
|
24880
|
-
return {
|
|
24881
|
-
query
|
|
24882
|
-
};
|
|
24883
25013
|
}
|
|
24884
25014
|
function useSymmFundingHistory(params) {
|
|
24885
25015
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24902,15 +25032,12 @@ function useSymmFundingHistory(params) {
|
|
|
24902
25032
|
weightMode,
|
|
24903
25033
|
includeContributions
|
|
24904
25034
|
};
|
|
24905
|
-
|
|
25035
|
+
return reactQuery.useQuery({
|
|
24906
25036
|
...params.query,
|
|
24907
25037
|
queryKey: symmKeys.fundingHistory(request),
|
|
24908
25038
|
queryFn: () => symmCoreClient.funding.getHistory(request),
|
|
24909
25039
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24910
25040
|
});
|
|
24911
|
-
return {
|
|
24912
|
-
query
|
|
24913
|
-
};
|
|
24914
25041
|
}
|
|
24915
25042
|
function useSymmFundingPayments(params) {
|
|
24916
25043
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24924,7 +25051,7 @@ function useSymmFundingPayments(params) {
|
|
|
24924
25051
|
limit,
|
|
24925
25052
|
offset
|
|
24926
25053
|
};
|
|
24927
|
-
|
|
25054
|
+
return reactQuery.useQuery({
|
|
24928
25055
|
...params.query,
|
|
24929
25056
|
queryKey: symmKeys.fundingPayments({
|
|
24930
25057
|
address,
|
|
@@ -24936,9 +25063,6 @@ function useSymmFundingPayments(params) {
|
|
|
24936
25063
|
queryFn: () => symmCoreClient.funding.getPayments(request),
|
|
24937
25064
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24938
25065
|
});
|
|
24939
|
-
return {
|
|
24940
|
-
query
|
|
24941
|
-
};
|
|
24942
25066
|
}
|
|
24943
25067
|
function useSymmPortfolio(params) {
|
|
24944
25068
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24946,7 +25070,7 @@ function useSymmPortfolio(params) {
|
|
|
24946
25070
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
24947
25071
|
const chainId = params.chainId ?? ctxChainId;
|
|
24948
25072
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
24949
|
-
|
|
25073
|
+
return reactQuery.useQuery({
|
|
24950
25074
|
...params.query,
|
|
24951
25075
|
queryKey: symmKeys.portfolio({
|
|
24952
25076
|
accountAddress,
|
|
@@ -24963,66 +25087,76 @@ function useSymmPortfolio(params) {
|
|
|
24963
25087
|
},
|
|
24964
25088
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24965
25089
|
});
|
|
24966
|
-
return {
|
|
24967
|
-
query
|
|
24968
|
-
};
|
|
24969
25090
|
}
|
|
24970
|
-
function
|
|
25091
|
+
function useResolvedNotificationsParams(params) {
|
|
24971
25092
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24972
|
-
const queryClient = reactQuery.useQueryClient();
|
|
24973
|
-
const { userAddress } = params;
|
|
24974
25093
|
const chainId = params.chainId ?? ctxChainId;
|
|
25094
|
+
return {
|
|
25095
|
+
symmCoreClient,
|
|
25096
|
+
chainId,
|
|
25097
|
+
userAddress: params.userAddress,
|
|
25098
|
+
query: params.query
|
|
25099
|
+
};
|
|
25100
|
+
}
|
|
25101
|
+
function useSymmNotificationsQuery(params) {
|
|
25102
|
+
const { symmCoreClient, chainId, userAddress, query } = useResolvedNotificationsParams(params);
|
|
24975
25103
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
24976
|
-
|
|
24977
|
-
...
|
|
25104
|
+
return reactQuery.useQuery({
|
|
25105
|
+
...query,
|
|
24978
25106
|
queryKey: symmKeys.notifications(userAddress, chainId),
|
|
24979
25107
|
queryFn: () => symmCoreClient.notifications.list({
|
|
24980
25108
|
userAddress,
|
|
24981
25109
|
chainId
|
|
24982
25110
|
}),
|
|
24983
|
-
enabled: internalEnabled && (
|
|
25111
|
+
enabled: internalEnabled && (query?.enabled ?? true)
|
|
24984
25112
|
});
|
|
24985
|
-
|
|
24986
|
-
|
|
25113
|
+
}
|
|
25114
|
+
function useSymmUnreadCountQuery(params) {
|
|
25115
|
+
const { symmCoreClient, chainId, userAddress, query } = useResolvedNotificationsParams(params);
|
|
25116
|
+
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
25117
|
+
return reactQuery.useQuery({
|
|
25118
|
+
...query,
|
|
24987
25119
|
queryKey: symmKeys.unreadCount(userAddress, chainId),
|
|
24988
25120
|
queryFn: () => symmCoreClient.notifications.getUnreadCount({
|
|
24989
25121
|
userAddress,
|
|
24990
25122
|
chainId
|
|
24991
25123
|
}),
|
|
24992
|
-
enabled: internalEnabled && (
|
|
25124
|
+
enabled: internalEnabled && (query?.enabled ?? true)
|
|
24993
25125
|
});
|
|
24994
|
-
|
|
25126
|
+
}
|
|
25127
|
+
function useSymmMarkReadNotificationMutation(params, options) {
|
|
25128
|
+
const { symmCoreClient, chainId, userAddress } = useResolvedNotificationsParams(params);
|
|
25129
|
+
const queryClient = reactQuery.useQueryClient();
|
|
25130
|
+
return reactQuery.useMutation({
|
|
25131
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
25132
|
+
onSuccess: () => {
|
|
25133
|
+
queryClient.invalidateQueries({
|
|
25134
|
+
queryKey: symmKeys.notifications(userAddress, chainId)
|
|
25135
|
+
});
|
|
25136
|
+
queryClient.invalidateQueries({
|
|
25137
|
+
queryKey: symmKeys.unreadCount(userAddress, chainId)
|
|
25138
|
+
});
|
|
25139
|
+
}
|
|
25140
|
+
}),
|
|
24995
25141
|
mutationFn: async ({ id, timestamp }) => {
|
|
24996
|
-
if (!symmCoreClient || !userAddress)
|
|
25142
|
+
if (!symmCoreClient || !userAddress) {
|
|
24997
25143
|
throw new Error("symm-core client not available");
|
|
25144
|
+
}
|
|
24998
25145
|
return symmCoreClient.notifications.markRead({
|
|
24999
25146
|
id,
|
|
25000
25147
|
timestamp,
|
|
25001
25148
|
userAddress,
|
|
25002
25149
|
chainId
|
|
25003
25150
|
});
|
|
25004
|
-
},
|
|
25005
|
-
onSuccess: () => {
|
|
25006
|
-
queryClient.invalidateQueries({
|
|
25007
|
-
queryKey: symmKeys.notifications(userAddress, chainId)
|
|
25008
|
-
});
|
|
25009
|
-
queryClient.invalidateQueries({
|
|
25010
|
-
queryKey: symmKeys.unreadCount(userAddress, chainId)
|
|
25011
|
-
});
|
|
25012
25151
|
}
|
|
25013
25152
|
});
|
|
25014
|
-
return {
|
|
25015
|
-
query: notificationsQuery,
|
|
25016
|
-
unreadQuery,
|
|
25017
|
-
markRead
|
|
25018
|
-
};
|
|
25019
25153
|
}
|
|
25020
25154
|
function useSymmPendingIds(params) {
|
|
25021
25155
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
25022
25156
|
const { accountAddress } = params;
|
|
25023
25157
|
const chainId = params.chainId ?? ctxChainId;
|
|
25024
25158
|
const internalEnabled = !!symmCoreClient && !!accountAddress;
|
|
25025
|
-
|
|
25159
|
+
return reactQuery.useQuery({
|
|
25026
25160
|
...params.query,
|
|
25027
25161
|
queryKey: symmKeys.pendingIds(accountAddress, chainId),
|
|
25028
25162
|
queryFn: () => symmCoreClient.positions.getPendingIds({
|
|
@@ -25031,9 +25165,6 @@ function useSymmPendingIds(params) {
|
|
|
25031
25165
|
}),
|
|
25032
25166
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25033
25167
|
});
|
|
25034
|
-
return {
|
|
25035
|
-
query
|
|
25036
|
-
};
|
|
25037
25168
|
}
|
|
25038
25169
|
function useSymmPendingInstantOpens(params) {
|
|
25039
25170
|
const {
|
|
@@ -25043,7 +25174,7 @@ function useSymmPendingInstantOpens(params) {
|
|
|
25043
25174
|
const { accountAddress, authToken: providedAuthToken } = params;
|
|
25044
25175
|
const chainId = params.chainId ?? ctxChainId;
|
|
25045
25176
|
const internalEnabled = !!symmCoreClient && !!accountAddress;
|
|
25046
|
-
|
|
25177
|
+
return reactQuery.useQuery({
|
|
25047
25178
|
...params.query,
|
|
25048
25179
|
queryKey: symmKeys.pendingInstantOpens(accountAddress, chainId),
|
|
25049
25180
|
queryFn: async () => {
|
|
@@ -25059,23 +25190,17 @@ function useSymmPendingInstantOpens(params) {
|
|
|
25059
25190
|
},
|
|
25060
25191
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25061
25192
|
});
|
|
25062
|
-
return {
|
|
25063
|
-
query
|
|
25064
|
-
};
|
|
25065
25193
|
}
|
|
25066
25194
|
function useSymmTwapOrder(params) {
|
|
25067
25195
|
const { symmCoreClient } = useSymmContext();
|
|
25068
25196
|
const { orderId } = params;
|
|
25069
25197
|
const internalEnabled = !!symmCoreClient && !!orderId;
|
|
25070
|
-
|
|
25198
|
+
return reactQuery.useQuery({
|
|
25071
25199
|
...params.query,
|
|
25072
25200
|
queryKey: symmKeys.twapOrder(orderId),
|
|
25073
25201
|
queryFn: () => symmCoreClient.orders.getTwapOrder(orderId),
|
|
25074
25202
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25075
25203
|
});
|
|
25076
|
-
return {
|
|
25077
|
-
query
|
|
25078
|
-
};
|
|
25079
25204
|
}
|
|
25080
25205
|
var useSymmWsStore = zustand.create((set) => ({
|
|
25081
25206
|
isConnected: false,
|
|
@@ -26280,50 +26405,68 @@ exports.symmKeys = symmKeys;
|
|
|
26280
26405
|
exports.useBinanceMarkPriceStore = useBinanceMarkPriceStore;
|
|
26281
26406
|
exports.useSymmAccountData = useSymmAccountData;
|
|
26282
26407
|
exports.useSymmAccountSummary = useSymmAccountSummary;
|
|
26283
|
-
exports.useSymmAccounts = useSymmAccounts;
|
|
26284
26408
|
exports.useSymmAccountsApi = useSymmAccountsApi;
|
|
26285
26409
|
exports.useSymmAccountsLength = useSymmAccountsLength;
|
|
26410
|
+
exports.useSymmAccountsQuery = useSymmAccountsQuery;
|
|
26286
26411
|
exports.useSymmAccountsWithPositions = useSymmAccountsWithPositions;
|
|
26287
|
-
exports.
|
|
26412
|
+
exports.useSymmAllocateCollateralMutation = useSymmAllocateCollateralMutation;
|
|
26413
|
+
exports.useSymmApprovalQuery = useSymmApprovalQuery;
|
|
26414
|
+
exports.useSymmApproveMutation = useSymmApproveMutation;
|
|
26288
26415
|
exports.useSymmAuth = useSymmAuth;
|
|
26289
26416
|
exports.useSymmAuthStore = useSymmAuthStore;
|
|
26290
26417
|
exports.useSymmAvailableMargin = useSymmAvailableMargin;
|
|
26291
26418
|
exports.useSymmBalances = useSymmBalances;
|
|
26292
26419
|
exports.useSymmCancelClose = useSymmCancelClose;
|
|
26420
|
+
exports.useSymmCancelOpenMutation = useSymmCancelOpenMutation;
|
|
26421
|
+
exports.useSymmCancelTpslMutation = useSymmCancelTpslMutation;
|
|
26422
|
+
exports.useSymmCancelTwapOrderMutation = useSymmCancelTwapOrderMutation;
|
|
26293
26423
|
exports.useSymmChartCandles = useSymmChartCandles;
|
|
26294
26424
|
exports.useSymmChartSelection = useSymmChartSelection;
|
|
26425
|
+
exports.useSymmClearTriggerConfigMutation = useSymmClearTriggerConfigMutation;
|
|
26426
|
+
exports.useSymmCloseAllPositionsMutation = useSymmCloseAllPositionsMutation;
|
|
26295
26427
|
exports.useSymmCloseOrder = useSymmCloseOrder;
|
|
26296
|
-
exports.
|
|
26428
|
+
exports.useSymmClosePositionMutation = useSymmClosePositionMutation;
|
|
26297
26429
|
exports.useSymmContext = useSymmContext;
|
|
26298
26430
|
exports.useSymmCoreClient = useSymmCoreClient;
|
|
26431
|
+
exports.useSymmCreateAccountMutation = useSymmCreateAccountMutation;
|
|
26432
|
+
exports.useSymmDeallocateCollateralMutation = useSymmDeallocateCollateralMutation;
|
|
26299
26433
|
exports.useSymmDelegation = useSymmDelegation;
|
|
26300
|
-
exports.
|
|
26434
|
+
exports.useSymmDepositAndAllocateMutation = useSymmDepositAndAllocateMutation;
|
|
26435
|
+
exports.useSymmDepositMutation = useSymmDepositMutation;
|
|
26436
|
+
exports.useSymmEditAccountNameMutation = useSymmEditAccountNameMutation;
|
|
26301
26437
|
exports.useSymmFunding = useSymmFunding;
|
|
26302
26438
|
exports.useSymmFundingHistory = useSymmFundingHistory;
|
|
26303
26439
|
exports.useSymmFundingPayments = useSymmFundingPayments;
|
|
26304
26440
|
exports.useSymmHedgerMarketById = useSymmHedgerMarketById;
|
|
26305
26441
|
exports.useSymmHedgerMarketBySymbol = useSymmHedgerMarketBySymbol;
|
|
26306
26442
|
exports.useSymmHedgerMarkets = useSymmHedgerMarkets;
|
|
26307
|
-
exports.
|
|
26443
|
+
exports.useSymmInstantTradeEnsureReadyMutation = useSymmInstantTradeEnsureReadyMutation;
|
|
26444
|
+
exports.useSymmInstantTradeExecuteMutation = useSymmInstantTradeExecuteMutation;
|
|
26445
|
+
exports.useSymmInternalTransferCollateralMutation = useSymmInternalTransferCollateralMutation;
|
|
26308
26446
|
exports.useSymmLockedParams = useSymmLockedParams;
|
|
26447
|
+
exports.useSymmMarkReadNotificationMutation = useSymmMarkReadNotificationMutation;
|
|
26309
26448
|
exports.useSymmMarkets = useSymmMarkets;
|
|
26310
|
-
exports.
|
|
26449
|
+
exports.useSymmNotificationsQuery = useSymmNotificationsQuery;
|
|
26450
|
+
exports.useSymmOpenBasketMutation = useSymmOpenBasketMutation;
|
|
26311
26451
|
exports.useSymmOpenOrders = useSymmOpenOrders;
|
|
26312
26452
|
exports.useSymmPendingIds = useSymmPendingIds;
|
|
26313
26453
|
exports.useSymmPendingInstantOpens = useSymmPendingInstantOpens;
|
|
26314
26454
|
exports.useSymmPerformanceOverlays = useSymmPerformanceOverlays;
|
|
26315
26455
|
exports.useSymmPortfolio = useSymmPortfolio;
|
|
26316
26456
|
exports.useSymmPositions = useSymmPositions;
|
|
26317
|
-
exports.
|
|
26457
|
+
exports.useSymmSetTpslMutation = useSymmSetTpslMutation;
|
|
26458
|
+
exports.useSymmSetTriggerConfigMutation = useSymmSetTriggerConfigMutation;
|
|
26459
|
+
exports.useSymmSignTermsMutation = useSymmSignTermsMutation;
|
|
26460
|
+
exports.useSymmSignatureQuery = useSymmSignatureQuery;
|
|
26318
26461
|
exports.useSymmTokenSelectionMetadata = useSymmTokenSelectionMetadata;
|
|
26319
|
-
exports.useSymmTpsl = useSymmTpsl;
|
|
26320
26462
|
exports.useSymmTpslOrders = useSymmTpslOrders;
|
|
26321
|
-
exports.useSymmTrade = useSymmTrade;
|
|
26322
26463
|
exports.useSymmTradeHistory = useSymmTradeHistory;
|
|
26323
|
-
exports.
|
|
26464
|
+
exports.useSymmTriggerConfigQuery = useSymmTriggerConfigQuery;
|
|
26324
26465
|
exports.useSymmTriggerOrders = useSymmTriggerOrders;
|
|
26325
|
-
exports.useSymmTwap = useSymmTwap;
|
|
26326
26466
|
exports.useSymmTwapOrder = useSymmTwapOrder;
|
|
26467
|
+
exports.useSymmTwapOrdersQuery = useSymmTwapOrdersQuery;
|
|
26468
|
+
exports.useSymmUnreadCountQuery = useSymmUnreadCountQuery;
|
|
26469
|
+
exports.useSymmUpdatePositionMutation = useSymmUpdatePositionMutation;
|
|
26327
26470
|
exports.useSymmWithdraw = useSymmWithdraw;
|
|
26328
26471
|
exports.useSymmWs = useSymmWs;
|
|
26329
26472
|
exports.useSymmWsStore = useSymmWsStore;
|