@sodax/dapp-kit 0.0.1-rc.9 → 1.0.0-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/LICENSE +21 -0
- package/README.md +157 -58
- package/dist/index.d.mts +1558 -0
- package/dist/index.d.ts +1558 -4
- package/dist/index.js +1025 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +983 -89
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -8
- package/src/contexts/index.ts +3 -2
- package/src/hooks/backend/README.md +135 -0
- package/src/hooks/backend/index.ts +23 -0
- package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +49 -0
- package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +61 -0
- package/src/hooks/backend/useBackendIntentByHash.ts +53 -0
- package/src/hooks/backend/useBackendIntentByTxHash.ts +57 -0
- package/src/hooks/backend/useBackendMoneyMarketAsset.ts +57 -0
- package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +67 -0
- package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +67 -0
- package/src/hooks/backend/useBackendMoneyMarketPosition.ts +56 -0
- package/src/hooks/backend/useBackendOrderbook.ts +63 -0
- package/src/hooks/bridge/index.ts +5 -0
- package/src/hooks/bridge/useBridge.ts +57 -0
- package/src/hooks/bridge/useBridgeAllowance.ts +49 -0
- package/src/hooks/bridge/useBridgeApprove.ts +68 -0
- package/src/hooks/bridge/useGetBridgeableAmount.ts +50 -0
- package/src/hooks/bridge/useGetBridgeableTokens.ts +62 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/migrate/index.ts +4 -0
- package/src/hooks/migrate/types.ts +15 -0
- package/src/hooks/migrate/useMigrate.tsx +110 -0
- package/src/hooks/migrate/useMigrationAllowance.tsx +79 -0
- package/src/hooks/migrate/useMigrationApprove.tsx +129 -0
- package/src/hooks/mm/index.ts +2 -0
- package/src/hooks/mm/useAToken.ts +47 -0
- package/src/hooks/mm/useMMAllowance.ts +2 -1
- package/src/hooks/mm/useMMApprove.ts +2 -1
- package/src/hooks/mm/useReservesData.ts +1 -8
- package/src/hooks/mm/useReservesHumanized.ts +30 -0
- package/src/hooks/mm/useReservesList.ts +29 -0
- package/src/hooks/mm/useReservesUsdFormat.ts +38 -0
- package/src/hooks/mm/useUserFormattedSummary.ts +54 -0
- package/src/hooks/mm/useUserReservesData.ts +30 -31
- package/src/hooks/provider/useHubProvider.ts +3 -3
- package/src/hooks/provider/useSpokeProvider.ts +45 -21
- package/src/hooks/shared/index.ts +4 -0
- package/src/hooks/shared/useDeriveUserWalletAddress.ts +44 -0
- package/src/hooks/shared/useEstimateGas.ts +18 -0
- package/src/hooks/shared/useRequestTrustline.ts +103 -0
- package/src/hooks/shared/useStellarTrustlineCheck.ts +71 -0
- package/src/hooks/staking/index.ts +19 -0
- package/src/hooks/staking/useCancelUnstake.ts +52 -0
- package/src/hooks/staking/useClaim.ts +46 -0
- package/src/hooks/staking/useConvertedAssets.ts +47 -0
- package/src/hooks/staking/useInstantUnstake.ts +50 -0
- package/src/hooks/staking/useInstantUnstakeAllowance.ts +59 -0
- package/src/hooks/staking/useInstantUnstakeApprove.ts +52 -0
- package/src/hooks/staking/useInstantUnstakeRatio.ts +54 -0
- package/src/hooks/staking/useStake.ts +47 -0
- package/src/hooks/staking/useStakeAllowance.ts +57 -0
- package/src/hooks/staking/useStakeApprove.ts +50 -0
- package/src/hooks/staking/useStakeRatio.ts +53 -0
- package/src/hooks/staking/useStakingConfig.ts +40 -0
- package/src/hooks/staking/useStakingInfo.ts +50 -0
- package/src/hooks/staking/useUnstake.ts +54 -0
- package/src/hooks/staking/useUnstakeAllowance.ts +58 -0
- package/src/hooks/staking/useUnstakeApprove.ts +52 -0
- package/src/hooks/staking/useUnstakingInfo.ts +53 -0
- package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +59 -0
- package/src/hooks/swap/index.ts +2 -1
- package/src/hooks/swap/useCancelSwap.ts +44 -0
- package/src/hooks/swap/useQuote.ts +16 -2
- package/src/hooks/swap/useStatus.ts +1 -1
- package/src/hooks/swap/{useCreateIntentOrder.ts → useSwap.ts} +16 -11
- package/src/hooks/swap/useSwapAllowance.ts +5 -1
- package/src/hooks/swap/useSwapApprove.ts +14 -14
- package/src/index.ts +0 -1
- package/src/providers/SodaxProvider.tsx +8 -20
- package/dist/contexts/index.d.ts +0 -8
- package/dist/contexts/index.d.ts.map +0 -1
- package/dist/core/index.d.ts +0 -3
- package/dist/core/index.d.ts.map +0 -1
- package/dist/hooks/index.d.ts +0 -5
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/mm/index.d.ts +0 -9
- package/dist/hooks/mm/index.d.ts.map +0 -1
- package/dist/hooks/mm/useBorrow.d.ts +0 -35
- package/dist/hooks/mm/useBorrow.d.ts.map +0 -1
- package/dist/hooks/mm/useMMAllowance.d.ts +0 -26
- package/dist/hooks/mm/useMMAllowance.d.ts.map +0 -1
- package/dist/hooks/mm/useMMApprove.d.ts +0 -27
- package/dist/hooks/mm/useMMApprove.d.ts.map +0 -1
- package/dist/hooks/mm/useRepay.d.ts +0 -35
- package/dist/hooks/mm/useRepay.d.ts.map +0 -1
- package/dist/hooks/mm/useReservesData.d.ts +0 -19
- package/dist/hooks/mm/useReservesData.d.ts.map +0 -1
- package/dist/hooks/mm/useSupply.d.ts +0 -34
- package/dist/hooks/mm/useSupply.d.ts.map +0 -1
- package/dist/hooks/mm/useUserReservesData.d.ts +0 -3
- package/dist/hooks/mm/useUserReservesData.d.ts.map +0 -1
- package/dist/hooks/mm/useWithdraw.d.ts +0 -33
- package/dist/hooks/mm/useWithdraw.d.ts.map +0 -1
- package/dist/hooks/provider/index.d.ts +0 -3
- package/dist/hooks/provider/index.d.ts.map +0 -1
- package/dist/hooks/provider/useHubProvider.d.ts +0 -3
- package/dist/hooks/provider/useHubProvider.d.ts.map +0 -1
- package/dist/hooks/provider/useSpokeProvider.d.ts +0 -18
- package/dist/hooks/provider/useSpokeProvider.d.ts.map +0 -1
- package/dist/hooks/shared/index.d.ts +0 -2
- package/dist/hooks/shared/index.d.ts.map +0 -1
- package/dist/hooks/shared/useSodaxContext.d.ts +0 -8
- package/dist/hooks/shared/useSodaxContext.d.ts.map +0 -1
- package/dist/hooks/swap/index.d.ts +0 -6
- package/dist/hooks/swap/index.d.ts.map +0 -1
- package/dist/hooks/swap/useCreateIntentOrder.d.ts +0 -33
- package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +0 -1
- package/dist/hooks/swap/useQuote.d.ts +0 -39
- package/dist/hooks/swap/useQuote.d.ts.map +0 -1
- package/dist/hooks/swap/useStatus.d.ts +0 -31
- package/dist/hooks/swap/useStatus.d.ts.map +0 -1
- package/dist/hooks/swap/useSwapAllowance.d.ts +0 -23
- package/dist/hooks/swap/useSwapAllowance.d.ts.map +0 -1
- package/dist/hooks/swap/useSwapApprove.d.ts +0 -26
- package/dist/hooks/swap/useSwapApprove.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/providers/SodaxProvider.d.ts +0 -10
- package/dist/providers/SodaxProvider.d.ts.map +0 -1
- package/dist/providers/index.d.ts +0 -2
- package/dist/providers/index.d.ts.map +0 -1
- package/src/core/index.ts +0 -12
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Backend API Hooks
|
|
2
|
+
|
|
3
|
+
This directory contains React hooks for interacting with the Sodax Backend API through the `BackendApiService`. These hooks provide a React-friendly interface with automatic caching, error handling, and loading states using React Query.
|
|
4
|
+
|
|
5
|
+
## Available Hooks
|
|
6
|
+
|
|
7
|
+
### Intent Hooks
|
|
8
|
+
|
|
9
|
+
#### `useIntentByTxHash(txHash: string | undefined)`
|
|
10
|
+
Fetches intent details by transaction hash.
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { useIntentByTxHash } from '@sodax/dapp-kit';
|
|
14
|
+
|
|
15
|
+
const { data: intent, isLoading, error } = useIntentByTxHash('0x123...');
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
#### `useIntentByHash(intentHash: string | undefined)`
|
|
19
|
+
Fetches intent details by intent hash.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { useIntentByHash } from '@sodax/dapp-kit';
|
|
23
|
+
|
|
24
|
+
const { data: intent, isLoading, error } = useIntentByHash('0xabc...');
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Solver Hooks
|
|
28
|
+
|
|
29
|
+
#### `useOrderbook(params: { offset: string; limit: string } | undefined)`
|
|
30
|
+
Fetches the solver orderbook with pagination support.
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { useOrderbook } from '@sodax/dapp-kit';
|
|
34
|
+
|
|
35
|
+
const { data: orderbook, isLoading, error } = useOrderbook({
|
|
36
|
+
offset: '0',
|
|
37
|
+
limit: '10'
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Money Market Hooks
|
|
42
|
+
|
|
43
|
+
#### `useMoneyMarketPosition(userAddress: string | undefined)`
|
|
44
|
+
Fetches a user's money market positions.
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { useMoneyMarketPosition } from '@sodax/dapp-kit';
|
|
48
|
+
|
|
49
|
+
const { data: position, isLoading, error } = useMoneyMarketPosition('0x123...');
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### `useAllMoneyMarketAssets()`
|
|
53
|
+
Fetches all available money market assets.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { useAllMoneyMarketAssets } from '@sodax/dapp-kit';
|
|
57
|
+
|
|
58
|
+
const { data: assets, isLoading, error } = useAllMoneyMarketAssets();
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### `useMoneyMarketAsset(reserveAddress: string | undefined)`
|
|
62
|
+
Fetches details for a specific money market asset.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { useMoneyMarketAsset } from '@sodax/dapp-kit';
|
|
66
|
+
|
|
67
|
+
const { data: asset, isLoading, error } = useMoneyMarketAsset('0xabc...');
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### `useMoneyMarketAssetBorrowers(params)`
|
|
71
|
+
Fetches borrowers for a specific money market asset.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { useMoneyMarketAssetBorrowers } from '@sodax/dapp-kit';
|
|
75
|
+
|
|
76
|
+
const { data: borrowers, isLoading, error } = useMoneyMarketAssetBorrowers({
|
|
77
|
+
reserveAddress: '0xabc...',
|
|
78
|
+
offset: '0',
|
|
79
|
+
limit: '20'
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### `useMoneyMarketAssetSuppliers(params)`
|
|
84
|
+
Fetches suppliers for a specific money market asset.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { useMoneyMarketAssetSuppliers } from '@sodax/dapp-kit';
|
|
88
|
+
|
|
89
|
+
const { data: suppliers, isLoading, error } = useMoneyMarketAssetSuppliers({
|
|
90
|
+
reserveAddress: '0xabc...',
|
|
91
|
+
offset: '0',
|
|
92
|
+
limit: '20'
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### `useAllMoneyMarketBorrowers(params)`
|
|
97
|
+
Fetches all money market borrowers across all assets.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { useAllMoneyMarketBorrowers } from '@sodax/dapp-kit';
|
|
101
|
+
|
|
102
|
+
const { data: borrowers, isLoading, error } = useAllMoneyMarketBorrowers({
|
|
103
|
+
offset: '0',
|
|
104
|
+
limit: '50'
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Features
|
|
109
|
+
|
|
110
|
+
- **Automatic Caching**: All hooks use React Query for efficient data caching
|
|
111
|
+
- **Error Handling**: Built-in error states and retry logic
|
|
112
|
+
- **Loading States**: Automatic loading indicators
|
|
113
|
+
- **TypeScript Support**: Full type safety with proper TypeScript definitions
|
|
114
|
+
- **Pagination Support**: Built-in pagination for list endpoints
|
|
115
|
+
- **Conditional Queries**: Queries are automatically disabled when required parameters are missing
|
|
116
|
+
- **Context Integration**: Uses `useSodaxContext` for consistent SDK access across the application
|
|
117
|
+
|
|
118
|
+
## Stale Times
|
|
119
|
+
|
|
120
|
+
Different hooks have different stale times optimized for their data types:
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
## Error Handling
|
|
124
|
+
|
|
125
|
+
All hooks return standard React Query result objects with:
|
|
126
|
+
|
|
127
|
+
- `data`: The fetched data (undefined when loading or on error)
|
|
128
|
+
- `isLoading`: Boolean indicating if the request is in progress
|
|
129
|
+
- `error`: Error object if the request failed
|
|
130
|
+
- `refetch`: Function to manually trigger a data refresh
|
|
131
|
+
|
|
132
|
+
## Requirements
|
|
133
|
+
|
|
134
|
+
- **SodaxProvider**: All backend hooks require the app to be wrapped with `SodaxProvider` from `@sodax/dapp-kit`
|
|
135
|
+
- **React Query**: The hooks use React Query for state management and caching
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/backend/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Backend API Hooks
|
|
4
|
+
*
|
|
5
|
+
* This module exports all hooks for interacting with the BackendApiService.
|
|
6
|
+
* These hooks provide a React-friendly interface to the Sodax Backend API,
|
|
7
|
+
* including intent management, solver orderbook, and money market operations.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Intent hooks
|
|
11
|
+
export { useBackendIntentByTxHash } from './useBackendIntentByTxHash';
|
|
12
|
+
export { useBackendIntentByHash } from './useBackendIntentByHash';
|
|
13
|
+
|
|
14
|
+
// Solver hooks
|
|
15
|
+
export { useBackendOrderbook } from './useBackendOrderbook';
|
|
16
|
+
|
|
17
|
+
// Money Market hooks
|
|
18
|
+
export { useBackendMoneyMarketPosition } from './useBackendMoneyMarketPosition';
|
|
19
|
+
export { useBackendAllMoneyMarketAssets } from './useBackendAllMoneyMarketAssets';
|
|
20
|
+
export { useBackendMoneyMarketAsset } from './useBackendMoneyMarketAsset';
|
|
21
|
+
export { useBackendMoneyMarketAssetBorrowers } from './useBackendMoneyMarketAssetBorrowers';
|
|
22
|
+
export { useBackendMoneyMarketAssetSuppliers } from './useBackendMoneyMarketAssetSuppliers';
|
|
23
|
+
export { useBackendAllMoneyMarketBorrowers } from './useBackendAllMoneyMarketBorrowers';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/backend/useAllMoneyMarketAssets.ts
|
|
2
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { MoneyMarketAsset } from '@sodax/sdk';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for fetching all money market assets from the backend API.
|
|
8
|
+
*
|
|
9
|
+
* This hook provides access to all available money market assets, including
|
|
10
|
+
* their reserve information, liquidity rates, borrow rates, and market statistics.
|
|
11
|
+
* The data is automatically fetched and cached using React Query.
|
|
12
|
+
*
|
|
13
|
+
* @returns {UseQueryResult<MoneyMarketAsset[]>} A query result object containing:
|
|
14
|
+
* - data: Array of money market asset data when available
|
|
15
|
+
* - isLoading: Boolean indicating if the request is in progress
|
|
16
|
+
* - error: Error object if the request failed
|
|
17
|
+
* - refetch: Function to manually trigger a data refresh
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const { data: assets, isLoading, error } = useAllMoneyMarketAssets();
|
|
22
|
+
*
|
|
23
|
+
* if (isLoading) return <div>Loading assets...</div>;
|
|
24
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
25
|
+
* if (assets) {
|
|
26
|
+
* console.log('Total assets:', assets.length);
|
|
27
|
+
* assets.forEach(asset => {
|
|
28
|
+
* console.log(`${asset.symbol}: ${asset.liquidityRate} liquidity rate`);
|
|
29
|
+
* });
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* - Uses React Query for efficient caching and state management
|
|
35
|
+
* - Automatically handles error states and loading indicators
|
|
36
|
+
* - Returns comprehensive asset information including rates and statistics
|
|
37
|
+
* - No parameters required - fetches all available assets
|
|
38
|
+
*/
|
|
39
|
+
export const useBackendAllMoneyMarketAssets = (): UseQueryResult<MoneyMarketAsset[]> => {
|
|
40
|
+
const { sodax } = useSodaxContext();
|
|
41
|
+
|
|
42
|
+
return useQuery({
|
|
43
|
+
queryKey: ['backend', 'moneymarket', 'assets', 'all'],
|
|
44
|
+
queryFn: async (): Promise<MoneyMarketAsset[]> => {
|
|
45
|
+
return sodax.backendApi.getAllMoneyMarketAssets();
|
|
46
|
+
},
|
|
47
|
+
retry: 3,
|
|
48
|
+
});
|
|
49
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/backend/useAllMoneyMarketBorrowers.ts
|
|
2
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { MoneyMarketBorrowers } from '@sodax/sdk';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for fetching all money market borrowers from the backend API.
|
|
8
|
+
*
|
|
9
|
+
* This hook provides access to the list of all borrowers across all money market assets,
|
|
10
|
+
* with pagination support. The data is automatically fetched and cached using React Query.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} params - Pagination parameters for fetching all borrowers
|
|
13
|
+
* @param {string} params.offset - The offset for pagination (number as string)
|
|
14
|
+
* @param {string} params.limit - The limit for pagination (number as string)
|
|
15
|
+
*
|
|
16
|
+
* @returns {UseQueryResult<MoneyMarketBorrowers | undefined>} A query result object containing:
|
|
17
|
+
* - data: The all borrowers data when available
|
|
18
|
+
* - isLoading: Boolean indicating if the request is in progress
|
|
19
|
+
* - error: Error object if the request failed
|
|
20
|
+
* - refetch: Function to manually trigger a data refresh
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const { data: borrowers, isLoading, error } = useAllMoneyMarketBorrowers({
|
|
25
|
+
* offset: '0',
|
|
26
|
+
* limit: '50'
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* if (isLoading) return <div>Loading borrowers...</div>;
|
|
30
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
31
|
+
* if (borrowers) {
|
|
32
|
+
* console.log('Total borrowers:', borrowers.total);
|
|
33
|
+
* console.log('Borrowers:', borrowers.borrowers);
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* - The query is disabled when params are undefined or invalid
|
|
39
|
+
* - Uses React Query for efficient caching and state management
|
|
40
|
+
* - Automatically handles error states and loading indicators
|
|
41
|
+
* - Supports pagination through offset and limit parameters
|
|
42
|
+
* - Returns borrowers across all money market assets
|
|
43
|
+
*/
|
|
44
|
+
export const useBackendAllMoneyMarketBorrowers = (
|
|
45
|
+
params: { offset: string; limit: string } | undefined,
|
|
46
|
+
): UseQueryResult<MoneyMarketBorrowers | undefined> => {
|
|
47
|
+
const { sodax } = useSodaxContext();
|
|
48
|
+
|
|
49
|
+
return useQuery({
|
|
50
|
+
queryKey: ['backend', 'moneymarket', 'borrowers', 'all', params],
|
|
51
|
+
queryFn: async (): Promise<MoneyMarketBorrowers | undefined> => {
|
|
52
|
+
if (!params || !params.offset || !params.limit) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return sodax.backendApi.getAllMoneyMarketBorrowers(params);
|
|
57
|
+
},
|
|
58
|
+
enabled: !!params && !!params.offset && !!params.limit,
|
|
59
|
+
retry: 3,
|
|
60
|
+
});
|
|
61
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/backend/useIntentByHash.ts
|
|
2
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { IntentResponse } from '@sodax/sdk';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for fetching intent details by intent hash from the backend API.
|
|
8
|
+
*
|
|
9
|
+
* This hook provides access to intent data using the intent hash directly,
|
|
10
|
+
* including intent details, events, and transaction information. The data is automatically
|
|
11
|
+
* fetched and cached using React Query.
|
|
12
|
+
*
|
|
13
|
+
* @param {string | undefined} intentHash - The intent hash to fetch intent for. If undefined, the query will be disabled.
|
|
14
|
+
*
|
|
15
|
+
* @returns {UseQueryResult<IntentResponse | undefined>} A query result object containing:
|
|
16
|
+
* - data: The intent response data when available
|
|
17
|
+
* - isLoading: Boolean indicating if the request is in progress
|
|
18
|
+
* - error: Error object if the request failed
|
|
19
|
+
* - refetch: Function to manually trigger a data refresh
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const { data: intent, isLoading, error } = useIntentByHash('0xabc...');
|
|
24
|
+
*
|
|
25
|
+
* if (isLoading) return <div>Loading intent...</div>;
|
|
26
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
27
|
+
* if (intent) {
|
|
28
|
+
* console.log('Intent found:', intent.intentHash);
|
|
29
|
+
* console.log('Open status:', intent.open);
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* - The query is disabled when intentHash is undefined or empty
|
|
35
|
+
* - Uses React Query for efficient caching and state management
|
|
36
|
+
* - Automatically handles error states and loading indicators
|
|
37
|
+
*/
|
|
38
|
+
export const useBackendIntentByHash = (intentHash: string | undefined): UseQueryResult<IntentResponse | undefined> => {
|
|
39
|
+
const { sodax } = useSodaxContext();
|
|
40
|
+
|
|
41
|
+
return useQuery({
|
|
42
|
+
queryKey: ['backend', 'intent', 'hash', intentHash],
|
|
43
|
+
queryFn: async (): Promise<IntentResponse | undefined> => {
|
|
44
|
+
if (!intentHash) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return sodax.backendApi.getIntentByHash(intentHash);
|
|
49
|
+
},
|
|
50
|
+
enabled: !!intentHash && intentHash.length > 0,
|
|
51
|
+
retry: 3,
|
|
52
|
+
});
|
|
53
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/backend/useIntentByTxHash.ts
|
|
2
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { IntentResponse } from '@sodax/sdk';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for fetching intent details by intent created transaction hash from the backend API.
|
|
8
|
+
*
|
|
9
|
+
* This hook provides access to intent data associated with the transaction hash from when
|
|
10
|
+
* the intent was created on the hub chain, including intent details, events, and transaction
|
|
11
|
+
* information. The data is automatically fetched and cached using React Query.
|
|
12
|
+
*
|
|
13
|
+
* @param {string | undefined} txHash - The intent created transaction hash from the hub chain to fetch intent for. If undefined, the query will be disabled.
|
|
14
|
+
*
|
|
15
|
+
* @returns {UseQueryResult<IntentResponse | undefined>} A query result object containing:
|
|
16
|
+
* - data: The intent response data when available
|
|
17
|
+
* - isLoading: Boolean indicating if the request is in progress
|
|
18
|
+
* - error: Error object if the request failed
|
|
19
|
+
* - refetch: Function to manually trigger a data refresh
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const { data: intent, isLoading, error } = useIntentByTxHash('0x123...');
|
|
24
|
+
*
|
|
25
|
+
* if (isLoading) return <div>Loading intent...</div>;
|
|
26
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
27
|
+
* if (intent) {
|
|
28
|
+
* console.log('Intent found:', intent.intentHash);
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* - Intents are only created on the hub chain, so the transaction hash must be from the hub chain
|
|
34
|
+
* - The query is disabled when txHash is undefined or empty
|
|
35
|
+
* - Uses React Query for efficient caching and state management
|
|
36
|
+
* - Automatically handles error states and loading indicators
|
|
37
|
+
*/
|
|
38
|
+
export const useBackendIntentByTxHash = (
|
|
39
|
+
txHash: string | undefined,
|
|
40
|
+
refetchInterval = 1000,
|
|
41
|
+
): UseQueryResult<IntentResponse | undefined> => {
|
|
42
|
+
const { sodax } = useSodaxContext();
|
|
43
|
+
|
|
44
|
+
return useQuery({
|
|
45
|
+
queryKey: ['backend', 'intent', 'txHash', txHash],
|
|
46
|
+
queryFn: async (): Promise<IntentResponse | undefined> => {
|
|
47
|
+
if (!txHash) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return sodax.backendApi.getIntentByTxHash(txHash);
|
|
52
|
+
},
|
|
53
|
+
refetchInterval,
|
|
54
|
+
enabled: !!txHash && txHash.length > 0,
|
|
55
|
+
retry: 3,
|
|
56
|
+
});
|
|
57
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/backend/useMoneyMarketAsset.ts
|
|
2
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { MoneyMarketAsset } from '@sodax/sdk';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for fetching specific money market asset details from the backend API.
|
|
8
|
+
*
|
|
9
|
+
* This hook provides access to detailed information for a specific money market asset,
|
|
10
|
+
* including reserve information, liquidity rates, borrow rates, and market statistics.
|
|
11
|
+
* The data is automatically fetched and cached using React Query.
|
|
12
|
+
*
|
|
13
|
+
* @param {string | undefined} reserveAddress - The reserve contract address. If undefined, the query will be disabled.
|
|
14
|
+
*
|
|
15
|
+
* @returns {UseQueryResult<MoneyMarketAsset | undefined>} A query result object containing:
|
|
16
|
+
* - data: The money market asset data when available
|
|
17
|
+
* - isLoading: Boolean indicating if the request is in progress
|
|
18
|
+
* - error: Error object if the request failed
|
|
19
|
+
* - refetch: Function to manually trigger a data refresh
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const { data: asset, isLoading, error } = useMoneyMarketAsset('0xabc...');
|
|
24
|
+
*
|
|
25
|
+
* if (isLoading) return <div>Loading asset...</div>;
|
|
26
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
27
|
+
* if (asset) {
|
|
28
|
+
* console.log('Asset symbol:', asset.symbol);
|
|
29
|
+
* console.log('Liquidity rate:', asset.liquidityRate);
|
|
30
|
+
* console.log('Variable borrow rate:', asset.variableBorrowRate);
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* - The query is disabled when reserveAddress is undefined or empty
|
|
36
|
+
* - Uses React Query for efficient caching and state management
|
|
37
|
+
* - Automatically handles error states and loading indicators
|
|
38
|
+
* - Returns comprehensive asset information for the specified reserve
|
|
39
|
+
*/
|
|
40
|
+
export const useBackendMoneyMarketAsset = (
|
|
41
|
+
reserveAddress: string | undefined,
|
|
42
|
+
): UseQueryResult<MoneyMarketAsset | undefined> => {
|
|
43
|
+
const { sodax } = useSodaxContext();
|
|
44
|
+
|
|
45
|
+
return useQuery({
|
|
46
|
+
queryKey: ['backend', 'moneymarket', 'asset', reserveAddress],
|
|
47
|
+
queryFn: async (): Promise<MoneyMarketAsset | undefined> => {
|
|
48
|
+
if (!reserveAddress) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return sodax.backendApi.getMoneyMarketAsset(reserveAddress);
|
|
53
|
+
},
|
|
54
|
+
enabled: !!reserveAddress && reserveAddress.length > 0,
|
|
55
|
+
retry: 3,
|
|
56
|
+
});
|
|
57
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/backend/useMoneyMarketAssetBorrowers.ts
|
|
2
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { MoneyMarketAssetBorrowers } from '@sodax/sdk';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for fetching borrowers for a specific money market asset from the backend API.
|
|
8
|
+
*
|
|
9
|
+
* This hook provides access to the list of borrowers for a specific money market asset,
|
|
10
|
+
* with pagination support. The data is automatically fetched and cached using React Query.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} params - Parameters for fetching asset borrowers
|
|
13
|
+
* @param {string | undefined} params.reserveAddress - The reserve contract address. If undefined, the query will be disabled.
|
|
14
|
+
* @param {string} params.offset - The offset for pagination (number as string)
|
|
15
|
+
* @param {string} params.limit - The limit for pagination (number as string)
|
|
16
|
+
*
|
|
17
|
+
* @returns {UseQueryResult<MoneyMarketAssetBorrowers | undefined>} A query result object containing:
|
|
18
|
+
* - data: The asset borrowers data when available
|
|
19
|
+
* - isLoading: Boolean indicating if the request is in progress
|
|
20
|
+
* - error: Error object if the request failed
|
|
21
|
+
* - refetch: Function to manually trigger a data refresh
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const { data: borrowers, isLoading, error } = useMoneyMarketAssetBorrowers({
|
|
26
|
+
* reserveAddress: '0xabc...',
|
|
27
|
+
* offset: '0',
|
|
28
|
+
* limit: '20'
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* if (isLoading) return <div>Loading borrowers...</div>;
|
|
32
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
33
|
+
* if (borrowers) {
|
|
34
|
+
* console.log('Total borrowers:', borrowers.total);
|
|
35
|
+
* console.log('Borrowers:', borrowers.borrowers);
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* - The query is disabled when reserveAddress is undefined or empty
|
|
41
|
+
* - Uses React Query for efficient caching and state management
|
|
42
|
+
* - Automatically handles error states and loading indicators
|
|
43
|
+
* - Supports pagination through offset and limit parameters
|
|
44
|
+
*/
|
|
45
|
+
export const useBackendMoneyMarketAssetBorrowers = (params: {
|
|
46
|
+
reserveAddress: string | undefined;
|
|
47
|
+
offset: string;
|
|
48
|
+
limit: string;
|
|
49
|
+
}): UseQueryResult<MoneyMarketAssetBorrowers | undefined> => {
|
|
50
|
+
const { sodax } = useSodaxContext();
|
|
51
|
+
|
|
52
|
+
return useQuery({
|
|
53
|
+
queryKey: ['backend', 'moneymarket', 'asset', 'borrowers', params],
|
|
54
|
+
queryFn: async (): Promise<MoneyMarketAssetBorrowers | undefined> => {
|
|
55
|
+
if (!params.reserveAddress || !params.offset || !params.limit) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return sodax.backendApi.getMoneyMarketAssetBorrowers(params.reserveAddress, {
|
|
60
|
+
offset: params.offset,
|
|
61
|
+
limit: params.limit,
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
enabled: !!params.reserveAddress && !!params.offset && !!params.limit,
|
|
65
|
+
retry: 3,
|
|
66
|
+
});
|
|
67
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/backend/useMoneyMarketAssetSuppliers.ts
|
|
2
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { MoneyMarketAssetSuppliers } from '@sodax/sdk';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for fetching suppliers for a specific money market asset from the backend API.
|
|
8
|
+
*
|
|
9
|
+
* This hook provides access to the list of suppliers for a specific money market asset,
|
|
10
|
+
* with pagination support. The data is automatically fetched and cached using React Query.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} params - Parameters for fetching asset suppliers
|
|
13
|
+
* @param {string | undefined} params.reserveAddress - The reserve contract address. If undefined, the query will be disabled.
|
|
14
|
+
* @param {string} params.offset - The offset for pagination (number as string)
|
|
15
|
+
* @param {string} params.limit - The limit for pagination (number as string)
|
|
16
|
+
*
|
|
17
|
+
* @returns {UseQueryResult<MoneyMarketAssetSuppliers | undefined>} A query result object containing:
|
|
18
|
+
* - data: The asset suppliers data when available
|
|
19
|
+
* - isLoading: Boolean indicating if the request is in progress
|
|
20
|
+
* - error: Error object if the request failed
|
|
21
|
+
* - refetch: Function to manually trigger a data refresh
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const { data: suppliers, isLoading, error } = useMoneyMarketAssetSuppliers({
|
|
26
|
+
* reserveAddress: '0xabc...',
|
|
27
|
+
* offset: '0',
|
|
28
|
+
* limit: '20'
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* if (isLoading) return <div>Loading suppliers...</div>;
|
|
32
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
33
|
+
* if (suppliers) {
|
|
34
|
+
* console.log('Total suppliers:', suppliers.total);
|
|
35
|
+
* console.log('Suppliers:', suppliers.suppliers);
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* - The query is disabled when reserveAddress is undefined or empty
|
|
41
|
+
* - Uses React Query for efficient caching and state management
|
|
42
|
+
* - Automatically handles error states and loading indicators
|
|
43
|
+
* - Supports pagination through offset and limit parameters
|
|
44
|
+
*/
|
|
45
|
+
export const useBackendMoneyMarketAssetSuppliers = (params: {
|
|
46
|
+
reserveAddress: string | undefined;
|
|
47
|
+
offset: string;
|
|
48
|
+
limit: string;
|
|
49
|
+
}): UseQueryResult<MoneyMarketAssetSuppliers | undefined> => {
|
|
50
|
+
const { sodax } = useSodaxContext();
|
|
51
|
+
|
|
52
|
+
return useQuery({
|
|
53
|
+
queryKey: ['backend', 'moneymarket', 'asset', 'suppliers', params],
|
|
54
|
+
queryFn: async (): Promise<MoneyMarketAssetSuppliers | undefined> => {
|
|
55
|
+
if (!params.reserveAddress || !params.offset || !params.limit) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return sodax.backendApi.getMoneyMarketAssetSuppliers(params.reserveAddress, {
|
|
60
|
+
offset: params.offset,
|
|
61
|
+
limit: params.limit,
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
enabled: !!params.reserveAddress && !!params.offset && !!params.limit,
|
|
65
|
+
retry: 3,
|
|
66
|
+
});
|
|
67
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/backend/useMoneyMarketPosition.ts
|
|
2
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { MoneyMarketPosition } from '@sodax/sdk';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for fetching money market position for a specific user from the backend API.
|
|
8
|
+
*
|
|
9
|
+
* This hook provides access to a user's money market positions, including their
|
|
10
|
+
* aToken balances, variable debt token balances, and associated reserve information.
|
|
11
|
+
* The data is automatically fetched and cached using React Query.
|
|
12
|
+
*
|
|
13
|
+
* @param {string | undefined} userAddress - The user's wallet address. If undefined, the query will be disabled.
|
|
14
|
+
*
|
|
15
|
+
* @returns {UseQueryResult<MoneyMarketPosition | undefined>} A query result object containing:
|
|
16
|
+
* - data: The money market position data when available
|
|
17
|
+
* - isLoading: Boolean indicating if the request is in progress
|
|
18
|
+
* - error: Error object if the request failed
|
|
19
|
+
* - refetch: Function to manually trigger a data refresh
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const { data: position, isLoading, error } = useMoneyMarketPosition('0x123...');
|
|
24
|
+
*
|
|
25
|
+
* if (isLoading) return <div>Loading position...</div>;
|
|
26
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
27
|
+
* if (position) {
|
|
28
|
+
* console.log('User address:', position.userAddress);
|
|
29
|
+
* console.log('Positions:', position.positions);
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* - The query is disabled when userAddress is undefined or empty
|
|
35
|
+
* - Uses React Query for efficient caching and state management
|
|
36
|
+
* - Automatically handles error states and loading indicators
|
|
37
|
+
* - Includes user's aToken and debt token balances across all reserves
|
|
38
|
+
*/
|
|
39
|
+
export const useBackendMoneyMarketPosition = (
|
|
40
|
+
userAddress: string | undefined,
|
|
41
|
+
): UseQueryResult<MoneyMarketPosition | undefined> => {
|
|
42
|
+
const { sodax } = useSodaxContext();
|
|
43
|
+
|
|
44
|
+
return useQuery({
|
|
45
|
+
queryKey: ['backend', 'moneymarket', 'position', userAddress],
|
|
46
|
+
queryFn: async (): Promise<MoneyMarketPosition | undefined> => {
|
|
47
|
+
if (!userAddress) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return sodax.backendApi.getMoneyMarketPosition(userAddress);
|
|
52
|
+
},
|
|
53
|
+
enabled: !!userAddress && userAddress.length > 0,
|
|
54
|
+
retry: 3,
|
|
55
|
+
});
|
|
56
|
+
};
|