@sodax/dapp-kit 1.5.6-beta → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +300 -422
- package/ai-exported/AGENTS.md +134 -0
- package/ai-exported/integration/README.md +49 -0
- package/ai-exported/integration/ai-rules.md +79 -0
- package/ai-exported/integration/architecture.md +274 -0
- package/ai-exported/integration/features/README.md +29 -0
- package/ai-exported/integration/features/auxiliary-services.md +169 -0
- package/ai-exported/integration/features/bitcoin.md +87 -0
- package/ai-exported/integration/features/bridge.md +91 -0
- package/ai-exported/integration/features/dex.md +152 -0
- package/ai-exported/integration/features/migration.md +118 -0
- package/ai-exported/integration/features/money-market.md +116 -0
- package/ai-exported/integration/features/staking.md +123 -0
- package/ai-exported/integration/features/swap.md +101 -0
- package/ai-exported/integration/quickstart.md +187 -0
- package/ai-exported/integration/recipes/README.md +136 -0
- package/ai-exported/integration/recipes/backend-queries.md +157 -0
- package/ai-exported/integration/recipes/bitcoin.md +193 -0
- package/ai-exported/integration/recipes/bridge.md +174 -0
- package/ai-exported/integration/recipes/dex.md +204 -0
- package/ai-exported/integration/recipes/invalidations.md +115 -0
- package/ai-exported/integration/recipes/migration.md +212 -0
- package/ai-exported/integration/recipes/money-market.md +206 -0
- package/ai-exported/integration/recipes/mutation-error-handling.md +118 -0
- package/ai-exported/integration/recipes/observability.md +93 -0
- package/ai-exported/integration/recipes/setup.md +144 -0
- package/ai-exported/integration/recipes/staking.md +202 -0
- package/ai-exported/integration/recipes/swap.md +272 -0
- package/ai-exported/integration/recipes/wallet-connectivity.md +101 -0
- package/ai-exported/integration/reference/README.md +12 -0
- package/ai-exported/integration/reference/glossary.md +188 -0
- package/ai-exported/integration/reference/hooks-index.md +194 -0
- package/ai-exported/integration/reference/public-api.md +110 -0
- package/ai-exported/integration/reference/querykey-conventions.md +179 -0
- package/ai-exported/migration/README.md +60 -0
- package/ai-exported/migration/ai-rules.md +81 -0
- package/ai-exported/migration/breaking-changes/hook-signatures.md +233 -0
- package/ai-exported/migration/breaking-changes/querykey-conventions.md +108 -0
- package/ai-exported/migration/breaking-changes/result-handling.md +211 -0
- package/ai-exported/migration/breaking-changes/sdk-leakage.md +165 -0
- package/ai-exported/migration/checklist.md +89 -0
- package/ai-exported/migration/features/README.md +34 -0
- package/ai-exported/migration/features/auxiliary-services.md +114 -0
- package/ai-exported/migration/features/bitcoin.md +88 -0
- package/ai-exported/migration/features/bridge.md +123 -0
- package/ai-exported/migration/features/dex.md +101 -0
- package/ai-exported/migration/features/migration.md +120 -0
- package/ai-exported/migration/features/money-market.md +97 -0
- package/ai-exported/migration/features/staking.md +109 -0
- package/ai-exported/migration/features/swap.md +118 -0
- package/ai-exported/migration/recipes.md +188 -0
- package/ai-exported/migration/reference/README.md +15 -0
- package/ai-exported/migration/reference/deleted-hooks.md +110 -0
- package/ai-exported/migration/reference/error-shape-crosswalk.md +144 -0
- package/ai-exported/migration/reference/renamed-hooks.md +66 -0
- package/dist/index.cjs +2642 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1550 -0
- package/dist/index.d.ts +1020 -2051
- package/dist/index.mjs +1594 -1532
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -10
- package/src/contexts/index.ts +0 -3
- package/src/hooks/_mutationContract.test.ts +99 -0
- package/src/hooks/backend/README.md +2 -2
- package/src/hooks/backend/index.ts +13 -13
- package/src/hooks/backend/unwrapResult.ts +1 -0
- package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +13 -45
- package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +29 -59
- package/src/hooks/backend/useBackendIntentByHash.ts +21 -47
- package/src/hooks/backend/useBackendIntentByTxHash.ts +23 -50
- package/src/hooks/backend/useBackendMoneyMarketAsset.ts +21 -54
- package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +30 -57
- package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +31 -58
- package/src/hooks/backend/useBackendMoneyMarketPosition.ts +22 -38
- package/src/hooks/backend/useBackendOrderbook.ts +27 -49
- package/src/hooks/backend/useBackendSubmitSwapTx.ts +30 -36
- package/src/hooks/backend/useBackendSubmitSwapTxStatus.ts +38 -58
- package/src/hooks/backend/useBackendUserIntents.ts +25 -63
- package/src/hooks/bitcoin/index.ts +9 -8
- package/src/hooks/bitcoin/useBitcoinBalance.ts +20 -5
- package/src/hooks/bitcoin/useExpiredUtxos.ts +26 -16
- package/src/hooks/bitcoin/useFundTradingWallet.ts +33 -30
- package/src/hooks/bitcoin/useRadfiAuth.ts +43 -40
- package/src/hooks/bitcoin/useRadfiSession.ts +53 -59
- package/src/hooks/bitcoin/useRadfiWithdraw.ts +35 -53
- package/src/hooks/bitcoin/useRenewUtxos.ts +30 -50
- package/src/hooks/bitcoin/useTradingWallet.ts +1 -1
- package/src/hooks/bitcoin/useTradingWalletBalance.ts +25 -14
- package/src/hooks/bridge/index.ts +5 -5
- package/src/hooks/bridge/useBridge.ts +29 -55
- package/src/hooks/bridge/useBridgeAllowance.ts +38 -38
- package/src/hooks/bridge/useBridgeApprove.ts +32 -57
- package/src/hooks/bridge/useGetBridgeableAmount.ts +23 -37
- package/src/hooks/bridge/useGetBridgeableTokens.ts +27 -50
- package/src/hooks/dex/index.ts +16 -16
- package/src/hooks/dex/useClaimRewards.ts +35 -54
- package/src/hooks/dex/useCreateDecreaseLiquidityParams.ts +7 -20
- package/src/hooks/dex/useCreateDepositParams.ts +7 -21
- package/src/hooks/dex/useCreateSupplyLiquidityParams.ts +13 -28
- package/src/hooks/dex/useCreateWithdrawParams.ts +7 -20
- package/src/hooks/dex/useDecreaseLiquidity.ts +40 -66
- package/src/hooks/dex/useDexAllowance.ts +29 -75
- package/src/hooks/dex/useDexApprove.ts +32 -43
- package/src/hooks/dex/useDexDeposit.ts +42 -49
- package/src/hooks/dex/useDexWithdraw.ts +32 -43
- package/src/hooks/dex/useLiquidityAmounts.ts +27 -84
- package/src/hooks/dex/usePoolBalances.ts +50 -72
- package/src/hooks/dex/usePoolData.ts +17 -43
- package/src/hooks/dex/usePools.ts +11 -38
- package/src/hooks/dex/usePositionInfo.ts +27 -62
- package/src/hooks/dex/useSupplyLiquidity.ts +80 -75
- package/src/hooks/index.ts +12 -10
- package/src/hooks/migrate/index.ts +13 -4
- package/src/hooks/migrate/useMigrateBaln.ts +42 -0
- package/src/hooks/migrate/useMigrateIcxToSoda.ts +44 -0
- package/src/hooks/migrate/useMigratebnUSD.ts +47 -0
- package/src/hooks/migrate/useMigrationAllowance.ts +76 -0
- package/src/hooks/migrate/useMigrationApprove.ts +66 -0
- package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +39 -0
- package/src/hooks/mm/index.ts +14 -12
- package/src/hooks/mm/useAToken.ts +25 -41
- package/src/hooks/mm/useATokensBalances.ts +29 -60
- package/src/hooks/mm/useBorrow.ts +38 -56
- package/src/hooks/mm/useMMAllowance.ts +37 -73
- package/src/hooks/mm/useMMApprove.ts +36 -43
- package/src/hooks/mm/useRepay.ts +33 -53
- package/src/hooks/mm/useReservesData.ts +12 -38
- package/src/hooks/mm/useReservesHumanized.ts +12 -31
- package/src/hooks/mm/useReservesList.ts +11 -31
- package/src/hooks/mm/useReservesUsdFormat.ts +15 -35
- package/src/hooks/mm/useSupply.ts +45 -51
- package/src/hooks/mm/useUserFormattedSummary.ts +32 -84
- package/src/hooks/mm/useUserReservesData.ts +27 -77
- package/src/hooks/mm/useWithdraw.ts +38 -54
- package/src/hooks/partner/index.ts +6 -0
- package/src/hooks/partner/useApproveToken.ts +42 -0
- package/src/hooks/partner/useFeeClaimSwap.ts +38 -0
- package/src/hooks/partner/useFetchAssetsBalances.ts +37 -0
- package/src/hooks/partner/useGetAutoSwapPreferences.ts +37 -0
- package/src/hooks/partner/useIsTokenApproved.ts +39 -0
- package/src/hooks/partner/useSetSwapPreference.ts +50 -0
- package/src/hooks/provider/index.ts +1 -2
- package/src/hooks/provider/useHubProvider.ts +1 -1
- package/src/hooks/recovery/index.ts +2 -0
- package/src/hooks/recovery/useHubAssetBalances.ts +43 -0
- package/src/hooks/recovery/useWithdrawHubAsset.ts +48 -0
- package/src/hooks/shared/index.ts +10 -6
- package/src/hooks/shared/types.ts +77 -0
- package/src/hooks/shared/unwrapResult.ts +19 -0
- package/src/hooks/shared/useDeriveUserWalletAddress.ts +22 -40
- package/src/hooks/shared/useEstimateGas.ts +18 -15
- package/src/hooks/shared/useGetUserHubWalletAddress.ts +25 -26
- package/src/hooks/shared/useRequestTrustline.ts +28 -61
- package/src/hooks/shared/useSafeMutation.test.ts +43 -0
- package/src/hooks/shared/useSafeMutation.ts +68 -0
- package/src/hooks/shared/useSodaxContext.ts +1 -1
- package/src/hooks/shared/useStellarTrustlineCheck.ts +30 -64
- package/src/hooks/shared/useXBalances.test.ts +113 -0
- package/src/hooks/shared/useXBalances.ts +61 -0
- package/src/hooks/staking/index.ts +18 -18
- package/src/hooks/staking/useCancelUnstake.ts +30 -41
- package/src/hooks/staking/useClaim.ts +27 -36
- package/src/hooks/staking/useConvertedAssets.ts +24 -34
- package/src/hooks/staking/useInstantUnstake.ts +33 -40
- package/src/hooks/staking/useInstantUnstakeAllowance.ts +37 -45
- package/src/hooks/staking/useInstantUnstakeApprove.ts +42 -42
- package/src/hooks/staking/useInstantUnstakeRatio.ts +24 -41
- package/src/hooks/staking/useStake.ts +32 -37
- package/src/hooks/staking/useStakeAllowance.ts +30 -43
- package/src/hooks/staking/useStakeApprove.ts +40 -40
- package/src/hooks/staking/useStakeRatio.ts +24 -40
- package/src/hooks/staking/useStakingConfig.ts +14 -27
- package/src/hooks/staking/useStakingInfo.ts +30 -38
- package/src/hooks/staking/useUnstake.ts +29 -43
- package/src/hooks/staking/useUnstakeAllowance.ts +37 -44
- package/src/hooks/staking/useUnstakeApprove.ts +40 -43
- package/src/hooks/staking/useUnstakingInfo.ts +29 -41
- package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +31 -47
- package/src/hooks/swap/index.ts +8 -8
- package/src/hooks/swap/useCancelLimitOrder.ts +24 -41
- package/src/hooks/swap/useCancelSwap.ts +24 -33
- package/src/hooks/swap/useCreateLimitOrder.ts +29 -62
- package/src/hooks/swap/useQuote.ts +17 -43
- package/src/hooks/swap/useStatus.ts +22 -29
- package/src/hooks/swap/useSwap.ts +31 -49
- package/src/hooks/swap/useSwapAllowance.ts +38 -35
- package/src/hooks/swap/useSwapApprove.ts +48 -57
- package/src/index.ts +5 -3
- package/src/providers/SodaxProvider.tsx +17 -11
- package/src/providers/createSodaxQueryClient.ts +96 -0
- package/src/providers/index.ts +2 -1
- package/src/utils/dex-utils.ts +27 -5
- package/src/utils/index.ts +1 -1
- package/dist/index.d.mts +0 -2581
- package/dist/index.js +0 -2562
- package/dist/index.js.map +0 -1
- package/src/hooks/migrate/types.ts +0 -15
- package/src/hooks/migrate/useMigrate.tsx +0 -110
- package/src/hooks/migrate/useMigrationAllowance.tsx +0 -79
- package/src/hooks/migrate/useMigrationApprove.tsx +0 -129
- package/src/hooks/provider/useSpokeProvider.ts +0 -172
|
@@ -1,68 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
1
|
+
// packages/dapp-kit/src/hooks/bridge/useBridgeApprove.ts
|
|
2
|
+
import type { BridgeParams, SpokeChainKey, TxReturnType } from '@sodax/sdk';
|
|
3
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import type { MutationHookParams } from '../shared/types.js';
|
|
6
|
+
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Mutation variables for {@link useBridgeApprove}. Generic over `K extends SpokeChainKey`
|
|
11
|
+
* (defaults to the full union). Sophisticated callers can lock K at the hook call site to narrow
|
|
12
|
+
* the `walletProvider` and `params.srcChainKey` types.
|
|
13
|
+
*/
|
|
14
|
+
export type UseBridgeApproveVars<K extends SpokeChainKey = SpokeChainKey> = Omit<BridgeParams<K, false>, 'raw'>;
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @returns Object containing approve function, loading state, error state and reset function
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* const { approve, isLoading, error } = useBridgeApprove(spokeProvider);
|
|
17
|
+
* React hook for approving ERC-20 token spending (or trustline establishment) for a bridge
|
|
18
|
+
* action.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* srcAsset: '0x...',
|
|
24
|
-
* amount: 1000n,
|
|
25
|
-
* dstChainId: '0x89.polygon',
|
|
26
|
-
* dstAsset: '0x...',
|
|
27
|
-
* recipient: '0x...'
|
|
28
|
-
* });
|
|
29
|
-
* ```
|
|
20
|
+
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
21
|
+
* `onError`, `retry`). Returns the unwrapped tx return value on success. Invalidates all
|
|
22
|
+
* `['bridge', 'allowance', ...]` queries so any pending allowance check refreshes.
|
|
30
23
|
*/
|
|
31
|
-
export function useBridgeApprove
|
|
24
|
+
export function useBridgeApprove<K extends SpokeChainKey = SpokeChainKey>({
|
|
25
|
+
mutationOptions,
|
|
26
|
+
}: MutationHookParams<TxReturnType<K, false>, UseBridgeApproveVars<K>> = {}): SafeUseMutationResult<
|
|
27
|
+
TxReturnType<K, false>,
|
|
28
|
+
Error,
|
|
29
|
+
UseBridgeApproveVars<K>
|
|
30
|
+
> {
|
|
32
31
|
const { sodax } = useSodaxContext();
|
|
33
32
|
const queryClient = useQueryClient();
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!spokeProvider) {
|
|
43
|
-
throw new Error('Spoke provider not found');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const allowance = await sodax.bridge.approve({
|
|
47
|
-
params,
|
|
48
|
-
spokeProvider,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
if (!allowance.ok) {
|
|
52
|
-
throw new Error('Failed to approve tokens for bridge');
|
|
53
|
-
}
|
|
54
|
-
return true;
|
|
55
|
-
},
|
|
56
|
-
onSuccess: (_, params) => {
|
|
57
|
-
// Invalidate allowance query to refetch the new allowance
|
|
58
|
-
queryClient.invalidateQueries({ queryKey: ['bridge-allowance', params] });
|
|
34
|
+
return useSafeMutation<TxReturnType<K, false>, Error, UseBridgeApproveVars<K>>({
|
|
35
|
+
mutationKey: ['bridge', 'approve'],
|
|
36
|
+
...mutationOptions,
|
|
37
|
+
mutationFn: async vars => unwrapResult(await sodax.bridge.approve({ ...vars, raw: false } as BridgeParams<K, false>)),
|
|
38
|
+
onSuccess: async (data, vars, ctx) => {
|
|
39
|
+
queryClient.invalidateQueries({ queryKey: ['bridge', 'allowance'] });
|
|
40
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
59
41
|
},
|
|
60
42
|
});
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
approve,
|
|
64
|
-
isLoading: isPending,
|
|
65
|
-
error: error,
|
|
66
|
-
resetError,
|
|
67
|
-
};
|
|
68
43
|
}
|
|
@@ -1,51 +1,37 @@
|
|
|
1
1
|
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
-
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
3
3
|
import type { BridgeLimit, XToken } from '@sodax/sdk';
|
|
4
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* const { data: balance, isLoading } = useSpokeAssetManagerTokenBalance(chainId, tokenAddress);
|
|
21
|
-
*
|
|
22
|
-
* if (balance) {
|
|
23
|
-
* console.log('Asset manager token balance:', balance.toString());
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export function useGetBridgeableAmount(
|
|
28
|
-
from: XToken | undefined,
|
|
29
|
-
to: XToken | undefined,
|
|
30
|
-
): UseQueryResult<BridgeLimit, Error> {
|
|
6
|
+
export type UseGetBridgeableAmountParams = ReadHookParams<
|
|
7
|
+
BridgeLimit,
|
|
8
|
+
{
|
|
9
|
+
from: XToken | undefined;
|
|
10
|
+
to: XToken | undefined;
|
|
11
|
+
}
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
export function useGetBridgeableAmount({
|
|
15
|
+
params,
|
|
16
|
+
queryOptions,
|
|
17
|
+
}: UseGetBridgeableAmountParams = {}): UseQueryResult<BridgeLimit, Error> {
|
|
31
18
|
const { sodax } = useSodaxContext();
|
|
19
|
+
const from = params?.from;
|
|
20
|
+
const to = params?.to;
|
|
32
21
|
|
|
33
|
-
return useQuery({
|
|
34
|
-
queryKey: ['
|
|
22
|
+
return useQuery<BridgeLimit, Error>({
|
|
23
|
+
queryKey: ['bridge', 'bridgeableAmount', from, to],
|
|
35
24
|
queryFn: async () => {
|
|
36
25
|
if (!from || !to) {
|
|
37
|
-
|
|
26
|
+
throw new Error('from and to tokens are required');
|
|
38
27
|
}
|
|
39
|
-
|
|
40
28
|
const result = await sodax.bridge.getBridgeableAmount(from, to);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return result.value;
|
|
29
|
+
if (!result.ok) {
|
|
30
|
+
throw result.error;
|
|
44
31
|
}
|
|
45
|
-
|
|
46
|
-
console.error('Error getting bridgeable amount:', result.error);
|
|
47
|
-
return { amount: 0n, decimals: 0, type: 'DEPOSIT_LIMIT' } as const;
|
|
32
|
+
return result.value;
|
|
48
33
|
},
|
|
49
34
|
enabled: !!from && !!to,
|
|
35
|
+
...queryOptions,
|
|
50
36
|
});
|
|
51
37
|
}
|
|
@@ -1,62 +1,39 @@
|
|
|
1
1
|
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
-
import type { XToken,
|
|
3
|
-
import { useSodaxContext } from '../shared';
|
|
2
|
+
import type { XToken, SpokeChainKey } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/index.js';
|
|
4
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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> {
|
|
6
|
+
export type UseGetBridgeableTokensParams = ReadHookParams<
|
|
7
|
+
XToken[],
|
|
8
|
+
{
|
|
9
|
+
from: SpokeChainKey | undefined;
|
|
10
|
+
to: SpokeChainKey | undefined;
|
|
11
|
+
token: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
export function useGetBridgeableTokens({
|
|
16
|
+
params,
|
|
17
|
+
queryOptions,
|
|
18
|
+
}: UseGetBridgeableTokensParams = {}): UseQueryResult<XToken[], Error> {
|
|
43
19
|
const { sodax } = useSodaxContext();
|
|
20
|
+
const from = params?.from;
|
|
21
|
+
const to = params?.to;
|
|
22
|
+
const token = params?.token;
|
|
44
23
|
|
|
45
|
-
return useQuery({
|
|
46
|
-
queryKey: ['
|
|
47
|
-
queryFn:
|
|
24
|
+
return useQuery<XToken[], Error>({
|
|
25
|
+
queryKey: ['bridge', 'bridgeableTokens', from, to, token],
|
|
26
|
+
queryFn: () => {
|
|
48
27
|
if (!from || !to || !token) {
|
|
49
|
-
|
|
28
|
+
throw new Error('from, to and token are required');
|
|
50
29
|
}
|
|
51
|
-
|
|
52
30
|
const result = sodax.bridge.getBridgeableTokens(from, to, token);
|
|
53
|
-
if (result.ok) {
|
|
54
|
-
|
|
31
|
+
if (!result.ok) {
|
|
32
|
+
throw result.error;
|
|
55
33
|
}
|
|
56
|
-
|
|
57
|
-
console.error('Error getting bridgeable tokens:', result.error);
|
|
58
|
-
return [];
|
|
34
|
+
return result.value;
|
|
59
35
|
},
|
|
60
36
|
enabled: !!from && !!to && !!token,
|
|
37
|
+
...queryOptions,
|
|
61
38
|
});
|
|
62
39
|
}
|
package/src/hooks/dex/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export * from './usePools';
|
|
2
|
-
export * from './usePoolData';
|
|
3
|
-
export * from './usePoolBalances';
|
|
4
|
-
export * from './usePositionInfo';
|
|
5
|
-
export * from './useDexDeposit';
|
|
6
|
-
export * from './useDexWithdraw';
|
|
7
|
-
export * from './useDexAllowance';
|
|
8
|
-
export * from './useDexApprove';
|
|
9
|
-
export * from './useLiquidityAmounts';
|
|
10
|
-
export * from './useSupplyLiquidity';
|
|
11
|
-
export * from './useDecreaseLiquidity';
|
|
12
|
-
export * from './useCreateDepositParams';
|
|
13
|
-
export * from './useCreateSupplyLiquidityParams';
|
|
14
|
-
export * from './useCreateDecreaseLiquidityParams';
|
|
15
|
-
export * from './useCreateWithdrawParams';
|
|
16
|
-
export * from './useClaimRewards';
|
|
1
|
+
export * from './usePools.js';
|
|
2
|
+
export * from './usePoolData.js';
|
|
3
|
+
export * from './usePoolBalances.js';
|
|
4
|
+
export * from './usePositionInfo.js';
|
|
5
|
+
export * from './useDexDeposit.js';
|
|
6
|
+
export * from './useDexWithdraw.js';
|
|
7
|
+
export * from './useDexAllowance.js';
|
|
8
|
+
export * from './useDexApprove.js';
|
|
9
|
+
export * from './useLiquidityAmounts.js';
|
|
10
|
+
export * from './useSupplyLiquidity.js';
|
|
11
|
+
export * from './useDecreaseLiquidity.js';
|
|
12
|
+
export * from './useCreateDepositParams.js';
|
|
13
|
+
export * from './useCreateSupplyLiquidityParams.js';
|
|
14
|
+
export * from './useCreateDecreaseLiquidityParams.js';
|
|
15
|
+
export * from './useCreateWithdrawParams.js';
|
|
16
|
+
export * from './useClaimRewards.js';
|
|
@@ -1,68 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '@sodax/sdk';
|
|
9
|
-
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
10
|
-
import { useMutation, type UseMutationResult, useQueryClient } from '@tanstack/react-query';
|
|
1
|
+
// packages/dapp-kit/src/hooks/dex/useClaimRewards.ts
|
|
2
|
+
import type { ClLiquidityClaimRewardsAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import type { MutationHookParams } from '../shared/types.js';
|
|
6
|
+
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Mutation variables for {@link useClaimRewards}. Generic over `K extends SpokeChainKey` (defaults
|
|
11
|
+
* to the full union). Sophisticated callers can lock K at the hook call site to narrow the
|
|
12
|
+
* `walletProvider` and `params.srcChainKey` types.
|
|
13
|
+
*/
|
|
14
|
+
export type UseClaimRewardsVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
|
|
15
|
+
ClLiquidityClaimRewardsAction<K, false>,
|
|
16
|
+
'raw'
|
|
17
|
+
>;
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
|
-
* React hook for
|
|
20
|
+
* React hook for claiming accrued fees on a concentrated-liquidity position.
|
|
19
21
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* - On success: resolves to a tuple `[SpokeTxHash, HubTxHash]`.
|
|
23
|
-
* - On error: the error is of type `ConcentratedLiquidityError<ConcentratedLiquidityErrorCode>`.
|
|
24
|
-
* - The mutation function expects an argument of type {@link UseClaimRewardsParams}
|
|
25
|
-
* containing `params` (the claim parameters) and `spokeProvider` (the target provider).
|
|
26
|
-
* - On mutation success, invalidates the queries `'dex/poolBalances'` and `'dex/positionInfo'`.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* const claimRewardsMutation = useClaimRewards();
|
|
30
|
-
* claimRewardsMutation.mutateAsync({
|
|
31
|
-
* params: { poolKey, tokenId, tickLower, tickUpper },
|
|
32
|
-
* spokeProvider,
|
|
33
|
-
* });
|
|
22
|
+
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
23
|
+
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
34
24
|
*/
|
|
35
|
-
export function useClaimRewards(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
export function useClaimRewards<K extends SpokeChainKey = SpokeChainKey>({
|
|
26
|
+
mutationOptions,
|
|
27
|
+
}: MutationHookParams<TxHashPair, UseClaimRewardsVars<K>> = {}): SafeUseMutationResult<
|
|
28
|
+
TxHashPair,
|
|
29
|
+
Error,
|
|
30
|
+
UseClaimRewardsVars<K>
|
|
39
31
|
> {
|
|
40
32
|
const { sodax } = useSodaxContext();
|
|
41
33
|
const queryClient = useQueryClient();
|
|
42
34
|
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
spokeProvider,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
if (!result.ok) {
|
|
54
|
-
throw new Error(`Claim rewards failed: ${result.error?.code || 'Unknown error'}`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return result.value;
|
|
58
|
-
},
|
|
59
|
-
onSuccess: (_, { params, spokeProvider }) => {
|
|
60
|
-
// Invalidate relevant queries
|
|
35
|
+
return useSafeMutation<TxHashPair, Error, UseClaimRewardsVars<K>>({
|
|
36
|
+
mutationKey: ['dex', 'claimRewards'],
|
|
37
|
+
...mutationOptions,
|
|
38
|
+
mutationFn: async vars => unwrapResult(await sodax.dex.clService.claimRewards({ ...vars, raw: false })),
|
|
39
|
+
onSuccess: async (data, vars, ctx) => {
|
|
40
|
+
const { params } = vars;
|
|
41
|
+
// `usePositionInfo` keys by string tokenId — stringify the bigint to keep the structural match.
|
|
61
42
|
queryClient.invalidateQueries({
|
|
62
|
-
queryKey: ['dex', '
|
|
43
|
+
queryKey: ['dex', 'positionInfo', params.tokenId.toString(), params.poolKey],
|
|
63
44
|
});
|
|
64
|
-
queryClient.invalidateQueries({ queryKey: ['dex', '
|
|
65
|
-
|
|
45
|
+
queryClient.invalidateQueries({ queryKey: ['dex', 'poolBalances', params.srcChainKey, params.srcAddress] });
|
|
46
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
66
47
|
},
|
|
67
48
|
});
|
|
68
49
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createDecreaseLiquidityParamsProps } from '@/utils/dex-utils';
|
|
2
|
-
import type { ClPositionInfo,
|
|
1
|
+
import { createDecreaseLiquidityParamsProps, type DecreaseLiquidityParamsCore } from '@/utils/dex-utils.js';
|
|
2
|
+
import type { ClPositionInfo, PoolKey } from '@sodax/sdk';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
|
|
5
5
|
export type UseCreateDecreaseLiquidityParamsProps = {
|
|
@@ -10,23 +10,10 @@ export type UseCreateDecreaseLiquidityParamsProps = {
|
|
|
10
10
|
slippageTolerance: string | number;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
/**
|
|
15
|
-
* React hook to
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* - Provides a hook which memoizes the decrease liquidity parameters for a given pool and position.
|
|
19
|
-
*
|
|
20
|
-
* Usage:
|
|
21
|
-
* - Call the function with the pool key, token ID, percentage, position info, and slippage tolerance to create the decrease liquidity parameters.
|
|
22
|
-
*
|
|
23
|
-
* Params:
|
|
24
|
-
* @param poolKey - The pool key of the pool to decrease the liquidity from.
|
|
25
|
-
* @param tokenId - The token ID of the position to decrease the liquidity from.
|
|
26
|
-
* @param percentage - The percentage of liquidity to decrease.
|
|
27
|
-
* @param positionInfo - The position info of the position to decrease the liquidity from.
|
|
28
|
-
* @param slippageTolerance - The slippage tolerance to use for the decrease.
|
|
29
|
-
* @returns The decrease liquidity parameters.
|
|
14
|
+
* React hook to memoize the decrease-liquidity-specific subset of {@link ClDecreaseLiquidityParams}
|
|
15
|
+
* (`{ poolKey, tokenId, liquidity, amount0Min, amount1Min }`). Callers add `srcChainKey` +
|
|
16
|
+
* `srcAddress` at the mutation call site.
|
|
30
17
|
*/
|
|
31
18
|
export function useCreateDecreaseLiquidityParams({
|
|
32
19
|
poolKey,
|
|
@@ -34,8 +21,8 @@ export function useCreateDecreaseLiquidityParams({
|
|
|
34
21
|
percentage,
|
|
35
22
|
positionInfo,
|
|
36
23
|
slippageTolerance,
|
|
37
|
-
}: UseCreateDecreaseLiquidityParamsProps):
|
|
38
|
-
return useMemo<
|
|
24
|
+
}: UseCreateDecreaseLiquidityParamsProps): DecreaseLiquidityParamsCore {
|
|
25
|
+
return useMemo<DecreaseLiquidityParamsCore>(() => {
|
|
39
26
|
return createDecreaseLiquidityParamsProps({ poolKey, tokenId, percentage, positionInfo, slippageTolerance });
|
|
40
27
|
}, [poolKey, tokenId, percentage, positionInfo, slippageTolerance]);
|
|
41
28
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
import { createDepositParamsProps } from '@/utils/dex-utils';
|
|
2
|
+
import type { PoolData, PoolSpokeAssets } from '@sodax/sdk';
|
|
3
|
+
import { createDepositParamsProps, type DepositParamsCore } from '@/utils/dex-utils.js';
|
|
4
4
|
|
|
5
5
|
export type UseCreateDepositParamsProps = {
|
|
6
6
|
tokenIndex: 0 | 1;
|
|
@@ -9,35 +9,21 @@ export type UseCreateDepositParamsProps = {
|
|
|
9
9
|
poolSpokeAssets: PoolSpokeAssets;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
|
|
13
12
|
/**
|
|
14
|
-
* React hook to
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* - Provides a hook which memoizes the deposit parameters for a given pool and token.
|
|
18
|
-
*
|
|
19
|
-
* Usage:
|
|
20
|
-
* - Call the function with the token index, amount, pool data, pool key, and spoke provider to create the deposit parameters.
|
|
21
|
-
*
|
|
22
|
-
* Params:
|
|
23
|
-
* @param tokenIndex - The index of the token to deposit.
|
|
24
|
-
* @param amount - The amount of the token to deposit.
|
|
25
|
-
* @param poolData - The pool data of the pool to deposit to.
|
|
26
|
-
* @param poolKey - The pool key of the pool to deposit to.
|
|
27
|
-
* @param spokeProvider - The spoke provider to use for the deposit.
|
|
28
|
-
* @returns The deposit parameters or undefined if the pool key, spoke provider, or amount is not set.
|
|
13
|
+
* React hook to memoize the deposit-specific subset of {@link CreateAssetDepositParams}
|
|
14
|
+
* (`{ asset, amount, poolToken, dst? }`). Callers add `srcChainKey` + `srcAddress` at the mutation
|
|
15
|
+
* call site.
|
|
29
16
|
*/
|
|
30
17
|
export function useCreateDepositParams({
|
|
31
18
|
tokenIndex,
|
|
32
19
|
amount,
|
|
33
20
|
poolData,
|
|
34
21
|
poolSpokeAssets,
|
|
35
|
-
}: UseCreateDepositParamsProps):
|
|
36
|
-
return useMemo<
|
|
22
|
+
}: UseCreateDepositParamsProps): DepositParamsCore | undefined {
|
|
23
|
+
return useMemo<DepositParamsCore | undefined>(() => {
|
|
37
24
|
if (!amount || Number.parseFloat(String(amount)) <= 0) {
|
|
38
25
|
return undefined;
|
|
39
26
|
}
|
|
40
|
-
|
|
41
27
|
return createDepositParamsProps({ tokenIndex, amount, poolData, poolSpokeAssets });
|
|
42
28
|
}, [tokenIndex, amount, poolData, poolSpokeAssets]);
|
|
43
29
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { createSupplyLiquidityParamsProps } from '@/utils/dex-utils';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
ConcentratedLiquidityIncreaseLiquidityParams,
|
|
5
|
-
PoolData,
|
|
6
|
-
PoolKey,
|
|
7
|
-
} from '@sodax/sdk';
|
|
1
|
+
import { createSupplyLiquidityParamsProps } from '@/utils/dex-utils.js';
|
|
2
|
+
import type { ClSupplyParams, ClIncreaseLiquidityParams, PoolData, PoolKey } from '@sodax/sdk';
|
|
3
|
+
import type { SpokeChainKey } from '@sodax/sdk';
|
|
8
4
|
import { useMemo } from 'react';
|
|
9
5
|
|
|
10
6
|
export type UseCreateSupplyLiquidityParamsProps = {
|
|
@@ -19,33 +15,22 @@ export type UseCreateSupplyLiquidityParamsProps = {
|
|
|
19
15
|
isValidPosition?: boolean;
|
|
20
16
|
};
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Subset of {@link ClSupplyParams} / {@link ClIncreaseLiquidityParams} produced by
|
|
20
|
+
* {@link useCreateSupplyLiquidityParams}. Callers add `srcChainKey` + `srcAddress` at the mutation
|
|
21
|
+
* call site. `tokenId` and `isValidPosition` distinguish the mint-new vs increase-existing path.
|
|
22
|
+
*/
|
|
23
|
+
export type UseCreateSupplyLiquidityParamsResult = Omit<ClSupplyParams<SpokeChainKey>, 'srcChainKey' | 'srcAddress'> &
|
|
24
|
+
Omit<ClIncreaseLiquidityParams<SpokeChainKey>, 'srcChainKey' | 'srcAddress' | 'tokenId'> & {
|
|
24
25
|
tokenId?: string | bigint;
|
|
25
26
|
positionId?: string | null;
|
|
26
27
|
isValidPosition?: boolean;
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
|
-
* React hook to
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* - Provides a hook which memoizes the supply liquidity parameters for a given pool.
|
|
34
|
-
*
|
|
35
|
-
* Usage:
|
|
36
|
-
* - Call the function with the pool data, pool key, minimum price, maximum price, liquidity token0 amount, liquidity token1 amount, slippage tolerance, position id, and validity of the position to create the supply liquidity parameters.
|
|
37
|
-
*
|
|
38
|
-
* Params:
|
|
39
|
-
* @param poolData - The pool data of the pool to supply liquidity to.
|
|
40
|
-
* @param poolKey - The pool key of the pool to supply liquidity to.
|
|
41
|
-
* @param minPrice - The minimum price of the liquidity to supply.
|
|
42
|
-
* @param maxPrice - The maximum price of the liquidity to supply.
|
|
43
|
-
* @param liquidityToken0Amount - The amount of the token0 to supply.
|
|
44
|
-
* @param liquidityToken1Amount - The amount of the token1 to supply.
|
|
45
|
-
* @param slippageTolerance - The slippage tolerance to use for the supply.
|
|
46
|
-
* @param positionId - The position id of the position to supply liquidity to.
|
|
47
|
-
* @param isValidPosition - Whether the position is valid.
|
|
48
|
-
* @returns The supply liquidity parameters.
|
|
31
|
+
* React hook to memoize concentrated-liquidity supply parameters for a given pool. Returns the
|
|
32
|
+
* pool/tick/liquidity/amount fields without `srcChainKey`/`srcAddress` — callers add those at the
|
|
33
|
+
* mutation call site.
|
|
49
34
|
*/
|
|
50
35
|
export function useCreateSupplyLiquidityParams({
|
|
51
36
|
poolData,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DestinationParamsType, PoolData, PoolSpokeAssets } from '@sodax/sdk';
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
-
import { createWithdrawParamsProps } from '@/utils/dex-utils';
|
|
3
|
+
import { createWithdrawParamsProps, type WithdrawParamsCore } from '@/utils/dex-utils.js';
|
|
4
4
|
|
|
5
5
|
export type UseCreateWithdrawParamsProps = {
|
|
6
6
|
tokenIndex: 0 | 1;
|
|
@@ -11,21 +11,9 @@ export type UseCreateWithdrawParamsProps = {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* React hook to
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* - Provides a hook which memoizes the withdrawal parameters for a given pool and token.
|
|
18
|
-
*
|
|
19
|
-
* Usage:
|
|
20
|
-
* - Call the function with the token index, amount, pool data, pool spoke assets, and destination parameters to create the withdrawal parameters.
|
|
21
|
-
*
|
|
22
|
-
* Params:
|
|
23
|
-
* @param tokenIndex - The index of the token to withdraw.
|
|
24
|
-
* @param amount - The amount of the token to withdraw.
|
|
25
|
-
* @param poolData - The pool data of the pool to withdraw from.
|
|
26
|
-
* @param poolSpokeAssets - The pool spoke assets of the pool to withdraw from.
|
|
27
|
-
* @param dst - The destination parameters for the withdrawal.
|
|
28
|
-
* @returns The withdrawal parameters or undefined if the amount is not set.
|
|
14
|
+
* React hook to memoize the withdraw-specific subset of {@link CreateAssetWithdrawParams}
|
|
15
|
+
* (`{ asset, amount, poolToken, dst? }`). Callers add `srcChainKey` + `srcAddress` at the mutation
|
|
16
|
+
* call site.
|
|
29
17
|
*/
|
|
30
18
|
export function useCreateWithdrawParams({
|
|
31
19
|
tokenIndex,
|
|
@@ -33,12 +21,11 @@ export function useCreateWithdrawParams({
|
|
|
33
21
|
poolData,
|
|
34
22
|
poolSpokeAssets,
|
|
35
23
|
dst,
|
|
36
|
-
}: UseCreateWithdrawParamsProps):
|
|
37
|
-
return useMemo<
|
|
24
|
+
}: UseCreateWithdrawParamsProps): WithdrawParamsCore | undefined {
|
|
25
|
+
return useMemo<WithdrawParamsCore | undefined>(() => {
|
|
38
26
|
if (!amount || Number.parseFloat(String(amount)) <= 0) {
|
|
39
27
|
return undefined;
|
|
40
28
|
}
|
|
41
|
-
|
|
42
29
|
return createWithdrawParamsProps({ tokenIndex, amount, poolData, poolSpokeAssets, dst });
|
|
43
30
|
}, [tokenIndex, amount, poolData, poolSpokeAssets, dst]);
|
|
44
31
|
}
|