@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
SOLVED_PAYOUT_HEADROOM_FACTOR,
|
|
2
3
|
isAuthFailure,
|
|
3
4
|
summarizeSwapStatus,
|
|
4
5
|
type CreateIntentParams,
|
|
@@ -14,6 +15,7 @@ import { useRef } from 'react';
|
|
|
14
15
|
import { resolveSwapLifecycle, toSwapAttempt, type SwapLifecycleState } from '../../utils/swapLifecycle.js';
|
|
15
16
|
import { useNearStorageGate, type NearStorageGate } from '../shared/useNearStorageGate.js';
|
|
16
17
|
import { useStellarGate, type StellarGate } from '../shared/useStellarGate.js';
|
|
18
|
+
import { useXrpGate, type XrpGate } from '../shared/useXrpGate.js';
|
|
17
19
|
import type { MutationHookOptions } from '../shared/types.js';
|
|
18
20
|
import type { SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
19
21
|
import { useDetailedStatus, type UseDetailedStatusResult } from './useDetailedStatus.js';
|
|
@@ -24,25 +26,17 @@ export type { SwapLifecycleState, SwapSetupReason } from '../../utils/swapLifecy
|
|
|
24
26
|
|
|
25
27
|
export type UseSwapLifecycleParams<K extends SpokeChainKey = SpokeChainKey> = {
|
|
26
28
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* accepts any fill, so an app should not send one.
|
|
29
|
+
* Changing it starts a new lifecycle once the current swap is done; one that may still land holds until `reset()`.
|
|
30
|
+
* A `0n` `minOutputAmount` accepts any fill, so do not send one.
|
|
30
31
|
*/
|
|
31
32
|
intentParams: CreateIntentParams<K> | undefined;
|
|
32
33
|
srcWalletProvider: GetWalletProviderType<K> | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* Destination wallet, for the Stellar and NEAR setup actions. The gates check `intentParams.dstAddress`,
|
|
35
|
-
* the account the swap pays, so this wallet must control it for those actions to clear them.
|
|
36
|
-
*/
|
|
34
|
+
/** For the Stellar, NEAR and XRPL setup actions; must control `intentParams.dstAddress`, which the gates check. */
|
|
37
35
|
dstWalletProvider: GetWalletProviderType<SpokeChainKey> | undefined;
|
|
38
36
|
/** Source-chain switching, e.g. `useEvmSwitchChain` from `@sodax/wallet-sdk-react`. */
|
|
39
37
|
chainSwitch?: { isWrongChain: boolean; switchChain: () => void | Promise<void> };
|
|
40
|
-
/** An app-owned prerequisite that must hold before swapping (e.g. a Bitcoin trading-wallet setup). */
|
|
41
38
|
externalBlocked?: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* `false` approves separately instead of asking a `'ready'` wallet to upgrade the account (e.g. after
|
|
44
|
-
* the user declined: `USER_REJECTED` with `context.reason === ACCOUNT_UPGRADE_DECLINED`). Defaults to `true`.
|
|
45
|
-
*/
|
|
39
|
+
/** `false` approves separately instead of asking a `'ready'` wallet to upgrade the account. Defaults to `true`. */
|
|
46
40
|
allowAccountUpgrade?: boolean;
|
|
47
41
|
extras?: SwapExtras<K>;
|
|
48
42
|
timeout?: number;
|
|
@@ -54,15 +48,11 @@ export type SwapLifecycle<K extends SpokeChainKey = SpokeChainKey> = {
|
|
|
54
48
|
/** The error behind `failed`, `unconfirmed` or a `pending` with one. Setup-action failures come back from `next()`. */
|
|
55
49
|
error: Error | undefined;
|
|
56
50
|
/**
|
|
57
|
-
* Does what the current state needs
|
|
58
|
-
*
|
|
59
|
-
* failed swap. Does nothing while waiting or while a previous call is still running.
|
|
51
|
+
* Does what the current state needs (switch chain, setup step, swap, re-check an `unconfirmed` batch without resending, restart).
|
|
52
|
+
* No-op while waiting or while a previous call is still running.
|
|
60
53
|
*/
|
|
61
54
|
next: () => Promise<Result<unknown> | undefined>;
|
|
62
|
-
/**
|
|
63
|
-
* Stops tracking the current swap and re-reads the approval strategy. Cancels nothing on-chain; a no-op
|
|
64
|
-
* while the swap call is still in flight.
|
|
65
|
-
*/
|
|
55
|
+
/** Stops tracking the current swap; cancels nothing on-chain and is a no-op while the swap call is in flight. */
|
|
66
56
|
reset: () => void;
|
|
67
57
|
// Escape hatches: the composed hooks, for UIs that need more than `state`.
|
|
68
58
|
approvalStrategy: UseQueryResult<SwapApprovalStrategy, Error>;
|
|
@@ -70,17 +60,13 @@ export type SwapLifecycle<K extends SpokeChainKey = SpokeChainKey> = {
|
|
|
70
60
|
status: UseQueryResult<UseDetailedStatusResult>;
|
|
71
61
|
stellar: StellarGate;
|
|
72
62
|
nearStorage: NearStorageGate;
|
|
63
|
+
/** `blockedReason` names why an XRPL destination cannot receive when the state is `xrpBlocked`. */
|
|
64
|
+
xrp: XrpGate;
|
|
73
65
|
};
|
|
74
66
|
|
|
75
67
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* signature on an EIP-5792 wallet) and its status (`useDetailedStatus`), as a single discriminated
|
|
79
|
-
* `state` with one `next()` action. Render from `state.kind`; wire the button to `next()`.
|
|
80
|
-
*
|
|
81
|
-
* Headless and additive: the granular hooks are unchanged, and each one this composes is returned.
|
|
82
|
-
* Wallet-layer concerns (chain switching, app-owned setup) are passed in, because dapp-kit does not
|
|
83
|
-
* depend on the wallet packages.
|
|
68
|
+
* Composes approval, destination setup gates, chain switching, swap and status into one `state` plus a `next()` action.
|
|
69
|
+
* Wallet-layer concerns are passed in because dapp-kit does not depend on the wallet packages.
|
|
84
70
|
*/
|
|
85
71
|
export function useSwapLifecycle<K extends SpokeChainKey = SpokeChainKey>({
|
|
86
72
|
intentParams,
|
|
@@ -112,12 +98,24 @@ export function useSwapLifecycle<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
112
98
|
walletProvider: dstWalletProvider,
|
|
113
99
|
});
|
|
114
100
|
|
|
101
|
+
const xrp = useXrpGate({
|
|
102
|
+
dstChainKey: intentParams?.dstChainKey,
|
|
103
|
+
token: intentParams?.outputToken,
|
|
104
|
+
address: intentParams?.dstAddress,
|
|
105
|
+
// Sized as the SDK's check before signing sizes it, so the gate never passes a swap the SDK then refuses.
|
|
106
|
+
amount: intentParams?.minOutputAmount,
|
|
107
|
+
maxAmount: intentParams && intentParams.minOutputAmount * SOLVED_PAYOUT_HEADROOM_FACTOR,
|
|
108
|
+
walletProvider: dstWalletProvider,
|
|
109
|
+
});
|
|
110
|
+
|
|
115
111
|
// The setup mutations invalidate these checks without awaiting the refetch, so a stale "needs setup"
|
|
116
112
|
// outlives the tx by one read.
|
|
117
113
|
const fetchingSetupChecks =
|
|
118
114
|
useIsFetching({ queryKey: ['sponsoring', 'stellarAccountStatus'] }) +
|
|
119
115
|
useIsFetching({ queryKey: ['shared', 'stellarTrustlineCheck'] }) +
|
|
120
|
-
useIsFetching({ queryKey: ['shared', 'nearStorageCheck'] })
|
|
116
|
+
useIsFetching({ queryKey: ['shared', 'nearStorageCheck'] }) +
|
|
117
|
+
useIsFetching({ queryKey: ['shared', 'xrpDestinationCheck'] }) +
|
|
118
|
+
useIsFetching({ queryKey: ['shared', 'xrpTrustlineReserveCheck'] });
|
|
121
119
|
|
|
122
120
|
const attempt = toSwapAttempt(swap, intentParams);
|
|
123
121
|
const broadcast = attempt.phase === 'broadcast' ? attempt : undefined;
|
|
@@ -132,9 +130,14 @@ export function useSwapLifecycle<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
132
130
|
hasInputs: !!intentParams && !!srcWalletProvider,
|
|
133
131
|
stellar,
|
|
134
132
|
nearStorage,
|
|
133
|
+
xrp,
|
|
135
134
|
externalBlocked,
|
|
136
135
|
setupBusy:
|
|
137
|
-
stellar.isActivating ||
|
|
136
|
+
stellar.isActivating ||
|
|
137
|
+
stellar.isRequestingTrustline ||
|
|
138
|
+
nearStorage.isRegistering ||
|
|
139
|
+
xrp.isRequestingTrustline ||
|
|
140
|
+
fetchingSetupChecks > 0,
|
|
138
141
|
isWrongChain: chainSwitch?.isWrongChain ?? false,
|
|
139
142
|
strategy: { data: approvalStrategy.data, error: approvalStrategy.error },
|
|
140
143
|
});
|
|
@@ -157,7 +160,9 @@ export function useSwapLifecycle<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
157
160
|
if (state.reason === 'nearStorage') return nearStorage.registerStorage();
|
|
158
161
|
if (state.reason === 'stellarCheckFailed') stellar.retry();
|
|
159
162
|
if (state.reason === 'nearStorageCheckFailed') nearStorage.retry();
|
|
160
|
-
|
|
163
|
+
if (state.reason === 'xrpTrustline') return xrp.requestTrustline();
|
|
164
|
+
if (state.reason === 'xrpCheckFailed') xrp.retry();
|
|
165
|
+
// `stellarFunding`, `xrpFunding`, `xrpBlocked` and `external` are for the app to resolve.
|
|
161
166
|
return undefined;
|
|
162
167
|
case 'ready':
|
|
163
168
|
if (!intentParams || !srcWalletProvider) return undefined;
|
|
@@ -208,5 +213,6 @@ export function useSwapLifecycle<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
208
213
|
status,
|
|
209
214
|
stellar,
|
|
210
215
|
nearStorage,
|
|
216
|
+
xrp,
|
|
211
217
|
};
|
|
212
218
|
}
|
|
@@ -7,20 +7,11 @@ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMu
|
|
|
7
7
|
import { retryBeforeSubmission } from '../shared/retryBeforeSubmission.js';
|
|
8
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* Mutation variables for {@link useSwapWithApproval}: `useSwap`'s, plus `allowAccountUpgrade`, `resumeBatchId` and
|
|
12
|
-
* `resumeBatchCallCount`.
|
|
13
|
-
*/
|
|
14
10
|
export type UseSwapWithApprovalVars<K extends SpokeChainKey = SpokeChainKey> = Omit<SwapWithApprovalParams<K>, 'raw'>;
|
|
15
11
|
|
|
16
12
|
/**
|
|
17
|
-
* `useSwap` with
|
|
18
|
-
*
|
|
19
|
-
* batch-capable EVM wallet, otherwise approve, wait for it, then swap. `data.approvalStrategy`
|
|
20
|
-
* says which ran; {@link useSwapApprovalStrategy} predicts it.
|
|
21
|
-
*
|
|
22
|
-
* Throws on SDK failure so React Query's error model engages. On success invalidates balances and
|
|
23
|
-
* the swap allowance and approval-strategy queries.
|
|
13
|
+
* `useSwap` with approval folded in (one EIP-5792 batch where supported); `data.approvalStrategy` says which path ran.
|
|
14
|
+
* Throws on SDK failure; on success invalidates balances, allowance and approval-strategy queries.
|
|
24
15
|
*/
|
|
25
16
|
export function useSwapWithApproval<K extends SpokeChainKey = SpokeChainKey>({
|
|
26
17
|
mutationOptions,
|
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Swaps API hooks — typed React Query wrappers over `sodax.api.swaps.*` (the SwapsApiService
|
|
3
|
-
* HTTP client). One hook per endpoint of the backend Swaps API.
|
|
4
|
-
*
|
|
5
|
-
* Distinct from the on-chain `swap/` hooks (`useQuote`/`useStatus`/`useSwap`/…), which drive the
|
|
6
|
-
* `SwapService` path (wallet → hub chain). These hooks call the backend HTTP API instead.
|
|
7
|
-
*/
|
|
1
|
+
/** Hooks over the backend Swaps HTTP API (`sodax.api.swaps`); the on-chain `swap/` hooks are separate. */
|
|
8
2
|
|
|
9
|
-
// Tokens
|
|
10
3
|
export * from './useSwapsApiTokens.js';
|
|
11
4
|
export * from './useSwapsApiTokensByChain.js';
|
|
12
5
|
|
|
13
|
-
// Quote · deadline
|
|
14
6
|
export * from './useSwapsApiQuote.js';
|
|
15
7
|
export * from './useSwapsApiDeadline.js';
|
|
16
8
|
|
|
17
|
-
// Allowance · approve · create intent
|
|
18
9
|
export * from './useSwapsApiAllowance.js';
|
|
19
10
|
export * from './useSwapsApiApprove.js';
|
|
20
11
|
export * from './useSwapsApiApproveAndBroadcast.js';
|
|
21
12
|
export * from './useSwapsApiBroadcastWithApproval.js';
|
|
22
13
|
export * from './useSwapsApiCreateIntent.js';
|
|
23
14
|
|
|
24
|
-
// Intent lifecycle: submit · status · cancel · hash · packet · extra-data · lookup
|
|
25
15
|
export * from './useSwapsApiSubmitIntent.js';
|
|
26
16
|
export * from './useSwapsApiStatus.js';
|
|
27
|
-
export * from './isTerminalSwapIntentStatus.js';
|
|
17
|
+
export * from './isTerminalSwapIntentStatus.js';
|
|
28
18
|
export * from './useSwapsApiCancelIntent.js';
|
|
29
19
|
export * from './useSwapsApiIntentHash.js';
|
|
30
20
|
export * from './useSwapsApiIntentPacket.js';
|
|
@@ -32,12 +22,10 @@ export * from './useSwapsApiIntentExtraData.js';
|
|
|
32
22
|
export * from './useSwapsApiFilledIntent.js';
|
|
33
23
|
export * from './useSwapsApiIntent.js';
|
|
34
24
|
|
|
35
|
-
// Limit orders · gas · fees
|
|
36
25
|
export * from './useSwapsApiCreateLimitOrder.js';
|
|
37
26
|
export * from './useSwapsApiEstimateGas.js';
|
|
38
27
|
export * from './useSwapsApiPartnerFee.js';
|
|
39
28
|
export * from './useSwapsApiSolverFee.js';
|
|
40
29
|
|
|
41
|
-
// Submit-tx state machine
|
|
42
30
|
export * from './useSwapsApiSubmitTx.js';
|
|
43
31
|
export * from './useSwapsApiSubmitTxStatus.js';
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { isTerminalSwapIntentStatus } from './isTerminalSwapIntentStatus.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
* Guards the polling-stop invariant for `useSwapsApiStatus.refetchInterval`: the hook keeps polling
|
|
6
|
-
* (1s) until the solver reports a terminal status, then stops. Tested as a pure predicate because
|
|
7
|
-
* dapp-kit's vitest runs in the `node` environment (no hook rendering) — see nearStorageGate.test.ts.
|
|
8
|
-
*/
|
|
4
|
+
// Tested as a pure predicate: dapp-kit's vitest runs in `node`, with no hook rendering.
|
|
9
5
|
describe('isTerminalSwapIntentStatus', () => {
|
|
10
6
|
it('is terminal for SOLVED (3) and FAILED (4)', () => {
|
|
11
7
|
expect(isTerminalSwapIntentStatus(3)).toBe(true);
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import type { SwapIntentStatusCodeV2 } from '@sodax/sdk';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Terminal solver intent states: once reached, the intent is resolved and polling stops.
|
|
5
|
-
* `3` = SOLVED, `4` = FAILED (per `SwapIntentStatusCodeV2`); `-1` / `1` / `2` are non-terminal.
|
|
6
|
-
*
|
|
7
|
-
* Kept in its own pure module (no React/context imports) so it is unit-testable in dapp-kit's
|
|
8
|
-
* `node` test environment — importing the hook itself pulls in `useSodaxContext`.
|
|
9
|
-
*/
|
|
3
|
+
/** SOLVED (3) / FAILED (4): polling stops. Kept React-free so it unit-tests in the `node` env. */
|
|
10
4
|
export const isTerminalSwapIntentStatus = (status: SwapIntentStatusCodeV2 | undefined): boolean =>
|
|
11
5
|
status === 3 || status === 4;
|
|
@@ -13,13 +13,6 @@ export type UseSwapsApiAllowanceParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to check whether the source-token allowance is already sufficient for an intent via
|
|
18
|
-
* the swaps API — `sodax.api.swaps.checkAllowance`. Returns `{ valid }`.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data: allowance } = useSwapsApiAllowance({ params: { body: createIntentParams } });
|
|
22
|
-
*/
|
|
23
16
|
export const useSwapsApiAllowance = ({
|
|
24
17
|
params,
|
|
25
18
|
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 useSwapsApiApprove}. 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 UseSwapsApiApproveVars = {
|
|
14
9
|
body: CreateIntentParamsV2;
|
|
15
10
|
apiConfig?: RequestOverrideConfig;
|
|
16
11
|
};
|
|
17
12
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook to build an unsigned token-approval transaction for the source token via the swaps
|
|
20
|
-
* API — `sodax.api.swaps.approve`. Returns `{ tx }` (chain-specific unsigned tx) to sign and
|
|
21
|
-
* broadcast yourself; it does not change state, so no queries are invalidated.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const { mutateAsync: approve } = useSwapsApiApprove();
|
|
25
|
-
* const { tx } = await approve({ body: createIntentParams });
|
|
26
|
-
*/
|
|
13
|
+
/** Builds the unsigned approval tx(s) only; {@link useSwapsApiApproveAndBroadcast} also signs, orders and waits. */
|
|
27
14
|
export const useSwapsApiApprove = ({
|
|
28
15
|
mutationOptions,
|
|
29
16
|
}: MutationHookParams<ApproveResponseV2, UseSwapsApiApproveVars> = {}): SafeUseMutationResult<
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* The swaps 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 — before
|
|
4
|
-
* it, every integration re-implemented it and could drop the wait or the abort, which costs the user
|
|
5
|
-
* gas on a transaction certain to revert.
|
|
6
|
-
*
|
|
7
|
-
* Follows the package convention of testing hooks without a renderer: the React Query wrapper is
|
|
8
|
-
* mocked so `mutationFn` can be captured and driven directly.
|
|
9
|
-
*/
|
|
1
|
+
// Hooks are tested without a renderer: the React Query wrapper is mocked to capture `mutationFn`.
|
|
10
2
|
|
|
11
3
|
import { ChainKeys, getEvmViemChain } from '@sodax/sdk';
|
|
12
4
|
import type { ApprovalProgress } from '../../utils/approvalPlan.js';
|
|
@@ -40,10 +32,7 @@ const APPROVE_HASH = '0xapprove-hash';
|
|
|
40
32
|
|
|
41
33
|
const body = (srcChainKey: string) => ({ srcChainKey, inputToken: '0xtoken', inputAmount: '1' });
|
|
42
34
|
|
|
43
|
-
/**
|
|
44
|
-
* Records the interleaving of sends and waits so ordering can be asserted, not assumed.
|
|
45
|
-
* `onWait` either throws (the receipt never arrives) or returns the mined status.
|
|
46
|
-
*/
|
|
35
|
+
/** Records send/wait interleaving; `onWait` throws (no receipt) or returns the mined status. */
|
|
47
36
|
function evmProvider(calls: string[], onWait?: (hash: string) => string | void) {
|
|
48
37
|
return {
|
|
49
38
|
sendTransaction: vi.fn(async (tx: { data: string }) => {
|
|
@@ -117,8 +106,7 @@ describe('useSwapsApiApproveAndBroadcast', () => {
|
|
|
117
106
|
it('never sends the approve when the reset is mined but reverts', async () => {
|
|
118
107
|
approve.mockResolvedValue({ ok: true, value: { tx: APPROVE_TX, resetTx: RESET_TX } });
|
|
119
108
|
const calls: string[] = [];
|
|
120
|
-
// A paused
|
|
121
|
-
// the approve that follows is certain to revert too and would be paid for.
|
|
109
|
+
// A paused/blacklisted token mines and reverts the reset; the paid approve would revert too.
|
|
122
110
|
const walletProvider = evmProvider(calls, hash => (hash === RESET_HASH ? 'reverted' : 'success'));
|
|
123
111
|
|
|
124
112
|
await expect(run({ body: body(ChainKeys.ARBITRUM_MAINNET), walletProvider })).rejects.toThrow(
|
|
@@ -131,8 +119,7 @@ describe('useSwapsApiApproveAndBroadcast', () => {
|
|
|
131
119
|
|
|
132
120
|
it('reports a reverted approve, whichever spelling of the status the provider returns', async () => {
|
|
133
121
|
approve.mockResolvedValue({ ok: true, value: { tx: APPROVE_TX } });
|
|
134
|
-
//
|
|
135
|
-
// directly returns `'0x0'`. Both mean the same thing.
|
|
122
|
+
// viem reports `'reverted'`; a provider reading the raw JSON-RPC receipt returns `'0x0'`.
|
|
136
123
|
const walletProvider = evmProvider([], () => '0x0');
|
|
137
124
|
|
|
138
125
|
await expect(run({ body: body(ChainKeys.ARBITRUM_MAINNET), walletProvider })).rejects.toThrow(
|
|
@@ -211,15 +198,13 @@ describe('useSwapsApiApproveAndBroadcast', () => {
|
|
|
211
198
|
|
|
212
199
|
await captured.onSuccess({ approveTxHash: APPROVE_HASH }, {}, undefined);
|
|
213
200
|
|
|
214
|
-
// The hook owns confirmation now, so unlike useSwapsApiApprove it can refresh this itself.
|
|
215
201
|
expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['swapsApi', 'allowance'] });
|
|
216
202
|
});
|
|
217
203
|
|
|
218
204
|
it('awaits the allowance refetch before resolving — a stale cache must not re-enable Approve', async () => {
|
|
219
205
|
useSwapsApiApproveAndBroadcast();
|
|
220
206
|
const order: string[] = [];
|
|
221
|
-
// A macrotask,
|
|
222
|
-
// would land before this fires, so a regression here proves the mutation returned too early.
|
|
207
|
+
// A macrotask, so a mutation that skips awaiting invalidateQueries resolves before this fires.
|
|
223
208
|
invalidateQueries.mockImplementationOnce(
|
|
224
209
|
() =>
|
|
225
210
|
new Promise<void>(resolve => {
|
|
@@ -25,30 +25,9 @@ export type UseSwapsApiApproveAndBroadcastVars<K extends SpokeChainKey = SpokeCh
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* Prefer this over {@link useSwapsApiApprove}, which returns the unsigned `{ tx, resetTx? }` and
|
|
32
|
-
* leaves the rest to you. A source token of the 2017 TetherToken lineage rejects an allowance change
|
|
33
|
-
* from one non-zero value to another, so the API can hand back a **reset** transaction that must be
|
|
34
|
-
* mined **before** the approve is even a valid state transition. Broadcasting them out of order, or
|
|
35
|
-
* without waiting, spends the user's gas on a transaction that is certain to revert — and that is
|
|
36
|
-
* ordering the package should own rather than every integration re-deriving it.
|
|
37
|
-
*
|
|
38
|
-
* Because confirmation now happens inside the hook, it can invalidate `['swapsApi','allowance']`
|
|
39
|
-
* itself; callers of `useSwapsApiApprove` have to refetch by hand. It first waits up to about 15 seconds
|
|
40
|
-
* for the API to report the allowance as valid, since its RPC can trail the node that confirmed the
|
|
41
|
-
* approve. It resolves after that wait either way, so read the allowance rather than treating success as
|
|
42
|
-
* `valid`.
|
|
43
|
-
*
|
|
44
|
-
* Supports the chains the swaps API can approve on — the hub (Sonic), EVM spokes, and Stellar.
|
|
45
|
-
* Every other chain reports its allowance as always sufficient, so approval never runs for it.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* const { mutateAsyncSafe: approve } = useSwapsApiApproveAndBroadcast();
|
|
49
|
-
* const result = await approve({ body: createIntentParams, walletProvider });
|
|
50
|
-
* if (!result.ok) return;
|
|
51
|
-
* const { resetTxHash, approveTxHash } = result.value; // resetTxHash only on a guarded token
|
|
28
|
+
* Signs and mines each approval tx in order: a USDT-style `resetTx` must mine before the approve.
|
|
29
|
+
* Then waits up to ~15s for the API to report the allowance valid, but resolves either way.
|
|
30
|
+
* Approval runs only on the hub, EVM spokes and Stellar; other chains report the allowance as always sufficient.
|
|
52
31
|
*/
|
|
53
32
|
export const useSwapsApiApproveAndBroadcast = <K extends SpokeChainKey = SpokeChainKey>({
|
|
54
33
|
mutationOptions,
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* wallet can, the approval plan then the intent tx when it cannot. The SDK's batch policy runs for
|
|
4
|
-
* real here; only the wallet and the API are faked.
|
|
5
|
-
*
|
|
6
|
-
* Follows the package convention of testing hooks without a renderer: the React Query wrapper is
|
|
7
|
-
* mocked so `mutationFn` can be captured and driven directly.
|
|
8
|
-
*/
|
|
1
|
+
// Hooks are tested without a renderer: the wrapper is mocked to capture `mutationFn`.
|
|
2
|
+
// The SDK's batch policy runs for real; only the wallet and the API are faked.
|
|
9
3
|
|
|
10
4
|
import {
|
|
11
5
|
ACCOUNT_UPGRADE_DECLINED,
|
|
@@ -36,18 +36,11 @@ export type UseSwapsApiBroadcastWithApprovalVars = ApprovalOptions & {
|
|
|
36
36
|
apiConfig?: RequestOverrideConfig;
|
|
37
37
|
/** Progress of a separate approval, hashes included. A batch is one prompt and reports nothing. */
|
|
38
38
|
onProgress?: ApprovalProgressListener;
|
|
39
|
-
/**
|
|
40
|
-
* Called with the batch id and its call count once the wallet accepts the batch, before the wait.
|
|
41
|
-
* Persist both: if the batch comes back unconfirmed, `confirmApprovalBatch` with them is how to find
|
|
42
|
-
* the deposit again instead of sending a second one.
|
|
43
|
-
*/
|
|
39
|
+
/** Fires once the wallet accepts the batch; persist both so `confirmApprovalBatch` can resume an unconfirmed one. */
|
|
44
40
|
onBatchSent?: (batchId: string, callCount: number) => void;
|
|
45
41
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* sends nothing: approve with `useSwapsApiApproveAndBroadcast`, then create the intent again and sign
|
|
49
|
-
* that one. `true` approves and then sends this `intentTx` instead — built before the approval, so its
|
|
50
|
-
* deadline and quote must outlast the approval's wait.
|
|
42
|
+
* On refusal or no batch support: approve, then send this `intentTx` (default: reject, send nothing).
|
|
43
|
+
* `intentTx` predates the approval, so its deadline and quote must outlast the approval wait.
|
|
51
44
|
*/
|
|
52
45
|
fallbackOnRefusal?: boolean;
|
|
53
46
|
};
|
|
@@ -63,37 +56,9 @@ export type SwapsApiBroadcastWithApprovalResult = {
|
|
|
63
56
|
const sameAddress = (a: string, b: string): boolean => a.toLowerCase() === b.toLowerCase();
|
|
64
57
|
|
|
65
58
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* Call it when `/swaps/allowance/check` says the allowance is short and the source is an EVM chain —
|
|
71
|
-
* it always approves, so with enough allowance sign `intentTx` directly instead. It stops at the
|
|
72
|
-
* broadcast: persist `txHash` and then call `/swaps/submit-tx` as before.
|
|
73
|
-
*
|
|
74
|
-
* The batch rules match the SDK's `swapWithApproval`; the Sonic hub never batches. With no batch to
|
|
75
|
-
* send — the wallet cannot batch, or refuses the batch before signing — it rejects with a refusal
|
|
76
|
-
* (`isAtomicBatchRefusal`) and sends nothing: approve with `useSwapsApiApproveAndBroadcast`, create
|
|
77
|
-
* the intent again and sign that. `fallbackOnRefusal: true` approves (via {@link runApprovalPlan}) and
|
|
78
|
-
* sends this `intentTx` instead. A batch the user saw is never resent:
|
|
79
|
-
* - rejected → `SodaxError` `USER_REJECTED`, with `context.reason: ACCOUNT_UPGRADE_DECLINED` when the
|
|
80
|
-
* user declined the account upgrade — retry with `allowAccountUpgrade: false`;
|
|
81
|
-
* - never included or fully reverted → `INTENT_CREATION_FAILED`, `context.reason: 'atomic-batch-failed'`;
|
|
82
|
-
* - sent but not confirmed → `TX_VERIFICATION_FAILED`, `context.reason: ATOMIC_BATCH_UNCONFIRMED`. It
|
|
83
|
-
* may still land: do not let the user swap again. Resume it with `confirmApprovalBatch` and the
|
|
84
|
-
* batch id `onBatchSent` reported.
|
|
85
|
-
*
|
|
86
|
-
* With `fallbackOnRefusal: true`, errors from the separate approval or intent send are the wallet's
|
|
87
|
-
* own, as with `useSwapsApiApproveAndBroadcast`.
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* const { mutateAsyncSafe: broadcast } = useSwapsApiBroadcastWithApproval();
|
|
91
|
-
* const created = await sodax.api.swaps.createIntent(body);
|
|
92
|
-
* const result = await broadcast({ body, intentTx: created.value.tx as EvmRawTransaction, walletProvider });
|
|
93
|
-
* if (result.ok) await submitTx({ txHash: result.value.txHash, ... });
|
|
94
|
-
* else if (isAtomicBatchRefusal(result.error)) {
|
|
95
|
-
* // Nothing was sent: approve, create the intent again (fresh deadline), sign it, then submit-tx.
|
|
96
|
-
* }
|
|
59
|
+
* Sends the approval and EVM `intentTx` as one EIP-5792 batch; a batch the user saw is never resent.
|
|
60
|
+
* Unconfirmed batch → `TX_VERIFICATION_FAILED` (may still land: resume via `confirmApprovalBatch`, never re-swap).
|
|
61
|
+
* Rejected → `USER_REJECTED` (`ACCOUNT_UPGRADE_DECLINED`: retry with `allowAccountUpgrade: false`); reverted → `INTENT_CREATION_FAILED`.
|
|
97
62
|
*/
|
|
98
63
|
export const useSwapsApiBroadcastWithApproval = ({
|
|
99
64
|
mutationOptions,
|
|
@@ -5,24 +5,11 @@ 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 useSwapsApiCancelIntent}. The per-request `apiConfig` override
|
|
10
|
-
* belongs here rather than at the hook level.
|
|
11
|
-
*/
|
|
12
8
|
export type UseSwapsApiCancelIntentVars = {
|
|
13
9
|
body: CancelIntentRequestV2;
|
|
14
10
|
apiConfig?: RequestOverrideConfig;
|
|
15
11
|
};
|
|
16
12
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook to build an unsigned cancel-intent transaction via the swaps API —
|
|
19
|
-
* `sodax.api.swaps.cancelIntent`. The `intent` carries `bigint` numerics. Returns `{ tx }` to sign
|
|
20
|
-
* and broadcast yourself; it does not change state, so no queries are invalidated.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* const { mutateAsync: cancelIntent } = useSwapsApiCancelIntent();
|
|
24
|
-
* const { tx } = await cancelIntent({ body: { srcChainKey: 'sonic', intent } });
|
|
25
|
-
*/
|
|
26
13
|
export const useSwapsApiCancelIntent = ({
|
|
27
14
|
mutationOptions,
|
|
28
15
|
}: MutationHookParams<CancelIntentResponseV2, UseSwapsApiCancelIntentVars> = {}): SafeUseMutationResult<
|
|
@@ -5,24 +5,11 @@ 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 useSwapsApiCreateIntent}. The per-request `apiConfig` override
|
|
10
|
-
* belongs here rather than at the hook level.
|
|
11
|
-
*/
|
|
12
8
|
export type UseSwapsApiCreateIntentVars = {
|
|
13
9
|
body: CreateIntentParamsV2;
|
|
14
10
|
apiConfig?: RequestOverrideConfig;
|
|
15
11
|
};
|
|
16
12
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook to build an unsigned create-intent transaction via the swaps API —
|
|
19
|
-
* `sodax.api.swaps.createIntent`. Returns `{ tx, intent, relayData }` to sign and broadcast
|
|
20
|
-
* yourself; it does not change state, so no queries are invalidated.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* const { mutateAsync: createIntent } = useSwapsApiCreateIntent();
|
|
24
|
-
* const { tx, intent, relayData } = await createIntent({ body: createIntentParams });
|
|
25
|
-
*/
|
|
26
13
|
export const useSwapsApiCreateIntent = ({
|
|
27
14
|
mutationOptions,
|
|
28
15
|
}: MutationHookParams<CreateIntentResponseV2, UseSwapsApiCreateIntentVars> = {}): SafeUseMutationResult<
|
|
@@ -5,24 +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 useSwapsApiCreateLimitOrder}. The per-request `apiConfig` override
|
|
10
|
-
* belongs here rather than at the hook level.
|
|
11
|
-
*/
|
|
12
8
|
export type UseSwapsApiCreateLimitOrderVars = {
|
|
13
9
|
body: CreateLimitOrderParamsV2;
|
|
14
10
|
apiConfig?: RequestOverrideConfig;
|
|
15
11
|
};
|
|
16
12
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook to build an unsigned create-limit-order-intent transaction via the swaps API —
|
|
19
|
-
* `sodax.api.swaps.createLimitOrderIntent` (same as create-intent but `deadline` is optional).
|
|
20
|
-
* Returns `{ tx, intent, relayData }`; it does not change state, so no queries are invalidated.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* const { mutateAsync: createLimitOrder } = useSwapsApiCreateLimitOrder();
|
|
24
|
-
* const { tx, intent, relayData } = await createLimitOrder({ body: createLimitOrderParams });
|
|
25
|
-
*/
|
|
13
|
+
/** Same as create-intent, but `deadline` is optional. */
|
|
26
14
|
export const useSwapsApiCreateLimitOrder = ({
|
|
27
15
|
mutationOptions,
|
|
28
16
|
}: MutationHookParams<CreateLimitOrderResponseV2, UseSwapsApiCreateLimitOrderVars> = {}): SafeUseMutationResult<
|
|
@@ -13,13 +13,7 @@ export type UseSwapsApiDeadlineParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to compute a swap deadline (hub timestamp + `offsetSeconds`, default 300s) via the
|
|
18
|
-
* swaps API — `sodax.api.swaps.getDeadline`.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data: deadline } = useSwapsApiDeadline({ params: { query: { offsetSeconds: 600 } } });
|
|
22
|
-
*/
|
|
16
|
+
/** Hub timestamp + `offsetSeconds` (default 300s). */
|
|
23
17
|
export const useSwapsApiDeadline = ({
|
|
24
18
|
params,
|
|
25
19
|
queryOptions,
|
|
@@ -13,13 +13,6 @@ export type UseSwapsApiEstimateGasParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to estimate gas for a raw transaction on a spoke chain via the swaps API —
|
|
18
|
-
* `sodax.api.swaps.estimateGas`. Returns `{ gas }` (chain-specific shape).
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data } = useSwapsApiEstimateGas({ params: { body: { chainKey: 'sonic', tx } } });
|
|
22
|
-
*/
|
|
23
16
|
export const useSwapsApiEstimateGas = ({
|
|
24
17
|
params,
|
|
25
18
|
queryOptions,
|
|
@@ -13,14 +13,6 @@ export type UseSwapsApiFilledIntentParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to get the on-chain fill state for an intent by its hub-chain tx hash via the swaps
|
|
18
|
-
* API — `sodax.api.swaps.getFilledIntent`. Returns
|
|
19
|
-
* `{ exists, remainingInput, receivedOutput, pendingPayment }`.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* const { data: fill } = useSwapsApiFilledIntent({ params: { txHash: '0x123...' } });
|
|
23
|
-
*/
|
|
24
16
|
export const useSwapsApiFilledIntent = ({
|
|
25
17
|
params,
|
|
26
18
|
queryOptions,
|
|
@@ -13,13 +13,7 @@ export type UseSwapsApiIntentParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to look up an Intent struct by its hub-chain creation tx hash via the swaps API —
|
|
18
|
-
* `sodax.api.swaps.getIntent`. The decoded intent's bigint fields are returned as decimal strings.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data: intent } = useSwapsApiIntent({ params: { txHash: '0x123...' } });
|
|
22
|
-
*/
|
|
16
|
+
/** Bigint fields of the decoded intent come back as decimal strings. */
|
|
23
17
|
export const useSwapsApiIntent = ({
|
|
24
18
|
params,
|
|
25
19
|
queryOptions,
|
|
@@ -13,14 +13,7 @@ export type UseSwapsApiIntentExtraDataParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to recover the relay extra data needed by `/swaps/intents/submit` via the swaps API —
|
|
18
|
-
* `sodax.api.swaps.getIntentSubmitTxExtraData`. Provide EITHER `txHash` OR `intent` in the body
|
|
19
|
-
* (whose `bigint` numerics are serialized by the SDK). Returns `{ address, payload }`.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* const { data } = useSwapsApiIntentExtraData({ params: { body: { txHash: '0x123...' } } });
|
|
23
|
-
*/
|
|
16
|
+
/** Pass either `txHash` or `intent` in the body. */
|
|
24
17
|
export const useSwapsApiIntentExtraData = ({
|
|
25
18
|
params,
|
|
26
19
|
queryOptions,
|
|
@@ -13,13 +13,6 @@ export type UseSwapsApiIntentHashParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to compute the keccak256 hash of an Intent struct via the swaps API —
|
|
18
|
-
* `sodax.api.swaps.getIntentHash`. The `intent` carries `bigint` numerics. Returns `{ hash }`.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data } = useSwapsApiIntentHash({ params: { intent } });
|
|
22
|
-
*/
|
|
23
16
|
export const useSwapsApiIntentHash = ({
|
|
24
17
|
params,
|
|
25
18
|
queryOptions,
|