@sodax/dapp-kit 0.0.1-rc.21 → 0.0.1-rc.23
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 +83 -1
- package/dist/contexts/index.d.ts +1 -2
- package/dist/contexts/index.d.ts.map +1 -1
- package/dist/hooks/backend/index.d.ts +17 -0
- package/dist/hooks/backend/index.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendAllMoneyMarketAssets.d.ts +37 -0
- package/dist/hooks/backend/useBackendAllMoneyMarketAssets.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendAllMoneyMarketBorrowers.d.ts +45 -0
- package/dist/hooks/backend/useBackendAllMoneyMarketBorrowers.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendIntentByHash.d.ts +36 -0
- package/dist/hooks/backend/useBackendIntentByHash.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendIntentByTxHash.d.ts +35 -0
- package/dist/hooks/backend/useBackendIntentByTxHash.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendMoneyMarketAsset.d.ts +38 -0
- package/dist/hooks/backend/useBackendMoneyMarketAsset.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendMoneyMarketAssetBorrowers.d.ts +47 -0
- package/dist/hooks/backend/useBackendMoneyMarketAssetBorrowers.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendMoneyMarketAssetSuppliers.d.ts +47 -0
- package/dist/hooks/backend/useBackendMoneyMarketAssetSuppliers.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendMoneyMarketPosition.d.ts +37 -0
- package/dist/hooks/backend/useBackendMoneyMarketPosition.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendOrderbook.d.ts +46 -0
- package/dist/hooks/backend/useBackendOrderbook.d.ts.map +1 -0
- package/dist/hooks/bridge/index.d.ts +6 -0
- package/dist/hooks/bridge/index.d.ts.map +1 -0
- package/dist/hooks/bridge/useBridge.d.ts +33 -0
- package/dist/hooks/bridge/useBridge.d.ts.map +1 -0
- package/dist/hooks/bridge/useBridgeAllowance.d.ts +23 -0
- package/dist/hooks/bridge/useBridgeAllowance.d.ts.map +1 -0
- package/dist/hooks/bridge/useBridgeApprove.d.ts +29 -0
- package/dist/hooks/bridge/useBridgeApprove.d.ts.map +1 -0
- package/dist/hooks/bridge/useGetBridgeableAmount.d.ts +26 -0
- package/dist/hooks/bridge/useGetBridgeableAmount.d.ts.map +1 -0
- package/dist/hooks/bridge/useGetBridgeableTokens.d.ts +37 -0
- package/dist/hooks/bridge/useGetBridgeableTokens.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/mm/useUserFormattedSummary.d.ts +1 -1
- package/dist/hooks/mm/useUserFormattedSummary.d.ts.map +1 -1
- package/dist/hooks/mm/useUserReservesData.d.ts +1 -1
- package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
- package/dist/hooks/provider/useHubProvider.d.ts +1 -1
- package/dist/hooks/provider/useHubProvider.d.ts.map +1 -1
- package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
- package/dist/hooks/shared/index.d.ts +1 -0
- package/dist/hooks/shared/index.d.ts.map +1 -1
- package/dist/hooks/shared/useDeriveUserWalletAddress.d.ts +24 -0
- package/dist/hooks/shared/useDeriveUserWalletAddress.d.ts.map +1 -0
- package/dist/index.js +278 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +265 -21
- package/dist/index.mjs.map +1 -1
- package/dist/providers/SodaxProvider.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/contexts/index.ts +1 -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 +52 -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 +2 -0
- package/src/hooks/mm/useUserFormattedSummary.ts +1 -1
- package/src/hooks/mm/useUserReservesData.ts +1 -1
- package/src/hooks/provider/useHubProvider.ts +3 -3
- package/src/hooks/provider/useSpokeProvider.ts +10 -4
- package/src/hooks/shared/index.ts +1 -0
- package/src/hooks/shared/useDeriveUserWalletAddress.ts +44 -0
- package/src/providers/SodaxProvider.tsx +4 -18
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { XToken, SpokeChainId } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
/**
|
|
7
|
+
* Hook for retrieving all bridgeable tokens from a source token on one chain to a destination chain.
|
|
8
|
+
*
|
|
9
|
+
* This hook queries and tracks the set of tokens on the destination chain that can be bridged to,
|
|
10
|
+
* given a source chain, destination chain, and source token address.
|
|
11
|
+
*
|
|
12
|
+
* @param {SpokeChainId | undefined} from - The source chain ID
|
|
13
|
+
* @param {SpokeChainId | undefined} to - The destination chain ID
|
|
14
|
+
* @param {string | undefined} token - The source token address
|
|
15
|
+
*
|
|
16
|
+
* @returns {UseQueryResult<XToken[], Error>} A React Query result containing:
|
|
17
|
+
* - data: Array of bridgeable tokens (XToken[]) on the destination chain
|
|
18
|
+
* - error: Any error that occurred during the query
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const { data: bridgeableTokens, isLoading } = useGetBridgeableTokens(
|
|
24
|
+
* fromChainId,
|
|
25
|
+
* toChainId,
|
|
26
|
+
* fromTokenAddress
|
|
27
|
+
* );
|
|
28
|
+
*
|
|
29
|
+
* if (bridgeableTokens && bridgeableTokens.length > 0) {
|
|
30
|
+
* bridgeableTokens.forEach(token => {
|
|
31
|
+
* console.log(`Bridgeable token: ${token.symbol} (${token.address}) on chain ${token.xChainId}`);
|
|
32
|
+
* });
|
|
33
|
+
* } else {
|
|
34
|
+
* console.log('No bridgeable tokens found for the selected route.');
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function useGetBridgeableTokens(
|
|
39
|
+
from: SpokeChainId | undefined,
|
|
40
|
+
to: SpokeChainId | undefined,
|
|
41
|
+
token: string | undefined,
|
|
42
|
+
): UseQueryResult<XToken[], Error> {
|
|
43
|
+
const { sodax } = useSodaxContext();
|
|
44
|
+
|
|
45
|
+
return useQuery({
|
|
46
|
+
queryKey: ['bridgeable-tokens', from, to, token],
|
|
47
|
+
queryFn: async () => {
|
|
48
|
+
if (!from || !to || !token) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const result = sodax.bridge.getBridgeableTokens(from, to, token);
|
|
53
|
+
if (result.ok) {
|
|
54
|
+
return result.value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
console.error('Error getting bridgeable tokens:', result.error);
|
|
58
|
+
return [];
|
|
59
|
+
},
|
|
60
|
+
enabled: !!from && !!to && !!token,
|
|
61
|
+
});
|
|
62
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FormatUserSummaryResponse, FormatReserveUSDResponse, SpokeProvider } from '@sodax/sdk';
|
|
2
2
|
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
4
4
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { EvmHubProvider } from '@sodax/sdk';
|
|
2
2
|
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
3
|
|
|
4
|
-
export function useHubProvider(): EvmHubProvider
|
|
5
|
-
const {
|
|
4
|
+
export function useHubProvider(): EvmHubProvider {
|
|
5
|
+
const { sodax } = useSodaxContext();
|
|
6
6
|
|
|
7
|
-
return hubProvider;
|
|
7
|
+
return sodax.hubProvider;
|
|
8
8
|
}
|
|
@@ -93,10 +93,16 @@ export function useSpokeProvider(
|
|
|
93
93
|
|
|
94
94
|
if (xChainType === 'STELLAR') {
|
|
95
95
|
const stellarConfig = spokeChainConfig[spokeChainId] as StellarSpokeChainConfig;
|
|
96
|
-
return new StellarSpokeProvider(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
return new StellarSpokeProvider(
|
|
97
|
+
walletProvider as IStellarWalletProvider,
|
|
98
|
+
stellarConfig,
|
|
99
|
+
rpcConfig.stellar
|
|
100
|
+
? rpcConfig.stellar
|
|
101
|
+
: {
|
|
102
|
+
horizonRpcUrl: stellarConfig.horizonRpcUrl,
|
|
103
|
+
sorobanRpcUrl: stellarConfig.sorobanRpcUrl,
|
|
104
|
+
},
|
|
105
|
+
);
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
if (xChainType === 'SOLANA') {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/shared/useDeriveUserWalletAddress.ts
|
|
2
|
+
import { deriveUserWalletAddress, type SpokeProvider, type EvmHubProvider } from '@sodax/sdk';
|
|
3
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
4
|
+
import { useSodaxContext } from './useSodaxContext';
|
|
5
|
+
import type { Address } from 'viem';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook for deriving user wallet address for hub abstraction.
|
|
9
|
+
*
|
|
10
|
+
* This hook derives the user's abstracted wallet address for the hub chain.
|
|
11
|
+
* If the spoke chain is the same as the hub chain, it returns the original wallet address.
|
|
12
|
+
* Otherwise, it returns the abstracted wallet address for cross-chain operations.
|
|
13
|
+
*
|
|
14
|
+
* @param spokeProvider - The spoke provider instance for the origin chain
|
|
15
|
+
* @param walletAddress - Optional user wallet address on spoke chain. If not provided, will fetch from spokeProvider
|
|
16
|
+
* @returns A React Query result object containing:
|
|
17
|
+
* - data: The derived user wallet address when available
|
|
18
|
+
* - isLoading: Loading state indicator
|
|
19
|
+
* - error: Any error that occurred during derivation
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeProvider, userAddress);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function useDeriveUserWalletAddress(
|
|
27
|
+
spokeProvider: SpokeProvider | undefined,
|
|
28
|
+
walletAddress?: string | undefined,
|
|
29
|
+
): UseQueryResult<Address, Error> {
|
|
30
|
+
const { sodax } = useSodaxContext();
|
|
31
|
+
|
|
32
|
+
return useQuery({
|
|
33
|
+
queryKey: ['deriveUserWalletAddress', spokeProvider?.chainConfig.chain.id, walletAddress],
|
|
34
|
+
queryFn: async (): Promise<Address> => {
|
|
35
|
+
if (!spokeProvider) {
|
|
36
|
+
throw new Error('Spoke provider is required');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return await deriveUserWalletAddress(spokeProvider, sodax.hubProvider, walletAddress);
|
|
40
|
+
},
|
|
41
|
+
enabled: !!spokeProvider,
|
|
42
|
+
refetchInterval: false, // This is a deterministic operation, no need to refetch
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { Sodax, type SodaxConfig } from '@sodax/sdk';
|
|
3
5
|
import { SodaxContext } from '@/contexts';
|
|
4
|
-
import React, { useMemo } from 'react';
|
|
5
6
|
import type { RpcConfig } from '@/types';
|
|
6
7
|
|
|
7
8
|
interface SodaxProviderProps {
|
|
@@ -14,20 +15,5 @@ interface SodaxProviderProps {
|
|
|
14
15
|
export const SodaxProvider = ({ children, testnet = false, config, rpcConfig }: SodaxProviderProps): ReactElement => {
|
|
15
16
|
const sodax = new Sodax(config);
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
const hubRpcUrl = config?.hubProviderConfig?.hubRpcUrl;
|
|
19
|
-
|
|
20
|
-
const hubProvider = useMemo(() => {
|
|
21
|
-
if (hubChainId && hubRpcUrl) {
|
|
22
|
-
const hubChainCfg = getHubChainConfig(hubChainId);
|
|
23
|
-
|
|
24
|
-
return new EvmHubProvider({
|
|
25
|
-
hubRpcUrl: hubRpcUrl,
|
|
26
|
-
chainConfig: hubChainCfg,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
return undefined;
|
|
30
|
-
}, [hubChainId, hubRpcUrl]);
|
|
31
|
-
|
|
32
|
-
return <SodaxContext.Provider value={{ sodax, testnet, hubProvider, rpcConfig }}>{children}</SodaxContext.Provider>;
|
|
18
|
+
return <SodaxContext.Provider value={{ sodax, testnet, rpcConfig }}>{children}</SodaxContext.Provider>;
|
|
33
19
|
};
|