0xtrails 0.4.2 → 0.5.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 (81) hide show
  1. package/dist/{ccip-Dl3umoGg.js → ccip-DhEkQ6QC.js} +27 -27
  2. package/dist/cctpqueue.d.ts.map +1 -1
  3. package/dist/chains.d.ts +3 -1
  4. package/dist/chains.d.ts.map +1 -1
  5. package/dist/config.d.ts +17 -52
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/constants.d.ts +0 -6
  8. package/dist/constants.d.ts.map +1 -1
  9. package/dist/{index-sMS_ge1R.js → index-MhD2DA7_.js} +23613 -23893
  10. package/dist/index.d.ts +7 -7
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +319 -944
  13. package/dist/indexerClient.d.ts +9 -6
  14. package/dist/indexerClient.d.ts.map +1 -1
  15. package/dist/intents.d.ts +0 -1
  16. package/dist/intents.d.ts.map +1 -1
  17. package/dist/prepareSend.d.ts.map +1 -1
  18. package/dist/sequenceWallet.d.ts +1 -1
  19. package/dist/sequenceWallet.d.ts.map +1 -1
  20. package/dist/trailsClient.d.ts +3 -3
  21. package/dist/trailsClient.d.ts.map +1 -1
  22. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
  23. package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
  24. package/dist/transactionIntent/handlers/crossChain.d.ts +3 -1
  25. package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
  26. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
  27. package/dist/transactionIntent/types.d.ts +1 -0
  28. package/dist/transactionIntent/types.d.ts.map +1 -1
  29. package/dist/transactions.d.ts +8 -2
  30. package/dist/transactions.d.ts.map +1 -1
  31. package/dist/wallets.d.ts.map +1 -1
  32. package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
  33. package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
  34. package/dist/widget/components/FeeOptions.d.ts.map +1 -1
  35. package/dist/widget/components/SlippageToleranceSettings.d.ts +1 -0
  36. package/dist/widget/components/SlippageToleranceSettings.d.ts.map +1 -1
  37. package/dist/widget/components/WalletConnect.d.ts.map +1 -1
  38. package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
  39. package/dist/widget/hooks/useQuote.d.ts +2 -4
  40. package/dist/widget/hooks/useQuote.d.ts.map +1 -1
  41. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  42. package/dist/widget/index.d.ts +1 -0
  43. package/dist/widget/index.d.ts.map +1 -1
  44. package/dist/widget/index.js +4 -2
  45. package/dist/widget/providers/TrailsProvider.d.ts +18 -0
  46. package/dist/widget/providers/TrailsProvider.d.ts.map +1 -0
  47. package/dist/widget/widget.d.ts +3 -3
  48. package/dist/widget/widget.d.ts.map +1 -1
  49. package/package.json +3 -2
  50. package/src/analytics.ts +2 -2
  51. package/src/cctpqueue.ts +6 -3
  52. package/src/chains.ts +62 -29
  53. package/src/config.ts +36 -210
  54. package/src/constants.ts +0 -9
  55. package/src/index.ts +12 -35
  56. package/src/indexerClient.ts +39 -48
  57. package/src/intents.ts +0 -21
  58. package/src/prepareSend.ts +16 -2
  59. package/src/sequenceWallet.ts +1 -2
  60. package/src/trailsClient.ts +17 -12
  61. package/src/transactionIntent/deposits/gaslessDeposit.ts +88 -43
  62. package/src/transactionIntent/deposits/standardDeposit.ts +91 -53
  63. package/src/transactionIntent/handlers/crossChain.ts +88 -0
  64. package/src/transactionIntent/handlers/sameChainSameToken.ts +22 -0
  65. package/src/transactionIntent/types.ts +1 -0
  66. package/src/transactions.ts +122 -24
  67. package/src/wallets.ts +5 -6
  68. package/src/widget/components/AccountIntentTransactionHistory.tsx +5 -0
  69. package/src/widget/components/ConfigDisplay.tsx +19 -59
  70. package/src/widget/components/FeeOptions.tsx +1 -1
  71. package/src/widget/components/SlippageToleranceSettings.tsx +63 -14
  72. package/src/widget/components/WalletConnect.tsx +37 -99
  73. package/src/widget/hooks/useIntentTransactionHistory.ts +9 -1
  74. package/src/widget/hooks/useQuote.ts +11 -17
  75. package/src/widget/hooks/useSendForm.ts +4 -0
  76. package/src/widget/index.tsx +8 -0
  77. package/src/widget/providers/TrailsProvider.tsx +95 -0
  78. package/src/widget/widget.tsx +49 -98
  79. package/dist/trails.d.ts +0 -110
  80. package/dist/trails.d.ts.map +0 -1
  81. package/src/trails.ts +0 -1303
package/dist/index.js CHANGED
@@ -1,358 +1,361 @@
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-sMS_ge1R.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-sMS_ge1R.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 h, t as se, a as oe, b as re, I as ae, g as T, c as ie, d as ce, e as le, f as ue, h as de, T as ge, p as me, i as q, j as pe, k as S } from "./index-MhD2DA7_.js";
2
+ import { m as Re, P as Le, _ as Oe, X as Me, a0 as qe, U as Ne, s as He, v as Be, w as Pe, $ as Fe, E as Qe, B as _e, r as Je, W as $e, R as Ge, V as Ke, Q as We, F as je, G as ze, A as Ve, n as Xe, Y as Ye, S as Ze, o as et, M as tt, Z as nt, O as st, z as ot, x as rt, y as at, H as it, C as ct, J as lt, K as ut, D as dt, q as gt, L as mt, N as pt } from "./index-MhD2DA7_.js";
3
+ import { useQuery as B, useMutation as P } from "@tanstack/react-query";
4
+ import { useIndexerGatewayClient as fe } from "@0xsequence/hooks";
5
+ import { useIndexerGatewayClient as Et } from "@0xsequence/hooks";
6
+ import { useRef as Ee } from "react";
7
+ import { zeroAddress as N } from "viem";
8
+ const H = 150, Ue = (i, e) => {
9
+ const t = B({
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) : H;
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 Ce() {
46
+ const i = h();
47
+ return P({
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.calls[0]?.chainId, n = e.calls[1]?.chainId;
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
+ se({
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
+ }), oe({
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 re({
73
+ error: T(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 ke() {
84
+ const i = h();
85
+ return P({
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 ae && 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 ve({
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: F,
153
+ checkoutOnHandlers: Q,
154
+ quoteProvider: w,
155
+ paymasterUrl: _,
156
+ selectedFeeToken: U,
157
+ nodeGatewayEnv: v,
158
+ abortSignal: D,
159
+ apiKey: J
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 = Ee(new AbortController()), $ = 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: G, trailsApiUrl: K, sequenceIndexerUrl: W } = ie(), g = h({
170
+ apiKey: G,
171
+ hostname: K
172
+ }), E = fe(), { supportedTokens: p } = ce(), j = Ce(), z = ke(), { data: x, isLoading: V, error: R, refetch: X } = B({
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
+ J
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 le({
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 = T(a), f = l.includes("Cross-Origin") || l.includes("CORS") || l.includes("Same Origin Policy"), ne = l.includes("fetch failed") || l.includes("network");
202
+ if (f || ne)
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 Y = u.find(
214
+ (a) => a.chainId === t && (a.contractAddress?.toLowerCase() === e.toLowerCase() || !a.contractAddress && e === N)
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 = ue(t)?.nativeCurrency?.symbol ?? "";
219
+ l && (C = (await de(g, {
220
+ tokenSymbol: l,
221
+ tokenAddress: N,
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
+ ), L = k?.decimals;
242
+ if (!L)
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 O = y?.decimals;
252
+ if (!O)
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 Z = y?.symbol ?? "", ee = k?.symbol ?? "", M = {
262
+ account: i.account,
263
+ originTokenAddress: e,
264
+ originChainId: t,
265
+ originTokenBalance: Y,
266
+ destinationChainId: s,
267
+ recipient: m,
268
+ destinationTokenAddress: n,
269
+ swapAmount: c.toString(),
270
+ tradeType: I ?? ge.EXACT_OUTPUT,
271
+ originTokenSymbol: ee,
272
+ destinationTokenSymbol: Z,
273
+ destinationCalldata: A,
274
+ client: i,
275
+ trailsClient: g,
276
+ sourceTokenDecimals: L,
277
+ destinationTokenDecimals: O,
276
278
  fee: "0",
277
279
  dryMode: !1,
278
- onTransactionStateChange: he ?? (() => {
280
+ onTransactionStateChange: F ?? (() => {
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: _,
285
+ selectedFeeToken: U ?? void 0,
286
+ abortSignal: $,
287
+ originNativeTokenPriceUsd: C,
288
+ commitIntentFn: j.mutateAsync,
289
+ executeIntentFn: z.mutateAsync,
290
+ checkoutOnHandlers: Q,
291
+ sequenceIndexerUrl: W
289
292
  };
290
- t.console.log("[trails-sdk] options", G);
291
- const { quote: r, send: Ae } = await Rn(G);
293
+ r.console.log("[trails-sdk] options", M);
294
+ const { quote: o, send: te } = await me(M);
292
295
  return {
293
296
  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
297
+ fromAmount: o.originAmount,
298
+ toAmount: o.destinationAmount,
299
+ fromAmountMin: o.originAmountMin,
300
+ toAmountMin: o.destinationAmountMin,
301
+ originToken: o.originToken,
302
+ destinationToken: o.destinationToken,
303
+ originChain: o.originChain,
304
+ destinationChain: o.destinationChain,
305
+ fees: o.fees,
306
+ priceImpact: o.priceImpact,
307
+ completionEstimateSeconds: o.completionEstimateSeconds,
308
+ slippageTolerance: o.slippageTolerance,
309
+ transactionStates: o.transactionStates,
310
+ originTokenRate: o.originTokenRate,
311
+ destinationTokenRate: o.destinationTokenRate,
312
+ quoteProvider: o.quoteProvider,
313
+ fromAmountUsdDisplay: o.originAmountUsdDisplay ?? void 0,
314
+ toAmountUsdDisplay: o.destinationAmountUsdDisplay ?? void 0,
315
+ gasCostUsd: o.gasCostUsd ?? void 0,
316
+ gasCostUsdDisplay: o.gasCostUsdDisplay ?? void 0,
317
+ gasCost: o.gasCost ?? void 0,
318
+ gasCostFormatted: o.gasCostFormatted ?? void 0
316
319
  },
317
320
  swap: async () => {
318
321
  const {
319
- depositUserTxnReceipt: c,
320
- destinationMetaTxnReceipt: h,
321
- totalCompletionSeconds: $
322
- } = await Ae({
323
- selectedFeeToken: R ?? void 0
322
+ depositUserTxnReceipt: a,
323
+ destinationMetaTxnReceipt: l,
324
+ totalCompletionSeconds: f
325
+ } = await te({
326
+ selectedFeeToken: U ?? void 0
324
327
  });
325
328
  return {
326
329
  originTransaction: {
327
- transactionHash: c?.transactionHash,
328
- explorerUrl: Fe({
329
- txHash: c?.transactionHash,
330
- chainId: a
330
+ transactionHash: a?.transactionHash,
331
+ explorerUrl: q({
332
+ txHash: a?.transactionHash,
333
+ chainId: t
331
334
  }),
332
- receipt: c
335
+ receipt: a
333
336
  },
334
337
  destinationTransaction: {
335
- transactionHash: h?.txnHash,
336
- explorerUrl: Fe({
337
- txHash: h?.txnHash,
338
- chainId: o
338
+ transactionHash: l?.txnHash,
339
+ explorerUrl: q({
340
+ txHash: l?.txnHash,
341
+ chainId: s
339
342
  }),
340
- receipt: h
343
+ receipt: l
341
344
  },
342
- totalCompletionSeconds: $
345
+ totalCompletionSeconds: f
343
346
  };
344
347
  }
345
348
  };
346
- } catch (s) {
347
- throw t.console.error(
349
+ } catch (u) {
350
+ throw r.console.error(
348
351
  "[trails-sdk] [useQuote] Error getting quote:",
349
- s
350
- ), Ue(s);
352
+ u
353
+ ), T(u);
351
354
  }
352
355
  },
353
356
  // Prevent unnecessary refetching
354
- enabled: !!(g && D && i && l && d && F && a && o && m && // !isLoadingTokens &&
355
- k && k.length > 0),
357
+ enabled: !!(i && g && e && n && c && m && t && s && E && // !isLoadingTokens &&
358
+ p && p.length > 0),
356
359
  staleTime: 30 * 1e3,
357
360
  // Consider data fresh for 30 seconds
358
361
  refetchOnWindowFocus: !1,
@@ -367,700 +370,72 @@ function Kn({
367
370
  // Refetch when network reconnects
368
371
  });
369
372
  return {
370
- quote: O?.quote || null,
371
- swap: O?.swap || null,
372
- isLoadingQuote: J,
373
- quoteError: le,
374
- quoteErrorPrettified: qn(le),
375
- refetchQuote: () => z(),
373
+ quote: x?.quote || null,
374
+ swap: x?.swap || null,
375
+ isLoadingQuote: V,
376
+ quoteError: R,
377
+ quoteErrorPrettified: pe(R),
378
+ refetchQuote: () => X(),
376
379
  abort: () => {
377
- t.console.log("[trails-sdk] useQuote abort() called"), t.console.log(
380
+ r.console.log("[trails-sdk] useQuote abort() called"), r.console.log(
378
381
  "[trails-sdk] Active operations before abort:",
379
- Pe.getAll()
380
- ), S.current.abort(), Pe.abortAll(), t.console.log(
382
+ S.getAll()
383
+ ), d.current.abort(), S.abortAll(), r.console.log(
381
384
  "[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
385
+ S.getAll()
421
386
  );
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
387
  }
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
388
  };
1001
389
  }
1002
390
  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
391
+ Re as InsufficientBalanceError,
392
+ Le as TRAILS_ROUTER_PLACEHOLDER_AMOUNT,
393
+ ge as TradeType,
394
+ Oe as TrailsClient,
395
+ Me as TrailsProvider,
396
+ qe as TrailsWidget,
397
+ Ne as UserRejectionError,
398
+ He as calculateIntentAddress,
399
+ Be as calculateOriginAndDestinationIntentAddresses,
400
+ Pe as commitIntent,
401
+ Fe as createModalController,
402
+ Qe as getAccountTotalBalanceUsd,
403
+ _e as getAccountTransactionHistory,
404
+ Je as getAllChains,
405
+ ue as getChainInfo,
406
+ $e as getCommitHash,
407
+ Ge as getConfig,
408
+ Ke as getDebug,
409
+ We as getERC20TransferData,
410
+ je as getHasSufficientBalanceToken,
411
+ ze as getHasSufficientBalanceUsd,
412
+ Ve as getIntentTransactionHistory,
413
+ Xe as getIsUserRejectionError,
414
+ Ye as getMinLogLevel,
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
+ me as prepareSend,
423
+ rt as quoteIntent,
424
+ at as sendOriginTransaction,
425
+ it as useAccountTotalBalanceUsd,
426
+ ct as useAccountTransactionHistory,
427
+ Ce as useCommitIntent,
428
+ ke as useExecuteIntent,
429
+ lt as useHasSufficientBalanceToken,
430
+ ut as useHasSufficientBalanceUsd,
431
+ Et as useIndexerGatewayClient,
432
+ Ue as useIntentReceiptMonitor,
433
+ dt as useIntentTransactionHistory,
434
+ ve as useQuote,
435
+ gt as useSupportedChains,
436
+ ce as useSupportedTokens,
437
+ mt as useTokenBalances,
438
+ pt as useTokenList,
439
+ ie as useTrails,
440
+ h as useTrailsClient
1066
441
  };