@sodax/dapp-kit 0.0.1-rc.1 → 0.0.1-rc.11
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 +15 -13
- package/dist/contexts/index.d.ts +2 -1
- package/dist/contexts/index.d.ts.map +1 -1
- package/dist/core/index.d.ts +2 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/hooks/mm/index.d.ts +3 -1
- package/dist/hooks/mm/index.d.ts.map +1 -1
- package/dist/hooks/mm/useBorrow.d.ts +13 -4
- package/dist/hooks/mm/useBorrow.d.ts.map +1 -1
- package/dist/hooks/mm/useMMAllowance.d.ts +26 -0
- package/dist/hooks/mm/useMMAllowance.d.ts.map +1 -0
- package/dist/hooks/mm/useMMApprove.d.ts +27 -0
- package/dist/hooks/mm/useMMApprove.d.ts.map +1 -0
- package/dist/hooks/mm/useRepay.d.ts +13 -4
- package/dist/hooks/mm/useRepay.d.ts.map +1 -1
- package/dist/hooks/mm/useReservesData.d.ts +19 -0
- package/dist/hooks/mm/useReservesData.d.ts.map +1 -0
- package/dist/hooks/mm/useSupply.d.ts +4 -2
- package/dist/hooks/mm/useSupply.d.ts.map +1 -1
- package/dist/hooks/mm/useUserReservesData.d.ts +1 -7
- package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
- package/dist/hooks/mm/useWithdraw.d.ts +11 -4
- package/dist/hooks/mm/useWithdraw.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 +16 -2
- package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
- package/dist/hooks/shared/index.d.ts +1 -2
- package/dist/hooks/shared/index.d.ts.map +1 -1
- package/dist/hooks/shared/useEstimateGas.d.ts +4 -0
- package/dist/hooks/shared/useEstimateGas.d.ts.map +1 -0
- package/dist/hooks/swap/index.d.ts +2 -0
- package/dist/hooks/swap/index.d.ts.map +1 -1
- package/dist/hooks/swap/useCreateIntentOrder.d.ts +6 -6
- package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +1 -1
- package/dist/hooks/swap/useQuote.d.ts +4 -4
- package/dist/hooks/swap/useQuote.d.ts.map +1 -1
- package/dist/hooks/swap/useStatus.d.ts +3 -3
- package/dist/hooks/swap/useStatus.d.ts.map +1 -1
- package/dist/hooks/swap/useSwapAllowance.d.ts +23 -0
- package/dist/hooks/swap/useSwapAllowance.d.ts.map +1 -0
- package/dist/hooks/swap/useSwapApprove.d.ts +26 -0
- package/dist/hooks/swap/useSwapApprove.d.ts.map +1 -0
- package/dist/index.js +242 -189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +239 -188
- package/dist/index.mjs.map +1 -1
- package/dist/providers/SodaxProvider.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/contexts/index.ts +2 -1
- package/src/core/index.ts +5 -35
- package/src/hooks/mm/index.ts +3 -1
- package/src/hooks/mm/useBorrow.ts +20 -10
- package/src/hooks/mm/useMMAllowance.ts +55 -0
- package/src/hooks/mm/useMMApprove.ts +67 -0
- package/src/hooks/mm/useRepay.ts +20 -10
- package/src/hooks/mm/useReservesData.ts +37 -0
- package/src/hooks/mm/useSupply.ts +9 -6
- package/src/hooks/mm/useUserReservesData.ts +17 -34
- package/src/hooks/mm/useWithdraw.ts +17 -11
- package/src/hooks/provider/useHubProvider.ts +2 -21
- package/src/hooks/provider/useSpokeProvider.ts +87 -10
- package/src/hooks/shared/index.ts +1 -2
- package/src/hooks/shared/useEstimateGas.ts +20 -0
- package/src/hooks/swap/index.ts +2 -0
- package/src/hooks/swap/useCreateIntentOrder.ts +9 -11
- package/src/hooks/swap/useQuote.ts +5 -5
- package/src/hooks/swap/useStatus.ts +3 -3
- package/src/hooks/swap/useSwapAllowance.ts +44 -0
- package/src/hooks/swap/useSwapApprove.ts +68 -0
- package/src/providers/SodaxProvider.tsx +18 -3
- package/dist/hooks/mm/useHubWalletAddress.d.ts +0 -24
- package/dist/hooks/mm/useHubWalletAddress.d.ts.map +0 -1
- package/dist/hooks/shared/useAllowance.d.ts +0 -3
- package/dist/hooks/shared/useAllowance.d.ts.map +0 -1
- package/dist/hooks/shared/useApprove.d.ts +0 -10
- package/dist/hooks/shared/useApprove.d.ts.map +0 -1
- package/src/hooks/mm/useHubWalletAddress.ts +0 -49
- package/src/hooks/shared/useAllowance.ts +0 -31
- package/src/hooks/shared/useApprove.ts +0 -53
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { type EvmHubProvider, EvmWalletAbstraction, type SpokeChainId } from '@sodax/sdk';
|
|
2
|
-
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Hook for retrieving the hub wallet address for a given spoke chain and address.
|
|
6
|
-
*
|
|
7
|
-
* This hook fetches the hub wallet address associated with a user's address on a specific spoke chain.
|
|
8
|
-
* It uses the EvmWalletAbstraction to query the hub wallet address from the hub provider.
|
|
9
|
-
*
|
|
10
|
-
* @param spokeChainId - The chain ID of the spoke chain
|
|
11
|
-
* @param address - The user's address on the spoke chain
|
|
12
|
-
* @param hubProvider - The hub provider instance
|
|
13
|
-
*
|
|
14
|
-
* @returns {UseQueryResult<string | null>} A query result object containing:
|
|
15
|
-
* - data: The hub wallet address or null if not found
|
|
16
|
-
* - isLoading: Boolean indicating if the query is in progress
|
|
17
|
-
* - error: Error object if the query failed, null otherwise
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const { data: hubWalletAddress, isLoading, error } = useHubWalletAddress(spokeChainId, address, hubProvider);
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
export function useHubWalletAddress(
|
|
26
|
-
spokeChainId: SpokeChainId,
|
|
27
|
-
address: string | undefined,
|
|
28
|
-
hubProvider: EvmHubProvider,
|
|
29
|
-
): UseQueryResult<string | null> {
|
|
30
|
-
return useQuery({
|
|
31
|
-
queryKey: ['hubWallet', spokeChainId, address],
|
|
32
|
-
queryFn: async () => {
|
|
33
|
-
if (!address) return null;
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
const hubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
37
|
-
spokeChainId,
|
|
38
|
-
address as `0x${string}`,
|
|
39
|
-
hubProvider,
|
|
40
|
-
);
|
|
41
|
-
return hubWalletAddress;
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.log('error', error);
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
enabled: !!address && !!hubProvider,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query';
|
|
2
|
-
import type { SpokeChainId, XToken } from '@sodax/types';
|
|
3
|
-
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
4
|
-
import { useSpokeProvider } from '../provider/useSpokeProvider';
|
|
5
|
-
import { parseUnits } from 'viem';
|
|
6
|
-
|
|
7
|
-
export function useAllowance(token: XToken, amount: string) {
|
|
8
|
-
const { sodax } = useSodaxContext();
|
|
9
|
-
const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);
|
|
10
|
-
|
|
11
|
-
return useQuery({
|
|
12
|
-
queryKey: ['allowance', token.address, amount],
|
|
13
|
-
queryFn: async () => {
|
|
14
|
-
if (!spokeProvider) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
const allowance = await sodax.moneyMarket.isAllowanceValid(
|
|
18
|
-
{
|
|
19
|
-
token: token.address,
|
|
20
|
-
amount: parseUnits(amount, token.decimals),
|
|
21
|
-
},
|
|
22
|
-
spokeProvider,
|
|
23
|
-
);
|
|
24
|
-
if (allowance.ok) {
|
|
25
|
-
return allowance.value;
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
},
|
|
29
|
-
enabled: !!spokeProvider,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
2
|
-
import { useSpokeProvider } from '../provider/useSpokeProvider';
|
|
3
|
-
import type { SpokeChainId, XToken } from '@sodax/types';
|
|
4
|
-
import { parseUnits } from 'viem';
|
|
5
|
-
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
6
|
-
import type { Address } from '@sodax/sdk';
|
|
7
|
-
|
|
8
|
-
interface UseApproveReturn {
|
|
9
|
-
approve: (amount: string) => Promise<boolean>;
|
|
10
|
-
isLoading: boolean;
|
|
11
|
-
error: Error | null;
|
|
12
|
-
resetError: () => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function useApprove(token: XToken): UseApproveReturn {
|
|
16
|
-
const { sodax } = useSodaxContext();
|
|
17
|
-
const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);
|
|
18
|
-
const queryClient = useQueryClient();
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
mutateAsync: approve,
|
|
22
|
-
isPending,
|
|
23
|
-
error,
|
|
24
|
-
reset: resetError,
|
|
25
|
-
} = useMutation({
|
|
26
|
-
mutationFn: async (amount: string) => {
|
|
27
|
-
if (!spokeProvider) {
|
|
28
|
-
throw new Error('Spoke provider not found');
|
|
29
|
-
}
|
|
30
|
-
const allowance = await sodax.moneyMarket.approve(
|
|
31
|
-
token.address as Address,
|
|
32
|
-
parseUnits(amount, token.decimals),
|
|
33
|
-
spokeProvider.chainConfig.addresses.assetManager as Address,
|
|
34
|
-
spokeProvider,
|
|
35
|
-
);
|
|
36
|
-
if (!allowance.ok) {
|
|
37
|
-
throw new Error('Failed to approve tokens');
|
|
38
|
-
}
|
|
39
|
-
return allowance.ok;
|
|
40
|
-
},
|
|
41
|
-
onSuccess: () => {
|
|
42
|
-
// Invalidate allowance query to refetch the new allowance
|
|
43
|
-
queryClient.invalidateQueries({ queryKey: ['allowance', token.address] });
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
approve,
|
|
49
|
-
isLoading: isPending,
|
|
50
|
-
error: error as Error | null,
|
|
51
|
-
resetError,
|
|
52
|
-
};
|
|
53
|
-
}
|