@sodax/dapp-kit 1.0.1-beta → 1.0.3-beta
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/README.md +130 -39
- package/dist/index.d.mts +576 -346
- package/dist/index.d.ts +576 -346
- package/dist/index.js +357 -176
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +354 -178
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/hooks/backend/README.md +148 -49
- package/src/hooks/backend/index.ts +2 -0
- package/src/hooks/backend/types.ts +4 -0
- package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +31 -20
- package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +25 -7
- package/src/hooks/backend/useBackendIntentByHash.ts +36 -26
- package/src/hooks/backend/useBackendIntentByTxHash.ts +41 -29
- package/src/hooks/backend/useBackendMoneyMarketAsset.ts +40 -27
- package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +45 -36
- package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +45 -36
- package/src/hooks/backend/useBackendMoneyMarketPosition.ts +34 -37
- package/src/hooks/backend/useBackendOrderbook.ts +38 -38
- package/src/hooks/backend/useBackendUserIntents.ts +81 -0
- package/src/hooks/mm/index.ts +2 -0
- package/src/hooks/mm/useAToken.ts +37 -20
- package/src/hooks/mm/useATokensBalances.ts +87 -0
- package/src/hooks/mm/useBorrow.ts +36 -36
- package/src/hooks/mm/useMMAllowance.ts +33 -24
- package/src/hooks/mm/useMMApprove.ts +43 -48
- package/src/hooks/mm/useRepay.ts +32 -36
- package/src/hooks/mm/useReservesData.ts +35 -16
- package/src/hooks/mm/useReservesHumanized.ts +15 -3
- package/src/hooks/mm/useReservesList.ts +28 -15
- package/src/hooks/mm/useReservesUsdFormat.ts +30 -21
- package/src/hooks/mm/useSupply.ts +34 -36
- package/src/hooks/mm/useUserFormattedSummary.ts +42 -20
- package/src/hooks/mm/useUserReservesData.ts +34 -19
- package/src/hooks/mm/useWithdraw.ts +33 -35
- package/src/hooks/swap/index.ts +2 -0
- package/src/hooks/swap/useCancelLimitOrder.ts +53 -0
- package/src/hooks/swap/useCreateLimitOrder.ts +72 -0
- package/src/hooks/swap/useSwapAllowance.ts +7 -7
- package/src/hooks/swap/useSwapApprove.ts +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { createContext, useContext, useState, useCallback, useMemo, useRef, useEffect } from 'react';
|
|
2
2
|
import { SpokeService, deriveUserWalletAddress, STELLAR_MAINNET_CHAIN_ID, StellarSpokeProvider, StellarSpokeService, spokeChainConfig, SONIC_MAINNET_CHAIN_ID, SonicSpokeProvider, EvmSpokeProvider, SuiSpokeProvider, IconSpokeProvider, InjectiveSpokeProvider, SolanaSpokeProvider, isLegacybnUSDToken, Sodax } from '@sodax/sdk';
|
|
3
3
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
4
|
-
import { parseUnits } from 'viem';
|
|
4
|
+
import { isAddress, parseUnits } from 'viem';
|
|
5
5
|
import { ICON_MAINNET_CHAIN_ID } from '@sodax/types';
|
|
6
6
|
|
|
7
7
|
// src/contexts/index.ts
|
|
@@ -175,218 +175,275 @@ function useSpokeProvider(spokeChainId, walletProvider) {
|
|
|
175
175
|
}, [spokeChainId, xChainType, walletProvider, rpcConfig]);
|
|
176
176
|
return spokeProvider;
|
|
177
177
|
}
|
|
178
|
-
function useBorrow(
|
|
178
|
+
function useBorrow() {
|
|
179
179
|
const { sodax } = useSodaxContext();
|
|
180
180
|
return useMutation({
|
|
181
|
-
mutationFn: async (
|
|
181
|
+
mutationFn: async ({ params, spokeProvider }) => {
|
|
182
182
|
if (!spokeProvider) {
|
|
183
183
|
throw new Error("spokeProvider is not found");
|
|
184
184
|
}
|
|
185
|
-
const response = await sodax.moneyMarket.borrow(
|
|
186
|
-
{
|
|
187
|
-
token: spokeToken.address,
|
|
188
|
-
amount: parseUnits(amount, 18),
|
|
189
|
-
action: "borrow",
|
|
190
|
-
toChainId,
|
|
191
|
-
toAddress
|
|
192
|
-
},
|
|
193
|
-
spokeProvider
|
|
194
|
-
);
|
|
185
|
+
const response = await sodax.moneyMarket.borrow(params, spokeProvider);
|
|
195
186
|
if (!response.ok) {
|
|
196
|
-
throw
|
|
187
|
+
throw response.error;
|
|
197
188
|
}
|
|
198
|
-
console.log("Borrow transaction submitted:", response);
|
|
199
189
|
return response;
|
|
200
190
|
}
|
|
201
191
|
});
|
|
202
192
|
}
|
|
203
|
-
function useRepay(
|
|
193
|
+
function useRepay() {
|
|
204
194
|
const { sodax } = useSodaxContext();
|
|
205
195
|
return useMutation({
|
|
206
|
-
mutationFn: async (
|
|
196
|
+
mutationFn: async ({ params, spokeProvider }) => {
|
|
207
197
|
if (!spokeProvider) {
|
|
208
198
|
throw new Error("spokeProvider is not found");
|
|
209
199
|
}
|
|
210
|
-
const response = await sodax.moneyMarket.repay(
|
|
211
|
-
{
|
|
212
|
-
token: spokeToken.address,
|
|
213
|
-
amount: parseUnits(amount, spokeToken.decimals),
|
|
214
|
-
action: "repay",
|
|
215
|
-
toChainId,
|
|
216
|
-
toAddress
|
|
217
|
-
},
|
|
218
|
-
spokeProvider
|
|
219
|
-
);
|
|
200
|
+
const response = await sodax.moneyMarket.repay(params, spokeProvider);
|
|
220
201
|
if (!response.ok) {
|
|
221
|
-
throw
|
|
202
|
+
throw response.error;
|
|
222
203
|
}
|
|
223
|
-
console.log("Repay transaction submitted:", response);
|
|
224
204
|
return response;
|
|
225
205
|
}
|
|
226
206
|
});
|
|
227
207
|
}
|
|
228
|
-
function useSupply(
|
|
208
|
+
function useSupply() {
|
|
229
209
|
const { sodax } = useSodaxContext();
|
|
230
210
|
return useMutation({
|
|
231
|
-
mutationFn: async (
|
|
211
|
+
mutationFn: async ({ params, spokeProvider }) => {
|
|
232
212
|
if (!spokeProvider) {
|
|
233
213
|
throw new Error("spokeProvider is not found");
|
|
234
214
|
}
|
|
235
|
-
const response = await sodax.moneyMarket.supply(
|
|
236
|
-
{
|
|
237
|
-
token: spokeToken.address,
|
|
238
|
-
amount: parseUnits(amount, spokeToken.decimals),
|
|
239
|
-
action: "supply",
|
|
240
|
-
toChainId,
|
|
241
|
-
toAddress
|
|
242
|
-
},
|
|
243
|
-
spokeProvider
|
|
244
|
-
);
|
|
215
|
+
const response = await sodax.moneyMarket.supply(params, spokeProvider);
|
|
245
216
|
if (!response.ok) {
|
|
246
|
-
throw
|
|
217
|
+
throw response.error;
|
|
247
218
|
}
|
|
248
|
-
console.log("Supply transaction submitted:", response);
|
|
249
219
|
return response;
|
|
250
220
|
}
|
|
251
221
|
});
|
|
252
222
|
}
|
|
253
|
-
function useWithdraw(
|
|
223
|
+
function useWithdraw() {
|
|
254
224
|
const { sodax } = useSodaxContext();
|
|
255
225
|
return useMutation({
|
|
256
|
-
mutationFn: async (
|
|
226
|
+
mutationFn: async ({ params, spokeProvider }) => {
|
|
257
227
|
if (!spokeProvider) {
|
|
258
228
|
throw new Error("spokeProvider is not found");
|
|
259
229
|
}
|
|
260
|
-
const response = await sodax.moneyMarket.withdraw(
|
|
261
|
-
{
|
|
262
|
-
token: spokeToken.address,
|
|
263
|
-
// vault token on hub chain decimals is 18
|
|
264
|
-
amount: parseUnits(amount, 18),
|
|
265
|
-
action: "withdraw",
|
|
266
|
-
toChainId,
|
|
267
|
-
toAddress
|
|
268
|
-
},
|
|
269
|
-
spokeProvider
|
|
270
|
-
);
|
|
230
|
+
const response = await sodax.moneyMarket.withdraw(params, spokeProvider);
|
|
271
231
|
if (!response.ok) {
|
|
272
|
-
throw
|
|
232
|
+
throw response.error;
|
|
273
233
|
}
|
|
274
|
-
console.log("Withdraw transaction submitted:", response);
|
|
275
234
|
return response;
|
|
276
235
|
}
|
|
277
236
|
});
|
|
278
237
|
}
|
|
279
|
-
function useUserReservesData(
|
|
238
|
+
function useUserReservesData(params) {
|
|
280
239
|
const { sodax } = useSodaxContext();
|
|
240
|
+
const defaultQueryOptions = {
|
|
241
|
+
queryKey: ["mm", "userReservesData", params?.spokeProvider?.chainConfig.chain.id, params?.address],
|
|
242
|
+
enabled: !!params?.spokeProvider && !!params?.address,
|
|
243
|
+
refetchInterval: 5e3
|
|
244
|
+
};
|
|
245
|
+
const queryOptions = {
|
|
246
|
+
...defaultQueryOptions,
|
|
247
|
+
...params?.queryOptions
|
|
248
|
+
// override default query options if provided
|
|
249
|
+
};
|
|
281
250
|
return useQuery({
|
|
282
|
-
|
|
251
|
+
...queryOptions,
|
|
283
252
|
queryFn: async () => {
|
|
284
|
-
if (!spokeProvider) {
|
|
253
|
+
if (!params?.spokeProvider || !params?.address) {
|
|
285
254
|
throw new Error("Spoke provider or address is not defined");
|
|
286
255
|
}
|
|
287
|
-
return await sodax.moneyMarket.data.getUserReservesData(spokeProvider);
|
|
288
|
-
}
|
|
289
|
-
enabled: !!spokeProvider && !!address,
|
|
290
|
-
refetchInterval
|
|
256
|
+
return await sodax.moneyMarket.data.getUserReservesData(params.spokeProvider);
|
|
257
|
+
}
|
|
291
258
|
});
|
|
292
259
|
}
|
|
293
|
-
function useReservesData() {
|
|
260
|
+
function useReservesData(params) {
|
|
261
|
+
const defaultQueryOptions = {
|
|
262
|
+
queryKey: ["mm", "reservesData"],
|
|
263
|
+
refetchInterval: 5e3
|
|
264
|
+
};
|
|
265
|
+
const queryOptions = {
|
|
266
|
+
...defaultQueryOptions,
|
|
267
|
+
...params?.queryOptions
|
|
268
|
+
// override default query options if provided
|
|
269
|
+
};
|
|
294
270
|
const { sodax } = useSodaxContext();
|
|
295
271
|
return useQuery({
|
|
296
|
-
|
|
272
|
+
...queryOptions,
|
|
297
273
|
queryFn: async () => {
|
|
298
274
|
return await sodax.moneyMarket.data.getReservesData();
|
|
299
275
|
}
|
|
300
276
|
});
|
|
301
277
|
}
|
|
302
|
-
function useMMAllowance(
|
|
278
|
+
function useMMAllowance({
|
|
279
|
+
params,
|
|
280
|
+
spokeProvider,
|
|
281
|
+
queryOptions
|
|
282
|
+
}) {
|
|
303
283
|
const { sodax } = useSodaxContext();
|
|
284
|
+
const defaultQueryOptions = {
|
|
285
|
+
queryKey: ["mm", "allowance", params?.token, params?.action],
|
|
286
|
+
enabled: !!spokeProvider,
|
|
287
|
+
refetchInterval: 5e3
|
|
288
|
+
};
|
|
289
|
+
queryOptions = {
|
|
290
|
+
...defaultQueryOptions,
|
|
291
|
+
...queryOptions
|
|
292
|
+
// override default query options if provided
|
|
293
|
+
};
|
|
304
294
|
return useQuery({
|
|
305
|
-
|
|
295
|
+
...queryOptions,
|
|
306
296
|
queryFn: async () => {
|
|
307
297
|
if (!spokeProvider) throw new Error("Spoke provider is required");
|
|
308
|
-
|
|
309
|
-
const allowance = await sodax.moneyMarket.isAllowanceValid(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
amount: parseUnits(amount, actionBasedDecimals),
|
|
313
|
-
action
|
|
314
|
-
},
|
|
315
|
-
spokeProvider
|
|
316
|
-
);
|
|
317
|
-
if (allowance.ok) {
|
|
318
|
-
return allowance.value;
|
|
298
|
+
if (!params) throw new Error("Params are required");
|
|
299
|
+
const allowance = await sodax.moneyMarket.isAllowanceValid(params, spokeProvider);
|
|
300
|
+
if (!allowance.ok) {
|
|
301
|
+
throw allowance.error;
|
|
319
302
|
}
|
|
320
|
-
return
|
|
321
|
-
}
|
|
322
|
-
enabled: !!spokeProvider
|
|
303
|
+
return allowance.value;
|
|
304
|
+
}
|
|
323
305
|
});
|
|
324
306
|
}
|
|
325
|
-
function useMMApprove(
|
|
307
|
+
function useMMApprove() {
|
|
326
308
|
const { sodax } = useSodaxContext();
|
|
327
309
|
const queryClient = useQueryClient();
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
isPending,
|
|
331
|
-
error,
|
|
332
|
-
reset: resetError
|
|
333
|
-
} = useMutation({
|
|
334
|
-
mutationFn: async ({ amount, action }) => {
|
|
310
|
+
return useMutation({
|
|
311
|
+
mutationFn: async ({ params, spokeProvider }) => {
|
|
335
312
|
if (!spokeProvider) {
|
|
336
313
|
throw new Error("Spoke provider not found");
|
|
337
314
|
}
|
|
338
|
-
const
|
|
339
|
-
const allowance = await sodax.moneyMarket.approve(
|
|
340
|
-
{
|
|
341
|
-
token: token.address,
|
|
342
|
-
amount: parseUnits(amount, actionBasedDecimals),
|
|
343
|
-
action
|
|
344
|
-
},
|
|
345
|
-
spokeProvider
|
|
346
|
-
);
|
|
315
|
+
const allowance = await sodax.moneyMarket.approve(params, spokeProvider, false);
|
|
347
316
|
if (!allowance.ok) {
|
|
348
|
-
throw
|
|
317
|
+
throw allowance.error;
|
|
349
318
|
}
|
|
350
|
-
return allowance.
|
|
319
|
+
return allowance.value;
|
|
351
320
|
},
|
|
352
|
-
onSuccess: () => {
|
|
353
|
-
|
|
321
|
+
onSuccess: (_, { params, spokeProvider }) => {
|
|
322
|
+
console.log("onSuccess invoked with queryKey:", [
|
|
323
|
+
"mm",
|
|
324
|
+
"allowance",
|
|
325
|
+
spokeProvider?.chainConfig.chain.id,
|
|
326
|
+
params.token,
|
|
327
|
+
params.action
|
|
328
|
+
]);
|
|
329
|
+
queryClient.invalidateQueries({
|
|
330
|
+
queryKey: ["mm", "allowance", spokeProvider?.chainConfig.chain.id, params.token, params.action]
|
|
331
|
+
});
|
|
354
332
|
}
|
|
355
333
|
});
|
|
356
|
-
return {
|
|
357
|
-
approve,
|
|
358
|
-
isLoading: isPending,
|
|
359
|
-
error,
|
|
360
|
-
resetError
|
|
361
|
-
};
|
|
362
334
|
}
|
|
363
|
-
function useAToken(aToken) {
|
|
335
|
+
function useAToken({ aToken, queryOptions }) {
|
|
364
336
|
const { sodax } = useSodaxContext();
|
|
337
|
+
const defaultQueryOptions = {
|
|
338
|
+
queryKey: ["mm", "aToken", aToken],
|
|
339
|
+
enabled: !!aToken
|
|
340
|
+
};
|
|
341
|
+
queryOptions = {
|
|
342
|
+
...defaultQueryOptions,
|
|
343
|
+
...queryOptions
|
|
344
|
+
// override default query options if provided
|
|
345
|
+
};
|
|
365
346
|
return useQuery({
|
|
366
|
-
|
|
347
|
+
...queryOptions,
|
|
367
348
|
queryFn: async () => {
|
|
368
349
|
if (!aToken) {
|
|
369
350
|
throw new Error("aToken address or hub provider is not defined");
|
|
370
351
|
}
|
|
352
|
+
if (!isAddress(aToken)) {
|
|
353
|
+
throw new Error("aToken address is not a valid address");
|
|
354
|
+
}
|
|
371
355
|
const aTokenData = await sodax.moneyMarket.data.getATokenData(aToken);
|
|
372
356
|
return {
|
|
373
357
|
...aTokenData,
|
|
374
358
|
xChainId: sodax.hubProvider.chainConfig.chain.id
|
|
375
359
|
};
|
|
376
|
-
}
|
|
377
|
-
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
function useATokensBalances({
|
|
364
|
+
aTokens,
|
|
365
|
+
spokeProvider,
|
|
366
|
+
userAddress,
|
|
367
|
+
queryOptions
|
|
368
|
+
}) {
|
|
369
|
+
const { sodax } = useSodaxContext();
|
|
370
|
+
const defaultQueryOptions = {
|
|
371
|
+
queryKey: ["mm", "aTokensBalances", aTokens, spokeProvider?.chainConfig.chain.id, userAddress],
|
|
372
|
+
enabled: aTokens.length > 0 && aTokens.every((token) => isAddress(token)) && !!spokeProvider && !!userAddress
|
|
373
|
+
};
|
|
374
|
+
queryOptions = {
|
|
375
|
+
...defaultQueryOptions,
|
|
376
|
+
...queryOptions
|
|
377
|
+
// override default query options if provided
|
|
378
|
+
};
|
|
379
|
+
return useQuery({
|
|
380
|
+
...queryOptions,
|
|
381
|
+
queryFn: async () => {
|
|
382
|
+
if (aTokens.length === 0) {
|
|
383
|
+
return /* @__PURE__ */ new Map();
|
|
384
|
+
}
|
|
385
|
+
if (!spokeProvider || !userAddress) {
|
|
386
|
+
throw new Error("Spoke provider and user address are required");
|
|
387
|
+
}
|
|
388
|
+
for (const aToken of aTokens) {
|
|
389
|
+
if (!isAddress(aToken)) {
|
|
390
|
+
throw new Error(`Invalid aToken address: ${aToken}`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
const hubWalletAddress = await deriveUserWalletAddress(
|
|
394
|
+
sodax.hubProvider,
|
|
395
|
+
spokeProvider.chainConfig.chain.id,
|
|
396
|
+
userAddress
|
|
397
|
+
);
|
|
398
|
+
return await sodax.moneyMarket.data.getATokensBalances(aTokens, hubWalletAddress);
|
|
399
|
+
}
|
|
378
400
|
});
|
|
379
401
|
}
|
|
380
|
-
function useReservesUsdFormat() {
|
|
402
|
+
function useReservesUsdFormat(params) {
|
|
381
403
|
const { sodax } = useSodaxContext();
|
|
404
|
+
const defaultQueryOptions = { queryKey: ["mm", "reservesUsdFormat"] };
|
|
405
|
+
const queryOptions = {
|
|
406
|
+
...defaultQueryOptions,
|
|
407
|
+
...params?.queryOptions
|
|
408
|
+
// override default query options if provided
|
|
409
|
+
};
|
|
382
410
|
return useQuery({
|
|
383
|
-
|
|
411
|
+
...queryOptions,
|
|
384
412
|
queryFn: async () => {
|
|
385
413
|
const reserves = await sodax.moneyMarket.data.getReservesHumanized();
|
|
386
414
|
return sodax.moneyMarket.data.formatReservesUSD(sodax.moneyMarket.data.buildReserveDataWithPrice(reserves));
|
|
387
415
|
}
|
|
388
416
|
});
|
|
389
417
|
}
|
|
418
|
+
function useUserFormattedSummary(params) {
|
|
419
|
+
const { sodax } = useSodaxContext();
|
|
420
|
+
const defaultQueryOptions = {
|
|
421
|
+
queryKey: ["mm", "userFormattedSummary", params?.spokeProvider?.chainConfig.chain.id, params?.address],
|
|
422
|
+
enabled: !!params?.spokeProvider && !!params?.address,
|
|
423
|
+
refetchInterval: 5e3
|
|
424
|
+
};
|
|
425
|
+
const queryOptions = {
|
|
426
|
+
...defaultQueryOptions,
|
|
427
|
+
...params?.queryOptions
|
|
428
|
+
// override default query options if provided
|
|
429
|
+
};
|
|
430
|
+
return useQuery({
|
|
431
|
+
...queryOptions,
|
|
432
|
+
queryFn: async () => {
|
|
433
|
+
if (!params?.spokeProvider || !params?.address) {
|
|
434
|
+
throw new Error("Spoke provider or address is not defined");
|
|
435
|
+
}
|
|
436
|
+
const reserves = await sodax.moneyMarket.data.getReservesHumanized();
|
|
437
|
+
const formattedReserves = sodax.moneyMarket.data.formatReservesUSD(
|
|
438
|
+
sodax.moneyMarket.data.buildReserveDataWithPrice(reserves)
|
|
439
|
+
);
|
|
440
|
+
const userReserves = await sodax.moneyMarket.data.getUserReservesHumanized(params?.spokeProvider);
|
|
441
|
+
return sodax.moneyMarket.data.formatUserSummary(
|
|
442
|
+
sodax.moneyMarket.data.buildUserSummaryRequest(reserves, formattedReserves, userReserves)
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
}
|
|
390
447
|
var useQuote = (payload) => {
|
|
391
448
|
const { sodax } = useSodaxContext();
|
|
392
449
|
const queryKey = useMemo(() => {
|
|
@@ -508,135 +565,254 @@ function useCancelSwap(spokeProvider) {
|
|
|
508
565
|
}
|
|
509
566
|
});
|
|
510
567
|
}
|
|
511
|
-
|
|
568
|
+
function useCreateLimitOrder(spokeProvider) {
|
|
512
569
|
const { sodax } = useSodaxContext();
|
|
570
|
+
return useMutation({
|
|
571
|
+
mutationFn: async (params) => {
|
|
572
|
+
if (!spokeProvider) {
|
|
573
|
+
throw new Error("Spoke provider not found");
|
|
574
|
+
}
|
|
575
|
+
return sodax.swaps.createLimitOrder({
|
|
576
|
+
intentParams: params,
|
|
577
|
+
spokeProvider
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
function useCancelLimitOrder() {
|
|
583
|
+
const { sodax } = useSodaxContext();
|
|
584
|
+
return useMutation({
|
|
585
|
+
mutationFn: async ({ intent, spokeProvider, timeout }) => {
|
|
586
|
+
return sodax.swaps.cancelLimitOrder({
|
|
587
|
+
intent,
|
|
588
|
+
spokeProvider,
|
|
589
|
+
timeout
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
var useBackendIntentByTxHash = (params) => {
|
|
595
|
+
const { sodax } = useSodaxContext();
|
|
596
|
+
const defaultQueryOptions = {
|
|
597
|
+
queryKey: ["api", "intent", "txHash", params?.params?.txHash],
|
|
598
|
+
enabled: !!params?.params?.txHash && params?.params?.txHash.length > 0,
|
|
599
|
+
retry: 3,
|
|
600
|
+
refetchInterval: 1e3
|
|
601
|
+
};
|
|
602
|
+
const queryOptions = {
|
|
603
|
+
...defaultQueryOptions,
|
|
604
|
+
...params?.queryOptions
|
|
605
|
+
};
|
|
513
606
|
return useQuery({
|
|
514
|
-
|
|
607
|
+
...queryOptions,
|
|
515
608
|
queryFn: async () => {
|
|
516
|
-
if (!txHash) {
|
|
609
|
+
if (!params?.params?.txHash) {
|
|
517
610
|
return void 0;
|
|
518
611
|
}
|
|
519
|
-
return sodax.backendApi.getIntentByTxHash(txHash);
|
|
520
|
-
}
|
|
521
|
-
refetchInterval,
|
|
522
|
-
enabled: !!txHash && txHash.length > 0,
|
|
523
|
-
retry: 3
|
|
612
|
+
return sodax.backendApi.getIntentByTxHash(params.params.txHash);
|
|
613
|
+
}
|
|
524
614
|
});
|
|
525
615
|
};
|
|
526
|
-
var useBackendIntentByHash = (
|
|
616
|
+
var useBackendIntentByHash = (params) => {
|
|
527
617
|
const { sodax } = useSodaxContext();
|
|
618
|
+
const defaultQueryOptions = {
|
|
619
|
+
queryKey: ["api", "intent", "hash", params?.params?.intentHash],
|
|
620
|
+
enabled: !!params?.params?.intentHash && params?.params?.intentHash.length > 0,
|
|
621
|
+
retry: 3
|
|
622
|
+
};
|
|
623
|
+
const queryOptions = {
|
|
624
|
+
...defaultQueryOptions,
|
|
625
|
+
...params?.queryOptions
|
|
626
|
+
};
|
|
528
627
|
return useQuery({
|
|
529
|
-
|
|
628
|
+
...queryOptions,
|
|
530
629
|
queryFn: async () => {
|
|
531
|
-
if (!intentHash) {
|
|
630
|
+
if (!params?.params?.intentHash) {
|
|
532
631
|
return void 0;
|
|
533
632
|
}
|
|
534
|
-
return sodax.backendApi.getIntentByHash(intentHash);
|
|
535
|
-
}
|
|
536
|
-
enabled: !!intentHash && intentHash.length > 0,
|
|
537
|
-
retry: 3
|
|
633
|
+
return sodax.backendApi.getIntentByHash(params.params.intentHash);
|
|
634
|
+
}
|
|
538
635
|
});
|
|
539
636
|
};
|
|
540
|
-
var
|
|
637
|
+
var useBackendUserIntents = ({
|
|
638
|
+
params,
|
|
639
|
+
queryOptions
|
|
640
|
+
}) => {
|
|
541
641
|
const { sodax } = useSodaxContext();
|
|
642
|
+
const defaultQueryOptions = {
|
|
643
|
+
queryKey: ["api", "intent", "user", params],
|
|
644
|
+
enabled: !!params && !!params.userAddress && params.userAddress.length > 0,
|
|
645
|
+
retry: 3
|
|
646
|
+
};
|
|
647
|
+
queryOptions = {
|
|
648
|
+
...defaultQueryOptions,
|
|
649
|
+
...queryOptions
|
|
650
|
+
// override default query options if provided
|
|
651
|
+
};
|
|
542
652
|
return useQuery({
|
|
543
|
-
|
|
653
|
+
...queryOptions,
|
|
544
654
|
queryFn: async () => {
|
|
545
|
-
if (!params
|
|
655
|
+
if (!params?.userAddress) {
|
|
546
656
|
return void 0;
|
|
547
657
|
}
|
|
548
|
-
return sodax.backendApi.
|
|
549
|
-
}
|
|
550
|
-
|
|
658
|
+
return sodax.backendApi.getUserIntents(params);
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
};
|
|
662
|
+
var useBackendOrderbook = (params) => {
|
|
663
|
+
const { sodax } = useSodaxContext();
|
|
664
|
+
const defaultQueryOptions = {
|
|
665
|
+
queryKey: ["api", "solver", "orderbook", params?.pagination?.offset, params?.pagination?.limit],
|
|
666
|
+
enabled: !!params?.pagination && !!params?.pagination.offset && !!params?.pagination.limit,
|
|
551
667
|
staleTime: 30 * 1e3,
|
|
552
668
|
// 30 seconds for real-time data
|
|
553
669
|
retry: 3
|
|
670
|
+
};
|
|
671
|
+
const queryOptions = {
|
|
672
|
+
...defaultQueryOptions,
|
|
673
|
+
...params?.queryOptions
|
|
674
|
+
// override default query options if provided
|
|
675
|
+
};
|
|
676
|
+
return useQuery({
|
|
677
|
+
...queryOptions,
|
|
678
|
+
queryFn: async () => {
|
|
679
|
+
if (!params?.pagination || !params?.pagination.offset || !params?.pagination.limit) {
|
|
680
|
+
return void 0;
|
|
681
|
+
}
|
|
682
|
+
return sodax.backendApi.getOrderbook(params.pagination);
|
|
683
|
+
}
|
|
554
684
|
});
|
|
555
685
|
};
|
|
556
|
-
var useBackendMoneyMarketPosition = (
|
|
686
|
+
var useBackendMoneyMarketPosition = (params) => {
|
|
557
687
|
const { sodax } = useSodaxContext();
|
|
688
|
+
const defaultQueryOptions = {
|
|
689
|
+
queryKey: ["api", "mm", "position", params?.userAddress],
|
|
690
|
+
enabled: !!params?.userAddress && params?.userAddress.length > 0,
|
|
691
|
+
retry: 3
|
|
692
|
+
};
|
|
693
|
+
const queryOptions = {
|
|
694
|
+
...defaultQueryOptions,
|
|
695
|
+
...params?.queryOptions
|
|
696
|
+
};
|
|
558
697
|
return useQuery({
|
|
559
|
-
|
|
698
|
+
...queryOptions,
|
|
560
699
|
queryFn: async () => {
|
|
561
|
-
if (!userAddress) {
|
|
700
|
+
if (!params?.userAddress) {
|
|
562
701
|
return void 0;
|
|
563
702
|
}
|
|
564
|
-
return sodax.backendApi.getMoneyMarketPosition(userAddress);
|
|
565
|
-
}
|
|
566
|
-
enabled: !!userAddress && userAddress.length > 0,
|
|
567
|
-
retry: 3
|
|
703
|
+
return sodax.backendApi.getMoneyMarketPosition(params.userAddress);
|
|
704
|
+
}
|
|
568
705
|
});
|
|
569
706
|
};
|
|
570
|
-
var useBackendAllMoneyMarketAssets = () => {
|
|
707
|
+
var useBackendAllMoneyMarketAssets = (params) => {
|
|
571
708
|
const { sodax } = useSodaxContext();
|
|
709
|
+
const defaultQueryOptions = {
|
|
710
|
+
queryKey: ["api", "mm", "assets", "all"],
|
|
711
|
+
enabled: true,
|
|
712
|
+
retry: 3
|
|
713
|
+
};
|
|
714
|
+
const queryOptions = {
|
|
715
|
+
...defaultQueryOptions,
|
|
716
|
+
...params?.queryOptions
|
|
717
|
+
};
|
|
572
718
|
return useQuery({
|
|
573
|
-
|
|
719
|
+
...queryOptions,
|
|
574
720
|
queryFn: async () => {
|
|
575
721
|
return sodax.backendApi.getAllMoneyMarketAssets();
|
|
576
|
-
}
|
|
577
|
-
retry: 3
|
|
722
|
+
}
|
|
578
723
|
});
|
|
579
724
|
};
|
|
580
|
-
var useBackendMoneyMarketAsset = (
|
|
725
|
+
var useBackendMoneyMarketAsset = (params) => {
|
|
581
726
|
const { sodax } = useSodaxContext();
|
|
727
|
+
const defaultQueryOptions = {
|
|
728
|
+
queryKey: ["api", "mm", "asset", params?.params?.reserveAddress],
|
|
729
|
+
enabled: !!params?.params?.reserveAddress && params?.params?.reserveAddress.length > 0,
|
|
730
|
+
retry: 3
|
|
731
|
+
};
|
|
732
|
+
const queryOptions = {
|
|
733
|
+
...defaultQueryOptions,
|
|
734
|
+
...params?.queryOptions
|
|
735
|
+
};
|
|
582
736
|
return useQuery({
|
|
583
|
-
|
|
737
|
+
...queryOptions,
|
|
584
738
|
queryFn: async () => {
|
|
585
|
-
if (!reserveAddress) {
|
|
739
|
+
if (!params?.params?.reserveAddress) {
|
|
586
740
|
return void 0;
|
|
587
741
|
}
|
|
588
|
-
return sodax.backendApi.getMoneyMarketAsset(reserveAddress);
|
|
589
|
-
}
|
|
590
|
-
enabled: !!reserveAddress && reserveAddress.length > 0,
|
|
591
|
-
retry: 3
|
|
742
|
+
return sodax.backendApi.getMoneyMarketAsset(params.params.reserveAddress);
|
|
743
|
+
}
|
|
592
744
|
});
|
|
593
745
|
};
|
|
594
746
|
var useBackendMoneyMarketAssetBorrowers = (params) => {
|
|
595
747
|
const { sodax } = useSodaxContext();
|
|
748
|
+
const defaultQueryOptions = {
|
|
749
|
+
queryKey: ["api", "mm", "asset", "borrowers", params],
|
|
750
|
+
enabled: !!params?.params?.reserveAddress && !!params.pagination.offset && !!params.pagination.limit,
|
|
751
|
+
retry: 3
|
|
752
|
+
};
|
|
753
|
+
const queryOptions = {
|
|
754
|
+
...defaultQueryOptions,
|
|
755
|
+
...params?.queryOptions
|
|
756
|
+
};
|
|
596
757
|
return useQuery({
|
|
597
|
-
|
|
758
|
+
...queryOptions,
|
|
598
759
|
queryFn: async () => {
|
|
599
|
-
if (!params
|
|
760
|
+
if (!params?.params?.reserveAddress || !params.pagination.offset || !params.pagination.limit) {
|
|
600
761
|
return void 0;
|
|
601
762
|
}
|
|
602
|
-
return sodax.backendApi.getMoneyMarketAssetBorrowers(params.reserveAddress, {
|
|
603
|
-
offset: params.offset,
|
|
604
|
-
limit: params.limit
|
|
763
|
+
return sodax.backendApi.getMoneyMarketAssetBorrowers(params.params.reserveAddress, {
|
|
764
|
+
offset: params.pagination.offset,
|
|
765
|
+
limit: params.pagination.limit
|
|
605
766
|
});
|
|
606
|
-
}
|
|
607
|
-
enabled: !!params.reserveAddress && !!params.offset && !!params.limit,
|
|
608
|
-
retry: 3
|
|
767
|
+
}
|
|
609
768
|
});
|
|
610
769
|
};
|
|
611
770
|
var useBackendMoneyMarketAssetSuppliers = (params) => {
|
|
612
771
|
const { sodax } = useSodaxContext();
|
|
772
|
+
const defaultQueryOptions = {
|
|
773
|
+
queryKey: ["api", "mm", "asset", "suppliers", params],
|
|
774
|
+
enabled: !!params?.params?.reserveAddress && !!params.pagination.offset && !!params.pagination.limit,
|
|
775
|
+
retry: 3
|
|
776
|
+
};
|
|
777
|
+
const queryOptions = {
|
|
778
|
+
...defaultQueryOptions,
|
|
779
|
+
...params?.queryOptions
|
|
780
|
+
};
|
|
613
781
|
return useQuery({
|
|
614
|
-
|
|
782
|
+
...queryOptions,
|
|
615
783
|
queryFn: async () => {
|
|
616
|
-
if (!params
|
|
784
|
+
if (!params?.params?.reserveAddress || !params.pagination.offset || !params.pagination.limit) {
|
|
617
785
|
return void 0;
|
|
618
786
|
}
|
|
619
|
-
return sodax.backendApi.getMoneyMarketAssetSuppliers(params.reserveAddress, {
|
|
620
|
-
offset: params.offset,
|
|
621
|
-
limit: params.limit
|
|
787
|
+
return sodax.backendApi.getMoneyMarketAssetSuppliers(params.params.reserveAddress, {
|
|
788
|
+
offset: params.pagination.offset,
|
|
789
|
+
limit: params.pagination.limit
|
|
622
790
|
});
|
|
623
|
-
}
|
|
624
|
-
enabled: !!params.reserveAddress && !!params.offset && !!params.limit,
|
|
625
|
-
retry: 3
|
|
791
|
+
}
|
|
626
792
|
});
|
|
627
793
|
};
|
|
628
794
|
var useBackendAllMoneyMarketBorrowers = (params) => {
|
|
629
795
|
const { sodax } = useSodaxContext();
|
|
796
|
+
const defaultQueryOptions = {
|
|
797
|
+
queryKey: ["api", "mm", "borrowers", "all", params],
|
|
798
|
+
enabled: !!params && !!params.pagination.offset && !!params.pagination.limit,
|
|
799
|
+
retry: 3
|
|
800
|
+
};
|
|
801
|
+
const queryOptions = {
|
|
802
|
+
...defaultQueryOptions,
|
|
803
|
+
...params?.queryOptions
|
|
804
|
+
};
|
|
630
805
|
return useQuery({
|
|
631
|
-
|
|
806
|
+
...queryOptions,
|
|
632
807
|
queryFn: async () => {
|
|
633
|
-
if (!params || !params.offset || !params.limit) {
|
|
808
|
+
if (!params || !params.pagination.offset || !params.pagination.limit) {
|
|
634
809
|
return void 0;
|
|
635
810
|
}
|
|
636
|
-
return sodax.backendApi.getAllMoneyMarketBorrowers(
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
811
|
+
return sodax.backendApi.getAllMoneyMarketBorrowers({
|
|
812
|
+
offset: params.pagination.offset,
|
|
813
|
+
limit: params.pagination.limit
|
|
814
|
+
});
|
|
815
|
+
}
|
|
640
816
|
});
|
|
641
817
|
};
|
|
642
818
|
function useBridgeAllowance(params, spokeProvider) {
|
|
@@ -1279,6 +1455,6 @@ var SodaxProvider = ({ children, testnet = false, config, rpcConfig }) => {
|
|
|
1279
1455
|
return /* @__PURE__ */ React.createElement(SodaxContext.Provider, { value: { sodax, testnet, rpcConfig } }, children);
|
|
1280
1456
|
};
|
|
1281
1457
|
|
|
1282
|
-
export { MIGRATION_MODE_BNUSD, MIGRATION_MODE_ICX_SODA, SodaxProvider, useAToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelSwap, useCancelUnstake, useClaim, useConvertedAssets, useDeriveUserWalletAddress, useEstimateGas, useGetBridgeableAmount, useGetBridgeableTokens, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useMMAllowance, useMMApprove, useMigrate, useMigrationAllowance, useMigrationApprove, useQuote, useRepay, useRequestTrustline, useReservesData, useReservesUsdFormat, useSodaxContext, useSpokeProvider, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSwap, useSwapAllowance, useSwapApprove, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserReservesData, useWithdraw };
|
|
1458
|
+
export { MIGRATION_MODE_BNUSD, MIGRATION_MODE_ICX_SODA, SodaxProvider, useAToken, useATokensBalances, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useConvertedAssets, useCreateLimitOrder, useDeriveUserWalletAddress, useEstimateGas, useGetBridgeableAmount, useGetBridgeableTokens, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useMMAllowance, useMMApprove, useMigrate, useMigrationAllowance, useMigrationApprove, useQuote, useRepay, useRequestTrustline, useReservesData, useReservesUsdFormat, useSodaxContext, useSpokeProvider, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSwap, useSwapAllowance, useSwapApprove, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw };
|
|
1283
1459
|
//# sourceMappingURL=index.mjs.map
|
|
1284
1460
|
//# sourceMappingURL=index.mjs.map
|