@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
@@ -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
- // Hash the whole request body so every quote input — including partnerFee and the other
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 when `status` is still non-terminal — same rule as the
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
  },
@@ -12,13 +12,6 @@ export type UseSwapsApiTokensParams = ReadHookParams<
12
12
  }
13
13
  >;
14
14
 
15
- /**
16
- * React hook to fetch all supported swap tokens grouped by SpokeChainKey via the swaps API —
17
- * `sodax.api.swaps.getTokens`.
18
- *
19
- * @example
20
- * const { data: tokensByChain } = useSwapsApiTokens();
21
- */
22
15
  export const useSwapsApiTokens = ({
23
16
  params,
24
17
  queryOptions,
@@ -13,13 +13,6 @@ export type UseSwapsApiTokensByChainParams = ReadHookParams<
13
13
  }
14
14
  >;
15
15
 
16
- /**
17
- * React hook to fetch supported swap tokens for a single SpokeChainKey via the swaps API —
18
- * `sodax.api.swaps.getTokensByChain`.
19
- *
20
- * @example
21
- * const { data: tokens } = useSwapsApiTokensByChain({ params: { chainKey: '0xa4b1.arbitrum' } });
22
- */
23
16
  export const useSwapsApiTokensByChain = ({
24
17
  params,
25
18
  queryOptions,
package/src/index.ts CHANGED
@@ -2,4 +2,4 @@ export * from './hooks/index.js';
2
2
  export * from './providers/index.js';
3
3
  export * from './utils/index.js';
4
4
 
5
- export * from '@sodax/sdk'; // export all sdk entities
5
+ export * from '@sodax/sdk';
@@ -1,12 +1,5 @@
1
- /**
2
- * `SodaxProvider` wire test for the consumer-supplied API key: `config.apiKey` handed to the
3
- * provider must reach the backend as `x-api-key` on requests made through the provided instance.
4
- *
5
- * Covers the one key-supply surface the hook manifests' hand-built `Sodax` does not: the provider's
6
- * own `new Sodax(config)`. No renderer — `useMemo` is patched to evaluate its factory so the
7
- * component can be called as a plain function and the provided `sodax` read off the element's
8
- * context value.
9
- */
1
+ // `config.apiKey` given to the provider must reach the backend as `x-api-key`.
2
+ // `useMemo` is patched to run its factory so the component can be called without a renderer.
10
3
 
11
4
  import type { Sodax } from '@sodax/sdk';
12
5
  import type { ReactElement } from 'react';
@@ -4,18 +4,7 @@ import { SodaxContext } from '@/contexts/index.js';
4
4
 
5
5
  interface SodaxProviderProps {
6
6
  children: ReactNode;
7
- /**
8
- * Sodax SDK config. Tracked by **reference** - a new identity re-instantiates the
9
- * SDK. Hoist to a module constant or wrap in `useMemo`; include any value the SDK
10
- * should react to (e.g. solver env) in the deps. Inline `{...}` re-creates the SDK
11
- * every parent render and resets every `useSodaxContext` consumer.
12
- *
13
- * @example
14
- * ```tsx
15
- * const config = useMemo(() => ({ solver: solverMap[env] }), [env]);
16
- * <SodaxProvider config={config}>...</SodaxProvider>
17
- * ```
18
- */
7
+ /** Tracked by reference: a new identity re-creates the SDK and resets consumers, so memoize it. */
19
8
  config?: SodaxOptions;
20
9
  }
21
10
 
@@ -1,36 +1,11 @@
1
- // packages/dapp-kit/src/providers/createSodaxQueryClient.ts
2
1
  import { MutationCache, QueryClient, type QueryClientConfig } from '@tanstack/react-query';
3
2
 
4
3
  export type CreateSodaxQueryClientOptions = {
5
4
  /**
6
- * Called for every mutation failure (i.e. every time `mutationFn` throws) that does NOT opt out
7
- * via `meta: { silent: true }` on the mutation. Defaults to `console.error`.
8
- *
9
- * This is **global observability** — it runs alongside any per-hook `onError` handler the
10
- * consumer set, NOT instead of them. In particular, it fires:
11
- * - whether or not `mutateAsync` was awaited inside `try/catch`
12
- * - whether or not `mutateAsyncSafe` was used (the wrapper packs into `Result<T>` AFTER React
13
- * Query has already entered the error state and dispatched its callbacks)
14
- * - whether or not the consumer's `mutationOptions.onError` already toasted/logged
15
- *
16
- * It is NOT a "did this rejection escape to the global handler?" detector — accurate
17
- * unhandled-rejection detection lives at `window.onunhandledrejection`, not here.
18
- *
19
- * To silence the default for a specific mutation that the consumer is handling locally, set
20
- * `meta: { silent: true }`:
21
- *
22
- * ```ts
23
- * useSwap({ mutationOptions: { meta: { silent: true }, onError: (e) => toast(e.message) } });
24
- * ```
25
- *
26
- * To disable the default globally (e.g. wire your own error boundary), pass a no-op:
27
- *
28
- * ```ts
29
- * createSodaxQueryClient({ onMutationError: () => {} });
30
- * ```
5
+ * Fires on every mutation failure, alongside per-hook `onError`, unless the mutation sets `meta: { silent: true }`.
6
+ * Defaults to `console.error`.
31
7
  */
32
8
  onMutationError?: (error: unknown) => void;
33
- /** Pass-through for any other QueryClient config (default queries options, etc.) */
34
9
  config?: QueryClientConfig;
35
10
  };
36
11
 
@@ -38,39 +13,12 @@ const defaultOnMutationError = (error: unknown): void => {
38
13
  console.error('[sodax] Mutation error:', error);
39
14
  };
40
15
 
41
- /**
42
- * Creates a `QueryClient` pre-wired with a mutation-error observability hook that gives dapp-kit
43
- * consumers a single seam for every mutation failure across the app — wire to Sentry/Datadog/console
44
- * as you like. Optional opt-in: consumers who construct their own `QueryClient` are unaffected.
45
- *
46
- * **Composition with a custom `MutationCache`.** If you pass `config.mutationCache`, we keep your
47
- * cache instance (preserving its own `onError` / `onSuccess` / etc.) and *additionally* subscribe
48
- * to its event stream to dispatch `onMutationError`. Both your handler and the dapp-kit handler
49
- * fire — neither replaces the other. If you don't pass one, we install our own.
50
- *
51
- * @example default — logs to console
52
- * const queryClient = createSodaxQueryClient();
53
- *
54
- * @example custom — Sentry
55
- * const queryClient = createSodaxQueryClient({
56
- * onMutationError: (e) => Sentry.captureException(e),
57
- * });
58
- *
59
- * @example silent — disable the default
60
- * const queryClient = createSodaxQueryClient({ onMutationError: () => {} });
61
- *
62
- * @example bring-your-own MutationCache
63
- * const myCache = new MutationCache({ onError: myOwnErrorHandler });
64
- * const queryClient = createSodaxQueryClient({ config: { mutationCache: myCache } });
65
- * // myOwnErrorHandler still runs; onMutationError ALSO runs (unless meta.silent).
66
- */
16
+ /** A custom `config.mutationCache` is kept and subscribed to, so its own handlers still fire too. */
67
17
  export function createSodaxQueryClient({
68
18
  onMutationError = defaultOnMutationError,
69
19
  config,
70
20
  }: CreateSodaxQueryClientOptions = {}): QueryClient {
71
21
  if (config?.mutationCache) {
72
- // Compose: keep the consumer's cache, attach our observability as an extra subscriber.
73
- // The consumer's own `MutationCache.onError` (if any) still fires — subscribe is additive.
74
22
  config.mutationCache.subscribe(event => {
75
23
  if (event.type === 'updated' && event.action.type === 'error' && event.mutation.options.meta?.silent !== true) {
76
24
  onMutationError(event.action.error);
@@ -79,7 +27,7 @@ export function createSodaxQueryClient({
79
27
  return new QueryClient(config);
80
28
  }
81
29
 
82
- // No consumer cache: install our own with `onError` directly (cheaper than a subscribe loop).
30
+ // No consumer cache: install our own `onError` (cheaper than a subscribe loop).
83
31
  return new QueryClient({
84
32
  ...config,
85
33
  mutationCache: new MutationCache({
@@ -57,21 +57,12 @@ type ChainSender = {
57
57
  /** Reads better than the id inside an error sentence. */
58
58
  const stepLabel = (step: ApprovalStepId): string => (step === 'allowance-reset' ? 'allowance reset' : 'approve');
59
59
 
60
- /**
61
- * `EvmRawTransactionReceipt.status` is documented as the JSON-RPC hex flag, but `EvmWalletProvider`
62
- * passes viem's `'reverted'` through unchanged, so both spellings reach here. A receipt without a
63
- * status is pre-Byzantium and inconclusive — not a revert.
64
- */
60
+ /** Matches both the JSON-RPC hex flag and viem's `'reverted'`, which `EvmWalletProvider` passes through unchanged.
61
+ * A missing status is pre-Byzantium and inconclusive, not a revert. */
65
62
  const isRevertedEvmReceiptStatus = (status: string | undefined): boolean => status === 'reverted' || status === '0x0';
66
63
 
67
- /**
68
- * How to send and confirm on the chains a SODAX approve route can act on — the hub (Sonic), EVM
69
- * spokes, and Stellar. Every other chain reports its allowance as always sufficient, so approval
70
- * never runs for it.
71
- *
72
- * Resolved once, before anything is sent: an unsupported chain or a Stellar wallet that cannot sign
73
- * then fails without first asking the user for a signature that could never be broadcast.
74
- */
64
+ /** Resolved before anything is sent, so an unsupported chain or a Stellar wallet that cannot sign fails
65
+ * without prompting for a signature that could never be broadcast. */
75
66
  function resolveChainSender(
76
67
  srcChainKey: SpokeChainKey,
77
68
  walletProvider: GetWalletProviderType<SpokeChainKey>,
@@ -79,9 +70,7 @@ function resolveChainSender(
79
70
  ): ChainSender {
80
71
  const fail = (message: string): Error => new Error(`[${hookName}] ${message}`);
81
72
 
82
- // Single SDK-exported source for "which chains support approval" — the same partition
83
- // SpokeService's approve-params guards resolve to, so a chain added there isn't silently
84
- // missed here too.
73
+ // Same SDK partition SpokeService's approve guards use, so a newly added chain isn't missed here.
85
74
  if (!isApprovalSupportedChainKeyType(srcChainKey)) {
86
75
  throw fail(
87
76
  `${srcChainKey} cannot be approved — SODAX approve routes support the hub (Sonic), EVM spokes, and Stellar.`,
@@ -92,8 +81,7 @@ function resolveChainSender(
92
81
  const evm = walletProvider as IEvmWalletProvider;
93
82
 
94
83
  return {
95
- // Chain-bind the send: the wallet broadcasts on ITS active chain, so refuse when that differs
96
- // from the srcChainKey the user asked for. (Verifying the tx CONTENT is a separate concern.)
84
+ // Chain-bind the send: the wallet broadcasts on ITS active chain, so refuse when it differs from srcChainKey.
97
85
  send: raw => evm.sendTransaction(raw as EvmRawTransaction, { expectedChainId: getEvmViemChain(srcChainKey).id }),
98
86
  confirm: async (hash, step) => {
99
87
  const receipt = await evm.waitForTransactionReceipt(hash as Hex);
@@ -124,25 +112,14 @@ function resolveChainSender(
124
112
  };
125
113
  }
126
114
 
127
- // Unreachable: isApprovalSupportedChainKeyType above already confirmed srcChainKey is hub, EVM-spoke,
128
- // or Stellar, and the two branches above cover all three — kept only to satisfy TypeScript's
129
- // return-path check (the guard is a plain boolean, so it doesn't narrow srcChainKey's type here).
115
+ // Unreachable: the boolean guard above doesn't narrow srcChainKey, so TypeScript needs this return path.
130
116
  throw fail(
131
117
  `${srcChainKey} cannot be approved — SODAX approve routes support the hub (Sonic), EVM spokes, and Stellar.`,
132
118
  );
133
119
  }
134
120
 
135
- /**
136
- * Broadcasts an approval plan in the only order that can work: `resetTx` mined first, then the
137
- * approve, which is not a valid state transition until the allowance has been zeroed on-chain.
138
- *
139
- * Not a pure helper like its neighbours here — it signs and sends through the caller's wallet
140
- * provider — but it is framework-free, and shared by the swaps and bridge approve-and-broadcast
141
- * hooks so the ordering is not re-derived per feature. `hookName` prefixes the errors.
142
- *
143
- * `onProgress` reports which transaction the user is being prompted for — `isPending` alone cannot
144
- * say whether a popup is the reset or the approve.
145
- */
121
+ /** Broadcasts `resetTx` and waits for it to be mined before the approve, which is invalid until the allowance is zeroed.
122
+ * `hookName` prefixes errors; `onProgress` says which tx the wallet is prompting for. */
146
123
  export async function runApprovalPlan({
147
124
  plan,
148
125
  srcChainKey,
@@ -14,22 +14,13 @@ import {
14
14
  import type { SpokeChainKey } from '@sodax/sdk';
15
15
  import { parseUnits } from 'viem';
16
16
 
17
- /**
18
- * Subset of {@link CreateAssetDepositParams} produced by {@link createDepositParamsProps}.
19
- * Callers add `srcChainKey` + `srcAddress` at the mutation call site.
20
- */
17
+ /** Callers add `srcChainKey` + `srcAddress` at the mutation call site. */
21
18
  export type DepositParamsCore = Omit<CreateAssetDepositParams<SpokeChainKey>, 'srcChainKey' | 'srcAddress'>;
22
19
 
23
- /**
24
- * Subset of {@link CreateAssetWithdrawParams} produced by {@link createWithdrawParamsProps}.
25
- * Callers add `srcChainKey` + `srcAddress` at the mutation call site.
26
- */
20
+ /** Callers add `srcChainKey` + `srcAddress` at the mutation call site. */
27
21
  export type WithdrawParamsCore = Omit<CreateAssetWithdrawParams<SpokeChainKey>, 'srcChainKey' | 'srcAddress'>;
28
22
 
29
- /**
30
- * Subset of {@link ClDecreaseLiquidityParams} produced by {@link createDecreaseLiquidityParamsProps}.
31
- * Callers add `srcChainKey` + `srcAddress` at the mutation call site.
32
- */
23
+ /** Callers add `srcChainKey` + `srcAddress` at the mutation call site. */
33
24
  export type DecreaseLiquidityParamsCore = Omit<ClDecreaseLiquidityParams<SpokeChainKey>, 'srcChainKey' | 'srcAddress'>;
34
25
 
35
26
  export function createDecreaseLiquidityParamsProps({
@@ -50,13 +41,11 @@ export function createDecreaseLiquidityParamsProps({
50
41
  throw new Error('Slippage must be between 0 and 100');
51
42
  }
52
43
 
53
- // Calculate liquidity to remove based on percentage
54
44
  const liquidityToRemove =
55
45
  percentageNum === 100
56
46
  ? positionInfo.liquidity
57
47
  : (positionInfo.liquidity * BigInt(Math.floor(percentageNum * 100))) / 10000n;
58
48
 
59
- // Calculate expected token amounts from this liquidity
60
49
  const expectedAmount0 =
61
50
  percentageNum === 100
62
51
  ? positionInfo.amount0
@@ -66,7 +55,6 @@ export function createDecreaseLiquidityParamsProps({
66
55
  ? positionInfo.amount1
67
56
  : (positionInfo.amount1 * BigInt(Math.floor(percentageNum * 100))) / 10000n;
68
57
 
69
- // Apply slippage to minimum amounts
70
58
  const slippageMultiplier = BigInt(Math.floor((100 - slippage) * 100));
71
59
  const amount0Min = (expectedAmount0 * slippageMultiplier) / 10000n;
72
60
  const amount1Min = (expectedAmount1 * slippageMultiplier) / 10000n;
@@ -97,7 +85,7 @@ export function createDepositParamsProps({
97
85
 
98
86
  return {
99
87
  asset: originalAsset.address,
100
- // Use deposit token decimals (original asset) for correct unit parsing
88
+ // Deposit token (original asset) decimals, not the pool token's.
101
89
  amount: parseUnits(String(amount), originalAsset.decimals),
102
90
  poolToken: token.address,
103
91
  };
@@ -135,7 +123,6 @@ export function createSupplyLiquidityParamsProps({
135
123
  const amount0BigInt = parseUnits(liquidityToken0Amount, poolData.token0.decimals);
136
124
  const amount1BigInt = parseUnits(liquidityToken1Amount, poolData.token1.decimals);
137
125
 
138
- // Convert prices to ticks
139
126
  const token0 = poolData.token0;
140
127
  const token1 = poolData.token1;
141
128
  const tickSpacing = poolData.tickSpacing;
@@ -143,7 +130,6 @@ export function createSupplyLiquidityParamsProps({
143
130
  const tickLower = ClService.priceToTick(minPriceNum, token0, token1, tickSpacing);
144
131
  const tickUpper = ClService.priceToTick(maxPriceNum, token0, token1, tickSpacing);
145
132
 
146
- // Calculate liquidity from full amounts (the desired deposit)
147
133
  const liquidity = ClService.calculateLiquidityFromAmounts(
148
134
  amount0BigInt,
149
135
  amount1BigInt,
@@ -152,8 +138,7 @@ export function createSupplyLiquidityParamsProps({
152
138
  BigInt(poolData.currentTick),
153
139
  );
154
140
 
155
- // Apply slippage to get max amounts — the ceiling the contract is allowed to pull.
156
- // If price moves unfavorably, the contract may need slightly more tokens than expected.
141
+ // Max amounts are the slippage-padded ceiling the contract may pull if price moves unfavorably.
157
142
  const { amount0Max, amount1Max } = ClService.calculateMaxAmountsForSlippage(
158
143
  liquidity,
159
144
  tickLower,
@@ -2,3 +2,4 @@ export * from './approvalPlan.js';
2
2
  export * from './dex-utils.js';
3
3
  export * from './nearStorageGate.js';
4
4
  export * from './stellarGate.js';
5
+ export * from './xrpGate.js';
@@ -10,23 +10,12 @@ export interface NearStorageGateState {
10
10
  isNear: boolean;
11
11
  /** Show the "register storage" action: the check resolved and the recipient is not registered. */
12
12
  needsRegistration: boolean;
13
- /**
14
- * Keep the downstream action (swap/bridge/borrow/withdraw) disabled: the NEAR gate is unresolved
15
- * (still checking) or unmet (needs registration).
16
- */
13
+ /** True while the check is unresolved or registration is needed. */
17
14
  blocksAction: boolean;
18
15
  }
19
16
 
20
- /**
21
- * Derives the NEP-141 storage-registration UI gate state for a flow that delivers a token to a user
22
- * on NEAR — NEAR's analogue of the Stellar trustline gate. Unwrapped (no hook): pass the destination
23
- * `chainKey` and the `useNearStorageCheck` result; the util owns the `=== NEAR` test and reads
24
- * `isLoading` (NOT `isPending`, which stays `true` for a disabled query and would block forever).
25
- *
26
- * `blocksAction` deliberately also covers the in-flight check window so the action can't be
27
- * triggered before registration status is known; `needsRegistration` only flips once the check has
28
- * resolved (so the "register" button isn't shown speculatively while still checking).
29
- */
17
+ /** NEAR analogue of the Stellar trustline gate. Reads `isLoading`, not `isPending` (stays true for a disabled query);
18
+ * `blocksAction` also covers the in-flight check, while `needsRegistration` waits for it to resolve. */
30
19
  export function resolveNearStorageGate(
31
20
  chainKey: SpokeChainKey | undefined,
32
21
  check: NearStorageCheckResult,
@@ -1,21 +1,13 @@
1
1
  import { ChainKeys, type SpokeChainKey, type StellarAccountStatus } from '@sodax/sdk';
2
2
  import type { UseQueryResult } from '@tanstack/react-query';
3
3
 
4
- /**
5
- * The subset of a query result the gate reads. A full `UseQueryResult<T>` satisfies it.
6
- *
7
- * `isLoading` is intentional: `isPending` remains true for disabled queries.
8
- * Errors remain distinct from unmet prerequisites.
9
- */
4
+ /** Reads `isLoading` because `isPending` stays true for disabled queries; errors stay distinct from unmet prerequisites. */
10
5
  export type StellarCheckResult<T> = Pick<UseQueryResult<T>, 'isLoading' | 'isError' | 'data'>;
11
6
 
12
7
  export interface StellarGateState {
13
8
  isStellar: boolean;
14
9
  needsActivation: boolean;
15
- /**
16
- * The account needs a trustline but lacks spendable XLM. Never set for
17
- * native XLM or an existing trustline.
18
- */
10
+ /** Never set for native XLM or an existing trustline. */
19
11
  needsFunding: boolean;
20
12
  needsTrustline: boolean;
21
13
  /** A query failed; disabled or unresolved queries do not set this. */
@@ -45,12 +37,7 @@ const NOT_STELLAR: StellarGateState = {
45
37
  blocksAction: false,
46
38
  };
47
39
 
48
- /**
49
- * Resolve activation, trustline, and funding prerequisites in order.
50
- *
51
- * Check the trustline before affordability because an existing trustline needs
52
- * no additional XLM. Unknown states fail closed.
53
- */
40
+ /** Checks the trustline before affordability because an existing trustline needs no extra XLM. Unknown states fail closed. */
54
41
  export function resolveStellarGate(chainKey: SpokeChainKey | undefined, inputs: StellarGateInputs): StellarGateState {
55
42
  const { statusCheck, trustlineCheck, isNativeToken } = inputs;
56
43