@sodax/dapp-kit 0.0.1-rc.29 → 0.0.1-rc.30
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 +37 -37
- package/dist/index.d.mts +1425 -0
- package/dist/index.d.ts +1425 -5
- package/dist/index.js +364 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +347 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/contexts/index.ts +1 -1
- package/src/hooks/bridge/useGetBridgeableAmount.ts +1 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/shared/useDeriveUserWalletAddress.ts +1 -1
- 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/index.ts +0 -1
- package/src/providers/SodaxProvider.tsx +1 -1
- package/dist/contexts/index.d.ts +0 -9
- 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/backend/index.d.ts +0 -17
- package/dist/hooks/backend/index.d.ts.map +0 -1
- package/dist/hooks/backend/useBackendAllMoneyMarketAssets.d.ts +0 -37
- package/dist/hooks/backend/useBackendAllMoneyMarketAssets.d.ts.map +0 -1
- package/dist/hooks/backend/useBackendAllMoneyMarketBorrowers.d.ts +0 -45
- package/dist/hooks/backend/useBackendAllMoneyMarketBorrowers.d.ts.map +0 -1
- package/dist/hooks/backend/useBackendIntentByHash.d.ts +0 -36
- package/dist/hooks/backend/useBackendIntentByHash.d.ts.map +0 -1
- package/dist/hooks/backend/useBackendIntentByTxHash.d.ts +0 -35
- package/dist/hooks/backend/useBackendIntentByTxHash.d.ts.map +0 -1
- package/dist/hooks/backend/useBackendMoneyMarketAsset.d.ts +0 -38
- package/dist/hooks/backend/useBackendMoneyMarketAsset.d.ts.map +0 -1
- package/dist/hooks/backend/useBackendMoneyMarketAssetBorrowers.d.ts +0 -47
- package/dist/hooks/backend/useBackendMoneyMarketAssetBorrowers.d.ts.map +0 -1
- package/dist/hooks/backend/useBackendMoneyMarketAssetSuppliers.d.ts +0 -47
- package/dist/hooks/backend/useBackendMoneyMarketAssetSuppliers.d.ts.map +0 -1
- package/dist/hooks/backend/useBackendMoneyMarketPosition.d.ts +0 -37
- package/dist/hooks/backend/useBackendMoneyMarketPosition.d.ts.map +0 -1
- package/dist/hooks/backend/useBackendOrderbook.d.ts +0 -46
- package/dist/hooks/backend/useBackendOrderbook.d.ts.map +0 -1
- package/dist/hooks/bridge/index.d.ts +0 -6
- package/dist/hooks/bridge/index.d.ts.map +0 -1
- package/dist/hooks/bridge/useBridge.d.ts +0 -33
- package/dist/hooks/bridge/useBridge.d.ts.map +0 -1
- package/dist/hooks/bridge/useBridgeAllowance.d.ts +0 -23
- package/dist/hooks/bridge/useBridgeAllowance.d.ts.map +0 -1
- package/dist/hooks/bridge/useBridgeApprove.d.ts +0 -29
- package/dist/hooks/bridge/useBridgeApprove.d.ts.map +0 -1
- package/dist/hooks/bridge/useGetBridgeableAmount.d.ts +0 -26
- package/dist/hooks/bridge/useGetBridgeableAmount.d.ts.map +0 -1
- package/dist/hooks/bridge/useGetBridgeableTokens.d.ts +0 -37
- package/dist/hooks/bridge/useGetBridgeableTokens.d.ts.map +0 -1
- package/dist/hooks/index.d.ts +0 -7
- 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/useReservesHumanized.d.ts +0 -21
- package/dist/hooks/mm/useReservesHumanized.d.ts.map +0 -1
- package/dist/hooks/mm/useReservesList.d.ts +0 -18
- package/dist/hooks/mm/useReservesList.d.ts.map +0 -1
- package/dist/hooks/mm/useReservesUsdFormat.d.ts +0 -23
- package/dist/hooks/mm/useReservesUsdFormat.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/useUserFormattedSummary.d.ts +0 -21
- package/dist/hooks/mm/useUserFormattedSummary.d.ts.map +0 -1
- package/dist/hooks/mm/useUserReservesData.d.ts +0 -20
- 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 -6
- package/dist/hooks/shared/index.d.ts.map +0 -1
- package/dist/hooks/shared/useDeriveUserWalletAddress.d.ts +0 -24
- package/dist/hooks/shared/useDeriveUserWalletAddress.d.ts.map +0 -1
- package/dist/hooks/shared/useEstimateGas.d.ts +0 -4
- package/dist/hooks/shared/useEstimateGas.d.ts.map +0 -1
- package/dist/hooks/shared/useRequestTrustline.d.ts +0 -44
- package/dist/hooks/shared/useRequestTrustline.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/shared/useStellarTrustlineCheck.d.ts +0 -40
- package/dist/hooks/shared/useStellarTrustlineCheck.d.ts.map +0 -1
- package/dist/hooks/swap/index.d.ts +0 -7
- package/dist/hooks/swap/index.d.ts.map +0 -1
- package/dist/hooks/swap/useCancelSwap.d.ts +0 -29
- package/dist/hooks/swap/useCancelSwap.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/useSwap.d.ts +0 -29
- package/dist/hooks/swap/useSwap.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 -25
- 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 -12
- 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/dist/types.d.ts +0 -17
- package/dist/types.d.ts.map +0 -1
- package/src/types.ts +0 -22
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sodax/dapp-kit",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.0.1-rc.
|
|
4
|
+
"version": "0.0.1-rc.30",
|
|
5
5
|
"description": "dapp-kit of New World",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"viem": "2.29.2",
|
|
19
|
-
"@sodax/sdk": "0.0.1-rc.
|
|
20
|
-
"@sodax/types": "0.0.1-rc.
|
|
19
|
+
"@sodax/sdk": "0.0.1-rc.43",
|
|
20
|
+
"@sodax/types": "0.0.1-rc.18"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/react": "18.3.1",
|
package/src/contexts/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
2
|
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
-
import type {
|
|
3
|
+
import type { XToken } from '@sodax/sdk';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Hook for getting the amount available to be bridged.
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// packages/dapp-kit/src/hooks/shared/useDeriveUserWalletAddress.ts
|
|
2
|
-
import { deriveUserWalletAddress, type SpokeProvider
|
|
2
|
+
import { deriveUserWalletAddress, type SpokeProvider } from '@sodax/sdk';
|
|
3
3
|
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
4
4
|
import { useSodaxContext } from './useSodaxContext';
|
|
5
5
|
import type { Address } from 'viem';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/staking/index.ts
|
|
2
|
+
export { useStake } from './useStake';
|
|
3
|
+
export { useStakeApprove } from './useStakeApprove';
|
|
4
|
+
export { useStakeAllowance } from './useStakeAllowance';
|
|
5
|
+
export { useUnstake } from './useUnstake';
|
|
6
|
+
export { useClaim } from './useClaim';
|
|
7
|
+
export { useCancelUnstake } from './useCancelUnstake';
|
|
8
|
+
export { useStakingInfo } from './useStakingInfo';
|
|
9
|
+
export { useUnstakingInfoWithPenalty } from './useUnstakingInfoWithPenalty';
|
|
10
|
+
export { useStakingConfig } from './useStakingConfig';
|
|
11
|
+
export { useStakeRatio } from './useStakeRatio';
|
|
12
|
+
export { useInstantUnstakeRatio } from './useInstantUnstakeRatio';
|
|
13
|
+
export { useConvertedAssets } from './useConvertedAssets';
|
|
14
|
+
export { useInstantUnstake } from './useInstantUnstake';
|
|
15
|
+
export { useUnstakeAllowance } from './useUnstakeAllowance';
|
|
16
|
+
export { useUnstakeApprove } from './useUnstakeApprove';
|
|
17
|
+
export { useUnstakingInfo } from './useUnstakingInfo';
|
|
18
|
+
export { useInstantUnstakeApprove } from './useInstantUnstakeApprove';
|
|
19
|
+
export { useInstantUnstakeAllowance } from './useInstantUnstakeAllowance';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/staking/useCancelUnstake.ts
|
|
2
|
+
import { useMutation, useQueryClient, type UseMutationResult } from '@tanstack/react-query';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
4
|
+
import type { CancelUnstakeParams, SpokeProvider, SpokeTxHash, HubTxHash } from '@sodax/sdk';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for executing cancel unstake transactions to cancel pending unstake requests.
|
|
8
|
+
* Uses React Query's useMutation for better state management and caching.
|
|
9
|
+
*
|
|
10
|
+
* @param {SpokeProvider | undefined} spokeProvider - The spoke provider to use for the cancel unstake
|
|
11
|
+
* @returns {UseMutationResult<[SpokeTxHash, HubTxHash], Error, Omit<CancelUnstakeParams, 'action'>>} Mutation result object containing mutation function and state
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const { mutateAsync: cancelUnstake, isPending } = useCancelUnstake(spokeProvider);
|
|
16
|
+
*
|
|
17
|
+
* const handleCancelUnstake = async () => {
|
|
18
|
+
* const result = await cancelUnstake({
|
|
19
|
+
* requestId: 1n
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* console.log('Cancel unstake successful:', result);
|
|
23
|
+
* };
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function useCancelUnstake(
|
|
27
|
+
spokeProvider: SpokeProvider | undefined,
|
|
28
|
+
): UseMutationResult<[SpokeTxHash, HubTxHash], Error, Omit<CancelUnstakeParams, 'action'>> {
|
|
29
|
+
const { sodax } = useSodaxContext();
|
|
30
|
+
const queryClient = useQueryClient();
|
|
31
|
+
|
|
32
|
+
return useMutation({
|
|
33
|
+
mutationFn: async (params: Omit<CancelUnstakeParams, 'action'>) => {
|
|
34
|
+
if (!spokeProvider) {
|
|
35
|
+
throw new Error('Spoke provider not available');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const result = await sodax.staking.cancelUnstake({ ...params, action: 'cancelUnstake' }, spokeProvider);
|
|
39
|
+
if (!result.ok) {
|
|
40
|
+
throw new Error(`Cancel unstake failed: ${result.error.code}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return result.value;
|
|
44
|
+
},
|
|
45
|
+
onSuccess: () => {
|
|
46
|
+
// Invalidate relevant queries to refresh data
|
|
47
|
+
queryClient.invalidateQueries({ queryKey: ['stakingInfo'] });
|
|
48
|
+
queryClient.invalidateQueries({ queryKey: ['unstakingInfo'] });
|
|
49
|
+
queryClient.invalidateQueries({ queryKey: ['unstakingInfoWithPenalty'] });
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/staking/useClaim.ts
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
import type { ClaimParams, SpokeTxHash, HubTxHash, SpokeProvider } from '@sodax/sdk';
|
|
4
|
+
import { useMutation, type UseMutationResult } from '@tanstack/react-query';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for executing claim transactions to claim unstaked SODA tokens after the unstaking period.
|
|
8
|
+
* Uses React Query's useMutation for better state management and caching.
|
|
9
|
+
*
|
|
10
|
+
* @param {SpokeProvider | undefined} spokeProvider - The spoke provider to use for the claim
|
|
11
|
+
* @returns {UseMutationResult<[SpokeTxHash, HubTxHash], Error, Omit<ClaimParams, 'action'>>} Mutation result object containing mutation function and state
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const { mutateAsync: claim, isPending } = useClaim(spokeProvider);
|
|
16
|
+
*
|
|
17
|
+
* const handleClaim = async () => {
|
|
18
|
+
* const result = await claim({
|
|
19
|
+
* requestId: 1n
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* console.log('Claim successful:', result);
|
|
23
|
+
* };
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function useClaim(
|
|
27
|
+
spokeProvider: SpokeProvider | undefined,
|
|
28
|
+
): UseMutationResult<[SpokeTxHash, HubTxHash], Error, Omit<ClaimParams, 'action'>> {
|
|
29
|
+
const { sodax } = useSodaxContext();
|
|
30
|
+
|
|
31
|
+
return useMutation<[SpokeTxHash, HubTxHash], Error, Omit<ClaimParams, 'action'>>({
|
|
32
|
+
mutationFn: async (params: Omit<ClaimParams, 'action'>) => {
|
|
33
|
+
if (!spokeProvider) {
|
|
34
|
+
throw new Error('Spoke provider not found');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const result = await sodax.staking.claim({ ...params, action: 'claim' }, spokeProvider);
|
|
38
|
+
|
|
39
|
+
if (!result.ok) {
|
|
40
|
+
throw new Error(`Claim failed: ${result.error.code}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return result.value;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/staking/useConvertedAssets.ts
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook for fetching converted assets amount for xSODA shares.
|
|
7
|
+
* Uses React Query for efficient caching and state management.
|
|
8
|
+
*
|
|
9
|
+
* @param {bigint | undefined} amount - The amount of xSODA shares to convert
|
|
10
|
+
* @param {number} refetchInterval - The interval in milliseconds to refetch data (default: 10000)
|
|
11
|
+
* @returns {UseQueryResult<bigint, Error>} Query result object containing converted assets amount and state
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const { data: convertedAssets, isLoading, error } = useConvertedAssets(1000000000000000000n); // 1 xSODA
|
|
16
|
+
*
|
|
17
|
+
* if (isLoading) return <div>Loading converted assets...</div>;
|
|
18
|
+
* if (convertedAssets) {
|
|
19
|
+
* console.log('Converted assets:', convertedAssets);
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function useConvertedAssets(amount: bigint | undefined, refetchInterval = 10000): UseQueryResult<bigint, Error> {
|
|
24
|
+
const { sodax } = useSodaxContext();
|
|
25
|
+
|
|
26
|
+
console.log('useConvertedAssets hook called with:', { amount: amount?.toString(), sodax: !!sodax });
|
|
27
|
+
|
|
28
|
+
return useQuery({
|
|
29
|
+
queryKey: ['soda', 'convertedAssets', amount?.toString()],
|
|
30
|
+
queryFn: async () => {
|
|
31
|
+
console.log('useConvertedAssets queryFn called with amount:', amount?.toString());
|
|
32
|
+
if (!amount || amount <= 0n) {
|
|
33
|
+
throw new Error('Amount must be greater than 0');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const result = await sodax.staking.getConvertedAssets(amount);
|
|
37
|
+
|
|
38
|
+
if (!result.ok) {
|
|
39
|
+
throw new Error(`Failed to fetch converted assets: ${result.error.code}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return result.value;
|
|
43
|
+
},
|
|
44
|
+
enabled: !!amount && amount > 0n && !!sodax?.staking,
|
|
45
|
+
refetchInterval,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/staking/useInstantUnstake.ts
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
import { useMutation, type UseMutationResult } from '@tanstack/react-query';
|
|
4
|
+
import type { SpokeProvider, InstantUnstakeParams } from '@sodax/sdk';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for executing instant unstake operations.
|
|
8
|
+
* Uses React Query for efficient state management and error handling.
|
|
9
|
+
*
|
|
10
|
+
* @param {SpokeProvider | undefined} spokeProvider - The spoke provider for the transaction
|
|
11
|
+
* @returns {UseMutationResult<[string, string], Error, Omit<InstantUnstakeParams, 'action'>>} Mutation result object containing instant unstake state and methods
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const { mutateAsync: instantUnstake, isPending } = useInstantUnstake(spokeProvider);
|
|
16
|
+
*
|
|
17
|
+
* const handleInstantUnstake = async () => {
|
|
18
|
+
* const result = await instantUnstake({
|
|
19
|
+
* amount: 1000000000000000000n,
|
|
20
|
+
* minAmount: 950000000000000000n,
|
|
21
|
+
* account: '0x...'
|
|
22
|
+
* });
|
|
23
|
+
* console.log('Instant unstake successful:', result);
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function useInstantUnstake(
|
|
28
|
+
spokeProvider: SpokeProvider | undefined,
|
|
29
|
+
): UseMutationResult<[string, string], Error, Omit<InstantUnstakeParams, 'action'>> {
|
|
30
|
+
const { sodax } = useSodaxContext();
|
|
31
|
+
|
|
32
|
+
return useMutation({
|
|
33
|
+
mutationFn: async (params: Omit<InstantUnstakeParams, 'action'>) => {
|
|
34
|
+
if (!spokeProvider) {
|
|
35
|
+
throw new Error('spokeProvider is not found');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const result = await sodax.staking.instantUnstake({ ...params, action: 'instantUnstake' }, spokeProvider);
|
|
39
|
+
|
|
40
|
+
if (!result.ok) {
|
|
41
|
+
throw new Error(`Instant unstake failed: ${result.error.code}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return result.value;
|
|
45
|
+
},
|
|
46
|
+
onError: error => {
|
|
47
|
+
console.error('Instant unstake error:', error);
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/staking/useStakeAllowance.ts
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
import type { SpokeProvider, InstantUnstakeParams } from '@sodax/sdk';
|
|
4
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for checking xSODA token allowance for instant unstaking operations.
|
|
8
|
+
* Uses React Query for efficient caching and state management.
|
|
9
|
+
*
|
|
10
|
+
* @param {Omit<InstantUnstakeParams, 'action'> | undefined} params - The instant unstaking parameters. If undefined, the query will be disabled.
|
|
11
|
+
* @param {SpokeProvider | undefined} spokeProvider - The spoke provider to use for the allowance check
|
|
12
|
+
* @returns {UseQueryResult<boolean, Error>} Query result object containing allowance data and state
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const { data: hasAllowed, isLoading } = useInstantUnstakeAllowance(
|
|
17
|
+
* {
|
|
18
|
+
* amount: 1000000000000000000n, // 1 xSODA
|
|
19
|
+
* minAmount: 950000000000000000n, // 0.95 SODA
|
|
20
|
+
* account: '0x...'
|
|
21
|
+
* },
|
|
22
|
+
* spokeProvider
|
|
23
|
+
* );
|
|
24
|
+
*
|
|
25
|
+
* if (isLoading) return <div>Checking allowance...</div>;
|
|
26
|
+
* if (hasAllowed) {
|
|
27
|
+
* console.log('Sufficient allowance for instant unstaking');
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function useInstantUnstakeAllowance(
|
|
32
|
+
params: Omit<InstantUnstakeParams, 'action'> | undefined,
|
|
33
|
+
spokeProvider: SpokeProvider | undefined,
|
|
34
|
+
): UseQueryResult<boolean, Error> {
|
|
35
|
+
const { sodax } = useSodaxContext();
|
|
36
|
+
|
|
37
|
+
return useQuery({
|
|
38
|
+
queryKey: ['soda', 'instantUnstakeAllowance', params, spokeProvider?.chainConfig.chain.id],
|
|
39
|
+
queryFn: async () => {
|
|
40
|
+
if (!params || !spokeProvider) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const result = await sodax.staking.isAllowanceValid({
|
|
45
|
+
params: { ...params, action: 'instantUnstake' },
|
|
46
|
+
spokeProvider,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (!result.ok) {
|
|
50
|
+
console.error(`Unstake allowance check failed: ${result.error.code}, error: ${result.error.error}`);
|
|
51
|
+
throw new Error(`Unstake allowance check failed: ${result.error.code}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return result.value;
|
|
55
|
+
},
|
|
56
|
+
enabled: !!params && !!spokeProvider,
|
|
57
|
+
refetchInterval: 5000, // Refetch every 5 seconds
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/staking/useStakeApprove.ts
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
import type { InstantUnstakeParams, TxReturnType, SpokeProvider } from '@sodax/sdk';
|
|
4
|
+
import { useMutation, type UseMutationResult } from '@tanstack/react-query';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for approving xSODA token spending for instant unstaking operations.
|
|
8
|
+
* Uses React Query's useMutation for better state management and caching.
|
|
9
|
+
*
|
|
10
|
+
* @param {SpokeProvider | undefined} spokeProvider - The spoke provider to use for the approval
|
|
11
|
+
* @returns {UseMutationResult<TxReturnType<SpokeProvider, false>, Error, Omit<InstantUnstakeParams, 'action'>>} Mutation result object containing mutation function and state
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const { mutateAsync: approve, isPending } = useInstantUnstakeApprove(spokeProvider);
|
|
16
|
+
*
|
|
17
|
+
* const handleApprove = async () => {
|
|
18
|
+
* const result = await approve({
|
|
19
|
+
* amount: 1000000000000000000n, // 1 xSODA
|
|
20
|
+
* minAmount: 950000000000000000n, // 0.95 SODA
|
|
21
|
+
* account: '0x...'
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* console.log('Approval successful:', result);
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function useInstantUnstakeApprove(
|
|
29
|
+
spokeProvider: SpokeProvider | undefined,
|
|
30
|
+
): UseMutationResult<TxReturnType<SpokeProvider, false>, Error, Omit<InstantUnstakeParams, 'action'>> {
|
|
31
|
+
const { sodax } = useSodaxContext();
|
|
32
|
+
|
|
33
|
+
return useMutation<TxReturnType<SpokeProvider, false>, Error, Omit<InstantUnstakeParams, 'action'>>({
|
|
34
|
+
mutationFn: async (params: Omit<InstantUnstakeParams, 'action'>) => {
|
|
35
|
+
console.log('useInstantUnstakeApprove called with params:', params);
|
|
36
|
+
if (!spokeProvider) {
|
|
37
|
+
throw new Error('Spoke provider not found');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const result = await sodax.staking.approve({
|
|
41
|
+
params: { ...params, action: 'instantUnstake' },
|
|
42
|
+
spokeProvider,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (!result.ok) {
|
|
46
|
+
throw new Error(`Instant unstake approval failed: ${result.error.code}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return result.value;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/staking/useInstantUnstakeRatio.ts
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook for fetching instant unstake ratio estimates.
|
|
7
|
+
* Uses React Query for efficient caching and state management.
|
|
8
|
+
*
|
|
9
|
+
* @param {bigint | undefined} amount - The amount of xSoda to estimate instant unstake for
|
|
10
|
+
* @param {number} refetchInterval - The interval in milliseconds to refetch data (default: 10000)
|
|
11
|
+
* @returns {UseQueryResult<bigint, Error>} Query result object containing instant unstake ratio and state
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const { data: instantUnstakeRatio, isLoading, error } = useInstantUnstakeRatio(1000000000000000000n); // 1 xSoda
|
|
16
|
+
*
|
|
17
|
+
* if (isLoading) return <div>Loading instant unstake ratio...</div>;
|
|
18
|
+
* if (instantUnstakeRatio) {
|
|
19
|
+
* console.log('Instant unstake ratio:', instantUnstakeRatio);
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function useInstantUnstakeRatio(
|
|
24
|
+
amount: bigint | undefined,
|
|
25
|
+
refetchInterval = 10000,
|
|
26
|
+
): UseQueryResult<bigint, Error> {
|
|
27
|
+
const { sodax } = useSodaxContext();
|
|
28
|
+
|
|
29
|
+
console.log('useInstantUnstakeRatio hook called with:', { amount: amount?.toString(), sodax: !!sodax });
|
|
30
|
+
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: ['soda', 'instantUnstakeRatio', amount?.toString()],
|
|
33
|
+
queryFn: async () => {
|
|
34
|
+
console.log('useInstantUnstakeRatio queryFn called with amount:', amount?.toString());
|
|
35
|
+
if (!amount || amount <= 0n) {
|
|
36
|
+
throw new Error('Amount must be greater than 0');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!sodax?.staking) {
|
|
40
|
+
throw new Error('Staking service not available');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const result = await sodax.staking.getInstantUnstakeRatio(amount);
|
|
44
|
+
|
|
45
|
+
if (!result.ok) {
|
|
46
|
+
throw new Error(`Failed to fetch instant unstake ratio: ${result.error.code}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return result.value;
|
|
50
|
+
},
|
|
51
|
+
enabled: !!amount && amount > 0n && !!sodax?.staking,
|
|
52
|
+
refetchInterval,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/staking/useStake.ts
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
import type { StakeParams, SpokeTxHash, HubTxHash, SpokeProvider } from '@sodax/sdk';
|
|
4
|
+
import { useMutation, type UseMutationResult } from '@tanstack/react-query';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for executing stake transactions to stake SODA tokens and receive xSODA shares.
|
|
8
|
+
* Uses React Query's useMutation for better state management and caching.
|
|
9
|
+
*
|
|
10
|
+
* @param {SpokeProvider | undefined} spokeProvider - The spoke provider to use for the stake
|
|
11
|
+
* @returns {UseMutationResult<[SpokeTxHash, HubTxHash], Error, StakeParams>} Mutation result object containing mutation function and state
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const { mutateAsync: stake, isPending } = useStake(spokeProvider);
|
|
16
|
+
*
|
|
17
|
+
* const handleStake = async () => {
|
|
18
|
+
* const result = await stake({
|
|
19
|
+
* amount: 1000000000000000000n, // 1 SODA
|
|
20
|
+
* account: '0x...'
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* console.log('Stake successful:', result);
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function useStake(
|
|
28
|
+
spokeProvider: SpokeProvider | undefined,
|
|
29
|
+
): UseMutationResult<[SpokeTxHash, HubTxHash], Error, StakeParams> {
|
|
30
|
+
const { sodax } = useSodaxContext();
|
|
31
|
+
|
|
32
|
+
return useMutation<[SpokeTxHash, HubTxHash], Error, StakeParams>({
|
|
33
|
+
mutationFn: async (params: StakeParams) => {
|
|
34
|
+
if (!spokeProvider) {
|
|
35
|
+
throw new Error('Spoke provider not found');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const result = await sodax.staking.stake(params, spokeProvider);
|
|
39
|
+
|
|
40
|
+
if (!result.ok) {
|
|
41
|
+
throw new Error(`Stake failed: ${result.error.code}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return result.value;
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/staking/useStakeAllowance.ts
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
import type { StakeParams, SpokeProvider } from '@sodax/sdk';
|
|
4
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for checking SODA token allowance for staking operations.
|
|
8
|
+
* Uses React Query for efficient caching and state management.
|
|
9
|
+
*
|
|
10
|
+
* @param {Omit<StakeParams, 'action'> | undefined} params - The staking parameters. If undefined, the query will be disabled.
|
|
11
|
+
* @param {SpokeProvider | undefined} spokeProvider - The spoke provider to use for the allowance check
|
|
12
|
+
* @returns {UseQueryResult<boolean, Error>} Query result object containing allowance data and state
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const { data: hasAllowed, isLoading } = useStakeAllowance(
|
|
17
|
+
* {
|
|
18
|
+
* amount: 1000000000000000000n, // 1 SODA
|
|
19
|
+
* account: '0x...'
|
|
20
|
+
* },
|
|
21
|
+
* spokeProvider
|
|
22
|
+
* );
|
|
23
|
+
*
|
|
24
|
+
* if (isLoading) return <div>Checking allowance...</div>;
|
|
25
|
+
* if (hasAllowed) {
|
|
26
|
+
* console.log('Sufficient allowance for staking');
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function useStakeAllowance(
|
|
31
|
+
params: Omit<StakeParams, 'action'> | undefined,
|
|
32
|
+
spokeProvider: SpokeProvider | undefined,
|
|
33
|
+
): UseQueryResult<boolean, Error> {
|
|
34
|
+
const { sodax } = useSodaxContext();
|
|
35
|
+
|
|
36
|
+
return useQuery({
|
|
37
|
+
queryKey: ['soda', 'stakeAllowance', params, spokeProvider?.chainConfig.chain.id],
|
|
38
|
+
queryFn: async () => {
|
|
39
|
+
if (!params || !spokeProvider) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const result = await sodax.staking.isAllowanceValid({
|
|
44
|
+
params: { ...params, action: 'stake' },
|
|
45
|
+
spokeProvider,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (!result.ok) {
|
|
49
|
+
throw new Error(`Allowance check failed: ${result.error.code}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return result.value;
|
|
53
|
+
},
|
|
54
|
+
enabled: !!params && !!spokeProvider,
|
|
55
|
+
refetchInterval: 5000, // Refetch every 5 seconds
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/staking/useStakeApprove.ts
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
import type { StakeParams, TxReturnType, SpokeProvider } from '@sodax/sdk';
|
|
4
|
+
import { useMutation, type UseMutationResult } from '@tanstack/react-query';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook for approving SODA token spending for staking operations.
|
|
8
|
+
* Uses React Query's useMutation for better state management and caching.
|
|
9
|
+
*
|
|
10
|
+
* @param {SpokeProvider | undefined} spokeProvider - The spoke provider to use for the approval
|
|
11
|
+
* @returns {UseMutationResult<TxReturnType<SpokeProvider, false>, Error, Omit<StakeParams, 'action'>>} Mutation result object containing mutation function and state
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const { mutateAsync: approve, isPending } = useStakeApprove(spokeProvider);
|
|
16
|
+
*
|
|
17
|
+
* const handleApprove = async () => {
|
|
18
|
+
* const result = await approve({
|
|
19
|
+
* amount: 1000000000000000000n, // 1 SODA
|
|
20
|
+
* account: '0x...'
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* console.log('Approval successful:', result);
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function useStakeApprove(
|
|
28
|
+
spokeProvider: SpokeProvider | undefined,
|
|
29
|
+
): UseMutationResult<TxReturnType<SpokeProvider, false>, Error, Omit<StakeParams, 'action'>> {
|
|
30
|
+
const { sodax } = useSodaxContext();
|
|
31
|
+
|
|
32
|
+
return useMutation<TxReturnType<SpokeProvider, false>, Error, Omit<StakeParams, 'action'>>({
|
|
33
|
+
mutationFn: async (params: Omit<StakeParams, 'action'>) => {
|
|
34
|
+
if (!spokeProvider) {
|
|
35
|
+
throw new Error('Spoke provider not found');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const result = await sodax.staking.approve({
|
|
39
|
+
params: { ...params, action: 'stake' },
|
|
40
|
+
spokeProvider,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (!result.ok) {
|
|
44
|
+
throw new Error(`Stake approval failed: ${result.error.code}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return result.value;
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/staking/useStakeRatio.ts
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook for fetching stake ratio estimates (xSoda amount and preview deposit).
|
|
7
|
+
* Uses React Query for efficient caching and state management.
|
|
8
|
+
*
|
|
9
|
+
* @param {bigint | undefined} amount - The amount of SODA to estimate stake for
|
|
10
|
+
* @param {number} refetchInterval - The interval in milliseconds to refetch data (default: 10000)
|
|
11
|
+
* @returns {UseQueryResult<[bigint, bigint], Error>} Query result object containing stake ratio estimates and state
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const { data: stakeRatio, isLoading, error } = useStakeRatio(1000000000000000000n); // 1 SODA
|
|
16
|
+
*
|
|
17
|
+
* if (isLoading) return <div>Loading stake ratio...</div>;
|
|
18
|
+
* if (stakeRatio) {
|
|
19
|
+
* const [xSodaAmount, previewDepositAmount] = stakeRatio;
|
|
20
|
+
* console.log('xSoda amount:', xSodaAmount);
|
|
21
|
+
* console.log('Preview deposit:', previewDepositAmount);
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export function useStakeRatio(
|
|
26
|
+
amount: bigint | undefined,
|
|
27
|
+
refetchInterval = 10000,
|
|
28
|
+
): UseQueryResult<[bigint, bigint], Error> {
|
|
29
|
+
const { sodax } = useSodaxContext();
|
|
30
|
+
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: ['soda', 'stakeRatio', amount?.toString()],
|
|
33
|
+
queryFn: async () => {
|
|
34
|
+
if (!amount || amount <= 0n) {
|
|
35
|
+
throw new Error('Amount must be greater than 0');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!sodax?.staking) {
|
|
39
|
+
throw new Error('Staking service not available');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const result = await sodax.staking.getStakeRatio(amount);
|
|
43
|
+
|
|
44
|
+
if (!result.ok) {
|
|
45
|
+
throw new Error(`Failed to fetch stake ratio: ${result.error.code}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return result.value;
|
|
49
|
+
},
|
|
50
|
+
enabled: !!amount && amount > 0n && !!sodax?.staking,
|
|
51
|
+
refetchInterval,
|
|
52
|
+
});
|
|
53
|
+
}
|