@sodax/dapp-kit 0.0.1-rc.1 → 0.0.1-rc.11

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 (80) hide show
  1. package/README.md +15 -13
  2. package/dist/contexts/index.d.ts +2 -1
  3. package/dist/contexts/index.d.ts.map +1 -1
  4. package/dist/core/index.d.ts +2 -3
  5. package/dist/core/index.d.ts.map +1 -1
  6. package/dist/hooks/mm/index.d.ts +3 -1
  7. package/dist/hooks/mm/index.d.ts.map +1 -1
  8. package/dist/hooks/mm/useBorrow.d.ts +13 -4
  9. package/dist/hooks/mm/useBorrow.d.ts.map +1 -1
  10. package/dist/hooks/mm/useMMAllowance.d.ts +26 -0
  11. package/dist/hooks/mm/useMMAllowance.d.ts.map +1 -0
  12. package/dist/hooks/mm/useMMApprove.d.ts +27 -0
  13. package/dist/hooks/mm/useMMApprove.d.ts.map +1 -0
  14. package/dist/hooks/mm/useRepay.d.ts +13 -4
  15. package/dist/hooks/mm/useRepay.d.ts.map +1 -1
  16. package/dist/hooks/mm/useReservesData.d.ts +19 -0
  17. package/dist/hooks/mm/useReservesData.d.ts.map +1 -0
  18. package/dist/hooks/mm/useSupply.d.ts +4 -2
  19. package/dist/hooks/mm/useSupply.d.ts.map +1 -1
  20. package/dist/hooks/mm/useUserReservesData.d.ts +1 -7
  21. package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
  22. package/dist/hooks/mm/useWithdraw.d.ts +11 -4
  23. package/dist/hooks/mm/useWithdraw.d.ts.map +1 -1
  24. package/dist/hooks/provider/useHubProvider.d.ts +1 -1
  25. package/dist/hooks/provider/useHubProvider.d.ts.map +1 -1
  26. package/dist/hooks/provider/useSpokeProvider.d.ts +16 -2
  27. package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
  28. package/dist/hooks/shared/index.d.ts +1 -2
  29. package/dist/hooks/shared/index.d.ts.map +1 -1
  30. package/dist/hooks/shared/useEstimateGas.d.ts +4 -0
  31. package/dist/hooks/shared/useEstimateGas.d.ts.map +1 -0
  32. package/dist/hooks/swap/index.d.ts +2 -0
  33. package/dist/hooks/swap/index.d.ts.map +1 -1
  34. package/dist/hooks/swap/useCreateIntentOrder.d.ts +6 -6
  35. package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +1 -1
  36. package/dist/hooks/swap/useQuote.d.ts +4 -4
  37. package/dist/hooks/swap/useQuote.d.ts.map +1 -1
  38. package/dist/hooks/swap/useStatus.d.ts +3 -3
  39. package/dist/hooks/swap/useStatus.d.ts.map +1 -1
  40. package/dist/hooks/swap/useSwapAllowance.d.ts +23 -0
  41. package/dist/hooks/swap/useSwapAllowance.d.ts.map +1 -0
  42. package/dist/hooks/swap/useSwapApprove.d.ts +26 -0
  43. package/dist/hooks/swap/useSwapApprove.d.ts.map +1 -0
  44. package/dist/index.js +242 -189
  45. package/dist/index.js.map +1 -1
  46. package/dist/index.mjs +239 -188
  47. package/dist/index.mjs.map +1 -1
  48. package/dist/providers/SodaxProvider.d.ts.map +1 -1
  49. package/package.json +4 -4
  50. package/src/contexts/index.ts +2 -1
  51. package/src/core/index.ts +5 -35
  52. package/src/hooks/mm/index.ts +3 -1
  53. package/src/hooks/mm/useBorrow.ts +20 -10
  54. package/src/hooks/mm/useMMAllowance.ts +55 -0
  55. package/src/hooks/mm/useMMApprove.ts +67 -0
  56. package/src/hooks/mm/useRepay.ts +20 -10
  57. package/src/hooks/mm/useReservesData.ts +37 -0
  58. package/src/hooks/mm/useSupply.ts +9 -6
  59. package/src/hooks/mm/useUserReservesData.ts +17 -34
  60. package/src/hooks/mm/useWithdraw.ts +17 -11
  61. package/src/hooks/provider/useHubProvider.ts +2 -21
  62. package/src/hooks/provider/useSpokeProvider.ts +87 -10
  63. package/src/hooks/shared/index.ts +1 -2
  64. package/src/hooks/shared/useEstimateGas.ts +20 -0
  65. package/src/hooks/swap/index.ts +2 -0
  66. package/src/hooks/swap/useCreateIntentOrder.ts +9 -11
  67. package/src/hooks/swap/useQuote.ts +5 -5
  68. package/src/hooks/swap/useStatus.ts +3 -3
  69. package/src/hooks/swap/useSwapAllowance.ts +44 -0
  70. package/src/hooks/swap/useSwapApprove.ts +68 -0
  71. package/src/providers/SodaxProvider.tsx +18 -3
  72. package/dist/hooks/mm/useHubWalletAddress.d.ts +0 -24
  73. package/dist/hooks/mm/useHubWalletAddress.d.ts.map +0 -1
  74. package/dist/hooks/shared/useAllowance.d.ts +0 -3
  75. package/dist/hooks/shared/useAllowance.d.ts.map +0 -1
  76. package/dist/hooks/shared/useApprove.d.ts +0 -10
  77. package/dist/hooks/shared/useApprove.d.ts.map +0 -1
  78. package/src/hooks/mm/useHubWalletAddress.ts +0 -49
  79. package/src/hooks/shared/useAllowance.ts +0 -31
  80. package/src/hooks/shared/useApprove.ts +0 -53
package/dist/index.mjs CHANGED
@@ -1,9 +1,8 @@
1
1
  import React, { createContext, useContext, useMemo } from 'react';
2
- import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
3
- import { hubAssets, EvmSpokeProvider, spokeChainConfig, SuiSpokeProvider, getHubChainConfig, EvmHubProvider, EvmWalletAbstraction, getMoneyMarketConfig, Sodax } from '@sodax/sdk';
4
- import { getXChainType, useWalletProvider, useXAccount } from '@sodax/wallet-sdk';
2
+ import { SpokeService, EvmSpokeProvider, spokeChainConfig, SuiSpokeProvider, IconSpokeProvider, InjectiveSpokeProvider, StellarSpokeProvider, SolanaSpokeProvider, encodeAddress, EvmWalletAbstraction, getMoneyMarketConfig, Sodax, getHubChainConfig, EvmHubProvider, hubAssets } from '@sodax/sdk';
3
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
4
+ import { getXChainType, useWalletProvider } from '@sodax/wallet-sdk';
5
5
  import { parseUnits } from 'viem';
6
- import { CHAIN_IDS } from '@sodax/types';
7
6
 
8
7
  // src/contexts/index.ts
9
8
  var SodaxContext = createContext(null);
@@ -14,111 +13,83 @@ var useSodaxContext = () => {
14
13
  }
15
14
  return context;
16
15
  };
17
- function useSpokeProvider(spokeChainId) {
16
+ function useEstimateGas(spokeProvider) {
17
+ return useMutation({
18
+ mutationFn: async (rawTx) => {
19
+ if (!spokeProvider) {
20
+ throw new Error("spokeProvider is not found");
21
+ }
22
+ const response = await SpokeService.estimateGas(rawTx, spokeProvider);
23
+ return response;
24
+ }
25
+ });
26
+ }
27
+
28
+ // src/hooks/provider/useHubProvider.ts
29
+ function useHubProvider() {
30
+ const { hubProvider } = useSodaxContext();
31
+ return hubProvider;
32
+ }
33
+ function useSpokeProvider(spokeChainId, walletProvider) {
18
34
  const xChainType = getXChainType(spokeChainId);
19
- const walletProvider = useWalletProvider(spokeChainId);
35
+ const walletProvider_ = useWalletProvider(spokeChainId);
36
+ const _walletProvider = walletProvider ?? walletProvider_;
20
37
  const spokeProvider = useMemo(() => {
21
- if (!walletProvider) return void 0;
38
+ if (!_walletProvider) return void 0;
39
+ if (!spokeChainId) return void 0;
22
40
  if (xChainType === "EVM") {
23
- return new EvmSpokeProvider(walletProvider, spokeChainConfig[spokeChainId]);
41
+ return new EvmSpokeProvider(
42
+ _walletProvider,
43
+ spokeChainConfig[spokeChainId]
44
+ );
24
45
  }
25
46
  if (xChainType === "SUI") {
26
- return new SuiSpokeProvider(spokeChainConfig[spokeChainId], walletProvider);
47
+ return new SuiSpokeProvider(
48
+ spokeChainConfig[spokeChainId],
49
+ _walletProvider
50
+ );
27
51
  }
28
- return void 0;
29
- }, [walletProvider, xChainType, spokeChainId]);
30
- return spokeProvider;
31
- }
32
- function useAllowance(token, amount) {
33
- const { sodax } = useSodaxContext();
34
- const spokeProvider = useSpokeProvider(token.xChainId);
35
- return useQuery({
36
- queryKey: ["allowance", token.address, amount],
37
- queryFn: async () => {
38
- if (!spokeProvider) {
39
- return false;
40
- }
41
- const allowance = await sodax.moneyMarket.isAllowanceValid(
42
- {
43
- token: token.address,
44
- amount: parseUnits(amount, token.decimals)
45
- },
46
- spokeProvider
52
+ if (xChainType === "ICON") {
53
+ return new IconSpokeProvider(
54
+ _walletProvider,
55
+ spokeChainConfig[spokeChainId]
47
56
  );
48
- if (allowance.ok) {
49
- return allowance.value;
50
- }
51
- return false;
52
- },
53
- enabled: !!spokeProvider
54
- });
55
- }
56
- function useApprove(token) {
57
- const { sodax } = useSodaxContext();
58
- const spokeProvider = useSpokeProvider(token.xChainId);
59
- const queryClient = useQueryClient();
60
- const {
61
- mutateAsync: approve,
62
- isPending,
63
- error,
64
- reset: resetError
65
- } = useMutation({
66
- mutationFn: async (amount) => {
67
- if (!spokeProvider) {
68
- throw new Error("Spoke provider not found");
69
- }
70
- const allowance = await sodax.moneyMarket.approve(
71
- token.address,
72
- parseUnits(amount, token.decimals),
73
- spokeProvider.chainConfig.addresses.assetManager,
74
- spokeProvider
57
+ }
58
+ if (xChainType === "INJECTIVE") {
59
+ return new InjectiveSpokeProvider(
60
+ spokeChainConfig[spokeChainId],
61
+ _walletProvider
75
62
  );
76
- if (!allowance.ok) {
77
- throw new Error("Failed to approve tokens");
78
- }
79
- return allowance.ok;
80
- },
81
- onSuccess: () => {
82
- queryClient.invalidateQueries({ queryKey: ["allowance", token.address] });
83
63
  }
84
- });
85
- return {
86
- approve,
87
- isLoading: isPending,
88
- error,
89
- resetError
90
- };
91
- }
92
- function useHubProvider() {
93
- const { sodax } = useSodaxContext();
94
- const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id;
95
- const hubRpcUrl = sodax.config?.hubProviderConfig?.hubRpcUrl;
96
- const xChainType = getXChainType(hubChainId);
97
- const hubProvider = useMemo(() => {
98
- if (xChainType === "EVM" && hubChainId && hubRpcUrl) {
99
- const hubChainCfg = getHubChainConfig(hubChainId);
100
- if (!hubChainCfg) return void 0;
101
- return new EvmHubProvider({
102
- hubRpcUrl,
103
- chainConfig: hubChainCfg
64
+ if (xChainType === "STELLAR") {
65
+ const stellarConfig = spokeChainConfig[spokeChainId];
66
+ return new StellarSpokeProvider(_walletProvider, stellarConfig, {
67
+ horizonRpcUrl: stellarConfig.horizonRpcUrl,
68
+ sorobanRpcUrl: stellarConfig.sorobanRpcUrl
104
69
  });
105
70
  }
71
+ if (xChainType === "SOLANA") {
72
+ return new SolanaSpokeProvider(
73
+ _walletProvider,
74
+ spokeChainConfig[spokeChainId]
75
+ );
76
+ }
106
77
  return void 0;
107
- }, [xChainType, hubChainId, hubRpcUrl]);
108
- return hubProvider;
78
+ }, [spokeChainId, xChainType, _walletProvider]);
79
+ return spokeProvider;
109
80
  }
110
- function useBorrow(hubToken, spokeChainId) {
81
+ function useBorrow(spokeToken, spokeProvider) {
111
82
  const { sodax } = useSodaxContext();
112
- const spokeProvider = useSpokeProvider(spokeChainId);
113
83
  return useMutation({
114
84
  mutationFn: async (amount) => {
115
85
  if (!spokeProvider) {
116
86
  throw new Error("spokeProvider is not found");
117
87
  }
118
- const response = await sodax.moneyMarket.borrowAndSubmit(
88
+ const response = await sodax.moneyMarket.borrow(
119
89
  {
120
- token: hubToken.address,
121
- amount: parseUnits(amount, hubToken.decimals)
90
+ token: spokeToken.address,
91
+ amount: parseUnits(amount, 18),
92
+ action: "borrow"
122
93
  },
123
94
  spokeProvider
124
95
  );
@@ -130,18 +101,18 @@ function useBorrow(hubToken, spokeChainId) {
130
101
  }
131
102
  });
132
103
  }
133
- function useRepay(hubToken, spokeChainId) {
104
+ function useRepay(spokeToken, spokeProvider) {
134
105
  const { sodax } = useSodaxContext();
135
- const spokeProvider = useSpokeProvider(spokeChainId);
136
106
  return useMutation({
137
107
  mutationFn: async (amount) => {
138
108
  if (!spokeProvider) {
139
109
  throw new Error("spokeProvider is not found");
140
110
  }
141
- const response = await sodax.moneyMarket.repayAndSubmit(
111
+ const response = await sodax.moneyMarket.repay(
142
112
  {
143
- token: hubToken.address,
144
- amount: parseUnits(amount, hubToken.decimals)
113
+ token: spokeToken.address,
114
+ amount: parseUnits(amount, spokeToken.decimals),
115
+ action: "repay"
145
116
  },
146
117
  spokeProvider
147
118
  );
@@ -153,18 +124,18 @@ function useRepay(hubToken, spokeChainId) {
153
124
  }
154
125
  });
155
126
  }
156
- function useSupply(spokeToken) {
127
+ function useSupply(spokeToken, spokeProvider) {
157
128
  const { sodax } = useSodaxContext();
158
- const spokeProvider = useSpokeProvider(spokeToken.xChainId);
159
129
  return useMutation({
160
130
  mutationFn: async (amount) => {
161
131
  if (!spokeProvider) {
162
132
  throw new Error("spokeProvider is not found");
163
133
  }
164
- const response = await sodax.moneyMarket.supplyAndSubmit(
134
+ const response = await sodax.moneyMarket.supply(
165
135
  {
166
136
  token: spokeToken.address,
167
- amount: parseUnits(amount, spokeToken.decimals)
137
+ amount: parseUnits(amount, spokeToken.decimals),
138
+ action: "supply"
168
139
  },
169
140
  spokeProvider
170
141
  );
@@ -176,18 +147,19 @@ function useSupply(spokeToken) {
176
147
  }
177
148
  });
178
149
  }
179
- function useWithdraw(hubToken, spokeChainId) {
150
+ function useWithdraw(spokeToken, spokeProvider) {
180
151
  const { sodax } = useSodaxContext();
181
- const spokeProvider = useSpokeProvider(spokeChainId);
182
152
  return useMutation({
183
153
  mutationFn: async (amount) => {
184
154
  if (!spokeProvider) {
185
155
  throw new Error("spokeProvider is not found");
186
156
  }
187
- const response = await sodax.moneyMarket.withdrawAndSubmit(
157
+ const response = await sodax.moneyMarket.withdraw(
188
158
  {
189
- token: hubToken.address,
190
- amount: parseUnits(amount, hubToken.decimals)
159
+ token: spokeToken.address,
160
+ // vault token on hub chain decimals is 18
161
+ amount: parseUnits(amount, 18),
162
+ action: "withdraw"
191
163
  },
192
164
  spokeProvider
193
165
  );
@@ -199,100 +171,107 @@ function useWithdraw(hubToken, spokeChainId) {
199
171
  }
200
172
  });
201
173
  }
202
- var allXTokens = [];
203
- Object.keys(hubAssets).forEach((xChainId) => {
204
- const tokens = hubAssets[xChainId];
205
- Object.keys(tokens).forEach((tokenAddress) => {
206
- const token = tokens[tokenAddress];
207
- allXTokens.push({
208
- xChainId,
209
- symbol: token.symbol,
210
- name: token.name,
211
- decimals: token.decimal,
212
- address: tokenAddress
213
- });
214
- allXTokens.push({
215
- // @ts-ignore
216
- xChainId: CHAIN_IDS.includes(xChainId) ? "sonic" : "sonic-blaze",
217
- symbol: token.symbol,
218
- name: token.name,
219
- decimals: token.decimal,
220
- address: token.vault
221
- });
222
- });
223
- });
224
- var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
225
- const tokens = hubAssets[spokeChainId];
226
- const token = Object.keys(tokens).find((tokenAddress) => tokens[tokenAddress].vault === vault);
227
- if (!token) {
228
- throw new Error("Token not found");
229
- }
230
- return token;
231
- };
232
- function useHubWalletAddress(spokeChainId, address, hubProvider) {
233
- return useQuery({
234
- queryKey: ["hubWallet", spokeChainId, address],
174
+ function useUserReservesData(spokeChainId, address) {
175
+ const { sodax } = useSodaxContext();
176
+ const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? "sonic";
177
+ const hubProvider = useHubProvider();
178
+ const { data: userReserves } = useQuery({
179
+ queryKey: ["userReserves", spokeChainId, address],
235
180
  queryFn: async () => {
236
- if (!address) return null;
237
- try {
238
- const hubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(
239
- spokeChainId,
240
- address,
241
- hubProvider
242
- );
243
- return hubWalletAddress;
244
- } catch (error) {
245
- console.log("error", error);
246
- return null;
181
+ if (!hubProvider || !address) {
182
+ return;
247
183
  }
184
+ const addressBytes = encodeAddress(spokeChainId, address);
185
+ const hubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(
186
+ spokeChainId,
187
+ addressBytes,
188
+ hubProvider
189
+ );
190
+ const moneyMarketConfig = getMoneyMarketConfig(hubChainId);
191
+ const [res] = await sodax.moneyMarket.getUserReservesData(
192
+ hubWalletAddress,
193
+ moneyMarketConfig.uiPoolDataProvider,
194
+ moneyMarketConfig.poolAddressesProvider
195
+ );
196
+ return res;
248
197
  },
249
- enabled: !!address && !!hubProvider
198
+ enabled: !!spokeChainId && !!hubProvider && !!address,
199
+ refetchInterval: 5e3
250
200
  });
201
+ return userReserves;
251
202
  }
252
-
253
- // src/hooks/mm/useUserReservesData.ts
254
- function useUserReservesData(spokeChainId) {
203
+ function useReservesData() {
255
204
  const { sodax } = useSodaxContext();
256
205
  const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? "sonic";
257
- const hubWalletProvider = useWalletProvider(hubChainId);
258
- const hubProvider = useHubProvider();
259
- const { address } = useXAccount(spokeChainId);
260
- const { data: hubWalletAddress } = useHubWalletAddress(
261
- spokeChainId,
262
- address,
263
- hubProvider
264
- );
265
- const { data: userReserves } = useQuery({
266
- queryKey: ["userReserves", hubWalletAddress],
206
+ return useQuery({
207
+ queryKey: ["reservesData"],
267
208
  queryFn: async () => {
268
- if (!hubWalletProvider) {
269
- return;
209
+ const moneyMarketConfig = getMoneyMarketConfig(hubChainId);
210
+ return await sodax.moneyMarket.getReservesData(
211
+ moneyMarketConfig.uiPoolDataProvider,
212
+ moneyMarketConfig.poolAddressesProvider
213
+ );
214
+ }
215
+ });
216
+ }
217
+ function useMMAllowance(token, amount, action, spokeProvider) {
218
+ const { sodax } = useSodaxContext();
219
+ return useQuery({
220
+ queryKey: ["allowance", token.address, amount, action],
221
+ queryFn: async () => {
222
+ if (!spokeProvider) throw new Error("Spoke provider is required");
223
+ const allowance = await sodax.moneyMarket.isAllowanceValid(
224
+ {
225
+ token: token.address,
226
+ amount: parseUnits(amount, token.decimals),
227
+ action
228
+ },
229
+ spokeProvider
230
+ );
231
+ if (allowance.ok) {
232
+ return allowance.value;
270
233
  }
271
- if (!hubWalletAddress) {
272
- return;
234
+ return false;
235
+ },
236
+ enabled: !!spokeProvider
237
+ });
238
+ }
239
+ function useMMApprove(token, spokeProvider) {
240
+ const { sodax } = useSodaxContext();
241
+ const queryClient = useQueryClient();
242
+ const {
243
+ mutateAsync: approve,
244
+ isPending,
245
+ error,
246
+ reset: resetError
247
+ } = useMutation({
248
+ mutationFn: async ({ amount, action }) => {
249
+ if (!spokeProvider) {
250
+ throw new Error("Spoke provider not found");
273
251
  }
274
- const moneyMarketConfig = getMoneyMarketConfig(hubChainId);
275
- try {
276
- const [res] = await sodax.moneyMarket.getUserReservesData(
277
- hubWalletAddress,
278
- moneyMarketConfig.uiPoolDataProvider,
279
- moneyMarketConfig.poolAddressesProvider
280
- );
281
- return res?.map((r) => {
282
- return {
283
- ...r,
284
- token: allXTokens.find((t) => t.address === r.underlyingAsset)
285
- };
286
- });
287
- } catch (error) {
288
- console.log("error", error);
289
- return;
252
+ const allowance = await sodax.moneyMarket.approve(
253
+ {
254
+ token: token.address,
255
+ amount: parseUnits(amount, token.decimals),
256
+ action
257
+ },
258
+ spokeProvider
259
+ );
260
+ if (!allowance.ok) {
261
+ throw new Error("Failed to approve tokens");
290
262
  }
263
+ return allowance.ok;
291
264
  },
292
- enabled: !!address && !!hubWalletProvider && !!hubWalletAddress,
293
- refetchInterval: 5e3
265
+ onSuccess: () => {
266
+ queryClient.invalidateQueries({ queryKey: ["allowance", token.address] });
267
+ }
294
268
  });
295
- return userReserves;
269
+ return {
270
+ approve,
271
+ isLoading: isPending,
272
+ error,
273
+ resetError
274
+ };
296
275
  }
297
276
  var useQuote = (payload) => {
298
277
  const { sodax } = useSodaxContext();
@@ -308,9 +287,8 @@ var useQuote = (payload) => {
308
287
  refetchInterval: 3e3
309
288
  });
310
289
  };
311
- function useCreateIntentOrder(chainId) {
290
+ function useCreateIntentOrder(spokeProvider) {
312
291
  const { sodax } = useSodaxContext();
313
- const spokeProvider = useSpokeProvider(chainId);
314
292
  return useMutation({
315
293
  mutationFn: async (params) => {
316
294
  if (!spokeProvider) {
@@ -331,11 +309,84 @@ var useStatus = (intent_tx_hash) => {
331
309
  // 3s
332
310
  });
333
311
  };
312
+ function useSwapAllowance(params, spokeProvider) {
313
+ const { sodax } = useSodaxContext();
314
+ return useQuery({
315
+ queryKey: ["allowance", params],
316
+ queryFn: async () => {
317
+ if (!spokeProvider || !params) {
318
+ return false;
319
+ }
320
+ const allowance = await sodax.solver.isAllowanceValid(params, spokeProvider);
321
+ if (allowance.ok) {
322
+ return allowance.value;
323
+ }
324
+ return false;
325
+ },
326
+ enabled: !!spokeProvider && !!params
327
+ });
328
+ }
329
+ function useSwapApprove(token, spokeProvider) {
330
+ const { sodax } = useSodaxContext();
331
+ const queryClient = useQueryClient();
332
+ const {
333
+ mutateAsync: approve,
334
+ isPending,
335
+ error,
336
+ reset: resetError
337
+ } = useMutation({
338
+ mutationFn: async ({ amount }) => {
339
+ if (!spokeProvider) {
340
+ throw new Error("Spoke provider not found");
341
+ }
342
+ if (!token) {
343
+ throw new Error("Token not found");
344
+ }
345
+ const allowance = await sodax.solver.approve(
346
+ token.address,
347
+ parseUnits(amount, token.decimals),
348
+ spokeProvider
349
+ );
350
+ if (!allowance.ok) {
351
+ throw new Error("Failed to approve tokens");
352
+ }
353
+ return allowance.ok;
354
+ },
355
+ onSuccess: () => {
356
+ queryClient.invalidateQueries({ queryKey: ["allowance", token?.address] });
357
+ }
358
+ });
359
+ return {
360
+ approve,
361
+ isLoading: isPending,
362
+ error,
363
+ resetError
364
+ };
365
+ }
334
366
  var SodaxProvider = ({ children, testnet = false, config }) => {
335
367
  const sodax = new Sodax(config);
336
- return /* @__PURE__ */ React.createElement(SodaxContext.Provider, { value: { sodax, testnet } }, children);
368
+ const hubChainId = config?.hubProviderConfig?.chainConfig.chain.id;
369
+ const hubRpcUrl = config?.hubProviderConfig?.hubRpcUrl;
370
+ const hubProvider = useMemo(() => {
371
+ if (hubChainId && hubRpcUrl) {
372
+ const hubChainCfg = getHubChainConfig(hubChainId);
373
+ return new EvmHubProvider({
374
+ hubRpcUrl,
375
+ chainConfig: hubChainCfg
376
+ });
377
+ }
378
+ return void 0;
379
+ }, [hubChainId, hubRpcUrl]);
380
+ return /* @__PURE__ */ React.createElement(SodaxContext.Provider, { value: { sodax, testnet, hubProvider } }, children);
381
+ };
382
+ var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
383
+ const tokens = hubAssets[spokeChainId];
384
+ const address = Object.keys(tokens).find(
385
+ (tokenAddress) => tokens[tokenAddress].vault.toLowerCase() === vault.toLowerCase()
386
+ );
387
+ return address;
337
388
  };
338
389
 
339
- export { SodaxProvider, allXTokens, getSpokeTokenAddressByVault, useAllowance, useApprove, useBorrow, useCreateIntentOrder, useHubProvider, useHubWalletAddress, useQuote, useRepay, useSodaxContext, useSpokeProvider, useStatus, useSupply, useUserReservesData, useWithdraw };
390
+ export { SodaxProvider, getSpokeTokenAddressByVault, useBorrow, useCreateIntentOrder, useEstimateGas, useHubProvider, useMMAllowance, useMMApprove, useQuote, useRepay, useReservesData, useSodaxContext, useSpokeProvider, useStatus, useSupply, useSwapAllowance, useSwapApprove, useUserReservesData, useWithdraw };
340
391
  //# sourceMappingURL=index.mjs.map
341
392
  //# sourceMappingURL=index.mjs.map