@sodax/dapp-kit 2.0.0-rc.8 → 2.0.0

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.
Files changed (74) hide show
  1. package/README.md +20 -11
  2. package/dist/index.d.ts +786 -54
  3. package/dist/index.mjs +864 -150
  4. package/package.json +3 -3
  5. package/src/hooks/_mutationContract.test.ts +15 -2
  6. package/src/hooks/backend/index.ts +1 -5
  7. package/src/hooks/bitcoin/index.ts +2 -0
  8. package/src/hooks/bitcoin/resolveBtcReadAddress.test.ts +54 -0
  9. package/src/hooks/bitcoin/resolveBtcReadAddress.ts +21 -0
  10. package/src/hooks/bitcoin/useBitcoinTradingSetup.ts +45 -0
  11. package/src/hooks/bitcoin/useEnsureRadfiAccessToken.ts +57 -0
  12. package/src/hooks/bitcoin/useFundTradingWallet.ts +1 -1
  13. package/src/hooks/bitcoin/useRadfiAuth.ts +2 -2
  14. package/src/hooks/bitcoin/useRadfiWithdraw.ts +2 -2
  15. package/src/hooks/bitcoin/useRenewUtxos.ts +2 -2
  16. package/src/hooks/bitcoin/useTradingWallet.ts +1 -1
  17. package/src/hooks/index.ts +2 -0
  18. package/src/hooks/leverageYield/index.ts +9 -0
  19. package/src/hooks/leverageYield/useLeverageYieldDeposit.ts +40 -0
  20. package/src/hooks/leverageYield/useLeverageYieldEffectiveApr.ts +42 -0
  21. package/src/hooks/leverageYield/useLeverageYieldNotifySolver.ts +34 -0
  22. package/src/hooks/leverageYield/useLeverageYieldPosition.ts +40 -0
  23. package/src/hooks/leverageYield/useLeverageYieldPreviewRedeem.ts +43 -0
  24. package/src/hooks/leverageYield/useLeverageYieldShareBalances.ts +74 -0
  25. package/src/hooks/leverageYield/useLeverageYieldTotalAssets.ts +36 -0
  26. package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +50 -0
  27. package/src/hooks/leverageYield/useLeverageYieldWithdraw.ts +40 -0
  28. package/src/hooks/mm/useATokensBalances.ts +7 -1
  29. package/src/hooks/mm/useUserFormattedSummary.ts +5 -1
  30. package/src/hooks/mm/useUserReservesData.ts +5 -1
  31. package/src/hooks/partner/index.ts +4 -0
  32. package/src/hooks/partner/useFeeClaimWithdraw.ts +88 -0
  33. package/src/hooks/partner/useGetIntentDetails.ts +39 -0
  34. package/src/hooks/partner/useGetUserIntent.ts +35 -0
  35. package/src/hooks/partner/usePartnerCancelIntent.ts +52 -0
  36. package/src/hooks/shared/index.ts +4 -0
  37. package/src/hooks/shared/isUserRejectedError.test.ts +42 -0
  38. package/src/hooks/shared/isUserRejectedError.ts +30 -0
  39. package/src/hooks/shared/useGetUserHubWalletAddress.ts +5 -1
  40. package/src/hooks/shared/useNearStorageCheck.ts +45 -0
  41. package/src/hooks/shared/useNearStorageGate.ts +60 -0
  42. package/src/hooks/shared/useRegisterNearStorage.ts +46 -0
  43. package/src/hooks/shared/useRequestTrustline.ts +1 -1
  44. package/src/hooks/shared/useStellarTrustlineCheck.test.ts +74 -0
  45. package/src/hooks/shared/useStellarTrustlineCheck.ts +39 -15
  46. package/src/hooks/swapsApi/index.ts +41 -0
  47. package/src/hooks/swapsApi/isTerminalSwapIntentStatus.test.ts +24 -0
  48. package/src/hooks/swapsApi/isTerminalSwapIntentStatus.ts +11 -0
  49. package/src/hooks/swapsApi/useSwapsApiAllowance.ts +40 -0
  50. package/src/hooks/swapsApi/useSwapsApiApprove.ts +42 -0
  51. package/src/hooks/swapsApi/useSwapsApiCancelIntent.ts +41 -0
  52. package/src/hooks/swapsApi/useSwapsApiCreateIntent.ts +41 -0
  53. package/src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts +41 -0
  54. package/src/hooks/swapsApi/useSwapsApiDeadline.ts +36 -0
  55. package/src/hooks/swapsApi/useSwapsApiEstimateGas.ts +40 -0
  56. package/src/hooks/swapsApi/useSwapsApiFilledIntent.ts +41 -0
  57. package/src/hooks/swapsApi/useSwapsApiIntent.ts +40 -0
  58. package/src/hooks/swapsApi/useSwapsApiIntentExtraData.ts +41 -0
  59. package/src/hooks/swapsApi/useSwapsApiIntentHash.ts +40 -0
  60. package/src/hooks/swapsApi/useSwapsApiIntentPacket.ts +43 -0
  61. package/src/hooks/swapsApi/useSwapsApiPartnerFee.ts +40 -0
  62. package/src/hooks/swapsApi/useSwapsApiQuote.ts +55 -0
  63. package/src/hooks/swapsApi/useSwapsApiSolverFee.ts +40 -0
  64. package/src/hooks/swapsApi/useSwapsApiStatus.ts +45 -0
  65. package/src/hooks/swapsApi/useSwapsApiSubmitIntent.ts +43 -0
  66. package/src/hooks/{backend/useBackendSubmitSwapTx.ts → swapsApi/useSwapsApiSubmitTx.ts} +16 -17
  67. package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +55 -0
  68. package/src/hooks/swapsApi/useSwapsApiTokens.ts +34 -0
  69. package/src/hooks/swapsApi/useSwapsApiTokensByChain.ts +40 -0
  70. package/src/providers/SodaxProvider.tsx +2 -3
  71. package/src/utils/index.ts +1 -0
  72. package/src/utils/nearStorageGate.test.ts +46 -0
  73. package/src/utils/nearStorageGate.ts +39 -0
  74. package/src/hooks/backend/useBackendSubmitSwapTxStatus.ts +0 -59
package/dist/index.mjs CHANGED
@@ -1,10 +1,15 @@
1
- import { useMutation, useQuery, useQueryClient, QueryClient, MutationCache } from '@tanstack/react-query';
2
- import { createContext, useCallback, useContext, useState, useRef, useEffect, useMemo } from 'react';
3
- import { ChainKeys, RadfiApiError, normalizePsbtToBase64, ClService, Sodax } from '@sodax/sdk';
1
+ import { isSodaxError, ChainKeys, RadfiApiError, normalizePsbtToBase64, ClService, Sodax } from '@sodax/sdk';
4
2
  export * from '@sodax/sdk';
3
+ import { useMutation, useQuery, useQueryClient, useQueries, QueryClient, MutationCache } from '@tanstack/react-query';
4
+ import { createContext, useCallback, useContext, useState, useRef, useEffect, useMemo } from 'react';
5
5
  import { isAddress, erc20Abi, parseUnits } from 'viem';
6
6
  import { jsx } from 'react/jsx-runtime';
7
7
 
8
+ // src/hooks/shared/isUserRejectedError.ts
9
+ function isUserRejectedError(error) {
10
+ return isSodaxError(error) && error.code === "USER_REJECTED";
11
+ }
12
+
8
13
  // src/hooks/shared/unwrapResult.ts
9
14
  function unwrapResult(result) {
10
15
  if (!result.ok) {
@@ -72,24 +77,37 @@ function useDeriveUserWalletAddress({
72
77
  ...queryOptions
73
78
  });
74
79
  }
80
+ function getStellarTrustlineCheckQueryOptions({
81
+ sodax,
82
+ token,
83
+ amount,
84
+ chainId,
85
+ walletAddress
86
+ }) {
87
+ return {
88
+ // Key on chain, token, account, amount so editing the amount (or switching account/chain) re-queries.
89
+ queryKey: ["shared", "stellarTrustlineCheck", chainId, token, walletAddress, amount?.toString()],
90
+ queryFn: async () => {
91
+ if (chainId !== ChainKeys.STELLAR_MAINNET) return true;
92
+ if (!walletAddress || !token || !amount) return false;
93
+ return sodax.spoke.stellar.hasSufficientTrustline(token, amount, walletAddress);
94
+ },
95
+ enabled: !!walletAddress && !!token && !!amount
96
+ };
97
+ }
75
98
  function useStellarTrustlineCheck({
76
99
  params,
77
100
  queryOptions
78
101
  } = {}) {
79
102
  const { sodax } = useSodaxContext();
80
- const token = params?.token;
81
- const amount = params?.amount;
82
- const chainId = params?.chainId;
83
- const walletProvider = params?.walletProvider;
84
103
  return useQuery({
85
- queryKey: ["shared", "stellarTrustlineCheck", token],
86
- queryFn: async () => {
87
- if (chainId !== ChainKeys.STELLAR_MAINNET) return true;
88
- if (!walletProvider || !token || !amount) return false;
89
- const walletAddress = await walletProvider.getWalletAddress();
90
- return sodax.spoke.stellar.hasSufficientTrustline(token, amount, walletAddress);
91
- },
92
- enabled: !!walletProvider && !!token && !!amount,
104
+ ...getStellarTrustlineCheckQueryOptions({
105
+ sodax,
106
+ token: params?.token,
107
+ amount: params?.amount,
108
+ chainId: params?.chainId,
109
+ walletAddress: params?.walletAddress
110
+ }),
93
111
  ...queryOptions
94
112
  });
95
113
  }
@@ -126,7 +144,7 @@ function useRequestTrustline(token) {
126
144
  });
127
145
  setData(result);
128
146
  setIsRequested(true);
129
- queryClient.invalidateQueries({ queryKey: ["shared", "stellarTrustlineCheck", token2] });
147
+ queryClient.invalidateQueries({ queryKey: ["shared", "stellarTrustlineCheck", srcChainKey, token2, srcAddress] });
130
148
  return result;
131
149
  } catch (err) {
132
150
  const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
@@ -140,59 +158,76 @@ function useRequestTrustline(token) {
140
158
  );
141
159
  return { requestTrustline, isLoading, isRequested, error, data };
142
160
  }
143
- function useGetUserHubWalletAddress({
161
+ function useNearStorageCheck({
144
162
  params,
145
163
  queryOptions
146
164
  } = {}) {
147
165
  const { sodax } = useSodaxContext();
148
- const spokeChainId = params?.spokeChainId;
149
- const spokeAddress = params?.spokeAddress;
166
+ const token = params?.token;
167
+ const accountId = params?.accountId;
168
+ const chainId = params?.chainId;
150
169
  return useQuery({
151
- queryKey: ["shared", "userHubWalletAddress", spokeChainId, spokeAddress],
170
+ queryKey: ["shared", "nearStorageCheck", chainId, token, accountId],
152
171
  queryFn: async () => {
153
- if (!spokeChainId || !spokeAddress) {
154
- throw new Error("Spoke chain id and address are required");
155
- }
156
- return await sodax.hubProvider.getUserHubWalletAddress(spokeAddress, spokeChainId);
172
+ if (chainId !== ChainKeys.NEAR_MAINNET) return true;
173
+ if (!token || !accountId) return false;
174
+ return sodax.spoke.near.isStorageRegistered(token, accountId);
157
175
  },
158
- enabled: !!spokeChainId && !!spokeAddress,
159
- refetchInterval: false,
176
+ enabled: !!token && !!accountId,
160
177
  ...queryOptions
161
178
  });
162
179
  }
163
- var REFETCH_INTERVAL_MS = 5e3;
164
- function getXBalancesQueryOptions({ xService, xChainId, xTokens, address }) {
165
- return {
166
- // Pair symbol + address: readable in devtools, unique on-chain (symbol alone
167
- // can collide — e.g. scam tokens copying legitimate ticker).
168
- queryKey: ["shared", "xBalances", xChainId, xTokens.map((x) => [x.symbol, x.address]), address],
169
- queryFn: async () => {
170
- if (!xService) return {};
171
- return xService.getBalances(address, xTokens);
172
- },
173
- enabled: !!xService && !!address && xTokens.length > 0,
174
- refetchInterval: REFETCH_INTERVAL_MS
175
- };
176
- }
177
- function useXBalances({
178
- params,
179
- queryOptions
180
+ function useRegisterNearStorage({
181
+ mutationOptions
180
182
  } = {}) {
181
- return useQuery({
182
- ...getXBalancesQueryOptions({
183
- xService: params?.xService,
184
- xChainId: params?.xChainId,
185
- xTokens: params?.xTokens ?? [],
186
- address: params?.address
187
- }),
188
- ...queryOptions
183
+ const { sodax } = useSodaxContext();
184
+ const queryClient = useQueryClient();
185
+ return useSafeMutation({
186
+ mutationKey: ["shared", "registerNearStorage"],
187
+ ...mutationOptions,
188
+ mutationFn: async ({ token, accountId, walletProvider, deposit }) => sodax.spoke.near.registerStorage({ token, accountId, walletProvider, deposit, raw: false }),
189
+ onSuccess: async (data, vars, ctx) => {
190
+ queryClient.invalidateQueries({
191
+ queryKey: ["shared", "nearStorageCheck", ChainKeys.NEAR_MAINNET, vars.token, vars.accountId]
192
+ });
193
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
194
+ }
189
195
  });
190
196
  }
197
+ function resolveNearStorageGate(chainKey, check) {
198
+ const isNear = chainKey === ChainKeys.NEAR_MAINNET;
199
+ const isChecking = check.isLoading;
200
+ const isRegistered = check.data;
201
+ return {
202
+ isNear,
203
+ needsRegistration: isNear && !isChecking && isRegistered === false,
204
+ blocksAction: isNear && (isChecking || isRegistered === false)
205
+ };
206
+ }
191
207
 
192
- // src/hooks/provider/useHubProvider.ts
193
- function useHubProvider() {
194
- const { sodax } = useSodaxContext();
195
- return sodax.hubProvider;
208
+ // src/hooks/shared/useNearStorageGate.ts
209
+ function useNearStorageGate({
210
+ dstChainKey,
211
+ token,
212
+ accountId,
213
+ walletProvider
214
+ }) {
215
+ const nearWalletProvider = walletProvider?.chainType === "NEAR" ? walletProvider : void 0;
216
+ const storageCheck = useNearStorageCheck({ params: { token, accountId, chainId: dstChainKey } });
217
+ const { mutateAsyncSafe: register, isPending: isRegistering } = useRegisterNearStorage();
218
+ const { isNear, needsRegistration, blocksAction } = resolveNearStorageGate(dstChainKey, storageCheck);
219
+ const registerStorage = async () => {
220
+ if (!nearWalletProvider || !token || !accountId) return void 0;
221
+ return register({ token, accountId, walletProvider: nearWalletProvider });
222
+ };
223
+ return {
224
+ isNear,
225
+ needsRegistration,
226
+ blocksAction,
227
+ isChecking: storageCheck.isLoading,
228
+ isRegistering,
229
+ registerStorage
230
+ };
196
231
  }
197
232
  var SESSION_KEY = (address) => `radfi_session_${address}`;
198
233
  function saveRadfiSession(address, session) {
@@ -254,7 +289,7 @@ function useRadfiAuth({
254
289
  clearRadfiSession(walletAddress);
255
290
  }
256
291
  throw new Error(
257
- "This wallet is already registered with Radfi from another session. Please clear your browser storage for this site and try again, or wait for the previous session to expire."
292
+ "This wallet is already registered with Bound Exchange from another session. Please clear your browser storage for this site and try again, or wait for the previous session to expire."
258
293
  );
259
294
  }
260
295
  throw err;
@@ -262,6 +297,99 @@ function useRadfiAuth({
262
297
  }
263
298
  });
264
299
  }
300
+
301
+ // src/hooks/bitcoin/resolveBtcReadAddress.ts
302
+ function resolveBtcReadAddress(chainKey, address) {
303
+ if (chainKey !== ChainKeys.BITCOIN_MAINNET) return address;
304
+ return loadRadfiSession(address)?.tradingAddress ?? address;
305
+ }
306
+
307
+ // src/hooks/shared/useGetUserHubWalletAddress.ts
308
+ function useGetUserHubWalletAddress({
309
+ params,
310
+ queryOptions
311
+ } = {}) {
312
+ const { sodax } = useSodaxContext();
313
+ const spokeChainId = params?.spokeChainId;
314
+ const spokeAddress = params?.spokeAddress;
315
+ return useQuery({
316
+ queryKey: ["shared", "userHubWalletAddress", spokeChainId, spokeAddress],
317
+ queryFn: async () => {
318
+ if (!spokeChainId || !spokeAddress) {
319
+ throw new Error("Spoke chain id and address are required");
320
+ }
321
+ return await sodax.hubProvider.getUserHubWalletAddress(
322
+ resolveBtcReadAddress(spokeChainId, spokeAddress),
323
+ spokeChainId
324
+ );
325
+ },
326
+ enabled: !!spokeChainId && !!spokeAddress,
327
+ refetchInterval: false,
328
+ ...queryOptions
329
+ });
330
+ }
331
+ var REFETCH_INTERVAL_MS = 5e3;
332
+ function getXBalancesQueryOptions({ xService, xChainId, xTokens, address }) {
333
+ return {
334
+ // Pair symbol + address: readable in devtools, unique on-chain (symbol alone
335
+ // can collide — e.g. scam tokens copying legitimate ticker).
336
+ queryKey: ["shared", "xBalances", xChainId, xTokens.map((x) => [x.symbol, x.address]), address],
337
+ queryFn: async () => {
338
+ if (!xService) return {};
339
+ return xService.getBalances(address, xTokens);
340
+ },
341
+ enabled: !!xService && !!address && xTokens.length > 0,
342
+ refetchInterval: REFETCH_INTERVAL_MS
343
+ };
344
+ }
345
+ function useXBalances({
346
+ params,
347
+ queryOptions
348
+ } = {}) {
349
+ return useQuery({
350
+ ...getXBalancesQueryOptions({
351
+ xService: params?.xService,
352
+ xChainId: params?.xChainId,
353
+ xTokens: params?.xTokens ?? [],
354
+ address: params?.address
355
+ }),
356
+ ...queryOptions
357
+ });
358
+ }
359
+
360
+ // src/hooks/provider/useHubProvider.ts
361
+ function useHubProvider() {
362
+ const { sodax } = useSodaxContext();
363
+ return sodax.hubProvider;
364
+ }
365
+
366
+ // src/hooks/bitcoin/useEnsureRadfiAccessToken.ts
367
+ function useEnsureRadfiAccessToken({
368
+ mutationOptions
369
+ } = {}) {
370
+ const { sodax } = useSodaxContext();
371
+ return useSafeMutation({
372
+ mutationKey: ["bitcoin", "ensureAccessToken"],
373
+ ...mutationOptions,
374
+ mutationFn: async ({ walletProvider }) => {
375
+ const radfi = sodax.spoke.bitcoin.radfi;
376
+ const walletAddress = await walletProvider.getWalletAddress();
377
+ const session = loadRadfiSession(walletAddress);
378
+ if (session?.refreshToken && !radfi.refreshToken) {
379
+ radfi.setRadfiAccessToken(session.accessToken, session.refreshToken);
380
+ }
381
+ await radfi.ensureRadfiAccessToken(walletProvider);
382
+ const accessToken = radfi.accessToken;
383
+ if (!accessToken) {
384
+ throw new Error("Failed to obtain a Bound Exchange access token");
385
+ }
386
+ if (session) {
387
+ saveRadfiSession(walletAddress, { ...session, accessToken, refreshToken: radfi.refreshToken });
388
+ }
389
+ return accessToken;
390
+ }
391
+ });
392
+ }
265
393
  var REFRESH_INTERVAL = 5 * 60 * 1e3;
266
394
  function useRadfiSession(walletProvider) {
267
395
  const { sodax } = useSodaxContext();
@@ -397,6 +525,19 @@ function useTradingWalletBalance({
397
525
  ...queryOptions
398
526
  });
399
527
  }
528
+ var INERT = { wallet: void 0, tradingBalance: void 0 };
529
+ function useBitcoinTradingSetup({
530
+ chainKey,
531
+ walletProvider,
532
+ address
533
+ }) {
534
+ const isBitcoin = chainKey === ChainKeys.BITCOIN_MAINNET;
535
+ const wallet = isBitcoin ? walletProvider : void 0;
536
+ const { tradingAddress } = useTradingWallet(isBitcoin ? address : void 0);
537
+ const { data: tradingBalance } = useTradingWalletBalance({ params: { walletProvider: wallet, tradingAddress } });
538
+ if (!isBitcoin) return INERT;
539
+ return { wallet, tradingBalance };
540
+ }
400
541
  function useExpiredUtxos({
401
542
  params,
402
543
  queryOptions
@@ -432,7 +573,7 @@ function useRenewUtxos({
432
573
  const session = loadRadfiSession(userAddress);
433
574
  const accessToken = session?.accessToken || radfi.accessToken;
434
575
  if (!accessToken) {
435
- throw new Error("Radfi authentication required. Please login first.");
576
+ throw new Error("Bound Exchange authentication required. Please login first.");
436
577
  }
437
578
  const buildResult = await radfi.buildRenewUtxoTransaction({ userAddress, txIdVouts }, accessToken);
438
579
  const signedTx = await walletProvider.signTransaction(buildResult.base64Psbt, false);
@@ -460,7 +601,7 @@ function useRadfiWithdraw({
460
601
  const session = loadRadfiSession(userAddress);
461
602
  const accessToken = session?.accessToken || radfi.accessToken;
462
603
  if (!accessToken) {
463
- throw new Error("Radfi authentication required. Please login first.");
604
+ throw new Error("Bound Exchange authentication required. Please login first.");
464
605
  }
465
606
  const buildResult = await radfi.withdrawToUser({ userAddress, amount, tokenId, withdrawTo }, accessToken);
466
607
  const signedTx = await walletProvider.signTransaction(buildResult.base64Psbt, false);
@@ -581,7 +722,10 @@ function useUserReservesData({
581
722
  if (!spokeChainKey || !userAddress) {
582
723
  throw new Error("spokeChainKey and userAddress are required");
583
724
  }
584
- return sodax.moneyMarket.data.getUserReservesData(spokeChainKey, userAddress);
725
+ return sodax.moneyMarket.data.getUserReservesData(
726
+ spokeChainKey,
727
+ resolveBtcReadAddress(spokeChainKey, userAddress)
728
+ );
585
729
  },
586
730
  enabled: !!spokeChainKey && !!userAddress,
587
731
  refetchInterval: 5e3,
@@ -707,7 +851,10 @@ function useATokensBalances({
707
851
  throw new Error(`Invalid aToken address: ${aToken}`);
708
852
  }
709
853
  }
710
- const hubWalletAddress = await sodax.hubProvider.getUserHubWalletAddress(userAddress, spokeChainKey);
854
+ const hubWalletAddress = await sodax.hubProvider.getUserHubWalletAddress(
855
+ resolveBtcReadAddress(spokeChainKey, userAddress),
856
+ spokeChainKey
857
+ );
711
858
  return sodax.moneyMarket.data.getATokensBalances(aTokens, hubWalletAddress);
712
859
  },
713
860
  enabled: aTokens.length > 0 && !!spokeChainKey && !!userAddress,
@@ -742,7 +889,10 @@ function useUserFormattedSummary({
742
889
  }
743
890
  const [reserves, userReserves] = await Promise.all([
744
891
  sodax.moneyMarket.data.getReservesHumanized(),
745
- sodax.moneyMarket.data.getUserReservesHumanized(spokeChainKey, userAddress)
892
+ sodax.moneyMarket.data.getUserReservesHumanized(
893
+ spokeChainKey,
894
+ resolveBtcReadAddress(spokeChainKey, userAddress)
895
+ )
746
896
  ]);
747
897
  const formattedReserves = sodax.moneyMarket.data.formatReservesUSD(
748
898
  sodax.moneyMarket.data.buildReserveDataWithPrice(reserves)
@@ -956,189 +1106,500 @@ var useBackendUserIntents = ({
956
1106
  ...queryOptions
957
1107
  });
958
1108
  };
1109
+ var useBackendOrderbook = ({
1110
+ params,
1111
+ queryOptions
1112
+ } = {}) => {
1113
+ const { sodax } = useSodaxContext();
1114
+ const pagination = params?.pagination;
1115
+ return useQuery({
1116
+ queryKey: ["backend", "orderbook", pagination?.offset, pagination?.limit],
1117
+ queryFn: async () => {
1118
+ if (!pagination?.offset || !pagination?.limit) {
1119
+ throw new Error("Pagination offset and limit are required");
1120
+ }
1121
+ return unwrapResult(await sodax.backendApi.getOrderbook(pagination));
1122
+ },
1123
+ enabled: !!pagination?.offset && !!pagination?.limit,
1124
+ staleTime: 30 * 1e3,
1125
+ retry: 3,
1126
+ ...queryOptions
1127
+ });
1128
+ };
1129
+ var useBackendMoneyMarketPosition = ({
1130
+ params,
1131
+ queryOptions
1132
+ } = {}) => {
1133
+ const { sodax } = useSodaxContext();
1134
+ const userAddress = params?.userAddress;
1135
+ return useQuery({
1136
+ queryKey: ["backend", "mm", "position", userAddress],
1137
+ queryFn: async () => {
1138
+ if (!userAddress) return void 0;
1139
+ return unwrapResult(await sodax.backendApi.getMoneyMarketPosition(userAddress));
1140
+ },
1141
+ enabled: !!userAddress && userAddress.length > 0,
1142
+ retry: 3,
1143
+ ...queryOptions
1144
+ });
1145
+ };
1146
+ var useBackendAllMoneyMarketAssets = ({
1147
+ queryOptions
1148
+ } = {}) => {
1149
+ const { sodax } = useSodaxContext();
1150
+ return useQuery({
1151
+ queryKey: ["backend", "mm", "assets", "all"],
1152
+ queryFn: async () => {
1153
+ return unwrapResult(await sodax.backendApi.getAllMoneyMarketAssets());
1154
+ },
1155
+ retry: 3,
1156
+ ...queryOptions
1157
+ });
1158
+ };
1159
+ var useBackendMoneyMarketAsset = ({
1160
+ params,
1161
+ queryOptions
1162
+ } = {}) => {
1163
+ const { sodax } = useSodaxContext();
1164
+ const reserveAddress = params?.reserveAddress;
1165
+ return useQuery({
1166
+ queryKey: ["backend", "mm", "asset", reserveAddress],
1167
+ queryFn: async () => {
1168
+ if (!reserveAddress) return void 0;
1169
+ return unwrapResult(await sodax.backendApi.getMoneyMarketAsset(reserveAddress));
1170
+ },
1171
+ enabled: !!reserveAddress && reserveAddress.length > 0,
1172
+ retry: 3,
1173
+ ...queryOptions
1174
+ });
1175
+ };
1176
+ var useBackendMoneyMarketAssetBorrowers = ({
1177
+ params,
1178
+ queryOptions
1179
+ } = {}) => {
1180
+ const { sodax } = useSodaxContext();
1181
+ const reserveAddress = params?.reserveAddress;
1182
+ const pagination = params?.pagination;
1183
+ return useQuery({
1184
+ queryKey: ["backend", "mm", "asset", "borrowers", reserveAddress, pagination],
1185
+ queryFn: async () => {
1186
+ if (!reserveAddress || !pagination?.offset || !pagination?.limit) {
1187
+ return void 0;
1188
+ }
1189
+ return unwrapResult(
1190
+ await sodax.backendApi.getMoneyMarketAssetBorrowers(reserveAddress, {
1191
+ offset: pagination.offset,
1192
+ limit: pagination.limit
1193
+ })
1194
+ );
1195
+ },
1196
+ enabled: !!reserveAddress && !!pagination?.offset && !!pagination?.limit,
1197
+ retry: 3,
1198
+ ...queryOptions
1199
+ });
1200
+ };
1201
+ var useBackendMoneyMarketAssetSuppliers = ({
1202
+ params,
1203
+ queryOptions
1204
+ } = {}) => {
1205
+ const { sodax } = useSodaxContext();
1206
+ const reserveAddress = params?.reserveAddress;
1207
+ const pagination = params?.pagination;
1208
+ return useQuery({
1209
+ queryKey: ["backend", "mm", "asset", "suppliers", reserveAddress, pagination],
1210
+ queryFn: async () => {
1211
+ if (!reserveAddress || !pagination?.offset || !pagination?.limit) {
1212
+ return void 0;
1213
+ }
1214
+ return unwrapResult(
1215
+ await sodax.backendApi.getMoneyMarketAssetSuppliers(reserveAddress, {
1216
+ offset: pagination.offset,
1217
+ limit: pagination.limit
1218
+ })
1219
+ );
1220
+ },
1221
+ enabled: !!reserveAddress && !!pagination?.offset && !!pagination?.limit,
1222
+ retry: 3,
1223
+ ...queryOptions
1224
+ });
1225
+ };
1226
+ var useBackendAllMoneyMarketBorrowers = ({
1227
+ params,
1228
+ queryOptions
1229
+ } = {}) => {
1230
+ const { sodax } = useSodaxContext();
1231
+ const pagination = params?.pagination;
1232
+ return useQuery({
1233
+ queryKey: ["backend", "mm", "borrowers", "all", pagination],
1234
+ queryFn: async () => {
1235
+ if (!pagination?.offset || !pagination?.limit) {
1236
+ return void 0;
1237
+ }
1238
+ return unwrapResult(
1239
+ await sodax.backendApi.getAllMoneyMarketBorrowers({
1240
+ offset: pagination.offset,
1241
+ limit: pagination.limit
1242
+ })
1243
+ );
1244
+ },
1245
+ enabled: !!pagination?.offset && !!pagination?.limit,
1246
+ retry: 3,
1247
+ ...queryOptions
1248
+ });
1249
+ };
1250
+ var useSwapsApiTokens = ({
1251
+ params,
1252
+ queryOptions
1253
+ } = {}) => {
1254
+ const { sodax } = useSodaxContext();
1255
+ const apiConfig = params?.apiConfig;
1256
+ return useQuery({
1257
+ queryKey: ["swapsApi", "tokens"],
1258
+ queryFn: async () => unwrapResult(await sodax.api.swaps.getTokens(apiConfig)),
1259
+ retry: 3,
1260
+ ...queryOptions
1261
+ });
1262
+ };
1263
+ var useSwapsApiTokensByChain = ({
1264
+ params,
1265
+ queryOptions
1266
+ } = {}) => {
1267
+ const { sodax } = useSodaxContext();
1268
+ const chainKey = params?.chainKey;
1269
+ const apiConfig = params?.apiConfig;
1270
+ return useQuery({
1271
+ queryKey: ["swapsApi", "tokens", chainKey],
1272
+ queryFn: async () => {
1273
+ if (!chainKey) return void 0;
1274
+ return unwrapResult(await sodax.api.swaps.getTokensByChain(chainKey, apiConfig));
1275
+ },
1276
+ enabled: !!chainKey && chainKey.length > 0,
1277
+ retry: 3,
1278
+ ...queryOptions
1279
+ });
1280
+ };
1281
+ var useSwapsApiQuote = ({
1282
+ params,
1283
+ queryOptions
1284
+ } = {}) => {
1285
+ const { sodax } = useSodaxContext();
1286
+ const body = params?.body;
1287
+ const query = params?.query;
1288
+ const apiConfig = params?.apiConfig;
1289
+ return useQuery({
1290
+ // Hash the whole request body so every quote input — including partnerFee and the other
1291
+ // SwapExtrasV2 fields — is a cache dimension; a partnerFee change alters the quote and must
1292
+ // miss the cache. QuoteRequestV2 is bigint-free (compile-time guaranteed), so React Query's
1293
+ // default key hashing handles the object directly.
1294
+ queryKey: ["swapsApi", "quote", body, query?.includeTxData ?? false],
1295
+ queryFn: async () => {
1296
+ if (!body) return void 0;
1297
+ return unwrapResult(await sodax.api.swaps.getQuote(body, query, apiConfig));
1298
+ },
1299
+ enabled: !!body,
1300
+ retry: 3,
1301
+ ...queryOptions
1302
+ });
1303
+ };
1304
+ var useSwapsApiDeadline = ({
1305
+ params,
1306
+ queryOptions
1307
+ } = {}) => {
1308
+ const { sodax } = useSodaxContext();
1309
+ const query = params?.query;
1310
+ const apiConfig = params?.apiConfig;
1311
+ return useQuery({
1312
+ queryKey: ["swapsApi", "deadline", query?.offsetSeconds ?? null],
1313
+ queryFn: async () => unwrapResult(await sodax.api.swaps.getDeadline(query, apiConfig)),
1314
+ retry: 3,
1315
+ ...queryOptions
1316
+ });
1317
+ };
1318
+ var useSwapsApiAllowance = ({
1319
+ params,
1320
+ queryOptions
1321
+ } = {}) => {
1322
+ const { sodax } = useSodaxContext();
1323
+ const body = params?.body;
1324
+ const apiConfig = params?.apiConfig;
1325
+ return useQuery({
1326
+ queryKey: ["swapsApi", "allowance", body?.srcChainKey, body?.inputToken, body?.inputAmount, body?.srcAddress],
1327
+ queryFn: async () => {
1328
+ if (!body) return void 0;
1329
+ return unwrapResult(await sodax.api.swaps.checkAllowance(body, apiConfig));
1330
+ },
1331
+ enabled: !!body,
1332
+ retry: 3,
1333
+ ...queryOptions
1334
+ });
1335
+ };
1336
+
1337
+ // src/hooks/swapsApi/useSwapsApiApprove.ts
1338
+ var useSwapsApiApprove = ({
1339
+ mutationOptions
1340
+ } = {}) => {
1341
+ const { sodax } = useSodaxContext();
1342
+ return useSafeMutation({
1343
+ mutationKey: ["swapsApi", "approve"],
1344
+ retry: 3,
1345
+ ...mutationOptions,
1346
+ mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.approve(body, apiConfig))
1347
+ });
1348
+ };
1349
+
1350
+ // src/hooks/swapsApi/useSwapsApiCreateIntent.ts
1351
+ var useSwapsApiCreateIntent = ({
1352
+ mutationOptions
1353
+ } = {}) => {
1354
+ const { sodax } = useSodaxContext();
1355
+ return useSafeMutation({
1356
+ mutationKey: ["swapsApi", "createIntent"],
1357
+ retry: 3,
1358
+ ...mutationOptions,
1359
+ mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.createIntent(body, apiConfig))
1360
+ });
1361
+ };
1362
+
1363
+ // src/hooks/swapsApi/useSwapsApiSubmitIntent.ts
1364
+ var useSwapsApiSubmitIntent = ({
1365
+ mutationOptions
1366
+ } = {}) => {
1367
+ const { sodax } = useSodaxContext();
1368
+ return useSafeMutation({
1369
+ mutationKey: ["swapsApi", "submitIntent"],
1370
+ retry: false,
1371
+ ...mutationOptions,
1372
+ mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.submitIntent(body, apiConfig))
1373
+ });
1374
+ };
1375
+
1376
+ // src/hooks/swapsApi/isTerminalSwapIntentStatus.ts
1377
+ var isTerminalSwapIntentStatus = (status) => status === 3 || status === 4;
1378
+
1379
+ // src/hooks/swapsApi/useSwapsApiStatus.ts
1380
+ var useSwapsApiStatus = ({
1381
+ params,
1382
+ queryOptions
1383
+ } = {}) => {
1384
+ const { sodax } = useSodaxContext();
1385
+ const intentTxHash = params?.intentTxHash;
1386
+ const apiConfig = params?.apiConfig;
1387
+ return useQuery({
1388
+ queryKey: ["swapsApi", "status", intentTxHash],
1389
+ queryFn: async () => {
1390
+ if (!intentTxHash) return void 0;
1391
+ return unwrapResult(await sodax.api.swaps.getStatus({ intentTxHash }, apiConfig));
1392
+ },
1393
+ enabled: !!intentTxHash && intentTxHash.length > 0,
1394
+ retry: 3,
1395
+ refetchInterval: (query) => isTerminalSwapIntentStatus(query.state.data?.status) ? false : 1e3,
1396
+ ...queryOptions
1397
+ });
1398
+ };
959
1399
 
960
- // src/hooks/backend/useBackendSubmitSwapTx.ts
961
- var useBackendSubmitSwapTx = ({
1400
+ // src/hooks/swapsApi/useSwapsApiCancelIntent.ts
1401
+ var useSwapsApiCancelIntent = ({
962
1402
  mutationOptions
963
1403
  } = {}) => {
964
1404
  const { sodax } = useSodaxContext();
965
1405
  return useSafeMutation({
966
- mutationKey: ["backend", "submitSwapTx"],
1406
+ mutationKey: ["swapsApi", "cancelIntent"],
967
1407
  retry: 3,
968
1408
  ...mutationOptions,
969
- mutationFn: async ({ request, apiConfig }) => unwrapResult(await sodax.backendApi.submitSwapTx(request, apiConfig))
1409
+ mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.cancelIntent(body, apiConfig))
970
1410
  });
971
1411
  };
972
- var useBackendSubmitSwapTxStatus = ({
1412
+ var useSwapsApiIntentHash = ({
973
1413
  params,
974
1414
  queryOptions
975
1415
  } = {}) => {
976
1416
  const { sodax } = useSodaxContext();
977
- const txHash = params?.txHash;
978
- const srcChainKey = params?.srcChainKey;
1417
+ const intent = params?.intent;
979
1418
  const apiConfig = params?.apiConfig;
980
1419
  return useQuery({
981
- queryKey: ["backend", "submitSwapTx", "status", txHash, srcChainKey],
1420
+ queryKey: ["swapsApi", "intentHash", intent?.intentId?.toString()],
982
1421
  queryFn: async () => {
983
- if (!txHash) return void 0;
984
- return unwrapResult(
985
- await sodax.backendApi.getSubmitSwapTxStatus(
986
- {
987
- txHash,
988
- srcChainKey
989
- },
990
- apiConfig
991
- )
992
- );
1422
+ if (!intent) return void 0;
1423
+ return unwrapResult(await sodax.api.swaps.getIntentHash({ intent }, apiConfig));
993
1424
  },
994
- enabled: !!txHash && txHash.length > 0,
1425
+ enabled: !!intent,
995
1426
  retry: 3,
996
- refetchInterval: (query) => {
997
- const status = query.state.data?.data?.status;
998
- if (status === "executed" || status === "failed") return false;
999
- return 1e3;
1427
+ ...queryOptions
1428
+ });
1429
+ };
1430
+ var useSwapsApiIntentPacket = ({
1431
+ params,
1432
+ queryOptions
1433
+ } = {}) => {
1434
+ const { sodax } = useSodaxContext();
1435
+ const body = params?.body;
1436
+ const apiConfig = params?.apiConfig;
1437
+ return useQuery({
1438
+ queryKey: ["swapsApi", "intentPacket", body?.chainId, body?.fillTxHash],
1439
+ queryFn: async () => {
1440
+ if (!body) return void 0;
1441
+ return unwrapResult(await sodax.api.swaps.getSolvedIntentPacket(body, apiConfig));
1000
1442
  },
1443
+ enabled: !!body,
1444
+ retry: 3,
1001
1445
  ...queryOptions
1002
1446
  });
1003
1447
  };
1004
- var useBackendOrderbook = ({
1448
+ var useSwapsApiIntentExtraData = ({
1005
1449
  params,
1006
1450
  queryOptions
1007
1451
  } = {}) => {
1008
1452
  const { sodax } = useSodaxContext();
1009
- const pagination = params?.pagination;
1453
+ const body = params?.body;
1454
+ const apiConfig = params?.apiConfig;
1010
1455
  return useQuery({
1011
- queryKey: ["backend", "orderbook", pagination?.offset, pagination?.limit],
1456
+ queryKey: ["swapsApi", "intentExtraData", body?.txHash ?? body?.intent?.intentId?.toString()],
1012
1457
  queryFn: async () => {
1013
- if (!pagination?.offset || !pagination?.limit) {
1014
- throw new Error("Pagination offset and limit are required");
1015
- }
1016
- return unwrapResult(await sodax.backendApi.getOrderbook(pagination));
1458
+ if (!body || !body.txHash && !body.intent) return void 0;
1459
+ return unwrapResult(await sodax.api.swaps.getIntentSubmitTxExtraData(body, apiConfig));
1017
1460
  },
1018
- enabled: !!pagination?.offset && !!pagination?.limit,
1019
- staleTime: 30 * 1e3,
1461
+ enabled: !!body && (!!body.txHash || !!body.intent),
1020
1462
  retry: 3,
1021
1463
  ...queryOptions
1022
1464
  });
1023
1465
  };
1024
- var useBackendMoneyMarketPosition = ({
1466
+ var useSwapsApiFilledIntent = ({
1025
1467
  params,
1026
1468
  queryOptions
1027
1469
  } = {}) => {
1028
1470
  const { sodax } = useSodaxContext();
1029
- const userAddress = params?.userAddress;
1471
+ const txHash = params?.txHash;
1472
+ const apiConfig = params?.apiConfig;
1030
1473
  return useQuery({
1031
- queryKey: ["backend", "mm", "position", userAddress],
1474
+ queryKey: ["swapsApi", "filledIntent", txHash],
1032
1475
  queryFn: async () => {
1033
- if (!userAddress) return void 0;
1034
- return unwrapResult(await sodax.backendApi.getMoneyMarketPosition(userAddress));
1476
+ if (!txHash) return void 0;
1477
+ return unwrapResult(await sodax.api.swaps.getFilledIntent(txHash, apiConfig));
1035
1478
  },
1036
- enabled: !!userAddress && userAddress.length > 0,
1479
+ enabled: !!txHash && txHash.length > 0,
1037
1480
  retry: 3,
1038
1481
  ...queryOptions
1039
1482
  });
1040
1483
  };
1041
- var useBackendAllMoneyMarketAssets = ({
1484
+ var useSwapsApiIntent = ({
1485
+ params,
1042
1486
  queryOptions
1043
1487
  } = {}) => {
1044
1488
  const { sodax } = useSodaxContext();
1489
+ const txHash = params?.txHash;
1490
+ const apiConfig = params?.apiConfig;
1045
1491
  return useQuery({
1046
- queryKey: ["backend", "mm", "assets", "all"],
1492
+ queryKey: ["swapsApi", "intent", txHash],
1047
1493
  queryFn: async () => {
1048
- return unwrapResult(await sodax.backendApi.getAllMoneyMarketAssets());
1494
+ if (!txHash) return void 0;
1495
+ return unwrapResult(await sodax.api.swaps.getIntent(txHash, apiConfig));
1049
1496
  },
1497
+ enabled: !!txHash && txHash.length > 0,
1050
1498
  retry: 3,
1051
1499
  ...queryOptions
1052
1500
  });
1053
1501
  };
1054
- var useBackendMoneyMarketAsset = ({
1502
+
1503
+ // src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts
1504
+ var useSwapsApiCreateLimitOrder = ({
1505
+ mutationOptions
1506
+ } = {}) => {
1507
+ const { sodax } = useSodaxContext();
1508
+ return useSafeMutation({
1509
+ mutationKey: ["swapsApi", "createLimitOrder"],
1510
+ retry: 3,
1511
+ ...mutationOptions,
1512
+ mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.createLimitOrderIntent(body, apiConfig))
1513
+ });
1514
+ };
1515
+ var useSwapsApiEstimateGas = ({
1055
1516
  params,
1056
1517
  queryOptions
1057
1518
  } = {}) => {
1058
1519
  const { sodax } = useSodaxContext();
1059
- const reserveAddress = params?.reserveAddress;
1520
+ const body = params?.body;
1521
+ const apiConfig = params?.apiConfig;
1060
1522
  return useQuery({
1061
- queryKey: ["backend", "mm", "asset", reserveAddress],
1523
+ queryKey: ["swapsApi", "estimateGas", body?.chainKey, body?.tx],
1062
1524
  queryFn: async () => {
1063
- if (!reserveAddress) return void 0;
1064
- return unwrapResult(await sodax.backendApi.getMoneyMarketAsset(reserveAddress));
1525
+ if (!body) return void 0;
1526
+ return unwrapResult(await sodax.api.swaps.estimateGas(body, apiConfig));
1065
1527
  },
1066
- enabled: !!reserveAddress && reserveAddress.length > 0,
1528
+ enabled: !!body,
1067
1529
  retry: 3,
1068
1530
  ...queryOptions
1069
1531
  });
1070
1532
  };
1071
- var useBackendMoneyMarketAssetBorrowers = ({
1533
+ var useSwapsApiPartnerFee = ({
1072
1534
  params,
1073
1535
  queryOptions
1074
1536
  } = {}) => {
1075
1537
  const { sodax } = useSodaxContext();
1076
- const reserveAddress = params?.reserveAddress;
1077
- const pagination = params?.pagination;
1538
+ const amount = params?.amount;
1539
+ const apiConfig = params?.apiConfig;
1078
1540
  return useQuery({
1079
- queryKey: ["backend", "mm", "asset", "borrowers", reserveAddress, pagination],
1541
+ queryKey: ["swapsApi", "partnerFee", amount],
1080
1542
  queryFn: async () => {
1081
- if (!reserveAddress || !pagination?.offset || !pagination?.limit) {
1082
- return void 0;
1083
- }
1084
- return unwrapResult(
1085
- await sodax.backendApi.getMoneyMarketAssetBorrowers(reserveAddress, {
1086
- offset: pagination.offset,
1087
- limit: pagination.limit
1088
- })
1089
- );
1543
+ if (!amount) return void 0;
1544
+ return unwrapResult(await sodax.api.swaps.getPartnerFee({ amount }, apiConfig));
1090
1545
  },
1091
- enabled: !!reserveAddress && !!pagination?.offset && !!pagination?.limit,
1546
+ enabled: !!amount && amount.length > 0,
1092
1547
  retry: 3,
1093
1548
  ...queryOptions
1094
1549
  });
1095
1550
  };
1096
- var useBackendMoneyMarketAssetSuppliers = ({
1551
+ var useSwapsApiSolverFee = ({
1097
1552
  params,
1098
1553
  queryOptions
1099
1554
  } = {}) => {
1100
1555
  const { sodax } = useSodaxContext();
1101
- const reserveAddress = params?.reserveAddress;
1102
- const pagination = params?.pagination;
1556
+ const amount = params?.amount;
1557
+ const apiConfig = params?.apiConfig;
1103
1558
  return useQuery({
1104
- queryKey: ["backend", "mm", "asset", "suppliers", reserveAddress, pagination],
1559
+ queryKey: ["swapsApi", "solverFee", amount],
1105
1560
  queryFn: async () => {
1106
- if (!reserveAddress || !pagination?.offset || !pagination?.limit) {
1107
- return void 0;
1108
- }
1109
- return unwrapResult(
1110
- await sodax.backendApi.getMoneyMarketAssetSuppliers(reserveAddress, {
1111
- offset: pagination.offset,
1112
- limit: pagination.limit
1113
- })
1114
- );
1561
+ if (!amount) return void 0;
1562
+ return unwrapResult(await sodax.api.swaps.getSolverFee({ amount }, apiConfig));
1115
1563
  },
1116
- enabled: !!reserveAddress && !!pagination?.offset && !!pagination?.limit,
1564
+ enabled: !!amount && amount.length > 0,
1117
1565
  retry: 3,
1118
1566
  ...queryOptions
1119
1567
  });
1120
1568
  };
1121
- var useBackendAllMoneyMarketBorrowers = ({
1569
+
1570
+ // src/hooks/swapsApi/useSwapsApiSubmitTx.ts
1571
+ var useSwapsApiSubmitTx = ({
1572
+ mutationOptions
1573
+ } = {}) => {
1574
+ const { sodax } = useSodaxContext();
1575
+ return useSafeMutation({
1576
+ mutationKey: ["swapsApi", "submitTx"],
1577
+ retry: 3,
1578
+ ...mutationOptions,
1579
+ mutationFn: async ({ request, apiConfig }) => unwrapResult(await sodax.api.swaps.submitTx(request, apiConfig))
1580
+ });
1581
+ };
1582
+ var useSwapsApiSubmitTxStatus = ({
1122
1583
  params,
1123
1584
  queryOptions
1124
1585
  } = {}) => {
1125
1586
  const { sodax } = useSodaxContext();
1126
- const pagination = params?.pagination;
1587
+ const txHash = params?.txHash;
1588
+ const srcChainKey = params?.srcChainKey;
1589
+ const apiConfig = params?.apiConfig;
1127
1590
  return useQuery({
1128
- queryKey: ["backend", "mm", "borrowers", "all", pagination],
1591
+ queryKey: ["swapsApi", "submitTx", "status", txHash, srcChainKey],
1129
1592
  queryFn: async () => {
1130
- if (!pagination?.offset || !pagination?.limit) {
1131
- return void 0;
1132
- }
1133
- return unwrapResult(
1134
- await sodax.backendApi.getAllMoneyMarketBorrowers({
1135
- offset: pagination.offset,
1136
- limit: pagination.limit
1137
- })
1138
- );
1593
+ if (!txHash || !srcChainKey) return void 0;
1594
+ return unwrapResult(await sodax.api.swaps.getSubmitTxStatus({ txHash, srcChainKey }, apiConfig));
1139
1595
  },
1140
- enabled: !!pagination?.offset && !!pagination?.limit,
1596
+ enabled: !!txHash && txHash.length > 0 && !!srcChainKey,
1141
1597
  retry: 3,
1598
+ refetchInterval: (query) => {
1599
+ const status = query.state.data?.data?.status;
1600
+ if (status === "solved" || status === "failed") return false;
1601
+ return 1e3;
1602
+ },
1142
1603
  ...queryOptions
1143
1604
  });
1144
1605
  };
@@ -1764,6 +2225,107 @@ function useFeeClaimSwap({
1764
2225
  }
1765
2226
  });
1766
2227
  }
2228
+ function usePartnerCancelIntent({
2229
+ mutationOptions
2230
+ } = {}) {
2231
+ const { sodax } = useSodaxContext();
2232
+ const queryClient = useQueryClient();
2233
+ return useSafeMutation({
2234
+ mutationKey: ["partner", "cancelIntent"],
2235
+ ...mutationOptions,
2236
+ mutationFn: async (vars) => unwrapResult(await sodax.partners.feeClaim.cancelIntent({ ...vars, raw: false })),
2237
+ onSuccess: async (data, vars, ctx) => {
2238
+ queryClient.invalidateQueries({
2239
+ queryKey: ["partner", "feeClaim", "assetsBalances", vars.params.srcAddress]
2240
+ });
2241
+ queryClient.invalidateQueries({
2242
+ queryKey: [
2243
+ "partner",
2244
+ "feeClaim",
2245
+ "userIntent",
2246
+ vars.params.srcAddress,
2247
+ vars.params.fromToken,
2248
+ vars.params.toToken
2249
+ ]
2250
+ });
2251
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
2252
+ }
2253
+ });
2254
+ }
2255
+ function useGetUserIntent({ params, queryOptions } = {}) {
2256
+ const { sodax } = useSodaxContext();
2257
+ const user = params?.user;
2258
+ const fromToken = params?.fromToken;
2259
+ const toToken = params?.toToken;
2260
+ return useQuery({
2261
+ queryKey: ["partner", "feeClaim", "userIntent", user, fromToken, toToken],
2262
+ queryFn: async () => {
2263
+ if (!user || !fromToken || !toToken) {
2264
+ throw new Error("user, fromToken and toToken are required");
2265
+ }
2266
+ const result = await sodax.partners.feeClaim.getUserIntent({ user, fromToken, toToken });
2267
+ if (!result.ok) throw result.error;
2268
+ return result.value;
2269
+ },
2270
+ enabled: !!user && !!fromToken && !!toToken,
2271
+ ...queryOptions
2272
+ });
2273
+ }
2274
+ var ZERO_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000";
2275
+ function useGetIntentDetails({
2276
+ params,
2277
+ queryOptions
2278
+ } = {}) {
2279
+ const { sodax } = useSodaxContext();
2280
+ const intentHash = params?.intentHash;
2281
+ const hasIntent = !!intentHash && intentHash !== ZERO_HASH;
2282
+ return useQuery({
2283
+ queryKey: ["partner", "feeClaim", "intentDetails", intentHash],
2284
+ queryFn: async () => {
2285
+ if (!intentHash) {
2286
+ throw new Error("intentHash is required");
2287
+ }
2288
+ const result = await sodax.partners.feeClaim.getIntentDetails(intentHash);
2289
+ if (!result.ok) throw result.error;
2290
+ return result.value;
2291
+ },
2292
+ enabled: hasIntent,
2293
+ ...queryOptions
2294
+ });
2295
+ }
2296
+ function useFeeClaimWithdraw({
2297
+ mutationOptions
2298
+ } = {}) {
2299
+ const { sodax } = useSodaxContext();
2300
+ const queryClient = useQueryClient();
2301
+ return useSafeMutation({
2302
+ mutationKey: ["partner", "feeClaimWithdraw"],
2303
+ ...mutationOptions,
2304
+ mutationFn: async ({ params, walletProvider }) => {
2305
+ const bridgeParams = {
2306
+ params: {
2307
+ srcChainKey: ChainKeys.SONIC_MAINNET,
2308
+ srcAddress: params.srcAddress,
2309
+ srcToken: params.feeToken,
2310
+ amount: params.amount,
2311
+ dstChainKey: params.dstChainKey,
2312
+ dstToken: params.dstToken,
2313
+ recipient: params.recipient
2314
+ },
2315
+ raw: false,
2316
+ walletProvider
2317
+ };
2318
+ return unwrapResult(await sodax.bridge.bridge(bridgeParams));
2319
+ },
2320
+ onSuccess: async (data, vars, ctx) => {
2321
+ queryClient.invalidateQueries({
2322
+ queryKey: ["partner", "feeClaim", "assetsBalances", vars.params.srcAddress]
2323
+ });
2324
+ queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.dstChainKey] });
2325
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
2326
+ }
2327
+ });
2328
+ }
1767
2329
  function useHubAssetBalances({
1768
2330
  params,
1769
2331
  queryOptions
@@ -2482,6 +3044,158 @@ function useClaimRewards({
2482
3044
  }
2483
3045
  });
2484
3046
  }
3047
+ function useLeverageYieldEffectiveApr({
3048
+ params,
3049
+ queryOptions
3050
+ } = {}) {
3051
+ const { sodax } = useSodaxContext();
3052
+ const vault = params?.vault;
3053
+ return useQuery({
3054
+ queryKey: ["leverageYield", "effectiveApr", vault],
3055
+ queryFn: async () => {
3056
+ if (!vault) throw new Error("vault is required");
3057
+ const result = await sodax.leverageYield.getEffectiveApr(vault);
3058
+ if (!result.ok) throw result.error;
3059
+ return result.value;
3060
+ },
3061
+ enabled: !!vault,
3062
+ refetchInterval: 6e4,
3063
+ ...queryOptions
3064
+ });
3065
+ }
3066
+ function useLeverageYieldPosition({
3067
+ params,
3068
+ queryOptions
3069
+ } = {}) {
3070
+ const { sodax } = useSodaxContext();
3071
+ const vault = params?.vault;
3072
+ return useQuery({
3073
+ queryKey: ["leverageYield", "position", vault],
3074
+ queryFn: async () => {
3075
+ if (!vault) throw new Error("vault is required");
3076
+ const result = await sodax.leverageYield.getPosition(vault);
3077
+ if (!result.ok) throw result.error;
3078
+ return result.value;
3079
+ },
3080
+ enabled: !!vault,
3081
+ refetchInterval: 3e4,
3082
+ ...queryOptions
3083
+ });
3084
+ }
3085
+ function useLeverageYieldTotalAssets({
3086
+ params,
3087
+ queryOptions
3088
+ } = {}) {
3089
+ const { sodax } = useSodaxContext();
3090
+ const vault = params?.vault;
3091
+ return useQuery({
3092
+ queryKey: ["leverageYield", "totalAssets", vault],
3093
+ queryFn: async () => {
3094
+ if (!vault) throw new Error("vault is required");
3095
+ const result = await sodax.leverageYield.getTotalAssets(vault);
3096
+ if (!result.ok) throw result.error;
3097
+ return result.value;
3098
+ },
3099
+ enabled: !!vault,
3100
+ refetchInterval: 6e4,
3101
+ ...queryOptions
3102
+ });
3103
+ }
3104
+ function useLeverageYieldPreviewRedeem({
3105
+ params,
3106
+ queryOptions
3107
+ } = {}) {
3108
+ const { sodax } = useSodaxContext();
3109
+ const vault = params?.vault;
3110
+ const shares = params?.shares;
3111
+ return useQuery({
3112
+ queryKey: ["leverageYield", "previewRedeem", vault, shares?.toString()],
3113
+ queryFn: async () => {
3114
+ if (!vault || shares === void 0) throw new Error("vault and shares are required");
3115
+ const result = await sodax.leverageYield.previewRedeem(vault, shares);
3116
+ if (!result.ok) throw result.error;
3117
+ return result.value;
3118
+ },
3119
+ enabled: !!vault && shares !== void 0,
3120
+ refetchInterval: 6e4,
3121
+ ...queryOptions
3122
+ });
3123
+ }
3124
+ function useLeverageYieldShareBalances({
3125
+ params,
3126
+ queryOptions
3127
+ } = {}) {
3128
+ const { sodax } = useSodaxContext();
3129
+ const vault = params?.vault;
3130
+ const holders = params?.holders;
3131
+ return useQueries({
3132
+ queries: (holders ?? []).map(({ chainKey, address }) => ({
3133
+ queryKey: ["leverageYield", "shareBalance", vault, chainKey, address],
3134
+ refetchInterval: 15e3,
3135
+ ...queryOptions,
3136
+ enabled: !!vault,
3137
+ queryFn: async () => {
3138
+ if (!vault) throw new Error("vault is required");
3139
+ const holder = await sodax.hubProvider.getUserHubWalletAddress(address, chainKey);
3140
+ const result = await sodax.leverageYield.getShareBalance(vault, holder);
3141
+ if (!result.ok) throw result.error;
3142
+ return { chainKey, holder, shares: result.value };
3143
+ }
3144
+ }))
3145
+ });
3146
+ }
3147
+
3148
+ // src/hooks/leverageYield/useLeverageYieldDeposit.ts
3149
+ function useLeverageYieldDeposit({
3150
+ mutationOptions
3151
+ } = {}) {
3152
+ const { sodax } = useSodaxContext();
3153
+ return useSafeMutation({
3154
+ mutationKey: ["leverageYield", "deposit"],
3155
+ ...mutationOptions,
3156
+ mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.deposit(vars))
3157
+ });
3158
+ }
3159
+
3160
+ // src/hooks/leverageYield/useLeverageYieldNotifySolver.ts
3161
+ function useLeverageYieldNotifySolver({
3162
+ mutationOptions
3163
+ } = {}) {
3164
+ const { sodax } = useSodaxContext();
3165
+ return useSafeMutation({
3166
+ mutationKey: ["leverageYield", "notifySolver"],
3167
+ ...mutationOptions,
3168
+ mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.notifySolver(vars))
3169
+ });
3170
+ }
3171
+ function useLeverageYieldVaultSwap({
3172
+ mutationOptions
3173
+ } = {}) {
3174
+ const { sodax } = useSodaxContext();
3175
+ const queryClient = useQueryClient();
3176
+ return useSafeMutation({
3177
+ mutationKey: ["leverageYield", "vaultSwap"],
3178
+ ...mutationOptions,
3179
+ mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.vaultSwap({ ...vars, raw: false })),
3180
+ onSuccess: async (data, vars, ctx) => {
3181
+ queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.srcChainKey] });
3182
+ queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.dstChainKey] });
3183
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
3184
+ }
3185
+ });
3186
+ }
3187
+
3188
+ // src/hooks/leverageYield/useLeverageYieldWithdraw.ts
3189
+ function useLeverageYieldWithdraw({
3190
+ mutationOptions
3191
+ } = {}) {
3192
+ const { sodax } = useSodaxContext();
3193
+ return useSafeMutation({
3194
+ mutationKey: ["leverageYield", "withdraw"],
3195
+ ...mutationOptions,
3196
+ mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.withdraw(vars))
3197
+ });
3198
+ }
2485
3199
  var SodaxProvider = ({ children, config }) => {
2486
3200
  const sodax = useMemo(() => new Sodax(config), [config]);
2487
3201
  const contextValue = useMemo(() => ({ sodax }), [sodax]);
@@ -2513,4 +3227,4 @@ function createSodaxQueryClient({
2513
3227
  });
2514
3228
  }
2515
3229
 
2516
- export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetUserHubWalletAddress, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
3230
+ export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getStellarTrustlineCheckQueryOptions, getXBalancesQueryOptions, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };