0xtrails 0.7.0 → 0.8.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 (102) hide show
  1. package/dist/{ccip-fConRNoG.js → ccip-uMWNlvmJ.js} +34 -34
  2. package/dist/fees.d.ts.map +1 -1
  3. package/dist/{index-BbajxCG_.js → index-BiPwqVkZ.js} +31527 -28874
  4. package/dist/index.d.ts +8 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +478 -456
  7. package/dist/intents.d.ts +10 -4
  8. package/dist/intents.d.ts.map +1 -1
  9. package/dist/prepareSend.d.ts +1 -1
  10. package/dist/prepareSend.d.ts.map +1 -1
  11. package/dist/prices.d.ts +2 -2
  12. package/dist/prices.d.ts.map +1 -1
  13. package/dist/refund.d.ts +116 -0
  14. package/dist/refund.d.ts.map +1 -0
  15. package/dist/tokenBalances.d.ts +1 -1
  16. package/dist/tokenBalances.d.ts.map +1 -1
  17. package/dist/transactionIntent/handlers/crossChain.d.ts +4 -3
  18. package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
  19. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +3 -3
  20. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
  21. package/dist/transactionIntent/quote/normalizeQuote.d.ts +1 -2
  22. package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
  23. package/dist/transactionIntent/quote/quoteHelpers.d.ts +3 -3
  24. package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
  25. package/dist/transactionIntent/types.d.ts +5 -4
  26. package/dist/transactionIntent/types.d.ts.map +1 -1
  27. package/dist/transactions.d.ts +4 -0
  28. package/dist/transactions.d.ts.map +1 -1
  29. package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
  30. package/dist/widget/components/ClassicSwap.d.ts +2 -1
  31. package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
  32. package/dist/widget/components/Earn.d.ts +2 -1
  33. package/dist/widget/components/Earn.d.ts.map +1 -1
  34. package/dist/widget/components/ErrorDisplay.d.ts.map +1 -1
  35. package/dist/widget/components/Fund.d.ts +2 -1
  36. package/dist/widget/components/Fund.d.ts.map +1 -1
  37. package/dist/widget/components/FundSwap.d.ts +2 -1
  38. package/dist/widget/components/FundSwap.d.ts.map +1 -1
  39. package/dist/widget/components/Pay.d.ts +2 -1
  40. package/dist/widget/components/Pay.d.ts.map +1 -1
  41. package/dist/widget/components/PoolDeposit.d.ts +2 -1
  42. package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
  43. package/dist/widget/components/QuoteDetails.d.ts +1 -0
  44. package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
  45. package/dist/widget/components/Swap.d.ts +2 -1
  46. package/dist/widget/components/Swap.d.ts.map +1 -1
  47. package/dist/widget/components/TokenImage.d.ts.map +1 -1
  48. package/dist/widget/components/TransactionDetails.d.ts.map +1 -1
  49. package/dist/widget/css/compiled.css +1 -1
  50. package/dist/widget/hooks/useAmountUsd.d.ts.map +1 -1
  51. package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
  52. package/dist/widget/hooks/useGetIntent.d.ts +18 -0
  53. package/dist/widget/hooks/useGetIntent.d.ts.map +1 -0
  54. package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
  55. package/dist/widget/hooks/useQuote.d.ts +10 -7
  56. package/dist/widget/hooks/useQuote.d.ts.map +1 -1
  57. package/dist/widget/hooks/useSendForm.d.ts +3 -2
  58. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  59. package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
  60. package/dist/widget/hooks/useTrailsSendTransaction.d.ts.map +1 -1
  61. package/dist/widget/index.js +3 -3
  62. package/dist/widget/widget.d.ts +2 -1
  63. package/dist/widget/widget.d.ts.map +1 -1
  64. package/package.json +5 -12
  65. package/src/fees.ts +8 -2
  66. package/src/index.ts +33 -1
  67. package/src/intents.ts +34 -7
  68. package/src/prepareSend.ts +6 -4
  69. package/src/prices.ts +6 -6
  70. package/src/refund.ts +914 -0
  71. package/src/tokenBalances.ts +4 -14
  72. package/src/transactionIntent/handlers/crossChain.ts +21 -10
  73. package/src/transactionIntent/handlers/sameChainSameToken.ts +12 -8
  74. package/src/transactionIntent/quote/normalizeQuote.ts +29 -27
  75. package/src/transactionIntent/quote/quoteHelpers.ts +5 -9
  76. package/src/transactionIntent/types.ts +5 -3
  77. package/src/transactions.ts +5 -0
  78. package/src/widget/compiled.css +1 -1
  79. package/src/widget/components/AccountIntentTransactionHistory.tsx +197 -5
  80. package/src/widget/components/ClassicSwap.tsx +6 -3
  81. package/src/widget/components/Earn.tsx +6 -3
  82. package/src/widget/components/ErrorDisplay.tsx +6 -4
  83. package/src/widget/components/Fund.tsx +6 -3
  84. package/src/widget/components/FundSwap.tsx +2 -1
  85. package/src/widget/components/Pay.tsx +15 -7
  86. package/src/widget/components/PoolDeposit.tsx +6 -3
  87. package/src/widget/components/QuoteDetails.tsx +34 -38
  88. package/src/widget/components/Swap.tsx +2 -1
  89. package/src/widget/components/TokenImage.tsx +3 -1
  90. package/src/widget/components/TransactionDetails.tsx +108 -0
  91. package/src/widget/hooks/useAmountUsd.ts +0 -3
  92. package/src/widget/hooks/useDefaultTokenSelection.tsx +0 -3
  93. package/src/widget/hooks/useGetIntent.ts +53 -0
  94. package/src/widget/hooks/useIntentTransactionHistory.ts +85 -3
  95. package/src/widget/hooks/useQuote.ts +16 -10
  96. package/src/widget/hooks/useSendForm.ts +30 -15
  97. package/src/widget/hooks/useTokenList.ts +2 -4
  98. package/src/widget/hooks/useTrailsSendTransaction.ts +2 -1
  99. package/src/widget/widget.tsx +12 -6
  100. package/dist/sequenceWallet.d.ts +0 -67
  101. package/dist/sequenceWallet.d.ts.map +0 -1
  102. package/src/sequenceWallet.ts +0 -532
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
- import { l as o, u as dt, t as Ht, T as vt, a as Lt, b as qt, g as B, I as bt, c as Et, d as ht, e as pt, f as yt, h as lt, i as It, j, p as St, k as G, m as Nt, n as ft, o as Bt, q as mt, r as Ct } from "./index-BbajxCG_.js";
2
- import { s as ee, ab as ne, ag as oe, ak as se, aj as re, ad as ie, ai as ae, U as ce, L as le, M as de, N as ue, a5 as ge, ah as fe, a6 as me, a8 as Te, a9 as ke, a7 as he, W as Ce, R as Ae, H as Ee, K as pe, ac as ye, X as Ie, w as Se, v as we, D as Ue, z as De, A as xe, C as Pe, B as Re, x as Oe, y as He, E as ve, ae as Le, J as qe, F as be, a0 as Ne, af as Be, aa as Fe, Q as Me, O as Qe, P as We, Y as $e, S as _e, a2 as je, Z as Ge, _ as Je, V as Ke, G as Xe, a3 as ze, $ as Ve, a4 as Ye, a1 as Ze } from "./index-BbajxCG_.js";
3
- import { useQuery as wt, useMutation as Tt } from "@tanstack/react-query";
4
- import { useRef as Ut, useCallback as ct } from "react";
1
+ import { l as o, u as gt, t as Ot, T as Ht, a as Lt, b as bt, g as M, I as qt, c as pt, d as Ct, e as yt, f as It, h as ut, i as St, j as K, p as wt, k as J, m as Nt, n as ft, o as Bt, q as Tt, r as At } from "./index-BiPwqVkZ.js";
2
+ import { s as ee, am as ne, ar as oe, aB as se, aA as re, ao as ae, az as ie, U as ce, L as le, at as de, au as ue, ag as ge, M as me, N as fe, O as Te, a7 as ke, ay as he, aw as Ce, a8 as Ae, aa as Ee, ai as pe, ab as ye, a9 as Ie, Y as Se, S as we, H as Ue, K as Pe, an as De, Z as xe, as as Re, w as ve, v as Oe, D as He, z as Le, A as be, C as qe, B as Ne, x as Be, y as Fe, E as Me, ap as Qe, J as We, F as _e, a2 as $e, ac as Ge, aq as je, al as Ke, af as Je, ak as Xe, aj as ze, ah as Ve, R as Ye, P as Ze, Q as tn, av as en, _ as nn, V as on, X as sn, a4 as rn, $ as an, a0 as cn, W as ln, G as dn, a5 as un, a1 as gn, a6 as mn, a3 as fn, ad as Tn, ae as kn, ax as hn } from "./index-BiPwqVkZ.js";
3
+ import { useQuery as Ut, useMutation as kt } from "@tanstack/react-query";
4
+ import { useRef as Pt, useCallback as dt } from "react";
5
5
  import { useWalletClient as Ft, useAccount as Mt, useChainId as Qt } from "wagmi";
6
- import { zeroAddress as R, erc20Abi as Dt } from "viem";
6
+ import { zeroAddress as x, erc20Abi as Dt } from "viem";
7
7
  import { useIndexerGatewayClient as xt } from "@0xsequence/hooks";
8
- import { useIndexerGatewayClient as en } from "@0xsequence/hooks";
9
- const At = 150, zt = (d, n) => {
10
- const s = wt({
8
+ import { useIndexerGatewayClient as An } from "@0xsequence/hooks";
9
+ const Et = 150, zt = (d, n) => {
10
+ const s = Ut({
11
11
  queryKey: ["waitIntentReceipt", d],
12
12
  queryFn: async () => {
13
13
  if (!d)
@@ -25,14 +25,14 @@ const At = 150, zt = (d, n) => {
25
25
  enabled: !!d,
26
26
  refetchIntervalInBackground: !0,
27
27
  refetchInterval: (a) => {
28
- const c = a.state.data;
29
- return c && c.done ? (o.console.log(
28
+ const i = a.state.data;
29
+ return i && i.done ? (o.console.log(
30
30
  `[trails-sdk] ✅ Intent monitoring complete for ${d}`
31
- ), !1) : At;
31
+ ), !1) : Et;
32
32
  },
33
- retry: (a, c) => a >= 30 ? (o.console.error(
33
+ retry: (a, i) => a >= 30 ? (o.console.error(
34
34
  `[trails-sdk] ❌ Giving up on intent ${d} after 30 failed API attempts:`,
35
- c
35
+ i
36
36
  ), !1) : !0
37
37
  });
38
38
  return {
@@ -43,9 +43,9 @@ const At = 150, zt = (d, n) => {
43
43
  error: s.error
44
44
  };
45
45
  };
46
- function Pt() {
47
- const d = dt();
48
- return Tt({
46
+ function Rt() {
47
+ const d = gt();
48
+ return kt({
49
49
  mutationFn: async (n) => {
50
50
  o.console.log("[trails-sdk] useCommitIntent: Starting commit", {
51
51
  intentId: n.intentId,
@@ -53,40 +53,40 @@ function Pt() {
53
53
  });
54
54
  const s = n.quoteRequest.originChainId.toString(), a = n.quoteRequest.destinationChainId.toString();
55
55
  try {
56
- Ht({
56
+ Ot({
57
57
  intentAddress: n.originIntentAddress,
58
58
  userAddress: n.ownerAddress,
59
59
  originChainId: s ? Number(s) : void 0,
60
60
  destinationChainId: a ? Number(a) : void 0
61
61
  });
62
- const c = await d.commitIntent({
62
+ const i = await d.commitIntent({
63
63
  intent: n,
64
- trailsContracts: vt
64
+ trailsContracts: Ht
65
65
  });
66
66
  return o.console.log("[trails-sdk] useCommitIntent: Commit successful", {
67
67
  intentId: n.intentId,
68
- response: c
68
+ response: i
69
69
  }), Lt({
70
70
  intentAddress: n.originIntentAddress,
71
71
  userAddress: n.ownerAddress,
72
72
  originChainId: s ? Number(s) : void 0,
73
73
  destinationChainId: a ? Number(a) : void 0
74
- }), c;
75
- } catch (c) {
76
- throw qt({
77
- error: B(c),
74
+ }), i;
75
+ } catch (i) {
76
+ throw bt({
77
+ error: M(i),
78
78
  userAddress: n.ownerAddress,
79
79
  intentAddress: n.originIntentAddress,
80
80
  originChainId: s ? Number(s) : void 0,
81
81
  destinationChainId: a ? Number(a) : void 0
82
- }), c;
82
+ }), i;
83
83
  }
84
84
  }
85
85
  });
86
86
  }
87
- function Rt() {
88
- const d = dt();
89
- return Tt({
87
+ function vt() {
88
+ const d = gt();
89
+ return kt({
90
90
  mutationFn: async ({
91
91
  intentId: n,
92
92
  depositTransactionHash: s,
@@ -100,9 +100,9 @@ function Rt() {
100
100
  throw new Error(
101
101
  "[trails-sdk] Either depositTransactionHash or depositSignature must be provided"
102
102
  );
103
- let c;
103
+ let i;
104
104
  try {
105
- c = await d.executeIntent({
105
+ i = await d.executeIntent({
106
106
  intentId: n,
107
107
  depositTransactionHash: s,
108
108
  depositSignature: a
@@ -115,7 +115,7 @@ function Rt() {
115
115
  error: T,
116
116
  errorJSON: JSON.stringify(T, null, 2)
117
117
  }
118
- ), T instanceof Error && T?.message?.includes("status=SUCCEEDED") || T instanceof Error && T?.cause?.message?.includes("status=SUCCEEDED") || T instanceof Error && JSON.stringify(T).includes("status=SUCCEEDED") || T instanceof bt && T?.cause?.toString().includes("status=SUCCEEDED") || JSON.stringify(T).includes("status=SUCCEEDED"))
118
+ ), T instanceof Error && T?.message?.includes("status=SUCCEEDED") || T instanceof Error && T?.cause?.message?.includes("status=SUCCEEDED") || T instanceof Error && JSON.stringify(T).includes("status=SUCCEEDED") || T instanceof qt && T?.cause?.toString().includes("status=SUCCEEDED") || JSON.stringify(T).includes("status=SUCCEEDED"))
119
119
  return o.console.error(
120
120
  "[trails-sdk] useExecuteIntent: Intent already succeeded, treating as success",
121
121
  { intentId: n }
@@ -136,9 +136,9 @@ function Rt() {
136
136
  "[trails-sdk] useExecuteIntent: Execution successful",
137
137
  {
138
138
  intentId: n,
139
- response: c
139
+ response: i
140
140
  }
141
- ), c;
141
+ ), i;
142
142
  }
143
143
  });
144
144
  }
@@ -147,129 +147,131 @@ function Vt({
147
147
  fromTokenAddress: n,
148
148
  fromChainId: s,
149
149
  toTokenAddress: a,
150
- toChainId: c,
150
+ toChainId: i,
151
151
  swapAmount: T,
152
- tradeType: Z,
153
- toRecipient: v,
154
- toCalldata: tt,
155
- slippageTolerance: J,
156
- onStatusUpdate: K,
157
- checkoutOnHandlers: X,
158
- quoteProvider: F,
159
- paymasterUrl: M,
160
- selectedFeeOption: et,
161
- nodeGatewayEnv: nt,
162
- abortSignal: ot,
163
- apiKey: z,
164
- isSmartWallet: O
152
+ tradeType: nt,
153
+ toRecipient: O,
154
+ toCalldata: ot,
155
+ slippageTolerance: X,
156
+ onStatusUpdate: z,
157
+ checkoutOnHandlers: V,
158
+ swapProvider: Q,
159
+ bridgeProvider: H,
160
+ paymasterUrl: mt,
161
+ selectedFeeOption: st,
162
+ nodeGatewayEnv: rt,
163
+ abortSignal: W,
164
+ apiKey: L,
165
+ isSmartWallet: at
165
166
  } = {}) {
166
- nt && (globalThis.__testNodeGatewayEnv = nt);
167
- const H = Ut(new AbortController()), ut = ot ? (() => {
168
- const f = new AbortController();
169
- return ot.addEventListener("abort", () => {
170
- f.abort(), H.current?.abort();
171
- }), H.current?.signal.addEventListener("abort", () => {
172
- f.abort();
173
- }), f.signal;
174
- })() : H.current.signal, { trailsApiKey: Q, trailsApiUrl: p, sequenceIndexerUrl: st } = Et(), y = Q, P = dt({
175
- apiKey: Q,
176
- hostname: p
177
- }), V = xt(), Y = ht(s ?? void 0), t = ht(c ?? void 0), { supportedTokens: r } = pt(), u = Pt(), k = Rt(), { data: g, isLoading: I, error: U, refetch: D } = wt({
167
+ rt && (globalThis.__testNodeGatewayEnv = rt);
168
+ const R = Pt(new AbortController()), it = W ? (() => {
169
+ const g = new AbortController();
170
+ return W.addEventListener("abort", () => {
171
+ g.abort(), R.current?.abort();
172
+ }), R.current?.signal.addEventListener("abort", () => {
173
+ g.abort();
174
+ }), g.signal;
175
+ })() : R.current.signal, { trailsApiKey: C, trailsApiUrl: Y, sequenceIndexerUrl: A } = pt(), Z = C, b = gt({
176
+ apiKey: C,
177
+ hostname: Y
178
+ }), _ = xt(), t = Ct(s ?? void 0), r = Ct(i ?? void 0), { supportedTokens: u } = yt(), k = Rt(), m = vt(), { data: E, isLoading: P, error: w, refetch: I } = Ut({
178
179
  queryKey: [
179
180
  "prepareSend",
180
181
  n,
181
182
  s,
182
183
  a,
183
- c,
184
+ i,
184
185
  T?.toString(),
185
- v,
186
- tt,
187
- Z,
188
- J,
189
- F,
190
- z,
191
- O
186
+ O,
187
+ ot,
188
+ nt,
189
+ X,
190
+ Q,
191
+ H,
192
+ L,
193
+ at
192
194
  ],
193
195
  queryFn: async () => {
194
196
  try {
195
- if (H.current.signal.aborted && (o.console.log(
197
+ if (R.current.signal.aborted && (o.console.log(
196
198
  "[trails-sdk] Resetting aborted controller for new query"
197
- ), H.current = new AbortController()), !d || !P || !n || !a || !T || !v || !s || !c || !V)
199
+ ), R.current = new AbortController()), !d || !b || !n || !a || !T || !O || !s || !i || !_)
198
200
  return null;
199
- let f = [];
201
+ let g = [];
200
202
  try {
201
- f = (await yt({
203
+ g = (await It({
202
204
  account: d.account.address,
203
- indexerGatewayClient: V,
204
- trailsClient: P
205
+ indexerGatewayClient: _,
206
+ trailsClient: b
205
207
  })).balances;
206
- } catch (i) {
207
- const m = B(i), x = m.includes("Cross-Origin") || m.includes("CORS") || m.includes("Same Origin Policy"), _ = m.includes("fetch failed") || m.includes("network");
208
- if (x || _)
208
+ } catch (l) {
209
+ const f = M(l), D = f.includes("Cross-Origin") || f.includes("CORS") || f.includes("Same Origin Policy"), j = f.includes("fetch failed") || f.includes("network");
210
+ if (D || j)
209
211
  o.console.warn(
210
212
  "[trails-sdk] [useQuote] Network or CORS error fetching balances, proceeding with quote using zero balance:",
211
213
  {
212
- error: m,
214
+ error: f,
213
215
  account: d.account.address
214
216
  }
215
- ), f = [];
217
+ ), g = [];
216
218
  else
217
- throw i;
219
+ throw l;
218
220
  }
219
- const E = f.find(
220
- (i) => i.chainId === s && (i.contractAddress?.toLowerCase() === n.toLowerCase() || !i.contractAddress && n === R)
221
+ const y = g.find(
222
+ (l) => l.chainId === s && (l.contractAddress?.toLowerCase() === n.toLowerCase() || !l.contractAddress && n === x)
221
223
  )?.balance ?? "0";
222
- let A = 0;
224
+ let v = 0;
223
225
  try {
224
- const m = lt(s)?.nativeCurrency?.symbol ?? "";
225
- m && (A = (await It(P, {
226
- tokenSymbol: m,
227
- tokenAddress: R,
226
+ const f = ut(s)?.nativeCurrency?.symbol ?? "";
227
+ f && (v = (await St(b, {
228
+ tokenSymbol: f,
229
+ tokenAddress: x,
228
230
  chainId: s
229
231
  }))?.priceUsd ?? 0, o.console.log(
230
232
  "[trails-sdk] [useQuote] Origin native token price:",
231
233
  {
232
234
  chainId: s,
233
- symbol: m,
234
- priceUsd: A
235
+ symbol: f,
236
+ priceUsd: v
235
237
  }
236
238
  ));
237
- } catch (i) {
239
+ } catch (l) {
238
240
  o.console.error(
239
241
  "[trails-sdk] [useQuote] Error getting origin native token price:",
240
- i
242
+ l
241
243
  );
242
244
  }
243
- const L = async (i, m) => {
245
+ const U = async (l, f) => {
244
246
  try {
245
- const x = m === s ? Y : m === c ? t : null;
246
- if (!x)
247
+ const D = f === s ? t : f === i ? r : null;
248
+ if (!D)
247
249
  return o.console.warn(
248
- `[trails-sdk] No RPC client available for chain ${m}`
250
+ `[trails-sdk] No RPC client available for chain ${f}`
249
251
  ), null;
250
- if (i.toLowerCase() === R.toLowerCase())
251
- return lt(m)?.nativeCurrency.decimals ?? 18;
252
- const _ = await x.readContract({
253
- address: i,
252
+ if (l.toLowerCase() === x.toLowerCase())
253
+ return ut(f)?.nativeCurrency.decimals ?? 18;
254
+ const j = await D.readContract({
255
+ address: l,
254
256
  abi: Dt,
255
257
  functionName: "decimals"
256
258
  });
257
259
  return o.console.log(
258
- `[trails-sdk] Fetched decimals on-chain for token ${i} on chain ${m}: ${_}`
259
- ), _;
260
- } catch (x) {
260
+ `[trails-sdk] Fetched decimals on-chain for token ${l} on chain ${f}: ${j}`
261
+ ), j;
262
+ } catch (D) {
261
263
  return o.console.error(
262
- `[trails-sdk] Error fetching decimals on-chain for token ${i} on chain ${m}:`,
263
- x
264
+ `[trails-sdk] Error fetching decimals on-chain for token ${l} on chain ${f}:`,
265
+ D
264
266
  ), null;
265
267
  }
266
- }, S = r?.find(
267
- (i) => i.contractAddress?.toLowerCase() === n?.toLowerCase() && i.chainId === s
268
- ), w = r?.find(
269
- (i) => i.contractAddress?.toLowerCase() === a?.toLowerCase() && i.chainId === c
268
+ }, S = u?.find(
269
+ (l) => l.contractAddress?.toLowerCase() === n?.toLowerCase() && l.chainId === s
270
+ ), q = u?.find(
271
+ (l) => l.contractAddress?.toLowerCase() === a?.toLowerCase() && l.chainId === i
270
272
  );
271
- let q = S?.decimals;
272
- if (!q && n && s) {
273
+ let N = S?.decimals;
274
+ if (!N && n && s) {
273
275
  o.console.warn(
274
276
  "[trails-sdk] [useQuote] Source token decimals not found in token list, fetching on-chain:",
275
277
  {
@@ -278,13 +280,13 @@ function Vt({
278
280
  fromChainId: s
279
281
  }
280
282
  );
281
- const i = await L(
283
+ const l = await U(
282
284
  n,
283
285
  s
284
286
  );
285
- i !== null && (q = i);
287
+ l !== null && (N = l);
286
288
  }
287
- if (!q)
289
+ if (!N)
288
290
  throw o.console.error(
289
291
  "[trails-sdk] [useQuote] Source token decimals not found:",
290
292
  {
@@ -293,143 +295,144 @@ function Vt({
293
295
  fromChainId: s
294
296
  }
295
297
  ), new Error("Source token decimals not found");
296
- let b = w?.decimals;
297
- if (!b && a && c) {
298
+ let B = q?.decimals;
299
+ if (!B && a && i) {
298
300
  o.console.warn(
299
301
  "[trails-sdk] Destination token decimals not found in token list, fetching on-chain:",
300
302
  {
301
- destinationToken: w,
303
+ destinationToken: q,
302
304
  toTokenAddress: a,
303
- toChainId: c
305
+ toChainId: i
304
306
  }
305
307
  );
306
- const i = await L(
308
+ const l = await U(
307
309
  a,
308
- c
310
+ i
309
311
  );
310
- i !== null && (b = i);
312
+ l !== null && (B = l);
311
313
  }
312
- if (!b)
314
+ if (!B)
313
315
  throw o.console.error(
314
316
  "[trails-sdk] Destination token decimals not found:",
315
317
  {
316
- destinationToken: w,
318
+ destinationToken: q,
317
319
  toTokenAddress: a,
318
- toChainId: c
320
+ toChainId: i
319
321
  }
320
322
  ), new Error("Destination token decimals not found");
321
- const rt = w?.symbol ?? "", it = S?.symbol ?? "", W = {
323
+ const ct = q?.symbol ?? "", tt = S?.symbol ?? "", et = {
322
324
  account: d.account,
323
325
  originTokenAddress: n,
324
326
  originChainId: s,
325
- originTokenBalance: E,
326
- destinationChainId: c,
327
- recipient: v,
327
+ originTokenBalance: y,
328
+ destinationChainId: i,
329
+ recipient: O,
328
330
  destinationTokenAddress: a,
329
331
  swapAmount: T.toString(),
330
- tradeType: Z ?? j.EXACT_OUTPUT,
331
- originTokenSymbol: it,
332
- destinationTokenSymbol: rt,
333
- destinationCalldata: tt,
332
+ tradeType: nt ?? K.EXACT_OUTPUT,
333
+ originTokenSymbol: tt,
334
+ destinationTokenSymbol: ct,
335
+ destinationCalldata: ot,
334
336
  client: d,
335
- trailsClient: P,
336
- sourceTokenDecimals: q,
337
- destinationTokenDecimals: b,
337
+ trailsClient: b,
338
+ sourceTokenDecimals: N,
339
+ destinationTokenDecimals: B,
338
340
  fee: "0",
339
341
  dryMode: !1,
340
- onTransactionStateChange: K ?? (() => {
342
+ onTransactionStateChange: z ?? (() => {
341
343
  }),
342
- slippageTolerance: J?.toString(),
343
- quoteProvider: F,
344
- paymasterUrl: M,
345
- selectedFeeOption: et ?? null,
346
- abortSignal: ut,
347
- originNativeTokenPriceUsd: A,
348
- commitIntentFn: u.mutateAsync,
349
- executeIntentFn: k.mutateAsync,
350
- checkoutOnHandlers: X,
351
- sequenceIndexerUrl: st,
352
- sequenceProjectAccessKey: y,
353
- originPublicClient: Y ?? void 0,
354
- destinationPublicClient: t ?? void 0,
355
- isSmartWallet: O ?? void 0,
356
- trailsApiKey: Q,
357
- trailsApiUrl: p
344
+ slippageTolerance: X?.toString(),
345
+ swapProvider: Q,
346
+ bridgeProvider: H,
347
+ paymasterUrl: mt,
348
+ selectedFeeOption: st ?? null,
349
+ abortSignal: it,
350
+ originNativeTokenPriceUsd: v,
351
+ commitIntentFn: k.mutateAsync,
352
+ executeIntentFn: m.mutateAsync,
353
+ checkoutOnHandlers: V,
354
+ sequenceIndexerUrl: A,
355
+ sequenceProjectAccessKey: Z,
356
+ originPublicClient: t ?? void 0,
357
+ destinationPublicClient: r ?? void 0,
358
+ isSmartWallet: at ?? void 0,
359
+ trailsApiKey: C,
360
+ trailsApiUrl: Y
358
361
  };
359
- o.console.log("[trails-sdk] options", W);
360
- const { quote: l, send: at } = await St(W);
362
+ o.console.log("[trails-sdk] options", et);
363
+ const { quote: c, send: lt } = await wt(et);
361
364
  return {
362
365
  quote: {
363
- fromAmount: l.originAmount,
364
- toAmount: l.destinationAmount,
365
- fromAmountMin: l.originAmountMin,
366
- toAmountMin: l.destinationAmountMin,
367
- originToken: l.originToken,
368
- destinationToken: l.destinationToken,
369
- originChain: l.originChain,
370
- destinationChain: l.destinationChain,
371
- fees: l.fees,
372
- priceImpact: l.priceImpact,
373
- priceImpactUsd: l.priceImpactUsd ?? void 0,
374
- priceImpactUsdDisplay: l.priceImpactUsdDisplay ?? void 0,
375
- completionEstimateSeconds: l.completionEstimateSeconds,
376
- slippageTolerance: l.slippageTolerance,
377
- transactionStates: l.transactionStates,
378
- originTokenRate: l.originTokenRate,
379
- destinationTokenRate: l.destinationTokenRate,
380
- quoteProvider: l.quoteProvider,
381
- fromAmountUsdDisplay: l.originAmountUsdDisplay ?? void 0,
382
- toAmountUsdDisplay: l.destinationAmountUsdDisplay ?? void 0,
383
- gasCostUsd: l.gasCostUsd ?? void 0,
384
- gasCostUsdDisplay: l.gasCostUsdDisplay ?? void 0,
385
- gasCost: l.gasCost ?? void 0,
386
- gasCostFormatted: l.gasCostFormatted ?? void 0,
387
- totalFeesUsd: l.grandTotalUsd ?? void 0,
388
- totalFeesUsdDisplay: l.grandTotalUsdDisplay ?? void 0,
389
- totalGasUsd: l.totalGasUsd ?? void 0,
390
- totalGasUsdDisplay: l.totalGasUsdDisplay ?? void 0,
391
- allProviderFeesUsd: l.allProviderFeesUsd ?? void 0,
392
- allProviderFeesUsdDisplay: l.allProviderFeesUsdDisplay ?? void 0
366
+ fromAmount: c.originAmount,
367
+ toAmount: c.destinationAmount,
368
+ fromAmountMin: c.originAmountMin,
369
+ toAmountMin: c.destinationAmountMin,
370
+ originToken: c.originToken,
371
+ destinationToken: c.destinationToken,
372
+ originChain: c.originChain,
373
+ destinationChain: c.destinationChain,
374
+ fees: c.fees,
375
+ priceImpact: c.priceImpact,
376
+ priceImpactUsd: c.priceImpactUsd ?? void 0,
377
+ priceImpactUsdDisplay: c.priceImpactUsdDisplay ?? void 0,
378
+ completionEstimateSeconds: c.completionEstimateSeconds,
379
+ slippageTolerance: c.slippageTolerance,
380
+ transactionStates: c.transactionStates,
381
+ originTokenRate: c.originTokenRate,
382
+ destinationTokenRate: c.destinationTokenRate,
383
+ routeProviders: c.routeProviders,
384
+ fromAmountUsdDisplay: c.originAmountUsdDisplay ?? void 0,
385
+ toAmountUsdDisplay: c.destinationAmountUsdDisplay ?? void 0,
386
+ gasCostUsd: c.gasCostUsd ?? void 0,
387
+ gasCostUsdDisplay: c.gasCostUsdDisplay ?? void 0,
388
+ gasCost: c.gasCost ?? void 0,
389
+ gasCostFormatted: c.gasCostFormatted ?? void 0,
390
+ totalFeesUsd: c.grandTotalUsd ?? void 0,
391
+ totalFeesUsdDisplay: c.grandTotalUsdDisplay ?? void 0,
392
+ totalGasUsd: c.totalGasUsd ?? void 0,
393
+ totalGasUsdDisplay: c.totalGasUsdDisplay ?? void 0,
394
+ allProviderFeesUsd: c.allProviderFeesUsd ?? void 0,
395
+ allProviderFeesUsdDisplay: c.allProviderFeesUsdDisplay ?? void 0
393
396
  },
394
397
  swap: async () => {
395
398
  const {
396
- depositUserTxnReceipt: i,
397
- destinationIntentTransaction: m,
398
- totalCompletionSeconds: x
399
- } = await at({
400
- selectedFeeOption: et ?? null
399
+ depositUserTxnReceipt: l,
400
+ destinationIntentTransaction: f,
401
+ totalCompletionSeconds: D
402
+ } = await lt({
403
+ selectedFeeOption: st ?? null
401
404
  });
402
405
  return {
403
406
  originTransaction: {
404
- transactionHash: i?.transactionHash,
405
- explorerUrl: G({
406
- txHash: i?.transactionHash,
407
+ transactionHash: l?.transactionHash,
408
+ explorerUrl: J({
409
+ txHash: l?.transactionHash,
407
410
  chainId: s
408
411
  }),
409
- receipt: i
412
+ receipt: l
410
413
  },
411
414
  destinationTransaction: {
412
- transactionHash: m?.txnHash,
413
- explorerUrl: G({
414
- txHash: m?.txnHash,
415
- chainId: c
415
+ transactionHash: f?.txnHash,
416
+ explorerUrl: J({
417
+ txHash: f?.txnHash,
418
+ chainId: i
416
419
  }),
417
- receipt: m
420
+ receipt: f
418
421
  },
419
- totalCompletionSeconds: x
422
+ totalCompletionSeconds: D
420
423
  };
421
424
  }
422
425
  };
423
- } catch (f) {
426
+ } catch (g) {
424
427
  throw o.console.error(
425
428
  "[trails-sdk] [useQuote] Error getting quote:",
426
- f
427
- ), B(f);
429
+ g
430
+ ), M(g);
428
431
  }
429
432
  },
430
433
  // Prevent unnecessary refetching
431
- enabled: !!(d && P && n && a && T && v && s && c && V && // !isLoadingTokens &&
432
- r && r.length > 0),
434
+ enabled: !!(d && b && n && a && T && O && s && i && _ && // !isLoadingTokens &&
435
+ u && u.length > 0),
433
436
  staleTime: 30 * 1e3,
434
437
  // Consider data fresh for 30 seconds
435
438
  refetchOnWindowFocus: !1,
@@ -444,17 +447,17 @@ function Vt({
444
447
  // Refetch when network reconnects
445
448
  });
446
449
  return {
447
- quote: g?.quote || null,
448
- swap: g?.swap || null,
449
- isLoadingQuote: I,
450
- quoteError: U,
451
- quoteErrorPrettified: Nt(U),
452
- refetchQuote: () => D(),
450
+ quote: E?.quote || null,
451
+ swap: E?.swap || null,
452
+ isLoadingQuote: P,
453
+ quoteError: w,
454
+ quoteErrorPrettified: Nt(w),
455
+ refetchQuote: () => I(),
453
456
  abort: () => {
454
457
  o.console.log("[trails-sdk] useQuote abort() called"), o.console.log(
455
458
  "[trails-sdk] Active operations before abort:",
456
459
  ft.getAll()
457
- ), H.current.abort(), ft.abortAll(), o.console.log(
460
+ ), R.current.abort(), ft.abortAll(), o.console.log(
458
461
  "[trails-sdk] Abort completed, active operations:",
459
462
  ft.getAll()
460
463
  );
@@ -462,20 +465,20 @@ function Vt({
462
465
  };
463
466
  }
464
467
  function Yt(d) {
465
- const { data: n } = Ft(), { chainId: s } = Mt(), a = Qt(), c = dt(), { trailsApiKey: T, sequenceIndexerUrl: Z } = Et(), {
466
- openModal: v,
467
- setPendingSelection: tt,
468
- setHostTransactionState: J,
469
- setHostTransactionQuote: K,
470
- setHostTransactionStates: X,
471
- setHostTransactionTimestamp: F,
472
- hostTransactionState: M,
473
- setReceiptActionButtonText: et,
474
- setOnReceiptAction: nt,
475
- retryTransactionRef: ot
476
- } = Bt(), z = xt(), { supportedTokens: O } = pt(), H = Pt(), ut = Rt(), Q = Ut(null), p = ct(
468
+ const { data: n } = Ft(), { chainId: s } = Mt(), a = Qt(), i = gt(), { trailsApiKey: T, sequenceIndexerUrl: nt } = pt(), {
469
+ openModal: O,
470
+ setPendingSelection: ot,
471
+ setHostTransactionState: X,
472
+ setHostTransactionQuote: z,
473
+ setHostTransactionStates: V,
474
+ setHostTransactionTimestamp: Q,
475
+ hostTransactionState: H,
476
+ setReceiptActionButtonText: mt,
477
+ setOnReceiptAction: st,
478
+ retryTransactionRef: rt
479
+ } = Bt(), W = xt(), { supportedTokens: L } = yt(), at = Rt(), R = vt(), it = Pt(null), C = dt(
477
480
  (t) => {
478
- J((r) => ({
481
+ X((r) => ({
479
482
  status: t.status ?? r.status,
480
483
  details: t.details === null ? void 0 : t.details ? { ...r.details, ...t.details } : r.details,
481
484
  error: t.error === null ? void 0 : t.error !== void 0 ? t.error : r.error,
@@ -483,8 +486,8 @@ function Yt(d) {
483
486
  retryEnabled: t.retryEnabled !== void 0 ? t.retryEnabled : r.retryEnabled
484
487
  }));
485
488
  },
486
- [J]
487
- ), st = async (t, r, u) => {
489
+ [X]
490
+ ), Y = async (t, r, u) => {
488
491
  if (o.console.log(
489
492
  "[trails-sdk] [useTrailsSendTransaction] Executing transaction",
490
493
  { variables: t, originSelection: r }
@@ -494,63 +497,63 @@ function Yt(d) {
494
497
  );
495
498
  if (!t.to)
496
499
  throw new Error("Transaction 'to' address is required.");
497
- let k, g, I;
500
+ let k, m, E;
498
501
  if (r)
499
- k = r.fromTokenAddress, g = r.fromChainId, I = r.fromAmount;
502
+ k = r.fromTokenAddress, m = r.fromChainId, E = r.fromAmount;
500
503
  else if (t.fromTokenAddress && t.fromChainId && t.fromAmount)
501
- k = t.fromTokenAddress, g = t.fromChainId, I = t.fromAmount;
504
+ k = t.fromTokenAddress, m = t.fromChainId, E = t.fromAmount;
502
505
  else if (t.to && t.value !== void 0) {
503
506
  const e = s || a;
504
507
  if (!e)
505
508
  throw new Error("Chain ID not available. Please connect your wallet.");
506
- g = e, k = R, I = t.value.toString();
509
+ m = e, k = x, E = t.value.toString();
507
510
  } else
508
511
  throw new Error(
509
512
  "Origin token parameters are required. Please provide 'value' (native token), or 'fromTokenAddress'/'fromChainId'/'fromAmount' (ERC20 token), or select via modal."
510
513
  );
511
- const U = s || a;
512
- if (!U)
514
+ const P = s || a;
515
+ if (!P)
513
516
  throw new Error("Chain ID not available. Please connect your wallet.");
514
- let D, f, C, E;
517
+ let w, I, g, p;
515
518
  if (t.tokenAddress && t.tokenAmount)
516
- D = t.tokenAddress, f = O?.find(
519
+ w = t.tokenAddress, I = L?.find(
517
520
  (h) => h.contractAddress?.toLowerCase() === t.tokenAddress?.toLowerCase()
518
- )?.chainId ?? U, C = t.tokenAmount, E = t.to;
521
+ )?.chainId ?? P, g = t.tokenAmount, p = t.to;
519
522
  else if (t.to && t.value !== void 0)
520
- D = R, f = U, C = t.value.toString(), E = t.to;
523
+ w = x, I = P, g = t.value.toString(), p = t.to;
521
524
  else
522
525
  throw new Error(
523
526
  "Either 'value' or 'tokenAddress'/'tokenAmount' must be provided."
524
527
  );
525
- const A = t.tokenAddress && t.tokenAmount ? j.EXACT_OUTPUT : j.EXACT_INPUT;
526
- if (A === j.EXACT_INPUT && !I)
528
+ const y = t.tokenAddress && t.tokenAmount ? K.EXACT_OUTPUT : K.EXACT_INPUT;
529
+ if (y === K.EXACT_INPUT && !E)
527
530
  throw new Error(
528
531
  "Origin amount is required for this transaction. Please provide 'value' or 'fromAmount'."
529
532
  );
530
- const L = A === j.EXACT_OUTPUT ? C : I;
531
- let S = [];
533
+ const v = y === K.EXACT_OUTPUT ? g : E;
534
+ let U = [];
532
535
  try {
533
- S = (await yt({
536
+ U = (await It({
534
537
  account: n.account.address,
535
- indexerGatewayClient: z,
536
- trailsClient: c
538
+ indexerGatewayClient: W,
539
+ trailsClient: i
537
540
  })).balances;
538
541
  } catch (e) {
539
542
  o.console.warn(
540
543
  "[trails-sdk] [useTrailsSendTransaction] Error fetching balances, proceeding with zero balance",
541
544
  e
542
- ), S = [];
545
+ ), U = [];
543
546
  }
544
- const q = S.find(
545
- (e) => e.chainId === g && (e.contractAddress?.toLowerCase() === k?.toLowerCase() || !e.contractAddress && k === R)
547
+ const q = U.find(
548
+ (e) => e.chainId === m && (e.contractAddress?.toLowerCase() === k?.toLowerCase() || !e.contractAddress && k === x)
546
549
  )?.balance ?? "0";
547
- let b = 0;
550
+ let N = 0;
548
551
  try {
549
- const h = lt(g)?.nativeCurrency?.symbol ?? "";
550
- h && (b = (await It(c, {
552
+ const h = ut(m)?.nativeCurrency?.symbol ?? "";
553
+ h && (N = (await St(i, {
551
554
  tokenSymbol: h,
552
- tokenAddress: R,
553
- chainId: g
555
+ tokenAddress: x,
556
+ chainId: m
554
557
  }))?.priceUsd ?? 0);
555
558
  } catch (e) {
556
559
  o.console.warn(
@@ -558,275 +561,276 @@ function Yt(d) {
558
561
  e
559
562
  );
560
563
  }
561
- const rt = O?.find(
562
- (e) => e.contractAddress?.toLowerCase() === k?.toLowerCase() && e.chainId === g
563
- ), it = O?.find(
564
- (e) => e.contractAddress?.toLowerCase() === D?.toLowerCase() && e.chainId === f
565
- ), { getChainRpcClient: W } = await import("./index-BbajxCG_.js").then((e) => e.aJ), l = W(g), at = W(f), gt = async (e, h) => {
564
+ const B = L?.find(
565
+ (e) => e.contractAddress?.toLowerCase() === k?.toLowerCase() && e.chainId === m
566
+ ), ct = L?.find(
567
+ (e) => e.contractAddress?.toLowerCase() === w?.toLowerCase() && e.chainId === I
568
+ ), { getChainRpcClient: tt } = await import("./index-BiPwqVkZ.js").then((e) => e.a_), et = tt(m), c = tt(I), lt = async (e, h) => {
566
569
  try {
567
- const N = h === g ? l : h === f ? at : W(h);
568
- return N ? e.toLowerCase() === R.toLowerCase() ? lt(h)?.nativeCurrency.decimals ?? 18 : await N.readContract({
570
+ const F = h === m ? et : h === I ? c : tt(h);
571
+ return F ? e.toLowerCase() === x.toLowerCase() ? ut(h)?.nativeCurrency.decimals ?? 18 : await F.readContract({
569
572
  address: e,
570
573
  abi: Dt,
571
574
  functionName: "decimals"
572
575
  }) : null;
573
- } catch (N) {
576
+ } catch (F) {
574
577
  return o.console.error(
575
578
  `[trails-sdk] Error fetching decimals on-chain for token ${e} on chain ${h}:`,
576
- N
579
+ F
577
580
  ), null;
578
581
  }
579
582
  };
580
- let $ = rt?.decimals;
583
+ let $ = B?.decimals;
581
584
  if (!$ && k) {
582
- const e = await gt(
585
+ const e = await lt(
583
586
  k,
584
- g
587
+ m
585
588
  );
586
589
  e !== null && ($ = e);
587
590
  }
588
591
  $ || ($ = 18);
589
- let i = it?.decimals;
590
- if (!i && D) {
591
- const e = await gt(
592
- D,
593
- f
592
+ let G = ct?.decimals;
593
+ if (!G && w) {
594
+ const e = await lt(
595
+ w,
596
+ I
594
597
  );
595
- e !== null && (i = e);
598
+ e !== null && (G = e);
596
599
  }
597
- i || (i = 18);
598
- const m = it?.symbol ?? "", x = rt?.symbol ?? "", _ = (e) => {
599
- u?.trackInWidget && X(e), d?.onStatusUpdate?.(e);
600
- }, { send: kt, quote: Ot } = await St({
600
+ G || (G = 18);
601
+ const l = ct?.symbol ?? "", f = B?.symbol ?? "", D = (e) => {
602
+ u?.trackInWidget && V(e), d?.onStatusUpdate?.(e);
603
+ }, { send: j, quote: ht } = await wt({
601
604
  account: n.account,
602
605
  originTokenAddress: k,
603
- originChainId: g,
606
+ originChainId: m,
604
607
  originTokenBalance: q,
605
- destinationChainId: f,
606
- recipient: E,
607
- destinationTokenAddress: D,
608
- swapAmount: L,
609
- tradeType: A,
610
- originTokenSymbol: x,
611
- destinationTokenSymbol: m,
608
+ destinationChainId: I,
609
+ recipient: p,
610
+ destinationTokenAddress: w,
611
+ swapAmount: v,
612
+ tradeType: y,
613
+ originTokenSymbol: f,
614
+ destinationTokenSymbol: l,
612
615
  fee: "0",
613
616
  client: n,
614
617
  dryMode: !1,
615
- trailsClient: c,
618
+ trailsClient: i,
616
619
  destinationCalldata: t.data ? t.data.toString() : void 0,
617
- onTransactionStateChange: _,
620
+ onTransactionStateChange: D,
618
621
  sourceTokenDecimals: $,
619
- destinationTokenDecimals: i,
622
+ destinationTokenDecimals: G,
620
623
  paymasterUrl: d?.paymasterUrl,
621
624
  slippageTolerance: d?.slippageTolerance?.toString(),
622
- originNativeTokenPriceUsd: b,
623
- quoteProvider: d?.quoteProvider,
624
- commitIntentFn: H.mutateAsync,
625
- executeIntentFn: ut.mutateAsync,
625
+ originNativeTokenPriceUsd: N,
626
+ swapProvider: d?.swapProvider,
627
+ bridgeProvider: d?.bridgeProvider,
628
+ commitIntentFn: at.mutateAsync,
629
+ executeIntentFn: R.mutateAsync,
626
630
  checkoutOnHandlers: d?.checkoutOnHandlers,
627
- sequenceIndexerUrl: Z,
631
+ sequenceIndexerUrl: nt,
628
632
  sequenceProjectAccessKey: T,
629
- originPublicClient: l ?? void 0,
630
- destinationPublicClient: at ?? void 0,
633
+ originPublicClient: et ?? void 0,
634
+ destinationPublicClient: c ?? void 0,
631
635
  isSmartWallet: d?.isSmartWallet ?? void 0
632
636
  });
633
- u?.trackInWidget && (K(Ot ?? null), M.details || p({
637
+ u?.trackInWidget && (z(ht ?? null), H.details || C({
634
638
  details: {
635
- to: E,
636
- tokenAddress: D,
637
- tokenAmount: A === j.EXACT_OUTPUT ? C : void 0,
638
- toChainId: f,
639
+ to: p,
640
+ tokenAddress: w,
641
+ tokenAmount: y === K.EXACT_OUTPUT ? g : void 0,
642
+ toChainId: I,
639
643
  data: t.data
640
644
  }
641
- }), (!M.status || M.status === "idle") && F(Date.now()));
645
+ }), (!H.status || H.status === "idle") && Q(Date.now()));
642
646
  try {
643
- u?.trackInWidget && p({ retryEnabled: !1 });
647
+ u?.trackInWidget && C({ retryEnabled: !1 });
644
648
  const {
645
649
  depositUserTxnReceipt: e,
646
650
  destinationIntentTransaction: h,
647
- totalCompletionSeconds: N
648
- } = await kt({
651
+ totalCompletionSeconds: F
652
+ } = await j({
649
653
  selectedFeeOption: null,
650
654
  // Transition to "pending" when wallet signature is complete
651
655
  onOriginSend: () => {
652
- u?.trackInWidget && p({ status: "pending", error: null });
656
+ u?.trackInWidget && C({ status: "pending", error: null });
653
657
  }
654
658
  });
655
- return u?.trackInWidget && p({
659
+ return u?.trackInWidget && C({
656
660
  status: "success",
657
661
  result: {
658
662
  originTxHash: e?.transactionHash,
659
- originExplorerUrl: e?.transactionHash ? G({
663
+ originExplorerUrl: e?.transactionHash ? J({
660
664
  txHash: e.transactionHash,
661
- chainId: g
665
+ chainId: m
662
666
  }) : void 0,
663
667
  destinationTxHash: h?.txnHash,
664
- destinationExplorerUrl: h?.txnHash ? G({
668
+ destinationExplorerUrl: h?.txnHash ? J({
665
669
  txHash: h.txnHash,
666
- chainId: f
670
+ chainId: I
667
671
  }) : void 0
668
672
  }
669
673
  }), {
670
674
  originTransaction: {
671
675
  transactionHash: e?.transactionHash,
672
- explorerUrl: G({
676
+ explorerUrl: J({
673
677
  txHash: e?.transactionHash,
674
- chainId: g
678
+ chainId: m
675
679
  }),
676
680
  receipt: e
677
681
  },
678
682
  destinationTransaction: {
679
683
  transactionHash: h?.txnHash,
680
- explorerUrl: G({
684
+ explorerUrl: J({
681
685
  txHash: h?.txnHash,
682
- chainId: f
686
+ chainId: I
683
687
  }),
684
688
  receipt: h
685
689
  },
686
- totalCompletionSeconds: N
690
+ totalCompletionSeconds: F
687
691
  };
688
692
  } catch (e) {
689
693
  if (u?.trackInWidget) {
690
- const h = mt(e);
691
- p(h ? {
694
+ const h = Tt(e);
695
+ C(h ? {
692
696
  status: "confirmation",
693
697
  error: null,
694
698
  retryEnabled: !0
695
699
  } : {
696
700
  status: "error",
697
- error: B(e),
701
+ error: M(e),
698
702
  retryEnabled: !1
699
703
  });
700
704
  }
701
705
  throw e;
702
706
  }
703
- }, y = Tt({
707
+ }, A = kt({
704
708
  mutationFn: async (t) => {
705
709
  o.console.log(
706
710
  "[trails-sdk] [useTrailsSendTransaction] Starting transaction",
707
711
  t
708
- ), et(
712
+ ), mt(
709
713
  d?.receiptActionButtonText ?? "Transact Again"
710
- ), nt(d?.onReceiptAction ?? null);
714
+ ), st(d?.onReceiptAction ?? null);
711
715
  const r = t.value !== void 0, u = t.fromTokenAddress !== void 0 && t.fromChainId !== void 0, k = r || u;
712
- let g;
713
- if (t.tokenAddress && O) {
714
- const C = O.find(
715
- (E) => E.contractAddress?.toLowerCase() === t.tokenAddress?.toLowerCase()
716
+ let m;
717
+ if (t.tokenAddress && L) {
718
+ const g = L.find(
719
+ (p) => p.contractAddress?.toLowerCase() === t.tokenAddress?.toLowerCase()
716
720
  );
717
- C && (g = C.chainId);
721
+ g && (m = g.chainId);
718
722
  }
719
- g || (g = s || a);
720
- let I = !0, U = !0;
723
+ m || (m = s || a);
724
+ let E = !0, P = !0;
721
725
  if (n?.account)
722
726
  try {
723
727
  if (k) {
724
- let C, E, A;
725
- t.value !== void 0 ? (C = R, E = s || a || 1, A = t.value.toString()) : t.fromTokenAddress && t.fromChainId && (C = t.fromTokenAddress, E = t.fromChainId, A = t.fromAmount), C && E && A && A !== "0" && (I = await Ct({
728
+ let g, p, y;
729
+ t.value !== void 0 ? (g = x, p = s || a || 1, y = t.value.toString()) : t.fromTokenAddress && t.fromChainId && (g = t.fromTokenAddress, p = t.fromChainId, y = t.fromAmount), g && p && y && y !== "0" && (E = await At({
726
730
  account: n.account.address,
727
- token: C,
728
- amount: A,
729
- chainId: E,
730
- indexerGatewayClient: z,
731
- trailsClient: c
731
+ token: g,
732
+ amount: y,
733
+ chainId: p,
734
+ indexerGatewayClient: W,
735
+ trailsClient: i
732
736
  }), o.console.log(
733
737
  "[trails-sdk] [useTrailsSendTransaction] Origin token balance check:",
734
738
  {
735
- tokenAddress: C,
736
- amount: A,
737
- chainId: E,
738
- hasSufficientBalance: I
739
+ tokenAddress: g,
740
+ amount: y,
741
+ chainId: p,
742
+ hasSufficientBalance: E
739
743
  }
740
744
  ));
741
745
  }
742
- I && t.tokenAddress && t.tokenAmount && (U = await Ct({
746
+ E && t.tokenAddress && t.tokenAmount && (P = await At({
743
747
  account: n.account.address,
744
748
  token: t.tokenAddress,
745
749
  amount: t.tokenAmount,
746
- chainId: g,
747
- indexerGatewayClient: z,
748
- trailsClient: c
750
+ chainId: m,
751
+ indexerGatewayClient: W,
752
+ trailsClient: i
749
753
  }), o.console.log(
750
754
  "[trails-sdk] [useTrailsSendTransaction] Destination token balance check:",
751
755
  {
752
756
  tokenAddress: t.tokenAddress,
753
757
  tokenAmount: t.tokenAmount,
754
- chainId: g,
755
- hasSufficientBalance: U
758
+ chainId: m,
759
+ hasSufficientBalance: P
756
760
  }
757
761
  ));
758
- } catch (C) {
762
+ } catch (g) {
759
763
  o.console.warn(
760
764
  "[trails-sdk] [useTrailsSendTransaction] Error checking balances, defaulting to origin selection:",
761
- C
762
- ), I = !1, U = !1;
765
+ g
766
+ ), E = !1, P = !1;
763
767
  }
764
- const D = !k || !I || !U;
768
+ const w = !k || !E || !P;
765
769
  if (o.console.log(
766
770
  "[trails-sdk] [useTrailsSendTransaction] Origin selection decision:",
767
771
  {
768
772
  hasOriginParams: k,
769
- hasSufficientOriginBalance: I,
770
- hasSufficientDestinationTokenBalance: U,
771
- needsOriginSelection: D
773
+ hasSufficientOriginBalance: E,
774
+ hasSufficientDestinationTokenBalance: P,
775
+ needsOriginSelection: w
772
776
  }
773
- ), D) {
774
- const C = !(t.tokenAddress && t.tokenAmount), E = {
777
+ ), w) {
778
+ const g = !(t.tokenAddress && t.tokenAmount), p = {
775
779
  to: t.to,
776
780
  tokenAddress: t.tokenAddress,
777
781
  tokenAmount: t.tokenAmount,
778
- toChainId: g,
782
+ toChainId: m,
779
783
  data: t.data
780
784
  };
781
- return p({
785
+ return C({
782
786
  status: "awaiting-origin",
783
- details: E,
787
+ details: p,
784
788
  error: null,
785
789
  result: null
786
- }), K(null), X([]), F(Date.now()), new Promise((A, L) => {
787
- tt({
788
- resolve: async (S) => {
790
+ }), z(null), V([]), Q(Date.now()), new Promise((y, v) => {
791
+ ot({
792
+ resolve: async (U) => {
789
793
  try {
790
- p({ status: "confirmation" });
791
- const w = await st(t, S, {
794
+ C({ status: "confirmation" });
795
+ const S = await Y(t, U, {
792
796
  trackInWidget: !0
793
797
  });
794
- A(w);
795
- } catch (w) {
796
- mt(w) || p({
798
+ y(S);
799
+ } catch (S) {
800
+ Tt(S) || C({
797
801
  status: "error",
798
- error: B(w)
799
- }), L(w);
802
+ error: M(S)
803
+ }), v(S);
800
804
  }
801
805
  },
802
- reject: (S) => {
803
- const w = S instanceof Error ? S : new Error(String(S));
804
- p({
806
+ reject: (U) => {
807
+ const S = U instanceof Error ? U : new Error(String(U));
808
+ C({
805
809
  status: "error",
806
- error: B(w)
807
- }), L(w);
810
+ error: M(S)
811
+ }), v(S);
808
812
  },
809
- requireAmountInput: C
813
+ requireAmountInput: g
810
814
  }), setTimeout(() => {
811
815
  o.console.log(
812
816
  "[trails-sdk] [useTrailsSendTransaction] Calling openModal()"
813
- ), v();
817
+ ), O();
814
818
  }, 0);
815
819
  });
816
820
  }
817
- const f = {
821
+ const I = {
818
822
  to: t.to,
819
823
  tokenAddress: t.tokenAddress,
820
824
  tokenAmount: t.tokenAmount,
821
- toChainId: g,
825
+ toChainId: m,
822
826
  data: t.data
823
827
  };
824
- return p({
828
+ return C({
825
829
  status: "confirmation",
826
- details: f,
830
+ details: I,
827
831
  error: null,
828
832
  result: null
829
- }), K(null), X([]), F(Date.now()), v(), st(t, void 0, { trackInWidget: !0 });
833
+ }), z(null), V([]), Q(Date.now()), O(), Y(t, void 0, { trackInWidget: !0 });
830
834
  },
831
835
  onSuccess: (t, r) => {
832
836
  o.console.log(
@@ -839,8 +843,8 @@ function Yt(d) {
839
843
  "[trails-sdk] [useTrailsSendTransaction] Transaction error",
840
844
  { error: t, variables: r }
841
845
  );
842
- const u = B(t), k = mt(t);
843
- M.status !== "idle" && !k && p({
846
+ const u = M(t), k = Tt(t);
847
+ H.status !== "idle" && !k && C({
844
848
  status: "error",
845
849
  error: u
846
850
  }), d?.onError?.(new Error(u), r);
@@ -851,9 +855,9 @@ function Yt(d) {
851
855
  { data: t, error: r, variables: u }
852
856
  ), d?.onSettled?.(t, r, u);
853
857
  }
854
- }), P = ct(
858
+ }), Z = dt(
855
859
  (t, r) => {
856
- y.mutate(t, {
860
+ A.mutate(t, {
857
861
  onSuccess: (u) => {
858
862
  r?.onSuccess?.(u);
859
863
  },
@@ -865,9 +869,9 @@ function Yt(d) {
865
869
  }
866
870
  });
867
871
  },
868
- [y]
869
- ), V = ct(
870
- async (t, r) => y.mutateAsync(t, {
872
+ [A]
873
+ ), b = dt(
874
+ async (t, r) => A.mutateAsync(t, {
871
875
  onSuccess: (u) => {
872
876
  r?.onSuccess?.(u);
873
877
  },
@@ -878,95 +882,113 @@ function Yt(d) {
878
882
  r?.onSettled?.(u, k);
879
883
  }
880
884
  }),
881
- [y]
882
- ), Y = ct(() => {
883
- Q.current && P(Q.current);
884
- }, [P]);
885
- return ot.current = Y, {
886
- sendTransaction: P,
887
- sendTransactionAsync: V,
888
- retry: Y,
889
- data: y.data,
890
- error: y.error,
891
- isPending: y.isPending,
892
- isSuccess: y.isSuccess,
893
- isError: y.isError,
894
- isIdle: y.isIdle,
895
- status: y.status,
896
- reset: y.reset,
897
- variables: y.variables
885
+ [A]
886
+ ), _ = dt(() => {
887
+ it.current && Z(it.current);
888
+ }, [Z]);
889
+ return rt.current = _, {
890
+ sendTransaction: Z,
891
+ sendTransactionAsync: b,
892
+ retry: _,
893
+ data: A.data,
894
+ error: A.error,
895
+ isPending: A.isPending,
896
+ isSuccess: A.isSuccess,
897
+ isError: A.isError,
898
+ isIdle: A.isIdle,
899
+ status: A.status,
900
+ reset: A.reset,
901
+ variables: A.variables
898
902
  };
899
903
  }
900
904
  export {
901
905
  ee as InsufficientBalanceError,
902
906
  ne as TRAILS_ROUTER_PLACEHOLDER_AMOUNT,
903
- j as TradeType,
907
+ K as TradeType,
904
908
  oe as TrailsClient,
905
909
  se as TrailsHookModal,
906
910
  re as TrailsModalProvider,
907
- ie as TrailsProvider,
908
- ae as TrailsWidget,
911
+ ae as TrailsProvider,
912
+ ie as TrailsWidget,
909
913
  ce as UserRejectionError,
910
- le as calculateIntentAddress,
911
- de as calculateOriginAndDestinationIntentAddresses,
912
- ue as commitIntent,
913
- ge as convertApiTokenInfoToToken,
914
- fe as createModalController,
915
- me as formatBalanceFields,
916
- Te as formatPriceFields,
917
- ke as formatUsdAmountFormatted,
918
- he as formatUsdFields,
919
- Ce as getAccountTotalBalanceUsd,
920
- Ae as getAccountTransactionHistory,
921
- Ee as getAllChains,
922
- lt as getChainInfo,
923
- pe as getChainRpcClient,
924
- ye as getERC20TransferData,
925
- Ct as getHasSufficientBalanceToken,
926
- Ie as getHasSufficientBalanceUsd,
927
- Se as getIsApiError,
928
- we as getIsBalanceTooLowError,
929
- Ue as getIsInsufficientLiquidityError,
930
- De as getIsNoAvailableQuoteError,
931
- xe as getIsQuoteFailedError,
932
- Pe as getIsQuoteInputError,
933
- Re as getIsQuoteTokenError,
934
- Oe as getIsRateLimitedError,
935
- He as getIsRequiredAmountNotMetError,
936
- mt as getIsUserRejectionError,
937
- ve as getIsWalletAlreadyConnectedError,
938
- Le as getMinLogLevel,
914
+ le as attemptSwitchChain,
915
+ de as buildRefundTransaction,
916
+ ue as buildRefundTransactionWithSignature,
917
+ ge as calcAmountUsdPrice,
918
+ me as calculateIntentAddress,
919
+ fe as calculateOriginAndDestinationIntentAddresses,
920
+ Te as commitIntent,
921
+ ke as convertApiTokenInfoToToken,
922
+ he as createModalController,
923
+ Ce as determineRefundCall,
924
+ Ae as formatBalanceFields,
925
+ Ee as formatPriceFields,
926
+ pe as formatTvl,
927
+ ye as formatUsdAmountFormatted,
928
+ Ie as formatUsdFields,
929
+ Se as getAccountTotalBalanceUsd,
930
+ we as getAccountTransactionHistory,
931
+ Ue as getAllChains,
932
+ ut as getChainInfo,
933
+ Pe as getChainRpcClient,
934
+ De as getERC20TransferData,
935
+ At as getHasSufficientBalanceToken,
936
+ xe as getHasSufficientBalanceUsd,
937
+ Re as getIntent,
938
+ ve as getIsApiError,
939
+ Oe as getIsBalanceTooLowError,
940
+ He as getIsInsufficientLiquidityError,
941
+ Le as getIsNoAvailableQuoteError,
942
+ be as getIsQuoteFailedError,
943
+ qe as getIsQuoteInputError,
944
+ Ne as getIsQuoteTokenError,
945
+ Be as getIsRateLimitedError,
946
+ Fe as getIsRequiredAmountNotMetError,
947
+ Tt as getIsUserRejectionError,
948
+ Me as getIsWalletAlreadyConnectedError,
949
+ Qe as getMinLogLevel,
939
950
  Nt as getPrettifiedErrorMessage,
940
- qe as getRpcUrl,
941
- be as getSupportedChains,
942
- Ne as getSupportedTokens,
943
- Be as getTrailsClient,
944
- Fe as getTxTimeDiff,
951
+ We as getRpcUrl,
952
+ _e as getSupportedChains,
953
+ $e as getSupportedTokens,
954
+ St as getTokenPrice,
955
+ Ge as getTokenPrices,
956
+ je as getTrailsClient,
957
+ Ke as getTxTimeDiff,
958
+ Je as invalidateTokenPricesCache,
959
+ Xe as isValidInteger,
960
+ ze as isValidNumeric,
945
961
  o as logger,
946
- Me as pollIntentReceipt,
947
- St as prepareSend,
948
- Qe as quoteIntent,
949
- We as sendOriginTransaction,
950
- $e as useAccountTotalBalanceUsd,
951
- _e as useAccountTransactionHistory,
952
- ht as useChainRpcClient,
953
- Pt as useCommitIntent,
954
- Rt as useExecuteIntent,
955
- je as useGetTokenImageUrl,
956
- Ge as useHasSufficientBalanceToken,
957
- Je as useHasSufficientBalanceUsd,
958
- en as useIndexerGatewayClient,
962
+ Ve as normalizeNumber,
963
+ Ye as pollIntentReceipt,
964
+ wt as prepareSend,
965
+ Ze as quoteIntent,
966
+ tn as sendOriginTransaction,
967
+ en as signPayload,
968
+ nn as useAccountTotalBalanceUsd,
969
+ on as useAccountTransactionHistory,
970
+ Ct as useChainRpcClient,
971
+ Rt as useCommitIntent,
972
+ vt as useExecuteIntent,
973
+ sn as useGetIntent,
974
+ rn as useGetTokenImageUrl,
975
+ an as useHasSufficientBalanceToken,
976
+ cn as useHasSufficientBalanceUsd,
977
+ An as useIndexerGatewayClient,
959
978
  zt as useIntentReceiptMonitor,
960
- Ke as useIntentTransactionHistory,
979
+ ln as useIntentTransactionHistory,
961
980
  Vt as useQuote,
962
- Xe as useSupportedChains,
963
- pt as useSupportedTokens,
964
- ze as useTokenAddress,
965
- Ve as useTokenBalances,
966
- Ye as useTokenInfo,
967
- Ze as useTokenList,
968
- Et as useTrails,
969
- dt as useTrailsClient,
981
+ dn as useSupportedChains,
982
+ yt as useSupportedTokens,
983
+ un as useTokenAddress,
984
+ gn as useTokenBalances,
985
+ mn as useTokenInfo,
986
+ fn as useTokenList,
987
+ Tn as useTokenPrice,
988
+ kn as useTokenPrices,
989
+ pt as useTrails,
990
+ gt as useTrailsClient,
970
991
  Bt as useTrailsModal,
992
+ hn as useTrailsRefund,
971
993
  Yt as useTrailsSendTransaction
972
994
  };