@sodax/dapp-kit 2.4.0-rc.2 → 2.4.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 +1 -1
- package/dist/index.d.ts +279 -2428
- package/dist/index.mjs +15 -24
- package/package.json +2 -2
- package/src/hooks/_apiKeyWire.test.ts +4 -29
- package/src/hooks/_mutationContract.test.ts +1 -8
- package/src/hooks/backend/index.ts +0 -13
- package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +0 -6
- package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +0 -10
- package/src/hooks/backend/useBackendIntentByHash.ts +0 -6
- package/src/hooks/backend/useBackendIntentByTxHash.ts +1 -10
- package/src/hooks/backend/useBackendMoneyMarketAsset.ts +0 -6
- package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +0 -8
- package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +0 -8
- package/src/hooks/backend/useBackendMoneyMarketPosition.ts +0 -6
- package/src/hooks/backend/useBackendOracleCandles.ts +1 -9
- package/src/hooks/backend/useBackendOracleMarkets.ts +1 -7
- package/src/hooks/backend/useBackendOrderbook.ts +0 -6
- package/src/hooks/backend/useBackendUserIntents.ts +0 -8
- package/src/hooks/bitcoin/resolveBtcReadAddress.test.ts +1 -3
- package/src/hooks/bitcoin/resolveBtcReadAddress.ts +2 -12
- package/src/hooks/bitcoin/useBitcoinBalance.ts +1 -7
- package/src/hooks/bitcoin/useBitcoinTradingSetup.ts +2 -4
- package/src/hooks/bitcoin/useEnsureRadfiAccessToken.ts +2 -13
- package/src/hooks/bitcoin/useFundTradingWallet.ts +0 -6
- package/src/hooks/bitcoin/useRadfiAuth.ts +1 -6
- package/src/hooks/bitcoin/useRadfiSession.ts +0 -1
- package/src/hooks/bitcoin/useRadfiWithdraw.ts +0 -6
- package/src/hooks/bitcoin/useRenewUtxos.ts +0 -5
- package/src/hooks/bitcoin/useTradingWallet.ts +1 -4
- package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.test.ts +1 -7
- package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.ts +7 -21
- package/src/hooks/bridge/useBridge.test.ts +1 -11
- package/src/hooks/bridge/useBridge.ts +2 -12
- package/src/hooks/bridge/useBridgeAllowance.ts +1 -2
- package/src/hooks/bridge/useBridgeApprovalStrategy.ts +2 -6
- package/src/hooks/bridge/useBridgeApprove.ts +2 -14
- package/src/hooks/bridge/useBridgeDetailedStatus.test.ts +2 -11
- package/src/hooks/bridge/useBridgeDetailedStatus.ts +3 -23
- package/src/hooks/bridge/useBridgeWithApproval.ts +2 -11
- package/src/hooks/bridgeApi/getBridgeSubmitTxStatusRefetchInterval.test.ts +2 -7
- package/src/hooks/bridgeApi/getBridgeSubmitTxStatusRefetchInterval.ts +2 -13
- package/src/hooks/bridgeApi/index.ts +11 -14
- package/src/hooks/bridgeApi/useBridgeApiAllowance.ts +1 -9
- package/src/hooks/bridgeApi/useBridgeApiApprove.ts +2 -17
- package/src/hooks/bridgeApi/useBridgeApiApproveAndBroadcast.test.ts +2 -13
- package/src/hooks/bridgeApi/useBridgeApiApproveAndBroadcast.ts +3 -20
- package/src/hooks/bridgeApi/useBridgeApiBridgeableAmount.ts +1 -12
- package/src/hooks/bridgeApi/useBridgeApiCreateBridgeIntent.ts +1 -14
- package/src/hooks/bridgeApi/useBridgeApiFee.ts +2 -11
- package/src/hooks/bridgeApi/useBridgeApiIsBridgeable.ts +1 -12
- package/src/hooks/bridgeApi/useBridgeApiSubmitTx.ts +2 -23
- package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.test.ts +1 -9
- package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.ts +1 -19
- package/src/hooks/bridgeApi/useBridgeApiTokens.ts +0 -8
- package/src/hooks/bridgeApi/useBridgeApiTokensByChain.ts +0 -7
- package/src/hooks/dex/useClaimRewards.ts +1 -12
- package/src/hooks/dex/useCreateDecreaseLiquidityParams.ts +1 -5
- package/src/hooks/dex/useCreateDepositParams.ts +1 -5
- package/src/hooks/dex/useCreateSupplyLiquidityParams.ts +1 -10
- package/src/hooks/dex/useCreateWithdrawParams.ts +1 -5
- package/src/hooks/dex/useDecreaseLiquidity.ts +2 -15
- package/src/hooks/dex/useDexAllowance.ts +1 -5
- package/src/hooks/dex/useDexApprove.ts +1 -12
- package/src/hooks/dex/useDexDeposit.ts +1 -23
- package/src/hooks/dex/useDexWithdraw.ts +1 -13
- package/src/hooks/dex/useLiquidityAmounts.ts +1 -4
- package/src/hooks/dex/usePoolBalances.ts +0 -4
- package/src/hooks/dex/usePoolData.ts +1 -4
- package/src/hooks/dex/usePools.ts +1 -4
- package/src/hooks/dex/usePositionInfo.ts +1 -4
- package/src/hooks/dex/useSupplyLiquidity.ts +3 -20
- package/src/hooks/leverageYield/useApproveLeveragePositionFunding.ts +2 -8
- package/src/hooks/leverageYield/useLeveragePositionAccount.ts +2 -13
- package/src/hooks/leverageYield/useLeveragePositionCollateral.ts +2 -14
- package/src/hooks/leverageYield/useLeveragePositionFundingAllowance.ts +2 -9
- package/src/hooks/leverageYield/useLeveragePositionInfo.ts +1 -13
- package/src/hooks/leverageYield/useLeveragePositionPayoutAddress.ts +3 -15
- package/src/hooks/leverageYield/useLeveragePositionPending.ts +2 -16
- package/src/hooks/leverageYield/useLeveragePositions.ts +1 -15
- package/src/hooks/leverageYield/useLeveragePositionsForUser.ts +1 -15
- package/src/hooks/leverageYield/useLeverageYieldApprovalStrategy.ts +1 -6
- package/src/hooks/leverageYield/useLeverageYieldDeposit.ts +1 -17
- package/src/hooks/leverageYield/useLeverageYieldDetailedStatus.test.ts +3 -14
- package/src/hooks/leverageYield/useLeverageYieldDetailedStatus.ts +2 -19
- package/src/hooks/leverageYield/useLeverageYieldEffectiveApr.ts +1 -12
- package/src/hooks/leverageYield/useLeverageYieldNotifySolver.ts +1 -11
- package/src/hooks/leverageYield/useLeverageYieldPosition.ts +1 -13
- package/src/hooks/leverageYield/useLeverageYieldPreviewRedeem.ts +1 -12
- package/src/hooks/leverageYield/useLeverageYieldQuote.test.ts +3 -13
- package/src/hooks/leverageYield/useLeverageYieldQuote.ts +5 -54
- package/src/hooks/leverageYield/useLeverageYieldShareBalances.ts +2 -29
- package/src/hooks/leverageYield/useLeverageYieldTotalAssets.ts +1 -9
- package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +2 -25
- package/src/hooks/leverageYield/useLeverageYieldVaultSwapWithApproval.ts +1 -11
- package/src/hooks/leverageYield/useLeverageYieldWithdraw.ts +1 -17
- package/src/hooks/leverageYield/useOpenLeveragePosition.ts +5 -18
- package/src/hooks/leverageYield/useRunLeveragePositionOperation.ts +4 -20
- package/src/hooks/leverageYield/useSubmitLeveragePositionIntent.ts +3 -15
- package/src/hooks/leverageYieldApi/index.ts +0 -15
- package/src/hooks/leverageYieldApi/useLeverageYieldApiAllowance.ts +1 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApprove.ts +3 -6
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.test.ts +4 -14
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.ts +4 -26
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApr.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiAsset.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCancelIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateDepositIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateWithdrawIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiDeadline.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiDepositQuote.ts +1 -15
- package/src/hooks/leverageYieldApi/useLeverageYieldApiEffectiveApr.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiEstimateGas.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiFilledIntent.ts +1 -6
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntent.ts +1 -6
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentExtraData.ts +1 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentHash.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentPacket.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiLsdApr.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiMaxWithdraw.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPartnerFee.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPosition.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewDeposit.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewRedeem.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewWithdraw.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiShareBalance.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSolverFee.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiStatus.ts +2 -12
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTx.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTxStatus.ts +2 -17
- package/src/hooks/leverageYieldApi/useLeverageYieldApiTotalAssets.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiVault.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiVaults.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiWithdrawQuote.ts +1 -15
- package/src/hooks/migrate/useMigrateBaln.ts +1 -8
- package/src/hooks/migrate/useMigrateIcxToSoda.ts +1 -12
- package/src/hooks/migrate/useMigratebnUSD.ts +1 -12
- package/src/hooks/migrate/useMigrationAllowance.ts +3 -19
- package/src/hooks/migrate/useMigrationApprove.ts +2 -20
- package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +0 -7
- package/src/hooks/mm/useAToken.ts +1 -6
- package/src/hooks/mm/useATokensBalances.ts +0 -5
- package/src/hooks/mm/useBorrow.ts +1 -13
- package/src/hooks/mm/useEModes.ts +2 -13
- package/src/hooks/mm/useMMAllowance.test.ts +55 -0
- package/src/hooks/mm/useMMAllowance.ts +6 -16
- package/src/hooks/mm/useMMApprove.ts +1 -14
- package/src/hooks/mm/useRepay.ts +1 -12
- package/src/hooks/mm/useReservesData.ts +0 -4
- package/src/hooks/mm/useReservesHumanized.ts +0 -4
- package/src/hooks/mm/useReservesList.ts +0 -4
- package/src/hooks/mm/useReservesUsdFormat.ts +0 -4
- package/src/hooks/mm/useSupply.ts +1 -24
- package/src/hooks/mm/useUserFormattedSummary.ts +0 -7
- package/src/hooks/mm/useUserReservesData.ts +0 -4
- package/src/hooks/mm/useWithdraw.ts +1 -13
- package/src/hooks/partner/useApproveToken.ts +1 -7
- package/src/hooks/partner/useFeeClaimSwap.ts +1 -7
- package/src/hooks/partner/useFeeClaimWithdraw.ts +3 -20
- package/src/hooks/partner/useFetchAssetsBalances.ts +0 -4
- package/src/hooks/partner/useGetAutoSwapPreferences.ts +0 -4
- package/src/hooks/partner/useGetIntentDetails.ts +1 -8
- package/src/hooks/partner/useGetUserIntent.ts +1 -8
- package/src/hooks/partner/useIsTokenApproved.ts +0 -4
- package/src/hooks/partner/usePartnerCancelIntent.ts +2 -9
- package/src/hooks/partner/useSetSwapPreference.ts +1 -14
- package/src/hooks/recovery/useHubAssetBalances.ts +1 -6
- package/src/hooks/recovery/useWithdrawHubAsset.ts +1 -13
- package/src/hooks/shared/invalidateBalances.ts +2 -10
- package/src/hooks/shared/isUserRejectedError.test.ts +0 -3
- package/src/hooks/shared/isUserRejectedError.ts +2 -23
- package/src/hooks/shared/notFoundStreak.ts +5 -22
- package/src/hooks/shared/retryUnlessAuthFailure.test.ts +1 -2
- package/src/hooks/shared/retryUnlessAuthFailure.ts +1 -12
- package/src/hooks/shared/solverStatusPolicy.test.ts +0 -5
- package/src/hooks/shared/solverStatusPolicy.ts +8 -58
- package/src/hooks/shared/types.ts +4 -55
- package/src/hooks/shared/unwrapResult.ts +1 -8
- package/src/hooks/shared/useBalances.ts +6 -39
- package/src/hooks/shared/useEstablishTrustline.test.ts +1 -5
- package/src/hooks/shared/useEstablishTrustline.ts +3 -13
- package/src/hooks/shared/useEstablishXrpTrustline.test.ts +1 -2
- package/src/hooks/shared/useEstablishXrpTrustline.ts +3 -5
- package/src/hooks/shared/useEstimateGas.ts +0 -1
- package/src/hooks/shared/useGetUserHubWalletAddress.ts +1 -18
- package/src/hooks/shared/useNearStorageCheck.ts +2 -9
- package/src/hooks/shared/useNearStorageGate.ts +5 -15
- package/src/hooks/shared/useRegisterNearStorage.ts +2 -10
- package/src/hooks/shared/useRequestTrustline.test.ts +1 -7
- package/src/hooks/shared/useRequestTrustline.ts +4 -14
- package/src/hooks/shared/useSafeMutation.test.ts +0 -3
- package/src/hooks/shared/useSafeMutation.ts +2 -26
- package/src/hooks/shared/useSodaxContext.ts +0 -6
- package/src/hooks/shared/useStellarGate.test.ts +2 -9
- package/src/hooks/shared/useStellarGate.ts +3 -9
- package/src/hooks/shared/useStellarTrustlineCheck.test.ts +0 -2
- package/src/hooks/shared/useStellarTrustlineCheck.ts +1 -4
- package/src/hooks/shared/useXBalances.ts +2 -20
- package/src/hooks/shared/useXrpDestinationCheck.ts +1 -5
- package/src/hooks/shared/useXrpGate.test.ts +1 -3
- package/src/hooks/shared/useXrpGate.ts +2 -3
- package/src/hooks/shared/waitForApiAllowance.test.ts +0 -1
- package/src/hooks/shared/waitForApiAllowance.ts +2 -6
- package/src/hooks/sponsoring/useActivateStellarAccount.test.ts +1 -2
- package/src/hooks/sponsoring/useActivateStellarAccount.ts +1 -5
- package/src/hooks/sponsoring/useActivateStellarAccount.wire.test.ts +2 -13
- package/src/hooks/sponsoring/useSponsorConfig.ts +0 -1
- package/src/hooks/sponsoring/useStellarAccountActive.ts +0 -1
- package/src/hooks/sponsoring/useStellarAccountStatus.ts +1 -4
- package/src/hooks/staking/index.ts +0 -1
- package/src/hooks/staking/useCancelUnstake.ts +1 -7
- package/src/hooks/staking/useClaim.ts +1 -7
- package/src/hooks/staking/useConvertedAssets.ts +1 -4
- package/src/hooks/staking/useInstantUnstake.ts +1 -7
- package/src/hooks/staking/useInstantUnstakeAllowance.ts +1 -5
- package/src/hooks/staking/useInstantUnstakeApprove.ts +1 -11
- package/src/hooks/staking/useInstantUnstakeRatio.ts +1 -4
- package/src/hooks/staking/useStake.ts +1 -12
- package/src/hooks/staking/useStakeAllowance.ts +1 -5
- package/src/hooks/staking/useStakeApprove.ts +1 -11
- package/src/hooks/staking/useStakeRatio.ts +1 -4
- package/src/hooks/staking/useStakingConfig.ts +1 -4
- package/src/hooks/staking/useStakingInfo.ts +1 -5
- package/src/hooks/staking/useUnstake.ts +2 -9
- package/src/hooks/staking/useUnstakeAllowance.ts +1 -5
- package/src/hooks/staking/useUnstakeApprove.ts +1 -10
- package/src/hooks/staking/useUnstakingInfo.ts +1 -4
- package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +1 -4
- package/src/hooks/swap/useCancelLimitOrder.ts +1 -7
- package/src/hooks/swap/useCancelSwap.ts +1 -7
- package/src/hooks/swap/useCreateLimitOrder.ts +2 -12
- package/src/hooks/swap/useDetailedStatus.test.ts +6 -18
- package/src/hooks/swap/useDetailedStatus.ts +2 -19
- package/src/hooks/swap/useQuote.test.ts +2 -8
- package/src/hooks/swap/useQuote.ts +5 -32
- package/src/hooks/swap/useStatus.ts +2 -10
- package/src/hooks/swap/useSwap.test.ts +1 -11
- package/src/hooks/swap/useSwap.ts +2 -12
- package/src/hooks/swap/useSwapAllowance.ts +1 -2
- package/src/hooks/swap/useSwapApprovalStrategy.ts +2 -7
- package/src/hooks/swap/useSwapApprove.ts +2 -14
- package/src/hooks/swap/useSwapLifecycle.test.ts +1 -2
- package/src/hooks/swap/useSwapLifecycle.ts +9 -27
- package/src/hooks/swap/useSwapWithApproval.ts +2 -11
- package/src/hooks/swapsApi/index.ts +2 -14
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.test.ts +1 -5
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.ts +1 -7
- package/src/hooks/swapsApi/useSwapsApiAllowance.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiApprove.ts +1 -14
- package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.test.ts +5 -20
- package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.ts +3 -24
- package/src/hooks/swapsApi/useSwapsApiBroadcastWithApproval.test.ts +2 -8
- package/src/hooks/swapsApi/useSwapsApiBroadcastWithApproval.ts +6 -41
- package/src/hooks/swapsApi/useSwapsApiCancelIntent.ts +0 -13
- package/src/hooks/swapsApi/useSwapsApiCreateIntent.ts +0 -13
- package/src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts +1 -13
- package/src/hooks/swapsApi/useSwapsApiDeadline.ts +1 -7
- package/src/hooks/swapsApi/useSwapsApiEstimateGas.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiFilledIntent.ts +0 -8
- package/src/hooks/swapsApi/useSwapsApiIntent.ts +1 -7
- package/src/hooks/swapsApi/useSwapsApiIntentExtraData.ts +1 -8
- package/src/hooks/swapsApi/useSwapsApiIntentHash.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiIntentPacket.ts +1 -10
- package/src/hooks/swapsApi/useSwapsApiPartnerFee.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiQuote.ts +2 -24
- package/src/hooks/swapsApi/useSwapsApiSolverFee.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiStatus.ts +1 -11
- package/src/hooks/swapsApi/useSwapsApiSubmitIntent.ts +1 -15
- package/src/hooks/swapsApi/useSwapsApiSubmitTx.ts +0 -21
- package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +2 -19
- package/src/hooks/swapsApi/useSwapsApiTokens.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiTokensByChain.ts +0 -7
- package/src/index.ts +1 -1
- package/src/providers/SodaxProvider.test.ts +2 -9
- package/src/providers/SodaxProvider.tsx +1 -12
- package/src/providers/createSodaxQueryClient.ts +4 -56
- package/src/utils/approvalPlan.ts +9 -32
- package/src/utils/dex-utils.ts +5 -20
- package/src/utils/nearStorageGate.ts +3 -14
- package/src/utils/stellarGate.ts +3 -16
- package/src/utils/swapLifecycle.ts +7 -26
- package/src/utils/xrpGate.ts +1 -4
|
@@ -5,34 +5,13 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
5
5
|
import type { MutationHookParams } from '../shared/types.js';
|
|
6
6
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Mutation variables for {@link useBridgeApiSubmitTx}. The per-request `apiConfig` override
|
|
10
|
-
* (e.g. base URL) belongs here rather than at the hook level — different submissions in the same
|
|
11
|
-
* component can target different endpoints without re-rendering.
|
|
12
|
-
*/
|
|
13
8
|
export type UseBridgeApiSubmitTxVars = {
|
|
14
9
|
request: BridgeSubmitTxRequestV2;
|
|
15
10
|
apiConfig?: RequestOverrideConfig;
|
|
16
11
|
};
|
|
17
12
|
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* (relayed server-side) via the bridge API — `sodax.api.bridge.submitTx`. Called AFTER signing +
|
|
21
|
-
* broadcasting the spoke-deposit tx, handing it (with the FULL `relayData { address, payload }`
|
|
22
|
-
* envelope) to the backend.
|
|
23
|
-
*
|
|
24
|
-
* Pure mutation: pass `{ request, apiConfig? }` to `mutate({...})`. Retries up to 3 times at the
|
|
25
|
-
* hook level, except on a terminal API-key rejection (401/403) — see `retryUnlessAuthFailure`.
|
|
26
|
-
* Consumers can override via `mutationOptions.retry`.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* const { mutateAsync: submitBridgeTx, isPending, error } = useBridgeApiSubmitTx();
|
|
30
|
-
*
|
|
31
|
-
* const result = await submitBridgeTx({
|
|
32
|
-
* request: { txHash: '0x123...', srcChainKey: '0xa4b1.arbitrum', walletAddress: '0xabc...', relayData: { address: '0x...', payload: '0x...' } },
|
|
33
|
-
* apiConfig: { baseURL: 'https://...' },
|
|
34
|
-
* });
|
|
35
|
-
*/
|
|
13
|
+
/** Call after broadcasting the spoke-deposit tx, passing the FULL `relayData { address, payload }` envelope.
|
|
14
|
+
* Retries up to 3 times except on API-key rejection (401/403). */
|
|
36
15
|
export const useBridgeApiSubmitTx = ({
|
|
37
16
|
mutationOptions,
|
|
38
17
|
}: MutationHookParams<BridgeSubmitTxResponseV2, UseBridgeApiSubmitTxVars> = {}): SafeUseMutationResult<
|
|
@@ -2,15 +2,7 @@ import { SodaxError } from '@sodax/sdk';
|
|
|
2
2
|
import { describe, expect, it, vi } from 'vitest';
|
|
3
3
|
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* Pins the WIRING of the auth stop, which `getBridgeSubmitTxStatusRefetchInterval.test.ts` cannot
|
|
7
|
-
* see: the policy is only reached if the hook hands it `query.state.error`. Passing the wrong
|
|
8
|
-
* argument (or none) reproduces the original defect — a rejected key re-requested every second —
|
|
9
|
-
* with the policy's own unit tests still green.
|
|
10
|
-
*
|
|
11
|
-
* No renderer, per the package convention (see `_apiKeyWire.test.ts`): the React Query wrapper is
|
|
12
|
-
* mocked so the captured options bag can be driven directly.
|
|
13
|
-
*/
|
|
5
|
+
// Pins that the hook hands `query.state.error` to the refetch policy, which the policy's own unit tests cannot see.
|
|
14
6
|
|
|
15
7
|
// The captured options bag is opaque, like the real wrapper's.
|
|
16
8
|
let captured: any;
|
|
@@ -15,23 +15,7 @@ export type UseBridgeApiSubmitTxStatusParams = ReadHookParams<
|
|
|
15
15
|
}
|
|
16
16
|
>;
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook for polling the processing status of a submitted bridge transaction via the bridge
|
|
20
|
-
* API — `sodax.api.bridge.getSubmitTxStatus`. Both `txHash` and `srcChainKey` are required for the
|
|
21
|
-
* query to run.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const { data: status } = useBridgeApiSubmitTxStatus({
|
|
25
|
-
* params: { txHash: '0x123...', srcChainKey: '0xa4b1.arbitrum' },
|
|
26
|
-
* });
|
|
27
|
-
*
|
|
28
|
-
* @remarks
|
|
29
|
-
* - Default refetch interval is 1 second; stops on 'executed' or 'failed' status, when the
|
|
30
|
-
* backend marks the submission abandoned (`abandonedAt`) while `status` stays non-terminal, or
|
|
31
|
-
* once the backend rejects the API key (401/403 is terminal — a retry cannot fix it) —
|
|
32
|
-
* mirroring the SDK's backend submit-tx poll (no solver `posting_execution` state — bridge has
|
|
33
|
-
* no post-execution).
|
|
34
|
-
*/
|
|
18
|
+
/** Polls every 1s until 'executed'/'failed', `abandonedAt`, or API-key rejection (401/403). */
|
|
35
19
|
export const useBridgeApiSubmitTxStatus = ({
|
|
36
20
|
params,
|
|
37
21
|
queryOptions,
|
|
@@ -44,8 +28,6 @@ export const useBridgeApiSubmitTxStatus = ({
|
|
|
44
28
|
return useQuery({
|
|
45
29
|
queryKey: ['bridgeApi', 'submitTx', 'status', txHash, srcChainKey],
|
|
46
30
|
queryFn: async (): Promise<BridgeSubmitTxStatusResponseV2 | undefined> => {
|
|
47
|
-
// `srcChainKey` is required by the bridge API status query. The `enabled` gate below ensures
|
|
48
|
-
// both are present; this guard also narrows the types for the call.
|
|
49
31
|
if (!txHash || !srcChainKey) return undefined;
|
|
50
32
|
return unwrapResult(await sodax.api.bridge.getSubmitTxStatus({ txHash, srcChainKey }, apiConfig));
|
|
51
33
|
},
|
|
@@ -12,14 +12,6 @@ export type UseBridgeApiTokensParams = ReadHookParams<
|
|
|
12
12
|
}
|
|
13
13
|
>;
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* React hook to fetch all supported bridge tokens grouped by SpokeChainKey via the bridge API —
|
|
17
|
-
* `sodax.api.bridge.getTokens`. The token list is backend-served; the bridgeable-amount quote is
|
|
18
|
-
* computable client-side via `useGetBridgeableAmount` (also mirrored by `useBridgeApiBridgeableAmount`).
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data: tokensByChain } = useBridgeApiTokens();
|
|
22
|
-
*/
|
|
23
15
|
export const useBridgeApiTokens = ({
|
|
24
16
|
params,
|
|
25
17
|
queryOptions,
|
|
@@ -13,13 +13,6 @@ export type UseBridgeApiTokensByChainParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to fetch supported bridge tokens for a single SpokeChainKey via the bridge API —
|
|
18
|
-
* `sodax.api.bridge.getTokensByChain`. Use `useBridgeApiTokens` for every chain at once.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data: tokens } = useBridgeApiTokensByChain({ params: { chainKey: '0xa4b1.arbitrum' } });
|
|
22
|
-
*/
|
|
23
16
|
export const useBridgeApiTokensByChain = ({
|
|
24
17
|
params,
|
|
25
18
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/dex/useClaimRewards.ts
|
|
2
1
|
import type { ClLiquidityClaimRewardsAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -6,22 +5,12 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
6
5
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
6
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
8
7
|
|
|
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
8
|
export type UseClaimRewardsVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
|
|
15
9
|
ClLiquidityClaimRewardsAction<K, false>,
|
|
16
10
|
'raw'
|
|
17
11
|
>;
|
|
18
12
|
|
|
19
|
-
/**
|
|
20
|
-
* React hook for claiming accrued fees on a concentrated-liquidity position.
|
|
21
|
-
*
|
|
22
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
23
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
24
|
-
*/
|
|
13
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
25
14
|
export function useClaimRewards<K extends SpokeChainKey = SpokeChainKey>({
|
|
26
15
|
mutationOptions,
|
|
27
16
|
}: MutationHookParams<TxHashPair, UseClaimRewardsVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -10,11 +10,7 @@ export type UseCreateDecreaseLiquidityParamsProps = {
|
|
|
10
10
|
slippageTolerance: string | number;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
/**
|
|
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.
|
|
17
|
-
*/
|
|
13
|
+
/** Memoizes the decrease-liquidity fields; callers add `srcChainKey` + `srcAddress` at mutation time. */
|
|
18
14
|
export function useCreateDecreaseLiquidityParams({
|
|
19
15
|
poolKey,
|
|
20
16
|
tokenId,
|
|
@@ -9,11 +9,7 @@ export type UseCreateDepositParamsProps = {
|
|
|
9
9
|
poolSpokeAssets: PoolSpokeAssets;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
/**
|
|
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.
|
|
16
|
-
*/
|
|
12
|
+
/** Memoizes the deposit fields; callers add `srcChainKey` + `srcAddress` at mutation time. */
|
|
17
13
|
export function useCreateDepositParams({
|
|
18
14
|
tokenIndex,
|
|
19
15
|
amount,
|
|
@@ -15,11 +15,7 @@ export type UseCreateSupplyLiquidityParamsProps = {
|
|
|
15
15
|
isValidPosition?: boolean;
|
|
16
16
|
};
|
|
17
17
|
|
|
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
|
-
*/
|
|
18
|
+
/** `tokenId` + `isValidPosition` select increase-existing over mint-new; callers add `srcChainKey` + `srcAddress`. */
|
|
23
19
|
export type UseCreateSupplyLiquidityParamsResult = Omit<ClSupplyParams<SpokeChainKey>, 'srcChainKey' | 'srcAddress'> &
|
|
24
20
|
Omit<ClIncreaseLiquidityParams<SpokeChainKey>, 'srcChainKey' | 'srcAddress' | 'tokenId'> & {
|
|
25
21
|
tokenId?: string | bigint;
|
|
@@ -27,11 +23,6 @@ export type UseCreateSupplyLiquidityParamsResult = Omit<ClSupplyParams<SpokeChai
|
|
|
27
23
|
isValidPosition?: boolean;
|
|
28
24
|
};
|
|
29
25
|
|
|
30
|
-
/**
|
|
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.
|
|
34
|
-
*/
|
|
35
26
|
export function useCreateSupplyLiquidityParams({
|
|
36
27
|
poolData,
|
|
37
28
|
poolKey,
|
|
@@ -10,11 +10,7 @@ export type UseCreateWithdrawParamsProps = {
|
|
|
10
10
|
dst?: DestinationParamsType;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
/**
|
|
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.
|
|
17
|
-
*/
|
|
13
|
+
/** Memoizes the withdraw fields; callers add `srcChainKey` + `srcAddress` at mutation time. */
|
|
18
14
|
export function useCreateWithdrawParams({
|
|
19
15
|
tokenIndex,
|
|
20
16
|
amount,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/dex/useDecreaseLiquidity.ts
|
|
2
1
|
import type { ClLiquidityDecreaseLiquidityAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -6,22 +5,12 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
6
5
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
6
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
8
7
|
|
|
9
|
-
/**
|
|
10
|
-
* Mutation variables for {@link useDecreaseLiquidity}. 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
8
|
export type UseDecreaseLiquidityVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
|
|
15
9
|
ClLiquidityDecreaseLiquidityAction<K, false>,
|
|
16
10
|
'raw'
|
|
17
11
|
>;
|
|
18
12
|
|
|
19
|
-
/**
|
|
20
|
-
* React hook for decreasing liquidity in an existing concentrated-liquidity position.
|
|
21
|
-
*
|
|
22
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
23
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
24
|
-
*/
|
|
13
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
25
14
|
export function useDecreaseLiquidity<K extends SpokeChainKey = SpokeChainKey>({
|
|
26
15
|
mutationOptions,
|
|
27
16
|
}: MutationHookParams<TxHashPair, UseDecreaseLiquidityVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -38,9 +27,7 @@ export function useDecreaseLiquidity<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
38
27
|
mutationFn: async vars => unwrapResult(await sodax.dex.clService.decreaseLiquidity({ ...vars, raw: false })),
|
|
39
28
|
onSuccess: async (data, vars, ctx) => {
|
|
40
29
|
const { params } = vars;
|
|
41
|
-
//
|
|
42
|
-
// of wiping all positions. `usePositionInfo` keys by string tokenId, so stringify the bigint
|
|
43
|
-
// here to keep the structural match.
|
|
30
|
+
// Scope invalidation to this position; `usePositionInfo` keys by string tokenId, so stringify the bigint.
|
|
44
31
|
queryClient.invalidateQueries({
|
|
45
32
|
queryKey: ['dex', 'positionInfo', params.tokenId.toString(), params.poolKey],
|
|
46
33
|
});
|
|
@@ -11,11 +11,7 @@ export type UseDexAllowanceParams<K extends SpokeChainKey = SpokeChainKey> = Rea
|
|
|
11
11
|
}
|
|
12
12
|
>;
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* React hook to check whether the user has approved sufficient token allowance (or established a
|
|
16
|
-
* trustline, on Stellar) for a DEX deposit. Read-only — calls `assetService.isAllowanceValid`
|
|
17
|
-
* with `raw: true` so no `walletProvider` is required.
|
|
18
|
-
*/
|
|
14
|
+
/** Read-only (`raw: true`), so no `walletProvider` is needed; covers Stellar trustlines too. */
|
|
19
15
|
export function useDexAllowance<K extends SpokeChainKey = SpokeChainKey>({
|
|
20
16
|
params,
|
|
21
17
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/dex/useDexApprove.ts
|
|
2
1
|
import type { AssetDepositAction, SpokeChainKey, TxReturnType } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -6,19 +5,9 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
6
5
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
6
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
8
7
|
|
|
9
|
-
/**
|
|
10
|
-
* Mutation variables for {@link useDexApprove}. 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
8
|
export type UseDexApproveVars<K extends SpokeChainKey = SpokeChainKey> = Omit<AssetDepositAction<K, false>, 'raw'>;
|
|
15
9
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook for approving ERC-20 token spending (or trustline establishment) for a DEX deposit.
|
|
18
|
-
*
|
|
19
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
20
|
-
* `onError`, `retry`). Returns the unwrapped tx return value on success.
|
|
21
|
-
*/
|
|
10
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped tx return value. */
|
|
22
11
|
export function useDexApprove<K extends SpokeChainKey = SpokeChainKey>({
|
|
23
12
|
mutationOptions,
|
|
24
13
|
}: MutationHookParams<TxReturnType<K, false>, UseDexApproveVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/dex/useDexDeposit.ts
|
|
2
1
|
import type { AssetDepositAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -8,30 +7,9 @@ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMu
|
|
|
8
7
|
import { retryBeforeSubmission } from '../shared/retryBeforeSubmission.js';
|
|
9
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
10
9
|
|
|
11
|
-
/**
|
|
12
|
-
* Mutation variables for {@link useDexDeposit}. Generic over `K extends SpokeChainKey` (defaults
|
|
13
|
-
* to the full union). Sophisticated callers can lock K at the hook call site to narrow the
|
|
14
|
-
* `walletProvider` and `params.srcChainKey` types.
|
|
15
|
-
*/
|
|
16
10
|
export type UseDexDepositVars<K extends SpokeChainKey = SpokeChainKey> = Omit<AssetDepositAction<K, false>, 'raw'>;
|
|
17
11
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook for depositing an asset into a DEX pool.
|
|
20
|
-
*
|
|
21
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
22
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```tsx
|
|
26
|
-
* const walletProvider = useWalletProvider({ xChainId: chainKey });
|
|
27
|
-
* const { mutateAsync: deposit } = useDexDeposit();
|
|
28
|
-
* try {
|
|
29
|
-
* const { spokeTxHash, hubTxHash } = await deposit({ params, walletProvider });
|
|
30
|
-
* } catch (e) {
|
|
31
|
-
* // surfaced via mutation.error / onError
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
12
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
35
13
|
export function useDexDeposit<K extends SpokeChainKey = SpokeChainKey>({
|
|
36
14
|
mutationOptions,
|
|
37
15
|
}: MutationHookParams<TxHashPair, UseDexDepositVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/dex/useDexWithdraw.ts
|
|
2
1
|
import type { AssetWithdrawAction, SpokeChainKey, OutboundSettlement } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -8,20 +7,9 @@ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMu
|
|
|
8
7
|
import { retryBeforeSubmission } from '../shared/retryBeforeSubmission.js';
|
|
9
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
10
9
|
|
|
11
|
-
/**
|
|
12
|
-
* Mutation variables for {@link useDexWithdraw}. Generic over `K extends SpokeChainKey` (defaults
|
|
13
|
-
* to the full union). Sophisticated callers can lock K at the hook call site to narrow the
|
|
14
|
-
* `walletProvider` and `params.srcChainKey` types.
|
|
15
|
-
*/
|
|
16
10
|
export type UseDexWithdrawVars<K extends SpokeChainKey = SpokeChainKey> = Omit<AssetWithdrawAction<K, false>, 'raw'>;
|
|
17
11
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook for withdrawing an asset from a DEX pool.
|
|
20
|
-
*
|
|
21
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
22
|
-
* `onError`, `retry`). Returns the unwrapped {@link OutboundSettlement} on success: a tx pair, or
|
|
23
|
-
* from Tron the relay's `trackingId` beside the destination tx.
|
|
24
|
-
*/
|
|
12
|
+
/** Throws on SDK failure; resolves to an {@link OutboundSettlement} (tx pair, or Tron relay `trackingId` + dst tx). */
|
|
25
13
|
export function useDexWithdraw<K extends SpokeChainKey = SpokeChainKey>({
|
|
26
14
|
mutationOptions,
|
|
27
15
|
}: MutationHookParams<OutboundSettlement<K>, UseDexWithdrawVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -11,10 +11,7 @@ export type UseLiquidityAmountsResult = {
|
|
|
11
11
|
handleToken1AmountChange: (value: string) => void;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Hook for calculating concentrated-liquidity amounts based on the price range. Pure state +
|
|
16
|
-
* math; no SDK calls beyond the static {@link ClService} helpers.
|
|
17
|
-
*/
|
|
14
|
+
/** Pure state + math; no SDK calls beyond the static {@link ClService} helpers. */
|
|
18
15
|
export function useLiquidityAmounts(
|
|
19
16
|
minPrice: string,
|
|
20
17
|
maxPrice: string,
|
|
@@ -20,10 +20,6 @@ export type UsePoolBalancesParams = ReadHookParams<
|
|
|
20
20
|
}
|
|
21
21
|
>;
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
* React hook to query the user's hub-side deposit balances for both pool tokens. Derives the hub
|
|
25
|
-
* wallet once and reads both pool-token balances in parallel via the hub `publicClient`.
|
|
26
|
-
*/
|
|
27
23
|
export function usePoolBalances({
|
|
28
24
|
params,
|
|
29
25
|
queryOptions,
|
|
@@ -5,10 +5,7 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
5
5
|
|
|
6
6
|
export type UsePoolDataParams = ReadHookParams<PoolData, { poolKey: PoolKey | null }>;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* React hook to fetch on-chain pool data (sqrt price, tick, fees, token info, etc.) for a given
|
|
10
|
-
* pool key. Reads via the hub `publicClient`. Disabled when `poolKey` is null.
|
|
11
|
-
*/
|
|
8
|
+
/** Disabled when `poolKey` is null. */
|
|
12
9
|
export function usePoolData({ params, queryOptions }: UsePoolDataParams = {}): UseQueryResult<PoolData, Error> {
|
|
13
10
|
const { sodax } = useSodaxContext();
|
|
14
11
|
const poolKey = params?.poolKey ?? null;
|
|
@@ -5,10 +5,7 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
5
5
|
|
|
6
6
|
export type UsePoolsParams = ReadHookParams<PoolKey[]>;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Loads the list of concentrated-liquidity pools known to the SDK config. The SDK's `getPools()`
|
|
10
|
-
* is synchronous in v2 (no network), so this hook caches indefinitely by default.
|
|
11
|
-
*/
|
|
8
|
+
/** `getPools()` is synchronous (no network), so the result is cached indefinitely. */
|
|
12
9
|
export function usePools({ queryOptions }: UsePoolsParams = {}): UseQueryResult<PoolKey[], Error> {
|
|
13
10
|
const { sodax } = useSodaxContext();
|
|
14
11
|
|
|
@@ -16,10 +16,7 @@ export type UsePositionInfoParams = ReadHookParams<
|
|
|
16
16
|
}
|
|
17
17
|
>;
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* React hook to fetch a CL position by NFT token id and validate it against an expected pool key.
|
|
21
|
-
* Reads via the hub `publicClient`. Disabled when `tokenId` or `poolKey` is missing.
|
|
22
|
-
*/
|
|
19
|
+
/** Validates the position against the expected pool key; disabled when `tokenId` or `poolKey` is missing. */
|
|
23
20
|
export function usePositionInfo({
|
|
24
21
|
params,
|
|
25
22
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/dex/useSupplyLiquidity.ts
|
|
2
1
|
import type {
|
|
3
2
|
ClIncreaseLiquidityParams,
|
|
4
3
|
ClSupplyParams,
|
|
@@ -14,12 +13,6 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
14
13
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
15
14
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
16
15
|
|
|
17
|
-
/**
|
|
18
|
-
* Mutation variables for {@link useSupplyLiquidity}. Generic over `K extends SpokeChainKey`
|
|
19
|
-
* (defaults to the full union). The hook fans out internally to either
|
|
20
|
-
* `clService.increaseLiquidity` (when `params.tokenId` + `params.isValidPosition` are present) or
|
|
21
|
-
* `clService.supplyLiquidity` (mint a new position).
|
|
22
|
-
*/
|
|
23
16
|
export type UseSupplyLiquidityVars<K extends SpokeChainKey = SpokeChainKey> = {
|
|
24
17
|
params: UseCreateSupplyLiquidityParamsResult & { srcChainKey: K; srcAddress: string };
|
|
25
18
|
walletProvider: GetWalletProviderType<K>;
|
|
@@ -27,14 +20,7 @@ export type UseSupplyLiquidityVars<K extends SpokeChainKey = SpokeChainKey> = {
|
|
|
27
20
|
timeout?: number;
|
|
28
21
|
};
|
|
29
22
|
|
|
30
|
-
/**
|
|
31
|
-
* React hook for supplying liquidity to a concentrated-liquidity pool. If the input vars include a
|
|
32
|
-
* valid `tokenId` for an existing position, the hook calls `increaseLiquidity`; otherwise it mints
|
|
33
|
-
* a new position via `supplyLiquidity`.
|
|
34
|
-
*
|
|
35
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
36
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
37
|
-
*/
|
|
23
|
+
/** Calls `increaseLiquidity` when vars carry a valid `tokenId`, else mints via `supplyLiquidity`. Throws on SDK failure. */
|
|
38
24
|
export function useSupplyLiquidity<K extends SpokeChainKey = SpokeChainKey>({
|
|
39
25
|
mutationOptions,
|
|
40
26
|
}: MutationHookParams<TxHashPair, UseSupplyLiquidityVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -77,12 +63,9 @@ export function useSupplyLiquidity<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
77
63
|
},
|
|
78
64
|
onSuccess: async (data, vars, ctx) => {
|
|
79
65
|
const { params } = vars;
|
|
80
|
-
//
|
|
81
|
-
// branch creates a fresh tokenId that's only known after the tx, so a bare invalidation is
|
|
82
|
-
// the right fallback (refetches all positions, including the new one once it lands).
|
|
66
|
+
// Mint-new has no tokenId until the tx lands, so it falls back to invalidating all positions.
|
|
83
67
|
if (params.tokenId !== undefined && params.isValidPosition) {
|
|
84
|
-
// `usePositionInfo` keys by string tokenId
|
|
85
|
-
// whether the caller passed bigint or string.
|
|
68
|
+
// `usePositionInfo` keys by string tokenId; caller may pass bigint or string.
|
|
86
69
|
const tokenIdStr = String(params.tokenId);
|
|
87
70
|
queryClient.invalidateQueries({ queryKey: ['dex', 'positionInfo', tokenIdStr, params.poolKey] });
|
|
88
71
|
} else {
|
|
@@ -5,7 +5,6 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
5
5
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
6
6
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
7
7
|
|
|
8
|
-
/** Mutation variables for {@link useApproveLeveragePositionFunding}. */
|
|
9
8
|
export type UseApproveLeveragePositionFundingVars<K extends SpokeChainKey = SpokeChainKey> = {
|
|
10
9
|
srcChainKey: K;
|
|
11
10
|
srcAddress: string;
|
|
@@ -16,13 +15,8 @@ export type UseApproveLeveragePositionFundingVars<K extends SpokeChainKey = Spok
|
|
|
16
15
|
};
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
|
-
* Approves the funding token for an open
|
|
20
|
-
*
|
|
21
|
-
* THE SPENDER IS CHAIN-DEPENDENT — the hub wallet on the hub, the spoke asset manager elsewhere.
|
|
22
|
-
* Nothing is ever approved to the position factory: it pulls from nobody.
|
|
23
|
-
*
|
|
24
|
-
* Wait for this before opening, and gate it on {@link useLeveragePositionFundingAllowance}, whose
|
|
25
|
-
* query is invalidated here on success.
|
|
18
|
+
* Approves the funding token for an open; the spender is chain-dependent (hub wallet on hub, spoke asset manager elsewhere).
|
|
19
|
+
* Await before opening; invalidates {@link useLeveragePositionFundingAllowance} on success.
|
|
26
20
|
*/
|
|
27
21
|
export function useApproveLeveragePositionFunding<K extends SpokeChainKey = SpokeChainKey>({
|
|
28
22
|
mutationOptions,
|
|
@@ -9,19 +9,8 @@ export type UseLeveragePositionAccountParams = ReadHookParams<
|
|
|
9
9
|
>;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* The figures come from the pool's `getUserAccountData`, not from the position contract,
|
|
16
|
-
* which keeps no accounting of its own. Health factor is WAD (1e18); below 1e18 the position
|
|
17
|
-
* is liquidatable, and there is no keeper deleveraging on the owner's behalf, so this is the
|
|
18
|
-
* number a UI should surface most prominently. Debt accrues continuously, hence the 30s
|
|
19
|
-
* default refresh.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* const { data: account } = useLeveragePositionAccount({ params: { position } });
|
|
24
|
-
* ```
|
|
12
|
+
* Live AAVE account snapshot (pool `getUserAccountData`). Health factor is WAD; below 1e18 the position
|
|
13
|
+
* is liquidatable with no keeper to deleverage it. Polled every 30s since debt accrues continuously.
|
|
25
14
|
*/
|
|
26
15
|
export function useLeveragePositionAccount({
|
|
27
16
|
params,
|
|
@@ -9,19 +9,8 @@ export type UseLeveragePositionCollateralParams = ReadHookParams<
|
|
|
9
9
|
>;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* Use this, not `useLeveragePositionAccount().totalCollateralBase`, whenever an amount is going into
|
|
15
|
-
* a transaction. The account snapshot is denominated in the oracle's base currency at 8 decimals, so
|
|
16
|
-
* dividing it back out by a price gives an amount near the balance rather than the balance — and a
|
|
17
|
-
* decrease-leverage call for more collateral than the position holds expires as an unfillable intent
|
|
18
|
-
* instead of failing up front.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* const { data: collateral } = useLeveragePositionCollateral({ params: { position } });
|
|
23
|
-
* // collateral.balance is what a full exit sells
|
|
24
|
-
* ```
|
|
12
|
+
* Exact aToken collateral balance; use this (not the account snapshot's oracle-priced total) for transaction
|
|
13
|
+
* amounts, since over-asking on decrease-leverage expires as an unfillable intent instead of failing up front.
|
|
25
14
|
*/
|
|
26
15
|
export function useLeveragePositionCollateral({
|
|
27
16
|
params,
|
|
@@ -40,7 +29,6 @@ export function useLeveragePositionCollateral({
|
|
|
40
29
|
return result.value;
|
|
41
30
|
},
|
|
42
31
|
enabled: !!position,
|
|
43
|
-
// Interest accrues into the balance continuously, so match the account snapshot's cadence.
|
|
44
32
|
refetchInterval: 30_000,
|
|
45
33
|
...queryOptions,
|
|
46
34
|
});
|
|
@@ -3,12 +3,10 @@ import type { SpokeChainKey } from '@sodax/sdk';
|
|
|
3
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
4
|
import type { ReadHookParams } from '../shared/types.js';
|
|
5
5
|
|
|
6
|
-
/** Params for {@link useLeveragePositionFundingAllowance}. */
|
|
7
6
|
export type UseLeveragePositionFundingAllowanceParams = ReadHookParams<
|
|
8
7
|
boolean,
|
|
9
8
|
{
|
|
10
9
|
srcChainKey: SpokeChainKey;
|
|
11
|
-
/** The user's address on `srcChainKey`. */
|
|
12
10
|
srcAddress: string | undefined;
|
|
13
11
|
/** Funding token, from `resolvePositionFunding` — not the reserve and not the vault. */
|
|
14
12
|
token: string | undefined;
|
|
@@ -17,13 +15,8 @@ export type UseLeveragePositionFundingAllowanceParams = ReadHookParams<
|
|
|
17
15
|
>;
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
|
-
* Whether the funding token is
|
|
21
|
-
*
|
|
22
|
-
* THE SPENDER IS CHAIN-DEPENDENT — the hub wallet on the hub, the spoke asset manager elsewhere —
|
|
23
|
-
* so a hand-rolled `allowance` call against a guessed spender is right half the time. The SDK
|
|
24
|
-
* resolves it; this only supplies React Query.
|
|
25
|
-
*
|
|
26
|
-
* Returns the SDK's answer as data. A chain with no allowance concept answers `true` without a call.
|
|
18
|
+
* Whether the funding token is approved for an open; the SDK resolves the chain-dependent spender.
|
|
19
|
+
* Chains with no allowance concept answer `true`.
|
|
27
20
|
*/
|
|
28
21
|
export function useLeveragePositionFundingAllowance({
|
|
29
22
|
params,
|
|
@@ -5,19 +5,7 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
5
5
|
|
|
6
6
|
export type UseLeveragePositionInfoParams = ReadHookParams<LeveragePosition, { position: Address | undefined }>;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Reads a leverage position's static descriptor — owner, collateral, borrow token, and the
|
|
10
|
-
* eMode category it was created with.
|
|
11
|
-
*
|
|
12
|
-
* All four are fixed at creation, so this never goes stale for a given position and is left
|
|
13
|
-
* on the default cache behaviour rather than polled. Pair it with
|
|
14
|
-
* `useLeveragePositionAccount` for the values that do move.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const { data: info } = useLeveragePositionInfo({ params: { position } });
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
8
|
+
/** A position's static descriptor (fixed at creation, so not polled); see `useLeveragePositionAccount` for live values. */
|
|
21
9
|
export function useLeveragePositionInfo({
|
|
22
10
|
params,
|
|
23
11
|
queryOptions,
|
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
import type { Address, SpokeChainKey } from '@sodax/sdk';
|
|
2
2
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
3
3
|
|
|
4
|
-
/** Params for {@link useLeveragePositionPayoutAddress}. */
|
|
5
4
|
export type UseLeveragePositionPayoutAddressParams = {
|
|
6
|
-
/** The chain the user signs on. */
|
|
7
5
|
chainKey: SpokeChainKey;
|
|
8
|
-
/**
|
|
9
|
-
* Their address on that chain. Supplied by the caller — this package does not depend on a wallet
|
|
10
|
-
* layer, so it cannot read the connected account itself.
|
|
11
|
-
*/
|
|
6
|
+
/** Supplied by the caller: this package has no wallet layer to read the connected account. */
|
|
12
7
|
signerAddress: Address | undefined;
|
|
13
8
|
/** The position's owner, from `useGetUserHubWalletAddress`. */
|
|
14
9
|
owner: Address | undefined;
|
|
15
10
|
};
|
|
16
11
|
|
|
17
12
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* `withdraw` is a plain pool withdrawal, so it pays out to an address ON THE HUB. For a hub-chain
|
|
21
|
-
* user that can be their own address; for anyone else it cannot — their signing address belongs to
|
|
22
|
-
* another chain, and for a non-EVM chain it is not an address the hub could pay at all. The hub
|
|
23
|
-
* wallet is the one destination that is always theirs, and bridging onward is a separate operation.
|
|
24
|
-
*
|
|
25
|
-
* Returns `undefined` while either address is still resolving, which is the disabled state for a
|
|
26
|
-
* withdraw button rather than a reason to fall back to the signer.
|
|
13
|
+
* Hub address a position withdrawal can pay to: the signer on the hub chain, else the hub wallet (owner).
|
|
14
|
+
* `undefined` while resolving means disable withdraw — do not fall back to the signer.
|
|
27
15
|
*/
|
|
28
16
|
export function useLeveragePositionPayoutAddress({
|
|
29
17
|
params,
|