@sodax/dapp-kit 1.0.1-beta → 1.0.2-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 +541 -347
- package/dist/index.d.ts +541 -347
- package/dist/index.js +317 -176
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +315 -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 +1 -0
- package/src/hooks/mm/useAToken.ts +37 -20
- 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,236 @@ 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
|
-
enabled: !!aToken
|
|
360
|
+
}
|
|
378
361
|
});
|
|
379
362
|
}
|
|
380
|
-
function useReservesUsdFormat() {
|
|
363
|
+
function useReservesUsdFormat(params) {
|
|
381
364
|
const { sodax } = useSodaxContext();
|
|
365
|
+
const defaultQueryOptions = { queryKey: ["mm", "reservesUsdFormat"] };
|
|
366
|
+
const queryOptions = {
|
|
367
|
+
...defaultQueryOptions,
|
|
368
|
+
...params?.queryOptions
|
|
369
|
+
// override default query options if provided
|
|
370
|
+
};
|
|
382
371
|
return useQuery({
|
|
383
|
-
|
|
372
|
+
...queryOptions,
|
|
384
373
|
queryFn: async () => {
|
|
385
374
|
const reserves = await sodax.moneyMarket.data.getReservesHumanized();
|
|
386
375
|
return sodax.moneyMarket.data.formatReservesUSD(sodax.moneyMarket.data.buildReserveDataWithPrice(reserves));
|
|
387
376
|
}
|
|
388
377
|
});
|
|
389
378
|
}
|
|
379
|
+
function useUserFormattedSummary(params) {
|
|
380
|
+
const { sodax } = useSodaxContext();
|
|
381
|
+
const defaultQueryOptions = {
|
|
382
|
+
queryKey: ["mm", "userFormattedSummary", params?.spokeProvider?.chainConfig.chain.id, params?.address],
|
|
383
|
+
enabled: !!params?.spokeProvider && !!params?.address,
|
|
384
|
+
refetchInterval: 5e3
|
|
385
|
+
};
|
|
386
|
+
const queryOptions = {
|
|
387
|
+
...defaultQueryOptions,
|
|
388
|
+
...params?.queryOptions
|
|
389
|
+
// override default query options if provided
|
|
390
|
+
};
|
|
391
|
+
return useQuery({
|
|
392
|
+
...queryOptions,
|
|
393
|
+
queryFn: async () => {
|
|
394
|
+
if (!params?.spokeProvider || !params?.address) {
|
|
395
|
+
throw new Error("Spoke provider or address is not defined");
|
|
396
|
+
}
|
|
397
|
+
const reserves = await sodax.moneyMarket.data.getReservesHumanized();
|
|
398
|
+
const formattedReserves = sodax.moneyMarket.data.formatReservesUSD(
|
|
399
|
+
sodax.moneyMarket.data.buildReserveDataWithPrice(reserves)
|
|
400
|
+
);
|
|
401
|
+
const userReserves = await sodax.moneyMarket.data.getUserReservesHumanized(params?.spokeProvider);
|
|
402
|
+
return sodax.moneyMarket.data.formatUserSummary(
|
|
403
|
+
sodax.moneyMarket.data.buildUserSummaryRequest(reserves, formattedReserves, userReserves)
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}
|
|
390
408
|
var useQuote = (payload) => {
|
|
391
409
|
const { sodax } = useSodaxContext();
|
|
392
410
|
const queryKey = useMemo(() => {
|
|
@@ -508,135 +526,254 @@ function useCancelSwap(spokeProvider) {
|
|
|
508
526
|
}
|
|
509
527
|
});
|
|
510
528
|
}
|
|
511
|
-
|
|
529
|
+
function useCreateLimitOrder(spokeProvider) {
|
|
512
530
|
const { sodax } = useSodaxContext();
|
|
531
|
+
return useMutation({
|
|
532
|
+
mutationFn: async (params) => {
|
|
533
|
+
if (!spokeProvider) {
|
|
534
|
+
throw new Error("Spoke provider not found");
|
|
535
|
+
}
|
|
536
|
+
return sodax.swaps.createLimitOrder({
|
|
537
|
+
intentParams: params,
|
|
538
|
+
spokeProvider
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
function useCancelLimitOrder() {
|
|
544
|
+
const { sodax } = useSodaxContext();
|
|
545
|
+
return useMutation({
|
|
546
|
+
mutationFn: async ({ intent, spokeProvider, timeout }) => {
|
|
547
|
+
return sodax.swaps.cancelLimitOrder({
|
|
548
|
+
intent,
|
|
549
|
+
spokeProvider,
|
|
550
|
+
timeout
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
var useBackendIntentByTxHash = (params) => {
|
|
556
|
+
const { sodax } = useSodaxContext();
|
|
557
|
+
const defaultQueryOptions = {
|
|
558
|
+
queryKey: ["api", "intent", "txHash", params?.params?.txHash],
|
|
559
|
+
enabled: !!params?.params?.txHash && params?.params?.txHash.length > 0,
|
|
560
|
+
retry: 3,
|
|
561
|
+
refetchInterval: 1e3
|
|
562
|
+
};
|
|
563
|
+
const queryOptions = {
|
|
564
|
+
...defaultQueryOptions,
|
|
565
|
+
...params?.queryOptions
|
|
566
|
+
};
|
|
513
567
|
return useQuery({
|
|
514
|
-
|
|
568
|
+
...queryOptions,
|
|
515
569
|
queryFn: async () => {
|
|
516
|
-
if (!txHash) {
|
|
570
|
+
if (!params?.params?.txHash) {
|
|
517
571
|
return void 0;
|
|
518
572
|
}
|
|
519
|
-
return sodax.backendApi.getIntentByTxHash(txHash);
|
|
520
|
-
}
|
|
521
|
-
refetchInterval,
|
|
522
|
-
enabled: !!txHash && txHash.length > 0,
|
|
523
|
-
retry: 3
|
|
573
|
+
return sodax.backendApi.getIntentByTxHash(params.params.txHash);
|
|
574
|
+
}
|
|
524
575
|
});
|
|
525
576
|
};
|
|
526
|
-
var useBackendIntentByHash = (
|
|
577
|
+
var useBackendIntentByHash = (params) => {
|
|
527
578
|
const { sodax } = useSodaxContext();
|
|
579
|
+
const defaultQueryOptions = {
|
|
580
|
+
queryKey: ["api", "intent", "hash", params?.params?.intentHash],
|
|
581
|
+
enabled: !!params?.params?.intentHash && params?.params?.intentHash.length > 0,
|
|
582
|
+
retry: 3
|
|
583
|
+
};
|
|
584
|
+
const queryOptions = {
|
|
585
|
+
...defaultQueryOptions,
|
|
586
|
+
...params?.queryOptions
|
|
587
|
+
};
|
|
528
588
|
return useQuery({
|
|
529
|
-
|
|
589
|
+
...queryOptions,
|
|
530
590
|
queryFn: async () => {
|
|
531
|
-
if (!intentHash) {
|
|
591
|
+
if (!params?.params?.intentHash) {
|
|
532
592
|
return void 0;
|
|
533
593
|
}
|
|
534
|
-
return sodax.backendApi.getIntentByHash(intentHash);
|
|
535
|
-
}
|
|
536
|
-
enabled: !!intentHash && intentHash.length > 0,
|
|
537
|
-
retry: 3
|
|
594
|
+
return sodax.backendApi.getIntentByHash(params.params.intentHash);
|
|
595
|
+
}
|
|
538
596
|
});
|
|
539
597
|
};
|
|
540
|
-
var
|
|
598
|
+
var useBackendUserIntents = ({
|
|
599
|
+
params,
|
|
600
|
+
queryOptions
|
|
601
|
+
}) => {
|
|
541
602
|
const { sodax } = useSodaxContext();
|
|
603
|
+
const defaultQueryOptions = {
|
|
604
|
+
queryKey: ["api", "intent", "user", params],
|
|
605
|
+
enabled: !!params && !!params.userAddress && params.userAddress.length > 0,
|
|
606
|
+
retry: 3
|
|
607
|
+
};
|
|
608
|
+
queryOptions = {
|
|
609
|
+
...defaultQueryOptions,
|
|
610
|
+
...queryOptions
|
|
611
|
+
// override default query options if provided
|
|
612
|
+
};
|
|
542
613
|
return useQuery({
|
|
543
|
-
|
|
614
|
+
...queryOptions,
|
|
544
615
|
queryFn: async () => {
|
|
545
|
-
if (!params
|
|
616
|
+
if (!params?.userAddress) {
|
|
546
617
|
return void 0;
|
|
547
618
|
}
|
|
548
|
-
return sodax.backendApi.
|
|
549
|
-
}
|
|
550
|
-
|
|
619
|
+
return sodax.backendApi.getUserIntents(params);
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
};
|
|
623
|
+
var useBackendOrderbook = (params) => {
|
|
624
|
+
const { sodax } = useSodaxContext();
|
|
625
|
+
const defaultQueryOptions = {
|
|
626
|
+
queryKey: ["api", "solver", "orderbook", params?.pagination?.offset, params?.pagination?.limit],
|
|
627
|
+
enabled: !!params?.pagination && !!params?.pagination.offset && !!params?.pagination.limit,
|
|
551
628
|
staleTime: 30 * 1e3,
|
|
552
629
|
// 30 seconds for real-time data
|
|
553
630
|
retry: 3
|
|
631
|
+
};
|
|
632
|
+
const queryOptions = {
|
|
633
|
+
...defaultQueryOptions,
|
|
634
|
+
...params?.queryOptions
|
|
635
|
+
// override default query options if provided
|
|
636
|
+
};
|
|
637
|
+
return useQuery({
|
|
638
|
+
...queryOptions,
|
|
639
|
+
queryFn: async () => {
|
|
640
|
+
if (!params?.pagination || !params?.pagination.offset || !params?.pagination.limit) {
|
|
641
|
+
return void 0;
|
|
642
|
+
}
|
|
643
|
+
return sodax.backendApi.getOrderbook(params.pagination);
|
|
644
|
+
}
|
|
554
645
|
});
|
|
555
646
|
};
|
|
556
|
-
var useBackendMoneyMarketPosition = (
|
|
647
|
+
var useBackendMoneyMarketPosition = (params) => {
|
|
557
648
|
const { sodax } = useSodaxContext();
|
|
649
|
+
const defaultQueryOptions = {
|
|
650
|
+
queryKey: ["api", "mm", "position", params?.userAddress],
|
|
651
|
+
enabled: !!params?.userAddress && params?.userAddress.length > 0,
|
|
652
|
+
retry: 3
|
|
653
|
+
};
|
|
654
|
+
const queryOptions = {
|
|
655
|
+
...defaultQueryOptions,
|
|
656
|
+
...params?.queryOptions
|
|
657
|
+
};
|
|
558
658
|
return useQuery({
|
|
559
|
-
|
|
659
|
+
...queryOptions,
|
|
560
660
|
queryFn: async () => {
|
|
561
|
-
if (!userAddress) {
|
|
661
|
+
if (!params?.userAddress) {
|
|
562
662
|
return void 0;
|
|
563
663
|
}
|
|
564
|
-
return sodax.backendApi.getMoneyMarketPosition(userAddress);
|
|
565
|
-
}
|
|
566
|
-
enabled: !!userAddress && userAddress.length > 0,
|
|
567
|
-
retry: 3
|
|
664
|
+
return sodax.backendApi.getMoneyMarketPosition(params.userAddress);
|
|
665
|
+
}
|
|
568
666
|
});
|
|
569
667
|
};
|
|
570
|
-
var useBackendAllMoneyMarketAssets = () => {
|
|
668
|
+
var useBackendAllMoneyMarketAssets = (params) => {
|
|
571
669
|
const { sodax } = useSodaxContext();
|
|
670
|
+
const defaultQueryOptions = {
|
|
671
|
+
queryKey: ["api", "mm", "assets", "all"],
|
|
672
|
+
enabled: true,
|
|
673
|
+
retry: 3
|
|
674
|
+
};
|
|
675
|
+
const queryOptions = {
|
|
676
|
+
...defaultQueryOptions,
|
|
677
|
+
...params?.queryOptions
|
|
678
|
+
};
|
|
572
679
|
return useQuery({
|
|
573
|
-
|
|
680
|
+
...queryOptions,
|
|
574
681
|
queryFn: async () => {
|
|
575
682
|
return sodax.backendApi.getAllMoneyMarketAssets();
|
|
576
|
-
}
|
|
577
|
-
retry: 3
|
|
683
|
+
}
|
|
578
684
|
});
|
|
579
685
|
};
|
|
580
|
-
var useBackendMoneyMarketAsset = (
|
|
686
|
+
var useBackendMoneyMarketAsset = (params) => {
|
|
581
687
|
const { sodax } = useSodaxContext();
|
|
688
|
+
const defaultQueryOptions = {
|
|
689
|
+
queryKey: ["api", "mm", "asset", params?.params?.reserveAddress],
|
|
690
|
+
enabled: !!params?.params?.reserveAddress && params?.params?.reserveAddress.length > 0,
|
|
691
|
+
retry: 3
|
|
692
|
+
};
|
|
693
|
+
const queryOptions = {
|
|
694
|
+
...defaultQueryOptions,
|
|
695
|
+
...params?.queryOptions
|
|
696
|
+
};
|
|
582
697
|
return useQuery({
|
|
583
|
-
|
|
698
|
+
...queryOptions,
|
|
584
699
|
queryFn: async () => {
|
|
585
|
-
if (!reserveAddress) {
|
|
700
|
+
if (!params?.params?.reserveAddress) {
|
|
586
701
|
return void 0;
|
|
587
702
|
}
|
|
588
|
-
return sodax.backendApi.getMoneyMarketAsset(reserveAddress);
|
|
589
|
-
}
|
|
590
|
-
enabled: !!reserveAddress && reserveAddress.length > 0,
|
|
591
|
-
retry: 3
|
|
703
|
+
return sodax.backendApi.getMoneyMarketAsset(params.params.reserveAddress);
|
|
704
|
+
}
|
|
592
705
|
});
|
|
593
706
|
};
|
|
594
707
|
var useBackendMoneyMarketAssetBorrowers = (params) => {
|
|
595
708
|
const { sodax } = useSodaxContext();
|
|
709
|
+
const defaultQueryOptions = {
|
|
710
|
+
queryKey: ["api", "mm", "asset", "borrowers", params],
|
|
711
|
+
enabled: !!params?.params?.reserveAddress && !!params.pagination.offset && !!params.pagination.limit,
|
|
712
|
+
retry: 3
|
|
713
|
+
};
|
|
714
|
+
const queryOptions = {
|
|
715
|
+
...defaultQueryOptions,
|
|
716
|
+
...params?.queryOptions
|
|
717
|
+
};
|
|
596
718
|
return useQuery({
|
|
597
|
-
|
|
719
|
+
...queryOptions,
|
|
598
720
|
queryFn: async () => {
|
|
599
|
-
if (!params
|
|
721
|
+
if (!params?.params?.reserveAddress || !params.pagination.offset || !params.pagination.limit) {
|
|
600
722
|
return void 0;
|
|
601
723
|
}
|
|
602
|
-
return sodax.backendApi.getMoneyMarketAssetBorrowers(params.reserveAddress, {
|
|
603
|
-
offset: params.offset,
|
|
604
|
-
limit: params.limit
|
|
724
|
+
return sodax.backendApi.getMoneyMarketAssetBorrowers(params.params.reserveAddress, {
|
|
725
|
+
offset: params.pagination.offset,
|
|
726
|
+
limit: params.pagination.limit
|
|
605
727
|
});
|
|
606
|
-
}
|
|
607
|
-
enabled: !!params.reserveAddress && !!params.offset && !!params.limit,
|
|
608
|
-
retry: 3
|
|
728
|
+
}
|
|
609
729
|
});
|
|
610
730
|
};
|
|
611
731
|
var useBackendMoneyMarketAssetSuppliers = (params) => {
|
|
612
732
|
const { sodax } = useSodaxContext();
|
|
733
|
+
const defaultQueryOptions = {
|
|
734
|
+
queryKey: ["api", "mm", "asset", "suppliers", params],
|
|
735
|
+
enabled: !!params?.params?.reserveAddress && !!params.pagination.offset && !!params.pagination.limit,
|
|
736
|
+
retry: 3
|
|
737
|
+
};
|
|
738
|
+
const queryOptions = {
|
|
739
|
+
...defaultQueryOptions,
|
|
740
|
+
...params?.queryOptions
|
|
741
|
+
};
|
|
613
742
|
return useQuery({
|
|
614
|
-
|
|
743
|
+
...queryOptions,
|
|
615
744
|
queryFn: async () => {
|
|
616
|
-
if (!params
|
|
745
|
+
if (!params?.params?.reserveAddress || !params.pagination.offset || !params.pagination.limit) {
|
|
617
746
|
return void 0;
|
|
618
747
|
}
|
|
619
|
-
return sodax.backendApi.getMoneyMarketAssetSuppliers(params.reserveAddress, {
|
|
620
|
-
offset: params.offset,
|
|
621
|
-
limit: params.limit
|
|
748
|
+
return sodax.backendApi.getMoneyMarketAssetSuppliers(params.params.reserveAddress, {
|
|
749
|
+
offset: params.pagination.offset,
|
|
750
|
+
limit: params.pagination.limit
|
|
622
751
|
});
|
|
623
|
-
}
|
|
624
|
-
enabled: !!params.reserveAddress && !!params.offset && !!params.limit,
|
|
625
|
-
retry: 3
|
|
752
|
+
}
|
|
626
753
|
});
|
|
627
754
|
};
|
|
628
755
|
var useBackendAllMoneyMarketBorrowers = (params) => {
|
|
629
756
|
const { sodax } = useSodaxContext();
|
|
757
|
+
const defaultQueryOptions = {
|
|
758
|
+
queryKey: ["api", "mm", "borrowers", "all", params],
|
|
759
|
+
enabled: !!params && !!params.pagination.offset && !!params.pagination.limit,
|
|
760
|
+
retry: 3
|
|
761
|
+
};
|
|
762
|
+
const queryOptions = {
|
|
763
|
+
...defaultQueryOptions,
|
|
764
|
+
...params?.queryOptions
|
|
765
|
+
};
|
|
630
766
|
return useQuery({
|
|
631
|
-
|
|
767
|
+
...queryOptions,
|
|
632
768
|
queryFn: async () => {
|
|
633
|
-
if (!params || !params.offset || !params.limit) {
|
|
769
|
+
if (!params || !params.pagination.offset || !params.pagination.limit) {
|
|
634
770
|
return void 0;
|
|
635
771
|
}
|
|
636
|
-
return sodax.backendApi.getAllMoneyMarketBorrowers(
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
772
|
+
return sodax.backendApi.getAllMoneyMarketBorrowers({
|
|
773
|
+
offset: params.pagination.offset,
|
|
774
|
+
limit: params.pagination.limit
|
|
775
|
+
});
|
|
776
|
+
}
|
|
640
777
|
});
|
|
641
778
|
};
|
|
642
779
|
function useBridgeAllowance(params, spokeProvider) {
|
|
@@ -1279,6 +1416,6 @@ var SodaxProvider = ({ children, testnet = false, config, rpcConfig }) => {
|
|
|
1279
1416
|
return /* @__PURE__ */ React.createElement(SodaxContext.Provider, { value: { sodax, testnet, rpcConfig } }, children);
|
|
1280
1417
|
};
|
|
1281
1418
|
|
|
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 };
|
|
1419
|
+
export { MIGRATION_MODE_BNUSD, MIGRATION_MODE_ICX_SODA, SodaxProvider, useAToken, 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
1420
|
//# sourceMappingURL=index.mjs.map
|
|
1284
1421
|
//# sourceMappingURL=index.mjs.map
|