@sodax/dapp-kit 2.4.0-rc.2 → 2.4.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +279 -2428
- package/dist/index.mjs +15 -24
- package/package.json +2 -2
- package/src/hooks/_apiKeyWire.test.ts +4 -29
- package/src/hooks/_mutationContract.test.ts +1 -8
- package/src/hooks/backend/index.ts +0 -13
- package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +0 -6
- package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +0 -10
- package/src/hooks/backend/useBackendIntentByHash.ts +0 -6
- package/src/hooks/backend/useBackendIntentByTxHash.ts +1 -10
- package/src/hooks/backend/useBackendMoneyMarketAsset.ts +0 -6
- package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +0 -8
- package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +0 -8
- package/src/hooks/backend/useBackendMoneyMarketPosition.ts +0 -6
- package/src/hooks/backend/useBackendOracleCandles.ts +1 -9
- package/src/hooks/backend/useBackendOracleMarkets.ts +1 -7
- package/src/hooks/backend/useBackendOrderbook.ts +0 -6
- package/src/hooks/backend/useBackendUserIntents.ts +0 -8
- package/src/hooks/bitcoin/resolveBtcReadAddress.test.ts +1 -3
- package/src/hooks/bitcoin/resolveBtcReadAddress.ts +2 -12
- package/src/hooks/bitcoin/useBitcoinBalance.ts +1 -7
- package/src/hooks/bitcoin/useBitcoinTradingSetup.ts +2 -4
- package/src/hooks/bitcoin/useEnsureRadfiAccessToken.ts +2 -13
- package/src/hooks/bitcoin/useFundTradingWallet.ts +0 -6
- package/src/hooks/bitcoin/useRadfiAuth.ts +1 -6
- package/src/hooks/bitcoin/useRadfiSession.ts +0 -1
- package/src/hooks/bitcoin/useRadfiWithdraw.ts +0 -6
- package/src/hooks/bitcoin/useRenewUtxos.ts +0 -5
- package/src/hooks/bitcoin/useTradingWallet.ts +1 -4
- package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.test.ts +1 -7
- package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.ts +7 -21
- package/src/hooks/bridge/useBridge.test.ts +1 -11
- package/src/hooks/bridge/useBridge.ts +2 -12
- package/src/hooks/bridge/useBridgeAllowance.ts +1 -2
- package/src/hooks/bridge/useBridgeApprovalStrategy.ts +2 -6
- package/src/hooks/bridge/useBridgeApprove.ts +2 -14
- package/src/hooks/bridge/useBridgeDetailedStatus.test.ts +2 -11
- package/src/hooks/bridge/useBridgeDetailedStatus.ts +3 -23
- package/src/hooks/bridge/useBridgeWithApproval.ts +2 -11
- package/src/hooks/bridgeApi/getBridgeSubmitTxStatusRefetchInterval.test.ts +2 -7
- package/src/hooks/bridgeApi/getBridgeSubmitTxStatusRefetchInterval.ts +2 -13
- package/src/hooks/bridgeApi/index.ts +11 -14
- package/src/hooks/bridgeApi/useBridgeApiAllowance.ts +1 -9
- package/src/hooks/bridgeApi/useBridgeApiApprove.ts +2 -17
- package/src/hooks/bridgeApi/useBridgeApiApproveAndBroadcast.test.ts +2 -13
- package/src/hooks/bridgeApi/useBridgeApiApproveAndBroadcast.ts +3 -20
- package/src/hooks/bridgeApi/useBridgeApiBridgeableAmount.ts +1 -12
- package/src/hooks/bridgeApi/useBridgeApiCreateBridgeIntent.ts +1 -14
- package/src/hooks/bridgeApi/useBridgeApiFee.ts +2 -11
- package/src/hooks/bridgeApi/useBridgeApiIsBridgeable.ts +1 -12
- package/src/hooks/bridgeApi/useBridgeApiSubmitTx.ts +2 -23
- package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.test.ts +1 -9
- package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.ts +1 -19
- package/src/hooks/bridgeApi/useBridgeApiTokens.ts +0 -8
- package/src/hooks/bridgeApi/useBridgeApiTokensByChain.ts +0 -7
- package/src/hooks/dex/useClaimRewards.ts +1 -12
- package/src/hooks/dex/useCreateDecreaseLiquidityParams.ts +1 -5
- package/src/hooks/dex/useCreateDepositParams.ts +1 -5
- package/src/hooks/dex/useCreateSupplyLiquidityParams.ts +1 -10
- package/src/hooks/dex/useCreateWithdrawParams.ts +1 -5
- package/src/hooks/dex/useDecreaseLiquidity.ts +2 -15
- package/src/hooks/dex/useDexAllowance.ts +1 -5
- package/src/hooks/dex/useDexApprove.ts +1 -12
- package/src/hooks/dex/useDexDeposit.ts +1 -23
- package/src/hooks/dex/useDexWithdraw.ts +1 -13
- package/src/hooks/dex/useLiquidityAmounts.ts +1 -4
- package/src/hooks/dex/usePoolBalances.ts +0 -4
- package/src/hooks/dex/usePoolData.ts +1 -4
- package/src/hooks/dex/usePools.ts +1 -4
- package/src/hooks/dex/usePositionInfo.ts +1 -4
- package/src/hooks/dex/useSupplyLiquidity.ts +3 -20
- package/src/hooks/leverageYield/useApproveLeveragePositionFunding.ts +2 -8
- package/src/hooks/leverageYield/useLeveragePositionAccount.ts +2 -13
- package/src/hooks/leverageYield/useLeveragePositionCollateral.ts +2 -14
- package/src/hooks/leverageYield/useLeveragePositionFundingAllowance.ts +2 -9
- package/src/hooks/leverageYield/useLeveragePositionInfo.ts +1 -13
- package/src/hooks/leverageYield/useLeveragePositionPayoutAddress.ts +3 -15
- package/src/hooks/leverageYield/useLeveragePositionPending.ts +2 -16
- package/src/hooks/leverageYield/useLeveragePositions.ts +1 -15
- package/src/hooks/leverageYield/useLeveragePositionsForUser.ts +1 -15
- package/src/hooks/leverageYield/useLeverageYieldApprovalStrategy.ts +1 -6
- package/src/hooks/leverageYield/useLeverageYieldDeposit.ts +1 -17
- package/src/hooks/leverageYield/useLeverageYieldDetailedStatus.test.ts +3 -14
- package/src/hooks/leverageYield/useLeverageYieldDetailedStatus.ts +2 -19
- package/src/hooks/leverageYield/useLeverageYieldEffectiveApr.ts +1 -12
- package/src/hooks/leverageYield/useLeverageYieldNotifySolver.ts +1 -11
- package/src/hooks/leverageYield/useLeverageYieldPosition.ts +1 -13
- package/src/hooks/leverageYield/useLeverageYieldPreviewRedeem.ts +1 -12
- package/src/hooks/leverageYield/useLeverageYieldQuote.test.ts +3 -13
- package/src/hooks/leverageYield/useLeverageYieldQuote.ts +5 -54
- package/src/hooks/leverageYield/useLeverageYieldShareBalances.ts +2 -29
- package/src/hooks/leverageYield/useLeverageYieldTotalAssets.ts +1 -9
- package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +2 -25
- package/src/hooks/leverageYield/useLeverageYieldVaultSwapWithApproval.ts +1 -11
- package/src/hooks/leverageYield/useLeverageYieldWithdraw.ts +1 -17
- package/src/hooks/leverageYield/useOpenLeveragePosition.ts +5 -18
- package/src/hooks/leverageYield/useRunLeveragePositionOperation.ts +4 -20
- package/src/hooks/leverageYield/useSubmitLeveragePositionIntent.ts +3 -15
- package/src/hooks/leverageYieldApi/index.ts +0 -15
- package/src/hooks/leverageYieldApi/useLeverageYieldApiAllowance.ts +1 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApprove.ts +3 -6
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.test.ts +4 -14
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.ts +4 -26
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApr.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiAsset.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCancelIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateDepositIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateWithdrawIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiDeadline.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiDepositQuote.ts +1 -15
- package/src/hooks/leverageYieldApi/useLeverageYieldApiEffectiveApr.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiEstimateGas.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiFilledIntent.ts +1 -6
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntent.ts +1 -6
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentExtraData.ts +1 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentHash.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentPacket.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiLsdApr.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiMaxWithdraw.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPartnerFee.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPosition.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewDeposit.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewRedeem.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewWithdraw.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiShareBalance.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSolverFee.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiStatus.ts +2 -12
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTx.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTxStatus.ts +2 -17
- package/src/hooks/leverageYieldApi/useLeverageYieldApiTotalAssets.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiVault.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiVaults.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiWithdrawQuote.ts +1 -15
- package/src/hooks/migrate/useMigrateBaln.ts +1 -8
- package/src/hooks/migrate/useMigrateIcxToSoda.ts +1 -12
- package/src/hooks/migrate/useMigratebnUSD.ts +1 -12
- package/src/hooks/migrate/useMigrationAllowance.ts +3 -19
- package/src/hooks/migrate/useMigrationApprove.ts +2 -20
- package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +0 -7
- package/src/hooks/mm/useAToken.ts +1 -6
- package/src/hooks/mm/useATokensBalances.ts +0 -5
- package/src/hooks/mm/useBorrow.ts +1 -13
- package/src/hooks/mm/useEModes.ts +2 -13
- package/src/hooks/mm/useMMAllowance.test.ts +55 -0
- package/src/hooks/mm/useMMAllowance.ts +6 -16
- package/src/hooks/mm/useMMApprove.ts +1 -14
- package/src/hooks/mm/useRepay.ts +1 -12
- package/src/hooks/mm/useReservesData.ts +0 -4
- package/src/hooks/mm/useReservesHumanized.ts +0 -4
- package/src/hooks/mm/useReservesList.ts +0 -4
- package/src/hooks/mm/useReservesUsdFormat.ts +0 -4
- package/src/hooks/mm/useSupply.ts +1 -24
- package/src/hooks/mm/useUserFormattedSummary.ts +0 -7
- package/src/hooks/mm/useUserReservesData.ts +0 -4
- package/src/hooks/mm/useWithdraw.ts +1 -13
- package/src/hooks/partner/useApproveToken.ts +1 -7
- package/src/hooks/partner/useFeeClaimSwap.ts +1 -7
- package/src/hooks/partner/useFeeClaimWithdraw.ts +3 -20
- package/src/hooks/partner/useFetchAssetsBalances.ts +0 -4
- package/src/hooks/partner/useGetAutoSwapPreferences.ts +0 -4
- package/src/hooks/partner/useGetIntentDetails.ts +1 -8
- package/src/hooks/partner/useGetUserIntent.ts +1 -8
- package/src/hooks/partner/useIsTokenApproved.ts +0 -4
- package/src/hooks/partner/usePartnerCancelIntent.ts +2 -9
- package/src/hooks/partner/useSetSwapPreference.ts +1 -14
- package/src/hooks/recovery/useHubAssetBalances.ts +1 -6
- package/src/hooks/recovery/useWithdrawHubAsset.ts +1 -13
- package/src/hooks/shared/invalidateBalances.ts +2 -10
- package/src/hooks/shared/isUserRejectedError.test.ts +0 -3
- package/src/hooks/shared/isUserRejectedError.ts +2 -23
- package/src/hooks/shared/notFoundStreak.ts +5 -22
- package/src/hooks/shared/retryUnlessAuthFailure.test.ts +1 -2
- package/src/hooks/shared/retryUnlessAuthFailure.ts +1 -12
- package/src/hooks/shared/solverStatusPolicy.test.ts +0 -5
- package/src/hooks/shared/solverStatusPolicy.ts +8 -58
- package/src/hooks/shared/types.ts +4 -55
- package/src/hooks/shared/unwrapResult.ts +1 -8
- package/src/hooks/shared/useBalances.ts +6 -39
- package/src/hooks/shared/useEstablishTrustline.test.ts +1 -5
- package/src/hooks/shared/useEstablishTrustline.ts +3 -13
- package/src/hooks/shared/useEstablishXrpTrustline.test.ts +1 -2
- package/src/hooks/shared/useEstablishXrpTrustline.ts +3 -5
- package/src/hooks/shared/useEstimateGas.ts +0 -1
- package/src/hooks/shared/useGetUserHubWalletAddress.ts +1 -18
- package/src/hooks/shared/useNearStorageCheck.ts +2 -9
- package/src/hooks/shared/useNearStorageGate.ts +5 -15
- package/src/hooks/shared/useRegisterNearStorage.ts +2 -10
- package/src/hooks/shared/useRequestTrustline.test.ts +1 -7
- package/src/hooks/shared/useRequestTrustline.ts +4 -14
- package/src/hooks/shared/useSafeMutation.test.ts +0 -3
- package/src/hooks/shared/useSafeMutation.ts +2 -26
- package/src/hooks/shared/useSodaxContext.ts +0 -6
- package/src/hooks/shared/useStellarGate.test.ts +2 -9
- package/src/hooks/shared/useStellarGate.ts +3 -9
- package/src/hooks/shared/useStellarTrustlineCheck.test.ts +0 -2
- package/src/hooks/shared/useStellarTrustlineCheck.ts +1 -4
- package/src/hooks/shared/useXBalances.ts +2 -20
- package/src/hooks/shared/useXrpDestinationCheck.ts +1 -5
- package/src/hooks/shared/useXrpGate.test.ts +1 -3
- package/src/hooks/shared/useXrpGate.ts +2 -3
- package/src/hooks/shared/waitForApiAllowance.test.ts +0 -1
- package/src/hooks/shared/waitForApiAllowance.ts +2 -6
- package/src/hooks/sponsoring/useActivateStellarAccount.test.ts +1 -2
- package/src/hooks/sponsoring/useActivateStellarAccount.ts +1 -5
- package/src/hooks/sponsoring/useActivateStellarAccount.wire.test.ts +2 -13
- package/src/hooks/sponsoring/useSponsorConfig.ts +0 -1
- package/src/hooks/sponsoring/useStellarAccountActive.ts +0 -1
- package/src/hooks/sponsoring/useStellarAccountStatus.ts +1 -4
- package/src/hooks/staking/index.ts +0 -1
- package/src/hooks/staking/useCancelUnstake.ts +1 -7
- package/src/hooks/staking/useClaim.ts +1 -7
- package/src/hooks/staking/useConvertedAssets.ts +1 -4
- package/src/hooks/staking/useInstantUnstake.ts +1 -7
- package/src/hooks/staking/useInstantUnstakeAllowance.ts +1 -5
- package/src/hooks/staking/useInstantUnstakeApprove.ts +1 -11
- package/src/hooks/staking/useInstantUnstakeRatio.ts +1 -4
- package/src/hooks/staking/useStake.ts +1 -12
- package/src/hooks/staking/useStakeAllowance.ts +1 -5
- package/src/hooks/staking/useStakeApprove.ts +1 -11
- package/src/hooks/staking/useStakeRatio.ts +1 -4
- package/src/hooks/staking/useStakingConfig.ts +1 -4
- package/src/hooks/staking/useStakingInfo.ts +1 -5
- package/src/hooks/staking/useUnstake.ts +2 -9
- package/src/hooks/staking/useUnstakeAllowance.ts +1 -5
- package/src/hooks/staking/useUnstakeApprove.ts +1 -10
- package/src/hooks/staking/useUnstakingInfo.ts +1 -4
- package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +1 -4
- package/src/hooks/swap/useCancelLimitOrder.ts +1 -7
- package/src/hooks/swap/useCancelSwap.ts +1 -7
- package/src/hooks/swap/useCreateLimitOrder.ts +2 -12
- package/src/hooks/swap/useDetailedStatus.test.ts +6 -18
- package/src/hooks/swap/useDetailedStatus.ts +2 -19
- package/src/hooks/swap/useQuote.test.ts +2 -8
- package/src/hooks/swap/useQuote.ts +5 -32
- package/src/hooks/swap/useStatus.ts +2 -10
- package/src/hooks/swap/useSwap.test.ts +1 -11
- package/src/hooks/swap/useSwap.ts +2 -12
- package/src/hooks/swap/useSwapAllowance.ts +1 -2
- package/src/hooks/swap/useSwapApprovalStrategy.ts +2 -7
- package/src/hooks/swap/useSwapApprove.ts +2 -14
- package/src/hooks/swap/useSwapLifecycle.test.ts +1 -2
- package/src/hooks/swap/useSwapLifecycle.ts +9 -27
- package/src/hooks/swap/useSwapWithApproval.ts +2 -11
- package/src/hooks/swapsApi/index.ts +2 -14
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.test.ts +1 -5
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.ts +1 -7
- package/src/hooks/swapsApi/useSwapsApiAllowance.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiApprove.ts +1 -14
- package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.test.ts +5 -20
- package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.ts +3 -24
- package/src/hooks/swapsApi/useSwapsApiBroadcastWithApproval.test.ts +2 -8
- package/src/hooks/swapsApi/useSwapsApiBroadcastWithApproval.ts +6 -41
- package/src/hooks/swapsApi/useSwapsApiCancelIntent.ts +0 -13
- package/src/hooks/swapsApi/useSwapsApiCreateIntent.ts +0 -13
- package/src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts +1 -13
- package/src/hooks/swapsApi/useSwapsApiDeadline.ts +1 -7
- package/src/hooks/swapsApi/useSwapsApiEstimateGas.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiFilledIntent.ts +0 -8
- package/src/hooks/swapsApi/useSwapsApiIntent.ts +1 -7
- package/src/hooks/swapsApi/useSwapsApiIntentExtraData.ts +1 -8
- package/src/hooks/swapsApi/useSwapsApiIntentHash.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiIntentPacket.ts +1 -10
- package/src/hooks/swapsApi/useSwapsApiPartnerFee.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiQuote.ts +2 -24
- package/src/hooks/swapsApi/useSwapsApiSolverFee.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiStatus.ts +1 -11
- package/src/hooks/swapsApi/useSwapsApiSubmitIntent.ts +1 -15
- package/src/hooks/swapsApi/useSwapsApiSubmitTx.ts +0 -21
- package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +2 -19
- package/src/hooks/swapsApi/useSwapsApiTokens.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiTokensByChain.ts +0 -7
- package/src/index.ts +1 -1
- package/src/providers/SodaxProvider.test.ts +2 -9
- package/src/providers/SodaxProvider.tsx +1 -12
- package/src/providers/createSodaxQueryClient.ts +4 -56
- package/src/utils/approvalPlan.ts +9 -32
- package/src/utils/dex-utils.ts +5 -20
- package/src/utils/nearStorageGate.ts +3 -14
- package/src/utils/stellarGate.ts +3 -16
- package/src/utils/swapLifecycle.ts +7 -26
- package/src/utils/xrpGate.ts +1 -4
|
@@ -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,
|
|
@@ -13,16 +13,7 @@ export type UseSwapsApiIntentPacketParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to long-poll the relayer until the fill packet lands on the destination chain via the
|
|
18
|
-
* swaps API — `sodax.api.swaps.getSolvedIntentPacket`. The request is held open server-side until
|
|
19
|
-
* the packet arrives (or `body.timeout` ms elapses), so no client-side `refetchInterval` is set.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* const { data: packet } = useSwapsApiIntentPacket({
|
|
23
|
-
* params: { body: { chainId: '146', fillTxHash: '0x123...' } },
|
|
24
|
-
* });
|
|
25
|
-
*/
|
|
16
|
+
/** Long-polls server-side until the packet lands (or `body.timeout` ms), so no `refetchInterval` is set. */
|
|
26
17
|
export const useSwapsApiIntentPacket = ({
|
|
27
18
|
params,
|
|
28
19
|
queryOptions,
|
|
@@ -13,13 +13,6 @@ export type UseSwapsApiPartnerFeeParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to compute the partner fee for a given input amount via the swaps API —
|
|
18
|
-
* `sodax.api.swaps.getPartnerFee`. Returns `{ fee }` (decimal string).
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data } = useSwapsApiPartnerFee({ params: { amount: '1000000' } });
|
|
22
|
-
*/
|
|
23
16
|
export const useSwapsApiPartnerFee = ({
|
|
24
17
|
params,
|
|
25
18
|
queryOptions,
|
|
@@ -14,26 +14,7 @@ export type UseSwapsApiQuoteParams = ReadHookParams<
|
|
|
14
14
|
}
|
|
15
15
|
>;
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook to get a solver quote for a cross-chain swap via the swaps API —
|
|
19
|
-
* `sodax.api.swaps.getQuote`. Pass `query.includeTxData = true` to also build an unsigned
|
|
20
|
-
* create-intent transaction (`txData`); `srcAddress`/`dstAddress` are then required in the body.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* const { data: quote } = useSwapsApiQuote({
|
|
24
|
-
* params: {
|
|
25
|
-
* body: {
|
|
26
|
-
* tokenSrc: '0x...', tokenSrcChainKey: '0xa4b1.arbitrum',
|
|
27
|
-
* tokenDst: '0x...', tokenDstChainKey: 'sonic',
|
|
28
|
-
* amount: '1000000', quoteType: 'exact_input',
|
|
29
|
-
* partnerFee: { address: '0xSonicFeeReceiver', percentage: 10 },
|
|
30
|
-
* },
|
|
31
|
-
* // Optional per-request override of the configured backend API key (`x-api-key`);
|
|
32
|
-
* // usually set once instead via new Sodax({ apiKey }).
|
|
33
|
-
* apiConfig: { apiKey: 'partner-api-key' },
|
|
34
|
-
* },
|
|
35
|
-
* });
|
|
36
|
-
*/
|
|
17
|
+
/** `query.includeTxData` also builds the unsigned create-intent tx; `srcAddress`/`dstAddress` are then required. */
|
|
37
18
|
export const useSwapsApiQuote = ({
|
|
38
19
|
params,
|
|
39
20
|
queryOptions,
|
|
@@ -44,10 +25,7 @@ export const useSwapsApiQuote = ({
|
|
|
44
25
|
const apiConfig = params?.apiConfig;
|
|
45
26
|
|
|
46
27
|
return useQuery({
|
|
47
|
-
//
|
|
48
|
-
// SwapExtrasV2 fields — is a cache dimension; a partnerFee change alters the quote and must
|
|
49
|
-
// miss the cache. QuoteRequestV2 is bigint-free (compile-time guaranteed), so React Query's
|
|
50
|
-
// default key hashing handles the object directly.
|
|
28
|
+
// Key on the whole (bigint-free) body so every input, e.g. partnerFee, is a cache dimension.
|
|
51
29
|
queryKey: ['swapsApi', 'quote', body, query?.includeTxData ?? false],
|
|
52
30
|
queryFn: async (): Promise<QuoteResponseV2 | undefined> => {
|
|
53
31
|
if (!body) return undefined;
|
|
@@ -13,13 +13,6 @@ export type UseSwapsApiSolverFeeParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to compute the protocol (solver) fee for a given input amount via the swaps API —
|
|
18
|
-
* `sodax.api.swaps.getSolverFee`. Returns `{ fee }` (decimal string).
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data } = useSwapsApiSolverFee({ params: { amount: '1000000' } });
|
|
22
|
-
*/
|
|
23
16
|
export const useSwapsApiSolverFee = ({
|
|
24
17
|
params,
|
|
25
18
|
queryOptions,
|
|
@@ -14,17 +14,7 @@ export type UseSwapsApiStatusParams = ReadHookParams<
|
|
|
14
14
|
}
|
|
15
15
|
>;
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook for polling the solver intent status by hub-chain intent tx hash via the swaps API —
|
|
19
|
-
* `sodax.api.swaps.getStatus`. Returns `{ status, fillTxHash? }` (`fillTxHash` set when `status === 3`).
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* const { data } = useSwapsApiStatus({ params: { intentTxHash: '0x123...' } });
|
|
23
|
-
*
|
|
24
|
-
* @remarks
|
|
25
|
-
* - Default refetch interval is 1 second; stops once `status` is `3` (SOLVED) or `4` (FAILED), or
|
|
26
|
-
* once the backend rejects the API key (401/403 is terminal — a retry cannot fix it).
|
|
27
|
-
*/
|
|
17
|
+
/** Polls every 1s until SOLVED (3), FAILED (4) or an API-key rejection (401/403). */
|
|
28
18
|
export const useSwapsApiStatus = ({
|
|
29
19
|
params,
|
|
30
20
|
queryOptions,
|
|
@@ -4,26 +4,12 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
4
4
|
import type { MutationHookParams } from '../shared/types.js';
|
|
5
5
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Mutation variables for {@link useSwapsApiSubmitIntent}. The per-request `apiConfig` override
|
|
9
|
-
* belongs here rather than at the hook level.
|
|
10
|
-
*/
|
|
11
7
|
export type UseSwapsApiSubmitIntentVars = {
|
|
12
8
|
body: SubmitIntentRequestV2;
|
|
13
9
|
apiConfig?: RequestOverrideConfig;
|
|
14
10
|
};
|
|
15
11
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to submit the broadcast intent tx to the relay via the swaps API —
|
|
18
|
-
* `sodax.api.swaps.submitIntent`. Returns `{ result }` (opaque relay response).
|
|
19
|
-
*
|
|
20
|
-
* No auto-retry (`retry: false`): submitting is non-idempotent — a retry after a lost response
|
|
21
|
-
* could double-submit to the relay. Override via `mutationOptions.retry` if your relay dedupes.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const { mutateAsync: submitIntent } = useSwapsApiSubmitIntent();
|
|
25
|
-
* const { result } = await submitIntent({ body: { chainId: '146', txHash: '0x123...' } });
|
|
26
|
-
*/
|
|
12
|
+
/** No auto-retry: submit is non-idempotent, so a retry after a lost response could double-submit. */
|
|
27
13
|
export const useSwapsApiSubmitIntent = ({
|
|
28
14
|
mutationOptions,
|
|
29
15
|
}: MutationHookParams<SubmitIntentResponseV2, UseSwapsApiSubmitIntentVars> = {}): SafeUseMutationResult<
|
|
@@ -5,32 +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 useSwapsApiSubmitTx}. 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 UseSwapsApiSubmitTxVars = {
|
|
14
9
|
request: SubmitTxRequestV2;
|
|
15
10
|
apiConfig?: RequestOverrideConfig;
|
|
16
11
|
};
|
|
17
12
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook for submitting a swap transaction to be processed (relay, post execution to the
|
|
20
|
-
* solver, etc.) via the swaps API — `sodax.api.swaps.submitTx`.
|
|
21
|
-
*
|
|
22
|
-
* Pure mutation: pass `{ request, apiConfig? }` to `mutate({...})`. Retries up to 3 times at the hook
|
|
23
|
-
* level, except on a terminal API-key rejection (401/403) — see `retryUnlessAuthFailure`. Consumers
|
|
24
|
-
* can override via `mutationOptions.retry`.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* const { mutateAsync: submitSwapTx, isPending, error } = useSwapsApiSubmitTx();
|
|
28
|
-
*
|
|
29
|
-
* const result = await submitSwapTx({
|
|
30
|
-
* request: { txHash: '0x123...', srcChainKey: 'sonic', walletAddress: '0xabc...', intent: { ... }, relayData: '0x...' },
|
|
31
|
-
* apiConfig: { baseURL: 'https://...' },
|
|
32
|
-
* });
|
|
33
|
-
*/
|
|
34
13
|
export const useSwapsApiSubmitTx = ({
|
|
35
14
|
mutationOptions,
|
|
36
15
|
}: MutationHookParams<SubmitTxResponseV2, UseSwapsApiSubmitTxVars> = {}): SafeUseMutationResult<
|
|
@@ -14,21 +14,7 @@ export type UseSwapsApiSubmitTxStatusParams = ReadHookParams<
|
|
|
14
14
|
}
|
|
15
15
|
>;
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook for polling the processing status of a submitted swap transaction via the swaps API —
|
|
19
|
-
* `sodax.api.swaps.getSubmitTxStatus`. Both `txHash` and `srcChainKey` are required for the query
|
|
20
|
-
* to run (the swaps API status query requires the source chain key).
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* const { data: status } = useSwapsApiSubmitTxStatus({
|
|
24
|
-
* params: { txHash: '0x123...', srcChainKey: 'sonic' },
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* @remarks
|
|
28
|
-
* - Default refetch interval is 1 second; stops on 'solved' or 'failed' status, when the
|
|
29
|
-
* backend marks the submission abandoned (`abandonedAt`) while `status` stays non-terminal, or
|
|
30
|
-
* once the backend rejects the API key (401/403 is terminal — a retry cannot fix it).
|
|
31
|
-
*/
|
|
17
|
+
/** Polls every 1s until solved/failed, `abandonedAt` is set, or an API-key rejection (401/403). */
|
|
32
18
|
export const useSwapsApiSubmitTxStatus = ({
|
|
33
19
|
params,
|
|
34
20
|
queryOptions,
|
|
@@ -41,8 +27,6 @@ export const useSwapsApiSubmitTxStatus = ({
|
|
|
41
27
|
return useQuery({
|
|
42
28
|
queryKey: ['swapsApi', 'submitTx', 'status', txHash, srcChainKey],
|
|
43
29
|
queryFn: async (): Promise<SubmitTxStatusResponseV2 | undefined> => {
|
|
44
|
-
// `srcChainKey` is required by the swaps API status query. The `enabled` gate below
|
|
45
|
-
// ensures both are present; this guard also narrows the types for the call.
|
|
46
30
|
if (!txHash || !srcChainKey) return undefined;
|
|
47
31
|
return unwrapResult(await sodax.api.swaps.getSubmitTxStatus({ txHash, srcChainKey }, apiConfig));
|
|
48
32
|
},
|
|
@@ -52,8 +36,7 @@ export const useSwapsApiSubmitTxStatus = ({
|
|
|
52
36
|
// `retry` bounds attempts within a tick, not the interval itself — so stop it here too.
|
|
53
37
|
if (isAuthFailure(query.state.error)) return false;
|
|
54
38
|
const data = query.state.data?.data;
|
|
55
|
-
// `abandonedAt` is terminal even
|
|
56
|
-
// SDK's pollBackendSubmitTx and the bridge-api status hook.
|
|
39
|
+
// `abandonedAt` is terminal even while `status` is not, as in the SDK's pollBackendSubmitTx.
|
|
57
40
|
if (data?.status === 'solved' || data?.status === 'failed' || data?.abandonedAt) return false;
|
|
58
41
|
return 1000;
|
|
59
42
|
},
|