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