@pear-protocol/symmio-client 0.2.12 → 0.2.14
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 +8290 -321
- package/dist/react/index.d.ts +8290 -321
- package/dist/react/index.js +528 -493
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +500 -483
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -948,95 +948,124 @@ function invalidateOrders(qc) {
|
|
|
948
948
|
qc.invalidateQueries({ queryKey: ["symm", "triggerOrders"] });
|
|
949
949
|
}
|
|
950
950
|
|
|
951
|
-
// src/react/
|
|
952
|
-
function
|
|
951
|
+
// src/react/mutation-config.ts
|
|
952
|
+
function withSymmMutationConfig(config, internal) {
|
|
953
953
|
const {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
} =
|
|
959
|
-
|
|
960
|
-
|
|
954
|
+
onSuccess: configOnSuccess,
|
|
955
|
+
onError: configOnError,
|
|
956
|
+
onSettled: configOnSettled,
|
|
957
|
+
...rest
|
|
958
|
+
} = config ?? {};
|
|
959
|
+
return {
|
|
960
|
+
...rest,
|
|
961
|
+
onSuccess: async (...args) => {
|
|
962
|
+
await internal?.onSuccess?.(...args);
|
|
963
|
+
await configOnSuccess?.(...args);
|
|
964
|
+
},
|
|
965
|
+
onError: async (...args) => {
|
|
966
|
+
await internal?.onError?.(...args);
|
|
967
|
+
await configOnError?.(...args);
|
|
968
|
+
},
|
|
969
|
+
onSettled: async (...args) => {
|
|
970
|
+
await internal?.onSettled?.(...args);
|
|
971
|
+
await configOnSettled?.(...args);
|
|
972
|
+
}
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// src/react/hooks/use-symm-instant-trade.ts
|
|
977
|
+
function useInstantTradeDeps(params) {
|
|
978
|
+
const { symmCoreClient, chainId, address, symmioConfig } = useSymmContext();
|
|
961
979
|
const multiAccount = symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
962
980
|
const defaultAccountAddress = params.accountAddress ?? address;
|
|
963
981
|
const defaultTarget = params.target ?? DEFAULT_PARTY_B_ADDRESS[chainId];
|
|
964
982
|
const defaultSelectors = params.selectors ?? ALL_TRADING_SELECTORS;
|
|
965
|
-
|
|
966
|
-
|
|
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
|
-
if (!accessStates.every(Boolean)) {
|
|
997
|
-
await delegateAccess(walletClient, publicClient, multiAccount, {
|
|
998
|
-
account: accountAddress,
|
|
999
|
-
target,
|
|
1000
|
-
selectors: [...selectors],
|
|
1001
|
-
activate: true
|
|
1002
|
-
});
|
|
1003
|
-
await queryClient.invalidateQueries({
|
|
1004
|
-
queryKey: symmKeys.delegation(accountAddress, target, selectors, chainId)
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
return {
|
|
1008
|
-
accessToken,
|
|
1009
|
-
accountAddress,
|
|
983
|
+
return {
|
|
984
|
+
chainId,
|
|
985
|
+
defaultAccountAddress,
|
|
986
|
+
defaultSelectors,
|
|
987
|
+
defaultTarget,
|
|
988
|
+
multiAccount,
|
|
989
|
+
publicClient: params.publicClient,
|
|
990
|
+
symmCoreClient,
|
|
991
|
+
walletClient: params.walletClient
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
async function ensureInstantTradeReady(deps, queryClient, request) {
|
|
995
|
+
const { chainId, defaultAccountAddress, defaultSelectors, defaultTarget, multiAccount, publicClient, walletClient } = deps;
|
|
996
|
+
if (!publicClient || !walletClient) throw new Error("Clients not available");
|
|
997
|
+
const accountAddress = request?.accountAddress ?? defaultAccountAddress;
|
|
998
|
+
const target = request?.target ?? defaultTarget;
|
|
999
|
+
const selectors = request?.selectors ?? defaultSelectors;
|
|
1000
|
+
if (!accountAddress) throw new Error("account address is required");
|
|
1001
|
+
if (!target) throw new Error("delegation target is not configured");
|
|
1002
|
+
if (selectors.length === 0) {
|
|
1003
|
+
throw new Error("at least one delegation selector is required");
|
|
1004
|
+
}
|
|
1005
|
+
const accessToken = useSymmAuthStore.getState().getToken(accountAddress, chainId);
|
|
1006
|
+
if (!accessToken) {
|
|
1007
|
+
throw new Error("auth token is required for instant trading");
|
|
1008
|
+
}
|
|
1009
|
+
const accessStates = await Promise.all(
|
|
1010
|
+
selectors.map(
|
|
1011
|
+
(selector) => hasDelegatedAccess(publicClient, multiAccount, {
|
|
1012
|
+
account: accountAddress,
|
|
1010
1013
|
target,
|
|
1011
|
-
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
+
selector
|
|
1015
|
+
})
|
|
1016
|
+
)
|
|
1017
|
+
);
|
|
1018
|
+
if (!accessStates.every(Boolean)) {
|
|
1019
|
+
await delegateAccess(walletClient, publicClient, multiAccount, {
|
|
1020
|
+
account: accountAddress,
|
|
1021
|
+
target,
|
|
1022
|
+
selectors: [...selectors],
|
|
1023
|
+
activate: true
|
|
1024
|
+
});
|
|
1025
|
+
await queryClient.invalidateQueries({
|
|
1026
|
+
queryKey: symmKeys.delegation(accountAddress, target, selectors, chainId)
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
return {
|
|
1030
|
+
accessToken,
|
|
1031
|
+
accountAddress,
|
|
1032
|
+
target,
|
|
1033
|
+
selectors
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
function useSymmInstantTradeEnsureReadyMutation(params, options) {
|
|
1037
|
+
const queryClient = useQueryClient();
|
|
1038
|
+
const deps = useInstantTradeDeps(params);
|
|
1039
|
+
return useMutation({
|
|
1040
|
+
...withSymmMutationConfig(options?.mutation),
|
|
1041
|
+
mutationFn: async (request) => ensureInstantTradeReady(deps, queryClient, request)
|
|
1014
1042
|
});
|
|
1015
|
-
|
|
1043
|
+
}
|
|
1044
|
+
function useSymmInstantTradeExecuteMutation(params, options) {
|
|
1045
|
+
const queryClient = useQueryClient();
|
|
1046
|
+
const deps = useInstantTradeDeps(params);
|
|
1047
|
+
return useMutation({
|
|
1048
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1049
|
+
onSuccess: (_data, variables) => {
|
|
1050
|
+
if (variables.invalidatePositionsOnSuccess !== false) {
|
|
1051
|
+
invalidatePositions(queryClient);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
}),
|
|
1016
1055
|
mutationFn: async (request) => {
|
|
1017
|
-
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
1018
|
-
const setup = await
|
|
1056
|
+
if (!deps.symmCoreClient) throw new Error("symm-core client not available");
|
|
1057
|
+
const setup = await ensureInstantTradeReady(deps, queryClient, {
|
|
1019
1058
|
accountAddress: request.accountAddress,
|
|
1020
1059
|
target: request.target,
|
|
1021
1060
|
selectors: request.selectors
|
|
1022
1061
|
});
|
|
1023
1062
|
return request.action({
|
|
1024
|
-
symmCoreClient,
|
|
1063
|
+
symmCoreClient: deps.symmCoreClient,
|
|
1025
1064
|
accessToken: setup.accessToken,
|
|
1026
1065
|
accountAddress: setup.accountAddress
|
|
1027
1066
|
});
|
|
1028
|
-
},
|
|
1029
|
-
onSuccess: (_data, variables) => {
|
|
1030
|
-
if (variables.invalidatePositionsOnSuccess !== false) {
|
|
1031
|
-
invalidatePositions(queryClient);
|
|
1032
|
-
}
|
|
1033
1067
|
}
|
|
1034
1068
|
});
|
|
1035
|
-
return {
|
|
1036
|
-
delegation,
|
|
1037
|
-
ensureReady,
|
|
1038
|
-
execute
|
|
1039
|
-
};
|
|
1040
1069
|
}
|
|
1041
1070
|
function prepareAddAccount(multiAccount, account, name) {
|
|
1042
1071
|
const data = encodeFunctionData({
|
|
@@ -1095,56 +1124,65 @@ async function getAccounts(publicClient, multiAccount, user, start = 0, size = 1
|
|
|
1095
1124
|
}
|
|
1096
1125
|
|
|
1097
1126
|
// src/react/hooks/use-symm-accounts.ts
|
|
1098
|
-
|
|
1099
|
-
function useSymmAccounts(params = {}, options) {
|
|
1127
|
+
function useResolvedMultiAccount() {
|
|
1100
1128
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1129
|
+
return symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
1130
|
+
}
|
|
1131
|
+
function useSymmAccountsQuery(params = {}, options) {
|
|
1132
|
+
const { chainId } = useSymmContext();
|
|
1133
|
+
const multiAccount = useResolvedMultiAccount();
|
|
1134
|
+
const { userAddress, publicClient } = params;
|
|
1104
1135
|
const internalEnabled = !!publicClient && !!userAddress;
|
|
1105
|
-
|
|
1136
|
+
return useQuery({
|
|
1106
1137
|
...options?.query,
|
|
1107
1138
|
queryKey: symmKeys.accounts(userAddress, chainId),
|
|
1108
1139
|
queryFn: () => getAccounts(publicClient, multiAccount, userAddress),
|
|
1109
1140
|
enabled: internalEnabled && (options?.query?.enabled ?? true)
|
|
1110
1141
|
});
|
|
1111
|
-
|
|
1142
|
+
}
|
|
1143
|
+
function useSymmCreateAccountMutation(params = {}, options) {
|
|
1144
|
+
const { chainId } = useSymmContext();
|
|
1145
|
+
const queryClient = useQueryClient();
|
|
1146
|
+
const multiAccount = useResolvedMultiAccount();
|
|
1147
|
+
const { userAddress, publicClient, walletClient } = params;
|
|
1148
|
+
return useMutation({
|
|
1149
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1150
|
+
onSuccess: () => {
|
|
1151
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.accounts(userAddress, chainId) });
|
|
1152
|
+
}
|
|
1153
|
+
}),
|
|
1112
1154
|
mutationFn: async ({ name }) => {
|
|
1113
1155
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
1114
1156
|
return addAccount(walletClient, publicClient, multiAccount, name);
|
|
1115
|
-
},
|
|
1116
|
-
onSuccess: () => {
|
|
1117
|
-
queryClient.invalidateQueries({ queryKey: symmKeys.accounts(userAddress, chainId) });
|
|
1118
1157
|
}
|
|
1119
1158
|
});
|
|
1120
|
-
|
|
1159
|
+
}
|
|
1160
|
+
function useSymmEditAccountNameMutation(params = {}, options) {
|
|
1161
|
+
const { chainId } = useSymmContext();
|
|
1162
|
+
const queryClient = useQueryClient();
|
|
1163
|
+
const multiAccount = useResolvedMultiAccount();
|
|
1164
|
+
const { userAddress, publicClient, walletClient } = params;
|
|
1165
|
+
return useMutation({
|
|
1166
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1167
|
+
onSuccess: () => {
|
|
1168
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.accounts(userAddress, chainId) });
|
|
1169
|
+
}
|
|
1170
|
+
}),
|
|
1121
1171
|
mutationFn: async ({
|
|
1122
1172
|
accountAddress,
|
|
1123
1173
|
name
|
|
1124
1174
|
}) => {
|
|
1125
1175
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
1126
1176
|
return editAccountName(walletClient, publicClient, multiAccount, accountAddress, name);
|
|
1127
|
-
},
|
|
1128
|
-
onSuccess: () => {
|
|
1129
|
-
queryClient.invalidateQueries({ queryKey: symmKeys.accounts(userAddress, chainId) });
|
|
1130
1177
|
}
|
|
1131
1178
|
});
|
|
1132
|
-
return {
|
|
1133
|
-
accounts: accountsQuery.data ?? EMPTY_ACCOUNTS,
|
|
1134
|
-
count: accountsQuery.data?.length ?? 0,
|
|
1135
|
-
isLoading: accountsQuery.isLoading,
|
|
1136
|
-
error: accountsQuery.error,
|
|
1137
|
-
refetch: accountsQuery.refetch,
|
|
1138
|
-
createAccount,
|
|
1139
|
-
editName
|
|
1140
|
-
};
|
|
1141
1179
|
}
|
|
1142
1180
|
function useSymmAccountsApi(params) {
|
|
1143
1181
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
1144
1182
|
const { userAddress } = params;
|
|
1145
1183
|
const chainId = params.chainId ?? ctxChainId;
|
|
1146
1184
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
1147
|
-
|
|
1185
|
+
return useQuery({
|
|
1148
1186
|
...params.query,
|
|
1149
1187
|
queryKey: symmKeys.accountsApi(userAddress, chainId),
|
|
1150
1188
|
queryFn: () => symmCoreClient.accounts.list({
|
|
@@ -1153,19 +1191,13 @@ function useSymmAccountsApi(params) {
|
|
|
1153
1191
|
}),
|
|
1154
1192
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
1155
1193
|
});
|
|
1156
|
-
return {
|
|
1157
|
-
accounts: query.data?.data?.accounts ?? [],
|
|
1158
|
-
total: query.data?.data?.total ?? 0,
|
|
1159
|
-
isLoading: query.isLoading,
|
|
1160
|
-
refetch: query.refetch
|
|
1161
|
-
};
|
|
1162
1194
|
}
|
|
1163
1195
|
function useSymmAccountsLength(params) {
|
|
1164
1196
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
1165
1197
|
const { userAddress } = params;
|
|
1166
1198
|
const chainId = params.chainId ?? ctxChainId;
|
|
1167
1199
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
1168
|
-
|
|
1200
|
+
return useQuery({
|
|
1169
1201
|
...params.query,
|
|
1170
1202
|
queryKey: symmKeys.accountsLength(userAddress, chainId),
|
|
1171
1203
|
queryFn: () => symmCoreClient.accounts.getLength({
|
|
@@ -1174,19 +1206,13 @@ function useSymmAccountsLength(params) {
|
|
|
1174
1206
|
}),
|
|
1175
1207
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
1176
1208
|
});
|
|
1177
|
-
return {
|
|
1178
|
-
chains: query.data?.data?.chains ?? [],
|
|
1179
|
-
total: query.data?.data?.total ?? 0,
|
|
1180
|
-
isLoading: query.isLoading,
|
|
1181
|
-
refetch: query.refetch
|
|
1182
|
-
};
|
|
1183
1209
|
}
|
|
1184
1210
|
function useSymmAccountsWithPositions(params) {
|
|
1185
1211
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
1186
1212
|
const { userAddress } = params;
|
|
1187
1213
|
const chainId = params.chainId ?? ctxChainId;
|
|
1188
1214
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
1189
|
-
|
|
1215
|
+
return useQuery({
|
|
1190
1216
|
...params.query,
|
|
1191
1217
|
queryKey: symmKeys.accountsWithPositions(userAddress, chainId),
|
|
1192
1218
|
queryFn: () => symmCoreClient.accounts.getWithPositions({
|
|
@@ -1195,12 +1221,6 @@ function useSymmAccountsWithPositions(params) {
|
|
|
1195
1221
|
}),
|
|
1196
1222
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
1197
1223
|
});
|
|
1198
|
-
return {
|
|
1199
|
-
accounts: query.data?.data?.accounts ?? [],
|
|
1200
|
-
total: query.data?.data?.total ?? 0,
|
|
1201
|
-
isLoading: query.isLoading,
|
|
1202
|
-
refetch: query.refetch
|
|
1203
|
-
};
|
|
1204
1224
|
}
|
|
1205
1225
|
|
|
1206
1226
|
// src/abis/ERC20.ts
|
|
@@ -1318,14 +1338,22 @@ async function getBalance(publicClient, tokenAddress, account) {
|
|
|
1318
1338
|
}
|
|
1319
1339
|
|
|
1320
1340
|
// src/react/hooks/use-symm-approval.ts
|
|
1321
|
-
function
|
|
1341
|
+
function useResolvedApprovalConfig(params) {
|
|
1322
1342
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1323
|
-
const queryClient = useQueryClient();
|
|
1324
|
-
const { owner, amount, publicClient, walletClient, spender, collateralToken } = params;
|
|
1325
1343
|
const multiAccount = symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
1326
1344
|
const collateral = symmioConfig?.collateralAddress ?? getAddress(COLLATERAL_ADDRESS, chainId, "Collateral");
|
|
1327
|
-
const resolvedSpender = spender ?? multiAccount;
|
|
1328
|
-
const resolvedToken = collateralToken ?? collateral;
|
|
1345
|
+
const resolvedSpender = params.spender ?? multiAccount;
|
|
1346
|
+
const resolvedToken = params.collateralToken ?? collateral;
|
|
1347
|
+
return {
|
|
1348
|
+
chainId,
|
|
1349
|
+
multiAccount,
|
|
1350
|
+
resolvedSpender,
|
|
1351
|
+
resolvedToken
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
1354
|
+
function useSymmApprovalQuery(params) {
|
|
1355
|
+
const { owner, amount, publicClient } = params;
|
|
1356
|
+
const { chainId, resolvedSpender, resolvedToken } = useResolvedApprovalConfig(params);
|
|
1329
1357
|
const selectWithAmount = useCallback(
|
|
1330
1358
|
(data) => ({
|
|
1331
1359
|
...data,
|
|
@@ -1334,7 +1362,7 @@ function useSymmApproval(params) {
|
|
|
1334
1362
|
[amount]
|
|
1335
1363
|
);
|
|
1336
1364
|
const internalEnabled = !!publicClient && !!owner && !!resolvedSpender && !!resolvedToken;
|
|
1337
|
-
|
|
1365
|
+
return useQuery({
|
|
1338
1366
|
...params.query,
|
|
1339
1367
|
queryKey: symmKeys.approval(owner, resolvedSpender, chainId, resolvedToken),
|
|
1340
1368
|
queryFn: async () => {
|
|
@@ -1347,29 +1375,35 @@ function useSymmApproval(params) {
|
|
|
1347
1375
|
select: selectWithAmount,
|
|
1348
1376
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
1349
1377
|
});
|
|
1350
|
-
|
|
1378
|
+
}
|
|
1379
|
+
function useSymmApproveMutation(params, options) {
|
|
1380
|
+
const { owner, publicClient, walletClient } = params;
|
|
1381
|
+
const { chainId, multiAccount, resolvedSpender, resolvedToken } = useResolvedApprovalConfig(params);
|
|
1382
|
+
const queryClient = useQueryClient();
|
|
1383
|
+
return useMutation({
|
|
1384
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1385
|
+
onSuccess: () => {
|
|
1386
|
+
queryClient.invalidateQueries({
|
|
1387
|
+
queryKey: symmKeys.approval(owner, resolvedSpender, chainId, resolvedToken)
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
}),
|
|
1351
1391
|
mutationFn: async (approveAmount) => {
|
|
1352
1392
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
1353
1393
|
return approve(walletClient, publicClient, resolvedToken, multiAccount, approveAmount);
|
|
1354
|
-
},
|
|
1355
|
-
onSuccess: () => {
|
|
1356
|
-
queryClient.invalidateQueries({
|
|
1357
|
-
queryKey: symmKeys.approval(owner, resolvedSpender, chainId, resolvedToken)
|
|
1358
|
-
});
|
|
1359
1394
|
}
|
|
1360
1395
|
});
|
|
1361
|
-
return {
|
|
1362
|
-
approvalState: approvalQuery.data?.state ?? null,
|
|
1363
|
-
allowance: approvalQuery.data?.allowance ?? 0n,
|
|
1364
|
-
balance: approvalQuery.data?.balance ?? 0n,
|
|
1365
|
-
isLoading: approvalQuery.isLoading,
|
|
1366
|
-
approve: approveMutation
|
|
1367
|
-
};
|
|
1368
1396
|
}
|
|
1369
|
-
function useSymmCancelClose() {
|
|
1397
|
+
function useSymmCancelClose(options) {
|
|
1370
1398
|
const { symmCoreClient, chainId, address } = useSymmContext();
|
|
1371
1399
|
const queryClient = useQueryClient();
|
|
1372
|
-
|
|
1400
|
+
return useMutation({
|
|
1401
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1402
|
+
onSuccess: () => {
|
|
1403
|
+
invalidateOrders(queryClient);
|
|
1404
|
+
invalidatePositions(queryClient);
|
|
1405
|
+
}
|
|
1406
|
+
}),
|
|
1373
1407
|
mutationFn: async ({
|
|
1374
1408
|
quoteId,
|
|
1375
1409
|
authToken,
|
|
@@ -1390,18 +1424,19 @@ function useSymmCancelClose() {
|
|
|
1390
1424
|
authToken: resolvedAuthToken,
|
|
1391
1425
|
chainId: resolvedChainId
|
|
1392
1426
|
});
|
|
1393
|
-
},
|
|
1394
|
-
onSuccess: () => {
|
|
1395
|
-
invalidateOrders(queryClient);
|
|
1396
|
-
invalidatePositions(queryClient);
|
|
1397
1427
|
}
|
|
1398
1428
|
});
|
|
1399
|
-
return { cancelClose };
|
|
1400
1429
|
}
|
|
1401
|
-
function useSymmCloseOrder() {
|
|
1430
|
+
function useSymmCloseOrder(options) {
|
|
1402
1431
|
const { symmCoreClient, address, chainId } = useSymmContext();
|
|
1403
1432
|
const queryClient = useQueryClient();
|
|
1404
|
-
|
|
1433
|
+
return useMutation({
|
|
1434
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1435
|
+
onSuccess: () => {
|
|
1436
|
+
invalidateOrders(queryClient);
|
|
1437
|
+
invalidatePositions(queryClient);
|
|
1438
|
+
}
|
|
1439
|
+
}),
|
|
1405
1440
|
mutationFn: async (request) => {
|
|
1406
1441
|
if (!symmCoreClient) {
|
|
1407
1442
|
throw new Error("symm-core client not available");
|
|
@@ -1411,13 +1446,8 @@ function useSymmCloseOrder() {
|
|
|
1411
1446
|
type: request.type,
|
|
1412
1447
|
authToken: request.authToken ?? (address ? useSymmAuthStore.getState().getToken(address, chainId) ?? void 0 : void 0)
|
|
1413
1448
|
});
|
|
1414
|
-
},
|
|
1415
|
-
onSuccess: () => {
|
|
1416
|
-
invalidateOrders(queryClient);
|
|
1417
|
-
invalidatePositions(queryClient);
|
|
1418
1449
|
}
|
|
1419
1450
|
});
|
|
1420
|
-
return { closeOrder };
|
|
1421
1451
|
}
|
|
1422
1452
|
function prepareDeposit(multiAccount, account, params) {
|
|
1423
1453
|
validateAmount(params.amount, "deposit amount");
|
|
@@ -1471,38 +1501,52 @@ async function depositAndAllocate(walletClient, publicClient, multiAccount, para
|
|
|
1471
1501
|
}
|
|
1472
1502
|
|
|
1473
1503
|
// src/react/hooks/use-symm-deposit.ts
|
|
1474
|
-
function
|
|
1504
|
+
function useResolvedDepositParams(params = {}) {
|
|
1475
1505
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1476
|
-
const { publicClient, walletClient } = params;
|
|
1477
|
-
const queryClient = useQueryClient();
|
|
1478
1506
|
const multiAccount = symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
1479
|
-
|
|
1507
|
+
return {
|
|
1508
|
+
multiAccount,
|
|
1509
|
+
publicClient: params.publicClient,
|
|
1510
|
+
walletClient: params.walletClient
|
|
1511
|
+
};
|
|
1512
|
+
}
|
|
1513
|
+
function useSymmDepositMutation(params = {}, options) {
|
|
1514
|
+
const queryClient = useQueryClient();
|
|
1515
|
+
const { multiAccount, publicClient, walletClient } = useResolvedDepositParams(params);
|
|
1516
|
+
return useMutation({
|
|
1517
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1518
|
+
onSuccess: () => {
|
|
1519
|
+
invalidateBalances(queryClient);
|
|
1520
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "approval"] });
|
|
1521
|
+
}
|
|
1522
|
+
}),
|
|
1480
1523
|
mutationFn: async ({
|
|
1481
1524
|
account,
|
|
1482
1525
|
amount
|
|
1483
1526
|
}) => {
|
|
1484
1527
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
1485
1528
|
return deposit(walletClient, publicClient, multiAccount, { account, amount });
|
|
1486
|
-
},
|
|
1487
|
-
onSuccess: () => {
|
|
1488
|
-
invalidateBalances(queryClient);
|
|
1489
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "approval"] });
|
|
1490
1529
|
}
|
|
1491
1530
|
});
|
|
1492
|
-
|
|
1531
|
+
}
|
|
1532
|
+
function useSymmDepositAndAllocateMutation(params = {}, options) {
|
|
1533
|
+
const queryClient = useQueryClient();
|
|
1534
|
+
const { multiAccount, publicClient, walletClient } = useResolvedDepositParams(params);
|
|
1535
|
+
return useMutation({
|
|
1536
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1537
|
+
onSuccess: () => {
|
|
1538
|
+
invalidateBalances(queryClient);
|
|
1539
|
+
queryClient.invalidateQueries({ queryKey: ["symm", "approval"] });
|
|
1540
|
+
}
|
|
1541
|
+
}),
|
|
1493
1542
|
mutationFn: async ({
|
|
1494
1543
|
account,
|
|
1495
1544
|
amount
|
|
1496
1545
|
}) => {
|
|
1497
1546
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
1498
1547
|
return depositAndAllocate(walletClient, publicClient, multiAccount, { account, amount });
|
|
1499
|
-
},
|
|
1500
|
-
onSuccess: () => {
|
|
1501
|
-
invalidateBalances(queryClient);
|
|
1502
|
-
queryClient.invalidateQueries({ queryKey: ["symm", "approval"] });
|
|
1503
1548
|
}
|
|
1504
1549
|
});
|
|
1505
|
-
return { deposit: depositMutation, depositAndAllocate: depositAndAllocateMutation };
|
|
1506
1550
|
}
|
|
1507
1551
|
function prepareWithdraw(multiAccount, account, params) {
|
|
1508
1552
|
validateAmount(params.amount, "withdraw amount");
|
|
@@ -1531,24 +1575,25 @@ async function withdraw(walletClient, publicClient, multiAccount, params) {
|
|
|
1531
1575
|
}
|
|
1532
1576
|
|
|
1533
1577
|
// src/react/hooks/use-symm-withdraw.ts
|
|
1534
|
-
function useSymmWithdraw(params = {}) {
|
|
1578
|
+
function useSymmWithdraw(params = {}, options) {
|
|
1535
1579
|
const { chainId, symmioConfig } = useSymmContext();
|
|
1536
1580
|
const { publicClient, walletClient } = params;
|
|
1537
1581
|
const queryClient = useQueryClient();
|
|
1538
1582
|
const multiAccount = symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
1539
|
-
|
|
1583
|
+
return useMutation({
|
|
1584
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
1585
|
+
onSuccess: () => {
|
|
1586
|
+
invalidateBalances(queryClient);
|
|
1587
|
+
}
|
|
1588
|
+
}),
|
|
1540
1589
|
mutationFn: async ({
|
|
1541
1590
|
account,
|
|
1542
1591
|
amount
|
|
1543
1592
|
}) => {
|
|
1544
1593
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
1545
1594
|
return withdraw(walletClient, publicClient, multiAccount, { account, amount });
|
|
1546
|
-
},
|
|
1547
|
-
onSuccess: () => {
|
|
1548
|
-
invalidateBalances(queryClient);
|
|
1549
1595
|
}
|
|
1550
1596
|
});
|
|
1551
|
-
return { withdraw: withdrawMutation };
|
|
1552
1597
|
}
|
|
1553
1598
|
|
|
1554
1599
|
// src/abis/SymmioDiamond.ts
|
|
@@ -24199,10 +24244,8 @@ var MuonClient = class {
|
|
|
24199
24244
|
};
|
|
24200
24245
|
|
|
24201
24246
|
// src/react/hooks/use-symm-collateral.ts
|
|
24202
|
-
function
|
|
24247
|
+
function useResolvedCollateralDeps(params = {}) {
|
|
24203
24248
|
const { chainId, symmioConfig } = useSymmContext();
|
|
24204
|
-
const { publicClient, walletClient } = params;
|
|
24205
|
-
const queryClient = useQueryClient();
|
|
24206
24249
|
const multiAccount = symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
24207
24250
|
const symmioDiamond = symmioConfig?.symmioDiamondAddress ?? getAddress(SYMMIO_DIAMOND_ADDRESS, chainId, "SymmioDiamond");
|
|
24208
24251
|
const muon = useMemo(
|
|
@@ -24212,19 +24255,42 @@ function useSymmCollateral(params = {}) {
|
|
|
24212
24255
|
}),
|
|
24213
24256
|
[symmioConfig?.muonBaseUrls, symmioConfig?.muonAppName]
|
|
24214
24257
|
);
|
|
24215
|
-
|
|
24258
|
+
return {
|
|
24259
|
+
chainId,
|
|
24260
|
+
muon,
|
|
24261
|
+
multiAccount,
|
|
24262
|
+
publicClient: params.publicClient,
|
|
24263
|
+
symmioDiamond,
|
|
24264
|
+
walletClient: params.walletClient
|
|
24265
|
+
};
|
|
24266
|
+
}
|
|
24267
|
+
function useSymmAllocateCollateralMutation(params = {}, options) {
|
|
24268
|
+
const queryClient = useQueryClient();
|
|
24269
|
+
const { multiAccount, publicClient, walletClient } = useResolvedCollateralDeps(params);
|
|
24270
|
+
return useMutation({
|
|
24271
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24272
|
+
onSuccess: () => {
|
|
24273
|
+
invalidateBalances(queryClient);
|
|
24274
|
+
}
|
|
24275
|
+
}),
|
|
24216
24276
|
mutationFn: async ({
|
|
24217
24277
|
subAccount,
|
|
24218
24278
|
amount
|
|
24219
24279
|
}) => {
|
|
24220
24280
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
24221
24281
|
return allocate(walletClient, publicClient, multiAccount, subAccount, { amount });
|
|
24222
|
-
},
|
|
24223
|
-
onSuccess: () => {
|
|
24224
|
-
invalidateBalances(queryClient);
|
|
24225
24282
|
}
|
|
24226
24283
|
});
|
|
24227
|
-
|
|
24284
|
+
}
|
|
24285
|
+
function useSymmDeallocateCollateralMutation(params = {}, options) {
|
|
24286
|
+
const queryClient = useQueryClient();
|
|
24287
|
+
const { chainId, muon, multiAccount, publicClient, symmioDiamond, walletClient } = useResolvedCollateralDeps(params);
|
|
24288
|
+
return useMutation({
|
|
24289
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24290
|
+
onSuccess: () => {
|
|
24291
|
+
invalidateBalances(queryClient);
|
|
24292
|
+
}
|
|
24293
|
+
}),
|
|
24228
24294
|
mutationFn: async ({
|
|
24229
24295
|
subAccount,
|
|
24230
24296
|
amount
|
|
@@ -24239,28 +24305,26 @@ function useSymmCollateral(params = {}) {
|
|
|
24239
24305
|
amount,
|
|
24240
24306
|
upnlSig
|
|
24241
24307
|
});
|
|
24242
|
-
},
|
|
24243
|
-
onSuccess: () => {
|
|
24244
|
-
invalidateBalances(queryClient);
|
|
24245
24308
|
}
|
|
24246
24309
|
});
|
|
24247
|
-
|
|
24310
|
+
}
|
|
24311
|
+
function useSymmInternalTransferCollateralMutation(params = {}, options) {
|
|
24312
|
+
const queryClient = useQueryClient();
|
|
24313
|
+
const { multiAccount, publicClient, walletClient } = useResolvedCollateralDeps(params);
|
|
24314
|
+
return useMutation({
|
|
24315
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24316
|
+
onSuccess: () => {
|
|
24317
|
+
invalidateBalances(queryClient);
|
|
24318
|
+
}
|
|
24319
|
+
}),
|
|
24248
24320
|
mutationFn: async ({
|
|
24249
24321
|
subAccount,
|
|
24250
24322
|
params: transferParams
|
|
24251
24323
|
}) => {
|
|
24252
24324
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
24253
24325
|
return internalTransfer(walletClient, publicClient, multiAccount, subAccount, transferParams);
|
|
24254
|
-
},
|
|
24255
|
-
onSuccess: () => {
|
|
24256
|
-
invalidateBalances(queryClient);
|
|
24257
24326
|
}
|
|
24258
24327
|
});
|
|
24259
|
-
return {
|
|
24260
|
-
allocate: allocateMutation,
|
|
24261
|
-
deallocate: deallocateMutation,
|
|
24262
|
-
internalTransfer: internalTransferMutation
|
|
24263
|
-
};
|
|
24264
24328
|
}
|
|
24265
24329
|
|
|
24266
24330
|
// src/abis/SignatureStore.ts
|
|
@@ -24352,41 +24416,47 @@ async function hasSignedCurrentVersion(publicClient, signatureStore, user) {
|
|
|
24352
24416
|
}
|
|
24353
24417
|
|
|
24354
24418
|
// src/react/hooks/use-symm-signature.ts
|
|
24355
|
-
function
|
|
24419
|
+
function useResolvedSignatureStore() {
|
|
24356
24420
|
const { chainId, symmioConfig } = useSymmContext();
|
|
24357
|
-
const { userAddress, publicClient, walletClient } = params;
|
|
24358
|
-
const queryClient = useQueryClient();
|
|
24359
24421
|
let signatureStore;
|
|
24360
24422
|
try {
|
|
24361
24423
|
signatureStore = symmioConfig?.signatureStoreAddress ?? getAddress(SIGNATURE_STORE_ADDRESS, chainId, "SignatureStore");
|
|
24362
24424
|
} catch {
|
|
24425
|
+
signatureStore = void 0;
|
|
24363
24426
|
}
|
|
24427
|
+
return { chainId, signatureStore };
|
|
24428
|
+
}
|
|
24429
|
+
function useSymmSignatureQuery(params = {}, options) {
|
|
24430
|
+
const { userAddress, publicClient } = params;
|
|
24431
|
+
const { chainId, signatureStore } = useResolvedSignatureStore();
|
|
24364
24432
|
const internalEnabled = !!publicClient && !!userAddress && !!signatureStore;
|
|
24365
|
-
|
|
24433
|
+
return useQuery({
|
|
24366
24434
|
...options?.query,
|
|
24367
24435
|
queryKey: symmKeys.signature(userAddress, chainId),
|
|
24368
24436
|
queryFn: () => hasSignedCurrentVersion(publicClient, signatureStore, userAddress),
|
|
24369
24437
|
enabled: internalEnabled && (options?.query?.enabled ?? true)
|
|
24370
24438
|
});
|
|
24371
|
-
|
|
24439
|
+
}
|
|
24440
|
+
function useSymmSignTermsMutation(params = {}, options) {
|
|
24441
|
+
const { userAddress, publicClient, walletClient } = params;
|
|
24442
|
+
const { chainId, signatureStore } = useResolvedSignatureStore();
|
|
24443
|
+
const queryClient = useQueryClient();
|
|
24444
|
+
return useMutation({
|
|
24445
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24446
|
+
onSuccess: () => {
|
|
24447
|
+
queryClient.invalidateQueries({
|
|
24448
|
+
queryKey: symmKeys.signature(userAddress, chainId)
|
|
24449
|
+
});
|
|
24450
|
+
}
|
|
24451
|
+
}),
|
|
24372
24452
|
mutationFn: async () => {
|
|
24373
24453
|
if (!walletClient || !publicClient || !signatureStore) {
|
|
24374
24454
|
throw new Error("Clients or SignatureStore not available");
|
|
24375
24455
|
}
|
|
24376
24456
|
const sig = await signTermsMessage(walletClient, publicClient, signatureStore);
|
|
24377
24457
|
await storeSignature(walletClient, publicClient, signatureStore, sig);
|
|
24378
|
-
},
|
|
24379
|
-
onSuccess: () => {
|
|
24380
|
-
queryClient.invalidateQueries({
|
|
24381
|
-
queryKey: symmKeys.signature(userAddress, chainId)
|
|
24382
|
-
});
|
|
24383
24458
|
}
|
|
24384
24459
|
});
|
|
24385
|
-
return {
|
|
24386
|
-
hasSigned: signedQuery.data ?? false,
|
|
24387
|
-
isLoading: signedQuery.isLoading,
|
|
24388
|
-
signTerms
|
|
24389
|
-
};
|
|
24390
24460
|
}
|
|
24391
24461
|
|
|
24392
24462
|
// src/actions/stats.ts
|
|
@@ -24414,25 +24484,6 @@ async function getPartyAStats(publicClient, symmioDiamond, partyA) {
|
|
|
24414
24484
|
nonces: 0
|
|
24415
24485
|
};
|
|
24416
24486
|
}
|
|
24417
|
-
function calculateAvailableForOrder(stats, upnl) {
|
|
24418
|
-
const {
|
|
24419
|
-
allocatedBalance,
|
|
24420
|
-
lockedCVA,
|
|
24421
|
-
lockedLF,
|
|
24422
|
-
lockedPartyAMM,
|
|
24423
|
-
pendingLockedCVA,
|
|
24424
|
-
pendingLockedLF,
|
|
24425
|
-
pendingLockedPartyAMM
|
|
24426
|
-
} = stats;
|
|
24427
|
-
const totalPendingLocked = pendingLockedCVA + pendingLockedLF + pendingLockedPartyAMM;
|
|
24428
|
-
if (upnl >= 0n) {
|
|
24429
|
-
const totalLocked = lockedCVA + lockedLF + lockedPartyAMM;
|
|
24430
|
-
return allocatedBalance + upnl - totalLocked - totalPendingLocked;
|
|
24431
|
-
}
|
|
24432
|
-
const absUpnl = -upnl;
|
|
24433
|
-
const consideringMm = absUpnl > lockedPartyAMM ? absUpnl : lockedPartyAMM;
|
|
24434
|
-
return allocatedBalance - lockedCVA - lockedLF - totalPendingLocked - consideringMm;
|
|
24435
|
-
}
|
|
24436
24487
|
|
|
24437
24488
|
// src/react/hooks/use-symm-available-margin.ts
|
|
24438
24489
|
function useSymmAvailableMargin(params) {
|
|
@@ -24443,32 +24494,25 @@ function useSymmAvailableMargin(params) {
|
|
|
24443
24494
|
const selectWithUpnl = useCallback(
|
|
24444
24495
|
(stats) => ({
|
|
24445
24496
|
...stats,
|
|
24446
|
-
upnl: resolvedUpnl
|
|
24447
|
-
availableForOrder: calculateAvailableForOrder(stats, resolvedUpnl)
|
|
24497
|
+
upnl: resolvedUpnl
|
|
24448
24498
|
}),
|
|
24449
24499
|
[resolvedUpnl]
|
|
24450
24500
|
);
|
|
24451
24501
|
const internalEnabled = !!publicClient && !!accountAddress;
|
|
24452
|
-
|
|
24502
|
+
return useQuery({
|
|
24453
24503
|
...params.query,
|
|
24454
24504
|
queryKey: symmKeys.availableMargin(accountAddress, chainId),
|
|
24455
24505
|
queryFn: () => getPartyAStats(publicClient, symmioDiamond, accountAddress),
|
|
24456
24506
|
select: selectWithUpnl,
|
|
24457
24507
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24458
24508
|
});
|
|
24459
|
-
return {
|
|
24460
|
-
availableForOrder: query.data?.availableForOrder ?? null,
|
|
24461
|
-
stats: query.data ?? null,
|
|
24462
|
-
isLoading: query.isLoading,
|
|
24463
|
-
refetch: query.refetch
|
|
24464
|
-
};
|
|
24465
24509
|
}
|
|
24466
24510
|
function useSymmAccountSummary(params) {
|
|
24467
24511
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24468
24512
|
const { userAddress } = params;
|
|
24469
24513
|
const chainId = params.chainId ?? ctxChainId;
|
|
24470
24514
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
24471
|
-
|
|
24515
|
+
return useQuery({
|
|
24472
24516
|
...params.query,
|
|
24473
24517
|
queryKey: symmKeys.accountSummary(userAddress, chainId),
|
|
24474
24518
|
queryFn: () => symmCoreClient.accounts.getSummary({
|
|
@@ -24477,19 +24521,13 @@ function useSymmAccountSummary(params) {
|
|
|
24477
24521
|
}),
|
|
24478
24522
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24479
24523
|
});
|
|
24480
|
-
return {
|
|
24481
|
-
accounts: query.data?.data?.accounts ?? [],
|
|
24482
|
-
total: query.data?.data?.total ?? 0,
|
|
24483
|
-
isLoading: query.isLoading,
|
|
24484
|
-
refetch: query.refetch
|
|
24485
|
-
};
|
|
24486
24524
|
}
|
|
24487
24525
|
function useSymmAccountData(params) {
|
|
24488
24526
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24489
24527
|
const { address, upnl } = params;
|
|
24490
24528
|
const chainId = params.chainId ?? ctxChainId;
|
|
24491
24529
|
const internalEnabled = !!symmCoreClient && !!address;
|
|
24492
|
-
|
|
24530
|
+
return useQuery({
|
|
24493
24531
|
...params.query,
|
|
24494
24532
|
queryKey: symmKeys.accountData(address, chainId, upnl),
|
|
24495
24533
|
queryFn: () => symmCoreClient.accounts.getData({
|
|
@@ -24499,18 +24537,13 @@ function useSymmAccountData(params) {
|
|
|
24499
24537
|
}),
|
|
24500
24538
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24501
24539
|
});
|
|
24502
|
-
return {
|
|
24503
|
-
accountData: query.data?.data ?? null,
|
|
24504
|
-
isLoading: query.isLoading,
|
|
24505
|
-
refetch: query.refetch
|
|
24506
|
-
};
|
|
24507
24540
|
}
|
|
24508
24541
|
function useSymmBalances(params) {
|
|
24509
24542
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24510
24543
|
const { userAddress, multiAccountAddress } = params;
|
|
24511
24544
|
const chainId = params.chainId ?? ctxChainId;
|
|
24512
24545
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
24513
|
-
|
|
24546
|
+
return useQuery({
|
|
24514
24547
|
...params.query,
|
|
24515
24548
|
queryKey: symmKeys.balances(userAddress, chainId),
|
|
24516
24549
|
queryFn: () => symmCoreClient.accounts.getBalanceInfo({
|
|
@@ -24520,64 +24553,134 @@ function useSymmBalances(params) {
|
|
|
24520
24553
|
}),
|
|
24521
24554
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24522
24555
|
});
|
|
24523
|
-
return {
|
|
24524
|
-
balanceInfo: query.data ?? null,
|
|
24525
|
-
isLoading: query.isLoading,
|
|
24526
|
-
refetch: query.refetch
|
|
24527
|
-
};
|
|
24528
24556
|
}
|
|
24529
|
-
function
|
|
24557
|
+
function useResolveTradeAuthToken() {
|
|
24558
|
+
const context = useSymmContext();
|
|
24559
|
+
const { address, chainId } = context;
|
|
24560
|
+
const { refreshAuth } = useSymmAuth({ address, chainId });
|
|
24561
|
+
const refreshAuthFromContext = context.refreshAuth;
|
|
24562
|
+
return useCallback(
|
|
24563
|
+
async (providedAuthToken, accountAddress) => {
|
|
24564
|
+
if (providedAuthToken) {
|
|
24565
|
+
return providedAuthToken;
|
|
24566
|
+
}
|
|
24567
|
+
const resolvedAccountAddress = accountAddress ?? address;
|
|
24568
|
+
if (!resolvedAccountAddress) {
|
|
24569
|
+
return null;
|
|
24570
|
+
}
|
|
24571
|
+
const inMemoryToken = useSymmAuthStore.getState().getToken(resolvedAccountAddress, chainId);
|
|
24572
|
+
if (inMemoryToken) {
|
|
24573
|
+
return inMemoryToken;
|
|
24574
|
+
}
|
|
24575
|
+
if (refreshAuthFromContext) {
|
|
24576
|
+
return refreshAuthFromContext(resolvedAccountAddress);
|
|
24577
|
+
}
|
|
24578
|
+
return refreshAuth(resolvedAccountAddress);
|
|
24579
|
+
},
|
|
24580
|
+
[address, chainId, refreshAuth, refreshAuthFromContext]
|
|
24581
|
+
);
|
|
24582
|
+
}
|
|
24583
|
+
function useSymmOpenBasketMutation(options) {
|
|
24530
24584
|
const { symmCoreClient } = useSymmContext();
|
|
24531
24585
|
const queryClient = useQueryClient();
|
|
24532
|
-
|
|
24586
|
+
return useMutation({
|
|
24587
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24588
|
+
onSuccess: () => {
|
|
24589
|
+
invalidatePositions(queryClient);
|
|
24590
|
+
}
|
|
24591
|
+
}),
|
|
24533
24592
|
mutationFn: async (request) => {
|
|
24534
24593
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24535
24594
|
return symmCoreClient.positions.openBasket(request);
|
|
24536
|
-
},
|
|
24537
|
-
onSuccess: () => {
|
|
24538
|
-
invalidatePositions(queryClient);
|
|
24539
24595
|
}
|
|
24540
24596
|
});
|
|
24541
|
-
|
|
24597
|
+
}
|
|
24598
|
+
function useSymmClosePositionMutation(options) {
|
|
24599
|
+
const { symmCoreClient } = useSymmContext();
|
|
24600
|
+
const queryClient = useQueryClient();
|
|
24601
|
+
const resolveAuthToken = useResolveTradeAuthToken();
|
|
24602
|
+
return useMutation({
|
|
24603
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24604
|
+
onSuccess: () => {
|
|
24605
|
+
invalidatePositions(queryClient);
|
|
24606
|
+
}
|
|
24607
|
+
}),
|
|
24542
24608
|
mutationFn: async (request) => {
|
|
24543
24609
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24544
|
-
|
|
24545
|
-
|
|
24546
|
-
|
|
24547
|
-
|
|
24610
|
+
const typedRequest = request;
|
|
24611
|
+
const authToken = await resolveAuthToken(
|
|
24612
|
+
typedRequest.authToken,
|
|
24613
|
+
typedRequest.accountAddress
|
|
24614
|
+
);
|
|
24615
|
+
if (!authToken) {
|
|
24616
|
+
throw new Error("auth token is required to close a position");
|
|
24617
|
+
}
|
|
24618
|
+
return symmCoreClient.positions.close({
|
|
24619
|
+
...request,
|
|
24620
|
+
authToken
|
|
24621
|
+
});
|
|
24548
24622
|
}
|
|
24549
24623
|
});
|
|
24550
|
-
|
|
24624
|
+
}
|
|
24625
|
+
function useSymmCloseAllPositionsMutation(options) {
|
|
24626
|
+
const { symmCoreClient } = useSymmContext();
|
|
24627
|
+
const queryClient = useQueryClient();
|
|
24628
|
+
return useMutation({
|
|
24629
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24630
|
+
onSuccess: () => {
|
|
24631
|
+
invalidatePositions(queryClient);
|
|
24632
|
+
}
|
|
24633
|
+
}),
|
|
24551
24634
|
mutationFn: async (request) => {
|
|
24552
24635
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24553
24636
|
return symmCoreClient.positions.closeAll(request);
|
|
24554
|
-
},
|
|
24555
|
-
onSuccess: () => {
|
|
24556
|
-
invalidatePositions(queryClient);
|
|
24557
24637
|
}
|
|
24558
24638
|
});
|
|
24559
|
-
|
|
24639
|
+
}
|
|
24640
|
+
function useSymmCancelOpenMutation(options) {
|
|
24641
|
+
const { symmCoreClient } = useSymmContext();
|
|
24642
|
+
const queryClient = useQueryClient();
|
|
24643
|
+
return useMutation({
|
|
24644
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24645
|
+
onSuccess: () => {
|
|
24646
|
+
invalidatePositions(queryClient);
|
|
24647
|
+
}
|
|
24648
|
+
}),
|
|
24560
24649
|
mutationFn: async (request) => {
|
|
24561
24650
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24562
24651
|
return symmCoreClient.positions.cancelOpen(request);
|
|
24563
|
-
},
|
|
24564
|
-
onSuccess: () => {
|
|
24565
|
-
invalidatePositions(queryClient);
|
|
24566
24652
|
}
|
|
24567
24653
|
});
|
|
24568
|
-
|
|
24654
|
+
}
|
|
24655
|
+
function useSymmUpdatePositionMutation(options) {
|
|
24656
|
+
const { symmCoreClient } = useSymmContext();
|
|
24657
|
+
const queryClient = useQueryClient();
|
|
24658
|
+
const resolveAuthToken = useResolveTradeAuthToken();
|
|
24659
|
+
return useMutation({
|
|
24660
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24661
|
+
onSuccess: () => {
|
|
24662
|
+
invalidatePositions(queryClient);
|
|
24663
|
+
}
|
|
24664
|
+
}),
|
|
24569
24665
|
mutationFn: async ({
|
|
24570
24666
|
positionId,
|
|
24571
24667
|
request
|
|
24572
24668
|
}) => {
|
|
24573
24669
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24574
|
-
|
|
24575
|
-
|
|
24576
|
-
|
|
24577
|
-
|
|
24670
|
+
const typedRequest = request;
|
|
24671
|
+
const authToken = await resolveAuthToken(
|
|
24672
|
+
typedRequest.authToken,
|
|
24673
|
+
typedRequest.accountAddress
|
|
24674
|
+
);
|
|
24675
|
+
if (!authToken) {
|
|
24676
|
+
throw new Error("auth token is required to update a position");
|
|
24677
|
+
}
|
|
24678
|
+
return symmCoreClient.positions.update(positionId, {
|
|
24679
|
+
...request,
|
|
24680
|
+
authToken
|
|
24681
|
+
});
|
|
24578
24682
|
}
|
|
24579
24683
|
});
|
|
24580
|
-
return { openBasket, closePosition, closeAll, cancelOpen, updatePosition };
|
|
24581
24684
|
}
|
|
24582
24685
|
function useSymmPositions(params) {
|
|
24583
24686
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24585,14 +24688,7 @@ function useSymmPositions(params) {
|
|
|
24585
24688
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
24586
24689
|
const chainId = params.chainId ?? ctxChainId;
|
|
24587
24690
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
24588
|
-
|
|
24589
|
-
symmCoreClient,
|
|
24590
|
-
accountAddress,
|
|
24591
|
-
resolvedAddress,
|
|
24592
|
-
chainId,
|
|
24593
|
-
internalEnabled
|
|
24594
|
-
});
|
|
24595
|
-
const query = useQuery({
|
|
24691
|
+
return useQuery({
|
|
24596
24692
|
...params.query,
|
|
24597
24693
|
queryKey: symmKeys.positions({
|
|
24598
24694
|
accountAddress,
|
|
@@ -24606,12 +24702,6 @@ function useSymmPositions(params) {
|
|
|
24606
24702
|
}),
|
|
24607
24703
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24608
24704
|
});
|
|
24609
|
-
console.log("positions query", { query });
|
|
24610
|
-
return {
|
|
24611
|
-
positions: query.data?.data?.positions ?? [],
|
|
24612
|
-
isLoading: query.isLoading,
|
|
24613
|
-
refetch: query.refetch
|
|
24614
|
-
};
|
|
24615
24705
|
}
|
|
24616
24706
|
function useSymmOpenOrders(params) {
|
|
24617
24707
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24619,7 +24709,7 @@ function useSymmOpenOrders(params) {
|
|
|
24619
24709
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
24620
24710
|
const chainId = params.chainId ?? ctxChainId;
|
|
24621
24711
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
24622
|
-
|
|
24712
|
+
return useQuery({
|
|
24623
24713
|
...params.query,
|
|
24624
24714
|
queryKey: symmKeys.openOrders({
|
|
24625
24715
|
accountAddress,
|
|
@@ -24632,11 +24722,6 @@ function useSymmOpenOrders(params) {
|
|
|
24632
24722
|
}),
|
|
24633
24723
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24634
24724
|
});
|
|
24635
|
-
return {
|
|
24636
|
-
orders: query.data?.data?.orders ?? [],
|
|
24637
|
-
isLoading: query.isLoading,
|
|
24638
|
-
refetch: query.refetch
|
|
24639
|
-
};
|
|
24640
24725
|
}
|
|
24641
24726
|
function useSymmTradeHistory(params) {
|
|
24642
24727
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24644,7 +24729,7 @@ function useSymmTradeHistory(params) {
|
|
|
24644
24729
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
24645
24730
|
const chainId = params.chainId ?? ctxChainId;
|
|
24646
24731
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
24647
|
-
|
|
24732
|
+
return useQuery({
|
|
24648
24733
|
...params.query,
|
|
24649
24734
|
queryKey: symmKeys.tradeHistory({
|
|
24650
24735
|
accountAddress,
|
|
@@ -24661,36 +24746,38 @@ function useSymmTradeHistory(params) {
|
|
|
24661
24746
|
},
|
|
24662
24747
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24663
24748
|
});
|
|
24664
|
-
return {
|
|
24665
|
-
trades: query.data ?? null,
|
|
24666
|
-
isLoading: query.isLoading,
|
|
24667
|
-
refetch: query.refetch
|
|
24668
|
-
};
|
|
24669
24749
|
}
|
|
24670
|
-
function
|
|
24750
|
+
function useSymmSetTpslMutation(options) {
|
|
24671
24751
|
const { symmCoreClient } = useSymmContext();
|
|
24672
24752
|
const queryClient = useQueryClient();
|
|
24673
|
-
|
|
24753
|
+
return useMutation({
|
|
24754
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24755
|
+
onSuccess: () => {
|
|
24756
|
+
invalidateOrders(queryClient);
|
|
24757
|
+
invalidatePositions(queryClient);
|
|
24758
|
+
}
|
|
24759
|
+
}),
|
|
24674
24760
|
mutationFn: async (request) => {
|
|
24675
24761
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24676
24762
|
return symmCoreClient.orders.setTpsl(request);
|
|
24677
|
-
},
|
|
24678
|
-
onSuccess: () => {
|
|
24679
|
-
invalidateOrders(queryClient);
|
|
24680
|
-
invalidatePositions(queryClient);
|
|
24681
24763
|
}
|
|
24682
24764
|
});
|
|
24683
|
-
|
|
24765
|
+
}
|
|
24766
|
+
function useSymmCancelTpslMutation(options) {
|
|
24767
|
+
const { symmCoreClient } = useSymmContext();
|
|
24768
|
+
const queryClient = useQueryClient();
|
|
24769
|
+
return useMutation({
|
|
24770
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24771
|
+
onSuccess: () => {
|
|
24772
|
+
invalidateOrders(queryClient);
|
|
24773
|
+
invalidatePositions(queryClient);
|
|
24774
|
+
}
|
|
24775
|
+
}),
|
|
24684
24776
|
mutationFn: async (request) => {
|
|
24685
24777
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24686
24778
|
return symmCoreClient.orders.cancelTpsl(request);
|
|
24687
|
-
},
|
|
24688
|
-
onSuccess: () => {
|
|
24689
|
-
invalidateOrders(queryClient);
|
|
24690
|
-
invalidatePositions(queryClient);
|
|
24691
24779
|
}
|
|
24692
24780
|
});
|
|
24693
|
-
return { setTpsl, cancelTpsl };
|
|
24694
24781
|
}
|
|
24695
24782
|
function useSymmTpslOrders(params) {
|
|
24696
24783
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24705,7 +24792,7 @@ function useSymmTpslOrders(params) {
|
|
|
24705
24792
|
status,
|
|
24706
24793
|
chainId
|
|
24707
24794
|
};
|
|
24708
|
-
|
|
24795
|
+
return useQuery({
|
|
24709
24796
|
...params.query,
|
|
24710
24797
|
queryKey: symmKeys.tpslOrdersList({
|
|
24711
24798
|
accountAddress,
|
|
@@ -24718,90 +24805,94 @@ function useSymmTpslOrders(params) {
|
|
|
24718
24805
|
queryFn: () => symmCoreClient.orders.getTpslOrders(request),
|
|
24719
24806
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24720
24807
|
});
|
|
24721
|
-
return {
|
|
24722
|
-
tpslOrders: query.data?.data?.tpslOrders ?? [],
|
|
24723
|
-
total: query.data?.data?.total ?? 0,
|
|
24724
|
-
isLoading: query.isLoading,
|
|
24725
|
-
refetch: query.refetch
|
|
24726
|
-
};
|
|
24727
24808
|
}
|
|
24728
|
-
function
|
|
24809
|
+
function useResolvedTwapParams(params) {
|
|
24729
24810
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24730
|
-
const queryClient = useQueryClient();
|
|
24731
24811
|
const { accountAddress, address } = params;
|
|
24732
24812
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
24733
24813
|
const chainId = params.chainId ?? ctxChainId;
|
|
24814
|
+
return { symmCoreClient, accountAddress, resolvedAddress, chainId, query: params.query };
|
|
24815
|
+
}
|
|
24816
|
+
function useSymmTwapOrdersQuery(params) {
|
|
24817
|
+
const { symmCoreClient, accountAddress, resolvedAddress, chainId, query } = useResolvedTwapParams(params);
|
|
24734
24818
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
24735
|
-
|
|
24736
|
-
...
|
|
24819
|
+
return useQuery({
|
|
24820
|
+
...query,
|
|
24737
24821
|
queryKey: symmKeys.twapOrders(accountAddress ?? resolvedAddress, chainId),
|
|
24738
24822
|
queryFn: () => symmCoreClient.orders.getTwapOrders({
|
|
24739
24823
|
address: accountAddress ?? resolvedAddress,
|
|
24740
24824
|
chainId
|
|
24741
24825
|
}),
|
|
24742
|
-
enabled: internalEnabled && (
|
|
24826
|
+
enabled: internalEnabled && (query?.enabled ?? true)
|
|
24743
24827
|
});
|
|
24744
|
-
|
|
24828
|
+
}
|
|
24829
|
+
function useSymmCancelTwapOrderMutation(options) {
|
|
24830
|
+
const { symmCoreClient } = useSymmContext();
|
|
24831
|
+
const queryClient = useQueryClient();
|
|
24832
|
+
return useMutation({
|
|
24833
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24834
|
+
onSuccess: () => {
|
|
24835
|
+
invalidateOrders(queryClient);
|
|
24836
|
+
}
|
|
24837
|
+
}),
|
|
24745
24838
|
mutationFn: async (orderId) => {
|
|
24746
24839
|
if (!symmCoreClient) throw new Error("symm-core client not available");
|
|
24747
24840
|
return symmCoreClient.orders.cancelTwapOrder(orderId);
|
|
24748
|
-
},
|
|
24749
|
-
onSuccess: () => {
|
|
24750
|
-
invalidateOrders(queryClient);
|
|
24751
24841
|
}
|
|
24752
24842
|
});
|
|
24753
|
-
return {
|
|
24754
|
-
twapOrders: query.data?.data?.orders ?? [],
|
|
24755
|
-
isLoading: query.isLoading,
|
|
24756
|
-
cancelTwap
|
|
24757
|
-
};
|
|
24758
24843
|
}
|
|
24759
|
-
function
|
|
24844
|
+
function useSymmTriggerConfigQuery(params) {
|
|
24760
24845
|
const { symmCoreClient } = useSymmContext();
|
|
24761
|
-
const queryClient = useQueryClient();
|
|
24762
24846
|
const { orderId } = params;
|
|
24763
24847
|
const internalEnabled = !!symmCoreClient && !!orderId;
|
|
24764
|
-
|
|
24848
|
+
return useQuery({
|
|
24765
24849
|
...params.query,
|
|
24766
24850
|
queryKey: symmKeys.triggerConfig(orderId),
|
|
24767
24851
|
queryFn: () => symmCoreClient.orders.getTriggerConfig(orderId),
|
|
24768
24852
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24769
24853
|
});
|
|
24770
|
-
|
|
24854
|
+
}
|
|
24855
|
+
function useSymmSetTriggerConfigMutation(params, options) {
|
|
24856
|
+
const { symmCoreClient } = useSymmContext();
|
|
24857
|
+
const { orderId } = params;
|
|
24858
|
+
const queryClient = useQueryClient();
|
|
24859
|
+
return useMutation({
|
|
24860
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24861
|
+
onSuccess: () => {
|
|
24862
|
+
queryClient.invalidateQueries({
|
|
24863
|
+
queryKey: symmKeys.triggerConfig(orderId)
|
|
24864
|
+
});
|
|
24865
|
+
invalidateOrders(queryClient);
|
|
24866
|
+
}
|
|
24867
|
+
}),
|
|
24771
24868
|
mutationFn: async (request) => {
|
|
24772
24869
|
if (!symmCoreClient || !orderId) {
|
|
24773
24870
|
throw new Error("symm-core client or orderId not available");
|
|
24774
24871
|
}
|
|
24775
24872
|
return symmCoreClient.orders.setTriggerConfig(orderId, request);
|
|
24776
|
-
},
|
|
24777
|
-
onSuccess: () => {
|
|
24778
|
-
queryClient.invalidateQueries({
|
|
24779
|
-
queryKey: symmKeys.triggerConfig(orderId)
|
|
24780
|
-
});
|
|
24781
|
-
invalidateOrders(queryClient);
|
|
24782
24873
|
}
|
|
24783
24874
|
});
|
|
24784
|
-
|
|
24875
|
+
}
|
|
24876
|
+
function useSymmClearTriggerConfigMutation(params, options) {
|
|
24877
|
+
const { symmCoreClient } = useSymmContext();
|
|
24878
|
+
const { orderId } = params;
|
|
24879
|
+
const queryClient = useQueryClient();
|
|
24880
|
+
return useMutation({
|
|
24881
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
24882
|
+
onSuccess: () => {
|
|
24883
|
+
queryClient.invalidateQueries({
|
|
24884
|
+
queryKey: symmKeys.triggerConfig(orderId)
|
|
24885
|
+
});
|
|
24886
|
+
invalidateOrders(queryClient);
|
|
24887
|
+
}
|
|
24888
|
+
}),
|
|
24785
24889
|
mutationFn: async () => {
|
|
24786
24890
|
if (!symmCoreClient || !orderId) {
|
|
24787
24891
|
throw new Error("symm-core client or orderId not available");
|
|
24788
24892
|
}
|
|
24789
24893
|
return symmCoreClient.orders.clearTriggerConfig(orderId);
|
|
24790
|
-
},
|
|
24791
|
-
onSuccess: () => {
|
|
24792
|
-
queryClient.invalidateQueries({
|
|
24793
|
-
queryKey: symmKeys.triggerConfig(orderId)
|
|
24794
|
-
});
|
|
24795
|
-
invalidateOrders(queryClient);
|
|
24796
24894
|
}
|
|
24797
24895
|
});
|
|
24798
|
-
return {
|
|
24799
|
-
triggerConfig: query.data?.data?.triggerConfig ?? null,
|
|
24800
|
-
isLoading: query.isLoading,
|
|
24801
|
-
refetch: query.refetch,
|
|
24802
|
-
setTriggerConfig,
|
|
24803
|
-
clearTriggerConfig
|
|
24804
|
-
};
|
|
24805
24896
|
}
|
|
24806
24897
|
function useSymmTriggerOrders(params) {
|
|
24807
24898
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24816,7 +24907,7 @@ function useSymmTriggerOrders(params) {
|
|
|
24816
24907
|
limit,
|
|
24817
24908
|
offset
|
|
24818
24909
|
};
|
|
24819
|
-
|
|
24910
|
+
return useQuery({
|
|
24820
24911
|
...params.query,
|
|
24821
24912
|
queryKey: symmKeys.triggerOrders({
|
|
24822
24913
|
accountAddress,
|
|
@@ -24829,21 +24920,13 @@ function useSymmTriggerOrders(params) {
|
|
|
24829
24920
|
queryFn: () => symmCoreClient.orders.listTriggerOrders(request),
|
|
24830
24921
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24831
24922
|
});
|
|
24832
|
-
return {
|
|
24833
|
-
orders: query.data?.data?.orders ?? [],
|
|
24834
|
-
total: query.data?.data?.total ?? 0,
|
|
24835
|
-
limit: query.data?.data?.limit ?? limit ?? 0,
|
|
24836
|
-
offset: query.data?.data?.offset ?? offset ?? 0,
|
|
24837
|
-
isLoading: query.isLoading,
|
|
24838
|
-
refetch: query.refetch
|
|
24839
|
-
};
|
|
24840
24923
|
}
|
|
24841
24924
|
function useSymmMarkets(params) {
|
|
24842
24925
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24843
24926
|
const chainId = params?.chainId ?? ctxChainId;
|
|
24844
24927
|
const searchText = params?.searchText;
|
|
24845
24928
|
const internalEnabled = !!symmCoreClient;
|
|
24846
|
-
|
|
24929
|
+
return useQuery({
|
|
24847
24930
|
...params?.query,
|
|
24848
24931
|
queryKey: symmKeys.markets(chainId, searchText),
|
|
24849
24932
|
queryFn: () => {
|
|
@@ -24855,54 +24938,37 @@ function useSymmMarkets(params) {
|
|
|
24855
24938
|
},
|
|
24856
24939
|
enabled: internalEnabled && (params?.query?.enabled ?? true)
|
|
24857
24940
|
});
|
|
24858
|
-
return {
|
|
24859
|
-
markets: query.data?.markets ?? [],
|
|
24860
|
-
isLoading: query.isLoading,
|
|
24861
|
-
refetch: query.refetch
|
|
24862
|
-
};
|
|
24863
24941
|
}
|
|
24864
24942
|
function useSymmHedgerMarketById(params) {
|
|
24865
24943
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24866
24944
|
const { id } = params;
|
|
24867
24945
|
const chainId = params.chainId ?? ctxChainId;
|
|
24868
24946
|
const internalEnabled = !!symmCoreClient && id != null;
|
|
24869
|
-
|
|
24947
|
+
return useQuery({
|
|
24870
24948
|
...params.query,
|
|
24871
24949
|
queryKey: symmKeys.hedgerMarketById(id, chainId),
|
|
24872
24950
|
queryFn: () => symmCoreClient.markets.getById(id, chainId),
|
|
24873
24951
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24874
24952
|
});
|
|
24875
|
-
return {
|
|
24876
|
-
market: query.data?.data?.markets?.[0] ?? null,
|
|
24877
|
-
markets: query.data?.data?.markets ?? [],
|
|
24878
|
-
isLoading: query.isLoading,
|
|
24879
|
-
refetch: query.refetch
|
|
24880
|
-
};
|
|
24881
24953
|
}
|
|
24882
24954
|
function useSymmHedgerMarketBySymbol(params) {
|
|
24883
24955
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24884
24956
|
const { symbol } = params;
|
|
24885
24957
|
const chainId = params.chainId ?? ctxChainId;
|
|
24886
24958
|
const internalEnabled = !!symmCoreClient && !!symbol;
|
|
24887
|
-
|
|
24959
|
+
return useQuery({
|
|
24888
24960
|
...params.query,
|
|
24889
24961
|
queryKey: symmKeys.hedgerMarketBySymbol(symbol, chainId),
|
|
24890
24962
|
queryFn: () => symmCoreClient.markets.getBySymbol(symbol, chainId),
|
|
24891
24963
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24892
24964
|
});
|
|
24893
|
-
return {
|
|
24894
|
-
market: query.data?.data?.markets?.[0] ?? null,
|
|
24895
|
-
markets: query.data?.data?.markets ?? [],
|
|
24896
|
-
isLoading: query.isLoading,
|
|
24897
|
-
refetch: query.refetch
|
|
24898
|
-
};
|
|
24899
24965
|
}
|
|
24900
24966
|
function useSymmLockedParams(params) {
|
|
24901
24967
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24902
24968
|
const { marketName, leverage } = params;
|
|
24903
24969
|
const chainId = params.chainId ?? ctxChainId;
|
|
24904
24970
|
const internalEnabled = !!symmCoreClient && !!marketName && leverage != null;
|
|
24905
|
-
|
|
24971
|
+
return useQuery({
|
|
24906
24972
|
...params.query,
|
|
24907
24973
|
queryKey: symmKeys.lockedParams(marketName, leverage, chainId),
|
|
24908
24974
|
queryFn: () => symmCoreClient.markets.getLockedParams({
|
|
@@ -24912,16 +24978,7 @@ function useSymmLockedParams(params) {
|
|
|
24912
24978
|
}),
|
|
24913
24979
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
24914
24980
|
});
|
|
24915
|
-
return {
|
|
24916
|
-
lockedParams: query.data?.data ?? null,
|
|
24917
|
-
isLoading: query.isLoading,
|
|
24918
|
-
refetch: query.refetch
|
|
24919
|
-
};
|
|
24920
24981
|
}
|
|
24921
|
-
var EMPTY_MARKETS = [];
|
|
24922
|
-
var EMPTY_SYMBOLS = [];
|
|
24923
|
-
var EMPTY_MAP_BY_ID = /* @__PURE__ */ new Map();
|
|
24924
|
-
var EMPTY_MAP_BY_SYMBOL = /* @__PURE__ */ new Map();
|
|
24925
24982
|
function useSymmHedgerMarkets(params) {
|
|
24926
24983
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24927
24984
|
const chainId = params?.chainId ?? ctxChainId;
|
|
@@ -24934,43 +24991,23 @@ function useSymmHedgerMarkets(params) {
|
|
|
24934
24991
|
searchText: searchText || void 0
|
|
24935
24992
|
};
|
|
24936
24993
|
const internalEnabled = !!symmCoreClient;
|
|
24937
|
-
|
|
24994
|
+
return useQuery({
|
|
24938
24995
|
...params?.query,
|
|
24939
24996
|
queryKey: symmKeys.hedgerMarkets(request),
|
|
24940
24997
|
queryFn: () => symmCoreClient.markets.listSymmHedger(request),
|
|
24941
24998
|
enabled: internalEnabled && consumerEnabled
|
|
24942
24999
|
});
|
|
24943
|
-
const data = query.data ?? null;
|
|
24944
|
-
return {
|
|
24945
|
-
data,
|
|
24946
|
-
markets: data?.markets ?? EMPTY_MARKETS,
|
|
24947
|
-
rawMarkets: data?.rawMarkets ?? EMPTY_MARKETS,
|
|
24948
|
-
filteredMarkets: data?.filteredMarkets ?? EMPTY_MARKETS,
|
|
24949
|
-
allSymbols: data?.allSymbols ?? EMPTY_SYMBOLS,
|
|
24950
|
-
filteredSymbols: data?.filteredSymbols ?? EMPTY_SYMBOLS,
|
|
24951
|
-
marketsById: data?.marketsById ?? EMPTY_MAP_BY_ID,
|
|
24952
|
-
marketsBySymbol: data?.marketsBySymbol ?? EMPTY_MAP_BY_SYMBOL,
|
|
24953
|
-
category: data?.category ?? params?.category ?? "all",
|
|
24954
|
-
resolvedSearchText: data?.searchText ?? searchText ?? "",
|
|
24955
|
-
isLoading: query.isLoading,
|
|
24956
|
-
isFetching: query.isFetching,
|
|
24957
|
-
refetch: query.refetch
|
|
24958
|
-
};
|
|
24959
25000
|
}
|
|
24960
25001
|
function useSymmFunding(params) {
|
|
24961
25002
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24962
25003
|
const chainId = params?.chainId ?? ctxChainId;
|
|
24963
25004
|
const internalEnabled = !!symmCoreClient;
|
|
24964
|
-
|
|
25005
|
+
return useQuery({
|
|
24965
25006
|
...params?.query,
|
|
24966
25007
|
queryKey: symmKeys.fundingRates(chainId),
|
|
24967
25008
|
queryFn: () => symmCoreClient.funding.getRates({ chainId }),
|
|
24968
25009
|
enabled: internalEnabled && (params?.query?.enabled ?? true)
|
|
24969
25010
|
});
|
|
24970
|
-
return {
|
|
24971
|
-
rates: query.data?.data?.rates ?? [],
|
|
24972
|
-
isLoading: query.isLoading
|
|
24973
|
-
};
|
|
24974
25011
|
}
|
|
24975
25012
|
function useSymmFundingHistory(params) {
|
|
24976
25013
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -24993,17 +25030,12 @@ function useSymmFundingHistory(params) {
|
|
|
24993
25030
|
weightMode,
|
|
24994
25031
|
includeContributions
|
|
24995
25032
|
};
|
|
24996
|
-
|
|
25033
|
+
return useQuery({
|
|
24997
25034
|
...params.query,
|
|
24998
25035
|
queryKey: symmKeys.fundingHistory(request),
|
|
24999
25036
|
queryFn: () => symmCoreClient.funding.getHistory(request),
|
|
25000
25037
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25001
25038
|
});
|
|
25002
|
-
return {
|
|
25003
|
-
history: query.data?.data ?? null,
|
|
25004
|
-
isLoading: query.isLoading,
|
|
25005
|
-
refetch: query.refetch
|
|
25006
|
-
};
|
|
25007
25039
|
}
|
|
25008
25040
|
function useSymmFundingPayments(params) {
|
|
25009
25041
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -25017,7 +25049,7 @@ function useSymmFundingPayments(params) {
|
|
|
25017
25049
|
limit,
|
|
25018
25050
|
offset
|
|
25019
25051
|
};
|
|
25020
|
-
|
|
25052
|
+
return useQuery({
|
|
25021
25053
|
...params.query,
|
|
25022
25054
|
queryKey: symmKeys.fundingPayments({
|
|
25023
25055
|
address,
|
|
@@ -25029,12 +25061,6 @@ function useSymmFundingPayments(params) {
|
|
|
25029
25061
|
queryFn: () => symmCoreClient.funding.getPayments(request),
|
|
25030
25062
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25031
25063
|
});
|
|
25032
|
-
return {
|
|
25033
|
-
payments: query.data?.data?.payments ?? [],
|
|
25034
|
-
total: query.data?.data?.total ?? 0,
|
|
25035
|
-
isLoading: query.isLoading,
|
|
25036
|
-
refetch: query.refetch
|
|
25037
|
-
};
|
|
25038
25064
|
}
|
|
25039
25065
|
function useSymmPortfolio(params) {
|
|
25040
25066
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
@@ -25042,7 +25068,7 @@ function useSymmPortfolio(params) {
|
|
|
25042
25068
|
const resolvedAddress = accountAddress ? void 0 : address;
|
|
25043
25069
|
const chainId = params.chainId ?? ctxChainId;
|
|
25044
25070
|
const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
|
|
25045
|
-
|
|
25071
|
+
return useQuery({
|
|
25046
25072
|
...params.query,
|
|
25047
25073
|
queryKey: symmKeys.portfolio({
|
|
25048
25074
|
accountAddress,
|
|
@@ -25059,70 +25085,76 @@ function useSymmPortfolio(params) {
|
|
|
25059
25085
|
},
|
|
25060
25086
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25061
25087
|
});
|
|
25062
|
-
return {
|
|
25063
|
-
metrics: query.data ?? null,
|
|
25064
|
-
isLoading: query.isLoading,
|
|
25065
|
-
refetch: query.refetch
|
|
25066
|
-
};
|
|
25067
25088
|
}
|
|
25068
|
-
function
|
|
25089
|
+
function useResolvedNotificationsParams(params) {
|
|
25069
25090
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
25070
|
-
const queryClient = useQueryClient();
|
|
25071
|
-
const { userAddress } = params;
|
|
25072
25091
|
const chainId = params.chainId ?? ctxChainId;
|
|
25092
|
+
return {
|
|
25093
|
+
symmCoreClient,
|
|
25094
|
+
chainId,
|
|
25095
|
+
userAddress: params.userAddress,
|
|
25096
|
+
query: params.query
|
|
25097
|
+
};
|
|
25098
|
+
}
|
|
25099
|
+
function useSymmNotificationsQuery(params) {
|
|
25100
|
+
const { symmCoreClient, chainId, userAddress, query } = useResolvedNotificationsParams(params);
|
|
25073
25101
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
25074
|
-
|
|
25075
|
-
...
|
|
25102
|
+
return useQuery({
|
|
25103
|
+
...query,
|
|
25076
25104
|
queryKey: symmKeys.notifications(userAddress, chainId),
|
|
25077
25105
|
queryFn: () => symmCoreClient.notifications.list({
|
|
25078
25106
|
userAddress,
|
|
25079
25107
|
chainId
|
|
25080
25108
|
}),
|
|
25081
|
-
enabled: internalEnabled && (
|
|
25109
|
+
enabled: internalEnabled && (query?.enabled ?? true)
|
|
25082
25110
|
});
|
|
25083
|
-
|
|
25084
|
-
|
|
25111
|
+
}
|
|
25112
|
+
function useSymmUnreadCountQuery(params) {
|
|
25113
|
+
const { symmCoreClient, chainId, userAddress, query } = useResolvedNotificationsParams(params);
|
|
25114
|
+
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
25115
|
+
return useQuery({
|
|
25116
|
+
...query,
|
|
25085
25117
|
queryKey: symmKeys.unreadCount(userAddress, chainId),
|
|
25086
25118
|
queryFn: () => symmCoreClient.notifications.getUnreadCount({
|
|
25087
25119
|
userAddress,
|
|
25088
25120
|
chainId
|
|
25089
25121
|
}),
|
|
25090
|
-
enabled: internalEnabled && (
|
|
25122
|
+
enabled: internalEnabled && (query?.enabled ?? true)
|
|
25091
25123
|
});
|
|
25092
|
-
|
|
25124
|
+
}
|
|
25125
|
+
function useSymmMarkReadNotificationMutation(params, options) {
|
|
25126
|
+
const { symmCoreClient, chainId, userAddress } = useResolvedNotificationsParams(params);
|
|
25127
|
+
const queryClient = useQueryClient();
|
|
25128
|
+
return useMutation({
|
|
25129
|
+
...withSymmMutationConfig(options?.mutation, {
|
|
25130
|
+
onSuccess: () => {
|
|
25131
|
+
queryClient.invalidateQueries({
|
|
25132
|
+
queryKey: symmKeys.notifications(userAddress, chainId)
|
|
25133
|
+
});
|
|
25134
|
+
queryClient.invalidateQueries({
|
|
25135
|
+
queryKey: symmKeys.unreadCount(userAddress, chainId)
|
|
25136
|
+
});
|
|
25137
|
+
}
|
|
25138
|
+
}),
|
|
25093
25139
|
mutationFn: async ({ id, timestamp }) => {
|
|
25094
|
-
if (!symmCoreClient || !userAddress)
|
|
25140
|
+
if (!symmCoreClient || !userAddress) {
|
|
25095
25141
|
throw new Error("symm-core client not available");
|
|
25142
|
+
}
|
|
25096
25143
|
return symmCoreClient.notifications.markRead({
|
|
25097
25144
|
id,
|
|
25098
25145
|
timestamp,
|
|
25099
25146
|
userAddress,
|
|
25100
25147
|
chainId
|
|
25101
25148
|
});
|
|
25102
|
-
},
|
|
25103
|
-
onSuccess: () => {
|
|
25104
|
-
queryClient.invalidateQueries({
|
|
25105
|
-
queryKey: symmKeys.notifications(userAddress, chainId)
|
|
25106
|
-
});
|
|
25107
|
-
queryClient.invalidateQueries({
|
|
25108
|
-
queryKey: symmKeys.unreadCount(userAddress, chainId)
|
|
25109
|
-
});
|
|
25110
25149
|
}
|
|
25111
25150
|
});
|
|
25112
|
-
return {
|
|
25113
|
-
notifications: notificationsQuery.data?.data?.notifications ?? [],
|
|
25114
|
-
unreadCount: unreadQuery.data?.data?.unreadCount ?? 0,
|
|
25115
|
-
isLoading: notificationsQuery.isLoading,
|
|
25116
|
-
markRead,
|
|
25117
|
-
refetch: notificationsQuery.refetch
|
|
25118
|
-
};
|
|
25119
25151
|
}
|
|
25120
25152
|
function useSymmPendingIds(params) {
|
|
25121
25153
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
25122
25154
|
const { accountAddress } = params;
|
|
25123
25155
|
const chainId = params.chainId ?? ctxChainId;
|
|
25124
25156
|
const internalEnabled = !!symmCoreClient && !!accountAddress;
|
|
25125
|
-
|
|
25157
|
+
return useQuery({
|
|
25126
25158
|
...params.query,
|
|
25127
25159
|
queryKey: symmKeys.pendingIds(accountAddress, chainId),
|
|
25128
25160
|
queryFn: () => symmCoreClient.positions.getPendingIds({
|
|
@@ -25131,11 +25163,6 @@ function useSymmPendingIds(params) {
|
|
|
25131
25163
|
}),
|
|
25132
25164
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25133
25165
|
});
|
|
25134
|
-
return {
|
|
25135
|
-
pendingIds: query.data?.data?.pendingIds ?? [],
|
|
25136
|
-
isLoading: query.isLoading,
|
|
25137
|
-
refetch: query.refetch
|
|
25138
|
-
};
|
|
25139
25166
|
}
|
|
25140
25167
|
function useSymmPendingInstantOpens(params) {
|
|
25141
25168
|
const {
|
|
@@ -25145,7 +25172,7 @@ function useSymmPendingInstantOpens(params) {
|
|
|
25145
25172
|
const { accountAddress, authToken: providedAuthToken } = params;
|
|
25146
25173
|
const chainId = params.chainId ?? ctxChainId;
|
|
25147
25174
|
const internalEnabled = !!symmCoreClient && !!accountAddress;
|
|
25148
|
-
|
|
25175
|
+
return useQuery({
|
|
25149
25176
|
...params.query,
|
|
25150
25177
|
queryKey: symmKeys.pendingInstantOpens(accountAddress, chainId),
|
|
25151
25178
|
queryFn: async () => {
|
|
@@ -25161,28 +25188,17 @@ function useSymmPendingInstantOpens(params) {
|
|
|
25161
25188
|
},
|
|
25162
25189
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25163
25190
|
});
|
|
25164
|
-
return {
|
|
25165
|
-
pendingOpens: query.data?.data?.pendingOpens ?? [],
|
|
25166
|
-
total: query.data?.data?.total ?? 0,
|
|
25167
|
-
isLoading: query.isLoading,
|
|
25168
|
-
refetch: query.refetch
|
|
25169
|
-
};
|
|
25170
25191
|
}
|
|
25171
25192
|
function useSymmTwapOrder(params) {
|
|
25172
25193
|
const { symmCoreClient } = useSymmContext();
|
|
25173
25194
|
const { orderId } = params;
|
|
25174
25195
|
const internalEnabled = !!symmCoreClient && !!orderId;
|
|
25175
|
-
|
|
25196
|
+
return useQuery({
|
|
25176
25197
|
...params.query,
|
|
25177
25198
|
queryKey: symmKeys.twapOrder(orderId),
|
|
25178
25199
|
queryFn: () => symmCoreClient.orders.getTwapOrder(orderId),
|
|
25179
25200
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25180
25201
|
});
|
|
25181
|
-
return {
|
|
25182
|
-
order: query.data?.data ?? null,
|
|
25183
|
-
isLoading: query.isLoading,
|
|
25184
|
-
refetch: query.refetch
|
|
25185
|
-
};
|
|
25186
25202
|
}
|
|
25187
25203
|
var useSymmWsStore = create((set) => ({
|
|
25188
25204
|
isConnected: false,
|
|
@@ -25975,6 +25991,7 @@ function useSymmTokenSelectionMetadata(selection, options = {}) {
|
|
|
25975
25991
|
const weightedRatio24h = computeWeightedRatio24h(metricInput) ?? 0;
|
|
25976
25992
|
const sumNetFunding = computeNetFundingSum(metricInput);
|
|
25977
25993
|
return {
|
|
25994
|
+
query,
|
|
25978
25995
|
isLoading,
|
|
25979
25996
|
isPriceDataReady,
|
|
25980
25997
|
isUnsupported,
|
|
@@ -26380,6 +26397,6 @@ function getSymmErrorMessage(error) {
|
|
|
26380
26397
|
return "An unexpected error occurred.";
|
|
26381
26398
|
}
|
|
26382
26399
|
|
|
26383
|
-
export { SymmProvider, getSymmErrorMessage, symmKeys, useBinanceMarkPriceStore, useSymmAccountData, useSymmAccountSummary,
|
|
26400
|
+
export { SymmProvider, getSymmErrorMessage, symmKeys, useBinanceMarkPriceStore, useSymmAccountData, useSymmAccountSummary, useSymmAccountsApi, useSymmAccountsLength, useSymmAccountsQuery, useSymmAccountsWithPositions, useSymmAllocateCollateralMutation, useSymmApprovalQuery, useSymmApproveMutation, useSymmAuth, useSymmAuthStore, useSymmAvailableMargin, useSymmBalances, useSymmCancelClose, useSymmCancelOpenMutation, useSymmCancelTpslMutation, useSymmCancelTwapOrderMutation, useSymmChartCandles, useSymmChartSelection, useSymmClearTriggerConfigMutation, useSymmCloseAllPositionsMutation, useSymmCloseOrder, useSymmClosePositionMutation, useSymmContext, useSymmCoreClient, useSymmCreateAccountMutation, useSymmDeallocateCollateralMutation, useSymmDelegation, useSymmDepositAndAllocateMutation, useSymmDepositMutation, useSymmEditAccountNameMutation, useSymmFunding, useSymmFundingHistory, useSymmFundingPayments, useSymmHedgerMarketById, useSymmHedgerMarketBySymbol, useSymmHedgerMarkets, useSymmInstantTradeEnsureReadyMutation, useSymmInstantTradeExecuteMutation, useSymmInternalTransferCollateralMutation, useSymmLockedParams, useSymmMarkReadNotificationMutation, useSymmMarkets, useSymmNotificationsQuery, useSymmOpenBasketMutation, useSymmOpenOrders, useSymmPendingIds, useSymmPendingInstantOpens, useSymmPerformanceOverlays, useSymmPortfolio, useSymmPositions, useSymmSetTpslMutation, useSymmSetTriggerConfigMutation, useSymmSignTermsMutation, useSymmSignatureQuery, useSymmTokenSelectionMetadata, useSymmTpslOrders, useSymmTradeHistory, useSymmTriggerConfigQuery, useSymmTriggerOrders, useSymmTwapOrder, useSymmTwapOrdersQuery, useSymmUnreadCountQuery, useSymmUpdatePositionMutation, useSymmWithdraw, useSymmWs, useSymmWsStore };
|
|
26384
26401
|
//# sourceMappingURL=index.mjs.map
|
|
26385
26402
|
//# sourceMappingURL=index.mjs.map
|