@sodax/dapp-kit 1.5.6-beta → 2.0.0-rc.1
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 +300 -422
- package/ai-exported/AGENTS.md +134 -0
- package/ai-exported/integration/README.md +49 -0
- package/ai-exported/integration/ai-rules.md +79 -0
- package/ai-exported/integration/architecture.md +274 -0
- package/ai-exported/integration/features/README.md +29 -0
- package/ai-exported/integration/features/auxiliary-services.md +169 -0
- package/ai-exported/integration/features/bitcoin.md +87 -0
- package/ai-exported/integration/features/bridge.md +91 -0
- package/ai-exported/integration/features/dex.md +152 -0
- package/ai-exported/integration/features/migration.md +118 -0
- package/ai-exported/integration/features/money-market.md +116 -0
- package/ai-exported/integration/features/staking.md +123 -0
- package/ai-exported/integration/features/swap.md +101 -0
- package/ai-exported/integration/quickstart.md +187 -0
- package/ai-exported/integration/recipes/README.md +136 -0
- package/ai-exported/integration/recipes/backend-queries.md +157 -0
- package/ai-exported/integration/recipes/bitcoin.md +193 -0
- package/ai-exported/integration/recipes/bridge.md +174 -0
- package/ai-exported/integration/recipes/dex.md +204 -0
- package/ai-exported/integration/recipes/invalidations.md +115 -0
- package/ai-exported/integration/recipes/migration.md +212 -0
- package/ai-exported/integration/recipes/money-market.md +206 -0
- package/ai-exported/integration/recipes/mutation-error-handling.md +118 -0
- package/ai-exported/integration/recipes/observability.md +93 -0
- package/ai-exported/integration/recipes/setup.md +144 -0
- package/ai-exported/integration/recipes/staking.md +202 -0
- package/ai-exported/integration/recipes/swap.md +272 -0
- package/ai-exported/integration/recipes/wallet-connectivity.md +101 -0
- package/ai-exported/integration/reference/README.md +12 -0
- package/ai-exported/integration/reference/glossary.md +188 -0
- package/ai-exported/integration/reference/hooks-index.md +194 -0
- package/ai-exported/integration/reference/public-api.md +110 -0
- package/ai-exported/integration/reference/querykey-conventions.md +179 -0
- package/ai-exported/migration/README.md +60 -0
- package/ai-exported/migration/ai-rules.md +81 -0
- package/ai-exported/migration/breaking-changes/hook-signatures.md +233 -0
- package/ai-exported/migration/breaking-changes/querykey-conventions.md +108 -0
- package/ai-exported/migration/breaking-changes/result-handling.md +211 -0
- package/ai-exported/migration/breaking-changes/sdk-leakage.md +165 -0
- package/ai-exported/migration/checklist.md +89 -0
- package/ai-exported/migration/features/README.md +34 -0
- package/ai-exported/migration/features/auxiliary-services.md +114 -0
- package/ai-exported/migration/features/bitcoin.md +88 -0
- package/ai-exported/migration/features/bridge.md +123 -0
- package/ai-exported/migration/features/dex.md +101 -0
- package/ai-exported/migration/features/migration.md +120 -0
- package/ai-exported/migration/features/money-market.md +97 -0
- package/ai-exported/migration/features/staking.md +109 -0
- package/ai-exported/migration/features/swap.md +118 -0
- package/ai-exported/migration/recipes.md +188 -0
- package/ai-exported/migration/reference/README.md +15 -0
- package/ai-exported/migration/reference/deleted-hooks.md +110 -0
- package/ai-exported/migration/reference/error-shape-crosswalk.md +144 -0
- package/ai-exported/migration/reference/renamed-hooks.md +66 -0
- package/dist/index.cjs +2642 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1550 -0
- package/dist/index.d.ts +1020 -2051
- package/dist/index.mjs +1594 -1532
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -10
- package/src/contexts/index.ts +0 -3
- package/src/hooks/_mutationContract.test.ts +99 -0
- package/src/hooks/backend/README.md +2 -2
- package/src/hooks/backend/index.ts +13 -13
- package/src/hooks/backend/unwrapResult.ts +1 -0
- package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +13 -45
- package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +29 -59
- package/src/hooks/backend/useBackendIntentByHash.ts +21 -47
- package/src/hooks/backend/useBackendIntentByTxHash.ts +23 -50
- package/src/hooks/backend/useBackendMoneyMarketAsset.ts +21 -54
- package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +30 -57
- package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +31 -58
- package/src/hooks/backend/useBackendMoneyMarketPosition.ts +22 -38
- package/src/hooks/backend/useBackendOrderbook.ts +27 -49
- package/src/hooks/backend/useBackendSubmitSwapTx.ts +30 -36
- package/src/hooks/backend/useBackendSubmitSwapTxStatus.ts +38 -58
- package/src/hooks/backend/useBackendUserIntents.ts +25 -63
- package/src/hooks/bitcoin/index.ts +9 -8
- package/src/hooks/bitcoin/useBitcoinBalance.ts +20 -5
- package/src/hooks/bitcoin/useExpiredUtxos.ts +26 -16
- package/src/hooks/bitcoin/useFundTradingWallet.ts +33 -30
- package/src/hooks/bitcoin/useRadfiAuth.ts +43 -40
- package/src/hooks/bitcoin/useRadfiSession.ts +53 -59
- package/src/hooks/bitcoin/useRadfiWithdraw.ts +35 -53
- package/src/hooks/bitcoin/useRenewUtxos.ts +30 -50
- package/src/hooks/bitcoin/useTradingWallet.ts +1 -1
- package/src/hooks/bitcoin/useTradingWalletBalance.ts +25 -14
- package/src/hooks/bridge/index.ts +5 -5
- package/src/hooks/bridge/useBridge.ts +29 -55
- package/src/hooks/bridge/useBridgeAllowance.ts +38 -38
- package/src/hooks/bridge/useBridgeApprove.ts +32 -57
- package/src/hooks/bridge/useGetBridgeableAmount.ts +23 -37
- package/src/hooks/bridge/useGetBridgeableTokens.ts +27 -50
- package/src/hooks/dex/index.ts +16 -16
- package/src/hooks/dex/useClaimRewards.ts +35 -54
- package/src/hooks/dex/useCreateDecreaseLiquidityParams.ts +7 -20
- package/src/hooks/dex/useCreateDepositParams.ts +7 -21
- package/src/hooks/dex/useCreateSupplyLiquidityParams.ts +13 -28
- package/src/hooks/dex/useCreateWithdrawParams.ts +7 -20
- package/src/hooks/dex/useDecreaseLiquidity.ts +40 -66
- package/src/hooks/dex/useDexAllowance.ts +29 -75
- package/src/hooks/dex/useDexApprove.ts +32 -43
- package/src/hooks/dex/useDexDeposit.ts +42 -49
- package/src/hooks/dex/useDexWithdraw.ts +32 -43
- package/src/hooks/dex/useLiquidityAmounts.ts +27 -84
- package/src/hooks/dex/usePoolBalances.ts +50 -72
- package/src/hooks/dex/usePoolData.ts +17 -43
- package/src/hooks/dex/usePools.ts +11 -38
- package/src/hooks/dex/usePositionInfo.ts +27 -62
- package/src/hooks/dex/useSupplyLiquidity.ts +80 -75
- package/src/hooks/index.ts +12 -10
- package/src/hooks/migrate/index.ts +13 -4
- package/src/hooks/migrate/useMigrateBaln.ts +42 -0
- package/src/hooks/migrate/useMigrateIcxToSoda.ts +44 -0
- package/src/hooks/migrate/useMigratebnUSD.ts +47 -0
- package/src/hooks/migrate/useMigrationAllowance.ts +76 -0
- package/src/hooks/migrate/useMigrationApprove.ts +66 -0
- package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +39 -0
- package/src/hooks/mm/index.ts +14 -12
- package/src/hooks/mm/useAToken.ts +25 -41
- package/src/hooks/mm/useATokensBalances.ts +29 -60
- package/src/hooks/mm/useBorrow.ts +38 -56
- package/src/hooks/mm/useMMAllowance.ts +37 -73
- package/src/hooks/mm/useMMApprove.ts +36 -43
- package/src/hooks/mm/useRepay.ts +33 -53
- package/src/hooks/mm/useReservesData.ts +12 -38
- package/src/hooks/mm/useReservesHumanized.ts +12 -31
- package/src/hooks/mm/useReservesList.ts +11 -31
- package/src/hooks/mm/useReservesUsdFormat.ts +15 -35
- package/src/hooks/mm/useSupply.ts +45 -51
- package/src/hooks/mm/useUserFormattedSummary.ts +32 -84
- package/src/hooks/mm/useUserReservesData.ts +27 -77
- package/src/hooks/mm/useWithdraw.ts +38 -54
- package/src/hooks/partner/index.ts +6 -0
- package/src/hooks/partner/useApproveToken.ts +42 -0
- package/src/hooks/partner/useFeeClaimSwap.ts +38 -0
- package/src/hooks/partner/useFetchAssetsBalances.ts +37 -0
- package/src/hooks/partner/useGetAutoSwapPreferences.ts +37 -0
- package/src/hooks/partner/useIsTokenApproved.ts +39 -0
- package/src/hooks/partner/useSetSwapPreference.ts +50 -0
- package/src/hooks/provider/index.ts +1 -2
- package/src/hooks/provider/useHubProvider.ts +1 -1
- package/src/hooks/recovery/index.ts +2 -0
- package/src/hooks/recovery/useHubAssetBalances.ts +43 -0
- package/src/hooks/recovery/useWithdrawHubAsset.ts +48 -0
- package/src/hooks/shared/index.ts +10 -6
- package/src/hooks/shared/types.ts +77 -0
- package/src/hooks/shared/unwrapResult.ts +19 -0
- package/src/hooks/shared/useDeriveUserWalletAddress.ts +22 -40
- package/src/hooks/shared/useEstimateGas.ts +18 -15
- package/src/hooks/shared/useGetUserHubWalletAddress.ts +25 -26
- package/src/hooks/shared/useRequestTrustline.ts +28 -61
- package/src/hooks/shared/useSafeMutation.test.ts +43 -0
- package/src/hooks/shared/useSafeMutation.ts +68 -0
- package/src/hooks/shared/useSodaxContext.ts +1 -1
- package/src/hooks/shared/useStellarTrustlineCheck.ts +30 -64
- package/src/hooks/shared/useXBalances.test.ts +113 -0
- package/src/hooks/shared/useXBalances.ts +61 -0
- package/src/hooks/staking/index.ts +18 -18
- package/src/hooks/staking/useCancelUnstake.ts +30 -41
- package/src/hooks/staking/useClaim.ts +27 -36
- package/src/hooks/staking/useConvertedAssets.ts +24 -34
- package/src/hooks/staking/useInstantUnstake.ts +33 -40
- package/src/hooks/staking/useInstantUnstakeAllowance.ts +37 -45
- package/src/hooks/staking/useInstantUnstakeApprove.ts +42 -42
- package/src/hooks/staking/useInstantUnstakeRatio.ts +24 -41
- package/src/hooks/staking/useStake.ts +32 -37
- package/src/hooks/staking/useStakeAllowance.ts +30 -43
- package/src/hooks/staking/useStakeApprove.ts +40 -40
- package/src/hooks/staking/useStakeRatio.ts +24 -40
- package/src/hooks/staking/useStakingConfig.ts +14 -27
- package/src/hooks/staking/useStakingInfo.ts +30 -38
- package/src/hooks/staking/useUnstake.ts +29 -43
- package/src/hooks/staking/useUnstakeAllowance.ts +37 -44
- package/src/hooks/staking/useUnstakeApprove.ts +40 -43
- package/src/hooks/staking/useUnstakingInfo.ts +29 -41
- package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +31 -47
- package/src/hooks/swap/index.ts +8 -8
- package/src/hooks/swap/useCancelLimitOrder.ts +24 -41
- package/src/hooks/swap/useCancelSwap.ts +24 -33
- package/src/hooks/swap/useCreateLimitOrder.ts +29 -62
- package/src/hooks/swap/useQuote.ts +17 -43
- package/src/hooks/swap/useStatus.ts +22 -29
- package/src/hooks/swap/useSwap.ts +31 -49
- package/src/hooks/swap/useSwapAllowance.ts +38 -35
- package/src/hooks/swap/useSwapApprove.ts +48 -57
- package/src/index.ts +5 -3
- package/src/providers/SodaxProvider.tsx +17 -11
- package/src/providers/createSodaxQueryClient.ts +96 -0
- package/src/providers/index.ts +2 -1
- package/src/utils/dex-utils.ts +27 -5
- package/src/utils/index.ts +1 -1
- package/dist/index.d.mts +0 -2581
- package/dist/index.js +0 -2562
- package/dist/index.js.map +0 -1
- package/src/hooks/migrate/types.ts +0 -15
- package/src/hooks/migrate/useMigrate.tsx +0 -110
- package/src/hooks/migrate/useMigrationAllowance.tsx +0 -79
- package/src/hooks/migrate/useMigrationApprove.tsx +0 -129
- package/src/hooks/provider/useSpokeProvider.ts +0 -172
|
@@ -1,70 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
import { useQuery, type UseQueryOptions, type UseQueryResult } from '@tanstack/react-query';
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
2
|
import type { MoneyMarketAsset } from '@sodax/sdk';
|
|
4
|
-
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from './unwrapResult.js';
|
|
5
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
5
6
|
|
|
6
|
-
export type UseBackendMoneyMarketAssetParams =
|
|
7
|
-
|
|
7
|
+
export type UseBackendMoneyMarketAssetParams = ReadHookParams<
|
|
8
|
+
MoneyMarketAsset | undefined,
|
|
9
|
+
{
|
|
8
10
|
reserveAddress: string | undefined;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
};
|
|
11
|
+
}
|
|
12
|
+
>;
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* React hook to fetch a specific money market asset from the backend API.
|
|
15
16
|
*
|
|
16
|
-
* @param params - The hook input parameter object (may be undefined):
|
|
17
|
-
* - `params`: An object containing:
|
|
18
|
-
* - `reserveAddress` (string | undefined): Reserve contract address to fetch asset details. Disables query if undefined or empty.
|
|
19
|
-
* - `queryOptions` (optional): React Query options for advanced configuration (e.g. caching, staleTime, retry, etc.).
|
|
20
|
-
*
|
|
21
|
-
* @returns A React Query result object: {@link UseQueryResult} for {@link MoneyMarketAsset} or `undefined` on error or if disabled,
|
|
22
|
-
* including:
|
|
23
|
-
* - `data`: The money market asset (when available) or `undefined`.
|
|
24
|
-
* - `isLoading`: Whether the query is running.
|
|
25
|
-
* - `error`: An error encountered by the query (if any).
|
|
26
|
-
* - `refetch`: Function to manually refetch the asset.
|
|
27
|
-
*
|
|
28
17
|
* @example
|
|
29
|
-
* const { data: asset
|
|
30
|
-
* params: { reserveAddress: '0xabc...' },
|
|
31
|
-
* });
|
|
32
|
-
* if (isLoading) return <div>Loading asset...</div>;
|
|
33
|
-
* if (error) return <div>Error: {error.message}</div>;
|
|
34
|
-
* if (asset) {
|
|
35
|
-
* console.log('Asset symbol:', asset.symbol);
|
|
36
|
-
* console.log('Liquidity rate:', asset.liquidityRate);
|
|
37
|
-
* console.log('Variable borrow rate:', asset.variableBorrowRate);
|
|
38
|
-
* }
|
|
39
|
-
*
|
|
40
|
-
* @remarks
|
|
41
|
-
* - Query is disabled if `params`, `params.params`, or `params.params.reserveAddress` is missing or empty.
|
|
42
|
-
* - Uses React Query for caching and background-state management.
|
|
43
|
-
* - Loading and error handling are managed automatically.
|
|
18
|
+
* const { data: asset } = useBackendMoneyMarketAsset({ params: { reserveAddress: '0xabc...' } });
|
|
44
19
|
*/
|
|
45
|
-
export const useBackendMoneyMarketAsset = (
|
|
46
|
-
params
|
|
47
|
-
|
|
20
|
+
export const useBackendMoneyMarketAsset = ({
|
|
21
|
+
params,
|
|
22
|
+
queryOptions,
|
|
23
|
+
}: UseBackendMoneyMarketAssetParams = {}): UseQueryResult<MoneyMarketAsset | undefined, Error> => {
|
|
48
24
|
const { sodax } = useSodaxContext();
|
|
49
|
-
|
|
50
|
-
const defaultQueryOptions = {
|
|
51
|
-
queryKey: ['api', 'mm', 'asset', params?.params?.reserveAddress],
|
|
52
|
-
enabled: !!params?.params?.reserveAddress && params?.params?.reserveAddress.length > 0,
|
|
53
|
-
retry: 3,
|
|
54
|
-
};
|
|
55
|
-
const queryOptions = {
|
|
56
|
-
...defaultQueryOptions,
|
|
57
|
-
...params?.queryOptions,
|
|
58
|
-
};
|
|
25
|
+
const reserveAddress = params?.reserveAddress;
|
|
59
26
|
|
|
60
27
|
return useQuery({
|
|
61
|
-
|
|
28
|
+
queryKey: ['backend', 'mm', 'asset', reserveAddress],
|
|
62
29
|
queryFn: async (): Promise<MoneyMarketAsset | undefined> => {
|
|
63
|
-
if (!
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return sodax.backendApi.getMoneyMarketAsset(params.params.reserveAddress);
|
|
30
|
+
if (!reserveAddress) return undefined;
|
|
31
|
+
return unwrapResult(await sodax.backendApi.getMoneyMarketAsset(reserveAddress));
|
|
68
32
|
},
|
|
33
|
+
enabled: !!reserveAddress && reserveAddress.length > 0,
|
|
34
|
+
retry: 3,
|
|
35
|
+
...queryOptions,
|
|
69
36
|
});
|
|
70
37
|
};
|
|
@@ -1,76 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
import { useQuery, type UseQueryOptions, type UseQueryResult } from '@tanstack/react-query';
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
2
|
import type { MoneyMarketAssetBorrowers } from '@sodax/sdk';
|
|
4
|
-
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
|
-
import
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from './unwrapResult.js';
|
|
5
|
+
import type { BackendPaginationParams } from './types.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
6
7
|
|
|
7
|
-
export type UseBackendMoneyMarketAssetBorrowersParams =
|
|
8
|
-
|
|
8
|
+
export type UseBackendMoneyMarketAssetBorrowersParams = ReadHookParams<
|
|
9
|
+
MoneyMarketAssetBorrowers | undefined,
|
|
10
|
+
{
|
|
9
11
|
reserveAddress: string | undefined;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
12
|
+
pagination: BackendPaginationParams;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* React hook for fetching borrowers for a specific money market asset from the backend API with pagination.
|
|
17
18
|
*
|
|
18
|
-
* @param {UseBackendMoneyMarketAssetBorrowersParams | undefined} params - Query parameters:
|
|
19
|
-
* - `params`: Object containing:
|
|
20
|
-
* - `reserveAddress`: Reserve contract address for which to fetch borrowers, or `undefined` to disable query.
|
|
21
|
-
* - `pagination`: Pagination controls with `offset` and `limit` (both required as strings).
|
|
22
|
-
* - `queryOptions` (optional): React Query options to override defaults (e.g. `staleTime`, `enabled`, etc.).
|
|
23
|
-
*
|
|
24
|
-
* @returns {UseQueryResult<MoneyMarketAssetBorrowers | undefined, Error>} React Query result object including:
|
|
25
|
-
* - `data`: The money market asset borrowers data, or `undefined` if not available.
|
|
26
|
-
* - `isLoading`: Boolean indicating whether the query is loading.
|
|
27
|
-
* - `error`: An Error instance if the request failed.
|
|
28
|
-
* - `refetch`: Function to manually trigger a data refresh.
|
|
29
|
-
*
|
|
30
19
|
* @example
|
|
31
|
-
* const { data: borrowers
|
|
32
|
-
* params: { reserveAddress: '0xabc...' },
|
|
33
|
-
* pagination: { offset: '0', limit: '20' }
|
|
20
|
+
* const { data: borrowers } = useBackendMoneyMarketAssetBorrowers({
|
|
21
|
+
* params: { reserveAddress: '0xabc...', pagination: { offset: '0', limit: '20' } },
|
|
34
22
|
* });
|
|
35
|
-
*
|
|
36
|
-
* if (isLoading) return <div>Loading borrowers...</div>;
|
|
37
|
-
* if (error) return <div>Error: {error.message}</div>;
|
|
38
|
-
* if (borrowers) {
|
|
39
|
-
* console.log('Total borrowers:', borrowers.total);
|
|
40
|
-
* console.log('Borrowers:', borrowers.borrowers);
|
|
41
|
-
* }
|
|
42
|
-
*
|
|
43
|
-
* @remarks
|
|
44
|
-
* - The query is disabled if `reserveAddress`, `offset`, or `limit` are not provided.
|
|
45
|
-
* - Uses React Query for caching, retries, and auto error/loading management.
|
|
46
|
-
* - Pagination is handled via `pagination.offset` and `pagination.limit`.
|
|
47
23
|
*/
|
|
48
|
-
export const useBackendMoneyMarketAssetBorrowers = (
|
|
49
|
-
params
|
|
50
|
-
|
|
24
|
+
export const useBackendMoneyMarketAssetBorrowers = ({
|
|
25
|
+
params,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: UseBackendMoneyMarketAssetBorrowersParams = {}): UseQueryResult<MoneyMarketAssetBorrowers | undefined, Error> => {
|
|
51
28
|
const { sodax } = useSodaxContext();
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
queryKey: ['api', 'mm', 'asset', 'borrowers', params],
|
|
55
|
-
enabled: !!params?.params?.reserveAddress && !!params.pagination.offset && !!params.pagination.limit,
|
|
56
|
-
retry: 3,
|
|
57
|
-
};
|
|
58
|
-
const queryOptions = {
|
|
59
|
-
...defaultQueryOptions,
|
|
60
|
-
...params?.queryOptions,
|
|
61
|
-
};
|
|
29
|
+
const reserveAddress = params?.reserveAddress;
|
|
30
|
+
const pagination = params?.pagination;
|
|
62
31
|
|
|
63
32
|
return useQuery({
|
|
64
|
-
|
|
33
|
+
queryKey: ['backend', 'mm', 'asset', 'borrowers', reserveAddress, pagination],
|
|
65
34
|
queryFn: async (): Promise<MoneyMarketAssetBorrowers | undefined> => {
|
|
66
|
-
if (!
|
|
35
|
+
if (!reserveAddress || !pagination?.offset || !pagination?.limit) {
|
|
67
36
|
return undefined;
|
|
68
37
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
38
|
+
return unwrapResult(
|
|
39
|
+
await sodax.backendApi.getMoneyMarketAssetBorrowers(reserveAddress, {
|
|
40
|
+
offset: pagination.offset,
|
|
41
|
+
limit: pagination.limit,
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
74
44
|
},
|
|
45
|
+
enabled: !!reserveAddress && !!pagination?.offset && !!pagination?.limit,
|
|
46
|
+
retry: 3,
|
|
47
|
+
...queryOptions,
|
|
75
48
|
});
|
|
76
49
|
};
|
|
@@ -1,76 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
import { useQuery, type UseQueryOptions, type UseQueryResult } from '@tanstack/react-query';
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
2
|
import type { MoneyMarketAssetSuppliers } from '@sodax/sdk';
|
|
4
|
-
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
|
-
import
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from './unwrapResult.js';
|
|
5
|
+
import type { BackendPaginationParams } from './types.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
6
7
|
|
|
7
|
-
export type UseBackendMoneyMarketAssetSuppliersParams =
|
|
8
|
-
|
|
8
|
+
export type UseBackendMoneyMarketAssetSuppliersParams = ReadHookParams<
|
|
9
|
+
MoneyMarketAssetSuppliers | undefined,
|
|
10
|
+
{
|
|
9
11
|
reserveAddress: string | undefined;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
12
|
+
pagination: BackendPaginationParams;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
|
-
* React hook for fetching suppliers for a specific money market asset from the backend API
|
|
17
|
-
*
|
|
18
|
-
* @param {UseBackendMoneyMarketAssetSuppliersParams | undefined} params - Hook parameters:
|
|
19
|
-
* - `params`: Object containing:
|
|
20
|
-
* - `reserveAddress`: The reserve contract address to query, or undefined to disable the query.
|
|
21
|
-
* - `pagination`: Backend pagination controls (`offset` and `limit` as strings).
|
|
22
|
-
* - `queryOptions` (optional): React Query options to override defaults.
|
|
23
|
-
*
|
|
24
|
-
* @returns {UseQueryResult<MoneyMarketAssetSuppliers | undefined, Error>} - Query result object with:
|
|
25
|
-
* - `data`: The asset suppliers data when available.
|
|
26
|
-
* - `isLoading`: Indicates if the request is in progress.
|
|
27
|
-
* - `error`: Error object if the request failed.
|
|
28
|
-
* - `refetch`: Function to trigger a manual data refresh.
|
|
17
|
+
* React hook for fetching suppliers for a specific money market asset from the backend API.
|
|
29
18
|
*
|
|
30
19
|
* @example
|
|
31
|
-
* const { data: suppliers
|
|
32
|
-
* params: { reserveAddress: '0xabc...' },
|
|
33
|
-
* pagination: { offset: '0', limit: '20' }
|
|
20
|
+
* const { data: suppliers } = useBackendMoneyMarketAssetSuppliers({
|
|
21
|
+
* params: { reserveAddress: '0xabc...', pagination: { offset: '0', limit: '20' } },
|
|
34
22
|
* });
|
|
35
|
-
*
|
|
36
|
-
* if (isLoading) return <div>Loading suppliers...</div>;
|
|
37
|
-
* if (error) return <div>Error: {error.message}</div>;
|
|
38
|
-
* if (suppliers) {
|
|
39
|
-
* console.log('Total suppliers:', suppliers.total);
|
|
40
|
-
* console.log('Suppliers:', suppliers.suppliers);
|
|
41
|
-
* }
|
|
42
|
-
*
|
|
43
|
-
* @remarks
|
|
44
|
-
* - The query is disabled if `reserveAddress`, `offset`, or `limit` are not provided.
|
|
45
|
-
* - Uses React Query for efficient caching, automatic retries, and error/loading handling.
|
|
46
|
-
* - Pagination is handled via `pagination.offset` and `pagination.limit`.
|
|
47
23
|
*/
|
|
48
|
-
export const useBackendMoneyMarketAssetSuppliers = (
|
|
49
|
-
params
|
|
50
|
-
|
|
24
|
+
export const useBackendMoneyMarketAssetSuppliers = ({
|
|
25
|
+
params,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: UseBackendMoneyMarketAssetSuppliersParams = {}): UseQueryResult<MoneyMarketAssetSuppliers | undefined, Error> => {
|
|
51
28
|
const { sodax } = useSodaxContext();
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
queryKey: ['api', 'mm', 'asset', 'suppliers', params],
|
|
55
|
-
enabled: !!params?.params?.reserveAddress && !!params.pagination.offset && !!params.pagination.limit,
|
|
56
|
-
retry: 3,
|
|
57
|
-
};
|
|
58
|
-
const queryOptions = {
|
|
59
|
-
...defaultQueryOptions,
|
|
60
|
-
...params?.queryOptions,
|
|
61
|
-
};
|
|
29
|
+
const reserveAddress = params?.reserveAddress;
|
|
30
|
+
const pagination = params?.pagination;
|
|
62
31
|
|
|
63
32
|
return useQuery({
|
|
64
|
-
|
|
33
|
+
queryKey: ['backend', 'mm', 'asset', 'suppliers', reserveAddress, pagination],
|
|
65
34
|
queryFn: async (): Promise<MoneyMarketAssetSuppliers | undefined> => {
|
|
66
|
-
if (!
|
|
35
|
+
if (!reserveAddress || !pagination?.offset || !pagination?.limit) {
|
|
67
36
|
return undefined;
|
|
68
37
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
38
|
+
return unwrapResult(
|
|
39
|
+
await sodax.backendApi.getMoneyMarketAssetSuppliers(reserveAddress, {
|
|
40
|
+
offset: pagination.offset,
|
|
41
|
+
limit: pagination.limit,
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
74
44
|
},
|
|
45
|
+
enabled: !!reserveAddress && !!pagination?.offset && !!pagination?.limit,
|
|
46
|
+
retry: 3,
|
|
47
|
+
...queryOptions,
|
|
75
48
|
});
|
|
76
49
|
};
|
|
@@ -1,53 +1,37 @@
|
|
|
1
|
-
import { useQuery, type
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
2
|
import type { MoneyMarketPosition } from '@sodax/sdk';
|
|
3
|
-
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from './unwrapResult.js';
|
|
5
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
4
6
|
|
|
5
|
-
export type UseBackendMoneyMarketPositionParams =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export type UseBackendMoneyMarketPositionParams = ReadHookParams<
|
|
8
|
+
MoneyMarketPosition | undefined,
|
|
9
|
+
{
|
|
10
|
+
userAddress: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
>;
|
|
9
13
|
|
|
10
14
|
/**
|
|
11
15
|
* React hook for fetching a user's money market position from the backend API.
|
|
12
16
|
*
|
|
13
|
-
* @param {UseBackendMoneyMarketPositionParams | undefined} params - Parameters object:
|
|
14
|
-
* - userAddress: The user's wallet address to fetch positions for. If undefined or empty, the query is disabled.
|
|
15
|
-
* - queryOptions: (Optional) React Query options to customize behavior (e.g., staleTime, enabled).
|
|
16
|
-
*
|
|
17
|
-
* @returns {UseQueryResult<MoneyMarketPosition | undefined, Error>} - React Query result object with:
|
|
18
|
-
* - data: The user's money market position data, or undefined if not available.
|
|
19
|
-
* - isLoading: Loading state.
|
|
20
|
-
* - error: An Error instance if fetching failed.
|
|
21
|
-
* - refetch: Function to manually trigger a refetch.
|
|
22
|
-
*
|
|
23
17
|
* @example
|
|
24
|
-
* const { data
|
|
25
|
-
* userAddress: '0xabc...',
|
|
26
|
-
* queryOptions: { staleTime: 60000 },
|
|
27
|
-
* });
|
|
18
|
+
* const { data } = useBackendMoneyMarketPosition({ params: { userAddress: '0xabc...' } });
|
|
28
19
|
*/
|
|
29
|
-
export const useBackendMoneyMarketPosition = (
|
|
30
|
-
params
|
|
31
|
-
|
|
20
|
+
export const useBackendMoneyMarketPosition = ({
|
|
21
|
+
params,
|
|
22
|
+
queryOptions,
|
|
23
|
+
}: UseBackendMoneyMarketPositionParams = {}): UseQueryResult<MoneyMarketPosition | undefined, Error> => {
|
|
32
24
|
const { sodax } = useSodaxContext();
|
|
33
|
-
|
|
34
|
-
const defaultQueryOptions = {
|
|
35
|
-
queryKey: ['api', 'mm', 'position', params?.userAddress],
|
|
36
|
-
enabled: !!params?.userAddress && params?.userAddress.length > 0,
|
|
37
|
-
retry: 3,
|
|
38
|
-
};
|
|
39
|
-
const queryOptions = {
|
|
40
|
-
...defaultQueryOptions,
|
|
41
|
-
...params?.queryOptions,
|
|
42
|
-
};
|
|
25
|
+
const userAddress = params?.userAddress;
|
|
43
26
|
|
|
44
27
|
return useQuery({
|
|
45
|
-
|
|
28
|
+
queryKey: ['backend', 'mm', 'position', userAddress],
|
|
46
29
|
queryFn: async (): Promise<MoneyMarketPosition | undefined> => {
|
|
47
|
-
if (!
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
return sodax.backendApi.getMoneyMarketPosition(params.userAddress);
|
|
30
|
+
if (!userAddress) return undefined;
|
|
31
|
+
return unwrapResult(await sodax.backendApi.getMoneyMarketPosition(userAddress));
|
|
51
32
|
},
|
|
33
|
+
enabled: !!userAddress && userAddress.length > 0,
|
|
34
|
+
retry: 3,
|
|
35
|
+
...queryOptions,
|
|
52
36
|
});
|
|
53
37
|
};
|
|
@@ -1,63 +1,41 @@
|
|
|
1
|
-
import { useQuery, type
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
2
|
import type { OrderbookResponse } from '@sodax/sdk';
|
|
3
|
-
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
4
|
-
import
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from './unwrapResult.js';
|
|
5
|
+
import type { BackendPaginationParams } from './types.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
5
7
|
|
|
6
|
-
export type UseBackendOrderbookParams =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export type UseBackendOrderbookParams = ReadHookParams<
|
|
9
|
+
OrderbookResponse,
|
|
10
|
+
{
|
|
11
|
+
pagination: BackendPaginationParams;
|
|
12
|
+
}
|
|
13
|
+
>;
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
16
|
* Hook for fetching the solver orderbook from the backend API.
|
|
13
17
|
*
|
|
14
|
-
* @param {UseBackendOrderbookParams | undefined} params - Optional parameters:
|
|
15
|
-
* - `pagination`: Pagination configuration (see `BackendPaginationParams`), including
|
|
16
|
-
* `offset` and `limit` (both required for fetch to be enabled).
|
|
17
|
-
* - `queryOptions`: Optional React Query options to override default behavior.
|
|
18
|
-
*
|
|
19
|
-
* @returns {UseQueryResult<OrderbookResponse | undefined, Error>} React Query result object:
|
|
20
|
-
* - `data`: The orderbook response, or undefined if unavailable.
|
|
21
|
-
* - `isLoading`: Loading state.
|
|
22
|
-
* - `error`: Error instance if the query failed.
|
|
23
|
-
* - `refetch`: Function to re-trigger the query.
|
|
24
|
-
*
|
|
25
18
|
* @example
|
|
26
|
-
* const { data
|
|
27
|
-
* pagination: { offset: '0', limit: '10' },
|
|
28
|
-
* queryOptions: { staleTime: 60000 },
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* @remarks
|
|
32
|
-
* - Query is disabled if `params?.pagination`, `offset`, or `limit` are missing/empty.
|
|
33
|
-
* - Caches and manages server state using React Query.
|
|
34
|
-
* - Default `staleTime` is 30 seconds to support near-real-time updates.
|
|
19
|
+
* const { data } = useBackendOrderbook({ params: { pagination: { offset: '0', limit: '10' } } });
|
|
35
20
|
*/
|
|
36
|
-
export const useBackendOrderbook = (
|
|
37
|
-
params
|
|
38
|
-
|
|
21
|
+
export const useBackendOrderbook = ({
|
|
22
|
+
params,
|
|
23
|
+
queryOptions,
|
|
24
|
+
}: UseBackendOrderbookParams = {}): UseQueryResult<OrderbookResponse> => {
|
|
39
25
|
const { sodax } = useSodaxContext();
|
|
26
|
+
const pagination = params?.pagination;
|
|
40
27
|
|
|
41
|
-
|
|
42
|
-
queryKey: ['
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const queryOptions = {
|
|
49
|
-
...defaultQueryOptions,
|
|
50
|
-
...params?.queryOptions, // override default query options if provided
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return useQuery({
|
|
54
|
-
...queryOptions,
|
|
55
|
-
queryFn: async (): Promise<OrderbookResponse | undefined> => {
|
|
56
|
-
if (!params?.pagination || !params?.pagination.offset || !params?.pagination.limit) {
|
|
57
|
-
return undefined;
|
|
28
|
+
return useQuery<OrderbookResponse, Error>({
|
|
29
|
+
queryKey: ['backend', 'orderbook', pagination?.offset, pagination?.limit],
|
|
30
|
+
queryFn: async (): Promise<OrderbookResponse> => {
|
|
31
|
+
if (!pagination?.offset || !pagination?.limit) {
|
|
32
|
+
throw new Error('Pagination offset and limit are required');
|
|
58
33
|
}
|
|
59
|
-
|
|
60
|
-
return sodax.backendApi.getOrderbook(params.pagination);
|
|
34
|
+
return unwrapResult(await sodax.backendApi.getOrderbook(pagination));
|
|
61
35
|
},
|
|
36
|
+
enabled: !!pagination?.offset && !!pagination?.limit,
|
|
37
|
+
staleTime: 30 * 1000,
|
|
38
|
+
retry: 3,
|
|
39
|
+
...queryOptions,
|
|
62
40
|
});
|
|
63
41
|
};
|
|
@@ -1,55 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
import type { SubmitSwapTxRequest, SubmitSwapTxResponse } from '@sodax/
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
// packages/dapp-kit/src/hooks/backend/useBackendSubmitSwapTx.ts
|
|
2
|
+
import type { RequestOverrideConfig, SubmitSwapTxRequest, SubmitSwapTxResponse } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from './unwrapResult.js';
|
|
5
|
+
import type { MutationHookParams } from '../shared/types.js';
|
|
6
|
+
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Mutation variables for {@link useBackendSubmitSwapTx}. The per-request `apiConfig` override
|
|
10
|
+
* (e.g. base URL) belongs here rather than at the hook level — different submissions in the same
|
|
11
|
+
* component can target different endpoints without re-rendering.
|
|
12
|
+
*/
|
|
13
|
+
export type UseBackendSubmitSwapTxVars = {
|
|
14
|
+
request: SubmitSwapTxRequest;
|
|
7
15
|
apiConfig?: RequestOverrideConfig;
|
|
8
|
-
mutationOptions?: UseMutationOptions<SubmitSwapTxResponse, Error, SubmitSwapTxRequest>;
|
|
9
16
|
};
|
|
10
17
|
|
|
11
18
|
/**
|
|
12
|
-
* React hook for submitting a swap transaction to be processed by the backend
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @param {UseBackendSubmitSwapTxParams | undefined} params - Optional parameters:
|
|
16
|
-
* - `mutationOptions`: React Query mutation options to customize behavior (e.g., onSuccess, onError, retry).
|
|
19
|
+
* React hook for submitting a swap transaction to be processed by the backend (relay, post
|
|
20
|
+
* execution to solver, etc.).
|
|
17
21
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* - `data`: The submit response on success.
|
|
21
|
-
* - `isPending`: Loading state.
|
|
22
|
-
* - `error`: Error instance if the mutation failed.
|
|
22
|
+
* Pure mutation: pass `{ request, apiConfig? }` to `mutate({...})`. Default `retry: 3` is applied
|
|
23
|
+
* at the hook level — consumers can override via `mutationOptions.retry`.
|
|
23
24
|
*
|
|
24
25
|
* @example
|
|
25
26
|
* const { mutateAsync: submitSwapTx, isPending, error } = useBackendSubmitSwapTx();
|
|
26
27
|
*
|
|
27
28
|
* const result = await submitSwapTx({
|
|
28
|
-
* txHash: '0x123...',
|
|
29
|
-
*
|
|
30
|
-
* walletAddress: '0xabc...',
|
|
31
|
-
* intent: { ... },
|
|
32
|
-
* relayData: '0x...',
|
|
29
|
+
* request: { txHash: '0x123...', srcChainKey: 'sonic', walletAddress: '0xabc...', intent: { ... }, relayData: '0x...' },
|
|
30
|
+
* apiConfig: { baseURL: 'https://...' },
|
|
33
31
|
* });
|
|
34
32
|
*/
|
|
35
|
-
export const useBackendSubmitSwapTx = (
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
export const useBackendSubmitSwapTx = ({
|
|
34
|
+
mutationOptions,
|
|
35
|
+
}: MutationHookParams<SubmitSwapTxResponse, UseBackendSubmitSwapTxVars> = {}): SafeUseMutationResult<
|
|
36
|
+
SubmitSwapTxResponse,
|
|
37
|
+
Error,
|
|
38
|
+
UseBackendSubmitSwapTxVars
|
|
39
|
+
> => {
|
|
38
40
|
const { sodax } = useSodaxContext();
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
return useSafeMutation<SubmitSwapTxResponse, Error, UseBackendSubmitSwapTxVars>({
|
|
43
|
+
mutationKey: ['backend', 'submitSwapTx'],
|
|
41
44
|
retry: 3,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const mutationOptions = {
|
|
45
|
-
...defaultMutationOptions,
|
|
46
|
-
...params?.mutationOptions,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return useMutation({
|
|
50
45
|
...mutationOptions,
|
|
51
|
-
mutationFn: async (request
|
|
52
|
-
|
|
53
|
-
},
|
|
46
|
+
mutationFn: async ({ request, apiConfig }): Promise<SubmitSwapTxResponse> =>
|
|
47
|
+
unwrapResult(await sodax.backendApi.submitSwapTx(request, apiConfig)),
|
|
54
48
|
});
|
|
55
49
|
};
|