0xtrails 0.16.1 → 0.16.2

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.
package/dist/package.js CHANGED
@@ -1,4 +1,4 @@
1
- var t = "0xtrails", e = "0.16.1", i = "SDK for Trails", s = "module", a = "./dist/index.js", r = "./dist/index.js", d = "./dist/index.d.ts";
1
+ var t = "0xtrails", e = "0.16.2", i = "SDK for Trails", s = "module", a = "./dist/index.js", r = "./dist/index.js", d = "./dist/index.d.ts";
2
2
  var c = { access: "public" }, o = ["dist"], n = {
3
3
  build: "rimraf dist && pnpm run build:css && pnpm run build:vite && pnpm run build:patch && pnpm run build:umd",
4
4
  "build:patch": "node scripts/apply-react-patch.cjs",
@@ -1 +1 @@
1
- {"version":3,"file":"prepareSend.d.ts","sourceRoot":"","sources":["../src/prepareSend.ts"],"names":[],"mappings":"AAkBA,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAIvB,MAAM,8BAA8B,CAAA;AASrC,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,GACX,MAAM,8BAA8B,CAAA;AAGrC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAGvE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAsB3D,wBAAsB,WAAW,CAC/B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAoa5B;AAGD,YAAY,EACV,aAAa,EACb,SAAS,EACT,OAAO,EACP,KAAK,EACL,cAAc,EACd,UAAU,EACV,iBAAiB,GAClB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAG7C,OAAO,EACL,iBAAiB,EACjB,8BAA8B,EAC9B,wBAAwB,EACxB,2BAA2B,EAC3B,WAAW,EACX,4BAA4B,EAC5B,wBAAwB,EACxB,SAAS,GACV,MAAM,8BAA8B,CAAA"}
1
+ {"version":3,"file":"prepareSend.d.ts","sourceRoot":"","sources":["../src/prepareSend.ts"],"names":[],"mappings":"AAkBA,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAIvB,MAAM,8BAA8B,CAAA;AASrC,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,GACX,MAAM,8BAA8B,CAAA;AAGrC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAGvE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAsB3D,wBAAsB,WAAW,CAC/B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAyZ5B;AAGD,YAAY,EACV,aAAa,EACb,SAAS,EACT,OAAO,EACP,KAAK,EACL,cAAc,EACd,UAAU,EACV,iBAAiB,GAClB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAG7C,OAAO,EACL,iBAAiB,EACjB,8BAA8B,EAC9B,wBAAwB,EACxB,2BAA2B,EAC3B,WAAW,EACX,4BAA4B,EAC5B,wBAAwB,EACxB,SAAS,GACV,MAAM,8BAA8B,CAAA"}
@@ -2,38 +2,38 @@ import { logger as p } from "./logger/index.js";
2
2
  import { getChainInfo as he, getPublicClient as Ce } from "./chains.js";
3
3
  import { abortControllerRegistry as Pe } from "./abortController.js";
4
4
  import { getIsCustomCalldata as ke } from "./contractUtils.js";
5
- import { addressEqual as T, isNativeToken as q, isZeroAccount as W } from "./utils/address.js";
6
- import { TRAILS_CONTRACTS as z } from "./contractConstants.js";
5
+ import { addressEqual as g, isNativeToken as F, isZeroAccount as $ } from "./utils/address.js";
6
+ import { TRAILS_CONTRACTS as W } from "./contractConstants.js";
7
7
  import { getWethAddress as ve } from "./tokenRegistry.js";
8
8
  import { trackPaymentError as Se, trackPaymentStarted as we } from "./analytics.js";
9
9
  import { getSlippageToleranceValue as Ee } from "./widget/components/SlippageToleranceSettings.js";
10
10
  import { getERC20TransferData as Ie } from "./utils.js";
11
11
  import { getTokenPrices as Ue } from "./query/price.queries.js";
12
- import { PlaceholderError as be, TRAILS_ROUTER_PLACEHOLDER_AMOUNT as _e, calldataHasPlaceholder as ye, replacePlaceholderInCalldata as De } from "./placeholder.js";
12
+ import { PlaceholderError as _e, TRAILS_ROUTER_PLACEHOLDER_AMOUNT as be, calldataHasPlaceholder as ye, replacePlaceholderInCalldata as De } from "./placeholder.js";
13
13
  import { resolveDefaultIntentProtocol as Oe } from "./intentProtocolResolver.js";
14
- import { TradeType as f } from "./transactionIntent/types.js";
14
+ import { TradeType as u } from "./transactionIntent/types.js";
15
15
  import { isSameChain as Re, isSameToken as Fe } from "./transactionIntent/validators.js";
16
16
  import "./transactionIntent/quote/feeExtractors.js";
17
17
  import "./transactionIntent/quote/normalizeQuote.js";
18
18
  import { handleIntent as Ne } from "./transactionIntent/handlers/intentHandler.js";
19
- import { DestinationEncodingError as K, encodeDestinationForIntentProtocol as qe } from "./intentProtocolEncoding.js";
19
+ import { DestinationEncodingError as z, encodeDestinationForIntentProtocol as qe } from "./intentProtocolEncoding.js";
20
20
  import "./quoteError.js";
21
21
  import "./hooks/useQuote.js";
22
22
  import { IntentProtocolVersion as S, RouteProvider as Le, RouteProvider as Tt } from "@0xtrails/api";
23
23
  function Me(t) {
24
- if (t instanceof be) {
25
- if (t.code === "MULTIPLE_AMOUNT_SLOTS") return new K("MULTIPLE_AMOUNT_SLOTS", t.message, t);
26
- if (t.code === "INVALID_AMOUNT_OFFSET") return new K("UNSAFE_PLACEHOLDER_MATCH", t.message, t);
24
+ if (t instanceof _e) {
25
+ if (t.code === "MULTIPLE_AMOUNT_SLOTS") return new z("MULTIPLE_AMOUNT_SLOTS", t.message, t);
26
+ if (t.code === "INVALID_AMOUNT_OFFSET") return new z("UNSAFE_PLACEHOLDER_MATCH", t.message, t);
27
27
  }
28
28
  return t;
29
29
  }
30
30
  async function At(t) {
31
31
  p.console.log("[trails-sdk] New quote generated - aborting all existing operations"), Pe.abortAll();
32
- const { account: s, originTokenAddress: i, originChainId: r, originTokenBalance: Q, destinationChainId: n, recipient: A, destinationTokenAddress: o, swapAmount: d, tradeType: c = f.EXACT_OUTPUT, originTokenSymbol: L, destinationTokenSymbol: h, client: j, trailsClient: w, destinationApproveAddress: B, destinationCalldata: C, onTransactionStateChange: Z, sourceTokenDecimals: E, destinationTokenDecimals: I, slippageTolerance: M, originNativeTokenPriceUsd: G, swapProvider: J, bridgeProvider: x, swapProviderFallback: Y, bridgeProviderFallback: ee, fundMethod: te, mode: U, checkoutOnHandlers: b, selectedFeeOption: re, walletId: H, abortSignal: oe, commitIntentFn: ie, executeIntentFn: ne, sequenceProjectAccessKey: ae, sequenceIndexerUrl: se, isSmartWallet: de, isSenderContractOnOrigin: le, trailsApiKey: ce, trailsApiUrl: me, sequenceMetadataUrl: pe, onramp: ue, refundAddress: fe, isMultiCallEncoding: g, intentProtocolVersion: _ } = t;
32
+ const { account: a, originTokenAddress: i, originChainId: r, originTokenBalance: K, destinationChainId: n, recipient: T, destinationTokenAddress: o, swapAmount: s, tradeType: d = u.EXACT_OUTPUT, originTokenSymbol: N, destinationTokenSymbol: A, client: Q, trailsClient: w, destinationApproveAddress: j, destinationCalldata: h, onTransactionStateChange: B, sourceTokenDecimals: E, destinationTokenDecimals: I, slippageTolerance: q, originNativeTokenPriceUsd: Z, swapProvider: G, bridgeProvider: L, swapProviderFallback: J, bridgeProviderFallback: Y, fundMethod: ee, mode: U, checkoutOnHandlers: _, selectedFeeOption: te, walletId: M, abortSignal: re, commitIntentFn: oe, executeIntentFn: ie, sequenceProjectAccessKey: ne, sequenceIndexerUrl: ae, isSmartWallet: se, isSenderContractOnOrigin: de, trailsApiKey: le, trailsApiUrl: ce, sequenceMetadataUrl: me, onramp: pe, refundAddress: ue, isMultiCallEncoding: C, intentProtocolVersion: b } = t;
33
33
  let { sourceTokenPriceUsd: P, destinationTokenPriceUsd: k } = t;
34
- const y = te ?? "wallet";
35
- if (!s?.address || W(s.address)) throw new Error("Account address is required and must not be the zero address");
36
- if (!d || d === "0") throw new Error("swapAmount is required and must be a positive numeric value");
34
+ const y = ee ?? "wallet";
35
+ if (!a?.address || $(a.address)) throw new Error("Account address is required and must not be the zero address");
36
+ if (!s || s === "0") throw new Error("swapAmount is required and must be a positive numeric value");
37
37
  if (!r) throw new Error("Origin chain ID is required");
38
38
  if (!n) throw new Error("Destination chain ID is required");
39
39
  if (t.originPublicClient) {
@@ -44,160 +44,160 @@ async function At(t) {
44
44
  const e = t.destinationPublicClient?.chain?.id;
45
45
  if (e !== n) throw new Error(`Destination public client chain ID mismatch: expected ${n}, got ${e}`);
46
46
  }
47
- const ge = M !== void 0 ? M : Ee("0.01");
47
+ const fe = q !== void 0 ? q : Ee("0.01");
48
48
  if (!E) throw new Error("Source token decimals not provided");
49
49
  if (!I) throw new Error("Destination token decimals not provided");
50
50
  const { intentProtocol: l } = await Oe({
51
51
  trailsClient: w,
52
- override: _
52
+ override: b
53
53
  });
54
- let a = ke(C);
55
- if (W(A)) throw new Error("Recipient address cannot be zero address");
56
- let u = A, v = B, m = C, D = J;
57
- const V = Re(r, n), Te = Fe(i, o), O = V && Te, R = ve(r), $ = V && !!R && (q(i) && T(o, R) || T(i, R) && q(o)) && T(A, s.address);
58
- $ && (u = s.address, D = Le.WETH, a || (m = void 0, a = !1));
59
- let F;
54
+ let c = ke(h);
55
+ if ($(T)) throw new Error("Recipient address cannot be zero address");
56
+ let f = T, v = j, m = h, D = G;
57
+ const x = Re(r, n), ge = Fe(i, o), Te = x && ge, O = ve(r), H = x && !!O && (F(i) && g(o, O) || g(i, O) && F(o)) && g(T, a.address);
58
+ H && (f = a.address, D = Le.WETH, c || (m = void 0, c = !1));
59
+ let V;
60
60
  try {
61
- F = ye(C);
61
+ V = ye(h);
62
62
  } catch (e) {
63
63
  throw Me(e);
64
64
  }
65
- if (O && a && F && !g && (m = De(m || "", d), p.console.log("[trails-sdk] Same-chain same-token: Replaced placeholder with actual amount in calldata", { swapAmount: d })), g && a && _ && _ !== S.v1_5)
65
+ if (c && V && !C && d === u.EXACT_OUTPUT && (m = De(m || "", s), p.console.log("[trails-sdk] Same-chain same-token: Replaced placeholder with actual amount in calldata", { swapAmount: s })), C && c && b && b !== S.v1_5)
66
66
  throw new Error("Multicall encoding (to.calls) requires v1.5 protocol. v1 is not supported.");
67
- if (!a && c === f.EXACT_INPUT && !q(o) && !O && !$ && (m = Ie(A, BigInt(_e)), u = o, a = !0, p.console.log("[trails-sdk] Setting ERC20 transfer calldata for destination metatxn tracking")), p.console.log("[trails-sdk] [intent-protocol] === Protocol Version Selected ===", {
67
+ if (!c && d === u.EXACT_INPUT && !F(o) && !Te && !H && (m = Ie(T, BigInt(be)), f = o, c = !0, p.console.log("[trails-sdk] Setting ERC20 transfer calldata for destination metatxn tracking")), p.console.log("[trails-sdk] [intent-protocol] === Protocol Version Selected ===", {
68
68
  intentProtocol: l,
69
69
  isV1: l === S.v1,
70
70
  isV1_5: l === S.v1_5
71
- }), a && c === f.EXACT_INPUT && !g && !(O && a && F && !g)) {
71
+ }), c && d === u.EXACT_INPUT && !C) {
72
72
  p.console.log("[trails-sdk] [intent-protocol] Calldata wrapping required for custom calldata", {
73
73
  intentProtocol: l,
74
74
  wrapperType: l === S.v1 ? "TrailsRouter" : "TrailsUtils (Hydrate)"
75
75
  });
76
76
  const e = qe({
77
77
  intentProtocol: l,
78
- destinationAddress: u,
78
+ destinationAddress: f,
79
79
  destinationCalldata: m ?? "0x",
80
80
  destinationApprovalAddress: v,
81
- isExactInput: c === f.EXACT_INPUT,
82
- hasCustomCalldata: a,
83
- swapAmount: d,
81
+ isExactInput: d === u.EXACT_INPUT,
82
+ hasCustomCalldata: c,
83
+ swapAmount: s,
84
84
  originChainId: r,
85
85
  destinationChainId: n,
86
86
  originTokenAddress: i,
87
87
  destinationTokenAddress: o,
88
- trailsRouterAddress: z.trailsRouterAddress,
89
- trailsUtilsAddress: z.trailsUtilsAddress
88
+ trailsRouterAddress: W.trailsRouterAddress,
89
+ trailsUtilsAddress: W.trailsUtilsAddress
90
90
  });
91
- u = e.destinationAddress, m = e.destinationCalldata, e.destinationApprovalAddress && (v = e.destinationApprovalAddress), p.console.log("[trails-sdk] [intent-protocol] Destination encoding", {
91
+ f = e.destinationAddress, m = e.destinationCalldata, e.destinationApprovalAddress && (v = e.destinationApprovalAddress), p.console.log("[trails-sdk] [intent-protocol] Destination encoding", {
92
92
  intentProtocol: l,
93
93
  strategy: {
94
94
  none: "none",
95
95
  v1_trails_router: "TrailsRouter",
96
96
  v1_5_trails_utils_hydrate: "TrailsUtils (Hydrate)"
97
97
  }[e.strategy],
98
- effectiveDestinationAddress: u,
98
+ effectiveDestinationAddress: f,
99
99
  hasApprovalAddress: !!v
100
100
  });
101
101
  }
102
102
  if (!P || !k) try {
103
103
  const e = await Ue(w, [{
104
- tokenSymbol: L,
104
+ tokenSymbol: N,
105
105
  tokenAddress: i,
106
106
  chainId: r
107
107
  }, {
108
- tokenSymbol: h,
108
+ tokenSymbol: A,
109
109
  tokenAddress: o,
110
110
  chainId: n
111
111
  }]);
112
- P = e.find((N) => T(N.token.tokenAddress, i))?.priceUsd ?? 0, k = e.find((N) => T(N.token.tokenAddress, o))?.priceUsd ?? 0;
112
+ P = e.find((R) => g(R.token.tokenAddress, i))?.priceUsd ?? 0, k = e.find((R) => g(R.token.tokenAddress, o))?.priceUsd ?? 0;
113
113
  } catch (e) {
114
114
  p.console.error("[trails-sdk] Error getting token prices:", e);
115
115
  }
116
116
  we({
117
- userAddress: s.address,
117
+ userAddress: a.address,
118
118
  originChainId: r,
119
119
  destinationChainId: n,
120
120
  originTokenAddress: i,
121
- originTokenAmount: c === f.EXACT_INPUT ? d : void 0,
121
+ originTokenAmount: d === u.EXACT_INPUT ? s : void 0,
122
122
  originTokenDecimals: E,
123
123
  destinationTokenAddress: o,
124
- destinationTokenSymbol: h || "",
125
- destinationTokenAmount: c === f.EXACT_OUTPUT ? d : void 0,
124
+ destinationTokenSymbol: A || "",
125
+ destinationTokenAmount: d === u.EXACT_OUTPUT ? s : void 0,
126
126
  destinationTokenDecimals: I,
127
127
  mode: U,
128
128
  fundMethod: y,
129
129
  sourceTokenPriceUsd: P?.toString(),
130
130
  destinationTokenPriceUsd: k?.toString(),
131
- tradeType: c.toString(),
131
+ tradeType: d.toString(),
132
132
  swapProvider: D || void 0,
133
- bridgeProvider: x || void 0,
134
- onramp: ue,
135
- walletId: H,
136
- destinationCalldata: C
133
+ bridgeProvider: L || void 0,
134
+ onramp: pe,
135
+ walletId: M,
136
+ destinationCalldata: h
137
137
  });
138
138
  const X = he(r);
139
139
  if (!X)
140
140
  throw Se({
141
141
  error: `Chain ${r} not found`,
142
- userAddress: s.address,
142
+ userAddress: a.address,
143
143
  mode: U,
144
144
  fundMethod: y,
145
145
  originChainId: r,
146
146
  destinationChainId: n,
147
147
  originTokenAddress: i,
148
148
  destinationTokenAddress: o,
149
- destinationTokenSymbol: h
149
+ destinationTokenSymbol: A
150
150
  }), new Error(`Chain ${r} not found`);
151
151
  const Ae = t.originPublicClient ?? Ce(r);
152
- return b?.triggerCheckoutStart && b.triggerCheckoutStart(), Ne({
152
+ return _?.triggerCheckoutStart && _.triggerCheckoutStart(), Ne({
153
153
  queryClient: t.queryClient,
154
- mainSignerAddress: s.address,
154
+ mainSignerAddress: a.address,
155
155
  originChainId: r,
156
156
  originTokenAddress: i,
157
- originTokenBalance: Q,
157
+ originTokenBalance: K,
158
158
  originTokenDecimals: E,
159
- originTokenSymbol: L,
159
+ originTokenSymbol: N,
160
160
  destinationChainId: n,
161
161
  destinationTokenAddress: o,
162
- destinationTokenSymbol: h,
162
+ destinationTokenSymbol: A,
163
163
  destinationTokenDecimals: I,
164
- swapAmount: d,
165
- recipient: u,
164
+ swapAmount: s,
165
+ recipient: f,
166
166
  destinationApproveAddress: v,
167
167
  destinationCalldata: m,
168
- walletClient: j,
168
+ walletClient: Q,
169
169
  publicClient: Ae,
170
- account: s,
170
+ account: a,
171
171
  chain: X,
172
- onTransactionStateChange: Z,
172
+ onTransactionStateChange: B,
173
173
  transactionStates: [],
174
174
  trailsClient: w,
175
175
  sourceTokenPriceUsd: P,
176
176
  destinationTokenPriceUsd: k,
177
- originNativeTokenPriceUsd: G,
178
- slippageTolerance: ge,
179
- tradeType: c,
177
+ originNativeTokenPriceUsd: Z,
178
+ slippageTolerance: fe,
179
+ tradeType: d,
180
180
  swapProvider: D,
181
- bridgeProvider: x,
182
- swapProviderFallback: Y,
183
- bridgeProviderFallback: ee,
181
+ bridgeProvider: L,
182
+ swapProviderFallback: J,
183
+ bridgeProviderFallback: Y,
184
184
  fundMethod: y,
185
185
  mode: U,
186
- checkoutOnHandlers: b,
187
- selectedFeeOption: re,
188
- walletId: H,
189
- abortSignal: oe,
190
- commitIntentFn: ie,
191
- executeIntentFn: ne,
192
- sequenceProjectAccessKey: ae,
193
- sequenceIndexerUrl: se,
194
- isSmartWallet: de,
195
- isSenderContractOnOrigin: le,
196
- trailsApiKey: ce,
197
- trailsApiUrl: me,
198
- sequenceMetadataUrl: pe,
199
- refundAddress: fe,
200
- isMultiCallEncoding: g,
186
+ checkoutOnHandlers: _,
187
+ selectedFeeOption: te,
188
+ walletId: M,
189
+ abortSignal: re,
190
+ commitIntentFn: oe,
191
+ executeIntentFn: ie,
192
+ sequenceProjectAccessKey: ne,
193
+ sequenceIndexerUrl: ae,
194
+ isSmartWallet: se,
195
+ isSenderContractOnOrigin: de,
196
+ trailsApiKey: le,
197
+ trailsApiUrl: ce,
198
+ sequenceMetadataUrl: me,
199
+ refundAddress: ue,
200
+ isMultiCallEncoding: C,
201
201
  intentProtocolVersion: l
202
202
  });
203
203
  }