@sodax/dapp-kit 2.4.0-rc.1 → 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 +11 -3
- package/dist/index.d.ts +395 -2413
- package/dist/index.mjs +206 -31
- package/package.json +2 -2
- package/src/hooks/_apiKeyWire.test.ts +4 -29
- package/src/hooks/_mutationContract.test.ts +2 -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/index.ts +4 -0
- 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 +112 -0
- package/src/hooks/shared/useEstablishXrpTrustline.ts +63 -0
- 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 +71 -0
- package/src/hooks/shared/useXrpGate.test.ts +116 -0
- package/src/hooks/shared/useXrpGate.ts +80 -0
- package/src/hooks/shared/useXrpTrustlineReserveCheck.ts +45 -0
- 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 +47 -2
- package/src/hooks/swap/useSwapLifecycle.ts +36 -30
- 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/index.ts +1 -0
- package/src/utils/nearStorageGate.ts +3 -14
- package/src/utils/stellarGate.ts +3 -16
- package/src/utils/swapLifecycle.test.ts +35 -0
- package/src/utils/swapLifecycle.ts +21 -28
- package/src/utils/xrpGate.test.ts +112 -0
- package/src/utils/xrpGate.ts +69 -0
|
@@ -2,19 +2,8 @@ import { isAuthFailure, type BridgeSubmitTxStatusDataV2 } from '@sodax/sdk';
|
|
|
2
2
|
|
|
3
3
|
export const BRIDGE_SUBMIT_TX_STATUS_POLL_MS = 1000;
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* the backend abandoned, and on a terminal API-key rejection.
|
|
8
|
-
*
|
|
9
|
-
* `abandonedAt` is terminal even when `status` is still non-terminal (e.g. `'relayed'`) — same rule
|
|
10
|
-
* as the SDK's `pollBackendSubmitTx`. The auth stop is separate from the hook's `retry` policy:
|
|
11
|
-
* `retry` bounds attempts *within* a tick, so without this the interval would keep firing a request
|
|
12
|
-
* a corrected key is the only fix for.
|
|
13
|
-
*
|
|
14
|
-
* Kept in its own pure module (no React/context imports) so it is unit-testable in dapp-kit's
|
|
15
|
-
* `node` test environment — importing the hook itself pulls in `useSodaxContext`. Same reason as
|
|
16
|
-
* `swapsApi/isTerminalSwapIntentStatus`.
|
|
17
|
-
*/
|
|
5
|
+
/** Stops on a terminal status, on `abandonedAt` (even while `status` is non-terminal) or on API-key rejection
|
|
6
|
+
* (`retry` only bounds attempts within a tick). Kept React-free so it is unit-testable under `node`. */
|
|
18
7
|
export function getBridgeSubmitTxStatusRefetchInterval(
|
|
19
8
|
error: unknown,
|
|
20
9
|
data: BridgeSubmitTxStatusDataV2 | undefined,
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './useBridgeApiSubmitTxStatus.js'; // query (poll)
|
|
13
|
-
export * from './useBridgeApiTokens.js'; // query (backend-served token list)
|
|
14
|
-
export * from './useBridgeApiTokensByChain.js'; // query (backend-served token list for one chain)
|
|
1
|
+
export * from './useBridgeApiAllowance.js';
|
|
2
|
+
export * from './useBridgeApiApprove.js';
|
|
3
|
+
export * from './useBridgeApiApproveAndBroadcast.js';
|
|
4
|
+
export * from './useBridgeApiBridgeableAmount.js';
|
|
5
|
+
export * from './useBridgeApiCreateBridgeIntent.js';
|
|
6
|
+
export * from './useBridgeApiFee.js';
|
|
7
|
+
export * from './useBridgeApiIsBridgeable.js';
|
|
8
|
+
export * from './useBridgeApiSubmitTx.js';
|
|
9
|
+
export * from './useBridgeApiSubmitTxStatus.js';
|
|
10
|
+
export * from './useBridgeApiTokens.js';
|
|
11
|
+
export * from './useBridgeApiTokensByChain.js';
|
|
@@ -13,15 +13,7 @@ export type UseBridgeApiAllowanceParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to check whether the source-token allowance is already sufficient for a bridge via
|
|
18
|
-
* the bridge API — `sodax.api.bridge.checkAllowance`. Returns `{ valid }`.
|
|
19
|
-
*
|
|
20
|
-
* The `body` uses the wire DTO field names (`inputToken`/`inputAmount`).
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* const { data: allowance } = useBridgeApiAllowance({ params: { body: createBridgeIntentParams } });
|
|
24
|
-
*/
|
|
16
|
+
/** `body` uses the wire DTO field names (`inputToken`/`inputAmount`). */
|
|
25
17
|
export const useBridgeApiAllowance = ({
|
|
26
18
|
params,
|
|
27
19
|
queryOptions,
|
|
@@ -5,28 +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 useBridgeApiApprove}. The per-request `apiConfig` override belongs
|
|
10
|
-
* here rather than at the hook level — different calls in the same component can target different
|
|
11
|
-
* endpoints without re-rendering.
|
|
12
|
-
*/
|
|
13
8
|
export type UseBridgeApiApproveVars = {
|
|
14
9
|
body: CreateBridgeIntentParamsV2;
|
|
15
10
|
apiConfig?: RequestOverrideConfig;
|
|
16
11
|
};
|
|
17
12
|
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* API — `sodax.api.bridge.approve`. Returns `{ tx, resetTx? }` (chain-specific unsigned txs) to sign
|
|
21
|
-
* and broadcast yourself; it does not change state, so no queries are invalidated.
|
|
22
|
-
*
|
|
23
|
-
* `resetTx`, when present, must be MINED before `tx` is a valid state transition. Prefer
|
|
24
|
-
* {@link useBridgeApiApproveAndBroadcast}, which owns that ordering and invalidates the allowance query.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* const { mutateAsync: approve } = useBridgeApiApprove();
|
|
28
|
-
* const { tx, resetTx } = await approve({ body: createBridgeIntentParams });
|
|
29
|
-
*/
|
|
13
|
+
/** Returns unsigned `{ tx, resetTx? }`; `resetTx` must be MINED before `tx` is valid.
|
|
14
|
+
* Prefer {@link useBridgeApiApproveAndBroadcast}, which owns that ordering. */
|
|
30
15
|
export const useBridgeApiApprove = ({
|
|
31
16
|
mutationOptions,
|
|
32
17
|
}: MutationHookParams<BridgeApproveResponseV2, UseBridgeApiApproveVars> = {}): SafeUseMutationResult<
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* The bridge API can return two approval transactions, and the second is only a valid state
|
|
3
|
-
* transition once the first has been mined. That ordering is what this hook exists to own.
|
|
4
|
-
*
|
|
5
|
-
* Follows the package convention of testing hooks without a renderer: the React Query wrapper is
|
|
6
|
-
* mocked so `mutationFn` can be captured and driven directly.
|
|
7
|
-
*/
|
|
1
|
+
// A second approval tx is only valid once the first is mined; this hook exists to own that ordering.
|
|
8
2
|
|
|
9
3
|
import { ChainKeys } from '@sodax/sdk';
|
|
10
4
|
import type { ApprovalProgress } from '../../utils/approvalPlan.js';
|
|
@@ -38,10 +32,7 @@ const APPROVE_HASH = '0xapprove-hash';
|
|
|
38
32
|
|
|
39
33
|
const body = (srcChainKey: string) => ({ srcChainKey, inputToken: '0xtoken', inputAmount: '1' });
|
|
40
34
|
|
|
41
|
-
/**
|
|
42
|
-
* Records the interleaving of sends and waits so ordering can be asserted, not assumed.
|
|
43
|
-
* `onWait` either throws (the receipt never arrives) or returns the mined status.
|
|
44
|
-
*/
|
|
35
|
+
/** Records send/wait interleaving; `onWait` throws (receipt never arrives) or returns the mined status. */
|
|
45
36
|
function evmProvider(calls: string[], onWait?: (hash: string) => string | void) {
|
|
46
37
|
return {
|
|
47
38
|
sendTransaction: vi.fn(async (tx: { data: string }) => {
|
|
@@ -59,10 +50,8 @@ const onEvent = (sink: ApprovalProgress[]) => (progress: ApprovalProgress) => {
|
|
|
59
50
|
sink.push(progress);
|
|
60
51
|
};
|
|
61
52
|
|
|
62
|
-
/** Compact rendering, so a sequence can be asserted as one readable list. */
|
|
63
53
|
const trace = (p: ApprovalProgress): string => `${p.step}:${p.phase}:${p.index}/${p.total}`;
|
|
64
54
|
|
|
65
|
-
/** One render, then the captured `mutationFn` invoked with `vars`. */
|
|
66
55
|
// biome-ignore lint/suspicious/noExplicitAny: vars mirror the hook's generic mutation variables.
|
|
67
56
|
const run = (vars: any) => {
|
|
68
57
|
useBridgeApiApproveAndBroadcast();
|
|
@@ -24,26 +24,9 @@ export type UseBridgeApiApproveAndBroadcastVars<K extends SpokeChainKey = SpokeC
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* Prefer this over {@link useBridgeApiApprove}, which hands back the unsigned `{ tx, resetTx? }` and
|
|
31
|
-
* leaves the ordering — reset mined first, then approve — to the caller. Confirmation happens inside
|
|
32
|
-
* the hook, so it invalidates `['bridgeApi','allowance']` itself — after waiting up to about 15 seconds for
|
|
33
|
-
* the API to report the allowance as valid, since its RPC can trail the node that confirmed the approve.
|
|
34
|
-
* It resolves after that wait either way, so read the allowance rather than treating success as `valid`.
|
|
35
|
-
*
|
|
36
|
-
* Supports the chains the bridge API can approve on — the hub (Sonic), EVM spokes, and Stellar.
|
|
37
|
-
* Every other chain reports its allowance as always sufficient, so approval never runs for it.
|
|
38
|
-
*
|
|
39
|
-
* `onProgress` reports each transaction as `{ step, phase, index, total }`, so the UI can name the
|
|
40
|
-
* wallet prompt the user is looking at instead of one flat "Approving…" across two signatures.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* const { mutateAsyncSafe: approve } = useBridgeApiApproveAndBroadcast();
|
|
44
|
-
* const result = await approve({ body: createBridgeIntentParams, walletProvider, onProgress: setStep });
|
|
45
|
-
* if (!result.ok) return;
|
|
46
|
-
* const { resetTxHash, approveTxHash } = result.value; // resetTxHash only on a guarded token
|
|
27
|
+
* Signs, broadcasts and waits for each approval tx (reset mined first), then waits up to ~15s for the API allowance to
|
|
28
|
+
* report valid since its RPC can lag; resolves either way, so read the allowance rather than treating success as `valid`.
|
|
29
|
+
* Approval runs only on the hub, EVM spokes and Stellar; other chains report the allowance as always sufficient.
|
|
47
30
|
*/
|
|
48
31
|
export const useBridgeApiApproveAndBroadcast = <K extends SpokeChainKey = SpokeChainKey>({
|
|
49
32
|
mutationOptions,
|
|
@@ -13,18 +13,7 @@ export type UseBridgeApiBridgeableAmountParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to fetch the deposit capacity / withdrawal liquidity limit for a (from, to) token pair
|
|
18
|
-
* via the bridge API — `sodax.api.bridge.getBridgeableAmount`. Returns `{ limit }`.
|
|
19
|
-
*
|
|
20
|
-
* Computable client-side from config + vault reserves — prefer `sodax.bridge.getBridgeableAmount`
|
|
21
|
-
* for a no-round-trip read; this HTTP variant mirrors the `/bridge/bridgeable-amount` endpoint.
|
|
22
|
-
*
|
|
23
|
-
* The `body` uses the wire DTO field names (`srcChainKey`/`dstChainKey`/`inputToken`/`outputToken`).
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* const { data } = useBridgeApiBridgeableAmount({ params: { body: quote } });
|
|
27
|
-
*/
|
|
16
|
+
/** HTTP mirror of `sodax.bridge.getBridgeableAmount` (prefer that for a no-round-trip read); `body` uses wire DTO field names. */
|
|
28
17
|
export const useBridgeApiBridgeableAmount = ({
|
|
29
18
|
params,
|
|
30
19
|
queryOptions,
|
|
@@ -5,25 +5,12 @@ 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 useBridgeApiCreateBridgeIntent}. The per-request `apiConfig`
|
|
10
|
-
* override belongs here rather than at the hook level.
|
|
11
|
-
*/
|
|
12
8
|
export type UseBridgeApiCreateBridgeIntentVars = {
|
|
13
9
|
body: CreateBridgeIntentParamsV2;
|
|
14
10
|
apiConfig?: RequestOverrideConfig;
|
|
15
11
|
};
|
|
16
12
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook to build an unsigned spoke-deposit (create-bridge-intent) transaction via the bridge
|
|
19
|
-
* API — `sodax.api.bridge.createBridgeIntent`. Returns `{ tx, relayData }` (no `intent` struct —
|
|
20
|
-
* bridge is vault-backed) to sign and broadcast yourself; it does not change state, so no queries
|
|
21
|
-
* are invalidated.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const { mutateAsync: createBridgeIntent } = useBridgeApiCreateBridgeIntent();
|
|
25
|
-
* const { tx, relayData } = await createBridgeIntent({ body: createBridgeIntentParams });
|
|
26
|
-
*/
|
|
13
|
+
/** Returns the unsigned spoke-deposit `{ tx, relayData }` to sign and broadcast yourself; invalidates no queries. */
|
|
27
14
|
export const useBridgeApiCreateBridgeIntent = ({
|
|
28
15
|
mutationOptions,
|
|
29
16
|
}: MutationHookParams<CreateBridgeIntentResponseV2, UseBridgeApiCreateBridgeIntentVars> = {}): SafeUseMutationResult<
|
|
@@ -13,17 +13,8 @@ export type UseBridgeApiFeeParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* `body.partnerFee` override when supplied, else the backend-configured fee) —
|
|
19
|
-
* `sodax.api.bridge.getFee`. Returns `{ fee }` (smallest unit, decimal string).
|
|
20
|
-
*
|
|
21
|
-
* The fee is computable client-side (config-driven, token-independent) — prefer `sodax.bridge.getFee`
|
|
22
|
-
* for a no-round-trip read; this HTTP variant mirrors the `/bridge/fee` endpoint for parity.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* const { data: fee } = useBridgeApiFee({ params: { body: { inputAmount } } });
|
|
26
|
-
*/
|
|
16
|
+
/** Uses `body.partnerFee` when supplied, else the backend-configured fee; `fee` is a smallest-unit decimal string.
|
|
17
|
+
* Prefer `sodax.bridge.getFee` for a no-round-trip read. */
|
|
27
18
|
export const useBridgeApiFee = ({
|
|
28
19
|
params,
|
|
29
20
|
queryOptions,
|
|
@@ -13,18 +13,7 @@ export type UseBridgeApiIsBridgeableParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to check whether a (from, to) token pair is bridgeable via the bridge API —
|
|
18
|
-
* `sodax.api.bridge.isBridgeable`. Returns `{ bridgeable }`.
|
|
19
|
-
*
|
|
20
|
-
* Computable client-side from config + vault reserves — prefer `sodax.bridge.isBridgeable`
|
|
21
|
-
* for a no-round-trip read; this HTTP variant mirrors the `/bridge/bridgeable/check` endpoint.
|
|
22
|
-
*
|
|
23
|
-
* The `body` uses the wire DTO field names (`srcChainKey`/`dstChainKey`/`inputToken`/`outputToken`).
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* const { data } = useBridgeApiIsBridgeable({ params: { body: quote } });
|
|
27
|
-
*/
|
|
16
|
+
/** HTTP mirror of `sodax.bridge.isBridgeable` (prefer that for a no-round-trip read); `body` uses wire DTO field names. */
|
|
28
17
|
export const useBridgeApiIsBridgeable = ({
|
|
29
18
|
params,
|
|
30
19
|
queryOptions,
|
|
@@ -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,
|