@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.
Files changed (288) hide show
  1. package/README.md +11 -3
  2. package/dist/index.d.ts +395 -2413
  3. package/dist/index.mjs +206 -31
  4. package/package.json +2 -2
  5. package/src/hooks/_apiKeyWire.test.ts +4 -29
  6. package/src/hooks/_mutationContract.test.ts +2 -8
  7. package/src/hooks/backend/index.ts +0 -13
  8. package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +0 -6
  9. package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +0 -10
  10. package/src/hooks/backend/useBackendIntentByHash.ts +0 -6
  11. package/src/hooks/backend/useBackendIntentByTxHash.ts +1 -10
  12. package/src/hooks/backend/useBackendMoneyMarketAsset.ts +0 -6
  13. package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +0 -8
  14. package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +0 -8
  15. package/src/hooks/backend/useBackendMoneyMarketPosition.ts +0 -6
  16. package/src/hooks/backend/useBackendOracleCandles.ts +1 -9
  17. package/src/hooks/backend/useBackendOracleMarkets.ts +1 -7
  18. package/src/hooks/backend/useBackendOrderbook.ts +0 -6
  19. package/src/hooks/backend/useBackendUserIntents.ts +0 -8
  20. package/src/hooks/bitcoin/resolveBtcReadAddress.test.ts +1 -3
  21. package/src/hooks/bitcoin/resolveBtcReadAddress.ts +2 -12
  22. package/src/hooks/bitcoin/useBitcoinBalance.ts +1 -7
  23. package/src/hooks/bitcoin/useBitcoinTradingSetup.ts +2 -4
  24. package/src/hooks/bitcoin/useEnsureRadfiAccessToken.ts +2 -13
  25. package/src/hooks/bitcoin/useFundTradingWallet.ts +0 -6
  26. package/src/hooks/bitcoin/useRadfiAuth.ts +1 -6
  27. package/src/hooks/bitcoin/useRadfiSession.ts +0 -1
  28. package/src/hooks/bitcoin/useRadfiWithdraw.ts +0 -6
  29. package/src/hooks/bitcoin/useRenewUtxos.ts +0 -5
  30. package/src/hooks/bitcoin/useTradingWallet.ts +1 -4
  31. package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.test.ts +1 -7
  32. package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.ts +7 -21
  33. package/src/hooks/bridge/useBridge.test.ts +1 -11
  34. package/src/hooks/bridge/useBridge.ts +2 -12
  35. package/src/hooks/bridge/useBridgeAllowance.ts +1 -2
  36. package/src/hooks/bridge/useBridgeApprovalStrategy.ts +2 -6
  37. package/src/hooks/bridge/useBridgeApprove.ts +2 -14
  38. package/src/hooks/bridge/useBridgeDetailedStatus.test.ts +2 -11
  39. package/src/hooks/bridge/useBridgeDetailedStatus.ts +3 -23
  40. package/src/hooks/bridge/useBridgeWithApproval.ts +2 -11
  41. package/src/hooks/bridgeApi/getBridgeSubmitTxStatusRefetchInterval.test.ts +2 -7
  42. package/src/hooks/bridgeApi/getBridgeSubmitTxStatusRefetchInterval.ts +2 -13
  43. package/src/hooks/bridgeApi/index.ts +11 -14
  44. package/src/hooks/bridgeApi/useBridgeApiAllowance.ts +1 -9
  45. package/src/hooks/bridgeApi/useBridgeApiApprove.ts +2 -17
  46. package/src/hooks/bridgeApi/useBridgeApiApproveAndBroadcast.test.ts +2 -13
  47. package/src/hooks/bridgeApi/useBridgeApiApproveAndBroadcast.ts +3 -20
  48. package/src/hooks/bridgeApi/useBridgeApiBridgeableAmount.ts +1 -12
  49. package/src/hooks/bridgeApi/useBridgeApiCreateBridgeIntent.ts +1 -14
  50. package/src/hooks/bridgeApi/useBridgeApiFee.ts +2 -11
  51. package/src/hooks/bridgeApi/useBridgeApiIsBridgeable.ts +1 -12
  52. package/src/hooks/bridgeApi/useBridgeApiSubmitTx.ts +2 -23
  53. package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.test.ts +1 -9
  54. package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.ts +1 -19
  55. package/src/hooks/bridgeApi/useBridgeApiTokens.ts +0 -8
  56. package/src/hooks/bridgeApi/useBridgeApiTokensByChain.ts +0 -7
  57. package/src/hooks/dex/useClaimRewards.ts +1 -12
  58. package/src/hooks/dex/useCreateDecreaseLiquidityParams.ts +1 -5
  59. package/src/hooks/dex/useCreateDepositParams.ts +1 -5
  60. package/src/hooks/dex/useCreateSupplyLiquidityParams.ts +1 -10
  61. package/src/hooks/dex/useCreateWithdrawParams.ts +1 -5
  62. package/src/hooks/dex/useDecreaseLiquidity.ts +2 -15
  63. package/src/hooks/dex/useDexAllowance.ts +1 -5
  64. package/src/hooks/dex/useDexApprove.ts +1 -12
  65. package/src/hooks/dex/useDexDeposit.ts +1 -23
  66. package/src/hooks/dex/useDexWithdraw.ts +1 -13
  67. package/src/hooks/dex/useLiquidityAmounts.ts +1 -4
  68. package/src/hooks/dex/usePoolBalances.ts +0 -4
  69. package/src/hooks/dex/usePoolData.ts +1 -4
  70. package/src/hooks/dex/usePools.ts +1 -4
  71. package/src/hooks/dex/usePositionInfo.ts +1 -4
  72. package/src/hooks/dex/useSupplyLiquidity.ts +3 -20
  73. package/src/hooks/leverageYield/useApproveLeveragePositionFunding.ts +2 -8
  74. package/src/hooks/leverageYield/useLeveragePositionAccount.ts +2 -13
  75. package/src/hooks/leverageYield/useLeveragePositionCollateral.ts +2 -14
  76. package/src/hooks/leverageYield/useLeveragePositionFundingAllowance.ts +2 -9
  77. package/src/hooks/leverageYield/useLeveragePositionInfo.ts +1 -13
  78. package/src/hooks/leverageYield/useLeveragePositionPayoutAddress.ts +3 -15
  79. package/src/hooks/leverageYield/useLeveragePositionPending.ts +2 -16
  80. package/src/hooks/leverageYield/useLeveragePositions.ts +1 -15
  81. package/src/hooks/leverageYield/useLeveragePositionsForUser.ts +1 -15
  82. package/src/hooks/leverageYield/useLeverageYieldApprovalStrategy.ts +1 -6
  83. package/src/hooks/leverageYield/useLeverageYieldDeposit.ts +1 -17
  84. package/src/hooks/leverageYield/useLeverageYieldDetailedStatus.test.ts +3 -14
  85. package/src/hooks/leverageYield/useLeverageYieldDetailedStatus.ts +2 -19
  86. package/src/hooks/leverageYield/useLeverageYieldEffectiveApr.ts +1 -12
  87. package/src/hooks/leverageYield/useLeverageYieldNotifySolver.ts +1 -11
  88. package/src/hooks/leverageYield/useLeverageYieldPosition.ts +1 -13
  89. package/src/hooks/leverageYield/useLeverageYieldPreviewRedeem.ts +1 -12
  90. package/src/hooks/leverageYield/useLeverageYieldQuote.test.ts +3 -13
  91. package/src/hooks/leverageYield/useLeverageYieldQuote.ts +5 -54
  92. package/src/hooks/leverageYield/useLeverageYieldShareBalances.ts +2 -29
  93. package/src/hooks/leverageYield/useLeverageYieldTotalAssets.ts +1 -9
  94. package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +2 -25
  95. package/src/hooks/leverageYield/useLeverageYieldVaultSwapWithApproval.ts +1 -11
  96. package/src/hooks/leverageYield/useLeverageYieldWithdraw.ts +1 -17
  97. package/src/hooks/leverageYield/useOpenLeveragePosition.ts +5 -18
  98. package/src/hooks/leverageYield/useRunLeveragePositionOperation.ts +4 -20
  99. package/src/hooks/leverageYield/useSubmitLeveragePositionIntent.ts +3 -15
  100. package/src/hooks/leverageYieldApi/index.ts +0 -15
  101. package/src/hooks/leverageYieldApi/useLeverageYieldApiAllowance.ts +1 -8
  102. package/src/hooks/leverageYieldApi/useLeverageYieldApiApprove.ts +3 -6
  103. package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.test.ts +4 -14
  104. package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.ts +4 -26
  105. package/src/hooks/leverageYieldApi/useLeverageYieldApiApr.ts +1 -7
  106. package/src/hooks/leverageYieldApi/useLeverageYieldApiAsset.ts +0 -7
  107. package/src/hooks/leverageYieldApi/useLeverageYieldApiCancelIntent.ts +2 -8
  108. package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateDepositIntent.ts +2 -8
  109. package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateWithdrawIntent.ts +2 -8
  110. package/src/hooks/leverageYieldApi/useLeverageYieldApiDeadline.ts +1 -7
  111. package/src/hooks/leverageYieldApi/useLeverageYieldApiDepositQuote.ts +1 -15
  112. package/src/hooks/leverageYieldApi/useLeverageYieldApiEffectiveApr.ts +1 -7
  113. package/src/hooks/leverageYieldApi/useLeverageYieldApiEstimateGas.ts +1 -7
  114. package/src/hooks/leverageYieldApi/useLeverageYieldApiFilledIntent.ts +1 -6
  115. package/src/hooks/leverageYieldApi/useLeverageYieldApiIntent.ts +1 -6
  116. package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentExtraData.ts +1 -8
  117. package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentHash.ts +0 -7
  118. package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentPacket.ts +1 -7
  119. package/src/hooks/leverageYieldApi/useLeverageYieldApiLsdApr.ts +1 -7
  120. package/src/hooks/leverageYieldApi/useLeverageYieldApiMaxWithdraw.ts +1 -7
  121. package/src/hooks/leverageYieldApi/useLeverageYieldApiPartnerFee.ts +1 -7
  122. package/src/hooks/leverageYieldApi/useLeverageYieldApiPosition.ts +0 -7
  123. package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewDeposit.ts +1 -7
  124. package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewRedeem.ts +1 -7
  125. package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewWithdraw.ts +1 -7
  126. package/src/hooks/leverageYieldApi/useLeverageYieldApiShareBalance.ts +0 -7
  127. package/src/hooks/leverageYieldApi/useLeverageYieldApiSolverFee.ts +1 -7
  128. package/src/hooks/leverageYieldApi/useLeverageYieldApiStatus.ts +2 -12
  129. package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitIntent.ts +2 -8
  130. package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTx.ts +2 -8
  131. package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTxStatus.ts +2 -17
  132. package/src/hooks/leverageYieldApi/useLeverageYieldApiTotalAssets.ts +0 -7
  133. package/src/hooks/leverageYieldApi/useLeverageYieldApiVault.ts +1 -7
  134. package/src/hooks/leverageYieldApi/useLeverageYieldApiVaults.ts +0 -7
  135. package/src/hooks/leverageYieldApi/useLeverageYieldApiWithdrawQuote.ts +1 -15
  136. package/src/hooks/migrate/useMigrateBaln.ts +1 -8
  137. package/src/hooks/migrate/useMigrateIcxToSoda.ts +1 -12
  138. package/src/hooks/migrate/useMigratebnUSD.ts +1 -12
  139. package/src/hooks/migrate/useMigrationAllowance.ts +3 -19
  140. package/src/hooks/migrate/useMigrationApprove.ts +2 -20
  141. package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +0 -7
  142. package/src/hooks/mm/useAToken.ts +1 -6
  143. package/src/hooks/mm/useATokensBalances.ts +0 -5
  144. package/src/hooks/mm/useBorrow.ts +1 -13
  145. package/src/hooks/mm/useEModes.ts +2 -13
  146. package/src/hooks/mm/useMMAllowance.test.ts +55 -0
  147. package/src/hooks/mm/useMMAllowance.ts +6 -16
  148. package/src/hooks/mm/useMMApprove.ts +1 -14
  149. package/src/hooks/mm/useRepay.ts +1 -12
  150. package/src/hooks/mm/useReservesData.ts +0 -4
  151. package/src/hooks/mm/useReservesHumanized.ts +0 -4
  152. package/src/hooks/mm/useReservesList.ts +0 -4
  153. package/src/hooks/mm/useReservesUsdFormat.ts +0 -4
  154. package/src/hooks/mm/useSupply.ts +1 -24
  155. package/src/hooks/mm/useUserFormattedSummary.ts +0 -7
  156. package/src/hooks/mm/useUserReservesData.ts +0 -4
  157. package/src/hooks/mm/useWithdraw.ts +1 -13
  158. package/src/hooks/partner/useApproveToken.ts +1 -7
  159. package/src/hooks/partner/useFeeClaimSwap.ts +1 -7
  160. package/src/hooks/partner/useFeeClaimWithdraw.ts +3 -20
  161. package/src/hooks/partner/useFetchAssetsBalances.ts +0 -4
  162. package/src/hooks/partner/useGetAutoSwapPreferences.ts +0 -4
  163. package/src/hooks/partner/useGetIntentDetails.ts +1 -8
  164. package/src/hooks/partner/useGetUserIntent.ts +1 -8
  165. package/src/hooks/partner/useIsTokenApproved.ts +0 -4
  166. package/src/hooks/partner/usePartnerCancelIntent.ts +2 -9
  167. package/src/hooks/partner/useSetSwapPreference.ts +1 -14
  168. package/src/hooks/recovery/useHubAssetBalances.ts +1 -6
  169. package/src/hooks/recovery/useWithdrawHubAsset.ts +1 -13
  170. package/src/hooks/shared/index.ts +4 -0
  171. package/src/hooks/shared/invalidateBalances.ts +2 -10
  172. package/src/hooks/shared/isUserRejectedError.test.ts +0 -3
  173. package/src/hooks/shared/isUserRejectedError.ts +2 -23
  174. package/src/hooks/shared/notFoundStreak.ts +5 -22
  175. package/src/hooks/shared/retryUnlessAuthFailure.test.ts +1 -2
  176. package/src/hooks/shared/retryUnlessAuthFailure.ts +1 -12
  177. package/src/hooks/shared/solverStatusPolicy.test.ts +0 -5
  178. package/src/hooks/shared/solverStatusPolicy.ts +8 -58
  179. package/src/hooks/shared/types.ts +4 -55
  180. package/src/hooks/shared/unwrapResult.ts +1 -8
  181. package/src/hooks/shared/useBalances.ts +6 -39
  182. package/src/hooks/shared/useEstablishTrustline.test.ts +1 -5
  183. package/src/hooks/shared/useEstablishTrustline.ts +3 -13
  184. package/src/hooks/shared/useEstablishXrpTrustline.test.ts +112 -0
  185. package/src/hooks/shared/useEstablishXrpTrustline.ts +63 -0
  186. package/src/hooks/shared/useEstimateGas.ts +0 -1
  187. package/src/hooks/shared/useGetUserHubWalletAddress.ts +1 -18
  188. package/src/hooks/shared/useNearStorageCheck.ts +2 -9
  189. package/src/hooks/shared/useNearStorageGate.ts +5 -15
  190. package/src/hooks/shared/useRegisterNearStorage.ts +2 -10
  191. package/src/hooks/shared/useRequestTrustline.test.ts +1 -7
  192. package/src/hooks/shared/useRequestTrustline.ts +4 -14
  193. package/src/hooks/shared/useSafeMutation.test.ts +0 -3
  194. package/src/hooks/shared/useSafeMutation.ts +2 -26
  195. package/src/hooks/shared/useSodaxContext.ts +0 -6
  196. package/src/hooks/shared/useStellarGate.test.ts +2 -9
  197. package/src/hooks/shared/useStellarGate.ts +3 -9
  198. package/src/hooks/shared/useStellarTrustlineCheck.test.ts +0 -2
  199. package/src/hooks/shared/useStellarTrustlineCheck.ts +1 -4
  200. package/src/hooks/shared/useXBalances.ts +2 -20
  201. package/src/hooks/shared/useXrpDestinationCheck.ts +71 -0
  202. package/src/hooks/shared/useXrpGate.test.ts +116 -0
  203. package/src/hooks/shared/useXrpGate.ts +80 -0
  204. package/src/hooks/shared/useXrpTrustlineReserveCheck.ts +45 -0
  205. package/src/hooks/shared/waitForApiAllowance.test.ts +0 -1
  206. package/src/hooks/shared/waitForApiAllowance.ts +2 -6
  207. package/src/hooks/sponsoring/useActivateStellarAccount.test.ts +1 -2
  208. package/src/hooks/sponsoring/useActivateStellarAccount.ts +1 -5
  209. package/src/hooks/sponsoring/useActivateStellarAccount.wire.test.ts +2 -13
  210. package/src/hooks/sponsoring/useSponsorConfig.ts +0 -1
  211. package/src/hooks/sponsoring/useStellarAccountActive.ts +0 -1
  212. package/src/hooks/sponsoring/useStellarAccountStatus.ts +1 -4
  213. package/src/hooks/staking/index.ts +0 -1
  214. package/src/hooks/staking/useCancelUnstake.ts +1 -7
  215. package/src/hooks/staking/useClaim.ts +1 -7
  216. package/src/hooks/staking/useConvertedAssets.ts +1 -4
  217. package/src/hooks/staking/useInstantUnstake.ts +1 -7
  218. package/src/hooks/staking/useInstantUnstakeAllowance.ts +1 -5
  219. package/src/hooks/staking/useInstantUnstakeApprove.ts +1 -11
  220. package/src/hooks/staking/useInstantUnstakeRatio.ts +1 -4
  221. package/src/hooks/staking/useStake.ts +1 -12
  222. package/src/hooks/staking/useStakeAllowance.ts +1 -5
  223. package/src/hooks/staking/useStakeApprove.ts +1 -11
  224. package/src/hooks/staking/useStakeRatio.ts +1 -4
  225. package/src/hooks/staking/useStakingConfig.ts +1 -4
  226. package/src/hooks/staking/useStakingInfo.ts +1 -5
  227. package/src/hooks/staking/useUnstake.ts +2 -9
  228. package/src/hooks/staking/useUnstakeAllowance.ts +1 -5
  229. package/src/hooks/staking/useUnstakeApprove.ts +1 -10
  230. package/src/hooks/staking/useUnstakingInfo.ts +1 -4
  231. package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +1 -4
  232. package/src/hooks/swap/useCancelLimitOrder.ts +1 -7
  233. package/src/hooks/swap/useCancelSwap.ts +1 -7
  234. package/src/hooks/swap/useCreateLimitOrder.ts +2 -12
  235. package/src/hooks/swap/useDetailedStatus.test.ts +6 -18
  236. package/src/hooks/swap/useDetailedStatus.ts +2 -19
  237. package/src/hooks/swap/useQuote.test.ts +2 -8
  238. package/src/hooks/swap/useQuote.ts +5 -32
  239. package/src/hooks/swap/useStatus.ts +2 -10
  240. package/src/hooks/swap/useSwap.test.ts +1 -11
  241. package/src/hooks/swap/useSwap.ts +2 -12
  242. package/src/hooks/swap/useSwapAllowance.ts +1 -2
  243. package/src/hooks/swap/useSwapApprovalStrategy.ts +2 -7
  244. package/src/hooks/swap/useSwapApprove.ts +2 -14
  245. package/src/hooks/swap/useSwapLifecycle.test.ts +47 -2
  246. package/src/hooks/swap/useSwapLifecycle.ts +36 -30
  247. package/src/hooks/swap/useSwapWithApproval.ts +2 -11
  248. package/src/hooks/swapsApi/index.ts +2 -14
  249. package/src/hooks/swapsApi/isTerminalSwapIntentStatus.test.ts +1 -5
  250. package/src/hooks/swapsApi/isTerminalSwapIntentStatus.ts +1 -7
  251. package/src/hooks/swapsApi/useSwapsApiAllowance.ts +0 -7
  252. package/src/hooks/swapsApi/useSwapsApiApprove.ts +1 -14
  253. package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.test.ts +5 -20
  254. package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.ts +3 -24
  255. package/src/hooks/swapsApi/useSwapsApiBroadcastWithApproval.test.ts +2 -8
  256. package/src/hooks/swapsApi/useSwapsApiBroadcastWithApproval.ts +6 -41
  257. package/src/hooks/swapsApi/useSwapsApiCancelIntent.ts +0 -13
  258. package/src/hooks/swapsApi/useSwapsApiCreateIntent.ts +0 -13
  259. package/src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts +1 -13
  260. package/src/hooks/swapsApi/useSwapsApiDeadline.ts +1 -7
  261. package/src/hooks/swapsApi/useSwapsApiEstimateGas.ts +0 -7
  262. package/src/hooks/swapsApi/useSwapsApiFilledIntent.ts +0 -8
  263. package/src/hooks/swapsApi/useSwapsApiIntent.ts +1 -7
  264. package/src/hooks/swapsApi/useSwapsApiIntentExtraData.ts +1 -8
  265. package/src/hooks/swapsApi/useSwapsApiIntentHash.ts +0 -7
  266. package/src/hooks/swapsApi/useSwapsApiIntentPacket.ts +1 -10
  267. package/src/hooks/swapsApi/useSwapsApiPartnerFee.ts +0 -7
  268. package/src/hooks/swapsApi/useSwapsApiQuote.ts +2 -24
  269. package/src/hooks/swapsApi/useSwapsApiSolverFee.ts +0 -7
  270. package/src/hooks/swapsApi/useSwapsApiStatus.ts +1 -11
  271. package/src/hooks/swapsApi/useSwapsApiSubmitIntent.ts +1 -15
  272. package/src/hooks/swapsApi/useSwapsApiSubmitTx.ts +0 -21
  273. package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +2 -19
  274. package/src/hooks/swapsApi/useSwapsApiTokens.ts +0 -7
  275. package/src/hooks/swapsApi/useSwapsApiTokensByChain.ts +0 -7
  276. package/src/index.ts +1 -1
  277. package/src/providers/SodaxProvider.test.ts +2 -9
  278. package/src/providers/SodaxProvider.tsx +1 -12
  279. package/src/providers/createSodaxQueryClient.ts +4 -56
  280. package/src/utils/approvalPlan.ts +9 -32
  281. package/src/utils/dex-utils.ts +5 -20
  282. package/src/utils/index.ts +1 -0
  283. package/src/utils/nearStorageGate.ts +3 -14
  284. package/src/utils/stellarGate.ts +3 -16
  285. package/src/utils/swapLifecycle.test.ts +35 -0
  286. package/src/utils/swapLifecycle.ts +21 -28
  287. package/src/utils/xrpGate.test.ts +112 -0
  288. package/src/utils/xrpGate.ts +69 -0
@@ -10,16 +10,7 @@ export type UseBackendIntentByTxHashParams = ReadHookParams<
10
10
  }
11
11
  >;
12
12
 
13
- /**
14
- * React hook for fetching intent details from the backend API using a transaction hash.
15
- *
16
- * @example
17
- * const { data: intent } = useBackendIntentByTxHash({ params: { txHash: '0x123...' } });
18
- *
19
- * @remarks
20
- * - Intents are only created on the hub chain, so `txHash` must originate from there.
21
- * - Default refetch interval is 1 second.
22
- */
13
+ /** `txHash` must be a hub-chain tx: intents are only created there. */
23
14
  export const useBackendIntentByTxHash = ({
24
15
  params,
25
16
  queryOptions,
@@ -11,12 +11,6 @@ export type UseBackendMoneyMarketAssetParams = ReadHookParams<
11
11
  }
12
12
  >;
13
13
 
14
- /**
15
- * React hook to fetch a specific money market asset from the backend API.
16
- *
17
- * @example
18
- * const { data: asset } = useBackendMoneyMarketAsset({ params: { reserveAddress: '0xabc...' } });
19
- */
20
14
  export const useBackendMoneyMarketAsset = ({
21
15
  params,
22
16
  queryOptions,
@@ -13,14 +13,6 @@ export type UseBackendMoneyMarketAssetBorrowersParams = ReadHookParams<
13
13
  }
14
14
  >;
15
15
 
16
- /**
17
- * React hook for fetching borrowers for a specific money market asset from the backend API with pagination.
18
- *
19
- * @example
20
- * const { data: borrowers } = useBackendMoneyMarketAssetBorrowers({
21
- * params: { reserveAddress: '0xabc...', pagination: { offset: '0', limit: '20' } },
22
- * });
23
- */
24
16
  export const useBackendMoneyMarketAssetBorrowers = ({
25
17
  params,
26
18
  queryOptions,
@@ -13,14 +13,6 @@ export type UseBackendMoneyMarketAssetSuppliersParams = ReadHookParams<
13
13
  }
14
14
  >;
15
15
 
16
- /**
17
- * React hook for fetching suppliers for a specific money market asset from the backend API.
18
- *
19
- * @example
20
- * const { data: suppliers } = useBackendMoneyMarketAssetSuppliers({
21
- * params: { reserveAddress: '0xabc...', pagination: { offset: '0', limit: '20' } },
22
- * });
23
- */
24
16
  export const useBackendMoneyMarketAssetSuppliers = ({
25
17
  params,
26
18
  queryOptions,
@@ -11,12 +11,6 @@ export type UseBackendMoneyMarketPositionParams = ReadHookParams<
11
11
  }
12
12
  >;
13
13
 
14
- /**
15
- * React hook for fetching a user's money market position from the backend API.
16
- *
17
- * @example
18
- * const { data } = useBackendMoneyMarketPosition({ params: { userAddress: '0xabc...' } });
19
- */
20
14
  export const useBackendMoneyMarketPosition = ({
21
15
  params,
22
16
  queryOptions,
@@ -16,15 +16,7 @@ export type UseBackendOracleCandlesParams = ReadHookParams<
16
16
  }
17
17
  >;
18
18
 
19
- /**
20
- * Hook for fetching USD OHLC candles for a symbol over the half-open range `[from, to)`
21
- * from the backend API. Responses are cached server-side for roughly 10 seconds.
22
- *
23
- * @example
24
- * const { data } = useBackendOracleCandles({
25
- * params: { symbol: 'ETH', interval: '1h', from: 1756000000, to: 1756360000 },
26
- * });
27
- */
19
+ /** USD OHLC candles over the half-open range `[from, to)`; responses are cached server-side for ~10s. */
28
20
  export const useBackendOracleCandles = ({
29
21
  params,
30
22
  queryOptions,
@@ -6,13 +6,7 @@ import type { ReadHookParams } from '../shared/types.js';
6
6
 
7
7
  export type UseBackendOracleMarketsParams = ReadHookParams<OracleMarketsResponse>;
8
8
 
9
- /**
10
- * Hook for fetching the oracle candle store's discovery payload (quote currency,
11
- * selectable intervals, and covered symbols) from the backend API.
12
- *
13
- * @example
14
- * const { data: markets } = useBackendOracleMarkets();
15
- */
9
+ /** Oracle discovery payload: quote currency, selectable intervals and covered symbols. */
16
10
  export const useBackendOracleMarkets = ({
17
11
  queryOptions,
18
12
  }: UseBackendOracleMarketsParams = {}): UseQueryResult<OracleMarketsResponse, Error> => {
@@ -12,12 +12,6 @@ export type UseBackendOrderbookParams = ReadHookParams<
12
12
  }
13
13
  >;
14
14
 
15
- /**
16
- * Hook for fetching the solver orderbook from the backend API.
17
- *
18
- * @example
19
- * const { data } = useBackendOrderbook({ params: { pagination: { offset: '0', limit: '10' } } });
20
- */
21
15
  export const useBackendOrderbook = ({
22
16
  params,
23
17
  queryOptions,
@@ -13,14 +13,6 @@ export type UseBackendUserIntentsParams = ReadHookParams<
13
13
  }
14
14
  >;
15
15
 
16
- /**
17
- * React hook for fetching user-created intents from the backend API for a given user address.
18
- *
19
- * @example
20
- * const { data: userIntents } = useBackendUserIntents({
21
- * params: { userAddress: '0x123...' },
22
- * });
23
- */
24
16
  export const useBackendUserIntents = ({
25
17
  params,
26
18
  queryOptions,
@@ -4,8 +4,7 @@ import type { RadfiSession } from './useRadfiAuth.js';
4
4
  import { loadRadfiSession } from './useRadfiAuth.js';
5
5
  import { resolveBtcReadAddress } from './resolveBtcReadAddress.js';
6
6
 
7
- // resolveBtcReadAddress reads the Bound Exchange session via loadRadfiSession (localStorage-backed).
8
- // The dapp-kit test env is `node` (no localStorage), so mock the session lookup to drive each branch.
7
+ // The test env is `node` (no localStorage), so mock the session lookup to drive each branch.
9
8
  vi.mock('./useRadfiAuth.js', () => ({
10
9
  loadRadfiSession: vi.fn(),
11
10
  }));
@@ -40,7 +39,6 @@ describe('resolveBtcReadAddress', () => {
40
39
  const result = resolveBtcReadAddress(ChainKeys.BITCOIN_MAINNET, PERSONAL_ADDRESS);
41
40
 
42
41
  expect(result).toBe(TRADING_ADDRESS);
43
- // The session is keyed by the personal address.
44
42
  expect(mockLoadRadfiSession).toHaveBeenCalledWith(PERSONAL_ADDRESS);
45
43
  });
46
44
 
@@ -2,18 +2,8 @@ import { ChainKeys, type SpokeChainKey } from '@sodax/sdk';
2
2
  import { loadRadfiSession } from './useRadfiAuth.js';
3
3
 
4
4
  /**
5
- * Resolve a spoke address for READ queries (positions, balances, hub-wallet display).
6
- *
7
- * Bitcoin positions live under the Bound Exchange trading-wallet-derived hub wallet, so for Bitcoin we
8
- * resolve to the trading address from the locally-persisted Bound Exchange session. This is intentionally
9
- * a LOCAL lookup (no network call): a transient Bound Exchange API outage can never make a real position
10
- * read as empty, and reads never throw "Trading wallet not found". When there is no session, the
11
- * user has no Bitcoin position to show, so the original (personal) address is returned — deriving
12
- * an empty hub wallet, which is correct. Non-Bitcoin chains pass through unchanged.
13
- *
14
- * The WRITE path resolves the trading address authoritatively in the SDK
15
- * (`getEffectiveWalletAddress`, called from the money-market create*Intent flows); reads
16
- * deliberately use this lighter, fail-safe path.
5
+ * Bitcoin reads resolve the trading address from the LOCAL Bound session (no network), so an API outage never
6
+ * empties a real position; with no session the personal address is returned. Writes resolve it in the SDK.
17
7
  */
18
8
  export function resolveBtcReadAddress(chainKey: SpokeChainKey, address: string): string {
19
9
  if (chainKey !== ChainKeys.BITCOIN_MAINNET) return address;
@@ -11,13 +11,7 @@ export type UseBitcoinBalanceParams = ReadHookParams<
11
11
 
12
12
  const DEFAULT_RPC_URL = 'https://mempool.space/api';
13
13
 
14
- /**
15
- * Hook to fetch BTC balance for any Bitcoin address.
16
- * Sums all UTXOs (confirmed + unconfirmed) from mempool.space API.
17
- *
18
- * The UTXO set already excludes spent outputs (even from unconfirmed txs),
19
- * so the total is always the correct spendable balance.
20
- */
14
+ /** Sums all UTXOs (confirmed + unconfirmed); the UTXO set already excludes spent outputs. */
21
15
  export function useBitcoinBalance({
22
16
  params,
23
17
  queryOptions,
@@ -10,7 +10,6 @@ import { useTradingWalletBalance } from './useTradingWalletBalance.js';
10
10
 
11
11
  export interface UseBitcoinTradingSetupParams {
12
12
  chainKey: SpokeChainKey;
13
- /** This side's wallet provider + account, e.g. `useWalletProvider` / `useXAccount`. */
14
13
  walletProvider: IWalletProvider | undefined;
15
14
  address: string | undefined;
16
15
  }
@@ -23,9 +22,8 @@ export interface BitcoinTradingSetup {
23
22
  const INERT: BitcoinTradingSetup = { wallet: undefined, tradingBalance: undefined };
24
23
 
25
24
  /**
26
- * Bitcoin trading-wallet setup for one side of a cross-chain flow: Bitcoin funds move through a
27
- * Bound Exchange (Radfi) trading wallet, not the personal wallet. Inert (no work) unless `chainKey`
28
- * is Bitcoin. Wallet-layer inputs are passed in — this package doesn't depend on wallet-sdk-react.
25
+ * Bitcoin funds move through a Bound (Radfi) trading wallet; inert unless `chainKey` is Bitcoin.
26
+ * Wallet inputs are passed in because this package must not depend on wallet-sdk-react.
29
27
  */
30
28
  export function useBitcoinTradingSetup({
31
29
  chainKey,
@@ -9,19 +9,8 @@ export type UseEnsureRadfiAccessTokenVars = {
9
9
  };
10
10
 
11
11
  /**
12
- * Ensure a valid Bound Exchange access token and return it. Refreshes the existing token (no
13
- * signature prompt) when a refresh token is available, falling back to a full BIP322 re-auth only if
14
- * refresh fails. Bound tokens are short-lived, so call this right before a Bitcoin-source
15
- * createIntent — forward the returned token via the typed `extras.bound.accessToken` slot (SDK in-process)
16
- * or the `accessToken` body field on the backend DTO — or before the client-side sign + co-sign step.
17
- *
18
- * @example
19
- * const { mutateAsync: ensureToken } = useEnsureRadfiAccessToken();
20
- * const accessToken = await ensureToken({ walletProvider });
21
- * // SDK in-process (Bitcoin-gated extras):
22
- * await sodax.swaps.createIntent({ params, extras: { bound: { accessToken } }, raw: true });
23
- * // or backend createIntent — token in the body, not an x-bound-access-token header:
24
- * await createIntent({ body: { ...body, accessToken } });
12
+ * Bound tokens are short-lived: call right before a Bitcoin-source createIntent and pass the token as
13
+ * `extras.bound.accessToken` (SDK) or the `accessToken` body field (backend). Falls back to BIP322 re-auth.
25
14
  */
26
15
  export function useEnsureRadfiAccessToken({
27
16
  mutationOptions,
@@ -1,4 +1,3 @@
1
- // packages/dapp-kit/src/hooks/bitcoin/useFundTradingWallet.ts
2
1
  import { useQueryClient } from '@tanstack/react-query';
3
2
  import { ChainKeys, type IBitcoinWalletProvider } from '@sodax/sdk';
4
3
  import { useSodaxContext } from '../shared/useSodaxContext.js';
@@ -11,11 +10,6 @@ export type UseFundTradingWalletVars = {
11
10
  walletProvider: IBitcoinWalletProvider;
12
11
  };
13
12
 
14
- /**
15
- * React hook for funding the user's Bound Exchange trading wallet from their personal Bitcoin wallet.
16
- * Pure mutation: pass `{ amount, walletProvider }` to `mutate({...})`. Returns the broadcast tx
17
- * id on success.
18
- */
19
13
  export function useFundTradingWallet({
20
14
  mutationOptions,
21
15
  }: MutationHookParams<string, UseFundTradingWalletVars> = {}): SafeUseMutationResult<
@@ -1,4 +1,3 @@
1
- // packages/dapp-kit/src/hooks/bitcoin/useRadfiAuth.ts
2
1
  import { RadfiApiError, type IBitcoinWalletProvider } from '@sodax/sdk';
3
2
  import { useSodaxContext } from '../shared/useSodaxContext.js';
4
3
  import type { MutationHookParams } from '../shared/types.js';
@@ -44,11 +43,7 @@ export function clearRadfiSession(address: string): void {
44
43
  } catch {}
45
44
  }
46
45
 
47
- /**
48
- * React hook for authenticating with Bound Exchange via BIP322-signed message. Pure mutation: pass
49
- * `{ walletProvider }` to `mutate({...})`. The hook itself takes no arguments other than the
50
- * structural `mutationOptions` slot.
51
- */
46
+ /** Authenticates with Bound Exchange via a BIP322-signed message. */
52
47
  export function useRadfiAuth({
53
48
  mutationOptions,
54
49
  }: MutationHookParams<RadfiAuthResult, UseRadfiAuthVars> = {}): SafeUseMutationResult<
@@ -1,4 +1,3 @@
1
- // packages/dapp-kit/src/hooks/bitcoin/useRadfiSession.ts
2
1
  import { useState, useEffect, useRef, useCallback } from 'react';
3
2
  import type { IBitcoinWalletProvider } from '@sodax/sdk';
4
3
  import {
@@ -1,4 +1,3 @@
1
- // packages/dapp-kit/src/hooks/bitcoin/useRadfiWithdraw.ts
2
1
  import { normalizePsbtToBase64, ChainKeys, type IBitcoinWalletProvider } from '@sodax/sdk';
3
2
  import { useQueryClient } from '@tanstack/react-query';
4
3
  import { loadRadfiSession } from './useRadfiAuth.js';
@@ -19,11 +18,6 @@ type WithdrawResult = {
19
18
  fee: number;
20
19
  };
21
20
 
22
- /**
23
- * React hook for withdrawing BTC from the user's Bound Exchange trading wallet back to their personal
24
- * Bitcoin wallet. Pure mutation: pass all inputs (including the wallet provider) to
25
- * `mutate({...})`.
26
- */
27
21
  export function useRadfiWithdraw({
28
22
  mutationOptions,
29
23
  }: MutationHookParams<WithdrawResult, UseRadfiWithdrawVars> = {}): SafeUseMutationResult<
@@ -1,4 +1,3 @@
1
- // packages/dapp-kit/src/hooks/bitcoin/useRenewUtxos.ts
2
1
  import { normalizePsbtToBase64, type IBitcoinWalletProvider } from '@sodax/sdk';
3
2
  import { useQueryClient } from '@tanstack/react-query';
4
3
  import { loadRadfiSession } from './useRadfiAuth.js';
@@ -11,10 +10,6 @@ export type UseRenewUtxosVars = {
11
10
  walletProvider: IBitcoinWalletProvider;
12
11
  };
13
12
 
14
- /**
15
- * React hook for renewing expired UTXOs in the user's Bound Exchange trading wallet. Pure mutation: pass
16
- * `{ txIdVouts, walletProvider }` to `mutate({...})`.
17
- */
18
13
  export function useRenewUtxos({
19
14
  mutationOptions,
20
15
  }: MutationHookParams<string, UseRenewUtxosVars> = {}): SafeUseMutationResult<string, Error, UseRenewUtxosVars> {
@@ -4,10 +4,7 @@ type UseTradingWalletReturn = {
4
4
  tradingAddress: string | undefined;
5
5
  };
6
6
 
7
- /**
8
- * Returns the Bound Exchange trading wallet address from the persisted session.
9
- * Trading wallet is created automatically during authentication — no API call needed.
10
- */
7
+ /** Reads the trading address from the persisted session (created during auth); no API call. */
11
8
  export function useTradingWallet(walletAddress: string | undefined): UseTradingWalletReturn {
12
9
  if (!walletAddress) return { tradingAddress: undefined };
13
10
  const session = loadRadfiSession(walletAddress);
@@ -19,13 +19,7 @@ import {
19
19
  isBridgeNotDelivered,
20
20
  } from './getBridgeDetailedStatusRefetchInterval.js';
21
21
 
22
- /**
23
- * Guards the polling-stop invariant for `useBridgeDetailedStatus.refetchInterval`: stop on a
24
- * terminal or abandoned backend record, on any relay packet or MPC deposit record (always
25
- * terminal), on a rejected API key, and on an exhausted not-delivered budget — but keep polling
26
- * through an outage. Tested as a pure function because dapp-kit's vitest runs in the `node`
27
- * environment.
28
- */
22
+ // Tested as a pure function because dapp-kit's vitest runs in the `node` environment.
29
23
  const KEY_A = 'arb:0xaaa';
30
24
  const KEY_B = 'arb:0xbbb';
31
25
 
@@ -7,17 +7,12 @@ import {
7
7
  } from '@sodax/sdk';
8
8
  import { MAX_MPC_RELAY_NOT_FOUND_POLLS, MAX_NOT_FOUND_POLLS, STATUS_POLL_MS } from '../shared/notFoundStreak.js';
9
9
 
10
- /**
11
- * Structural mirror of `useBridgeDetailedStatus`'s data type. Declared locally rather than imported
12
- * so this module does not own the hook's public contract.
13
- */
10
+ /** Mirrors `useBridgeDetailedStatus`'s data type locally so this module does not own the hook's contract. */
14
11
  type DetailedBridgeStatusRead = Result<DetailedBridgeStatus, BridgeDetailedStatusError> | undefined;
15
12
 
16
13
  /**
17
- * The read the budget counts: the relay has no packet for this source tx *and* the backend answered,
18
- * so the miss is real rather than unprovable. Every other `LOOKUP_FAILED` is a dependency failing
19
- * right now — the relay unreachable, a malformed response — and those keep polling, because that is
20
- * how the read recovers when the outage ends.
14
+ * The only read the budget counts: no relay packet *and* the backend answered, so the miss is real.
15
+ * Other `LOOKUP_FAILED`s are outages and keep polling so the read recovers.
21
16
  */
22
17
  export function isBridgeNotDelivered(data: DetailedBridgeStatusRead): boolean {
23
18
  return data !== undefined && !data.ok && data.error?.context?.reason === DETAILED_STATUS_NOT_DELIVERED;
@@ -29,16 +24,8 @@ export function isBridgeMpcRelayRead(data: DetailedBridgeStatusRead): boolean {
29
24
  }
30
25
 
31
26
  /**
32
- * Polling interval for `useBridgeDetailedStatus`.
33
- *
34
- * Unlike the swap analog there is no in-flight second arm to wait on: the relay arm only ever
35
- * carries a matched `executed` packet, and the MPC-relay arm a minted deposit record, so both are
36
- * terminal on arrival. That leaves three stops — a terminal or abandoned backend record, a rejected
37
- * API key, and the ambiguous relay miss once it has run `MAX_NOT_FOUND_POLLS` times in a row, or
38
- * `MAX_MPC_RELAY_NOT_FOUND_POLLS` when the SDK tags it `context.mpcRelay`.
39
- *
40
- * Kept in its own pure module (no React/context imports) so it is unit-testable in dapp-kit's `node`
41
- * test environment — importing the hook itself pulls in `useSodaxContext`.
27
+ * Relay and MPC-relay answers are terminal on arrival; stops on a terminal/abandoned backend record, a rejected key, or an exhausted miss budget.
28
+ * Kept free of React imports so it is unit-testable in the `node` test environment.
42
29
  */
43
30
  export function getBridgeDetailedStatusRefetchInterval(
44
31
  data: DetailedBridgeStatusRead,
@@ -46,13 +33,12 @@ export function getBridgeDetailedStatusRefetchInterval(
46
33
  ): number | false {
47
34
  if (data?.ok) {
48
35
  if (data.value.source !== 'backend') return false;
49
- // The two terminal states of the bridge wire contract, plus a record the backend abandoned
50
- // while its status was still non-terminal.
36
+ // `abandonedAt` marks a record the backend gave up on while still non-terminal.
51
37
  const { status, abandonedAt } = data.value.data;
52
38
  return status === 'executed' || status === 'failed' || abandonedAt ? false : STATUS_POLL_MS;
53
39
  }
54
40
  if (data && !data.ok) {
55
- // A rejected key is terminal — only a corrected key changes the answer, so stop asking.
41
+ // Only a corrected key changes the answer, so stop asking.
56
42
  if (isAuthFailure(data.error)) return false;
57
43
  const budget = isBridgeMpcRelayRead(data) ? MAX_MPC_RELAY_NOT_FOUND_POLLS : MAX_NOT_FOUND_POLLS;
58
44
  if (isBridgeNotDelivered(data) && consecutiveNotFound >= budget) return false;
@@ -1,14 +1,4 @@
1
- /**
2
- * `useBridge` wire test for the per-action API key: `extras.apiKey` in the mutation vars must reach
3
- * the backend submit-tx leg as `x-api-key` — on the POST and on the status poll — beating the
4
- * instance-level key.
5
- *
6
- * Follows the package convention of testing hooks without a renderer (captured `mutationFn`), with
7
- * the SDK stubbed at the same seams its own backend submit-tx tests use: `createBridgeIntent` is
8
- * spied on a real keyed `Sodax` so no wallet or chain is touched, while `POST /bridge/submit-tx`
9
- * and `GET /bridge/submit-tx/status` run call-through to a stubbed global fetch serving the
10
- * schema-valid fixtures from packages/sdk/src/bridge/BridgeService.test.ts.
11
- */
1
+ // `createBridgeIntent` is spied on a real keyed `Sodax` (no wallet/chain); submit-tx calls hit a stubbed global fetch.
12
2
 
13
3
  import { ChainKeys, Sodax } from '@sodax/sdk';
14
4
  import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -1,4 +1,3 @@
1
- // packages/dapp-kit/src/hooks/bridge/useBridge.ts
2
1
  import { useSodaxContext } from '../shared/useSodaxContext.js';
3
2
  import { invalidateBalances } from '../shared/invalidateBalances.js';
4
3
  import type { BridgeParams, SpokeChainKey, TxHashPair } from '@sodax/sdk';
@@ -8,19 +7,10 @@ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMu
8
7
  import { unwrapResult } from '../shared/unwrapResult.js';
9
8
  import { retryBeforeSubmission } from '../shared/retryBeforeSubmission.js';
10
9
 
11
- /**
12
- * Mutation variables for {@link useBridge}. Generic over `K extends SpokeChainKey` (defaults to
13
- * the full union). Sophisticated callers can lock K at the hook call site to narrow the
14
- * `walletProvider` and `params.srcChainKey` types.
15
- */
10
+ /** Lock `K` at the call site to narrow `walletProvider` and `params.srcChainKey`. */
16
11
  export type UseBridgeVars<K extends SpokeChainKey = SpokeChainKey> = Omit<BridgeParams<K, false>, 'raw'>;
17
12
 
18
- /**
19
- * React hook for executing a cross-chain bridge transfer.
20
- *
21
- * Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
22
- * `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
23
- */
13
+ /** Throws on SDK failure; resolves to the unwrapped `TxHashPair` and invalidates balances. */
24
14
  export function useBridge<K extends SpokeChainKey = SpokeChainKey>({
25
15
  mutationOptions,
26
16
  }: MutationHookParams<TxHashPair, UseBridgeVars<K>> = {}): SafeUseMutationResult<TxHashPair, Error, UseBridgeVars<K>> {
@@ -20,8 +20,7 @@ export function useBridgeAllowance<K extends SpokeChainKey>({
20
20
  const walletProvider = params?.walletProvider;
21
21
 
22
22
  return useQuery<boolean, Error>({
23
- // Extract the (chain, owner, token, amount) tuple that actually scopes the allowance —
24
- // raw-object keys break per Rule 4 (bigints) and churn on every render.
23
+ // Key on the scoping tuple only: raw payload objects hold bigints and churn every render.
25
24
  queryKey: [
26
25
  'bridge',
27
26
  'allowance',
@@ -15,12 +15,8 @@ export type UseBridgeApprovalStrategyParams<K extends SpokeChainKey = SpokeChain
15
15
  >;
16
16
 
17
17
  /**
18
- * Which approval path {@link useBridgeWithApproval} would take for this bridge: `'not-required'`,
19
- * `'atomic-batch'` (approve + deposit in one EIP-5792 signature) or `'sequential'` (approve, then
20
- * bridge). Use it to label the bridge button. Pass the same `allowAccountUpgrade` you give the bridge.
21
- *
22
- * Not polled: `useBridgeWithApproval` invalidates it after a successful bridge, and the bridge
23
- * re-reads the strategy at execution, so a stale label never picks the wrong path.
18
+ * Predicts the approval path {@link useBridgeWithApproval} will take; pass the same `allowAccountUpgrade`.
19
+ * Not polled: the bridge re-reads the strategy at execution, so a stale label never picks the wrong path.
24
20
  */
25
21
  export function useBridgeApprovalStrategy<K extends SpokeChainKey = SpokeChainKey>({
26
22
  params,
@@ -1,4 +1,3 @@
1
- // packages/dapp-kit/src/hooks/bridge/useBridgeApprove.ts
2
1
  import type { BridgeParams, SpokeChainKey, TxReturnType } from '@sodax/sdk';
3
2
  import { useQueryClient } from '@tanstack/react-query';
4
3
  import { useSodaxContext } from '../shared/useSodaxContext.js';
@@ -6,21 +5,10 @@ import type { MutationHookParams } from '../shared/types.js';
6
5
  import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
7
6
  import { unwrapResult } from '../shared/unwrapResult.js';
8
7
 
9
- /**
10
- * Mutation variables for {@link useBridgeApprove}. Generic over `K extends SpokeChainKey`
11
- * (defaults to the full union). Sophisticated callers can lock K at the hook call site to narrow
12
- * the `walletProvider` and `params.srcChainKey` types.
13
- */
8
+ /** Lock `K` at the call site to narrow `walletProvider` and `params.srcChainKey`. */
14
9
  export type UseBridgeApproveVars<K extends SpokeChainKey = SpokeChainKey> = Omit<BridgeParams<K, false>, 'raw'>;
15
10
 
16
- /**
17
- * React hook for approving ERC-20 token spending (or trustline establishment) for a bridge
18
- * action.
19
- *
20
- * Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
21
- * `onError`, `retry`). Returns the unwrapped tx return value on success. Invalidates all
22
- * `['bridge', 'allowance', ...]` queries so any pending allowance check refreshes.
23
- */
11
+ /** Approves spending (or sets a trustline). Throws on SDK failure; invalidates `['bridge', 'allowance']` on success. */
24
12
  export function useBridgeApprove<K extends SpokeChainKey = SpokeChainKey>({
25
13
  mutationOptions,
26
14
  }: MutationHookParams<TxReturnType<K, false>, UseBridgeApproveVars<K>> = {}): SafeUseMutationResult<
@@ -1,14 +1,7 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
2
  import { MAX_MPC_RELAY_NOT_FOUND_POLLS, MAX_NOT_FOUND_POLLS, STATUS_POLL_MS } from '../shared/notFoundStreak.js';
3
3
 
4
- /**
5
- * Pins the WIRING the pure-policy test cannot see: the hook must pass the read into the policy and
6
- * advance the budget once per query update. Feeding the policy the wrong argument reproduces a
7
- * poll that never stops, with the policy's own tests still green.
8
- *
9
- * No renderer, per the package convention (see `_apiKeyWire.test.ts`): the React Query wrapper is
10
- * mocked so the captured options bag can be driven directly.
11
- */
4
+ // Pins the hook-to-policy wiring the pure-policy test cannot see: a wrong argument polls forever with those tests green.
12
5
 
13
6
  // The captured options bag is opaque, like the real wrapper's.
14
7
  let captured: any;
@@ -16,9 +9,7 @@ let captured: any;
16
9
  const refSlots: Array<{ current: unknown }> = [];
17
10
  let refCursor = 0;
18
11
 
19
- // Only useRef is needed, and call order is stable, so this replays React's slot semantics well
20
- // enough to observe the budget across refetchInterval calls — the same shape
21
- // `shared/useRequestTrustline.test.ts` uses.
12
+ // Only useRef is needed and call order is stable, so this replays React's slot semantics well enough.
22
13
  vi.mock('react', () => ({
23
14
  useRef: (initial: unknown) => {
24
15
  const slot = refSlots[refCursor] ?? { current: initial };
@@ -36,28 +36,9 @@ function onwardHubTxHash(data: UseBridgeDetailedStatusResult): string | undefine
36
36
  }
37
37
 
38
38
  /**
39
- * Hook for monitoring a bridge from its source-chain transaction.
40
- *
41
- * `useBridgeApiSubmitTxStatus` needs the backend to still hold a usable record; this takes
42
- * `(srcChainKey, srcTxHash)` — the pair you hold after `bridge()`, plus `dstChainKey` for a bridge from Tron —
43
- * and routes to whichever source
44
- * can answer, so it also covers a bridge the client-side fallback completed. `data.value` is
45
- * discriminated on `source`, and each variant carries that source's payload unmodified.
46
- *
47
- * Polls every 3s. Stops once the answering source is terminal (a relay packet always is), once the
48
- * backend rejects the API key, and — like `useDetailedStatus` — after 40 consecutive *ambiguous*
49
- * reads, meaning a `LOOKUP_FAILED` whose relay has no packet for the tx — 100, about 5 minutes, for a bridge
50
- * with an MPC-relay end (`context.mpcRelay`), which settles more slowly. A dependency outage keeps
51
- * polling instead, so the read recovers by itself; any real answer resets the budget. Override with
52
- * `queryOptions.refetchInterval`.
53
- *
54
- * @example
55
- * ```typescript
56
- * const { data } = useBridgeDetailedStatus({ params: { srcChainKey, srcTxHash, dstChainKey } });
57
- * if (data?.ok && data.value.source === 'relay') console.log(data.value.data.dst_tx_hash);
58
- * ```
39
+ * Status by source tx (plus `dstChainKey` from Tron), routed to whichever source can answer; `data.value` is discriminated on `source`.
40
+ * Polls every 3s until terminal, API-key rejection, or 40 (MPC-relay: 100) consecutive no-packet misses; outages keep polling.
59
41
  */
60
-
61
42
  export const useBridgeDetailedStatus = ({
62
43
  params,
63
44
  queryOptions,
@@ -79,8 +60,7 @@ export const useBridgeDetailedStatus = ({
79
60
  },
80
61
  enabled: !!srcChainKey && !!srcTxHash,
81
62
  refetchInterval: query => {
82
- // Reaching the hub is progress, so the leg after it gets a budget of its own. An MPC-relay miss counts
83
- // on its own streak too, so one untagged miss in between cannot cut its longer budget short.
63
+ // Reaching the hub starts a fresh budget for the next leg; MPC-relay misses keep their own streak.
84
64
  const { data } = query.state;
85
65
  const leg = [onwardHubTxHash(data), isBridgeMpcRelayRead(data) ? 'mpcRelay' : undefined].filter(Boolean);
86
66
  notFoundStreakRef.current = advanceNotFoundStreak(
@@ -7,23 +7,14 @@ 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 useBridgeWithApproval}: `useBridge`'s, plus `allowAccountUpgrade`, `resumeBatchId` and
12
- * `resumeBatchCallCount`.
13
- */
14
10
  export type UseBridgeWithApprovalVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
15
11
  BridgeWithApprovalParams<K>,
16
12
  'raw'
17
13
  >;
18
14
 
19
15
  /**
20
- * `useBridge` with the source-token approval folded in (`sodax.bridge.bridgeWithApproval`): no approval
21
- * when the allowance suffices, approve + deposit as one EIP-5792 batch (one signature) on a
22
- * batch-capable EVM wallet, otherwise approve, wait for it, then bridge. `data.approvalStrategy`
23
- * says which ran; {@link useBridgeApprovalStrategy} predicts it.
24
- *
25
- * Throws on SDK failure so React Query's error model engages. On success invalidates balances and
26
- * the bridge allowance and approval-strategy queries.
16
+ * `useBridge` with approval folded in (one EIP-5792 batch where supported); `data.approvalStrategy` says which path ran.
17
+ * Throws on SDK failure; on success invalidates balances, allowance and approval-strategy queries.
27
18
  */
28
19
  export function useBridgeWithApproval<K extends SpokeChainKey = SpokeChainKey>({
29
20
  mutationOptions,
@@ -5,11 +5,7 @@ import {
5
5
  getBridgeSubmitTxStatusRefetchInterval,
6
6
  } from './getBridgeSubmitTxStatusRefetchInterval.js';
7
7
 
8
- /**
9
- * Guards the polling-stop invariant for `useBridgeApiSubmitTxStatus.refetchInterval`: keep polling
10
- * a live record, stop on a terminal or abandoned one, and stop on a rejected API key. Tested as a
11
- * pure function because dapp-kit's vitest runs in the `node` environment.
12
- */
8
+ /** Tested as a pure function because dapp-kit's vitest runs in the `node` environment. */
13
9
  const record = (data: Partial<BridgeSubmitTxStatusDataV2>): BridgeSubmitTxStatusDataV2 => ({
14
10
  txHash: '0xabc',
15
11
  srcChainKey: '0xa4b1.arbitrum',
@@ -74,8 +70,7 @@ describe('getBridgeSubmitTxStatusRefetchInterval', () => {
74
70
  });
75
71
 
76
72
  it('stops on an auth failure even when a live record is still cached', () => {
77
- // Order matters: the key was rejected on a later poll, so the stale in-flight record must not
78
- // keep the interval alive.
73
+ // Order matters: a key rejected on a later poll must stop polling despite the stale in-flight record.
79
74
  expect(getBridgeSubmitTxStatusRefetchInterval(apiError(401), record({ status: 'relaying' }))).toBe(false);
80
75
  });
81
76
  });