@sodax/dapp-kit 2.2.0-rc.1 → 2.2.0-rc.3
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 +2 -0
- package/dist/index.d.ts +599 -3
- package/dist/index.mjs +705 -41
- package/package.json +3 -3
- package/src/hooks/_apiKeyWire.test.ts +384 -18
- package/src/hooks/_mutationContract.test.ts +13 -0
- package/src/hooks/backend/index.ts +4 -0
- package/src/hooks/backend/useBackendOracleCandles.ts +47 -0
- package/src/hooks/backend/useBackendOracleMarkets.ts +30 -0
- package/src/hooks/bitcoin/useFundTradingWallet.ts +2 -1
- package/src/hooks/bitcoin/useRadfiWithdraw.ts +2 -1
- package/src/hooks/bridge/useBridge.ts +2 -2
- package/src/hooks/dex/useDexDeposit.ts +2 -1
- package/src/hooks/dex/useDexWithdraw.ts +2 -1
- package/src/hooks/dex/useSupplyLiquidity.ts +2 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +2 -2
- package/src/hooks/leverageYieldApi/index.ts +55 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiAllowance.ts +50 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApprove.ts +37 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.test.ts +176 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.ts +83 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApr.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiAsset.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCancelIntent.ts +37 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateDepositIntent.ts +37 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateWithdrawIntent.ts +37 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiDeadline.ts +38 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiDepositQuote.ts +57 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiEffectiveApr.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiEstimateGas.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiFilledIntent.ts +40 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntent.ts +40 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentExtraData.ts +42 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentHash.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentPacket.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiLsdApr.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiMaxWithdraw.ts +43 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPartnerFee.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPosition.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewDeposit.ts +43 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewRedeem.ts +43 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewWithdraw.ts +43 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiShareBalance.ts +43 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSolverFee.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiStatus.ts +48 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitIntent.ts +36 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTx.ts +37 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTxStatus.ts +60 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiTotalAssets.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiVault.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiVaults.ts +36 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiWithdrawQuote.ts +56 -0
- package/src/hooks/migrate/useMigrateBaln.ts +2 -2
- package/src/hooks/migrate/useMigrateIcxToSoda.ts +2 -2
- package/src/hooks/migrate/useMigratebnUSD.ts +2 -2
- package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +2 -2
- package/src/hooks/mm/useBorrow.ts +2 -4
- package/src/hooks/mm/useRepay.ts +2 -1
- package/src/hooks/mm/useSupply.ts +2 -1
- package/src/hooks/mm/useWithdraw.ts +2 -4
- package/src/hooks/partner/useFeeClaimWithdraw.ts +2 -1
- package/src/hooks/recovery/useWithdrawHubAsset.ts +2 -1
- package/src/hooks/shared/index.ts +2 -0
- package/src/hooks/shared/invalidateBalances.test.ts +71 -0
- package/src/hooks/shared/invalidateBalances.ts +25 -0
- package/src/hooks/shared/useBalances.test.ts +118 -0
- package/src/hooks/shared/useBalances.ts +81 -0
- package/src/hooks/shared/useEstablishTrustline.test.ts +2 -0
- package/src/hooks/shared/useEstablishTrustline.ts +2 -1
- package/src/hooks/shared/useStellarGate.test.ts +1 -1
- package/src/hooks/sponsoring/useActivateStellarAccount.test.ts +6 -4
- package/src/hooks/sponsoring/useActivateStellarAccount.ts +2 -1
- package/src/hooks/sponsoring/useSponsorConfig.test.ts +8 -2
- package/src/hooks/sponsoring/useStellarAccountActive.test.ts +2 -2
- package/src/hooks/sponsoring/useStellarAccountStatus.test.ts +8 -2
- package/src/hooks/staking/useClaim.ts +2 -1
- package/src/hooks/staking/useInstantUnstake.ts +2 -1
- package/src/hooks/staking/useStake.ts +2 -1
- package/src/hooks/swap/useDetailedStatus.test.ts +2 -2
- package/src/hooks/swap/useSwap.ts +2 -2
- package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.test.ts +5 -1
- package/src/providers/SodaxProvider.test.ts +1 -1
- package/src/utils/approvalPlan.ts +4 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { PreviewWithdrawResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiPreviewWithdrawParams = ReadHookParams<
|
|
9
|
+
PreviewWithdrawResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
vault: string | undefined;
|
|
12
|
+
assets: string | undefined;
|
|
13
|
+
apiConfig?: RequestOverrideConfig;
|
|
14
|
+
}
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React hook to preview the shares burned to withdraw `assets` (ERC-4626 previewWithdraw) via the leverage-yield API —
|
|
19
|
+
* `sodax.api.leverageYield.previewWithdraw`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const { data } = useLeverageYieldApiPreviewWithdraw({ params: { vault: '0x...', assets: '1000000000000000000' } });
|
|
23
|
+
*/
|
|
24
|
+
export const useLeverageYieldApiPreviewWithdraw = ({
|
|
25
|
+
params,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: UseLeverageYieldApiPreviewWithdrawParams = {}): UseQueryResult<PreviewWithdrawResponseV2 | undefined, Error> => {
|
|
28
|
+
const { sodax } = useSodaxContext();
|
|
29
|
+
const vault = params?.vault;
|
|
30
|
+
const assets = params?.assets;
|
|
31
|
+
const apiConfig = params?.apiConfig;
|
|
32
|
+
|
|
33
|
+
return useQuery({
|
|
34
|
+
queryKey: ['leverageYieldApi', 'previewWithdraw', vault, assets],
|
|
35
|
+
queryFn: async (): Promise<PreviewWithdrawResponseV2 | undefined> => {
|
|
36
|
+
if (!vault || assets === undefined) return undefined;
|
|
37
|
+
return unwrapResult(await sodax.api.leverageYield.previewWithdraw({ vault, assets }, apiConfig));
|
|
38
|
+
},
|
|
39
|
+
enabled: !!vault && vault.length > 0 && assets !== undefined,
|
|
40
|
+
retry: retryUnlessAuthFailure,
|
|
41
|
+
...queryOptions,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { ShareBalanceResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiShareBalanceParams = ReadHookParams<
|
|
9
|
+
ShareBalanceResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
vault: string | undefined;
|
|
12
|
+
owner: string | undefined;
|
|
13
|
+
apiConfig?: RequestOverrideConfig;
|
|
14
|
+
}
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React hook to get an owner's vault share (lsoda*) balance via the leverage-yield API —
|
|
19
|
+
* `sodax.api.leverageYield.getShareBalance`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const { data } = useLeverageYieldApiShareBalance({ params: { vault: '0x...', owner: '1000000000000000000' } });
|
|
23
|
+
*/
|
|
24
|
+
export const useLeverageYieldApiShareBalance = ({
|
|
25
|
+
params,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: UseLeverageYieldApiShareBalanceParams = {}): UseQueryResult<ShareBalanceResponseV2 | undefined, Error> => {
|
|
28
|
+
const { sodax } = useSodaxContext();
|
|
29
|
+
const vault = params?.vault;
|
|
30
|
+
const owner = params?.owner;
|
|
31
|
+
const apiConfig = params?.apiConfig;
|
|
32
|
+
|
|
33
|
+
return useQuery({
|
|
34
|
+
queryKey: ['leverageYieldApi', 'shareBalance', vault, owner],
|
|
35
|
+
queryFn: async (): Promise<ShareBalanceResponseV2 | undefined> => {
|
|
36
|
+
if (!vault || owner === undefined) return undefined;
|
|
37
|
+
return unwrapResult(await sodax.api.leverageYield.getShareBalance({ vault, owner }, apiConfig));
|
|
38
|
+
},
|
|
39
|
+
enabled: !!vault && vault.length > 0 && owner !== undefined,
|
|
40
|
+
retry: retryUnlessAuthFailure,
|
|
41
|
+
...queryOptions,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { FeeResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiSolverFeeParams = ReadHookParams<
|
|
9
|
+
FeeResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
amount: string | undefined;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to compute the protocol (solver) fee for a given input amount via the leverage-yield API — `sodax.api.leverageYield.getSolverFee`.
|
|
18
|
+
* Returns `{ fee }` (decimal string).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const { data } = useLeverageYieldApiSolverFee({ params: { amount: '1000000' } });
|
|
22
|
+
*/
|
|
23
|
+
export const useLeverageYieldApiSolverFee = ({
|
|
24
|
+
params,
|
|
25
|
+
queryOptions,
|
|
26
|
+
}: UseLeverageYieldApiSolverFeeParams = {}): UseQueryResult<FeeResponseV2 | undefined, Error> => {
|
|
27
|
+
const { sodax } = useSodaxContext();
|
|
28
|
+
const amount = params?.amount;
|
|
29
|
+
const apiConfig = params?.apiConfig;
|
|
30
|
+
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: ['leverageYieldApi', 'solverFee', amount],
|
|
33
|
+
queryFn: async (): Promise<FeeResponseV2 | undefined> => {
|
|
34
|
+
if (!amount) return undefined;
|
|
35
|
+
return unwrapResult(await sodax.api.leverageYield.getSolverFee({ amount }, apiConfig));
|
|
36
|
+
},
|
|
37
|
+
enabled: !!amount && amount.length > 0,
|
|
38
|
+
retry: retryUnlessAuthFailure,
|
|
39
|
+
...queryOptions,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { RequestOverrideConfig, StatusResponseV2 } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
// Leverage-yield intents share the solver status codes with swaps, so the terminal-status predicate
|
|
8
|
+
// is reused rather than duplicated.
|
|
9
|
+
import { isTerminalSwapIntentStatus } from '../swapsApi/isTerminalSwapIntentStatus.js';
|
|
10
|
+
|
|
11
|
+
export type UseLeverageYieldApiStatusParams = ReadHookParams<
|
|
12
|
+
StatusResponseV2 | undefined,
|
|
13
|
+
{
|
|
14
|
+
intentTxHash: string | undefined;
|
|
15
|
+
apiConfig?: RequestOverrideConfig;
|
|
16
|
+
}
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* React hook for polling the solver intent status by hub-chain intent tx hash via the leverage-yield
|
|
21
|
+
* API — `sodax.api.leverageYield.getStatus`. Returns `{ status, fillTxHash? }`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const { data } = useLeverageYieldApiStatus({ params: { intentTxHash: '0x123...' } });
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* - Default refetch interval is 1 second; stops once `status` is `3` (SOLVED) or `4` (FAILED).
|
|
28
|
+
*/
|
|
29
|
+
export const useLeverageYieldApiStatus = ({
|
|
30
|
+
params,
|
|
31
|
+
queryOptions,
|
|
32
|
+
}: UseLeverageYieldApiStatusParams = {}): UseQueryResult<StatusResponseV2 | undefined, Error> => {
|
|
33
|
+
const { sodax } = useSodaxContext();
|
|
34
|
+
const intentTxHash = params?.intentTxHash;
|
|
35
|
+
const apiConfig = params?.apiConfig;
|
|
36
|
+
|
|
37
|
+
return useQuery({
|
|
38
|
+
queryKey: ['leverageYieldApi', 'status', intentTxHash],
|
|
39
|
+
queryFn: async (): Promise<StatusResponseV2 | undefined> => {
|
|
40
|
+
if (!intentTxHash) return undefined;
|
|
41
|
+
return unwrapResult(await sodax.api.leverageYield.getStatus({ intentTxHash }, apiConfig));
|
|
42
|
+
},
|
|
43
|
+
enabled: !!intentTxHash && intentTxHash.length > 0,
|
|
44
|
+
retry: retryUnlessAuthFailure,
|
|
45
|
+
refetchInterval: query => (isTerminalSwapIntentStatus(query.state.data?.status) ? false : 1000),
|
|
46
|
+
...queryOptions,
|
|
47
|
+
});
|
|
48
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SubmitIntentRequestV2, SubmitIntentResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
3
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
4
|
+
import type { MutationHookParams } from '../shared/types.js';
|
|
5
|
+
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Mutation variables for {@link useLeverageYieldApiSubmitIntent}. The per-request `apiConfig` override belongs here
|
|
9
|
+
* rather than at the hook level — different calls in the same component can target different
|
|
10
|
+
* endpoints without re-rendering.
|
|
11
|
+
*/
|
|
12
|
+
export type UseLeverageYieldApiSubmitIntentVars = {
|
|
13
|
+
body: SubmitIntentRequestV2;
|
|
14
|
+
apiConfig?: RequestOverrideConfig;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React hook to submit the broadcast intent tx to the relay via the leverage-yield API — `sodax.api.leverageYield.submitIntent`.
|
|
19
|
+
*/
|
|
20
|
+
export const useLeverageYieldApiSubmitIntent = ({
|
|
21
|
+
mutationOptions,
|
|
22
|
+
}: MutationHookParams<SubmitIntentResponseV2, UseLeverageYieldApiSubmitIntentVars> = {}): SafeUseMutationResult<
|
|
23
|
+
SubmitIntentResponseV2,
|
|
24
|
+
Error,
|
|
25
|
+
UseLeverageYieldApiSubmitIntentVars
|
|
26
|
+
> => {
|
|
27
|
+
const { sodax } = useSodaxContext();
|
|
28
|
+
|
|
29
|
+
return useSafeMutation<SubmitIntentResponseV2, Error, UseLeverageYieldApiSubmitIntentVars>({
|
|
30
|
+
mutationKey: ['leverageYieldApi', 'submitIntent'],
|
|
31
|
+
retry: false,
|
|
32
|
+
...mutationOptions,
|
|
33
|
+
mutationFn: async ({ body, apiConfig }): Promise<SubmitIntentResponseV2> =>
|
|
34
|
+
unwrapResult(await sodax.api.leverageYield.submitIntent(body, apiConfig)),
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { LeverageYieldSubmitTxRequestV2, SubmitTxResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
3
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
4
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
5
|
+
import type { MutationHookParams } from '../shared/types.js';
|
|
6
|
+
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Mutation variables for {@link useLeverageYieldApiSubmitTx}. The per-request `apiConfig` override belongs here
|
|
10
|
+
* rather than at the hook level — different calls in the same component can target different
|
|
11
|
+
* endpoints without re-rendering.
|
|
12
|
+
*/
|
|
13
|
+
export type UseLeverageYieldApiSubmitTxVars = {
|
|
14
|
+
request: LeverageYieldSubmitTxRequestV2;
|
|
15
|
+
apiConfig?: RequestOverrideConfig;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* React hook to submit a vault-swap transaction to be processed (relay, post-execution, etc.) via the leverage-yield API — `sodax.api.leverageYield.submitTx`.
|
|
20
|
+
*/
|
|
21
|
+
export const useLeverageYieldApiSubmitTx = ({
|
|
22
|
+
mutationOptions,
|
|
23
|
+
}: MutationHookParams<SubmitTxResponseV2, UseLeverageYieldApiSubmitTxVars> = {}): SafeUseMutationResult<
|
|
24
|
+
SubmitTxResponseV2,
|
|
25
|
+
Error,
|
|
26
|
+
UseLeverageYieldApiSubmitTxVars
|
|
27
|
+
> => {
|
|
28
|
+
const { sodax } = useSodaxContext();
|
|
29
|
+
|
|
30
|
+
return useSafeMutation<SubmitTxResponseV2, Error, UseLeverageYieldApiSubmitTxVars>({
|
|
31
|
+
mutationKey: ['leverageYieldApi', 'submitTx'],
|
|
32
|
+
retry: retryUnlessAuthFailure,
|
|
33
|
+
...mutationOptions,
|
|
34
|
+
mutationFn: async ({ request, apiConfig }): Promise<SubmitTxResponseV2> =>
|
|
35
|
+
unwrapResult(await sodax.api.leverageYield.submitTx(request, apiConfig)),
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { isAuthFailure, type RequestOverrideConfig, type SubmitTxStatusResponseV2 } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiSubmitTxStatusParams = ReadHookParams<
|
|
9
|
+
SubmitTxStatusResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
txHash: string | undefined;
|
|
12
|
+
srcChainKey?: string;
|
|
13
|
+
apiConfig?: RequestOverrideConfig;
|
|
14
|
+
}
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React hook for polling the processing status of a submitted vault-swap transaction via the
|
|
19
|
+
* leverage-yield API — `sodax.api.leverageYield.getSubmitTxStatus`. Both `txHash` and `srcChainKey`
|
|
20
|
+
* are required for the query to run.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const { data: status } = useLeverageYieldApiSubmitTxStatus({
|
|
24
|
+
* params: { txHash: '0x123...', srcChainKey: 'sonic' },
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* - Default refetch interval is 1 second; stops on 'solved' or 'failed' status, when the backend
|
|
29
|
+
* marks the submission abandoned (`abandonedAt`) while `status` stays non-terminal, or once the
|
|
30
|
+
* backend rejects the API key (401/403 is terminal — a retry cannot fix it).
|
|
31
|
+
*/
|
|
32
|
+
export const useLeverageYieldApiSubmitTxStatus = ({
|
|
33
|
+
params,
|
|
34
|
+
queryOptions,
|
|
35
|
+
}: UseLeverageYieldApiSubmitTxStatusParams = {}): UseQueryResult<SubmitTxStatusResponseV2 | undefined, Error> => {
|
|
36
|
+
const { sodax } = useSodaxContext();
|
|
37
|
+
const txHash = params?.txHash;
|
|
38
|
+
const srcChainKey = params?.srcChainKey;
|
|
39
|
+
const apiConfig = params?.apiConfig;
|
|
40
|
+
|
|
41
|
+
return useQuery({
|
|
42
|
+
queryKey: ['leverageYieldApi', 'submitTx', 'status', txHash, srcChainKey],
|
|
43
|
+
queryFn: async (): Promise<SubmitTxStatusResponseV2 | undefined> => {
|
|
44
|
+
if (!txHash || !srcChainKey) return undefined;
|
|
45
|
+
return unwrapResult(await sodax.api.leverageYield.getSubmitTxStatus({ txHash, srcChainKey }, apiConfig));
|
|
46
|
+
},
|
|
47
|
+
enabled: !!txHash && txHash.length > 0 && !!srcChainKey,
|
|
48
|
+
retry: retryUnlessAuthFailure,
|
|
49
|
+
refetchInterval: query => {
|
|
50
|
+
// `retry` bounds attempts within a tick, not the interval itself — so stop it here too.
|
|
51
|
+
if (isAuthFailure(query.state.error)) return false;
|
|
52
|
+
const data = query.state.data?.data;
|
|
53
|
+
// `abandonedAt` is terminal even when `status` is still non-terminal — same rule as the
|
|
54
|
+
// SDK's pollBackendSubmitTx and the swaps-api status hook.
|
|
55
|
+
if (data?.status === 'solved' || data?.status === 'failed' || data?.abandonedAt) return false;
|
|
56
|
+
return 1000;
|
|
57
|
+
},
|
|
58
|
+
...queryOptions,
|
|
59
|
+
});
|
|
60
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { VaultTotalAssetsResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiTotalAssetsParams = ReadHookParams<
|
|
9
|
+
VaultTotalAssetsResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
vault: string | undefined;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to fetch the total assets managed by the vault for a leverage-yield vault via the leverage-yield API —
|
|
18
|
+
* `sodax.api.leverageYield.getTotalAssets`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const { data } = useLeverageYieldApiTotalAssets({ params: { vault: '0x...' } });
|
|
22
|
+
*/
|
|
23
|
+
export const useLeverageYieldApiTotalAssets = ({
|
|
24
|
+
params,
|
|
25
|
+
queryOptions,
|
|
26
|
+
}: UseLeverageYieldApiTotalAssetsParams = {}): UseQueryResult<VaultTotalAssetsResponseV2 | undefined, Error> => {
|
|
27
|
+
const { sodax } = useSodaxContext();
|
|
28
|
+
const vault = params?.vault;
|
|
29
|
+
const apiConfig = params?.apiConfig;
|
|
30
|
+
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: ['leverageYieldApi', 'totalAssets', vault],
|
|
33
|
+
queryFn: async (): Promise<VaultTotalAssetsResponseV2 | undefined> => {
|
|
34
|
+
if (!vault) return undefined;
|
|
35
|
+
return unwrapResult(await sodax.api.leverageYield.getTotalAssets({ vault }, apiConfig));
|
|
36
|
+
},
|
|
37
|
+
enabled: !!vault && vault.length > 0,
|
|
38
|
+
retry: retryUnlessAuthFailure,
|
|
39
|
+
...queryOptions,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { GetLeverageVaultResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiVaultParams = ReadHookParams<
|
|
9
|
+
GetLeverageVaultResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
name: string | undefined;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to fetch a single vault descriptor by its lsoda* share-token name via the
|
|
18
|
+
* leverage-yield API — `sodax.api.leverageYield.getVault`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const { data: vault } = useLeverageYieldApiVault({ params: { name: 'lsodaWEETH' } });
|
|
22
|
+
*/
|
|
23
|
+
export const useLeverageYieldApiVault = ({
|
|
24
|
+
params,
|
|
25
|
+
queryOptions,
|
|
26
|
+
}: UseLeverageYieldApiVaultParams = {}): UseQueryResult<GetLeverageVaultResponseV2 | undefined, Error> => {
|
|
27
|
+
const { sodax } = useSodaxContext();
|
|
28
|
+
const name = params?.name;
|
|
29
|
+
const apiConfig = params?.apiConfig;
|
|
30
|
+
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: ['leverageYieldApi', 'vault', name],
|
|
33
|
+
queryFn: async (): Promise<GetLeverageVaultResponseV2 | undefined> => {
|
|
34
|
+
if (!name) return undefined;
|
|
35
|
+
return unwrapResult(await sodax.api.leverageYield.getVault(name, apiConfig));
|
|
36
|
+
},
|
|
37
|
+
enabled: !!name && name.length > 0,
|
|
38
|
+
retry: retryUnlessAuthFailure,
|
|
39
|
+
...queryOptions,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { GetLeverageVaultsResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiVaultsParams = ReadHookParams<
|
|
9
|
+
GetLeverageVaultsResponseV2,
|
|
10
|
+
{
|
|
11
|
+
apiConfig?: RequestOverrideConfig;
|
|
12
|
+
}
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* React hook to fetch the registry of deployed leverage-yield vaults via the leverage-yield API —
|
|
17
|
+
* `sodax.api.leverageYield.getVaults`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const { data: vaults } = useLeverageYieldApiVaults();
|
|
21
|
+
*/
|
|
22
|
+
export const useLeverageYieldApiVaults = ({
|
|
23
|
+
params,
|
|
24
|
+
queryOptions,
|
|
25
|
+
}: UseLeverageYieldApiVaultsParams = {}): UseQueryResult<GetLeverageVaultsResponseV2, Error> => {
|
|
26
|
+
const { sodax } = useSodaxContext();
|
|
27
|
+
const apiConfig = params?.apiConfig;
|
|
28
|
+
|
|
29
|
+
return useQuery<GetLeverageVaultsResponseV2, Error>({
|
|
30
|
+
queryKey: ['leverageYieldApi', 'vaults'],
|
|
31
|
+
queryFn: async (): Promise<GetLeverageVaultsResponseV2> =>
|
|
32
|
+
unwrapResult(await sodax.api.leverageYield.getVaults(apiConfig)),
|
|
33
|
+
retry: retryUnlessAuthFailure,
|
|
34
|
+
...queryOptions,
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type {
|
|
3
|
+
LeverageYieldWithdrawQuoteRequestV2,
|
|
4
|
+
QuoteQueryV2,
|
|
5
|
+
QuoteResponseV2,
|
|
6
|
+
RequestOverrideConfig,
|
|
7
|
+
} from '@sodax/sdk';
|
|
8
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
9
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
10
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
11
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
12
|
+
|
|
13
|
+
export type UseLeverageYieldApiWithdrawQuoteParams = ReadHookParams<
|
|
14
|
+
QuoteResponseV2 | undefined,
|
|
15
|
+
{
|
|
16
|
+
body: LeverageYieldWithdrawQuoteRequestV2 | undefined;
|
|
17
|
+
query?: QuoteQueryV2;
|
|
18
|
+
apiConfig?: RequestOverrideConfig;
|
|
19
|
+
}
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* React hook to quote a swap-style leverage-yield withdraw (lsoda* shares → any token) via the
|
|
24
|
+
* leverage-yield API — `sodax.api.leverageYield.getWithdrawQuote`. Pass `query.includeTxData = true`
|
|
25
|
+
* to also build the unsigned transaction (`srcAddress`/`dstAddress` then required in the body).
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const { data: quote } = useLeverageYieldApiWithdrawQuote({
|
|
29
|
+
* params: {
|
|
30
|
+
* body: {
|
|
31
|
+
* vault: '0x...', srcChainKey: 'sonic', tokenDst: '0x...', tokenDstChainKey: '0xa4b1.arbitrum',
|
|
32
|
+
* amount: '1000000000000000000', quoteType: 'exact_input',
|
|
33
|
+
* },
|
|
34
|
+
* },
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
37
|
+
export const useLeverageYieldApiWithdrawQuote = ({
|
|
38
|
+
params,
|
|
39
|
+
queryOptions,
|
|
40
|
+
}: UseLeverageYieldApiWithdrawQuoteParams = {}): UseQueryResult<QuoteResponseV2 | undefined, Error> => {
|
|
41
|
+
const { sodax } = useSodaxContext();
|
|
42
|
+
const body = params?.body;
|
|
43
|
+
const query = params?.query;
|
|
44
|
+
const apiConfig = params?.apiConfig;
|
|
45
|
+
|
|
46
|
+
return useQuery({
|
|
47
|
+
queryKey: ['leverageYieldApi', 'withdrawQuote', body, query?.includeTxData ?? false],
|
|
48
|
+
queryFn: async (): Promise<QuoteResponseV2 | undefined> => {
|
|
49
|
+
if (!body) return undefined;
|
|
50
|
+
return unwrapResult(await sodax.api.leverageYield.getWithdrawQuote(body, query, apiConfig));
|
|
51
|
+
},
|
|
52
|
+
enabled: !!body,
|
|
53
|
+
retry: retryUnlessAuthFailure,
|
|
54
|
+
...queryOptions,
|
|
55
|
+
});
|
|
56
|
+
};
|
|
@@ -3,6 +3,7 @@ import type { BalnMigrateAction, TxHashPair } from '@sodax/sdk';
|
|
|
3
3
|
import { ChainKeys } from '@sodax/sdk';
|
|
4
4
|
import { useQueryClient } from '@tanstack/react-query';
|
|
5
5
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
6
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
6
7
|
import type { MutationHookParams } from '../shared/types.js';
|
|
7
8
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
8
9
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
@@ -32,8 +33,7 @@ export function useMigrateBaln({
|
|
|
32
33
|
mutationFn: async vars => unwrapResult(await sodax.migration.migrateBaln({ ...vars, raw: false })),
|
|
33
34
|
onSuccess: async (data, vars, ctx) => {
|
|
34
35
|
queryClient.invalidateQueries({ queryKey: ['migrate', 'allowance'] });
|
|
35
|
-
queryClient
|
|
36
|
-
queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', ChainKeys.SONIC_MAINNET] });
|
|
36
|
+
invalidateBalances(queryClient, ChainKeys.ICON_MAINNET, ChainKeys.SONIC_MAINNET);
|
|
37
37
|
// BALN with stake=true affects staking info too; cheap broad invalidation.
|
|
38
38
|
queryClient.invalidateQueries({ queryKey: ['staking', 'info'] });
|
|
39
39
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
@@ -3,6 +3,7 @@ import type { IcxMigrateAction, TxHashPair } from '@sodax/sdk';
|
|
|
3
3
|
import { ChainKeys } from '@sodax/sdk';
|
|
4
4
|
import { useQueryClient } from '@tanstack/react-query';
|
|
5
5
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
6
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
6
7
|
import type { MutationHookParams } from '../shared/types.js';
|
|
7
8
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
8
9
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
@@ -36,8 +37,7 @@ export function useMigrateIcxToSoda({
|
|
|
36
37
|
mutationFn: async vars => unwrapResult(await sodax.migration.migrateIcxToSoda({ ...vars, raw: false })),
|
|
37
38
|
onSuccess: async (data, vars, ctx) => {
|
|
38
39
|
queryClient.invalidateQueries({ queryKey: ['migrate', 'allowance'] });
|
|
39
|
-
queryClient
|
|
40
|
-
queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', ChainKeys.SONIC_MAINNET] });
|
|
40
|
+
invalidateBalances(queryClient, vars.params.srcChainKey, ChainKeys.SONIC_MAINNET);
|
|
41
41
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
42
42
|
},
|
|
43
43
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { SpokeChainKey, TxHashPair, UnifiedBnUSDMigrateAction } from '@sodax/sdk';
|
|
3
3
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
5
6
|
import type { MutationHookParams } from '../shared/types.js';
|
|
6
7
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
@@ -39,8 +40,7 @@ export function useMigratebnUSD<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
39
40
|
onSuccess: async (data, vars, ctx) => {
|
|
40
41
|
const { params } = vars;
|
|
41
42
|
queryClient.invalidateQueries({ queryKey: ['migrate', 'allowance'] });
|
|
42
|
-
queryClient
|
|
43
|
-
queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', params.dstChainKey] });
|
|
43
|
+
invalidateBalances(queryClient, params.srcChainKey, params.dstChainKey);
|
|
44
44
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
45
45
|
},
|
|
46
46
|
});
|
|
@@ -3,6 +3,7 @@ import type { IcxRevertMigrationAction, TxHashPair } from '@sodax/sdk';
|
|
|
3
3
|
import { ChainKeys } from '@sodax/sdk';
|
|
4
4
|
import { useQueryClient } from '@tanstack/react-query';
|
|
5
5
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
6
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
6
7
|
import type { MutationHookParams } from '../shared/types.js';
|
|
7
8
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
8
9
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
@@ -31,8 +32,7 @@ export function useRevertMigrateSodaToIcx({
|
|
|
31
32
|
mutationFn: async vars => unwrapResult(await sodax.migration.revertMigrateSodaToIcx({ ...vars, raw: false })),
|
|
32
33
|
onSuccess: async (data, vars, ctx) => {
|
|
33
34
|
queryClient.invalidateQueries({ queryKey: ['migrate', 'allowance'] });
|
|
34
|
-
queryClient
|
|
35
|
-
queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', ChainKeys.ICON_MAINNET] });
|
|
35
|
+
invalidateBalances(queryClient, vars.params.srcChainKey, ChainKeys.ICON_MAINNET);
|
|
36
36
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
37
37
|
},
|
|
38
38
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { MoneyMarketBorrowActionParams, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
3
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
5
6
|
import type { MutationHookParams } from '../shared/types.js';
|
|
6
7
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
@@ -39,10 +40,7 @@ export function useBorrow<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
39
40
|
queryKey: ['mm', 'userFormattedSummary', params.srcChainKey, params.srcAddress],
|
|
40
41
|
});
|
|
41
42
|
queryClient.invalidateQueries({ queryKey: ['mm', 'aTokensBalances'] });
|
|
42
|
-
|
|
43
|
-
for (const chainKey of balanceChains) {
|
|
44
|
-
queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', chainKey] });
|
|
45
|
-
}
|
|
43
|
+
invalidateBalances(queryClient, params.srcChainKey, params.dstChainKey);
|
|
46
44
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
47
45
|
},
|
|
48
46
|
});
|
package/src/hooks/mm/useRepay.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { MoneyMarketRepayActionParams, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
3
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
5
6
|
import type { MutationHookParams } from '../shared/types.js';
|
|
6
7
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
@@ -37,7 +38,7 @@ export function useRepay<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
37
38
|
});
|
|
38
39
|
queryClient.invalidateQueries({ queryKey: ['mm', 'aTokensBalances'] });
|
|
39
40
|
queryClient.invalidateQueries({ queryKey: ['mm', 'allowance', params.srcChainKey, params.token, params.action] });
|
|
40
|
-
queryClient
|
|
41
|
+
invalidateBalances(queryClient, params.srcChainKey);
|
|
41
42
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
42
43
|
},
|
|
43
44
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { MoneyMarketSupplyActionParams, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
3
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
5
6
|
import type { MutationHookParams } from '../shared/types.js';
|
|
6
7
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
@@ -52,7 +53,7 @@ export function useSupply<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
52
53
|
});
|
|
53
54
|
queryClient.invalidateQueries({ queryKey: ['mm', 'aTokensBalances'] });
|
|
54
55
|
queryClient.invalidateQueries({ queryKey: ['mm', 'allowance', params.srcChainKey, params.token, params.action] });
|
|
55
|
-
queryClient
|
|
56
|
+
invalidateBalances(queryClient, params.srcChainKey);
|
|
56
57
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
57
58
|
},
|
|
58
59
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { MoneyMarketWithdrawActionParams, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
3
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
5
6
|
import type { MutationHookParams } from '../shared/types.js';
|
|
6
7
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
@@ -43,10 +44,7 @@ export function useWithdraw<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
43
44
|
queryKey: ['mm', 'userFormattedSummary', params.srcChainKey, params.srcAddress],
|
|
44
45
|
});
|
|
45
46
|
queryClient.invalidateQueries({ queryKey: ['mm', 'aTokensBalances'] });
|
|
46
|
-
|
|
47
|
-
for (const chainKey of balanceChains) {
|
|
48
|
-
queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', chainKey] });
|
|
49
|
-
}
|
|
47
|
+
invalidateBalances(queryClient, params.srcChainKey, params.dstChainKey);
|
|
50
48
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
51
49
|
},
|
|
52
50
|
});
|