0xtrails 0.13.2 → 0.14.0

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 (753) hide show
  1. package/dist/abis/trailsHydrate.d.ts +5 -42
  2. package/dist/abis/trailsHydrate.d.ts.map +1 -1
  3. package/dist/abis/trailsRouter.d.ts +1 -1
  4. package/dist/abis/trailsRouter.d.ts.map +1 -1
  5. package/dist/{widget/analytics → analytics/hooks}/useWidgetAnalytics.d.ts +2 -4
  6. package/dist/analytics/hooks/useWidgetAnalytics.d.ts.map +1 -0
  7. package/dist/analytics.d.ts.map +1 -1
  8. package/dist/chainSwitch.d.ts.map +1 -1
  9. package/dist/chains-C1NhDLF_.js +4 -0
  10. package/dist/chains-CcoarGia.js +658 -0
  11. package/dist/chains.d.ts +0 -1
  12. package/dist/chains.d.ts.map +1 -1
  13. package/dist/committedIntentStore.d.ts +5 -0
  14. package/dist/committedIntentStore.d.ts.map +1 -0
  15. package/dist/config.d.ts +2 -0
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/constants.d.ts +2 -1
  18. package/dist/constants.d.ts.map +1 -1
  19. package/dist/error.d.ts +73 -4
  20. package/dist/error.d.ts.map +1 -1
  21. package/dist/hooks/useAddressWalletIcon.d.ts.map +1 -0
  22. package/dist/hooks/useAmountUsd.d.ts.map +1 -0
  23. package/dist/hooks/useBalanceVisible.d.ts.map +1 -0
  24. package/dist/hooks/useChainFilter.d.ts.map +1 -0
  25. package/dist/{widget/hooks → hooks}/useCheckout.d.ts +15 -15
  26. package/dist/hooks/useCheckout.d.ts.map +1 -0
  27. package/dist/hooks/useClickTracking.d.ts.map +1 -0
  28. package/dist/{widget/hooks → hooks}/useCombinedHistory.d.ts +3 -2
  29. package/dist/hooks/useCombinedHistory.d.ts.map +1 -0
  30. package/dist/hooks/useConnector.d.ts.map +1 -0
  31. package/dist/{widget/hooks → hooks}/useCustomTokenSearch.d.ts +1 -1
  32. package/dist/hooks/useCustomTokenSearch.d.ts.map +1 -0
  33. package/dist/hooks/useDebounce.d.ts.map +1 -0
  34. package/dist/{widget/hooks → hooks}/useDebugScreens.d.ts +2 -2
  35. package/dist/hooks/useDebugScreens.d.ts.map +1 -0
  36. package/dist/{widget/hooks → hooks}/useDefaultDestinationToken.d.ts +1 -1
  37. package/dist/hooks/useDefaultDestinationToken.d.ts.map +1 -0
  38. package/dist/{widget/hooks → hooks}/useDefaultOriginToken.d.ts +1 -1
  39. package/dist/hooks/useDefaultOriginToken.d.ts.map +1 -0
  40. package/dist/hooks/useDepositMonitor.d.ts.map +1 -0
  41. package/dist/{widget/hooks → hooks}/useDestinationSelectedToken.d.ts +2 -2
  42. package/dist/hooks/useDestinationSelectedToken.d.ts.map +1 -0
  43. package/dist/hooks/useDisplayCurrencyPreference.d.ts.map +1 -0
  44. package/dist/{widget/hooks → hooks}/useEarnPool.d.ts +1 -1
  45. package/dist/hooks/useEarnPool.d.ts.map +1 -0
  46. package/dist/hooks/useEffectiveFundBalance.d.ts +28 -0
  47. package/dist/hooks/useEffectiveFundBalance.d.ts.map +1 -0
  48. package/dist/hooks/useExecutingIntentsCount.d.ts.map +1 -0
  49. package/dist/{widget/hooks → hooks}/useExternalFundingReceiptSync.d.ts +1 -1
  50. package/dist/hooks/useExternalFundingReceiptSync.d.ts.map +1 -0
  51. package/dist/{widget/hooks → hooks}/useFiatOnRampCurrencies.d.ts +1 -1
  52. package/dist/hooks/useFiatOnRampCurrencies.d.ts.map +1 -0
  53. package/dist/hooks/useFiatSelectedCurrency.d.ts.map +1 -0
  54. package/dist/hooks/useGetIntent.d.ts.map +1 -0
  55. package/dist/{widget/hooks → hooks}/useIntentReceiptBalances.d.ts +1 -1
  56. package/dist/hooks/useIntentReceiptBalances.d.ts.map +1 -0
  57. package/dist/{widget/hooks → hooks}/useIntentTransactionHistory.d.ts +2 -1
  58. package/dist/hooks/useIntentTransactionHistory.d.ts.map +1 -0
  59. package/dist/hooks/useIsMobile.d.ts.map +1 -0
  60. package/dist/hooks/useIsSequenceWallet.d.ts.map +1 -0
  61. package/dist/hooks/useLocalePreference.d.ts.map +1 -0
  62. package/dist/hooks/useMeldTransactionHistory.d.ts.map +1 -0
  63. package/dist/hooks/useMeldTransactionStatus.d.ts.map +1 -0
  64. package/dist/hooks/useOnRampCountryDefaults.d.ts.map +1 -0
  65. package/dist/{widget/hooks → hooks}/useOnRampPaymentMethods.d.ts +2 -2
  66. package/dist/hooks/useOnRampPaymentMethods.d.ts.map +1 -0
  67. package/dist/{widget/hooks → hooks}/useOnRampProviderWidget.d.ts +1 -1
  68. package/dist/hooks/useOnRampProviderWidget.d.ts.map +1 -0
  69. package/dist/{widget/hooks → hooks}/useOnRampQuote.d.ts +3 -3
  70. package/dist/hooks/useOnRampQuote.d.ts.map +1 -0
  71. package/dist/{widget/hooks → hooks}/useOnRampTransactionStatus.d.ts +1 -1
  72. package/dist/hooks/useOnRampTransactionStatus.d.ts.map +1 -0
  73. package/dist/{widget/hooks → hooks}/useOriginSelectedToken.d.ts +1 -1
  74. package/dist/hooks/useOriginSelectedToken.d.ts.map +1 -0
  75. package/dist/hooks/usePayMessage.d.ts.map +1 -0
  76. package/dist/hooks/usePriceImpactWarning.d.ts.map +1 -0
  77. package/dist/hooks/useQuote.d.ts +439 -0
  78. package/dist/hooks/useQuote.d.ts.map +1 -0
  79. package/dist/{widget/hooks → hooks}/useRecentTokens.d.ts +1 -1
  80. package/dist/hooks/useRecentTokens.d.ts.map +1 -0
  81. package/dist/hooks/useRecipients.d.ts.map +1 -0
  82. package/dist/hooks/useSelectedFeeOption.d.ts.map +1 -0
  83. package/dist/{widget/hooks → hooks}/useSelectedFundMethod.d.ts +11 -1
  84. package/dist/hooks/useSelectedFundMethod.d.ts.map +1 -0
  85. package/dist/hooks/useSelectedRecipient.d.ts.map +1 -0
  86. package/dist/{widget/hooks → hooks}/useSendForm.d.ts +6 -11
  87. package/dist/hooks/useSendForm.d.ts.map +1 -0
  88. package/dist/hooks/useSwapAmount.d.ts.map +1 -0
  89. package/dist/{widget/hooks → hooks}/useSwapState.d.ts +1 -1
  90. package/dist/hooks/useSwapState.d.ts.map +1 -0
  91. package/dist/hooks/useTargetAmount.d.ts.map +1 -0
  92. package/dist/hooks/useTheme.d.ts.map +1 -0
  93. package/dist/{widget/hooks → hooks}/useTokenList.d.ts +2 -2
  94. package/dist/hooks/useTokenList.d.ts.map +1 -0
  95. package/dist/{widget/hooks → hooks}/useTrailsSendTransaction.d.ts +1 -1
  96. package/dist/hooks/useTrailsSendTransaction.d.ts.map +1 -0
  97. package/dist/{widget/hooks → hooks}/useViewManager.d.ts +1 -1
  98. package/dist/hooks/useViewManager.d.ts.map +1 -0
  99. package/dist/hooks/useWalletConnectUri.d.ts +19 -0
  100. package/dist/hooks/useWalletConnectUri.d.ts.map +1 -0
  101. package/dist/hooks/useWalletConnectionContext.d.ts.map +1 -0
  102. package/dist/{widget/hooks → hooks}/useWidgetProps.d.ts +1 -1
  103. package/dist/hooks/useWidgetProps.d.ts.map +1 -0
  104. package/dist/hydrate/builder.d.ts +131 -0
  105. package/dist/hydrate/builder.d.ts.map +1 -0
  106. package/dist/hydrate/constants.d.ts +13 -0
  107. package/dist/hydrate/constants.d.ts.map +1 -0
  108. package/dist/hydrate/encodeExecute.d.ts +73 -0
  109. package/dist/hydrate/encodeExecute.d.ts.map +1 -0
  110. package/dist/hydrate/index.d.ts +6 -0
  111. package/dist/hydrate/index.d.ts.map +1 -0
  112. package/dist/hydrate/index.js +11 -0
  113. package/dist/hydrate/payload.d.ts +38 -0
  114. package/dist/hydrate/payload.d.ts.map +1 -0
  115. package/dist/hydrate/selectors.d.ts +28 -0
  116. package/dist/hydrate/selectors.d.ts.map +1 -0
  117. package/dist/hydrate/types.d.ts +19 -0
  118. package/dist/hydrate/types.d.ts.map +1 -0
  119. package/dist/hydrate/utils.d.ts +8 -0
  120. package/dist/hydrate/utils.d.ts.map +1 -0
  121. package/dist/hydrate-Cr9eaeDK.js +654 -0
  122. package/dist/index.d.ts +19 -13
  123. package/dist/index.d.ts.map +1 -1
  124. package/dist/index.js +157 -662
  125. package/dist/intentConfigStore.d.ts +8 -0
  126. package/dist/intentConfigStore.d.ts.map +1 -0
  127. package/dist/intentProtocolApi.d.ts +11 -0
  128. package/dist/intentProtocolApi.d.ts.map +1 -0
  129. package/dist/intentProtocolEncoding.d.ts +25 -0
  130. package/dist/intentProtocolEncoding.d.ts.map +1 -0
  131. package/dist/intentProtocolResolver.d.ts +28 -0
  132. package/dist/intentProtocolResolver.d.ts.map +1 -0
  133. package/dist/intentReceiptPoller.d.ts.map +1 -1
  134. package/dist/intentValidation.d.ts +5 -0
  135. package/dist/intentValidation.d.ts.map +1 -0
  136. package/dist/intents.d.ts.map +1 -1
  137. package/dist/keymachine/index.d.ts +20 -0
  138. package/dist/keymachine/index.d.ts.map +1 -1
  139. package/dist/mutations.d.ts.map +1 -1
  140. package/dist/offlineRecovery.d.ts +24 -0
  141. package/dist/offlineRecovery.d.ts.map +1 -0
  142. package/dist/onramp/MeshConnectFlow.d.ts +9 -0
  143. package/dist/onramp/MeshConnectFlow.d.ts.map +1 -1
  144. package/dist/onramp/MeshConnectIframe.d.ts +9 -0
  145. package/dist/onramp/MeshConnectIframe.d.ts.map +1 -1
  146. package/dist/onramp/TrailsOnRampProvider.d.ts.map +1 -1
  147. package/dist/onramp/mesh/components/MeshExchangeConfirmation.d.ts +10 -0
  148. package/dist/onramp/mesh/components/MeshExchangeConfirmation.d.ts.map +1 -0
  149. package/dist/onramp/mesh/components/MeshExchangeIcon.d.ts +13 -0
  150. package/dist/onramp/mesh/components/MeshExchangeIcon.d.ts.map +1 -0
  151. package/dist/{widget → onramp/mesh}/components/MeshExchangeSelection.d.ts +1 -0
  152. package/dist/onramp/mesh/components/MeshExchangeSelection.d.ts.map +1 -0
  153. package/dist/onramp/mesh/components/MeshSessionOptions.d.ts +15 -0
  154. package/dist/onramp/mesh/components/MeshSessionOptions.d.ts.map +1 -0
  155. package/dist/onramp/mesh/hooks/useMeshAccessTokens.d.ts +9 -0
  156. package/dist/onramp/mesh/hooks/useMeshAccessTokens.d.ts.map +1 -0
  157. package/dist/onramp/mesh/hooks/useMeshFundingSelection.d.ts +11 -0
  158. package/dist/onramp/mesh/hooks/useMeshFundingSelection.d.ts.map +1 -0
  159. package/dist/onramp/mesh/hooks/useMeshOnrampFlow.d.ts +71 -0
  160. package/dist/onramp/mesh/hooks/useMeshOnrampFlow.d.ts.map +1 -0
  161. package/dist/onramp/mesh/hooks/useMeshOnrampSessionState.d.ts +32 -0
  162. package/dist/onramp/mesh/hooks/useMeshOnrampSessionState.d.ts.map +1 -0
  163. package/dist/onramp/mesh/hooks/useMeshSelectedTokenBalance.d.ts +19 -0
  164. package/dist/onramp/mesh/hooks/useMeshSelectedTokenBalance.d.ts.map +1 -0
  165. package/dist/onramp/mesh/hooks/useMeshSessionAccountBalance.d.ts +15 -0
  166. package/dist/onramp/mesh/hooks/useMeshSessionAccountBalance.d.ts.map +1 -0
  167. package/dist/onramp/mesh/hooks/useMeshSessionStorage.d.ts +7 -0
  168. package/dist/onramp/mesh/hooks/useMeshSessionStorage.d.ts.map +1 -0
  169. package/dist/onramp/meshSessionStorage.d.ts +13 -0
  170. package/dist/onramp/meshSessionStorage.d.ts.map +1 -0
  171. package/dist/onramp/meshconnect.d.ts +6 -4
  172. package/dist/onramp/meshconnect.d.ts.map +1 -1
  173. package/dist/onramp/trailsOnramp.d.ts +8 -0
  174. package/dist/onramp/trailsOnramp.d.ts.map +1 -1
  175. package/dist/onrampClient.d.ts.map +1 -1
  176. package/dist/prepareSend.d.ts +3 -2
  177. package/dist/prepareSend.d.ts.map +1 -1
  178. package/dist/query/intentProtocol.queries.d.ts +32 -0
  179. package/dist/query/intentProtocol.queries.d.ts.map +1 -0
  180. package/dist/recover.d.ts +70 -24
  181. package/dist/recover.d.ts.map +1 -1
  182. package/dist/src-4HYDQv2T.js +48798 -0
  183. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +2 -3
  184. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
  185. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +2 -3
  186. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
  187. package/dist/transactionIntent/deposits/standardDeposit.d.ts +2 -5
  188. package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
  189. package/dist/transactionIntent/handlers/intentHandler.d.ts +4 -4
  190. package/dist/transactionIntent/handlers/intentHandler.d.ts.map +1 -1
  191. package/dist/transactionIntent/quote/quoteHelpers.d.ts +2 -2
  192. package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
  193. package/dist/transactionIntent/types.d.ts +3 -3
  194. package/dist/transactionIntent/types.d.ts.map +1 -1
  195. package/dist/transactions.d.ts +1 -0
  196. package/dist/transactions.d.ts.map +1 -1
  197. package/dist/umd/trails.min.js +1370 -410
  198. package/dist/utils/localStorageGc.d.ts +22 -0
  199. package/dist/utils/localStorageGc.d.ts.map +1 -0
  200. package/dist/walletUtils.d.ts.map +1 -1
  201. package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
  202. package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
  203. package/dist/widget/components/ConnectedWallets.d.ts +1 -1
  204. package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
  205. package/dist/widget/components/Earn.d.ts +2 -6
  206. package/dist/widget/components/Earn.d.ts.map +1 -1
  207. package/dist/widget/components/FeeOption.d.ts +1 -1
  208. package/dist/widget/components/FeeOption.d.ts.map +1 -1
  209. package/dist/widget/components/FeeOptions.d.ts +1 -1
  210. package/dist/widget/components/FeeOptions.d.ts.map +1 -1
  211. package/dist/widget/components/FiatSelector.d.ts +1 -1
  212. package/dist/widget/components/FiatSelector.d.ts.map +1 -1
  213. package/dist/widget/components/FiatSelectorButton.d.ts +1 -1
  214. package/dist/widget/components/FiatSelectorButton.d.ts.map +1 -1
  215. package/dist/widget/components/Fund.d.ts +1 -1
  216. package/dist/widget/components/Fund.d.ts.map +1 -1
  217. package/dist/widget/components/FundMethods.d.ts.map +1 -1
  218. package/dist/widget/components/FundingMethodSelectorButton.d.ts +1 -1
  219. package/dist/widget/components/FundingMethodSelectorButton.d.ts.map +1 -1
  220. package/dist/widget/components/MeldHistory.d.ts +1 -1
  221. package/dist/widget/components/MeldHistory.d.ts.map +1 -1
  222. package/dist/widget/components/MeldTransactionStatus.d.ts +1 -1
  223. package/dist/widget/components/MeldTransactionStatus.d.ts.map +1 -1
  224. package/dist/widget/components/MeshExchangeAccountHeader.d.ts +9 -0
  225. package/dist/widget/components/MeshExchangeAccountHeader.d.ts.map +1 -0
  226. package/dist/widget/components/OnrampHistoryRow.d.ts +1 -1
  227. package/dist/widget/components/OnrampHistoryRow.d.ts.map +1 -1
  228. package/dist/widget/components/OnrampProviderConfirmation.d.ts +1 -1
  229. package/dist/widget/components/OnrampProviderConfirmation.d.ts.map +1 -1
  230. package/dist/widget/components/Pay.d.ts.map +1 -1
  231. package/dist/widget/components/PoolDeposit.d.ts +2 -6
  232. package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
  233. package/dist/widget/components/PoolWithdraw.d.ts +2 -2
  234. package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
  235. package/dist/widget/components/PulsatingButton.d.ts +9 -0
  236. package/dist/widget/components/PulsatingButton.d.ts.map +1 -0
  237. package/dist/widget/components/Receipt.d.ts +1 -1
  238. package/dist/widget/components/Receipt.d.ts.map +1 -1
  239. package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -1
  240. package/dist/widget/components/Recipients.d.ts.map +1 -1
  241. package/dist/widget/components/Swap.d.ts +2 -6
  242. package/dist/widget/components/Swap.d.ts.map +1 -1
  243. package/dist/widget/components/TokenList.d.ts +1 -0
  244. package/dist/widget/components/TokenList.d.ts.map +1 -1
  245. package/dist/widget/components/TokenSelector.d.ts +1 -2
  246. package/dist/widget/components/TokenSelector.d.ts.map +1 -1
  247. package/dist/widget/components/TransactionDetails.d.ts +1 -0
  248. package/dist/widget/components/TransactionDetails.d.ts.map +1 -1
  249. package/dist/widget/components/TransactionHistoryItem.d.ts +1 -0
  250. package/dist/widget/components/TransactionHistoryItem.d.ts.map +1 -1
  251. package/dist/widget/components/TransferPendingVertical.d.ts +1 -1
  252. package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
  253. package/dist/widget/components/WalletAccountHeader.d.ts +7 -0
  254. package/dist/widget/components/WalletAccountHeader.d.ts.map +1 -0
  255. package/dist/widget/components/WalletConfirmation.d.ts +2 -1
  256. package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
  257. package/dist/widget/components/WalletConnect.d.ts.map +1 -1
  258. package/dist/widget/components/WidgetProviders.d.ts.map +1 -1
  259. package/dist/widget/components/Withdraw.d.ts.map +1 -1
  260. package/dist/widget/index.d.ts +13 -0
  261. package/dist/widget/index.d.ts.map +1 -1
  262. package/dist/widget/index.js +16 -8
  263. package/dist/widget/modes/EarnWidget.d.ts +83 -0
  264. package/dist/widget/modes/EarnWidget.d.ts.map +1 -0
  265. package/dist/widget/modes/FundWidget.d.ts +103 -0
  266. package/dist/widget/modes/FundWidget.d.ts.map +1 -0
  267. package/dist/widget/modes/PayWidget.d.ts +86 -0
  268. package/dist/widget/modes/PayWidget.d.ts.map +1 -0
  269. package/dist/widget/modes/SwapWidget.d.ts +82 -0
  270. package/dist/widget/modes/SwapWidget.d.ts.map +1 -0
  271. package/dist/widget/modes/WithdrawWidget.d.ts +71 -0
  272. package/dist/widget/modes/WithdrawWidget.d.ts.map +1 -0
  273. package/dist/widget/providers/TrailsProvider.d.ts +3 -0
  274. package/dist/widget/providers/TrailsProvider.d.ts.map +1 -1
  275. package/dist/widget/shared/mapSharedProps.d.ts +9 -0
  276. package/dist/widget/shared/mapSharedProps.d.ts.map +1 -0
  277. package/dist/widget/shared/methodMap.d.ts +18 -0
  278. package/dist/widget/shared/methodMap.d.ts.map +1 -0
  279. package/dist/widget/shared/resolution.d.ts +22 -0
  280. package/dist/widget/shared/resolution.d.ts.map +1 -0
  281. package/dist/widget/shared/resolvePaymentSource.d.ts +34 -0
  282. package/dist/widget/shared/resolvePaymentSource.d.ts.map +1 -0
  283. package/dist/widget/shared/types.d.ts +94 -0
  284. package/dist/widget/shared/types.d.ts.map +1 -0
  285. package/dist/widget/types/commonProps.d.ts +3 -7
  286. package/dist/widget/types/commonProps.d.ts.map +1 -1
  287. package/dist/widget/utils/fundMethodSwitchState.d.ts +1 -0
  288. package/dist/widget/utils/fundMethodSwitchState.d.ts.map +1 -1
  289. package/dist/widget/utils/viewManagerGuards.d.ts +1 -1
  290. package/dist/widget/utils/viewManagerGuards.d.ts.map +1 -1
  291. package/dist/widget/widget.d.ts +21 -16
  292. package/dist/widget/widget.d.ts.map +1 -1
  293. package/package.json +17 -23
  294. package/dist/buffer.d.ts +0 -3
  295. package/dist/buffer.d.ts.map +0 -1
  296. package/dist/ccip-CT_An6eM.js +0 -230
  297. package/dist/index-RfqL5Foz.js +0 -114567
  298. package/dist/paymasterSend.d.ts +0 -90
  299. package/dist/paymasterSend.d.ts.map +0 -1
  300. package/dist/sendUserOp.d.ts +0 -122
  301. package/dist/sendUserOp.d.ts.map +0 -1
  302. package/dist/toSimpleSmartAccount.d.ts +0 -95
  303. package/dist/toSimpleSmartAccount.d.ts.map +0 -1
  304. package/dist/transactionIntent/utils/erc20Approval.d.ts +0 -34
  305. package/dist/transactionIntent/utils/erc20Approval.d.ts.map +0 -1
  306. package/dist/utils/allowance.d.ts +0 -19
  307. package/dist/utils/allowance.d.ts.map +0 -1
  308. package/dist/widget/analytics/useWidgetAnalytics.d.ts.map +0 -1
  309. package/dist/widget/components/FeeBreakdown.d.ts +0 -9
  310. package/dist/widget/components/FeeBreakdown.d.ts.map +0 -1
  311. package/dist/widget/components/HideBalances.d.ts +0 -4
  312. package/dist/widget/components/HideBalances.d.ts.map +0 -1
  313. package/dist/widget/components/MeshExchangeSelection.d.ts.map +0 -1
  314. package/dist/widget/components/OnrampDeposit.d.ts +0 -10
  315. package/dist/widget/components/OnrampDeposit.d.ts.map +0 -1
  316. package/dist/widget/components/SwapSettings.d.ts +0 -4
  317. package/dist/widget/components/SwapSettings.d.ts.map +0 -1
  318. package/dist/widget/components/TruncatedAddress.d.ts +0 -12
  319. package/dist/widget/components/TruncatedAddress.d.ts.map +0 -1
  320. package/dist/widget/components/WalletImage.d.ts +0 -8
  321. package/dist/widget/components/WalletImage.d.ts.map +0 -1
  322. package/dist/widget/css/compiled.css +0 -26
  323. package/dist/widget/css/index.css +0 -686
  324. package/dist/widget/hooks/useAddressWalletIcon.d.ts.map +0 -1
  325. package/dist/widget/hooks/useAmountUsd.d.ts.map +0 -1
  326. package/dist/widget/hooks/useBalanceVisible.d.ts.map +0 -1
  327. package/dist/widget/hooks/useChainFilter.d.ts.map +0 -1
  328. package/dist/widget/hooks/useCheckout.d.ts.map +0 -1
  329. package/dist/widget/hooks/useClickTracking.d.ts.map +0 -1
  330. package/dist/widget/hooks/useCombinedHistory.d.ts.map +0 -1
  331. package/dist/widget/hooks/useConnector.d.ts.map +0 -1
  332. package/dist/widget/hooks/useCustomTokenSearch.d.ts.map +0 -1
  333. package/dist/widget/hooks/useDebounce.d.ts.map +0 -1
  334. package/dist/widget/hooks/useDebugScreens.d.ts.map +0 -1
  335. package/dist/widget/hooks/useDefaultDestinationToken.d.ts.map +0 -1
  336. package/dist/widget/hooks/useDefaultOriginToken.d.ts.map +0 -1
  337. package/dist/widget/hooks/useDepositMonitor.d.ts.map +0 -1
  338. package/dist/widget/hooks/useDestinationSelectedToken.d.ts.map +0 -1
  339. package/dist/widget/hooks/useDisplayCurrencyPreference.d.ts.map +0 -1
  340. package/dist/widget/hooks/useEarnPool.d.ts.map +0 -1
  341. package/dist/widget/hooks/useExecutingIntentsCount.d.ts.map +0 -1
  342. package/dist/widget/hooks/useExternalFundingReceiptSync.d.ts.map +0 -1
  343. package/dist/widget/hooks/useFiatOnRampCurrencies.d.ts.map +0 -1
  344. package/dist/widget/hooks/useFiatSelectedCurrency.d.ts.map +0 -1
  345. package/dist/widget/hooks/useGetIntent.d.ts.map +0 -1
  346. package/dist/widget/hooks/useIntentReceiptBalances.d.ts.map +0 -1
  347. package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +0 -1
  348. package/dist/widget/hooks/useIsConnectedWalletSmartContract.d.ts +0 -7
  349. package/dist/widget/hooks/useIsConnectedWalletSmartContract.d.ts.map +0 -1
  350. package/dist/widget/hooks/useIsMobile.d.ts.map +0 -1
  351. package/dist/widget/hooks/useIsSequenceWallet.d.ts.map +0 -1
  352. package/dist/widget/hooks/useLocalePreference.d.ts.map +0 -1
  353. package/dist/widget/hooks/useMeldTransactionHistory.d.ts.map +0 -1
  354. package/dist/widget/hooks/useMeldTransactionStatus.d.ts.map +0 -1
  355. package/dist/widget/hooks/useOnRampCountryDefaults.d.ts.map +0 -1
  356. package/dist/widget/hooks/useOnRampPaymentMethods.d.ts.map +0 -1
  357. package/dist/widget/hooks/useOnRampProviderWidget.d.ts.map +0 -1
  358. package/dist/widget/hooks/useOnRampQuote.d.ts.map +0 -1
  359. package/dist/widget/hooks/useOnRampTransactionStatus.d.ts.map +0 -1
  360. package/dist/widget/hooks/useOriginSelectedToken.d.ts.map +0 -1
  361. package/dist/widget/hooks/usePayMessage.d.ts.map +0 -1
  362. package/dist/widget/hooks/usePriceImpactWarning.d.ts.map +0 -1
  363. package/dist/widget/hooks/useQuote.d.ts +0 -378
  364. package/dist/widget/hooks/useQuote.d.ts.map +0 -1
  365. package/dist/widget/hooks/useRecentTokens.d.ts.map +0 -1
  366. package/dist/widget/hooks/useRecipients.d.ts.map +0 -1
  367. package/dist/widget/hooks/useScreenTracking.d.ts +0 -2
  368. package/dist/widget/hooks/useScreenTracking.d.ts.map +0 -1
  369. package/dist/widget/hooks/useSelectedFeeOption.d.ts.map +0 -1
  370. package/dist/widget/hooks/useSelectedFundMethod.d.ts.map +0 -1
  371. package/dist/widget/hooks/useSelectedRecipient.d.ts.map +0 -1
  372. package/dist/widget/hooks/useSendForm.d.ts.map +0 -1
  373. package/dist/widget/hooks/useSwapAmount.d.ts.map +0 -1
  374. package/dist/widget/hooks/useSwapState.d.ts.map +0 -1
  375. package/dist/widget/hooks/useTargetAmount.d.ts.map +0 -1
  376. package/dist/widget/hooks/useTheme.d.ts.map +0 -1
  377. package/dist/widget/hooks/useTokenList.d.ts.map +0 -1
  378. package/dist/widget/hooks/useTrailsSendTransaction.d.ts.map +0 -1
  379. package/dist/widget/hooks/useViewManager.d.ts.map +0 -1
  380. package/dist/widget/hooks/useWalletConnectUri.d.ts +0 -11
  381. package/dist/widget/hooks/useWalletConnectUri.d.ts.map +0 -1
  382. package/dist/widget/hooks/useWalletConnectionContext.d.ts.map +0 -1
  383. package/dist/widget/hooks/useWidgetProps.d.ts.map +0 -1
  384. package/dist/widget/types.d.ts +0 -44
  385. package/dist/widget/types.d.ts.map +0 -1
  386. package/dist/widget/utils/historyUtils.d.ts +0 -18
  387. package/dist/widget/utils/historyUtils.d.ts.map +0 -1
  388. package/src/abi.ts +0 -38
  389. package/src/abis/erc20.ts +0 -60
  390. package/src/abis/trailsHydrate.ts +0 -185
  391. package/src/abis/trailsRouter.ts +0 -121
  392. package/src/abis/trailsSweep.ts +0 -32
  393. package/src/abortController.ts +0 -35
  394. package/src/analytics.ts +0 -2029
  395. package/src/buffer.ts +0 -10
  396. package/src/chainSwitch.ts +0 -95
  397. package/src/chains.ts +0 -570
  398. package/src/config.ts +0 -118
  399. package/src/constants.ts +0 -239
  400. package/src/contractUtils.ts +0 -46
  401. package/src/cssUtils.ts +0 -5
  402. package/src/customChains.ts +0 -24
  403. package/src/customTokens.ts +0 -168
  404. package/src/decoders.ts +0 -365
  405. package/src/ens.ts +0 -74
  406. package/src/error.ts +0 -268
  407. package/src/estimate.ts +0 -480
  408. package/src/explorer.ts +0 -38
  409. package/src/fees.ts +0 -362
  410. package/src/gasless.ts +0 -638
  411. package/src/index.ts +0 -205
  412. package/src/indexerClient.ts +0 -118
  413. package/src/intentReceiptMonitor.ts +0 -99
  414. package/src/intentReceiptPoller.ts +0 -327
  415. package/src/intents.ts +0 -1133
  416. package/src/keyMachineClient.ts +0 -29
  417. package/src/keymachine/index.ts +0 -175
  418. package/src/keymachine/key-machine.gen.ts +0 -993
  419. package/src/localeUtils.ts +0 -244
  420. package/src/logger/index.ts +0 -95
  421. package/src/logger/useSyncLoggerDebug.ts +0 -11
  422. package/src/logger.ts +0 -1
  423. package/src/meld/components/MeldCountriesList.tsx +0 -237
  424. package/src/meld/components/MeldFundMethods.tsx +0 -265
  425. package/src/meld/components/MeldProvidersList.tsx +0 -187
  426. package/src/meld/components/MeldTokensList.tsx +0 -321
  427. package/src/meld/components/SimpleHeader.tsx +0 -35
  428. package/src/meld/utils/meld.ts +0 -77
  429. package/src/mutations.ts +0 -166
  430. package/src/onramp/MeshConnectFlow.tsx +0 -86
  431. package/src/onramp/MeshConnectIframe.tsx +0 -661
  432. package/src/onramp/SendFromExchangeButton.tsx +0 -81
  433. package/src/onramp/TrailsOnRampProvider.tsx +0 -59
  434. package/src/onramp/index.ts +0 -31
  435. package/src/onramp/meshconnect.ts +0 -277
  436. package/src/onramp/trailsOnramp.tsx +0 -130
  437. package/src/onramp-client/index.ts +0 -52
  438. package/src/onrampClient.ts +0 -46
  439. package/src/paymasterSend.ts +0 -521
  440. package/src/placeholder.ts +0 -92
  441. package/src/poolUtils.ts +0 -222
  442. package/src/pools.ts +0 -120
  443. package/src/prepareSend.ts +0 -553
  444. package/src/query/balance.fetchers.ts +0 -753
  445. package/src/query/balance.hooks.ts +0 -357
  446. package/src/query/balance.queries.ts +0 -307
  447. package/src/query/chains.hooks.ts +0 -45
  448. package/src/query/chains.queries.ts +0 -17
  449. package/src/query/client.ts +0 -20
  450. package/src/query/fiat.fetchers.ts +0 -33
  451. package/src/query/fiat.hooks.ts +0 -71
  452. package/src/query/fiat.queries.ts +0 -67
  453. package/src/query/geo.fetchers.ts +0 -100
  454. package/src/query/geo.hooks.ts +0 -16
  455. package/src/query/geo.queries.ts +0 -36
  456. package/src/query/helpers.ts +0 -81
  457. package/src/query/meld.fetchers.ts +0 -97
  458. package/src/query/meld.hooks.ts +0 -18
  459. package/src/query/meld.queries.ts +0 -184
  460. package/src/query/persister.ts +0 -11
  461. package/src/query/price.fetchers.ts +0 -53
  462. package/src/query/price.hooks.ts +0 -46
  463. package/src/query/price.queries.ts +0 -364
  464. package/src/query/tokenList.queries.ts +0 -118
  465. package/src/queryParams.ts +0 -100
  466. package/src/recover.ts +0 -1728
  467. package/src/sendUserOp.ts +0 -512
  468. package/src/theme.ts +0 -2
  469. package/src/toSimpleSmartAccount.ts +0 -567
  470. package/src/toast.ts +0 -110
  471. package/src/tokens.ts +0 -1862
  472. package/src/trailsClient.ts +0 -40
  473. package/src/transactionIntent/constants.ts +0 -15
  474. package/src/transactionIntent/deposits/depositOrchestrator.ts +0 -243
  475. package/src/transactionIntent/deposits/gaslessDeposit.ts +0 -705
  476. package/src/transactionIntent/deposits/index.ts +0 -3
  477. package/src/transactionIntent/deposits/standardDeposit.ts +0 -590
  478. package/src/transactionIntent/execution/index.ts +0 -1
  479. package/src/transactionIntent/execution/transactionState.ts +0 -38
  480. package/src/transactionIntent/handlers/index.ts +0 -1
  481. package/src/transactionIntent/handlers/intentHandler.ts +0 -1613
  482. package/src/transactionIntent/helpers/index.ts +0 -1
  483. package/src/transactionIntent/helpers/transactionStateHelpers.ts +0 -440
  484. package/src/transactionIntent/index.ts +0 -10
  485. package/src/transactionIntent/quote/feeExtractors.ts +0 -61
  486. package/src/transactionIntent/quote/index.ts +0 -3
  487. package/src/transactionIntent/quote/normalizeQuote.ts +0 -559
  488. package/src/transactionIntent/quote/quoteHelpers.ts +0 -117
  489. package/src/transactionIntent/types.ts +0 -241
  490. package/src/transactionIntent/utils/balanceChecker.ts +0 -103
  491. package/src/transactionIntent/utils/erc20Approval.ts +0 -171
  492. package/src/transactionIntent/utils/index.ts +0 -2
  493. package/src/transactionIntent/utils/resilientDepositTracker.ts +0 -171
  494. package/src/transactionIntent/utils/testnetHelpers.ts +0 -5
  495. package/src/transactionIntent/validators.ts +0 -27
  496. package/src/transactions.ts +0 -429
  497. package/src/types.d.ts +0 -16
  498. package/src/umd.tsx +0 -33
  499. package/src/utils/address.ts +0 -78
  500. package/src/utils/allowance.ts +0 -47
  501. package/src/utils/fiat.ts +0 -32
  502. package/src/utils/format.ts +0 -625
  503. package/src/utils/passthrough.ts +0 -93
  504. package/src/utils/time.ts +0 -118
  505. package/src/utils/validation.ts +0 -104
  506. package/src/utils.ts +0 -112
  507. package/src/version.ts +0 -8
  508. package/src/vite-env.d.ts +0 -4
  509. package/src/walletUtils.ts +0 -293
  510. package/src/wallets.ts +0 -544
  511. package/src/widget/analytics/useWidgetAnalytics.ts +0 -56
  512. package/src/widget/assets/Exchange-icon-black.svg +0 -5
  513. package/src/widget/assets/MetaMask-icon-fox-with-margins.svg +0 -31
  514. package/src/widget/assets/MetaMask-icon-fox.svg +0 -26
  515. package/src/widget/assets/MetaMask-logo-black.svg +0 -3
  516. package/src/widget/assets/MetaMask-logo-white.svg +0 -16
  517. package/src/widget/assets/Trails-logo-black.svg +0 -13
  518. package/src/widget/assets/Trails-logo-white.svg +0 -13
  519. package/src/widget/assets/WalletChange-black.svg +0 -5
  520. package/src/widget/assets/WalletConnect-logo-black.svg +0 -14
  521. package/src/widget/assets/WalletConnect-logo-blue.svg +0 -14
  522. package/src/widget/assets/WalletConnect-logo-white.svg +0 -14
  523. package/src/widget/assets/WalletConnect-logo.svg +0 -40
  524. package/src/widget/assets/aave.svg +0 -14
  525. package/src/widget/assets/morpho.svg +0 -14
  526. package/src/widget/compiled.css +0 -26
  527. package/src/widget/components/AccountActionsDropdown.tsx +0 -31
  528. package/src/widget/components/AccountIntentTransactionHistory.tsx +0 -756
  529. package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +0 -34
  530. package/src/widget/components/AccountSettings.tsx +0 -168
  531. package/src/widget/components/AddressOrEnsName.tsx +0 -24
  532. package/src/widget/components/AddressWalletIcon.tsx +0 -49
  533. package/src/widget/components/AllChainsIcon.tsx +0 -54
  534. package/src/widget/components/ChainFilterDropdown.tsx +0 -220
  535. package/src/widget/components/ChainImage.tsx +0 -40
  536. package/src/widget/components/ChainList.tsx +0 -158
  537. package/src/widget/components/ClassicSwap.tsx +0 -1761
  538. package/src/widget/components/ConfigDisplay.tsx +0 -158
  539. package/src/widget/components/ConnectWallet.tsx +0 -566
  540. package/src/widget/components/ConnectedWallets.tsx +0 -414
  541. package/src/widget/components/CopyButton.tsx +0 -108
  542. package/src/widget/components/CountryFilterDropdown.tsx +0 -179
  543. package/src/widget/components/DebugMenu.tsx +0 -50
  544. package/src/widget/components/DebugScreensList.tsx +0 -70
  545. package/src/widget/components/DebugToast.tsx +0 -63
  546. package/src/widget/components/DepositTracker.tsx +0 -326
  547. package/src/widget/components/DirectTransfer.tsx +0 -305
  548. package/src/widget/components/Disconnect.tsx +0 -68
  549. package/src/widget/components/DynamicInputStyles.tsx +0 -121
  550. package/src/widget/components/DynamicSizeInputField.tsx +0 -245
  551. package/src/widget/components/ENSAvatar.tsx +0 -33
  552. package/src/widget/components/Earn.tsx +0 -160
  553. package/src/widget/components/EarnPools.tsx +0 -417
  554. package/src/widget/components/EarnPoolsFilters.tsx +0 -165
  555. package/src/widget/components/ErrorAnimationIcon.tsx +0 -130
  556. package/src/widget/components/ErrorDisplay.tsx +0 -152
  557. package/src/widget/components/ExecutingIntentsBadge.tsx +0 -24
  558. package/src/widget/components/ExecutionStatusBadge.tsx +0 -53
  559. package/src/widget/components/FeeBreakdown.tsx +0 -155
  560. package/src/widget/components/FeeOption.tsx +0 -170
  561. package/src/widget/components/FeeOptions.tsx +0 -247
  562. package/src/widget/components/FiatSelector.tsx +0 -308
  563. package/src/widget/components/FiatSelectorButton.tsx +0 -68
  564. package/src/widget/components/Footer.tsx +0 -67
  565. package/src/widget/components/Fund.tsx +0 -2463
  566. package/src/widget/components/FundMethods.tsx +0 -423
  567. package/src/widget/components/FundWalletSelection.tsx +0 -60
  568. package/src/widget/components/FundingMethodSelectorButton.tsx +0 -106
  569. package/src/widget/components/GreenCheckAnimation.tsx +0 -119
  570. package/src/widget/components/HideBalances.tsx +0 -24
  571. package/src/widget/components/HighPriceImpactBlock.tsx +0 -44
  572. package/src/widget/components/HookModalContent.tsx +0 -377
  573. package/src/widget/components/Identicon.tsx +0 -228
  574. package/src/widget/components/LoadingSpinner.tsx +0 -9
  575. package/src/widget/components/MeldForm.tsx +0 -780
  576. package/src/widget/components/MeldHistory.tsx +0 -433
  577. package/src/widget/components/MeldStepsFlow.tsx +0 -1651
  578. package/src/widget/components/MeldTransactionStatus.tsx +0 -255
  579. package/src/widget/components/MeshExchangeSelection.tsx +0 -218
  580. package/src/widget/components/Modal.tsx +0 -86
  581. package/src/widget/components/OFTProgressBar.tsx +0 -89
  582. package/src/widget/components/OnRampProviderSelector.tsx +0 -263
  583. package/src/widget/components/OnrampDeposit.tsx +0 -122
  584. package/src/widget/components/OnrampErrorScreen.tsx +0 -163
  585. package/src/widget/components/OnrampHistoryRow.tsx +0 -321
  586. package/src/widget/components/OnrampPaymentMethods.tsx +0 -81
  587. package/src/widget/components/OnrampProviderConfirmation.tsx +0 -1060
  588. package/src/widget/components/OriginSelectionAmount.tsx +0 -144
  589. package/src/widget/components/OriginTransferInformation.tsx +0 -59
  590. package/src/widget/components/Pay.tsx +0 -1165
  591. package/src/widget/components/PaymentMethods.tsx +0 -198
  592. package/src/widget/components/PercentageMaxButtons.tsx +0 -112
  593. package/src/widget/components/PoolDeposit.tsx +0 -642
  594. package/src/widget/components/PoolWithdraw.tsx +0 -761
  595. package/src/widget/components/PriceImpactWarning.tsx +0 -87
  596. package/src/widget/components/QRCodeOptions.tsx +0 -65
  597. package/src/widget/components/QRCodeWalletSelect.tsx +0 -80
  598. package/src/widget/components/QrCode.tsx +0 -216
  599. package/src/widget/components/QuoteDetails.tsx +0 -1275
  600. package/src/widget/components/Receipt.tsx +0 -673
  601. package/src/widget/components/ReceiptRecoverableFunds.tsx +0 -135
  602. package/src/widget/components/RecentTokens.tsx +0 -66
  603. package/src/widget/components/RecipientSelectorButton.tsx +0 -50
  604. package/src/widget/components/Recipients.tsx +0 -413
  605. package/src/widget/components/RefundWarning.tsx +0 -61
  606. package/src/widget/components/RequiredPropsError.tsx +0 -33
  607. package/src/widget/components/ScreenHeader.tsx +0 -123
  608. package/src/widget/components/SearchInputField.tsx +0 -99
  609. package/src/widget/components/SessionTimeoutScreen.tsx +0 -103
  610. package/src/widget/components/ShadowPortal.tsx +0 -99
  611. package/src/widget/components/ShadowRootContext.tsx +0 -17
  612. package/src/widget/components/SimpleRecipientInputScreen.tsx +0 -91
  613. package/src/widget/components/SlippageToleranceSettings.tsx +0 -279
  614. package/src/widget/components/Swap.tsx +0 -50
  615. package/src/widget/components/SwapDisplay.tsx +0 -68
  616. package/src/widget/components/SwapSettings.tsx +0 -52
  617. package/src/widget/components/ThemeProvider.tsx +0 -115
  618. package/src/widget/components/ThemeSyncer.tsx +0 -47
  619. package/src/widget/components/Toast.tsx +0 -336
  620. package/src/widget/components/TokenDisplayNonSelectable.tsx +0 -40
  621. package/src/widget/components/TokenImage.tsx +0 -156
  622. package/src/widget/components/TokenList.tsx +0 -107
  623. package/src/widget/components/TokenSelector.tsx +0 -807
  624. package/src/widget/components/TokenSelectorButton.tsx +0 -123
  625. package/src/widget/components/TokenSkeleton.tsx +0 -53
  626. package/src/widget/components/Tooltip.tsx +0 -64
  627. package/src/widget/components/TrailsHookModal.tsx +0 -107
  628. package/src/widget/components/TransactionDetails.tsx +0 -534
  629. package/src/widget/components/TransactionHistoryItem.tsx +0 -767
  630. package/src/widget/components/TransferPendingVertical.tsx +0 -591
  631. package/src/widget/components/TruncatedAddress.tsx +0 -68
  632. package/src/widget/components/TruncatedTransactionHash.tsx +0 -74
  633. package/src/widget/components/UserPreferences.tsx +0 -570
  634. package/src/widget/components/WaasFeeOptions.tsx +0 -588
  635. package/src/widget/components/WalletConfirmation.tsx +0 -220
  636. package/src/widget/components/WalletConnect.tsx +0 -348
  637. package/src/widget/components/WalletConnectionPending.tsx +0 -178
  638. package/src/widget/components/WalletImage.tsx +0 -52
  639. package/src/widget/components/WalletList.tsx +0 -125
  640. package/src/widget/components/WidgetProviders.tsx +0 -82
  641. package/src/widget/components/Withdraw.tsx +0 -1106
  642. package/src/widget/components/YellowWarningAnimation.tsx +0 -146
  643. package/src/widget/hooks/useAddressWalletIcon.ts +0 -55
  644. package/src/widget/hooks/useAmountUsd.ts +0 -44
  645. package/src/widget/hooks/useBalanceVisible.tsx +0 -95
  646. package/src/widget/hooks/useChainFilter.tsx +0 -56
  647. package/src/widget/hooks/useCheckout.ts +0 -361
  648. package/src/widget/hooks/useClickTracking.ts +0 -74
  649. package/src/widget/hooks/useCombinedHistory.ts +0 -420
  650. package/src/widget/hooks/useConnector.tsx +0 -24
  651. package/src/widget/hooks/useCustomTokenSearch.tsx +0 -369
  652. package/src/widget/hooks/useDebounce.ts +0 -25
  653. package/src/widget/hooks/useDebugScreens.ts +0 -600
  654. package/src/widget/hooks/useDefaultDestinationToken.tsx +0 -179
  655. package/src/widget/hooks/useDefaultOriginToken.tsx +0 -407
  656. package/src/widget/hooks/useDepositMonitor.ts +0 -118
  657. package/src/widget/hooks/useDestinationSelectedToken.tsx +0 -310
  658. package/src/widget/hooks/useDisplayCurrencyPreference.tsx +0 -145
  659. package/src/widget/hooks/useEarnPool.tsx +0 -36
  660. package/src/widget/hooks/useExecutingIntentsCount.ts +0 -78
  661. package/src/widget/hooks/useExternalFundingReceiptSync.ts +0 -79
  662. package/src/widget/hooks/useFiatOnRampCurrencies.ts +0 -46
  663. package/src/widget/hooks/useFiatSelectedCurrency.tsx +0 -123
  664. package/src/widget/hooks/useGetIntent.ts +0 -54
  665. package/src/widget/hooks/useIntentReceiptBalances.ts +0 -141
  666. package/src/widget/hooks/useIntentTransactionHistory.ts +0 -790
  667. package/src/widget/hooks/useIsConnectedWalletSmartContract.ts +0 -43
  668. package/src/widget/hooks/useIsMobile.tsx +0 -50
  669. package/src/widget/hooks/useIsSequenceWallet.ts +0 -17
  670. package/src/widget/hooks/useLocalePreference.tsx +0 -187
  671. package/src/widget/hooks/useMeldTransactionHistory.ts +0 -184
  672. package/src/widget/hooks/useMeldTransactionStatus.ts +0 -707
  673. package/src/widget/hooks/useOnRampCountryDefaults.ts +0 -57
  674. package/src/widget/hooks/useOnRampPaymentMethods.ts +0 -72
  675. package/src/widget/hooks/useOnRampProviderWidget.ts +0 -184
  676. package/src/widget/hooks/useOnRampQuote.ts +0 -340
  677. package/src/widget/hooks/useOnRampTransactionStatus.ts +0 -196
  678. package/src/widget/hooks/useOriginSelectedToken.tsx +0 -253
  679. package/src/widget/hooks/usePayMessage.tsx +0 -496
  680. package/src/widget/hooks/usePriceImpactWarning.ts +0 -17
  681. package/src/widget/hooks/useQuote.ts +0 -1239
  682. package/src/widget/hooks/useRecentTokens.ts +0 -159
  683. package/src/widget/hooks/useRecipients.ts +0 -167
  684. package/src/widget/hooks/useScreenTracking.ts +0 -14
  685. package/src/widget/hooks/useSelectedFeeOption.tsx +0 -323
  686. package/src/widget/hooks/useSelectedFundMethod.tsx +0 -93
  687. package/src/widget/hooks/useSelectedRecipient.tsx +0 -75
  688. package/src/widget/hooks/useSendForm.ts +0 -1389
  689. package/src/widget/hooks/useSwapAmount.tsx +0 -50
  690. package/src/widget/hooks/useSwapState.tsx +0 -121
  691. package/src/widget/hooks/useTargetAmount.ts +0 -26
  692. package/src/widget/hooks/useTheme.tsx +0 -80
  693. package/src/widget/hooks/useTokenList.ts +0 -1168
  694. package/src/widget/hooks/useTrailsSendTransaction.ts +0 -987
  695. package/src/widget/hooks/useViewManager.tsx +0 -506
  696. package/src/widget/hooks/useWalletConnectUri.tsx +0 -307
  697. package/src/widget/hooks/useWalletConnectionContext.tsx +0 -128
  698. package/src/widget/hooks/useWidgetProps.tsx +0 -33
  699. package/src/widget/index.css +0 -686
  700. package/src/widget/index.tsx +0 -28
  701. package/src/widget/providers/TrailsModalProvider.tsx +0 -238
  702. package/src/widget/providers/TrailsProvider.tsx +0 -155
  703. package/src/widget/providers/UserActivityProvider.tsx +0 -78
  704. package/src/widget/providers/WidgetProviderTree.tsx +0 -90
  705. package/src/widget/styles.ts +0 -26
  706. package/src/widget/types/analytics.ts +0 -22
  707. package/src/widget/types/commonProps.ts +0 -56
  708. package/src/widget/types/svg.d.ts +0 -8
  709. package/src/widget/types.ts +0 -51
  710. package/src/widget/utils/countryUtils.ts +0 -89
  711. package/src/widget/utils/createWagmiConfig.ts +0 -43
  712. package/src/widget/utils/forexRateStore.ts +0 -120
  713. package/src/widget/utils/fundMethodSwitchState.ts +0 -27
  714. package/src/widget/utils/historyFilters.ts +0 -157
  715. package/src/widget/utils/historyUtils.ts +0 -101
  716. package/src/widget/utils/localeStore.ts +0 -68
  717. package/src/widget/utils/meldProviderUtils.ts +0 -26
  718. package/src/widget/utils/meshSupportedTokens.ts +0 -28
  719. package/src/widget/utils/onrampConfig.ts +0 -15
  720. package/src/widget/utils/statusLabel.ts +0 -3
  721. package/src/widget/utils/tokens.ts +0 -138
  722. package/src/widget/utils/trailsOnrampConfig.ts +0 -39
  723. package/src/widget/utils/transactionFailure.ts +0 -52
  724. package/src/widget/utils/viewManagerGuards.ts +0 -49
  725. package/src/widget/utils/windowUtils.ts +0 -138
  726. package/src/widget/widget.tsx +0 -3400
  727. /package/dist/{widget/hooks → hooks}/useAddressWalletIcon.d.ts +0 -0
  728. /package/dist/{widget/hooks → hooks}/useAmountUsd.d.ts +0 -0
  729. /package/dist/{widget/hooks → hooks}/useBalanceVisible.d.ts +0 -0
  730. /package/dist/{widget/hooks → hooks}/useChainFilter.d.ts +0 -0
  731. /package/dist/{widget/hooks → hooks}/useClickTracking.d.ts +0 -0
  732. /package/dist/{widget/hooks → hooks}/useConnector.d.ts +0 -0
  733. /package/dist/{widget/hooks → hooks}/useDebounce.d.ts +0 -0
  734. /package/dist/{widget/hooks → hooks}/useDepositMonitor.d.ts +0 -0
  735. /package/dist/{widget/hooks → hooks}/useDisplayCurrencyPreference.d.ts +0 -0
  736. /package/dist/{widget/hooks → hooks}/useExecutingIntentsCount.d.ts +0 -0
  737. /package/dist/{widget/hooks → hooks}/useFiatSelectedCurrency.d.ts +0 -0
  738. /package/dist/{widget/hooks → hooks}/useGetIntent.d.ts +0 -0
  739. /package/dist/{widget/hooks → hooks}/useIsMobile.d.ts +0 -0
  740. /package/dist/{widget/hooks → hooks}/useIsSequenceWallet.d.ts +0 -0
  741. /package/dist/{widget/hooks → hooks}/useLocalePreference.d.ts +0 -0
  742. /package/dist/{widget/hooks → hooks}/useMeldTransactionHistory.d.ts +0 -0
  743. /package/dist/{widget/hooks → hooks}/useMeldTransactionStatus.d.ts +0 -0
  744. /package/dist/{widget/hooks → hooks}/useOnRampCountryDefaults.d.ts +0 -0
  745. /package/dist/{widget/hooks → hooks}/usePayMessage.d.ts +0 -0
  746. /package/dist/{widget/hooks → hooks}/usePriceImpactWarning.d.ts +0 -0
  747. /package/dist/{widget/hooks → hooks}/useRecipients.d.ts +0 -0
  748. /package/dist/{widget/hooks → hooks}/useSelectedFeeOption.d.ts +0 -0
  749. /package/dist/{widget/hooks → hooks}/useSelectedRecipient.d.ts +0 -0
  750. /package/dist/{widget/hooks → hooks}/useSwapAmount.d.ts +0 -0
  751. /package/dist/{widget/hooks → hooks}/useTargetAmount.d.ts +0 -0
  752. /package/dist/{widget/hooks → hooks}/useTheme.d.ts +0 -0
  753. /package/dist/{widget/hooks → hooks}/useWalletConnectionContext.d.ts +0 -0
package/src/recover.ts DELETED
@@ -1,1728 +0,0 @@
1
- import type { Payload as WalletPayload } from "@0xsequence/wallet-primitives"
2
- import {
3
- type Config,
4
- Constants,
5
- Erc6492,
6
- Payload,
7
- Signature,
8
- } from "@0xsequence/wallet-primitives"
9
- import { isPositiveBigInt } from "./utils/validation.js"
10
- import {
11
- IntentProtocolVersion,
12
- type Intent,
13
- type IntentCalls,
14
- type TransactionCall,
15
- } from "@0xtrails/api"
16
- import { AbiFunction, Address, Bytes, type Hex } from "ox"
17
- import { useCallback, useMemo } from "react"
18
- import type { Chain, TransactionReceipt, WalletClient } from "viem"
19
- import { zeroAddress } from "viem"
20
- import { getChainInfo, getChainRpcClient } from "./chains.js"
21
- import { attemptSwitchChain } from "./chainSwitch.js"
22
- import { SEQUENCE_V3_CONTRACT_ADDRESSES } from "./constants.js"
23
- import { decodeGuestModuleEvents } from "./decoders.js"
24
- import { splitSignature } from "./gasless.js"
25
- import {
26
- abortIntent,
27
- getIntentConfigurationFromAddress,
28
- getIntentConfigurationFromCalls,
29
- } from "./intents.js"
30
- import { logger } from "./logger.js"
31
- import { type TrailsClient, useTrailsClient } from "./trailsClient.js"
32
- import {
33
- useTokenBalancesForMultipleAccounts,
34
- WIDGET_REFRESH_INTERVAL,
35
- } from "./query/balance.hooks.js"
36
- import type { FlatTokenBalancesData } from "./query/balance.fetchers.js"
37
- import type { Token } from "./tokens.js"
38
- import {
39
- checkProviderHealth,
40
- sendWalletTransaction,
41
- signWithTimeout,
42
- } from "./walletUtils.js"
43
- import { getERC20TransferData } from "./utils.js"
44
- import { useGetIntent } from "./widget/hooks/useGetIntent.js"
45
-
46
- import { normalizeAddress } from "./utils/address.js"
47
- import {
48
- type KeyMachineClient,
49
- useKeyMachineClient,
50
- } from "./keyMachineClient.js"
51
-
52
- function getIntentProtocol(
53
- intent: Intent | null | undefined,
54
- ): IntentProtocolVersion {
55
- const rawIntentProtocol = (
56
- intent as { intentProtocol?: string; intentProtocolVersion?: string }
57
- )?.intentProtocol
58
- const rawIntentProtocolVersion = (
59
- intent as { intentProtocol?: string; intentProtocolVersion?: string }
60
- )?.intentProtocolVersion
61
- const rawVersion = rawIntentProtocol ?? rawIntentProtocolVersion
62
-
63
- if (rawVersion === "v1.5" || rawVersion === "v1_5") {
64
- return IntentProtocolVersion.v1_5
65
- }
66
-
67
- return IntentProtocolVersion.v1
68
- }
69
- /**
70
- * Checks if an address is deployed by checking for bytecode
71
- * @param address - The address to check
72
- * @param chainId - The chain ID where the address exists
73
- * @returns Promise resolving to true if the address has bytecode, false otherwise
74
- */
75
- export async function isAddressDeployed(
76
- address: Address.Address,
77
- chainId: number,
78
- ): Promise<boolean> {
79
- const publicClient = getChainRpcClient(chainId)
80
- const code = await publicClient.getCode({ address })
81
- const isDeployed = code !== undefined && code !== "0x"
82
- logger.console.log("[refund] Address deployment check:", {
83
- address,
84
- chainId,
85
- codeLength: code?.length ?? 0,
86
- isDeployed,
87
- })
88
- return isDeployed
89
- }
90
-
91
- /**
92
- * Generates a random space value for Sequence wallet payloads.
93
- * Space must be in the range [0, 2^160) (20 bytes).
94
- */
95
- function generateRandomSpace(): bigint {
96
- const bytes = new Uint8Array(20) // 20 bytes = 160 bits
97
- crypto.getRandomValues(bytes)
98
- // Convert bytes to BigInt, ensuring it's within [0, 2^160)
99
- return BigInt(
100
- `0x${Array.from(bytes)
101
- .map((b) => b.toString(16).padStart(2, "0"))
102
- .join("")}`,
103
- )
104
- }
105
-
106
- /**
107
- * Creates a refund payload with random space
108
- * @param refundCall - The refund call to include in the payload
109
- * @param nonce - The nonce value to use
110
- * @returns The created payload
111
- */
112
- function createRefundPayload(
113
- refundCall: Payload.Call,
114
- nonce: bigint,
115
- ): Payload.Calls {
116
- const refundSpace = generateRandomSpace()
117
- return {
118
- type: "call",
119
- calls: [refundCall],
120
- space: refundSpace,
121
- nonce,
122
- }
123
- }
124
-
125
- /**
126
- * Signs the payload hash for a refund transaction
127
- */
128
- export async function signPayload(
129
- walletClient: WalletClient,
130
- intentAddress: Address.Address,
131
- chainId: number,
132
- payload: Payload.Calls,
133
- ): Promise<string> {
134
- if (!walletClient.account) {
135
- throw new Error("Wallet client account is required for signing")
136
- }
137
-
138
- // Check provider health before signing
139
- await checkProviderHealth(walletClient)
140
-
141
- const typedData = Payload.toTyped(
142
- Address.from(intentAddress),
143
- chainId,
144
- payload,
145
- )
146
-
147
- // Sign with timeout to prevent hanging
148
- const signature = await signWithTimeout(
149
- walletClient.signTypedData({
150
- account: walletClient.account,
151
- ...typedData,
152
- }),
153
- "Payload signature",
154
- )
155
-
156
- logger.console.log("[refund] Signature received:", signature)
157
- return signature
158
- }
159
-
160
- export interface BuildRefundTransactionWithSignatureParams {
161
- trailsClient: TrailsClient
162
- keyMachineClient: KeyMachineClient
163
- intentId: string
164
- intentProtocol: IntentProtocolVersion
165
- mainSigner: Address.Address
166
- checkpoint: number
167
- calls: Array<IntentCalls>
168
- payload: Payload.Calls // The payload that was signed
169
- chainId: number
170
- intentAddress: Address.Address
171
- signature: string // Hex string signature
172
- isOriginIntent: boolean // Whether this is the origin intent address (vs destination)
173
- }
174
-
175
- /**
176
- * Builds a refund transaction using a pre-signed hash
177
- */
178
- export async function buildRefundTransactionWithSignature(
179
- params: BuildRefundTransactionWithSignatureParams,
180
- ): Promise<{ to: `0x${string}`; data: Hex.Hex }> {
181
- const {
182
- trailsClient,
183
- keyMachineClient,
184
- intentId,
185
- intentProtocol,
186
- mainSigner,
187
- checkpoint,
188
- calls,
189
- payload,
190
- chainId,
191
- intentAddress,
192
- signature,
193
- isOriginIntent,
194
- } = params
195
-
196
- // Validate refund call "to" address is not zeroAddress
197
- const refundCall = payload.calls[0]
198
- if (!refundCall) {
199
- throw new Error("Refund call not found in payload")
200
- }
201
- if (!refundCall.to || Address.isEqual(refundCall.to, zeroAddress)) {
202
- throw new Error("Refund call 'to' address cannot be zero address")
203
- }
204
-
205
- logger.console.log(
206
- "[refund] buildRefundTransactionWithSignature called with params:",
207
- {
208
- mainSigner,
209
- callsCount: calls.length,
210
- calls: calls.map((c) => ({
211
- chainId: c.chainId,
212
- space: c.space?.toString(),
213
- nonce: c.nonce?.toString(),
214
- callsCount: c.calls?.length,
215
- calls: c.calls.map((c) => ({
216
- to: c.to,
217
- value: c.value?.toString(),
218
- data: c.data,
219
- gasLimit: c.gasLimit?.toString(),
220
- delegateCall: c.delegateCall,
221
- onlyFallback: c.onlyFallback,
222
- behaviorOnError: c.behaviorOnError,
223
- })),
224
- })),
225
- refundCall: {
226
- to: refundCall.to,
227
- value: refundCall.value.toString(),
228
- data: refundCall.data,
229
- gasLimit: refundCall.gasLimit.toString(),
230
- },
231
- chainId,
232
- intentAddress,
233
- signatureLength: signature.length,
234
- space: payload.space.toString(),
235
- nonce: payload.nonce.toString(),
236
- },
237
- )
238
-
239
- // In the current version, calls are already pre-filtered in the hook
240
- // to contain only the calls for the selected intent address (origin or destination)
241
- logger.console.log("[refund] Using pre-filtered calls for configuration:", {
242
- intentProtocol,
243
- callsCount: calls.length,
244
- chainId,
245
- intentAddress,
246
- isOriginIntent,
247
- callChainIds: calls.map((c) => c.chainId),
248
- })
249
-
250
- if (calls.length !== 1) {
251
- throw new Error("Invalid calls provided for intent configuration")
252
- }
253
-
254
- let intentConfig: Config.Config
255
- let imageHash: Hex.Hex
256
- let resolvedAddress: Address.Address
257
- const context = SEQUENCE_V3_CONTRACT_ADDRESSES
258
- // Attempt to get the intent configuration from the address
259
- const configFromAddress = await getIntentConfigurationFromAddress(
260
- keyMachineClient,
261
- intentAddress,
262
- )
263
- if (configFromAddress) {
264
- intentConfig = configFromAddress.config
265
- imageHash = configFromAddress.imageHash
266
- resolvedAddress = configFromAddress.address
267
- } else {
268
- // Fallback to reconstruction
269
- const configFromCalls = await getIntentConfigurationFromCalls(
270
- trailsClient,
271
- intentId,
272
- intentProtocol,
273
- mainSigner,
274
- checkpoint,
275
- calls[0]!,
276
- isOriginIntent,
277
- context,
278
- )
279
- intentConfig = configFromCalls.config
280
- imageHash = configFromCalls.imageHash
281
- resolvedAddress = configFromCalls.address
282
- }
283
-
284
- logger.console.log("[refund] Image hash:", imageHash)
285
-
286
- if (!Address.isEqual(resolvedAddress, intentAddress)) {
287
- throw new Error(
288
- "API address does not match intent address. Probably config is wrong",
289
- )
290
- }
291
-
292
- // Use the payload that was passed in (already contains space, nonce, and refundCall)
293
- logger.console.log("[refund] Payload created:", {
294
- type: payload.type,
295
- callsCount: payload.calls.length,
296
- space: payload.space.toString(),
297
- nonce: payload.nonce.toString(),
298
- calls: payload.calls.map((c) => ({
299
- to: c.to,
300
- value: c.value.toString(),
301
- data: c.data,
302
- gasLimit: c.gasLimit.toString(),
303
- })),
304
- })
305
-
306
- const encodedPayload = Bytes.toHex(Payload.encode(payload))
307
- logger.console.log("[refund] Encoded payload:", encodedPayload)
308
-
309
- const toSignatureLeaf = async (
310
- signer: Address.Address,
311
- signature: `0x${string}`,
312
- ): Promise<
313
- Signature.SignatureOfSignerLeaf | Signature.SignatureOfSapientSignerLeaf
314
- > => {
315
- const signerIsContract = await isAddressDeployed(signer, chainId)
316
- if (signerIsContract) {
317
- return {
318
- address: signer,
319
- type: "erc1271",
320
- data: signature as `0x${string}`,
321
- }
322
- } else {
323
- const { r, s, v } = splitSignature(signature)
324
- const yParity = v - 27 // Convert v to yParity (0 or 1)
325
- logger.console.log("[refund] Signature parsed:", { r, s, v, yParity })
326
- const rBigInt = BigInt(r)
327
- const sBigInt = BigInt(s)
328
- return {
329
- type: "hash",
330
- r: rBigInt,
331
- s: sBigInt,
332
- yParity,
333
- }
334
- }
335
- }
336
- const signerSignatureLeaf = await toSignatureLeaf(
337
- mainSigner,
338
- signature as `0x${string}`,
339
- )
340
- const topology = Signature.fillLeaves(intentConfig.topology, (leaf) =>
341
- Address.isEqual(leaf.address, mainSigner) ? signerSignatureLeaf : undefined,
342
- )
343
- logger.console.log("[refund] Topology filled with signature leaves")
344
-
345
- const filledConfig = {
346
- noChainId: false,
347
- configuration: { ...intentConfig, topology },
348
- }
349
- const encodedSignature = Signature.encodeSignature(filledConfig, true, true)
350
- logger.console.log(
351
- "[refund] Signature encoded:",
352
- Bytes.toHex(encodedSignature),
353
- )
354
-
355
- // Check if intent address has bytecode deployed
356
- const intentAddressDeployed = await isAddressDeployed(intentAddress, chainId)
357
-
358
- const executeData = AbiFunction.encodeData(Constants.EXECUTE, [
359
- encodedPayload,
360
- Bytes.toHex(encodedSignature),
361
- ])
362
- logger.console.log("[refund] Execute data encoded:", executeData)
363
-
364
- // Validate intent address is not zeroAddress
365
- if (!intentAddress || Address.isEqual(intentAddress, zeroAddress)) {
366
- throw new Error("Intent address cannot be zero address")
367
- }
368
-
369
- if (intentAddressDeployed) {
370
- logger.console.log(
371
- "[refund] Intent address is deployed, returning direct transaction:",
372
- {
373
- to: intentAddress,
374
- data: executeData,
375
- },
376
- )
377
- return { to: intentAddress, data: executeData }
378
- } else {
379
- logger.console.log(
380
- "[refund] Intent address not deployed, using ERC-6492 deploy",
381
- )
382
- const deploy = Erc6492.deploy(imageHash, context)
383
- logger.console.log("[refund] ERC-6492 deploy created:", {
384
- to: deploy.to,
385
- dataLength: deploy.data.length,
386
- deployToHex: deploy.to,
387
- imageHashUsed: imageHash,
388
- factoryAddress: context.factory,
389
- guestModuleAddress: context.guestModule,
390
- })
391
-
392
- // Validate deploy.to and intentAddress are not zeroAddress
393
- if (!deploy.to || Address.isEqual(deploy.to, zeroAddress)) {
394
- throw new Error("Deploy 'to' address cannot be zero address")
395
- }
396
-
397
- const deployPayload = {
398
- type: "call" as const,
399
- space: 0n,
400
- nonce: 0n,
401
- calls: [
402
- {
403
- to: deploy.to,
404
- value: 0n,
405
- data: deploy.data,
406
- gasLimit: 0n,
407
- delegateCall: false,
408
- onlyFallback: false,
409
- behaviorOnError: "revert" as const,
410
- },
411
- {
412
- to: intentAddress,
413
- value: 0n,
414
- data: executeData,
415
- gasLimit: 0n,
416
- delegateCall: false,
417
- onlyFallback: false,
418
- behaviorOnError: "revert" as const,
419
- },
420
- ],
421
- }
422
- logger.console.log("[refund] Deploy payload created:", {
423
- callsCount: deployPayload.calls.length,
424
- calls: deployPayload.calls.map((c) => ({
425
- to: c.to,
426
- value: c.value.toString(),
427
- dataLength: c.data.length,
428
- gasLimit: c.gasLimit.toString(),
429
- })),
430
- })
431
-
432
- const encodedDeployPayload = Bytes.toHex(Payload.encode(deployPayload))
433
- logger.console.log("[refund] Encoded deploy payload:", {
434
- fullPayload: encodedDeployPayload,
435
- payloadLength: encodedDeployPayload.length,
436
- payloadPreview: `${encodedDeployPayload.slice(0, 100)}...`,
437
- executeDataLength: executeData.length,
438
- executeDataPreview: `${executeData.slice(0, 100)}...`,
439
- })
440
-
441
- const result = {
442
- to: context.guestModule as `0x${string}`,
443
- data: encodedDeployPayload,
444
- }
445
-
446
- // Validate final transaction "to" address is not zeroAddress
447
- if (!result.to || Address.isEqual(result.to, zeroAddress)) {
448
- throw new Error("Transaction 'to' address cannot be zero address")
449
- }
450
-
451
- logger.console.log("[refund] Returning ERC-6492 transaction:", {
452
- to: result.to,
453
- dataLength: result.data.length,
454
- })
455
-
456
- return result
457
- }
458
- }
459
-
460
- /**
461
- * Determines the refund call based on token balances at the intent address
462
- * Uses Token type which has symbol, name, decimals, chainId directly (no contractInfo)
463
- */
464
- export function determineRefundCall(
465
- tokenBalancesData:
466
- | {
467
- tokens?: Array<{
468
- balance?: string
469
- contractAddress?: string
470
- decimals?: number
471
- chainId?: number
472
- isNativeToken?: boolean
473
- }>
474
- }
475
- | undefined,
476
- refundToAddress: `0x${string}`,
477
- ): WalletPayload.Call {
478
- // Validate refund address is not zeroAddress
479
- if (!refundToAddress || Address.isEqual(refundToAddress, zeroAddress)) {
480
- throw new Error("Refund address cannot be zero address")
481
- }
482
- // Find the token with the highest balance
483
- let highestBalanceToken: {
484
- type: "native" | "erc20"
485
- balance: bigint
486
- tokenAddress?: string
487
- decimals?: number
488
- chainId?: number
489
- } | null = null
490
-
491
- // Check all tokens (both native and ERC20)
492
- if (tokenBalancesData?.tokens) {
493
- for (const token of tokenBalancesData.tokens) {
494
- const balance = BigInt(token.balance || "0")
495
- if (balance > 0n) {
496
- if (!highestBalanceToken || balance > highestBalanceToken.balance) {
497
- highestBalanceToken = {
498
- type: token.isNativeToken ? "native" : "erc20",
499
- balance,
500
- tokenAddress: token.contractAddress,
501
- decimals: token.decimals,
502
- chainId: token.chainId,
503
- }
504
- }
505
- }
506
- }
507
- }
508
-
509
- if (!highestBalanceToken) {
510
- logger.console.log(
511
- "[refund] No tokens found at intent address, creating empty refund call",
512
- )
513
- return {
514
- to: refundToAddress,
515
- value: 0n,
516
- data: "0x" as `0x${string}`,
517
- gasLimit: 0n,
518
- delegateCall: false,
519
- onlyFallback: false,
520
- behaviorOnError: "revert",
521
- }
522
- } else if (highestBalanceToken.type === "native") {
523
- logger.console.log("[refund] Creating native token refund call:", {
524
- to: refundToAddress,
525
- value: highestBalanceToken.balance.toString(),
526
- balance: highestBalanceToken.balance.toString(),
527
- chainId: highestBalanceToken.chainId,
528
- })
529
- return {
530
- to: refundToAddress,
531
- value: highestBalanceToken.balance,
532
- data: "0x" as `0x${string}`,
533
- gasLimit: 0n,
534
- delegateCall: false,
535
- onlyFallback: false,
536
- behaviorOnError: "revert",
537
- }
538
- } else {
539
- // ERC20 token refund
540
- // For recovery operations, we still encode client-side
541
- const transferData = getERC20TransferData(
542
- refundToAddress,
543
- highestBalanceToken.balance,
544
- )
545
- logger.console.log("[refund] Creating ERC20 token refund call:", {
546
- to: highestBalanceToken.tokenAddress,
547
- value: "0",
548
- data: transferData,
549
- balance: highestBalanceToken.balance.toString(),
550
- decimals: highestBalanceToken.decimals,
551
- chainId: highestBalanceToken.chainId,
552
- recipient: refundToAddress,
553
- })
554
- // Validate token address is not zeroAddress
555
- if (
556
- !highestBalanceToken.tokenAddress ||
557
- Address.isEqual(
558
- Address.from(highestBalanceToken.tokenAddress),
559
- zeroAddress,
560
- )
561
- ) {
562
- throw new Error("ERC20 token address cannot be zero address")
563
- }
564
-
565
- return {
566
- to: Address.from(highestBalanceToken.tokenAddress),
567
- value: 0n,
568
- data: transferData as `0x${string}`,
569
- gasLimit: 0n,
570
- delegateCall: false,
571
- onlyFallback: false,
572
- behaviorOnError: "revert",
573
- }
574
- }
575
- }
576
-
577
- // ─── Shared helper types and functions (used by multiple hooks) ───
578
-
579
- interface SelectedIntentAddress {
580
- address: Address.Address
581
- chainId: number
582
- intentAddress: Address.Address
583
- tokenBalancesData: FlatTokenBalancesData | undefined
584
- isOrigin: boolean
585
- }
586
-
587
- function findHighestTokenUsdBalance(
588
- tokenBalancesData: FlatTokenBalancesData | undefined,
589
- ): number {
590
- if (!tokenBalancesData?.tokens) return 0
591
- let highest = 0
592
- for (const token of tokenBalancesData.tokens) {
593
- const balanceUsd = token.balanceUsd || 0
594
- if (balanceUsd > highest) highest = balanceUsd
595
- }
596
- return highest
597
- }
598
-
599
- function findHighestRawTokenBalance(
600
- tokenBalancesData: FlatTokenBalancesData | undefined,
601
- ): bigint {
602
- if (!tokenBalancesData?.tokens) return 0n
603
- let highest = 0n
604
- for (const token of tokenBalancesData.tokens) {
605
- const balance = BigInt(token.balance || "0")
606
- if (balance > highest) highest = balance
607
- }
608
- return highest
609
- }
610
-
611
- function selectIntentAddress(
612
- intentData: Intent,
613
- originBalances: FlatTokenBalancesData | undefined,
614
- destBalances: FlatTokenBalancesData | undefined,
615
- originAddr: Address.Address | null,
616
- destAddr: Address.Address | null,
617
- ): SelectedIntentAddress | null {
618
- const originHighestTokenUsd = findHighestTokenUsdBalance(originBalances)
619
- const destinationHighestTokenUsd = findHighestTokenUsdBalance(destBalances)
620
- const originHighestRawBalance = findHighestRawTokenBalance(originBalances)
621
- const destinationHighestRawBalance = findHighestRawTokenBalance(destBalances)
622
-
623
- let useDestination = false
624
- if (destAddr) {
625
- if (originHighestTokenUsd > 0 && destinationHighestTokenUsd > 0) {
626
- useDestination = destinationHighestTokenUsd > originHighestTokenUsd
627
- } else if (destinationHighestTokenUsd > 0 && originHighestTokenUsd === 0) {
628
- useDestination = true
629
- } else if (originHighestTokenUsd > 0 && destinationHighestTokenUsd === 0) {
630
- useDestination = false
631
- } else {
632
- useDestination = destinationHighestRawBalance > originHighestRawBalance
633
- }
634
- }
635
-
636
- const makeOriginResult = (): SelectedIntentAddress | null => {
637
- if (!intentData.originIntentAddress || !originAddr) return null
638
- return {
639
- address: originAddr,
640
- chainId: Number(intentData.originChainId || 0),
641
- intentAddress: Address.from(intentData.originIntentAddress),
642
- tokenBalancesData: originBalances,
643
- isOrigin: true,
644
- }
645
- }
646
-
647
- if (useDestination) {
648
- const chainId = intentData.destinationChainId
649
- if (!chainId || !intentData.destinationIntentAddress || !destAddr) {
650
- return makeOriginResult()
651
- }
652
- return {
653
- address: destAddr,
654
- chainId: Number(chainId),
655
- intentAddress: Address.from(intentData.destinationIntentAddress),
656
- tokenBalancesData: destBalances,
657
- isOrigin: false,
658
- }
659
- }
660
-
661
- return makeOriginResult()
662
- }
663
-
664
- function checkAnyIntentBalance(
665
- originBalances: FlatTokenBalancesData | undefined,
666
- destBalances: FlatTokenBalancesData | undefined,
667
- ): boolean {
668
- const hasBalance = (data: { tokens?: Token[] } | undefined): boolean => {
669
- if (!data?.tokens) return false
670
- for (const token of data.tokens) {
671
- if (isPositiveBigInt(token.balance || "0")) return true
672
- }
673
- return false
674
- }
675
- return hasBalance(originBalances) || hasBalance(destBalances)
676
- }
677
-
678
- function findRecoverToken(
679
- selected: SelectedIntentAddress | null,
680
- ): Token | null {
681
- if (!selected?.tokenBalancesData?.tokens) return null
682
- let highestBalanceToken: Token | null = null
683
- let highestBalance = 0n
684
- for (const token of selected.tokenBalancesData.tokens) {
685
- const balance = BigInt(token.balance || "0")
686
- if (balance > 0n && balance > highestBalance) {
687
- highestBalance = balance
688
- highestBalanceToken = token
689
- }
690
- }
691
- return highestBalanceToken
692
- }
693
-
694
- function mapTransactionCalls(intentData: Intent): IntentCalls[] {
695
- const allCalls: IntentCalls[] = []
696
- if (intentData.originCalls) {
697
- allCalls.push({
698
- chainId: intentData.originCalls.chainId,
699
- space: intentData.originCalls.space,
700
- nonce: intentData.originCalls.nonce,
701
- calls: intentData.originCalls.calls.map((call: TransactionCall) => ({
702
- to: call.to,
703
- value: call.value,
704
- data: call.data,
705
- gasLimit: call.gasLimit,
706
- delegateCall: call.delegateCall,
707
- onlyFallback: call.onlyFallback,
708
- behaviorOnError: call.behaviorOnError,
709
- })),
710
- })
711
- }
712
- if (
713
- intentData.destinationCalls &&
714
- intentData.destinationCalls.chainId !== intentData.originCalls?.chainId
715
- ) {
716
- allCalls.push({
717
- chainId: intentData.destinationCalls.chainId,
718
- space: intentData.destinationCalls.space,
719
- nonce: intentData.destinationCalls.nonce,
720
- calls: intentData.destinationCalls.calls.map((call: TransactionCall) => ({
721
- to: call.to,
722
- value: call.value,
723
- data: call.data,
724
- gasLimit: call.gasLimit,
725
- delegateCall: call.delegateCall,
726
- onlyFallback: call.onlyFallback,
727
- behaviorOnError: call.behaviorOnError,
728
- })),
729
- })
730
- }
731
- return allCalls
732
- }
733
-
734
- function filterCallsByChainId(
735
- allCalls: IntentCalls[],
736
- targetChainId: number,
737
- ): IntentCalls[] {
738
- return allCalls.filter((call) => {
739
- const callChainId =
740
- typeof call.chainId === "bigint"
741
- ? call.chainId
742
- : BigInt(String(call.chainId))
743
- return callChainId === BigInt(targetChainId)
744
- })
745
- }
746
-
747
- function validateRefundAddress(
748
- address: `0x${string}` | null,
749
- ): asserts address is `0x${string}` {
750
- if (!address) {
751
- throw new Error(
752
- "Refund address is required. Provide refundToAddress or connect a wallet with a valid address",
753
- )
754
- }
755
- if (Address.isEqual(address, zeroAddress)) {
756
- throw new Error("Refund address cannot be zero address")
757
- }
758
- }
759
-
760
- async function getRecoverStatusFromChain(params: {
761
- txHash: `0x${string}`
762
- chainId: number
763
- }): Promise<{ status: "success" | "fail" | "pending" }> {
764
- const { txHash, chainId } = params
765
- const publicClient = getChainRpcClient(chainId)
766
- try {
767
- const transaction = await publicClient.getTransaction({ hash: txHash })
768
- if (transaction) {
769
- try {
770
- const receipt = await publicClient.getTransactionReceipt({
771
- hash: txHash,
772
- })
773
- if (receipt.status === "reverted") return { status: "fail" }
774
- const guestModuleEvents = decodeGuestModuleEvents(receipt)
775
- if (guestModuleEvents.some((e) => e.type === "CallFailed"))
776
- return { status: "fail" }
777
- return { status: "success" }
778
- } catch {
779
- return { status: "pending" }
780
- }
781
- }
782
- } catch {
783
- try {
784
- const receipt = await publicClient.getTransactionReceipt({
785
- hash: txHash,
786
- })
787
- if (receipt.status === "reverted") return { status: "fail" }
788
- const guestModuleEvents = decodeGuestModuleEvents(receipt)
789
- if (guestModuleEvents.some((e) => e.type === "CallFailed"))
790
- return { status: "fail" }
791
- return { status: "success" }
792
- } catch {
793
- return { status: "pending" }
794
- }
795
- }
796
- return { status: "pending" }
797
- }
798
-
799
- function buildSelectedRecoveryTarget(selected: SelectedIntentAddress | null) {
800
- if (!selected) return null
801
- const chainInfo = getChainInfo(selected.chainId)
802
- return {
803
- address: selected.address,
804
- chainId: selected.chainId,
805
- chainName: chainInfo?.name || `Chain ${selected.chainId}`,
806
- isOrigin: selected.isOrigin,
807
- tokenBalancesData: selected.tokenBalancesData,
808
- }
809
- }
810
-
811
- /**
812
- * Builds the calls array for a specific intent address (origin or destination).
813
- * Used by getRecoverTx in multiple hooks.
814
- */
815
- function buildCallsForSelectedAddress(
816
- intentData: Intent,
817
- selected: SelectedIntentAddress,
818
- ): IntentCalls[] {
819
- const calls: IntentCalls[] = []
820
- if (selected.isOrigin && intentData.originCalls) {
821
- calls.push({
822
- chainId: intentData.originCalls.chainId,
823
- space: intentData.originCalls.space,
824
- nonce: intentData.originCalls.nonce,
825
- calls: intentData.originCalls.calls.map((call: TransactionCall) => ({
826
- to: call.to,
827
- value: call.value,
828
- data: call.data,
829
- gasLimit: call.gasLimit,
830
- delegateCall: call.delegateCall,
831
- onlyFallback: call.onlyFallback,
832
- behaviorOnError: call.behaviorOnError,
833
- })),
834
- })
835
- } else if (!selected.isOrigin && intentData.destinationCalls) {
836
- calls.push({
837
- chainId: intentData.destinationCalls.chainId,
838
- space: intentData.destinationCalls.space,
839
- nonce: intentData.destinationCalls.nonce,
840
- calls: intentData.destinationCalls.calls.map((call: TransactionCall) => ({
841
- to: call.to,
842
- value: call.value,
843
- data: call.data,
844
- gasLimit: call.gasLimit,
845
- delegateCall: call.delegateCall,
846
- onlyFallback: call.onlyFallback,
847
- behaviorOnError: call.behaviorOnError,
848
- })),
849
- })
850
- }
851
- return calls
852
- }
853
-
854
- /**
855
- * Builds a recover transaction from signature + payload using shared logic.
856
- */
857
- async function buildRecoverTxFromSignature(params: {
858
- trailsClient: TrailsClient
859
- keyMachineClient: KeyMachineClient
860
- intentData: Intent
861
- mainSigner: Address.Address
862
- selected: SelectedIntentAddress
863
- effectiveRefundAddress: `0x${string}`
864
- signature: string
865
- payload: Payload.Calls
866
- }): Promise<{
867
- to: `0x${string}`
868
- data: `0x${string}`
869
- chainId: number
870
- chain: Chain
871
- }> {
872
- const {
873
- trailsClient,
874
- keyMachineClient,
875
- intentData,
876
- mainSigner,
877
- selected,
878
- effectiveRefundAddress,
879
- signature,
880
- payload,
881
- } = params
882
- validateRefundAddress(effectiveRefundAddress)
883
-
884
- const calls = buildCallsForSelectedAddress(intentData, selected)
885
- if (calls.length === 0) {
886
- throw new Error("No calls found for the selected intent address")
887
- }
888
-
889
- const chainId = selected.chainId
890
- if (!chainId) {
891
- throw new Error("Chain ID not found for selected intent address")
892
- }
893
-
894
- const intentProtocol = getIntentProtocol(intentData)
895
- const checkpoint = Number(intentData.salt)
896
-
897
- const result = await buildRefundTransactionWithSignature({
898
- trailsClient,
899
- keyMachineClient,
900
- intentId: intentData.intentId,
901
- intentProtocol,
902
- checkpoint,
903
- mainSigner,
904
- calls,
905
- payload,
906
- chainId: Number(chainId),
907
- intentAddress: selected.intentAddress,
908
- signature,
909
- isOriginIntent: selected.isOrigin,
910
- })
911
-
912
- if (!result.to || Address.isEqual(result.to, zeroAddress)) {
913
- throw new Error("Refund transaction 'to' address cannot be zero address")
914
- }
915
-
916
- const chainInfo = getChainInfo(Number(chainId))
917
- if (!chainInfo) {
918
- throw new Error(`Chain info not found for chain ID: ${chainId}`)
919
- }
920
-
921
- return {
922
- to: result.to,
923
- data: result.data,
924
- chainId: Number(chainId),
925
- chain: chainInfo as Chain,
926
- }
927
- }
928
-
929
- // ─── End shared helpers ───
930
-
931
- export interface UseIntentRecoverParams {
932
- intentId: string | undefined
933
- walletClient: WalletClient | undefined
934
- refundToAddress?: `0x${string}`
935
- }
936
-
937
- export interface UseIntentRecoverWithBalancesParams {
938
- intent: Intent | null
939
- balancesByIntentAddress: {
940
- [account: string]: {
941
- tokenBalancesData: FlatTokenBalancesData | undefined
942
- isLoading: boolean
943
- error: Error | null
944
- }
945
- }
946
- walletClient: WalletClient | undefined
947
- refundToAddress?: `0x${string}`
948
- }
949
-
950
- /**
951
- * Optimized return type for useIntentRecoverWithBalances
952
- */
953
- export interface UseIntentRecoverWithBalancesReturn {
954
- intent: Intent | null
955
- hasIntentBalance: boolean
956
- recoverToken: Token | null
957
- selectedRecoveryTarget: {
958
- address: Address.Address
959
- chainId: number
960
- chainName: string
961
- isOrigin: boolean
962
- tokenBalancesData: FlatTokenBalancesData | undefined
963
- } | null
964
- refetchIntent: () => void
965
- signPayload: () => Promise<{
966
- signature: string
967
- payload: Payload.Calls
968
- refundCall: Payload.Call
969
- }>
970
- getRecoverTx: (params: {
971
- signedHash: string
972
- payload: Payload.Calls
973
- }) => Promise<{
974
- to: `0x${string}`
975
- data: `0x${string}`
976
- chainId: number
977
- chain: Chain
978
- }>
979
- recover: () => Promise<{
980
- txHash: `0x${string}`
981
- }>
982
- getRecoverStatus: (params: {
983
- txHash: `0x${string}`
984
- chainId: number
985
- }) => Promise<{
986
- status: "success" | "fail" | "pending"
987
- }>
988
- }
989
-
990
- export interface UseIntentRecoverReturn {
991
- intent: Intent | null
992
- isLoadingIntent: boolean
993
- isLoadingBalances: boolean
994
- intentError: Error | null
995
- balancesError: Error | null
996
- hasIntentBalance: boolean
997
- /** Token that will be recovered (the one with highest balance) */
998
- recoverToken: Token | null
999
- /** Information about which intent address will be recovered from */
1000
- selectedRecoveryTarget: {
1001
- address: Address.Address
1002
- chainId: number
1003
- chainName: string
1004
- isOrigin: boolean
1005
- tokenBalancesData: FlatTokenBalancesData | undefined
1006
- } | null
1007
- refetchIntent: () => void
1008
- signPayload: () => Promise<{
1009
- signature: string
1010
- payload: Payload.Calls
1011
- refundCall: Payload.Call
1012
- }>
1013
- getRecoverTx: (params: {
1014
- signedHash: string
1015
- payload: Payload.Calls
1016
- }) => Promise<{
1017
- to: `0x${string}`
1018
- data: `0x${string}`
1019
- chainId: number
1020
- chain: Chain
1021
- }>
1022
- recover: () => Promise<{
1023
- txHash: `0x${string}`
1024
- receipt: TransactionReceipt
1025
- chainId: number
1026
- }>
1027
- getRecoverStatus: (params: {
1028
- txHash: `0x${string}`
1029
- chainId: number
1030
- }) => Promise<{
1031
- status: "success" | "fail" | "pending"
1032
- }>
1033
- }
1034
-
1035
- export interface UseIntentRecoverWithAddressParams {
1036
- intentId: string | undefined
1037
- /** Signer for the recovery tx and default refund receiver */
1038
- walletAddress: `0x${string}` | undefined
1039
- /** Optional. If set, refund is sent here instead of walletAddress (signer stays walletAddress). */
1040
- refundToAddress?: `0x${string}`
1041
- }
1042
-
1043
- export interface UseIntentRecoverWithAddressReturn {
1044
- intent: Intent | null
1045
- isLoadingIntent: boolean
1046
- isLoadingBalances: boolean
1047
- intentError: Error | null
1048
- balancesError: Error | null
1049
- hasIntentBalance: boolean
1050
- recoverToken: Token | null
1051
- selectedRecoveryTarget: {
1052
- address: Address.Address
1053
- chainId: number
1054
- chainName: string
1055
- isOrigin: boolean
1056
- tokenBalancesData: FlatTokenBalancesData | undefined
1057
- } | null
1058
- refetchIntent: () => void
1059
- /** Returns payload and EIP-712 typed data for the app to sign (e.g. with embedded wallet). */
1060
- getDataToSign: () => Promise<{
1061
- payload: Payload.Calls
1062
- refundCall: Payload.Call
1063
- chainId: number
1064
- typedData: ReturnType<typeof Payload.toTyped>
1065
- }>
1066
- getRecoverTx: (params: {
1067
- signature: string
1068
- payload: Payload.Calls
1069
- }) => Promise<{
1070
- to: `0x${string}`
1071
- data: `0x${string}`
1072
- chainId: number
1073
- chain: Chain
1074
- }>
1075
- getRecoverStatus: (params: {
1076
- txHash: `0x${string}`
1077
- chainId: number
1078
- }) => Promise<{
1079
- status: "success" | "fail" | "pending"
1080
- }>
1081
- }
1082
-
1083
- /**
1084
- * Hook for building and signing recover transactions.
1085
- * Wraps useIntentRecoverWithAddress and adds walletClient-based signing + sending.
1086
- * @example
1087
- * ```tsx
1088
- * const { signPayload, getRecoverTx, recover } = useIntentRecover({
1089
- * intentId: "0x...",
1090
- * walletClient: walletClient,
1091
- * })
1092
- *
1093
- * // Option 1: Manual flow
1094
- * const signedHash = await signPayload()
1095
- * const recoverTx = await getRecoverTx({ signedHash })
1096
- * await walletClient.sendTransaction(recoverTx)
1097
- *
1098
- * // Option 2: Automatic flow (recommended)
1099
- * const { txHash, receipt, chainId } = await recover()
1100
- * const status = await getRecoverStatus({ txHash, chainId })
1101
- * ```
1102
- */
1103
- export function useIntentRecover({
1104
- intentId,
1105
- walletClient,
1106
- refundToAddress,
1107
- }: UseIntentRecoverParams): UseIntentRecoverReturn {
1108
- const trailsClient = useTrailsClient()
1109
- const walletAddress = walletClient?.account?.address as
1110
- | `0x${string}`
1111
- | undefined
1112
-
1113
- const inner = useIntentRecoverWithAddress({
1114
- intentId,
1115
- walletAddress,
1116
- refundToAddress: refundToAddress || walletAddress,
1117
- })
1118
-
1119
- const signPayload = useCallback(async (): Promise<{
1120
- signature: string
1121
- payload: Payload.Calls
1122
- refundCall: Payload.Call
1123
- }> => {
1124
- if (!walletClient || !walletClient.account) {
1125
- throw new Error("Intent data and wallet client with account required")
1126
- }
1127
-
1128
- await checkProviderHealth(walletClient)
1129
-
1130
- const { payload, refundCall, chainId, typedData } =
1131
- await inner.getDataToSign()
1132
-
1133
- await attemptSwitchChain({
1134
- walletClient,
1135
- desiredChainId: Number(chainId),
1136
- })
1137
-
1138
- await checkProviderHealth(walletClient)
1139
-
1140
- const signature = await signWithTimeout(
1141
- walletClient.signTypedData({
1142
- account: walletClient.account,
1143
- ...typedData,
1144
- }),
1145
- "Recovery signature",
1146
- )
1147
-
1148
- return { signature, payload, refundCall }
1149
- }, [walletClient, inner])
1150
-
1151
- const getRecoverTx = useCallback(
1152
- async (params: {
1153
- signedHash: string
1154
- payload: Payload.Calls
1155
- }): Promise<{
1156
- to: `0x${string}`
1157
- data: `0x${string}`
1158
- chainId: number
1159
- chain: Chain
1160
- }> =>
1161
- inner.getRecoverTx({
1162
- signature: params.signedHash,
1163
- payload: params.payload,
1164
- }),
1165
- [inner],
1166
- )
1167
-
1168
- const recover = useCallback(async (): Promise<{
1169
- txHash: `0x${string}`
1170
- receipt: TransactionReceipt
1171
- chainId: number
1172
- }> => {
1173
- if (!walletClient || !walletClient.account) {
1174
- throw new Error("Intent data and wallet client with account required")
1175
- }
1176
-
1177
- const { signature, payload } = await signPayload()
1178
-
1179
- const recoverTx = await getRecoverTx({
1180
- signedHash: signature,
1181
- payload,
1182
- })
1183
-
1184
- await attemptSwitchChain({
1185
- walletClient,
1186
- desiredChainId: recoverTx.chainId,
1187
- })
1188
-
1189
- const txHash = await sendWalletTransaction(walletClient, {
1190
- account: walletClient.account,
1191
- to: recoverTx.to,
1192
- data: recoverTx.data,
1193
- chain: recoverTx.chain,
1194
- })
1195
-
1196
- const publicClient = getChainRpcClient(recoverTx.chainId)
1197
- const receipt = await publicClient.waitForTransactionReceipt({
1198
- hash: txHash as `0x${string}`,
1199
- })
1200
-
1201
- if (intentId && trailsClient) {
1202
- try {
1203
- await abortIntent(trailsClient, intentId, recoverTx.chainId, txHash)
1204
- } catch (error) {
1205
- logger.console.error(
1206
- "[recover] Failed to abort intent after recovery:",
1207
- {
1208
- error: error instanceof Error ? error.message : String(error),
1209
- intentId,
1210
- chainId: recoverTx.chainId,
1211
- txHash,
1212
- },
1213
- )
1214
- }
1215
- }
1216
-
1217
- return {
1218
- txHash: txHash as `0x${string}`,
1219
- receipt,
1220
- chainId: recoverTx.chainId,
1221
- }
1222
- }, [signPayload, getRecoverTx, walletClient, intentId, trailsClient])
1223
-
1224
- return {
1225
- ...inner,
1226
- signPayload,
1227
- getRecoverTx,
1228
- recover,
1229
- }
1230
- }
1231
-
1232
- /**
1233
- * Recovery hook for apps that handle signing externally (e.g. embedded wallets)
1234
- * Use getDataToSign to get EIP-712 data, sign with walletAddress, then getRecoverTx(signature, payload).
1235
- * Refund goes to refundToAddress if provided, otherwise to walletAddress.
1236
- * @example
1237
- * ```tsx
1238
- * const { getDataToSign, getRecoverTx } = useIntentRecoverWithAddress({
1239
- * intentId: "0x...",
1240
- * walletAddress: "0x...",
1241
- * refundToAddress: "0x...", // optional, allows for different refund address than signer
1242
- * })
1243
- * const { payload, typedData, chainId } = await getDataToSign()
1244
- * const signature = await myCustomWallet.signTypedData({ account: walletAddress, ...typedData })
1245
- * const recoverTx = await getRecoverTx({ signature, payload })
1246
- * const hash = await myCustomWallet.sendTransaction({ to: recoverTx.to, data: recoverTx.data, chain: recoverTx.chain })
1247
- * ```
1248
- */
1249
- export function useIntentRecoverWithAddress({
1250
- intentId,
1251
- walletAddress,
1252
- refundToAddress,
1253
- }: UseIntentRecoverWithAddressParams): UseIntentRecoverWithAddressReturn {
1254
- const {
1255
- intent: intentData,
1256
- isLoading: isLoadingIntent,
1257
- error: intentError,
1258
- refetch: refetchIntent,
1259
- } = useGetIntent({
1260
- intentId,
1261
- enabled: !!intentId,
1262
- })
1263
-
1264
- const trailsClient = useTrailsClient()
1265
- const keyMachineClient = useKeyMachineClient()
1266
- const originIntentAddressForBalances = intentData?.originIntentAddress
1267
- ? Address.from(intentData.originIntentAddress)
1268
- : null
1269
- const destinationIntentAddressForBalances =
1270
- intentData?.destinationIntentAddress
1271
- ? Address.from(intentData.destinationIntentAddress)
1272
- : null
1273
-
1274
- const {
1275
- balancesByAccount: balancesByIntentAddress,
1276
- isLoading: isLoadingBalances,
1277
- error: balanceError,
1278
- } = useTokenBalancesForMultipleAccounts(
1279
- [originIntentAddressForBalances, destinationIntentAddressForBalances],
1280
- {
1281
- refetchInterval: WIDGET_REFRESH_INTERVAL,
1282
- },
1283
- )
1284
-
1285
- const originTokenBalancesData = originIntentAddressForBalances
1286
- ? balancesByIntentAddress[normalizeAddress(originIntentAddressForBalances)]
1287
- ?.tokenBalancesData
1288
- : undefined
1289
- const destinationTokenBalancesData = destinationIntentAddressForBalances
1290
- ? balancesByIntentAddress[
1291
- normalizeAddress(destinationIntentAddressForBalances)
1292
- ]?.tokenBalancesData
1293
- : undefined
1294
- const balancesError = balanceError
1295
-
1296
- const selectedIntentAddress = useMemo<SelectedIntentAddress | null>(
1297
- () =>
1298
- intentData
1299
- ? selectIntentAddress(
1300
- intentData,
1301
- originTokenBalancesData,
1302
- destinationTokenBalancesData,
1303
- originIntentAddressForBalances,
1304
- destinationIntentAddressForBalances,
1305
- )
1306
- : null,
1307
- [
1308
- intentData,
1309
- originTokenBalancesData,
1310
- destinationTokenBalancesData,
1311
- originIntentAddressForBalances,
1312
- destinationIntentAddressForBalances,
1313
- ],
1314
- )
1315
-
1316
- const hasIntentBalance = useMemo<boolean>(
1317
- () =>
1318
- checkAnyIntentBalance(
1319
- originTokenBalancesData,
1320
- destinationTokenBalancesData,
1321
- ),
1322
- [originTokenBalancesData, destinationTokenBalancesData],
1323
- )
1324
-
1325
- const recoverToken = useMemo<Token | null>(
1326
- () => findRecoverToken(selectedIntentAddress),
1327
- [selectedIntentAddress],
1328
- )
1329
-
1330
- const effectiveRefundAddress = useMemo<`0x${string}` | null>(() => {
1331
- const address = refundToAddress ?? walletAddress
1332
- if (!address || Address.isEqual(address, zeroAddress)) return null
1333
- return address
1334
- }, [refundToAddress, walletAddress])
1335
-
1336
- const getDataToSign = useCallback(async (): Promise<{
1337
- payload: Payload.Calls
1338
- refundCall: Payload.Call
1339
- chainId: number
1340
- typedData: ReturnType<typeof Payload.toTyped>
1341
- }> => {
1342
- if (!intentData) {
1343
- throw new Error("Intent data required")
1344
- }
1345
- if (!effectiveRefundAddress) {
1346
- throw new Error(
1347
- "Refund address required. Provide refundToAddress or walletAddress",
1348
- )
1349
- }
1350
- if (Address.isEqual(effectiveRefundAddress, zeroAddress)) {
1351
- throw new Error("Refund address cannot be zero address")
1352
- }
1353
- if (!selectedIntentAddress) {
1354
- throw new Error("No intent address selected for recovery")
1355
- }
1356
- const allCalls = mapTransactionCalls(intentData)
1357
- const calls = filterCallsByChainId(allCalls, selectedIntentAddress.chainId)
1358
- if (calls.length === 0) {
1359
- throw new Error("No calls found for the selected intent address")
1360
- }
1361
- const refundCall = determineRefundCall(
1362
- selectedIntentAddress.tokenBalancesData,
1363
- effectiveRefundAddress,
1364
- )
1365
- const chainId = selectedIntentAddress.chainId
1366
- if (!chainId) {
1367
- throw new Error("Chain ID not found for selected intent address")
1368
- }
1369
- const payload = createRefundPayload(
1370
- refundCall,
1371
- BigInt(calls[0]?.nonce ?? 0),
1372
- )
1373
- const typedData = Payload.toTyped(
1374
- selectedIntentAddress.intentAddress,
1375
- chainId,
1376
- payload,
1377
- )
1378
- return { payload, refundCall, chainId, typedData }
1379
- }, [intentData, selectedIntentAddress, effectiveRefundAddress])
1380
-
1381
- const getRecoverTx = useCallback(
1382
- async (params: {
1383
- signature: string
1384
- payload: Payload.Calls
1385
- }): Promise<{
1386
- to: `0x${string}`
1387
- data: `0x${string}`
1388
- chainId: number
1389
- chain: Chain
1390
- }> => {
1391
- if (!intentData) {
1392
- throw new Error("Intent data required")
1393
- }
1394
- if (!walletAddress) {
1395
- throw new Error("walletAddress is required")
1396
- }
1397
- if (!selectedIntentAddress) {
1398
- throw new Error("No intent address selected for recovery")
1399
- }
1400
- return buildRecoverTxFromSignature({
1401
- trailsClient,
1402
- keyMachineClient,
1403
- intentData,
1404
- mainSigner: Address.from(walletAddress),
1405
- selected: selectedIntentAddress,
1406
- effectiveRefundAddress: effectiveRefundAddress!,
1407
- signature: params.signature,
1408
- payload: params.payload,
1409
- })
1410
- },
1411
- [
1412
- intentData,
1413
- walletAddress,
1414
- selectedIntentAddress,
1415
- effectiveRefundAddress,
1416
- trailsClient,
1417
- keyMachineClient,
1418
- ],
1419
- )
1420
-
1421
- const getRecoverStatus = useCallback(
1422
- (params: { txHash: `0x${string}`; chainId: number }) =>
1423
- getRecoverStatusFromChain(params),
1424
- [],
1425
- )
1426
-
1427
- const selectedRecoveryTarget = useMemo(
1428
- () => buildSelectedRecoveryTarget(selectedIntentAddress),
1429
- [selectedIntentAddress],
1430
- )
1431
-
1432
- return {
1433
- intent: intentData,
1434
- isLoadingIntent,
1435
- isLoadingBalances,
1436
- intentError: intentError as Error | null,
1437
- balancesError: balancesError as Error | null,
1438
- hasIntentBalance,
1439
- recoverToken,
1440
- selectedRecoveryTarget,
1441
- refetchIntent,
1442
- getDataToSign,
1443
- getRecoverTx,
1444
- getRecoverStatus,
1445
- }
1446
- }
1447
-
1448
- /**
1449
- * Optimized hook for building and signing recover transactions with pre-fetched data
1450
- * @example
1451
- * ```tsx
1452
- * const { hasIntentBalance, recoverToken, recover } = useIntentRecoverWithBalances({
1453
- * intent: intentData,
1454
- * balancesByIntentAddress: balancesMap,
1455
- * walletClient: walletClient,
1456
- * })
1457
- * ```
1458
- */
1459
- export function useIntentRecoverWithBalances({
1460
- intent: intentData,
1461
- balancesByIntentAddress,
1462
- walletClient,
1463
- refundToAddress,
1464
- }: UseIntentRecoverWithBalancesParams): UseIntentRecoverWithBalancesReturn {
1465
- const trailsClient = useTrailsClient()
1466
- const keyMachineClient = useKeyMachineClient()
1467
-
1468
- const originTokenBalancesData = intentData?.originIntentAddress
1469
- ? balancesByIntentAddress[normalizeAddress(intentData.originIntentAddress)]
1470
- ?.tokenBalancesData
1471
- : undefined
1472
-
1473
- const destinationTokenBalancesData = intentData?.destinationIntentAddress
1474
- ? balancesByIntentAddress[
1475
- normalizeAddress(intentData.destinationIntentAddress)
1476
- ]?.tokenBalancesData
1477
- : undefined
1478
-
1479
- const originIntentAddressForBalances = intentData?.originIntentAddress
1480
- ? Address.from(intentData.originIntentAddress)
1481
- : null
1482
-
1483
- const destinationIntentAddressForBalances =
1484
- intentData?.destinationIntentAddress
1485
- ? Address.from(intentData.destinationIntentAddress)
1486
- : null
1487
-
1488
- const selectedIntentAddress = useMemo<SelectedIntentAddress | null>(
1489
- () =>
1490
- intentData
1491
- ? selectIntentAddress(
1492
- intentData,
1493
- originTokenBalancesData,
1494
- destinationTokenBalancesData,
1495
- originIntentAddressForBalances,
1496
- destinationIntentAddressForBalances,
1497
- )
1498
- : null,
1499
- [
1500
- intentData,
1501
- originTokenBalancesData,
1502
- destinationTokenBalancesData,
1503
- originIntentAddressForBalances,
1504
- destinationIntentAddressForBalances,
1505
- ],
1506
- )
1507
-
1508
- const hasIntentBalance = useMemo<boolean>(
1509
- () =>
1510
- checkAnyIntentBalance(
1511
- originTokenBalancesData,
1512
- destinationTokenBalancesData,
1513
- ),
1514
- [originTokenBalancesData, destinationTokenBalancesData],
1515
- )
1516
-
1517
- const recoverToken = useMemo<Token | null>(
1518
- () => findRecoverToken(selectedIntentAddress),
1519
- [selectedIntentAddress],
1520
- )
1521
-
1522
- // Get refund address
1523
- const effectiveRefundAddress = useMemo<`0x${string}` | null>(() => {
1524
- const address =
1525
- refundToAddress || (walletClient?.account?.address as `0x${string}`)
1526
- if (!address || Address.isEqual(address, zeroAddress)) {
1527
- return null
1528
- }
1529
- return address
1530
- }, [refundToAddress, walletClient?.account?.address])
1531
-
1532
- const signPayloadCallback = useCallback(async (): Promise<{
1533
- signature: string
1534
- payload: Payload.Calls
1535
- refundCall: Payload.Call
1536
- }> => {
1537
- if (!intentData || !walletClient || !walletClient.account) {
1538
- throw new Error("Intent data and wallet client with account required")
1539
- }
1540
-
1541
- await checkProviderHealth(walletClient)
1542
- validateRefundAddress(effectiveRefundAddress)
1543
-
1544
- if (!selectedIntentAddress) {
1545
- throw new Error("No intent address selected for recovery")
1546
- }
1547
-
1548
- const allCalls = mapTransactionCalls(intentData)
1549
- const calls = filterCallsByChainId(allCalls, selectedIntentAddress.chainId)
1550
-
1551
- if (calls.length === 0) {
1552
- throw new Error("No calls found for the selected intent address")
1553
- }
1554
-
1555
- const refundCall = determineRefundCall(
1556
- selectedIntentAddress.tokenBalancesData,
1557
- effectiveRefundAddress,
1558
- )
1559
-
1560
- const chainId = selectedIntentAddress.chainId
1561
- if (!chainId) {
1562
- throw new Error("Chain ID not found for selected intent address")
1563
- }
1564
-
1565
- await attemptSwitchChain({
1566
- walletClient,
1567
- desiredChainId: Number(chainId),
1568
- })
1569
-
1570
- const intentAddress = selectedIntentAddress.intentAddress
1571
- const payload = createRefundPayload(
1572
- refundCall,
1573
- BigInt(calls[0]?.nonce ?? 0),
1574
- )
1575
-
1576
- await checkProviderHealth(walletClient)
1577
-
1578
- const typedData = Payload.toTyped(intentAddress, chainId, payload)
1579
-
1580
- const signature = await signWithTimeout(
1581
- walletClient.signTypedData({
1582
- account: walletClient.account,
1583
- ...typedData,
1584
- }),
1585
- "Recovery signature",
1586
- )
1587
-
1588
- return {
1589
- signature,
1590
- payload,
1591
- refundCall,
1592
- }
1593
- }, [intentData, walletClient, selectedIntentAddress, effectiveRefundAddress])
1594
-
1595
- const signPayload = signPayloadCallback
1596
-
1597
- const getRecoverTx = useCallback(
1598
- async (params: {
1599
- signedHash: string
1600
- payload: Payload.Calls
1601
- }): Promise<{
1602
- to: `0x${string}`
1603
- data: `0x${string}`
1604
- chainId: number
1605
- chain: Chain
1606
- }> => {
1607
- if (!intentData || !walletClient?.account) {
1608
- throw new Error("Intent data and wallet client with account required")
1609
- }
1610
- if (!selectedIntentAddress) {
1611
- throw new Error("No intent address selected for recovery")
1612
- }
1613
-
1614
- const rawIntentProtocol = (
1615
- intentData as {
1616
- intentProtocol?: string
1617
- intentProtocolVersion?: string
1618
- }
1619
- ).intentProtocol
1620
- const rawIntentProtocolVersion = (
1621
- intentData as {
1622
- intentProtocol?: string
1623
- intentProtocolVersion?: string
1624
- }
1625
- ).intentProtocolVersion
1626
-
1627
- if (!rawIntentProtocol && !rawIntentProtocolVersion) {
1628
- logger.console.log(
1629
- "[recover] Intent configuration version not found, using V1",
1630
- )
1631
- }
1632
-
1633
- return buildRecoverTxFromSignature({
1634
- trailsClient,
1635
- keyMachineClient,
1636
- intentData,
1637
- mainSigner: Address.from(walletClient.account.address),
1638
- selected: selectedIntentAddress,
1639
- effectiveRefundAddress: effectiveRefundAddress!,
1640
- signature: params.signedHash,
1641
- payload: params.payload,
1642
- })
1643
- },
1644
- [
1645
- intentData,
1646
- walletClient,
1647
- selectedIntentAddress,
1648
- effectiveRefundAddress,
1649
- trailsClient,
1650
- keyMachineClient,
1651
- ],
1652
- )
1653
-
1654
- const recover = useCallback(async (): Promise<{
1655
- txHash: `0x${string}`
1656
- }> => {
1657
- if (!walletClient || !walletClient.account) {
1658
- throw new Error("Wallet client with account is required for recovery")
1659
- }
1660
- if (!intentData) {
1661
- throw new Error("Intent data is required for recovery")
1662
- }
1663
-
1664
- const { signature, payload } = await signPayload()
1665
- const recoverTx = await getRecoverTx({
1666
- signedHash: signature,
1667
- payload,
1668
- })
1669
-
1670
- await attemptSwitchChain({
1671
- walletClient,
1672
- desiredChainId: Number(recoverTx.chainId),
1673
- })
1674
-
1675
- const txHash = await sendWalletTransaction(walletClient, {
1676
- account: walletClient.account,
1677
- to: recoverTx.to,
1678
- data: recoverTx.data,
1679
- chain: recoverTx.chain,
1680
- })
1681
-
1682
- const publicClient = getChainRpcClient(recoverTx.chainId)
1683
- await publicClient.waitForTransactionReceipt({
1684
- hash: txHash,
1685
- })
1686
-
1687
- if (intentData.intentId && trailsClient) {
1688
- try {
1689
- await abortIntent(
1690
- trailsClient,
1691
- intentData.intentId,
1692
- recoverTx.chainId,
1693
- txHash,
1694
- )
1695
- } catch (error) {
1696
- logger.console.warn(
1697
- "[recover] Failed to abort intent after recovery (non-fatal):",
1698
- error,
1699
- )
1700
- }
1701
- }
1702
-
1703
- return { txHash }
1704
- }, [walletClient, intentData, signPayload, getRecoverTx, trailsClient])
1705
-
1706
- const getRecoverStatus = useCallback(
1707
- (params: { txHash: `0x${string}`; chainId: number }) =>
1708
- getRecoverStatusFromChain(params),
1709
- [],
1710
- )
1711
-
1712
- const selectedRecoveryTarget = useMemo(
1713
- () => buildSelectedRecoveryTarget(selectedIntentAddress),
1714
- [selectedIntentAddress],
1715
- )
1716
-
1717
- return {
1718
- intent: intentData,
1719
- hasIntentBalance,
1720
- recoverToken,
1721
- selectedRecoveryTarget,
1722
- refetchIntent: () => {}, // No-op since intent is passed in
1723
- signPayload,
1724
- getRecoverTx,
1725
- recover,
1726
- getRecoverStatus,
1727
- }
1728
- }