0xtrails 0.2.5 → 0.3.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 (267) hide show
  1. package/dist/aave.d.ts +2 -0
  2. package/dist/aave.d.ts.map +1 -1
  3. package/dist/abortController.d.ts +8 -0
  4. package/dist/abortController.d.ts.map +1 -0
  5. package/dist/{ccip-CXlshvBY.js → ccip-BMB3uDZt.js} +1 -1
  6. package/dist/config.d.ts +0 -5
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/constants.d.ts +4 -4
  9. package/dist/constants.d.ts.map +1 -1
  10. package/dist/error.d.ts +4 -1
  11. package/dist/error.d.ts.map +1 -1
  12. package/dist/fees.d.ts +19 -0
  13. package/dist/fees.d.ts.map +1 -0
  14. package/dist/{index-_QuyGrjU.js → index-QXPUrZVv.js} +48719 -50852
  15. package/dist/index.d.ts +9 -8
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +811 -784
  18. package/dist/intentReceiptMonitor.d.ts +24 -0
  19. package/dist/intentReceiptMonitor.d.ts.map +1 -0
  20. package/dist/intentReceiptPoller.d.ts +69 -0
  21. package/dist/intentReceiptPoller.d.ts.map +1 -0
  22. package/dist/intents.d.ts +15 -11
  23. package/dist/intents.d.ts.map +1 -1
  24. package/dist/morpho.d.ts +6 -5
  25. package/dist/morpho.d.ts.map +1 -1
  26. package/dist/mutations.d.ts +16 -0
  27. package/dist/mutations.d.ts.map +1 -0
  28. package/dist/preconditions.d.ts +5 -4
  29. package/dist/preconditions.d.ts.map +1 -1
  30. package/dist/prepareSend.d.ts +7 -258
  31. package/dist/prepareSend.d.ts.map +1 -1
  32. package/dist/prices.d.ts +9 -6
  33. package/dist/prices.d.ts.map +1 -1
  34. package/dist/sequenceWallet.d.ts +3 -16
  35. package/dist/sequenceWallet.d.ts.map +1 -1
  36. package/dist/tokenBalances.d.ts +17 -13
  37. package/dist/tokenBalances.d.ts.map +1 -1
  38. package/dist/trails.d.ts +24 -40
  39. package/dist/trails.d.ts.map +1 -1
  40. package/dist/transactionIntent/constants.d.ts +7 -0
  41. package/dist/transactionIntent/constants.d.ts.map +1 -0
  42. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +44 -0
  43. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -0
  44. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +30 -0
  45. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -0
  46. package/dist/transactionIntent/deposits/index.d.ts +4 -0
  47. package/dist/transactionIntent/deposits/index.d.ts.map +1 -0
  48. package/dist/transactionIntent/deposits/standardDeposit.d.ts +30 -0
  49. package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -0
  50. package/dist/transactionIntent/execution/index.d.ts +2 -0
  51. package/dist/transactionIntent/execution/index.d.ts.map +1 -0
  52. package/dist/transactionIntent/execution/transactionState.d.ts +5 -0
  53. package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -0
  54. package/dist/transactionIntent/handlers/crossChain.d.ts +82 -0
  55. package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -0
  56. package/dist/transactionIntent/handlers/index.d.ts +4 -0
  57. package/dist/transactionIntent/handlers/index.d.ts.map +1 -0
  58. package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts +62 -0
  59. package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts.map +1 -0
  60. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +72 -0
  61. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -0
  62. package/dist/transactionIntent/index.d.ts +9 -0
  63. package/dist/transactionIntent/index.d.ts.map +1 -0
  64. package/dist/transactionIntent/quote/feeExtractors.d.ts +17 -0
  65. package/dist/transactionIntent/quote/feeExtractors.d.ts.map +1 -0
  66. package/dist/transactionIntent/quote/index.d.ts +4 -0
  67. package/dist/transactionIntent/quote/index.d.ts.map +1 -0
  68. package/dist/transactionIntent/quote/normalizeQuote.d.ts +34 -0
  69. package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -0
  70. package/dist/transactionIntent/quote/quoteHelpers.d.ts +5 -0
  71. package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -0
  72. package/dist/transactionIntent/types.d.ts +131 -0
  73. package/dist/transactionIntent/types.d.ts.map +1 -0
  74. package/dist/transactionIntent/utils/balanceChecker.d.ts +18 -0
  75. package/dist/transactionIntent/utils/balanceChecker.d.ts.map +1 -0
  76. package/dist/transactionIntent/utils/index.d.ts +4 -0
  77. package/dist/transactionIntent/utils/index.d.ts.map +1 -0
  78. package/dist/transactionIntent/utils/lifiHelpers.d.ts +10 -0
  79. package/dist/transactionIntent/utils/lifiHelpers.d.ts.map +1 -0
  80. package/dist/transactionIntent/utils/testnetHelpers.d.ts +3 -0
  81. package/dist/transactionIntent/utils/testnetHelpers.d.ts.map +1 -0
  82. package/dist/transactionIntent/validators.d.ts +6 -0
  83. package/dist/transactionIntent/validators.d.ts.map +1 -0
  84. package/dist/transactions.d.ts +6 -3
  85. package/dist/transactions.d.ts.map +1 -1
  86. package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts +4 -0
  87. package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts.map +1 -0
  88. package/dist/widget/components/AccountSettings.d.ts.map +1 -1
  89. package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
  90. package/dist/widget/components/ClassicSwap.d.ts +2 -3
  91. package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
  92. package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
  93. package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
  94. package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
  95. package/dist/widget/components/DynamicInputStyles.d.ts +18 -0
  96. package/dist/widget/components/DynamicInputStyles.d.ts.map +1 -0
  97. package/dist/widget/components/DynamicSizeInputField.d.ts +13 -0
  98. package/dist/widget/components/DynamicSizeInputField.d.ts.map +1 -0
  99. package/dist/widget/components/Earn.d.ts +2 -3
  100. package/dist/widget/components/Earn.d.ts.map +1 -1
  101. package/dist/widget/components/ErrorAnimationIcon.d.ts +2 -0
  102. package/dist/widget/components/ErrorAnimationIcon.d.ts.map +1 -0
  103. package/dist/widget/components/FeeBreakdown.d.ts +9 -0
  104. package/dist/widget/components/FeeBreakdown.d.ts.map +1 -0
  105. package/dist/widget/components/FeeOptions.d.ts +5 -13
  106. package/dist/widget/components/FeeOptions.d.ts.map +1 -1
  107. package/dist/widget/components/Fund.d.ts +2 -3
  108. package/dist/widget/components/Fund.d.ts.map +1 -1
  109. package/dist/widget/components/FundMethods.d.ts.map +1 -1
  110. package/dist/widget/components/FundSwap.d.ts +2 -3
  111. package/dist/widget/components/FundSwap.d.ts.map +1 -1
  112. package/dist/widget/components/FundingMethodSelectorButton.d.ts.map +1 -1
  113. package/dist/widget/components/Identicon.d.ts.map +1 -1
  114. package/dist/widget/components/MeshConnectExchanges.d.ts +0 -3
  115. package/dist/widget/components/MeshConnectExchanges.d.ts.map +1 -1
  116. package/dist/widget/components/Modal.d.ts.map +1 -1
  117. package/dist/widget/components/Pay.d.ts +2 -3
  118. package/dist/widget/components/Pay.d.ts.map +1 -1
  119. package/dist/widget/components/PoolDeposit.d.ts +3 -3
  120. package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
  121. package/dist/widget/components/PoolWithdraw.d.ts +3 -20
  122. package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
  123. package/dist/widget/components/QuoteDetails.d.ts +2 -0
  124. package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
  125. package/dist/widget/components/Receipt.d.ts.map +1 -1
  126. package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -1
  127. package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
  128. package/dist/widget/components/Swap.d.ts +2 -3
  129. package/dist/widget/components/Swap.d.ts.map +1 -1
  130. package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
  131. package/dist/widget/components/TokenDisplayNonSelectable.d.ts +11 -0
  132. package/dist/widget/components/TokenDisplayNonSelectable.d.ts.map +1 -0
  133. package/dist/widget/components/TokenSelector.d.ts.map +1 -1
  134. package/dist/widget/components/TokenSelectorButton.d.ts.map +1 -1
  135. package/dist/widget/components/Tooltip.d.ts +9 -0
  136. package/dist/widget/components/Tooltip.d.ts.map +1 -0
  137. package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
  138. package/dist/widget/components/WaasFeeOptions.d.ts +1 -0
  139. package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -1
  140. package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
  141. package/dist/widget/components/WalletConnect.d.ts.map +1 -1
  142. package/dist/widget/css/compiled.css +2 -2
  143. package/dist/widget/hooks/useCheckout.d.ts +17 -4
  144. package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
  145. package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
  146. package/dist/widget/hooks/useQuote.d.ts +82 -0
  147. package/dist/widget/hooks/useQuote.d.ts.map +1 -0
  148. package/dist/widget/hooks/useSelectedFeeToken.d.ts +1 -0
  149. package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +1 -1
  150. package/dist/widget/hooks/useSendForm.d.ts +5 -6
  151. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  152. package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
  153. package/dist/widget/hooks/useWalletConnectionContext.d.ts +25 -0
  154. package/dist/widget/hooks/useWalletConnectionContext.d.ts.map +1 -0
  155. package/dist/widget/index.js +2 -2
  156. package/dist/widget/widget.d.ts +17 -7
  157. package/dist/widget/widget.d.ts.map +1 -1
  158. package/package.json +19 -21
  159. package/src/aave.ts +54 -1
  160. package/src/abortController.ts +35 -0
  161. package/src/config.ts +57 -58
  162. package/src/constants.ts +11 -9
  163. package/src/error.ts +21 -3
  164. package/src/fees.ts +210 -0
  165. package/src/index.ts +35 -13
  166. package/src/intentReceiptMonitor.ts +102 -0
  167. package/src/intentReceiptPoller.ts +299 -0
  168. package/src/intents.ts +205 -171
  169. package/src/morpho.ts +58 -9
  170. package/src/mutations.ts +129 -0
  171. package/src/preconditions.ts +16 -21
  172. package/src/prepareSend.ts +92 -4699
  173. package/src/prices.ts +26 -22
  174. package/src/relaySdk.ts +2 -2
  175. package/src/sequenceWallet.ts +6 -73
  176. package/src/tokenBalances.ts +175 -69
  177. package/src/trails.ts +230 -722
  178. package/src/transactionIntent/constants.ts +11 -0
  179. package/src/transactionIntent/deposits/depositOrchestrator.ts +210 -0
  180. package/src/transactionIntent/deposits/gaslessDeposit.ts +588 -0
  181. package/src/transactionIntent/deposits/index.ts +3 -0
  182. package/src/transactionIntent/deposits/standardDeposit.ts +379 -0
  183. package/src/transactionIntent/execution/index.ts +1 -0
  184. package/src/transactionIntent/execution/transactionState.ts +35 -0
  185. package/src/transactionIntent/handlers/crossChain.ts +1707 -0
  186. package/src/transactionIntent/handlers/index.ts +3 -0
  187. package/src/transactionIntent/handlers/sameChainDifferentToken.ts +323 -0
  188. package/src/transactionIntent/handlers/sameChainSameToken.ts +712 -0
  189. package/src/transactionIntent/index.ts +9 -0
  190. package/src/transactionIntent/quote/feeExtractors.ts +81 -0
  191. package/src/transactionIntent/quote/index.ts +3 -0
  192. package/src/transactionIntent/quote/normalizeQuote.ts +367 -0
  193. package/src/transactionIntent/quote/quoteHelpers.ts +53 -0
  194. package/src/transactionIntent/types.ts +157 -0
  195. package/src/transactionIntent/utils/balanceChecker.ts +96 -0
  196. package/src/transactionIntent/utils/index.ts +3 -0
  197. package/src/transactionIntent/utils/lifiHelpers.ts +68 -0
  198. package/src/transactionIntent/utils/testnetHelpers.ts +10 -0
  199. package/src/transactionIntent/validators.ts +57 -0
  200. package/src/transactions.ts +98 -71
  201. package/src/widget/compiled.css +2 -2
  202. package/src/widget/components/AccountIntentTransactionHistory.tsx +36 -36
  203. package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +22 -0
  204. package/src/widget/components/AccountSettings.tsx +70 -41
  205. package/src/widget/components/ChainFilterDropdown.tsx +24 -3
  206. package/src/widget/components/ClassicSwap.tsx +44 -107
  207. package/src/widget/components/ConfigDisplay.tsx +0 -11
  208. package/src/widget/components/ConnectWallet.tsx +4 -1
  209. package/src/widget/components/ConnectedWallets.tsx +51 -25
  210. package/src/widget/components/DynamicInputStyles.tsx +76 -0
  211. package/src/widget/components/DynamicSizeInputField.tsx +109 -0
  212. package/src/widget/components/Earn.tsx +34 -45
  213. package/src/widget/components/ErrorAnimationIcon.tsx +130 -0
  214. package/src/widget/components/FeeBreakdown.tsx +155 -0
  215. package/src/widget/components/FeeOption.tsx +2 -2
  216. package/src/widget/components/FeeOptions.tsx +151 -112
  217. package/src/widget/components/Fund.tsx +10 -29
  218. package/src/widget/components/FundMethods.tsx +4 -3
  219. package/src/widget/components/FundSwap.tsx +2 -3
  220. package/src/widget/components/FundingMethodSelectorButton.tsx +24 -14
  221. package/src/widget/components/Identicon.tsx +164 -95
  222. package/src/widget/components/MeshConnectExchanges.tsx +2 -15
  223. package/src/widget/components/Modal.tsx +0 -12
  224. package/src/widget/components/Pay.tsx +72 -75
  225. package/src/widget/components/PoolDeposit.tsx +221 -242
  226. package/src/widget/components/PoolWithdraw.tsx +347 -469
  227. package/src/widget/components/PriceImpactWarning.tsx +1 -1
  228. package/src/widget/components/QuoteDetails.tsx +906 -484
  229. package/src/widget/components/Receipt.tsx +16 -2
  230. package/src/widget/components/RecipientSelectorButton.tsx +7 -5
  231. package/src/widget/components/Recipients.tsx +1 -1
  232. package/src/widget/components/ScreenHeader.tsx +60 -36
  233. package/src/widget/components/Swap.tsx +2 -3
  234. package/src/widget/components/ThemeProvider.tsx +2 -1
  235. package/src/widget/components/TokenDisplayNonSelectable.tsx +40 -0
  236. package/src/widget/components/TokenImage.tsx +1 -1
  237. package/src/widget/components/TokenSelector.tsx +62 -53
  238. package/src/widget/components/TokenSelectorButton.tsx +38 -15
  239. package/src/widget/components/Tooltip.tsx +51 -0
  240. package/src/widget/components/TransferPendingVertical.tsx +12 -8
  241. package/src/widget/components/WaasFeeOptions.tsx +139 -4
  242. package/src/widget/components/WalletConfirmation.tsx +23 -13
  243. package/src/widget/components/WalletConnect.tsx +93 -29
  244. package/src/widget/hooks/useAmountUsd.ts +9 -9
  245. package/src/widget/hooks/useCheckout.ts +97 -9
  246. package/src/widget/hooks/useDefaultTokenSelection.tsx +27 -21
  247. package/src/widget/hooks/useQuote.ts +466 -0
  248. package/src/widget/hooks/useSelectedFeeToken.tsx +32 -37
  249. package/src/widget/hooks/useSendForm.ts +45 -51
  250. package/src/widget/hooks/useTokenList.ts +34 -26
  251. package/src/widget/hooks/useWalletConnectionContext.tsx +128 -0
  252. package/src/widget/widget.tsx +365 -390
  253. package/dist/apiClient.d.ts +0 -9
  254. package/dist/apiClient.d.ts.map +0 -1
  255. package/dist/intentEntrypoint.d.ts +0 -114
  256. package/dist/intentEntrypoint.d.ts.map +0 -1
  257. package/dist/metaTxnMonitor.d.ts +0 -15
  258. package/dist/metaTxnMonitor.d.ts.map +0 -1
  259. package/dist/metaTxns.d.ts +0 -11
  260. package/dist/metaTxns.d.ts.map +0 -1
  261. package/dist/relayer.d.ts +0 -43
  262. package/dist/relayer.d.ts.map +0 -1
  263. package/src/apiClient.ts +0 -35
  264. package/src/intentEntrypoint.ts +0 -203
  265. package/src/metaTxnMonitor.ts +0 -171
  266. package/src/metaTxns.ts +0 -45
  267. package/src/relayer.ts +0 -289
package/dist/index.js CHANGED
@@ -1,122 +1,450 @@
1
- import { u as bn, a as En, l as t, c as Pe, f as Pn, b as B, S as xe, d as Me, e as xn, h as Mn, i as ce, q as On, j as Rn, k as Oe } from "./index-_QuyGrjU.js";
2
- import { O as zn, T as Yn, ad as Jn, af as Xn, v as Zn, ae as et, U as nt, m as tt, D as st, A as it, r as at, aa as ot, E as rt, F as ct, s as lt, z as dt, R as ut, ab as gt, P as mt, W as ft, Z as ht, Y as It, a3 as pt, V as vt, a8 as Tt, o as Ct, K as St, X as At, ac as yt, N as wt, a6 as kt, x as bt, Q as Et, w as Pt, a9 as xt, $ as Mt, a4 as Ot, a1 as Rt, a2 as qt, _ as $t, a7 as Nt, a0 as Ft, a5 as Ut, n as Ht, G as Dt, B as Bt, H as jt, I as Gt, t as Lt, C as _t, y as Wt, p as Qt, L as Vt, J as Kt, M as zt } from "./index-_QuyGrjU.js";
3
- import { useMutation as Se, useQuery as qn } from "@tanstack/react-query";
4
- import { useState as c, useCallback as Re, useEffect as b, useMemo as $n, useRef as qe } from "react";
5
- import { isAddressEqual as ee, zeroAddress as $e, isAddress as Nn, createPublicClient as Ne, http as Fe, createWalletClient as Ue, custom as He } from "viem";
6
- import { useSwitchChain as Fn, useSendTransaction as Un, useEstimateGas as Hn, useWaitForTransactionReceipt as Dn } from "wagmi";
7
- const De = 1e4;
8
- function Qn(Be) {
1
+ import { l as t, u as pe, t as Sn, a as wn, b as yn, g as be, c as kn, d as En, e as bn, f as xe, h as xn, T as Pn, p as Rn, i as He, j as Un, k as Ee, m as De, n as qn, o as se, q as Fe, r as On, s as Mn, v as Hn, w as Le } from "./index-QXPUrZVv.js";
2
+ import { I as Zn, W as et, ae as nt, ag as tt, U as st, C as it, af as ot, X as rt, K as at, G as ct, A as lt, ab as dt, L as ut, M as gt, B as mt, F as ft, x as It, ac as ht, $ as pt, _ as vt, a4 as Tt, Y as At, a9 as Ct, y as St, R as wt, Z as yt, ad as kt, V as Et, a7 as bt, E as xt, D as Pt, aa as Rt, a5 as Ut, a2 as qt, a3 as Ot, a0 as Mt, a8 as Ht, a1 as Dt, a6 as Ft, N as Lt, H as Bt, O as Nt, P as $t, J as Gt, z as jt, Q as Qt, S as Wt } from "./index-QXPUrZVv.js";
3
+ import { useQuery as Pe, useMutation as Ie } from "@tanstack/react-query";
4
+ import { useRef as Dn, useState as d, useCallback as Be, useEffect as P } from "react";
5
+ import { zeroAddress as he, isAddressEqual as ce, isAddress as Fn, ethAddress as Ln, createWalletClient as Ne, custom as $e } from "viem";
6
+ import { useSwitchChain as Bn, useSendTransaction as Nn, useEstimateGas as $n, useWaitForTransactionReceipt as Gn } from "wagmi";
7
+ const Ge = 150, jn = (u, i) => {
8
+ const r = Pe({
9
+ queryKey: ["waitIntentReceipt", u],
10
+ queryFn: async () => {
11
+ if (!u)
12
+ throw new Error("Intent ID is required for monitoring");
13
+ t.console.log(
14
+ `[trails-sdk] 🔍 Monitoring intent receipt for ${u}`
15
+ );
16
+ const l = await i.waitIntentReceipt({
17
+ intentId: u
18
+ });
19
+ return t.console.log(
20
+ `[trails-sdk] 📊 Intent ${u} status: ${l.intentReceipt.status}, done: ${l.done}`
21
+ ), l;
22
+ },
23
+ enabled: !!u,
24
+ refetchIntervalInBackground: !0,
25
+ refetchInterval: (l) => {
26
+ const o = l.state.data;
27
+ return o && o.done ? (t.console.log(
28
+ `[trails-sdk] ✅ Intent monitoring complete for ${u}`
29
+ ), !1) : Ge;
30
+ },
31
+ retry: (l, o) => l >= 30 ? (t.console.error(
32
+ `[trails-sdk] ❌ Giving up on intent ${u} after 30 failed API attempts:`,
33
+ o
34
+ ), !1) : !0
35
+ });
36
+ return {
37
+ intentReceipt: r.data?.intentReceipt ?? null,
38
+ done: r.data?.done ?? !1,
39
+ isLoading: r.isLoading,
40
+ isError: r.isError,
41
+ error: r.error
42
+ };
43
+ };
44
+ function je() {
45
+ const u = pe();
46
+ return Ie({
47
+ mutationFn: async (i) => {
48
+ t.console.log("[trails-sdk] useCommitIntent: Starting commit", {
49
+ intentId: i.intentId,
50
+ originIntentAddress: i.originIntentAddress
51
+ });
52
+ const r = i.calls[0]?.chainId, l = i.calls[1]?.chainId;
53
+ try {
54
+ Sn({
55
+ intentAddress: i.originIntentAddress,
56
+ userAddress: i.ownerAddress,
57
+ originChainId: r ? Number(r) : void 0,
58
+ destinationChainId: l ? Number(l) : void 0
59
+ });
60
+ const o = await u.commitIntent({ intent: i });
61
+ return t.console.log("[trails-sdk] useCommitIntent: Commit successful", {
62
+ intentId: i.intentId,
63
+ response: o
64
+ }), wn({
65
+ intentAddress: i.originIntentAddress,
66
+ userAddress: i.ownerAddress,
67
+ originChainId: r ? Number(r) : void 0,
68
+ destinationChainId: l ? Number(l) : void 0
69
+ }), o;
70
+ } catch (o) {
71
+ throw yn({
72
+ error: be(o),
73
+ userAddress: i.ownerAddress,
74
+ intentAddress: i.originIntentAddress,
75
+ originChainId: r ? Number(r) : void 0,
76
+ destinationChainId: l ? Number(l) : void 0
77
+ }), o;
78
+ }
79
+ }
80
+ });
81
+ }
82
+ function Qe() {
83
+ const u = pe();
84
+ return Ie({
85
+ mutationFn: async ({
86
+ intentId: i,
87
+ depositTransactionHash: r,
88
+ depositSignature: l
89
+ }) => {
90
+ if (t.console.log("[trails-sdk] useExecuteIntent: Starting execution", {
91
+ intentId: i,
92
+ depositTransactionHash: r,
93
+ hasDepositSignature: !!l
94
+ }), !r && !l)
95
+ throw new Error(
96
+ "[trails-sdk] Either depositTransactionHash or depositSignature must be provided"
97
+ );
98
+ const o = await u.executeIntent({
99
+ intentId: i,
100
+ depositTransactionHash: r,
101
+ depositSignature: l
102
+ });
103
+ return t.console.log(
104
+ "[trails-sdk] useExecuteIntent: Execution successful",
105
+ {
106
+ intentId: i,
107
+ response: o
108
+ }
109
+ ), o;
110
+ }
111
+ });
112
+ }
113
+ function zn({
114
+ walletClient: u,
115
+ fromTokenAddress: i,
116
+ fromChainId: r,
117
+ toTokenAddress: l,
118
+ toChainId: o,
119
+ swapAmount: C,
120
+ tradeType: N,
121
+ toRecipient: H,
122
+ toCalldata: _,
123
+ slippageTolerance: $,
124
+ onStatusUpdate: ve,
125
+ quoteProvider: D,
126
+ paymasterUrl: F,
127
+ selectedFeeToken: L,
128
+ nodeGatewayEnv: R,
129
+ abortSignal: E
130
+ } = {}) {
131
+ R && (globalThis.__testNodeGatewayEnv = R);
132
+ const T = Dn(new AbortController()), B = E ? (() => {
133
+ const f = new AbortController();
134
+ return E.addEventListener("abort", () => {
135
+ f.abort(), T.current?.abort();
136
+ }), T.current?.signal.addEventListener("abort", () => {
137
+ f.abort();
138
+ }), f.signal;
139
+ })() : T.current.signal, w = pe(), G = kn(), { supportedTokens: z } = En(), p = je(), ie = Qe(), { data: m, isLoading: j, error: le, refetch: Q } = Pe({
140
+ queryKey: [
141
+ "prepareSend",
142
+ i,
143
+ r,
144
+ l,
145
+ o,
146
+ C?.toString(),
147
+ H,
148
+ _,
149
+ N,
150
+ $,
151
+ D
152
+ ],
153
+ queryFn: async () => {
154
+ try {
155
+ if (T.current.signal.aborted && (t.console.log(
156
+ "[trails-sdk] Resetting aborted controller for new query"
157
+ ), T.current = new AbortController()), !u || !w || !i || !l || !C || !H || !r || !o || !G)
158
+ return null;
159
+ let f = [];
160
+ try {
161
+ f = (await bn({
162
+ account: u.account.address,
163
+ indexerGatewayClient: G,
164
+ trailsClient: w
165
+ })).balances;
166
+ } catch (a) {
167
+ const h = be(a), W = h.includes("Cross-Origin") || h.includes("CORS") || h.includes("Same Origin Policy"), y = h.includes("fetch failed") || h.includes("network");
168
+ if (W || y)
169
+ t.console.warn(
170
+ "[trails-sdk] [useQuote] Network or CORS error fetching balances, proceeding with quote using zero balance:",
171
+ {
172
+ error: h,
173
+ account: u.account.address
174
+ }
175
+ ), f = [];
176
+ else
177
+ throw a;
178
+ }
179
+ const Te = f.find(
180
+ (a) => a.chainId === r && (a.contractAddress?.toLowerCase() === i.toLowerCase() || !a.contractAddress && i === he)
181
+ )?.balance ?? "0";
182
+ let U = 0;
183
+ try {
184
+ const h = xe(r)?.nativeCurrency?.symbol ?? "";
185
+ h && (U = (await xn(w, {
186
+ tokenSymbol: h,
187
+ tokenAddress: he,
188
+ chainId: r
189
+ }))?.priceUsd ?? 0, t.console.log(
190
+ "[trails-sdk] [useQuote] Origin native token price:",
191
+ {
192
+ chainId: r,
193
+ symbol: h,
194
+ priceUsd: U
195
+ }
196
+ ));
197
+ } catch (a) {
198
+ t.console.error(
199
+ "[trails-sdk] [useQuote] Error getting origin native token price:",
200
+ a
201
+ );
202
+ }
203
+ const s = z?.find(
204
+ (a) => a.contractAddress?.toLowerCase() === i?.toLowerCase() && a.chainId === r
205
+ ), q = z?.find(
206
+ (a) => a.contractAddress?.toLowerCase() === l?.toLowerCase() && a.chainId === o
207
+ ), de = s?.decimals;
208
+ if (!de)
209
+ throw t.console.error(
210
+ "[trails-sdk] [useQuote] Missing source token decimals:",
211
+ {
212
+ originToken: s,
213
+ fromTokenAddress: i,
214
+ fromChainId: r
215
+ }
216
+ ), new Error("Source token decimals not found");
217
+ const ue = q?.decimals;
218
+ if (!ue)
219
+ throw t.console.error(
220
+ "[trails-sdk] Missing destination token decimals:",
221
+ {
222
+ destinationToken: q,
223
+ toTokenAddress: l,
224
+ toChainId: o
225
+ }
226
+ ), new Error("Destination token decimals not found");
227
+ const J = q?.symbol ?? "", Y = s?.symbol ?? "", oe = {
228
+ account: u.account,
229
+ originTokenAddress: i,
230
+ originChainId: r,
231
+ originTokenBalance: Te,
232
+ destinationChainId: o,
233
+ recipient: H,
234
+ destinationTokenAddress: l,
235
+ swapAmount: C.toString(),
236
+ tradeType: N ?? Pn.EXACT_OUTPUT,
237
+ originTokenSymbol: Y,
238
+ destinationTokenSymbol: J,
239
+ destinationCalldata: _,
240
+ client: u,
241
+ trailsClient: w,
242
+ sourceTokenDecimals: de,
243
+ destinationTokenDecimals: ue,
244
+ fee: "0",
245
+ dryMode: !1,
246
+ onTransactionStateChange: ve ?? (() => {
247
+ }),
248
+ slippageTolerance: $?.toString(),
249
+ quoteProvider: D,
250
+ paymasterUrl: F,
251
+ selectedFeeToken: L ?? void 0,
252
+ abortSignal: B,
253
+ originNativeTokenPriceUsd: U,
254
+ commitIntentFn: p.mutateAsync,
255
+ executeIntentFn: ie.mutateAsync
256
+ };
257
+ t.console.log("[trails-sdk] options", oe);
258
+ const { quote: c, send: Ae } = await Rn(oe);
259
+ return {
260
+ quote: {
261
+ fromAmount: c.originAmount,
262
+ toAmount: c.destinationAmount,
263
+ fromAmountMin: c.originAmountMin,
264
+ toAmountMin: c.destinationAmountMin,
265
+ originToken: c.originToken,
266
+ destinationToken: c.destinationToken,
267
+ originChain: c.originChain,
268
+ destinationChain: c.destinationChain,
269
+ fees: c.fees,
270
+ priceImpact: c.priceImpact,
271
+ completionEstimateSeconds: c.completionEstimateSeconds,
272
+ slippageTolerance: c.slippageTolerance,
273
+ transactionStates: c.transactionStates,
274
+ originTokenRate: c.originTokenRate,
275
+ destinationTokenRate: c.destinationTokenRate,
276
+ quoteProvider: c.quoteProvider,
277
+ fromAmountUsdDisplay: c.originAmountUsdDisplay ?? void 0,
278
+ toAmountUsdDisplay: c.destinationAmountUsdDisplay ?? void 0,
279
+ gasCostUsd: c.gasCostUsd ?? void 0,
280
+ gasCostUsdDisplay: c.gasCostUsdDisplay ?? void 0,
281
+ gasCost: c.gasCost ?? void 0,
282
+ gasCostFormatted: c.gasCostFormatted ?? void 0
283
+ },
284
+ swap: async () => {
285
+ const {
286
+ depositUserTxnReceipt: a,
287
+ destinationMetaTxnReceipt: h,
288
+ totalCompletionSeconds: W
289
+ } = await Ae({
290
+ selectedFeeToken: L ?? void 0
291
+ });
292
+ return {
293
+ originTransaction: {
294
+ transactionHash: a?.transactionHash,
295
+ explorerUrl: He({
296
+ txHash: a?.transactionHash,
297
+ chainId: r
298
+ }),
299
+ receipt: a
300
+ },
301
+ destinationTransaction: {
302
+ transactionHash: h?.txnHash,
303
+ explorerUrl: He({
304
+ txHash: h?.txnHash,
305
+ chainId: o
306
+ }),
307
+ receipt: h
308
+ },
309
+ totalCompletionSeconds: W
310
+ };
311
+ }
312
+ };
313
+ } catch (f) {
314
+ throw t.console.error(
315
+ "[trails-sdk] [useQuote] Error getting quote:",
316
+ f
317
+ ), be(f);
318
+ }
319
+ },
320
+ // Prevent unnecessary refetching
321
+ enabled: !!(u && w && i && l && C && H && r && o && G && // !isLoadingTokens &&
322
+ z && z.length > 0),
323
+ staleTime: 30 * 1e3,
324
+ // Consider data fresh for 30 seconds
325
+ refetchOnWindowFocus: !1,
326
+ // Don't refetch when window regains focus
327
+ refetchOnMount: !1,
328
+ // Don't refetch on component remount if data exists
329
+ refetchInterval: !1,
330
+ // Disable automatic polling
331
+ retry: 2,
332
+ // Limit retry attempts
333
+ refetchOnReconnect: !0
334
+ // Refetch when network reconnects
335
+ });
336
+ return {
337
+ quote: m?.quote || null,
338
+ swap: m?.swap || null,
339
+ isLoadingQuote: j,
340
+ quoteError: le,
341
+ quoteErrorPrettified: Un(le),
342
+ refetchQuote: () => Q(),
343
+ abort: () => {
344
+ t.console.log("[trails-sdk] useQuote abort() called"), t.console.log(
345
+ "[trails-sdk] Active operations before abort:",
346
+ Ee.getAll()
347
+ ), T.current.abort(), Ee.abortAll(), t.console.log(
348
+ "[trails-sdk] Abort completed, active operations:",
349
+ Ee.getAll()
350
+ );
351
+ }
352
+ };
353
+ }
354
+ function Xn(u) {
9
355
  const {
10
- account: d,
11
- disableAutoExecute: je = !1,
12
- env: Ge,
13
- sequenceProjectAccessKey: Le
14
- } = Be, S = bn({
15
- projectAccessKey: Le
16
- }), [x, ne] = c(!je), [le, de] = c(!1), [j, Ae] = c(
356
+ account: i,
357
+ disableAutoExecute: r = !1,
358
+ sequenceProjectAccessKey: l
359
+ } = u, o = pe({
360
+ projectAccessKey: l
361
+ }), [C, N] = d(!r), [H, _] = d(!1), [$, ve] = d(
17
362
  {}
18
- ), [u, O] = c(null), [y, R] = c(null), [v, q] = c(null), [A, G] = c(null), [T, ue] = c(), [$, L] = c(null), [
19
- _e,
20
- _
21
- ] = c(null), [N, W] = c(
363
+ ), [D, F] = d(null), [L, R] = d(null), [E, T] = d(null), [B, w] = d(null), [G, z] = d(null), [p, ie] = d(), [m, j] = d(null), [
364
+ le,
365
+ Q
366
+ ] = d(null), [f, X] = d(
22
367
  null
23
- ), [We, Q] = c(null), [i, V] = c(null), [Qe, ye] = c({}), [te, se] = c(!1), [we, K] = c(!1), {
24
- switchChain: Ve,
25
- isPending: Ke,
26
- error: z
27
- } = Fn(), E = Un(), [ze, ke] = c(!1), [w, M] = c(null), [Ye, F] = c(null), [ge, Y] = c({}), [Je, ie] = c(null), { getRelayer: me, relayers: Xe } = En({
28
- env: Ge
29
- }), {
30
- data: ae,
31
- isError: fe,
32
- error: he
33
- } = Hn(
34
- i?.to && i?.chainId && !i.error ? {
35
- to: i.to || void 0,
36
- data: i.data || void 0,
37
- value: i.value || void 0,
38
- chainId: i.chainId || void 0
368
+ ), [Te, U] = d(null), [s, q] = d(null), [de, ue] = d({}), [J, Y] = d(!1), [oe, c] = d(!1), {
369
+ switchChain: Ae,
370
+ isPending: Re,
371
+ error: Z
372
+ } = Bn(), a = Nn(), [h, W] = d(!1), [y, K] = d(null), [We, Ce] = d(null), [Ke, Ue] = d({}), [Ve, ge] = d(null), {
373
+ data: me,
374
+ isError: Se,
375
+ error: we
376
+ } = $n(
377
+ s?.to && s?.chainId && !s.error ? {
378
+ to: s.to || void 0,
379
+ data: s.data || void 0,
380
+ value: s.value || void 0,
381
+ chainId: s.chainId || void 0
39
382
  } : void 0
40
- ), I = Se({
383
+ ), _e = je(), S = Ie({
41
384
  mutationFn: async (e) => {
42
- if (t.console.log(
43
- "[useTrails] commitIntentConfigMutation started with args:",
385
+ t.console.log(
386
+ "[useTrails] commitIntentMutation started with intent:",
44
387
  e
45
- ), !S)
46
- throw t.console.error("[useTrails] API client not available"), new Error("API client not available");
47
- if (!e.quoteProvider)
48
- throw t.console.error("[useTrails] quoteProvider is required"), new Error("quoteProvider is required");
388
+ );
49
389
  try {
50
- t.console.log("[useTrails] Calculating intent address..."), t.console.log("[useTrails] Main signer:", e.mainSignerAddress), t.console.log("[useTrails] Calls:", e.calls);
51
- const n = g.variables?.params.originChainId, a = g.variables?.params.destinationChainId;
52
- if (!n || !a)
390
+ const n = v.variables?.originChainId, g = v.variables?.destinationChainId;
391
+ if (!n || !g)
53
392
  throw t.console.error(
54
393
  "[useTrails] Could not determine origin/destination chain IDs for verification."
55
394
  ), new Error(
56
395
  "Could not determine origin/destination chain IDs for verification."
57
396
  );
58
- const { originIntentAddress: l, destinationIntentAddress: s } = Pe(
59
- e.mainSignerAddress,
397
+ t.console.log("[useTrails] Calculating intent address..."), t.console.log("[useTrails] Main signer:", e.ownerAddress), t.console.log("[useTrails] Calls:", e.calls);
398
+ const { originIntentAddress: k, destinationIntentAddress: b } = De(
399
+ e.ownerAddress,
60
400
  e.calls
61
401
  ), {
62
- originAddress: r,
63
- destinationAddress: f
64
- } = Pn(
402
+ originAddress: ae,
403
+ destinationAddress: V
404
+ } = qn(
65
405
  e.preconditions,
66
406
  n,
67
- a
407
+ g
68
408
  );
69
409
  t.console.log("[useTrails] Verification addresses:", {
70
- calculatedOrigin: l.toString(),
71
- calculatedDestination: s.toString(),
72
- preconditionOrigin: r,
73
- preconditionDestination: f
410
+ calculatedOrigin: k.toString(),
411
+ calculatedDestination: b.toString(),
412
+ preconditionOrigin: ae,
413
+ preconditionDestination: V
74
414
  });
75
- const m = !!r && ee(
76
- B(r),
77
- l
415
+ const x = !!ae && ce(
416
+ se(ae),
417
+ k
78
418
  );
79
- t.console.log("[useTrails] Origin verified:", m);
80
- const o = f && ee(
81
- B(f),
82
- s
83
- ) || !f && n === a && ee(s, $e);
419
+ t.console.log("[useTrails] Origin verified:", x);
420
+ const A = V && ce(
421
+ se(V),
422
+ b
423
+ ) || !V && n === g && ce(b, he);
84
424
  t.console.log(
85
425
  "[useTrails] Destination verified:",
86
- o
426
+ A
87
427
  );
88
- const h = m && o;
89
- if (ie({
90
- success: h,
91
- receivedOriginAddress: r,
92
- receivedDestinationAddress: f,
93
- calculatedOriginAddress: l.toString(),
94
- calculatedDestinationAddress: s.toString()
95
- }), !h)
428
+ const Oe = x && A;
429
+ if (ge({
430
+ success: Oe,
431
+ receivedOriginAddress: ae,
432
+ receivedDestinationAddress: V,
433
+ calculatedOriginAddress: k.toString(),
434
+ calculatedDestinationAddress: b.toString()
435
+ }), !Oe)
96
436
  throw t.console.error("[useTrails] Address verification failed.", {
97
- isOriginVerified: m,
98
- isDestinationVerified: o
437
+ isOriginVerified: x,
438
+ isDestinationVerified: A
99
439
  }), new Error(
100
- `Address verification failed. Origin verified: ${m}, Destination verified: ${o}`
440
+ `Address verification failed. Origin verified: ${x}, Destination verified: ${A}`
101
441
  );
102
- t.console.log("[useTrails] Committing intent config to API...");
103
- const p = await S.commitIntentConfig({
104
- params: {
105
- originIntentAddress: l.toString(),
106
- destinationIntentAddress: s.toString(),
107
- mainSigner: e.mainSignerAddress,
108
- calls: e.calls,
109
- preconditions: e.preconditions,
110
- addressOverrides: {
111
- ...xe,
112
- ...e.addressOverrides
113
- }
114
- }
115
- });
116
- return t.console.log("[useTrails] API Commit Response:", p), {
117
- originIntentAddress: l.toString(),
118
- destinationIntentAddress: s.toString(),
119
- response: p
442
+ t.console.log("[useTrails] Committing intent to API...");
443
+ const Me = await _e.mutateAsync(e);
444
+ return t.console.log("[useTrails] API Commit Response:", Me), {
445
+ originIntentAddress: k.toString(),
446
+ destinationIntentAddress: b.toString(),
447
+ response: Me
120
448
  };
121
449
  } catch (n) {
122
450
  throw console.error("[useTrails] Error during commit intent mutation:", n), n;
@@ -129,96 +457,89 @@ function Qn(Be) {
129
457
  ), t.console.log(
130
458
  "[useTrails] Setting committedOriginIntentAddress:",
131
459
  e.originIntentAddress
132
- ), L(e.originIntentAddress), _(e.destinationIntentAddress);
460
+ ), j(e.originIntentAddress), Q(e.destinationIntentAddress);
133
461
  },
134
462
  onError: (e) => {
135
- t.console.error("[useTrails] Failed to commit intent config:", e), L(null), _(null);
463
+ t.console.error("[useTrails] Failed to commit intent config:", e), j(null), Q(null);
136
464
  }
137
- }), {
138
- data: Ze,
139
- isLoading: en,
140
- error: nn
141
- } = qn({
142
- queryKey: ["getIntentConfig", $],
465
+ }), ee = Qe(), {
466
+ data: ze,
467
+ isLoading: Xe,
468
+ error: Je
469
+ } = Pe({
470
+ queryKey: ["getIntent", m],
143
471
  queryFn: async () => {
144
- if (!S || !$)
472
+ if (!o || !m)
145
473
  throw new Error("API client or committed intent address not available");
146
474
  return t.console.log(
147
475
  "Fetching intent config for address:",
148
- $
149
- ), await S.getIntentConfig({
150
- intentAddress: $
151
- });
476
+ m
477
+ ), (await o.getIntent({
478
+ intentId: m
479
+ })).intent;
152
480
  },
153
- enabled: !!$ && !!S && I.isSuccess,
481
+ enabled: !!m && !!o && S.isSuccess,
154
482
  staleTime: 1e3 * 60 * 5,
155
483
  // 5 minutes
156
484
  retry: 1
157
485
  });
158
- async function be(e) {
159
- return Rn(S, {
160
- params: {
161
- ...e.params,
162
- addressOverrides: {
163
- ...xe,
164
- ...e.params.addressOverrides
165
- }
166
- }
167
- });
486
+ async function Ye(e) {
487
+ const { intent: n } = await Fe(o, e);
488
+ return n;
168
489
  }
169
- const g = Se({
490
+ const v = Ie({
170
491
  mutationFn: async (e) => {
171
- if (e.params.originChainId === e.params.destinationChainId && ee(
172
- B(e.params.originTokenAddress),
173
- B(e.params.destinationTokenAddress)
492
+ if (e.originChainId === e.destinationChainId && ce(
493
+ se(e.originTokenAddress),
494
+ se(e.destinationTokenAddress)
174
495
  ))
175
496
  throw new Error(
176
497
  "The same token cannot be used as both the source and destination token."
177
498
  );
178
- if (!d.address)
499
+ if (!i.address)
179
500
  throw new Error("Missing selected token or account address");
180
- L(null), _(null), ie(null), G(null), O(null), R(null), q(null), W(null), Q(null);
181
- const n = await be(e);
182
- return O(n.payloads.metaTxns), R(n.payloads.calls), q(n.payloads.preconditions), G(n.payloads.trailsFee), W(n.payloads.originIntentAddress), Q(n.payloads.destinationIntentAddress), L(null), _(null), ie(null), n;
501
+ j(null), Q(null), ge(null), w(null), F(null), R(null), T(null), X(null), U(null);
502
+ const { intent: n } = await Fe(o, e);
503
+ return F(n.metaTxns), R(n.calls), T(n.preconditions), w(n.fees), X(n.originIntentAddress), U(n.destinationIntentAddress), z(n), j(null), Q(null), ge(null), n;
183
504
  },
184
505
  onSuccess: (e) => {
185
- t.console.log("Intent Config Success:", e), G(e.payloads.trailsFee || null), W(e.payloads.originIntentAddress), Q(e.payloads.destinationIntentAddress), e.payloads?.calls && e.payloads.calls.length > 0 && e.payloads.preconditions && e.payloads.preconditions.length > 0 && e.payloads.metaTxns && e.payloads.metaTxns.length > 0 ? (R(e.payloads.calls), q(e.payloads.preconditions), O(e.payloads.metaTxns)) : (t.console.warn("API returned success but no operations found."), R(null), q(null), O(null));
506
+ t.console.log("Intent Config Success:", e), w(e.fees || null), X(e.originIntentAddress), U(e.destinationIntentAddress), e?.calls && e.calls.length > 0 && e.preconditions && e.preconditions.length > 0 && e.metaTxns && e.metaTxns.length > 0 ? (R(e.calls), T(e.preconditions), F(e.metaTxns)) : (t.console.warn("API returned success but no operations found."), R(null), T(null), F(null));
186
507
  },
187
508
  onError: (e) => {
188
- console.error("Intent Config Error:", e), R(null), q(null), O(null), G(null), W(null), Q(null);
509
+ console.error("Intent Config Error:", e), R(null), T(null), F(null), w(null), X(null), U(null);
189
510
  }
190
511
  });
191
- function tn(e) {
192
- g.mutate(e);
512
+ function Ze(e) {
513
+ v.mutate(e);
193
514
  }
194
- const sn = Re(() => {
195
- t.console.log("[Trails] Clearing intent state"), R(null), q(null), O(null), G(null), L(null), _(null), ie(null), W(null), Q(null), ye({}), de(!1), Y({});
196
- }, []), k = Re(
197
- (e, n, a, l, s) => {
198
- M({
515
+ const en = Be(() => {
516
+ t.console.log("[Trails] Clearing intent state"), R(null), T(null), F(null), w(null), j(null), Q(null), ge(null), X(null), U(null), ue({}), _(!1), Ue({});
517
+ }, []), O = Be(
518
+ (e, n, g, k, b) => {
519
+ K({
199
520
  txnHash: e,
200
521
  status: n === "success" ? "Success" : n === "reverted" ? "Failed" : n === "sending" ? "Sending..." : "Pending",
201
- revertReason: n === "reverted" ? s || "Transaction reverted" : void 0,
202
- gasUsed: a ? Number(a) : void 0,
203
- effectiveGasPrice: l?.toString()
522
+ revertReason: n === "reverted" ? b || "Transaction reverted" : void 0,
523
+ gasUsed: g ? Number(g) : void 0,
524
+ effectiveGasPrice: k?.toString()
204
525
  });
205
526
  },
206
527
  []
207
- ), an = async () => {
528
+ ), nn = async () => {
208
529
  if (t.console.log("Sending origin transaction..."), t.console.log(
209
- te,
210
- i,
211
- i?.error,
212
- i?.to,
213
- i?.data,
214
- i?.value,
215
- i?.chainId
216
- ), te || // Prevent duplicate transactions
217
- !i || i.error || !i.to || i.data === null || i.value === null || i.chainId === null) {
530
+ J,
531
+ s,
532
+ s?.error,
533
+ s?.to,
534
+ s?.data,
535
+ s?.value,
536
+ s?.chainId
537
+ ), J || // Prevent duplicate transactions
538
+ !s || s.error || !s.to || s.data === null || s.value === null || s.chainId === null) {
218
539
  t.console.error(
219
540
  "Origin call parameters not available or invalid:",
220
- i
221
- ), k(
541
+ s
542
+ ), O(
222
543
  void 0,
223
544
  "reverted",
224
545
  void 0,
@@ -227,103 +548,103 @@ function Qn(Be) {
227
548
  );
228
549
  return;
229
550
  }
230
- if (d.chainId !== i.chainId) {
231
- K(!0), k(
551
+ if (i.chainId !== s.chainId) {
552
+ c(!0), O(
232
553
  void 0,
233
554
  "pending",
234
555
  void 0,
235
556
  void 0,
236
- `Switching to chain ${i.chainId}...`
557
+ `Switching to chain ${s.chainId}...`
237
558
  );
238
- const e = Ue({
239
- chain: ce(i.chainId),
240
- transport: He(await d.connector.getProvider())
559
+ const e = Ne({
560
+ chain: xe(s.chainId),
561
+ transport: $e(await i.connector.getProvider())
241
562
  // TODO: Add proper type
242
563
  });
243
564
  try {
244
- await Oe({
565
+ await Le({
245
566
  walletClient: e,
246
- desiredChainId: i.chainId
247
- }), K(!1);
567
+ desiredChainId: s.chainId
568
+ }), c(!1);
248
569
  } catch (n) {
249
- t.console.error("Chain switch failed:", n), n instanceof Error && n.message.includes("User rejected") && ne(!1), k(
570
+ t.console.error("Chain switch failed:", n), n instanceof Error && n.message.includes("User rejected") && N(!1), O(
250
571
  void 0,
251
572
  "reverted",
252
573
  void 0,
253
574
  void 0,
254
575
  n instanceof Error ? n.message : "Unknown error switching chain"
255
- ), K(!1);
576
+ ), c(!1);
256
577
  return;
257
578
  }
258
579
  }
259
- if (te)
580
+ if (J)
260
581
  t.console.warn(
261
582
  "Transaction already in progress. Skipping duplicate request."
262
583
  );
263
584
  else {
264
- if (se(!0), ue(void 0), k(void 0, "sending"), !ae && !fe) {
265
- ke(!0);
585
+ if (Y(!0), ie(void 0), O(void 0, "sending"), !me && !Se) {
586
+ W(!0);
266
587
  return;
267
588
  }
268
- if (fe) {
269
- t.console.error("Gas estimation failed:", he), k(
589
+ if (Se) {
590
+ t.console.error("Gas estimation failed:", we), O(
270
591
  void 0,
271
592
  "reverted",
272
593
  void 0,
273
594
  void 0,
274
- `Gas estimation failed: ${he?.message}`
275
- ), se(!1);
595
+ `Gas estimation failed: ${we?.message}`
596
+ ), Y(!1);
276
597
  return;
277
598
  }
278
- const e = ae ? BigInt(Math.floor(Number(ae) * 1.2)) : void 0;
279
- E.sendTransaction(
599
+ const e = me ? BigInt(Math.floor(Number(me) * 1.2)) : void 0;
600
+ a.sendTransaction(
280
601
  {
281
- to: i.to,
282
- data: i.data,
283
- value: i.value,
284
- chainId: i.chainId,
602
+ to: s.to,
603
+ data: s.data,
604
+ value: s.value,
605
+ chainId: s.chainId,
285
606
  gas: e
286
607
  },
287
608
  {
288
609
  onSuccess: (n) => {
289
- t.console.log("Transaction sent, hash:", n), ue(n), se(!1);
610
+ t.console.log("Transaction sent, hash:", n), ie(n), Y(!1);
290
611
  },
291
612
  onError: (n) => {
292
- t.console.error("Transaction failed:", n), n instanceof Error && (n.message.includes("User rejected") || n.message.includes("user rejected")) && ne(!1), k(
613
+ t.console.error("Transaction failed:", n), n instanceof Error && (n.message.includes("User rejected") || n.message.includes("user rejected")) && N(!1), O(
293
614
  void 0,
294
615
  "reverted",
295
616
  void 0,
296
617
  void 0,
297
618
  n instanceof Error ? n.message : "Unknown error"
298
- ), se(!1);
619
+ ), Y(!1);
299
620
  }
300
621
  }
301
622
  );
302
623
  }
303
624
  };
304
- b(() => {
305
- z && (t.console.error("Chain switch error:", z), k(
625
+ P(() => {
626
+ Z && (t.console.error("Chain switch error:", Z), O(
306
627
  void 0,
307
628
  "reverted",
308
629
  void 0,
309
630
  void 0,
310
- `Chain switch failed: ${z.message || "Unknown error"}`
311
- ), K(!1));
312
- }, [z, k]), b(() => {
313
- ke(!1);
314
- }, []), b(() => {
315
- i?.chainId && d.chainId === i.chainId && (t.console.log("No chain switch required"), K(!1));
316
- }, [d.chainId, i?.chainId]), b(() => {
317
- if (i?.chainId && d.chainId !== i.chainId) {
631
+ `Chain switch failed: ${Z.message || "Unknown error"}`
632
+ ), c(!1));
633
+ }, [Z, O]), P(() => {
634
+ W(!1);
635
+ }, []), P(() => {
636
+ s?.chainId && i.chainId === s.chainId && (t.console.log("No chain switch required"), c(!1));
637
+ }, [i.chainId, s?.chainId]), P(() => {
638
+ if (s?.chainId && i.chainId !== s.chainId) {
318
639
  async function e() {
319
640
  try {
320
- const n = i.chainId, a = Ue({
321
- chain: ce(n),
322
- transport: He(await d.connector.getProvider())
641
+ const n = s.chainId, g = Ne({
642
+ chain: xe(n),
643
+ transport: $e(await i.connector.getProvider())
323
644
  // TODO: Add proper type
324
645
  });
325
- await Oe({
326
- walletClient: a,
646
+ await Le({
647
+ walletClient: g,
327
648
  desiredChainId: n
328
649
  });
329
650
  } catch (n) {
@@ -332,365 +653,167 @@ function Qn(Be) {
332
653
  }
333
654
  e().catch(t.console.error);
334
655
  }
335
- }, [d, i]);
656
+ }, [i, s]);
336
657
  const {
337
- data: C,
338
- isLoading: U,
339
- isSuccess: Ie,
340
- isError: pe,
341
- error: oe
342
- } = Dn({
343
- hash: T,
658
+ data: M,
659
+ isLoading: ne,
660
+ isSuccess: ye,
661
+ isError: ke,
662
+ error: fe
663
+ } = Gn({
664
+ hash: p,
344
665
  confirmations: 1,
345
666
  query: {
346
- enabled: !!T
667
+ enabled: !!p
347
668
  }
348
669
  });
349
- b(() => {
350
- if (!T) {
351
- w?.txnHash && M(null), F(null), Object.keys(j).length > 0 && Ae({});
670
+ P(() => {
671
+ if (!p) {
672
+ y?.txnHash && K(null), Ce(null), Object.keys($).length > 0 && ve({});
352
673
  return;
353
674
  }
354
- if (!(w?.txnHash === T && (w?.status === "Success" || w?.status === "Failed") && !U)) {
355
- if (U) {
356
- M((e) => ({
357
- ...e?.txnHash === T ? e : {
675
+ if (!(y?.txnHash === p && (y?.status === "Success" || y?.status === "Failed") && !ne)) {
676
+ if (ne) {
677
+ K((e) => ({
678
+ ...e?.txnHash === p ? e : {
358
679
  gasUsed: void 0,
359
680
  effectiveGasPrice: void 0,
360
681
  revertReason: void 0
361
682
  },
362
- txnHash: T,
683
+ txnHash: p,
363
684
  status: "Pending"
364
685
  }));
365
686
  return;
366
687
  }
367
- if (Ie && C) {
368
- const e = C.status === "success" ? "Success" : "Failed";
369
- M({
370
- txnHash: C.transactionHash,
688
+ if (ye && M) {
689
+ const e = M.status === "success" ? "Success" : "Failed";
690
+ K({
691
+ txnHash: M.transactionHash,
371
692
  status: e,
372
- gasUsed: C.gasUsed ? Number(C.gasUsed) : void 0,
373
- effectiveGasPrice: C.effectiveGasPrice?.toString(),
374
- revertReason: C.status === "reverted" ? oe?.message || "Transaction reverted by receipt" : void 0
375
- }), e === "Success" && C.blockNumber ? (async () => {
376
- try {
377
- if (!i?.chainId) {
378
- t.console.error(
379
- "[Trails] Origin chainId not available for fetching origin block timestamp."
380
- ), F(null);
381
- return;
382
- }
383
- const a = ce(i.chainId), s = await Ne({
384
- chain: a,
385
- transport: Fe()
386
- }).getBlock({
387
- blockNumber: BigInt(C.blockNumber)
388
- });
389
- F(Number(s.timestamp));
390
- } catch (a) {
391
- t.console.error(
392
- "[Trails] Error fetching origin block timestamp:",
393
- a
394
- ), F(null);
395
- }
396
- })() : e !== "Success" && F(null), e === "Success" && u && u.length > 0 && x && !u.some((n) => j[`${n.chainId}-${n.id}`]) && (t.console.log(
397
- "Origin transaction successful, auto-sending all meta transactions..."
398
- ), H.mutate({ selectedId: null }));
399
- } else pe && (M({
400
- txnHash: T,
693
+ gasUsed: M.gasUsed ? Number(M.gasUsed) : void 0,
694
+ effectiveGasPrice: M.effectiveGasPrice?.toString(),
695
+ revertReason: M.status === "reverted" ? fe?.message || "Transaction reverted by receipt" : void 0
696
+ }), e !== "Success" && Ce(null), e === "Success" && D && D.length > 0 && C && !D.some((n) => $[`${n.chainId}-${n.id}`]) && (t.console.log(
697
+ "Origin transaction successful, calling executeIntent and auto-sending all meta transactions..."
698
+ ), m && p && ee.mutate({
699
+ intentId: m,
700
+ depositTransactionHash: p
701
+ }));
702
+ } else ke && (K({
703
+ txnHash: p,
401
704
  status: "Failed",
402
- revertReason: oe?.message || "Failed to get receipt",
705
+ revertReason: fe?.message || "Failed to get receipt",
403
706
  gasUsed: void 0,
404
707
  effectiveGasPrice: void 0
405
- }), F(null));
708
+ }), Ce(null));
406
709
  }
407
710
  }, [
408
- T,
409
- U,
410
- Ie,
411
- pe,
711
+ p,
712
+ ne,
713
+ ye,
714
+ ke,
715
+ M,
716
+ fe,
717
+ D,
718
+ $,
412
719
  C,
413
- oe,
414
- u,
415
- j,
416
- x,
417
- i?.chainId,
418
- w?.status,
419
- w?.txnHash
420
- ]), b(() => {
421
- x && I.isSuccess && i?.chainId && d.chainId === i.chainId && !i.error && i.to && i.data !== null && i.value !== null && !E.isPending && !U && !T && !we && !w && !le && (t.console.log("Auto-executing transaction: All conditions met."), de(!0), M({
720
+ y?.status,
721
+ y?.txnHash,
722
+ m,
723
+ ee
724
+ ]), P(() => {
725
+ C && S.isSuccess && s?.chainId && i.chainId === s.chainId && !s.error && s.to && s.data !== null && s.value !== null && !a.isPending && !ne && !p && !oe && !y && !H && (t.console.log("Auto-executing transaction: All conditions met."), _(!0), K({
422
726
  status: "Sending..."
423
- }), E.sendTransaction(
727
+ }), a.sendTransaction(
424
728
  {
425
- to: i.to,
426
- data: i.data,
427
- value: i.value,
428
- chainId: i.chainId
729
+ to: s.to,
730
+ data: s.data,
731
+ value: s.value,
732
+ chainId: s.chainId
429
733
  },
430
734
  {
431
735
  onSuccess: (n) => {
432
- t.console.log("Auto-executed transaction sent, hash:", n), ue(n);
736
+ t.console.log("Auto-executed transaction sent, hash:", n), ie(n);
433
737
  },
434
738
  onError: (n) => {
435
- t.console.error("Auto-executed transaction failed:", n), n instanceof Error && (n.message.includes("User rejected") || n.message.includes("user rejected")) && ne(!1), M({
739
+ t.console.error("Auto-executed transaction failed:", n), n instanceof Error && (n.message.includes("User rejected") || n.message.includes("user rejected")) && N(!1), K({
436
740
  status: "Failed",
437
741
  revertReason: n instanceof Error ? n.message : "Unknown error"
438
- }), de(!1);
742
+ }), _(!1);
439
743
  }
440
744
  }
441
745
  ));
442
746
  }, [
443
- x,
444
- I.isSuccess,
445
- i,
446
- d.chainId,
447
- E.isPending,
448
- U,
449
- T,
450
- we,
451
- w,
452
- le,
453
- E
454
- ]), b(() => {
455
- x && y && v && A && d.address && N && !I.isPending && !I.isSuccess && (t.console.log("Auto-committing intent configuration..."), I.mutate({
456
- mainSignerAddress: d.address,
457
- calls: y,
458
- preconditions: v,
459
- quoteProvider: A.quoteProvider,
460
- addressOverrides: g.variables?.params.addressOverrides
461
- }));
462
- }, [
463
- x,
747
+ C,
748
+ S.isSuccess,
749
+ s,
750
+ i.chainId,
751
+ a.isPending,
752
+ ne,
753
+ p,
754
+ oe,
464
755
  y,
465
- v,
466
- A,
467
- d.address,
468
- N,
469
- I,
470
- g.variables
756
+ H,
757
+ a
758
+ ]), P(() => {
759
+ C && L && E && B && i.address && f && !S.isPending && !S.isSuccess && (t.console.log("Auto-committing intent configuration..."), G && S.mutate(G));
760
+ }, [
761
+ C,
762
+ G,
763
+ L,
764
+ E,
765
+ B,
766
+ i.address,
767
+ f,
768
+ S
471
769
  ]);
472
- const H = Se({
473
- mutationFn: async ({ selectedId: e }) => {
474
- if (t.console.log("[trails-sdk] Starting sendMetaTxn mutation", {
475
- selectedId: e,
476
- hasIntentCallsPayloads: !!y,
477
- hasIntentPreconditions: !!v,
478
- hasMetaTxns: !!u,
479
- hasAccountAddress: !!d.address,
480
- quoteProvider: A?.quoteProvider
481
- }), !y || !v || !u || !d.address)
482
- throw new Error("Missing required data for meta-transaction");
483
- if (!A?.quoteProvider)
484
- throw new Error("quoteProvider is required");
485
- const n = Me(
486
- d.address,
487
- y
488
- ), a = e ? [u.find((s) => s.id === e)] : u;
489
- if (t.console.log("[trails-sdk] Selected transactions to send", {
490
- selectedId: e,
491
- totalMetaTxns: u.length,
492
- txnsToSendCount: a.filter((s) => s).length,
493
- txnsToSend: a.filter((s) => s).map((s) => ({
494
- id: s?.id,
495
- chainId: s?.chainId,
496
- walletAddress: s?.walletAddress,
497
- contract: s?.contract
498
- }))
499
- }), !a || e && !a[0])
500
- throw new Error("Meta transaction not found");
501
- const l = [];
502
- for (const s of a) {
503
- if (!s) continue;
504
- const r = `${s.chainId}-${s.id}`, f = j[r], m = Date.now();
505
- if (t.console.log(
506
- `[trails-sdk] Processing meta transaction ${r}`,
507
- {
508
- metaTxnId: s.id,
509
- chainId: s.chainId,
510
- walletAddress: s.walletAddress,
511
- contract: s.contract,
512
- intentAddress: n
513
- }
514
- ), f && m - f < De) {
515
- const o = Math.ceil(
516
- (De - (m - f)) / 1e3
517
- );
518
- t.console.log(
519
- `[trails-sdk] Meta transaction for ${r} was sent recently. Wait ${o}s before retry`,
520
- {
521
- lastSentTime: f,
522
- now: m,
523
- timeLeft: o
524
- }
525
- );
526
- continue;
527
- }
528
- try {
529
- const o = parseInt(s.chainId, 10);
530
- if (Number.isNaN(o) || o <= 0)
531
- throw t.console.error(
532
- "[trails-sdk] Invalid chainId for meta transaction",
533
- {
534
- chainId: o,
535
- operationKey: r,
536
- metaTxn: s
537
- }
538
- ), new Error(`Invalid chainId for meta transaction: ${o}`);
539
- const h = me(o);
540
- if (!h)
541
- throw t.console.error("[trails-sdk] No relayer found for chainId", {
542
- chainId: o,
543
- operationKey: r,
544
- availableRelayers: Array.from(Xe.keys())
545
- }), new Error(`No relayer found for chainId: ${o}`);
546
- const p = v.filter(
547
- (D) => D.chainId && parseInt(D.chainId, 10) === o
548
- );
549
- t.console.log(
550
- `[trails-sdk] Relaying meta transaction ${r} to intent ${n} via relayer`,
551
- {
552
- chainId: o,
553
- operationKey: r,
554
- intentAddress: n,
555
- relayer: !!h,
556
- preconditionsCount: p.length
557
- }
558
- );
559
- const { opHash: Z } = await h.sendMetaTxn(
560
- s.walletAddress,
561
- s.contract,
562
- s.input,
563
- Number(s.chainId),
564
- void 0,
565
- p
566
- );
567
- t.console.log(
568
- `[trails-sdk] Successfully sent meta transaction ${r}`,
569
- {
570
- operationKey: r,
571
- opHash: Z,
572
- chainId: o
573
- }
574
- );
575
- const re = !1;
576
- l.push({
577
- operationKey: r,
578
- opHash: Z,
579
- success: !0
580
- });
581
- } catch (o) {
582
- const h = o instanceof Error ? o.message : "Unknown error";
583
- t.console.error(
584
- `[trails-sdk] Failed to send meta transaction ${r}`,
585
- {
586
- operationKey: r,
587
- error: h,
588
- chainId: s.chainId,
589
- metaTxnId: s.id,
590
- walletAddress: s.walletAddress,
591
- contract: s.contract
592
- }
593
- ), l.push({
594
- operationKey: r,
595
- error: h,
596
- success: !1
597
- });
598
- }
599
- }
600
- return l;
601
- },
602
- onSuccess: (e) => {
603
- t.console.log(
604
- "[trails-sdk] sendMetaTxn mutation completed successfully",
605
- {
606
- totalResults: e.length,
607
- successfulResults: e.filter((n) => n.success).length,
608
- failedResults: e.filter((n) => !n.success).length,
609
- results: e.map((n) => ({
610
- operationKey: n.operationKey,
611
- success: n.success,
612
- opHash: n.opHash || null,
613
- error: n.error || null
614
- }))
615
- }
616
- ), e.forEach(({ operationKey: n, opHash: a, success: l }) => {
617
- l && a ? (Ae((s) => ({
618
- ...s,
619
- [n]: Date.now()
620
- })), ye((s) => ({
621
- ...s,
622
- [n]: a
623
- }))) : t.console.warn(
624
- `[trails-sdk] Not updating state for failed meta transaction ${n}`,
625
- {
626
- operationKey: n,
627
- error: e.find((s) => s.operationKey === n)?.error
628
- }
629
- );
630
- });
631
- },
632
- onError: (e) => {
633
- t.console.error("[trails-sdk] Error in meta-transaction process", {
634
- error: e instanceof Error ? e.message : String(e),
635
- errorType: e instanceof Error ? e.constructor.name : typeof e,
636
- stack: e instanceof Error ? e.stack : void 0
637
- });
638
- },
639
- retry: 5,
640
- // Allow up to 2 retries
641
- retryDelay: (e) => Math.min(1e3 * 2 ** e, 3e4)
642
- // Exponential backoff
643
- }), [J, on] = c(null), [X, rn] = c(null);
644
- b(() => {
645
- if (!N || !y?.[0]?.chainId || !J || !X || !v || !d.address) {
646
- V(null);
770
+ const [te, tn] = d(null), [re, sn] = d(null);
771
+ P(() => {
772
+ if (!f || !L?.[0]?.chainId || !te || !re || !E || !i.address) {
773
+ q(null);
647
774
  return;
648
775
  }
649
776
  try {
650
- const e = N;
651
- if (!e || !Nn(e)) {
652
- V(null);
777
+ const e = f;
778
+ if (!e || !Fn(e)) {
779
+ q(null);
653
780
  return;
654
781
  }
655
- let n, a = "0x", l = 0n;
656
- const s = e;
657
- if (J === $e) {
658
- const m = v.find(
659
- (o) => (o.type === "transfer-native" || o.type === "native-balance") && o.chainId === X.toString()
660
- )?.data?.min?.toString();
661
- if (m === void 0)
662
- throw new Error(
663
- "Could not find native precondition (transfer-native or native-balance) or min amount"
664
- );
665
- l = BigInt(m), n = s;
782
+ let n, g = "0x", k = 0n;
783
+ const b = e;
784
+ if (te === he || te === Ln) {
785
+ const x = E.find(
786
+ (A) => (A.type === "transfer-native" || A.type === "native-balance") && A.chainId === re
787
+ )?.minAmount?.toString();
788
+ if (x === void 0)
789
+ throw new Error("Could not find precondition or min amount");
790
+ k = BigInt(x), n = b;
666
791
  } else {
667
- const m = v.find(
668
- (o) => o.type === "erc20-balance" && o.chainId === X.toString() && o.data?.token && ee(
669
- B(o.data.token),
670
- B(J)
792
+ const x = E.find(
793
+ (A) => A.type === "erc20-balance" && A.chainId === re && A.tokenAddress && ce(
794
+ se(A.tokenAddress),
795
+ se(te)
671
796
  )
672
- )?.data?.min?.toString();
673
- if (m === void 0)
674
- throw new Error(
675
- "Could not find ERC20 balance precondition or min amount"
676
- );
677
- a = xn({
678
- recipient: s,
679
- amount: BigInt(m)
680
- }), n = J;
797
+ )?.minAmount?.toString();
798
+ if (x === void 0)
799
+ throw new Error("Could not find precondition or min amount");
800
+ g = On({
801
+ recipient: b,
802
+ amount: BigInt(x)
803
+ }), n = te;
681
804
  }
682
- V({
805
+ q({
683
806
  to: n,
684
- data: a,
685
- value: l,
686
- chainId: X,
807
+ data: g,
808
+ value: k,
809
+ chainId: re,
687
810
  error: void 0
688
811
  });
689
812
  } catch (e) {
690
813
  t.console.error(
691
814
  "[trails-sdk] Failed to calculate origin call params for UI:",
692
815
  e
693
- ), V({
816
+ ), q({
694
817
  to: null,
695
818
  data: null,
696
819
  value: null,
@@ -699,313 +822,217 @@ function Qn(Be) {
699
822
  });
700
823
  }
701
824
  }, [
702
- y,
703
- J,
704
- X,
705
- v,
706
- d.address,
707
- N
825
+ L,
826
+ te,
827
+ re,
828
+ E,
829
+ i.address,
830
+ f
708
831
  ]);
709
- const P = Mn(
710
- u,
711
- me
832
+ const I = jn(
833
+ m ?? void 0,
834
+ o
712
835
  );
713
- $n(() => !u || Object.keys(P).length === 0 ? "no_statuses" : u.map((n) => `${n.chainId}-${n.id}`).sort().map((n) => {
714
- const a = P[n];
715
- return `${n}:${a ? a.status : "loading"}`;
716
- }).join(","), [u, P]);
717
- const ve = qe(/* @__PURE__ */ new Set()), Te = qe(null);
718
- b(() => {
719
- if (t.console.log(
720
- "[trails-sdk] Running meta-transaction block timestamp effect:",
721
- {
722
- metaTxnsLength: u?.length,
723
- monitorStatusesLength: Object.keys(P).length
724
- }
725
- ), !u || u.length === 0) {
726
- t.console.log(
727
- "[trails-sdk] No meta transactions, clearing timestamps"
728
- ), ve.current.clear(), Object.keys(ge).length > 0 && Y({});
836
+ P(() => {
837
+ if (t.console.log("[trails-sdk] Intent receipt status update:", {
838
+ intentId: m,
839
+ done: I.done,
840
+ hasReceipt: !!I.intentReceipt
841
+ }), !I.intentReceipt) {
842
+ t.console.log("[trails-sdk] No intent receipt yet, waiting...");
729
843
  return;
730
844
  }
731
- if (!Object.keys(P).length) {
732
- t.console.log("[trails-sdk] No monitor statuses yet, waiting...");
733
- return;
845
+ const e = {};
846
+ if (I.intentReceipt.originTransaction) {
847
+ const n = I.intentReceipt.originTransaction, g = `${n.chainId}-${n.metaTxnId}`;
848
+ e[g] = { timestamp: null };
734
849
  }
735
- u.forEach(async (e, n) => {
736
- const a = `${e.chainId}-${e.id}`;
737
- if (ve.current.has(a)) {
738
- t.console.log(
739
- `[trails-sdk] MetaTxn ${a}: Already processed, skipping`
740
- );
741
- return;
742
- }
743
- const l = P[a];
744
- if (!l || l.status !== "confirmed") {
745
- t.console.log(
746
- `[trails-sdk] MetaTxn ${a}: Status not confirmed, skipping`
747
- );
748
- return;
749
- }
750
- const s = l.transactionHash;
751
- if (!s) {
752
- t.console.log(
753
- `[trails-sdk] MetaTxn ${a}: No transaction hash, skipping`
754
- );
755
- return;
756
- }
757
- t.console.log(
758
- `[trails-sdk] MetaTxn ${a}: Processing transaction ${s}`
759
- ), ve.current.add(a);
760
- try {
761
- const r = parseInt(e.chainId, 10);
762
- if (Number.isNaN(r) || r <= 0)
763
- throw new Error(
764
- `Invalid chainId for meta transaction: ${e.chainId}`
765
- );
766
- const f = ce(r), m = Ne({
767
- chain: f,
768
- transport: Fe()
769
- }), o = await m.getTransactionReceipt({
770
- hash: s
771
- });
772
- if (o && typeof o.blockNumber == "bigint") {
773
- const h = await m.getBlock({
774
- blockNumber: o.blockNumber
850
+ if (I.intentReceipt.destinationTransaction) {
851
+ const n = I.intentReceipt.destinationTransaction, g = `${n.chainId}-${n.metaTxnId}`;
852
+ e[g] = { timestamp: null };
853
+ }
854
+ Ue(e);
855
+ }, [
856
+ I.intentReceipt,
857
+ I.done,
858
+ m
859
+ ]), P(() => {
860
+ if (I.done && I.intentReceipt && (t.console.log("[trails-sdk] Intent execution completed", {
861
+ intentId: m,
862
+ status: I.intentReceipt.status
863
+ }), I.intentReceipt.originTransaction?.txnHash)) {
864
+ const e = B?.quoteProvider ? String(B.quoteProvider).toLowerCase() : void 0, n = v.variables?.options?.quoteProvider ? String(
865
+ v.variables.options.quoteProvider
866
+ ).toLowerCase() : void 0;
867
+ if ((e === "cctp" || n === "cctp") && v.variables)
868
+ try {
869
+ Mn({
870
+ sourceTxHash: I.intentReceipt.originTransaction.txnHash,
871
+ sourceChainId: v.variables.originChainId,
872
+ destinationChainId: v.variables.destinationChainId,
873
+ trailsClient: o
775
874
  });
776
- t.console.log(
777
- `[trails-sdk] MetaTxn ${a}: Got block timestamp ${h.timestamp}`
778
- ), Y((p) => ({
779
- ...p,
780
- [a]: {
781
- timestamp: Number(h.timestamp),
782
- error: void 0
783
- }
784
- }));
785
- try {
786
- const p = A?.quoteProvider ? String(A.quoteProvider).toLowerCase() : void 0, Z = g.variables?.params.provider ? String(
787
- g.variables.params.provider
788
- ).toLowerCase() : void 0, re = p === "cctp" || Z === "cctp", D = g.variables?.params.originChainId, Ce = g.variables?.params.destinationChainId;
789
- t.console.log("[Trails] isCctp", re), t.console.log("[Trails] providerFromQuote", p), t.console.log("[Trails] providerFromArgs", Z), t.console.log("[Trails] trailsFee", A), t.console.log(
790
- "[Trails] createIntentMutation.variables",
791
- g.variables
792
- ), t.console.log(
793
- "[Trails] createIntentMutation.variables.params.provider",
794
- g.variables?.params.provider
795
- ), t.console.log(
796
- "[Trails] createIntentMutation.variables.params.originChainId",
797
- g.variables?.params.originChainId
798
- ), t.console.log(
799
- "[Trails] createIntentMutation.variables.params.destinationChainId",
800
- g.variables?.params.destinationChainId
801
- ), t.console.log(
802
- "[Trails] lastQueuedCctpSourceTxHash",
803
- Te.current
804
- ), t.console.log("[Trails] transactionHash", s), t.console.log(
805
- "[Trails] originChainIdForCctp",
806
- D
807
- ), t.console.log(
808
- "[Trails] destinationChainIdForCctp",
809
- Ce
810
- ), re && S && s && typeof D == "number" && typeof Ce == "number" && Te.current !== s && n === 0 && (Te.current = s, await On({
811
- trailsClient: S,
812
- sourceTxHash: s,
813
- sourceChainId: D,
814
- destinationChainId: Ce
815
- }));
816
- } catch (p) {
817
- t.console.error(
818
- `[trails-sdk] Queue CCTP on meta-tx error (${a}):`,
819
- p
820
- );
821
- }
822
- } else
823
- t.console.warn(
824
- `[trails-sdk] MetaTxn ${a}: No block number in receipt`
825
- ), Y((h) => ({
826
- ...h,
827
- [a]: {
828
- timestamp: null,
829
- error: "Block number not found in receipt"
830
- }
831
- }));
832
- } catch (r) {
833
- t.console.error(
834
- `[trails-sdk] MetaTxn ${a}: Error:`,
835
- r
836
- ), Y((f) => ({
837
- ...f,
838
- [a]: {
839
- timestamp: null,
840
- error: r.message || "Failed to fetch receipt/timestamp"
841
- }
842
- }));
843
- }
844
- });
875
+ } catch (k) {
876
+ t.console.error("[Trails] queueCCTPTransfer error", k);
877
+ }
878
+ }
845
879
  }, [
846
- u,
847
- P,
848
- ge,
849
- A,
850
- g.variables,
851
- S
880
+ I.done,
881
+ I.intentReceipt,
882
+ m,
883
+ B,
884
+ v.variables,
885
+ o
852
886
  ]);
853
- const cn = (e) => {
854
- ne(e);
887
+ const on = (e) => {
888
+ N(e);
855
889
  };
856
- function ln(e) {
857
- g.mutate({
858
- ...e,
859
- destinationSalt: Date.now().toString()
860
- });
890
+ function rn(e) {
891
+ v.mutate(e);
861
892
  }
862
- function dn(e) {
863
- t.console.log("[trails-sdk] commitIntentConfig", e), I.mutate(e);
893
+ function an(e) {
894
+ t.console.log("[trails-sdk] commitIntent", e), S.mutate(e);
864
895
  }
865
- function un(e) {
896
+ function cn(e) {
866
897
  if (!e) {
867
- V(null);
898
+ q(null);
868
899
  return;
869
900
  }
870
- const { originChainId: n, tokenAddress: a } = e;
871
- rn(n), on(a);
901
+ const { originChainId: n, tokenAddress: g } = e;
902
+ sn(n), tn(g);
872
903
  }
873
- function gn(e) {
874
- H.mutate({ selectedId: e });
904
+ const { chainId: ln } = i, qe = s?.chainId, dn = v.isPending, un = v.isSuccess, gn = v.error, mn = v.variables, fn = S.isPending, In = S.isSuccess, hn = S.error, pn = S.variables, vn = ee.isPending, Tn = ee.isSuccess, An = ee.error;
905
+ function Cn(e) {
906
+ ee.mutate(e);
875
907
  }
876
- const { chainId: mn } = d, Ee = i?.chainId, fn = g.isPending, hn = g.isSuccess, In = g.error, pn = g.variables, vn = I.isPending, Tn = I.isSuccess, Cn = I.error, Sn = I.variables, An = H.isPending, yn = H.isSuccess, wn = H.error, kn = H.variables;
877
908
  return {
878
- trailsClient: S,
879
- metaTxns: u,
880
- intentCallsPayloads: y,
881
- intentPreconditions: v,
882
- trailsFee: A,
883
- txnHash: T,
884
- committedOriginIntentAddress: $,
885
- committedDestinationIntentAddress: _e,
886
- verificationStatus: Je,
887
- getRelayer: me,
888
- estimatedGas: ae,
889
- isEstimateError: fe,
890
- estimateError: he,
891
- calculateIntentAddress: Me,
892
- calculateOriginAndDestinationIntentAddresses: Pe,
893
- committedIntentConfig: Ze,
894
- isLoadingCommittedConfig: en,
895
- committedConfigError: nn,
896
- commitIntentConfig: dn,
897
- commitIntentConfigPending: vn,
898
- commitIntentConfigSuccess: Tn,
899
- commitIntentConfigError: Cn,
900
- commitIntentConfigArgs: Sn,
901
- getIntentCallsPayloads: be,
902
- operationHashes: Qe,
903
- callIntentCallsPayload: tn,
904
- sendOriginTransaction: an,
905
- switchChain: Ve,
906
- isSwitchingChain: Ke,
907
- switchChainError: z,
908
- isTransactionInProgress: te,
909
- isChainSwitchRequired: mn !== Ee && !!Ee,
910
- sendTransaction: E.sendTransaction,
911
- isSendingTransaction: E.isPending,
912
- originCallStatus: w,
913
- updateOriginCallStatus: k,
914
- isEstimatingGas: ze,
915
- isAutoExecute: x,
916
- updateAutoExecute: cn,
917
- receipt: C,
918
- isWaitingForReceipt: U,
919
- receiptIsSuccess: Ie,
920
- receiptIsError: pe,
921
- receiptError: oe,
922
- hasAutoExecuted: le,
923
- originCallSuccess: E.isSuccess,
924
- sentMetaTxns: j,
925
- sendMetaTxn: gn,
926
- sendMetaTxnPending: An,
927
- sendMetaTxnSuccess: yn,
928
- sendMetaTxnError: wn,
929
- sendMetaTxnArgs: kn,
930
- clearIntent: sn,
931
- metaTxnMonitorStatuses: P,
932
- createIntent: ln,
933
- createIntentPending: fn,
934
- createIntentSuccess: hn,
935
- createIntentError: In,
936
- createIntentArgs: pn,
937
- originCallParams: i,
938
- updateOriginCallParams: un,
939
- originBlockTimestamp: Ye,
940
- metaTxnBlockTimestamps: ge,
941
- originIntentAddress: N,
942
- destinationIntentAddress: We
909
+ trailsClient: o,
910
+ metaTxns: D,
911
+ intentCallsPayloads: L,
912
+ intentPreconditions: E,
913
+ trailsFee: B,
914
+ txnHash: p,
915
+ committedOriginIntentAddress: m,
916
+ committedDestinationIntentAddress: le,
917
+ verificationStatus: Ve,
918
+ estimatedGas: me,
919
+ isEstimateError: Se,
920
+ estimateError: we,
921
+ calculateIntentAddress: Hn,
922
+ calculateOriginAndDestinationIntentAddresses: De,
923
+ committedIntentConfig: ze,
924
+ isLoadingCommittedConfig: Xe,
925
+ committedConfigError: Je,
926
+ commitIntent: an,
927
+ commitIntentPending: fn,
928
+ commitIntentSuccess: In,
929
+ commitIntentError: hn,
930
+ commitIntentArgs: pn,
931
+ executeIntent: Cn,
932
+ executeIntentPending: vn,
933
+ executeIntentSuccess: Tn,
934
+ executeIntentError: An,
935
+ getIntent: Ye,
936
+ operationHashes: de,
937
+ callIntentCallsPayload: Ze,
938
+ sendOriginTransaction: nn,
939
+ switchChain: Ae,
940
+ isSwitchingChain: Re,
941
+ switchChainError: Z,
942
+ isTransactionInProgress: J,
943
+ isChainSwitchRequired: ln !== qe && !!qe,
944
+ sendTransaction: a.sendTransaction,
945
+ isSendingTransaction: a.isPending,
946
+ originCallStatus: y,
947
+ updateOriginCallStatus: O,
948
+ isEstimatingGas: h,
949
+ isAutoExecute: C,
950
+ updateAutoExecute: on,
951
+ receipt: M,
952
+ isWaitingForReceipt: ne,
953
+ receiptIsSuccess: ye,
954
+ receiptIsError: ke,
955
+ receiptError: fe,
956
+ hasAutoExecuted: H,
957
+ originCallSuccess: a.isSuccess,
958
+ sentMetaTxns: $,
959
+ clearIntent: en,
960
+ intentReceiptStatus: I,
961
+ createIntent: rn,
962
+ createIntentPending: dn,
963
+ createIntentSuccess: un,
964
+ createIntentError: gn,
965
+ createIntentArgs: mn,
966
+ originCallParams: s,
967
+ updateOriginCallParams: cn,
968
+ originBlockTimestamp: We,
969
+ metaTxnBlockTimestamps: Ke,
970
+ originIntentAddress: f,
971
+ destinationIntentAddress: Te
943
972
  };
944
973
  }
945
974
  export {
946
- zn as TRAILS_ROUTER_PLACEHOLDER_AMOUNT,
947
- Yn as TradeType,
948
- Jn as TrailsClient,
949
- Xn as TrailsWidget,
950
- Me as calculateIntentAddress,
951
- Pe as calculateOriginAndDestinationIntentAddresses,
952
- Zn as commitIntentConfig,
953
- et as createModalController,
954
- nt as declareSequenceEnv,
955
- tt as getAPIClient,
956
- st as getAccountTotalBalanceUsd,
957
- it as getAccountTransactionHistory,
958
- at as getAllChains,
959
- ce as getChainInfo,
960
- ot as getDebug,
961
- xn as getERC20TransferData,
962
- rt as getHasSufficientBalanceToken,
963
- ct as getHasSufficientBalanceUsd,
964
- lt as getIndexerGatewayClient,
965
- Rn as getIntentCallsPayloads,
966
- dt as getIntentTransactionHistory,
967
- ut as getMetaTxnReceipt,
968
- gt as getMinLogLevel,
969
- mt as getRelayer,
970
- ft as getSequenceApiUrl,
971
- ht as getSequenceEnv,
972
- It as getSequenceIndexerUrl,
973
- pt as getSequenceNodeGatewayUrl,
974
- vt as getSequenceProjectAccessKey,
975
- Tt as getSlippageTolerance,
976
- Ct as getSupportedChains,
977
- St as getSupportedTokens,
978
- At as getTrailsApiUrl,
979
- yt as getTrailsClient,
980
- wt as getTxTimeDiff,
981
- kt as getWalletConnectProjectId,
975
+ Zn as InsufficientBalanceError,
976
+ et as TRAILS_ROUTER_PLACEHOLDER_AMOUNT,
977
+ Pn as TradeType,
978
+ nt as TrailsClient,
979
+ tt as TrailsWidget,
980
+ st as UserRejectionError,
981
+ Hn as calculateIntentAddress,
982
+ De as calculateOriginAndDestinationIntentAddresses,
983
+ it as commitIntent,
984
+ ot as createModalController,
985
+ rt as declareSequenceEnv,
986
+ at as getAccountTotalBalanceUsd,
987
+ ct as getAccountTransactionHistory,
988
+ lt as getAllChains,
989
+ xe as getChainInfo,
990
+ dt as getDebug,
991
+ On as getERC20TransferData,
992
+ ut as getHasSufficientBalanceToken,
993
+ gt as getHasSufficientBalanceUsd,
994
+ mt as getIndexerGatewayClient,
995
+ Fe as getIntent,
996
+ ft as getIntentTransactionHistory,
997
+ It as getIsUserRejectionError,
998
+ ht as getMinLogLevel,
999
+ pt as getSequenceEnv,
1000
+ vt as getSequenceIndexerUrl,
1001
+ Tt as getSequenceNodeGatewayUrl,
1002
+ At as getSequenceProjectAccessKey,
1003
+ Ct as getSlippageTolerance,
1004
+ St as getSupportedChains,
1005
+ wt as getSupportedTokens,
1006
+ yt as getTrailsApiUrl,
1007
+ kt as getTrailsClient,
1008
+ Et as getTxTimeDiff,
1009
+ bt as getWalletConnectProjectId,
982
1010
  t as logger,
983
- bt as prepareSend,
984
- Et as relayerSendMetaTx,
1011
+ xt as pollIntentReceipt,
1012
+ Rn as prepareSend,
985
1013
  Pt as sendOriginTransaction,
986
- xt as setDebug,
987
- Mt as setSequenceApiUrl,
988
- Ot as setSequenceEnv,
989
- Rt as setSequenceIndexerUrl,
990
- qt as setSequenceNodeGatewayUrl,
991
- $t as setSequenceProjectAccessKey,
992
- Nt as setSlippageTolerance,
993
- Ft as setTrailsApiUrl,
994
- Ut as setWalletConnectProjectId,
995
- Ht as useAPIClient,
996
- Dt as useAccountTotalBalanceUsd,
1014
+ Rt as setDebug,
1015
+ Ut as setSequenceEnv,
1016
+ qt as setSequenceIndexerUrl,
1017
+ Ot as setSequenceNodeGatewayUrl,
1018
+ Mt as setSequenceProjectAccessKey,
1019
+ Ht as setSlippageTolerance,
1020
+ Dt as setTrailsApiUrl,
1021
+ Ft as setWalletConnectProjectId,
1022
+ Lt as useAccountTotalBalanceUsd,
997
1023
  Bt as useAccountTransactionHistory,
998
- jt as useHasSufficientBalanceToken,
999
- Gt as useHasSufficientBalanceUsd,
1000
- Lt as useIndexerGatewayClient,
1001
- _t as useIntentTransactionHistory,
1002
- Mn as useMetaTxnsMonitor,
1003
- Wt as useQuote,
1004
- En as useRelayers,
1005
- Qt as useSupportedChains,
1006
- Vt as useSupportedTokens,
1007
- Kt as useTokenBalances,
1008
- zt as useTokenList,
1009
- Qn as useTrails,
1010
- bn as useTrailsClient
1024
+ je as useCommitIntent,
1025
+ Qe as useExecuteIntent,
1026
+ Nt as useHasSufficientBalanceToken,
1027
+ $t as useHasSufficientBalanceUsd,
1028
+ kn as useIndexerGatewayClient,
1029
+ jn as useIntentReceiptMonitor,
1030
+ Gt as useIntentTransactionHistory,
1031
+ zn as useQuote,
1032
+ jt as useSupportedChains,
1033
+ En as useSupportedTokens,
1034
+ Qt as useTokenBalances,
1035
+ Wt as useTokenList,
1036
+ Xn as useTrails,
1037
+ pe as useTrailsClient
1011
1038
  };