0xtrails 0.4.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/dist/analytics.d.ts +8 -3
  2. package/dist/analytics.d.ts.map +1 -1
  3. package/dist/{ccip-C9CA3tIi.js → ccip-Dw5AN7oU.js} +27 -27
  4. package/dist/cctp.d.ts +0 -149
  5. package/dist/cctp.d.ts.map +1 -1
  6. package/dist/chains.d.ts +31 -4
  7. package/dist/chains.d.ts.map +1 -1
  8. package/dist/config.d.ts +28 -52
  9. package/dist/config.d.ts.map +1 -1
  10. package/dist/constants.d.ts +1 -7
  11. package/dist/constants.d.ts.map +1 -1
  12. package/dist/contractUtils.d.ts.map +1 -1
  13. package/dist/estimate.d.ts.map +1 -1
  14. package/dist/fees.d.ts.map +1 -1
  15. package/dist/gasless.d.ts +12 -0
  16. package/dist/gasless.d.ts.map +1 -1
  17. package/dist/{index-CNB57v0n.js → index-BtVUTbEZ.js} +32255 -40547
  18. package/dist/index.d.ts +13 -11
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +320 -944
  21. package/dist/indexerClient.d.ts +9 -6
  22. package/dist/indexerClient.d.ts.map +1 -1
  23. package/dist/intents.d.ts +0 -18
  24. package/dist/intents.d.ts.map +1 -1
  25. package/dist/mutations.d.ts.map +1 -1
  26. package/dist/paymasterSend.d.ts.map +1 -1
  27. package/dist/prepareSend.d.ts +1 -1
  28. package/dist/prepareSend.d.ts.map +1 -1
  29. package/dist/sendUserOp.d.ts +0 -18
  30. package/dist/sendUserOp.d.ts.map +1 -1
  31. package/dist/sequenceWallet.d.ts +1 -1
  32. package/dist/sequenceWallet.d.ts.map +1 -1
  33. package/dist/tokenBalances.d.ts.map +1 -1
  34. package/dist/tokens.d.ts +10 -8
  35. package/dist/tokens.d.ts.map +1 -1
  36. package/dist/trailsClient.d.ts +3 -3
  37. package/dist/trailsClient.d.ts.map +1 -1
  38. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +4 -5
  39. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
  40. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +4 -5
  41. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
  42. package/dist/transactionIntent/deposits/standardDeposit.d.ts +2 -2
  43. package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
  44. package/dist/transactionIntent/execution/transactionState.d.ts +2 -2
  45. package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -1
  46. package/dist/transactionIntent/handlers/crossChain.d.ts +6 -4
  47. package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
  48. package/dist/transactionIntent/handlers/index.d.ts +0 -1
  49. package/dist/transactionIntent/handlers/index.d.ts.map +1 -1
  50. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +4 -34
  51. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
  52. package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
  53. package/dist/transactionIntent/quote/quoteHelpers.d.ts +2 -1
  54. package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
  55. package/dist/transactionIntent/types.d.ts +7 -19
  56. package/dist/transactionIntent/types.d.ts.map +1 -1
  57. package/dist/transactionIntent/utils/index.d.ts +0 -1
  58. package/dist/transactionIntent/utils/index.d.ts.map +1 -1
  59. package/dist/transactions.d.ts +6 -18
  60. package/dist/transactions.d.ts.map +1 -1
  61. package/dist/utils.d.ts +8 -2
  62. package/dist/utils.d.ts.map +1 -1
  63. package/dist/walletUtils.d.ts +21 -0
  64. package/dist/walletUtils.d.ts.map +1 -0
  65. package/dist/wallets.d.ts +33 -240
  66. package/dist/wallets.d.ts.map +1 -1
  67. package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
  68. package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
  69. package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
  70. package/dist/widget/components/FeeOption.d.ts +8 -13
  71. package/dist/widget/components/FeeOption.d.ts.map +1 -1
  72. package/dist/widget/components/FeeOptions.d.ts +11 -5
  73. package/dist/widget/components/FeeOptions.d.ts.map +1 -1
  74. package/dist/widget/components/NativeGasOption.d.ts.map +1 -1
  75. package/dist/widget/components/Pay.d.ts.map +1 -1
  76. package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
  77. package/dist/widget/components/QRCodeDeposit.d.ts +5 -0
  78. package/dist/widget/components/QRCodeDeposit.d.ts.map +1 -1
  79. package/dist/widget/components/QRCodeWalletSelect.d.ts +13 -0
  80. package/dist/widget/components/QRCodeWalletSelect.d.ts.map +1 -0
  81. package/dist/widget/components/QrCode.d.ts.map +1 -1
  82. package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
  83. package/dist/widget/components/Receipt.d.ts.map +1 -1
  84. package/dist/widget/components/ScreenHeader.d.ts +1 -1
  85. package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
  86. package/dist/widget/components/SlippageToleranceSettings.d.ts +1 -0
  87. package/dist/widget/components/SlippageToleranceSettings.d.ts.map +1 -1
  88. package/dist/widget/components/Toast.d.ts.map +1 -1
  89. package/dist/widget/components/TokenImage.d.ts.map +1 -1
  90. package/dist/widget/components/WalletConnect.d.ts.map +1 -1
  91. package/dist/widget/css/compiled.css +1 -1
  92. package/dist/widget/hooks/useCheckout.d.ts +15 -1
  93. package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
  94. package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
  95. package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
  96. package/dist/widget/hooks/useDebugScreens.d.ts +1 -1
  97. package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -1
  98. package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
  99. package/dist/widget/hooks/useIsConnectedWalletSmartContract.d.ts +7 -0
  100. package/dist/widget/hooks/useIsConnectedWalletSmartContract.d.ts.map +1 -0
  101. package/dist/widget/hooks/useIsSequenceWallet.d.ts +6 -0
  102. package/dist/widget/hooks/useIsSequenceWallet.d.ts.map +1 -0
  103. package/dist/widget/hooks/useQuote.d.ts +6 -11
  104. package/dist/widget/hooks/useQuote.d.ts.map +1 -1
  105. package/dist/widget/hooks/useRecentTokens.d.ts.map +1 -1
  106. package/dist/widget/hooks/useSelectedFeeOption.d.ts +30 -0
  107. package/dist/widget/hooks/useSelectedFeeOption.d.ts.map +1 -0
  108. package/dist/widget/hooks/useSendForm.d.ts +6 -15
  109. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  110. package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
  111. package/dist/widget/index.d.ts +1 -0
  112. package/dist/widget/index.d.ts.map +1 -1
  113. package/dist/widget/index.js +4 -2
  114. package/dist/widget/providers/TrailsProvider.d.ts +29 -0
  115. package/dist/widget/providers/TrailsProvider.d.ts.map +1 -0
  116. package/dist/widget/widget.d.ts +14 -3
  117. package/dist/widget/widget.d.ts.map +1 -1
  118. package/package.json +9 -8
  119. package/src/analytics.ts +53 -21
  120. package/src/cctp.ts +0 -1016
  121. package/src/chains.ts +155 -68
  122. package/src/config.ts +51 -207
  123. package/src/constants.ts +1 -13
  124. package/src/contractUtils.ts +6 -6
  125. package/src/estimate.ts +3 -6
  126. package/src/fees.ts +5 -10
  127. package/src/gasless.ts +45 -0
  128. package/src/index.ts +18 -40
  129. package/src/indexerClient.ts +39 -48
  130. package/src/intents.ts +51 -226
  131. package/src/mutations.ts +3 -2
  132. package/src/paymasterSend.ts +2 -5
  133. package/src/prepareSend.ts +21 -14
  134. package/src/sendUserOp.ts +3 -64
  135. package/src/sequenceWallet.ts +1 -2
  136. package/src/tokenBalances.ts +2 -1
  137. package/src/tokens.ts +62 -133
  138. package/src/trailsClient.ts +17 -12
  139. package/src/transactionIntent/deposits/depositOrchestrator.ts +14 -15
  140. package/src/transactionIntent/deposits/gaslessDeposit.ts +70 -100
  141. package/src/transactionIntent/deposits/standardDeposit.ts +22 -28
  142. package/src/transactionIntent/execution/transactionState.ts +2 -2
  143. package/src/transactionIntent/handlers/crossChain.ts +179 -381
  144. package/src/transactionIntent/handlers/index.ts +0 -1
  145. package/src/transactionIntent/handlers/sameChainSameToken.ts +228 -94
  146. package/src/transactionIntent/quote/normalizeQuote.ts +4 -6
  147. package/src/transactionIntent/quote/quoteHelpers.ts +35 -3
  148. package/src/transactionIntent/types.ts +7 -27
  149. package/src/transactionIntent/utils/index.ts +0 -1
  150. package/src/transactions.ts +19 -118
  151. package/src/umd.tsx +1 -3
  152. package/src/utils.ts +28 -8
  153. package/src/walletUtils.ts +42 -0
  154. package/src/wallets.ts +365 -208
  155. package/src/widget/compiled.css +1 -1
  156. package/src/widget/components/AccountIntentTransactionHistory.tsx +78 -4
  157. package/src/widget/components/AccountSettings.tsx +17 -17
  158. package/src/widget/components/ChainList.tsx +3 -3
  159. package/src/widget/components/ClassicSwap.tsx +19 -10
  160. package/src/widget/components/ConfigDisplay.tsx +19 -59
  161. package/src/widget/components/FeeOption.tsx +63 -20
  162. package/src/widget/components/FeeOptions.tsx +54 -123
  163. package/src/widget/components/NativeGasOption.tsx +3 -1
  164. package/src/widget/components/Pay.tsx +18 -11
  165. package/src/widget/components/PoolDeposit.tsx +23 -10
  166. package/src/widget/components/QRCodeDeposit.tsx +50 -30
  167. package/src/widget/components/QRCodeWalletSelect.tsx +77 -0
  168. package/src/widget/components/QrCode.tsx +188 -233
  169. package/src/widget/components/QuoteDetails.tsx +48 -2
  170. package/src/widget/components/Receipt.tsx +5 -2
  171. package/src/widget/components/ScreenHeader.tsx +10 -8
  172. package/src/widget/components/SlippageToleranceSettings.tsx +63 -14
  173. package/src/widget/components/Toast.tsx +10 -0
  174. package/src/widget/components/TokenImage.tsx +56 -13
  175. package/src/widget/components/WalletConnect.tsx +37 -99
  176. package/src/widget/hooks/useCheckout.ts +71 -0
  177. package/src/widget/hooks/useCurrentScreen.tsx +1 -0
  178. package/src/widget/hooks/useDebugScreens.ts +5 -0
  179. package/src/widget/hooks/useIntentTransactionHistory.ts +790 -412
  180. package/src/widget/hooks/useIsConnectedWalletSmartContract.ts +43 -0
  181. package/src/widget/hooks/useIsSequenceWallet.ts +17 -0
  182. package/src/widget/hooks/useQuote.ts +27 -34
  183. package/src/widget/hooks/useRecentTokens.ts +2 -1
  184. package/src/widget/hooks/useSelectedFeeOption.tsx +257 -0
  185. package/src/widget/hooks/useSendForm.ts +175 -46
  186. package/src/widget/hooks/useTokenList.ts +15 -2
  187. package/src/widget/index.tsx +8 -0
  188. package/src/widget/providers/TrailsProvider.tsx +123 -0
  189. package/src/widget/widget.tsx +165 -143
  190. package/dist/cctpqueue.d.ts +0 -18
  191. package/dist/cctpqueue.d.ts.map +0 -1
  192. package/dist/preconditions.d.ts +0 -12
  193. package/dist/preconditions.d.ts.map +0 -1
  194. package/dist/trails.d.ts +0 -110
  195. package/dist/trails.d.ts.map +0 -1
  196. package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts +0 -62
  197. package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts.map +0 -1
  198. package/dist/transactionIntent/utils/lifiHelpers.d.ts +0 -10
  199. package/dist/transactionIntent/utils/lifiHelpers.d.ts.map +0 -1
  200. package/dist/widget/hooks/useSelectedFeeToken.d.ts +0 -33
  201. package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +0 -1
  202. package/src/cctpqueue.ts +0 -66
  203. package/src/preconditions.ts +0 -47
  204. package/src/trails.ts +0 -1303
  205. package/src/transactionIntent/handlers/sameChainDifferentToken.ts +0 -323
  206. package/src/transactionIntent/utils/lifiHelpers.ts +0 -68
  207. package/src/widget/hooks/useSelectedFeeToken.tsx +0 -288
package/src/intents.ts CHANGED
@@ -3,44 +3,25 @@ import type {
3
3
  CommitIntentResponse,
4
4
  Intent,
5
5
  IntentCalls,
6
- TransactionPrecondition,
7
6
  TrailsApi,
8
7
  ExecuteIntentRequest,
9
8
  GasFeeOptions,
10
9
  DepositSignature,
11
10
  } from "@0xsequence/trails-api"
11
+ import { JsonEncode } from "@0xsequence/trails-api"
12
12
  import type { TrailsClient } from "./trailsClient.js"
13
13
  import { logger } from "./logger.js"
14
- import { bigintReplacer } from "./utils.js"
15
-
16
- export type {
17
- IntentCalls,
18
- TransactionPrecondition,
19
- } from "@0xsequence/trails-api"
20
14
 
21
15
  import { Config, type Context, Payload } from "@0xsequence/wallet-primitives"
22
- import {
23
- AbiParameters,
24
- Address,
25
- Bytes,
26
- ContractAddress,
27
- Hash,
28
- type Hex,
29
- } from "ox"
16
+ import { Address, Bytes, ContractAddress, Hash, type Hex } from "ox"
30
17
  import {
31
18
  type Account,
32
19
  type Chain,
33
20
  isAddressEqual,
34
21
  type WalletClient,
35
- http,
36
- createPublicClient,
37
22
  } from "viem"
38
- import {
39
- ATTESATION_SIGNER_ADDRESS,
40
- SEQUENCE_V3_CONTRACT_ADDRESSES,
41
- } from "./constants.js"
42
- import { findPreconditionAddresses } from "./preconditions.js"
43
- import { getChainInfo } from "./chains.js"
23
+ import { getChainInfo, getPublicRpcClient } from "./chains.js"
24
+ import { SEQUENCE_V3_CONTRACT_ADDRESSES } from "./constants.js"
44
25
  import {
45
26
  trackTransactionStarted,
46
27
  trackTransactionSubmitted,
@@ -52,11 +33,10 @@ import {
52
33
  trackIntentCommitCompleted,
53
34
  trackIntentCommitError,
54
35
  } from "./analytics.js"
55
- import { getQueryParam } from "./queryParams.js"
56
36
  import { getFullErrorMessage } from "./error.js"
57
37
  import { GAS_BUFFER, getFeeData } from "./estimate.js"
58
38
  import { getERC20TransferData } from "./encoders.js"
59
- import { zeroAddress } from "viem"
39
+ import { isNativeToken } from "./utils.js"
60
40
 
61
41
  export type IntentRequestParams = {
62
42
  userAddress: string
@@ -135,27 +115,11 @@ export type SendOriginCallTxArgs = {
135
115
  maxPriorityFeePerGas?: bigint // Optional: EIP-1559 max priority fee per gas
136
116
  }
137
117
 
138
- export async function getLocalClientIfEnabled(
139
- trailsClient: TrailsApi,
140
- ): Promise<TrailsApi> {
141
- const localApiIntent = getQueryParam("localapiintent") === "true"
142
- if (localApiIntent) {
143
- // for testing local api changes
144
- const { getTrailsClient } = await import("./trailsClient.js")
145
- trailsClient = getTrailsClient({
146
- hostname: "http://localhost:4422",
147
- })
148
- }
149
- return trailsClient
150
- }
151
-
152
118
  export async function quoteIntent(
153
119
  trailsClient: TrailsApi,
154
120
  args: QuoteIntentRequest,
155
121
  additionalTrackingProps: Record<string, string> = {},
156
122
  ): Promise<{ intent: Intent; gasFeeOptions?: GasFeeOptions }> {
157
- trailsClient = await getLocalClientIfEnabled(trailsClient)
158
-
159
123
  // Track intent quote request
160
124
  trackIntentQuoteRequested({
161
125
  originChainId: args.originChainId || 0,
@@ -177,17 +141,9 @@ export async function quoteIntent(
177
141
 
178
142
  const result = response.intent
179
143
 
180
- // Extract precondition amounts
181
- const originChainId = args.originChainId || 0
182
- const destinationChainId = args.destinationChainId || 0
183
- const originPrecondition = result.preconditions?.find(
184
- (p: TransactionPrecondition) =>
185
- Number(p.chainId) === Number(originChainId),
186
- )
187
- const destinationPrecondition = result.preconditions?.find(
188
- (p: TransactionPrecondition) =>
189
- Number(p.chainId) === Number(destinationChainId),
190
- )
144
+ // Extract precondition amounts from origin and destination preconditions
145
+ const originPrecondition = result.originPrecondition
146
+ const destinationPrecondition = result.destinationPrecondition
191
147
 
192
148
  // Track successful intent quote received
193
149
  trackIntentQuoteReceived({
@@ -246,7 +202,7 @@ export function calculateIntentAddress(
246
202
  ): `0x${string}` {
247
203
  logger.console.log("[trails-sdk] calculateIntentAddress inputs:", {
248
204
  mainSigner,
249
- calls: JSON.stringify(calls, bigintReplacer, 2),
205
+ calls,
250
206
  })
251
207
 
252
208
  const context = SEQUENCE_V3_CONTRACT_ADDRESSES
@@ -351,25 +307,33 @@ export async function commitIntent(
351
307
  intent: Intent,
352
308
  additionalTrackingProps: Record<string, string> = {},
353
309
  ): Promise<CommitIntentResponse> {
354
- trailsClient = await getLocalClientIfEnabled(trailsClient)
310
+ // Build arrays for logging
311
+ const originIntentCalls = intent.originCalls
312
+ const destinationIntentCalls = intent.destinationCalls
313
+ const calls = []
314
+ if (originIntentCalls) calls.push(originIntentCalls)
315
+ if (destinationIntentCalls) calls.push(destinationIntentCalls)
316
+
317
+ const originPre = intent.originPrecondition
318
+ const destinationPre = intent.destinationPrecondition
319
+ const preconditions = []
320
+ if (originPre) preconditions.push(originPre)
321
+ if (destinationPre) preconditions.push(destinationPre)
355
322
 
356
323
  logger.console.log("[trails-sdk] commitIntent inputs:", {
357
324
  intentId: intent.intentId,
358
325
  ownerAddress: intent.ownerAddress,
359
326
  originIntentAddress: intent.originIntentAddress,
360
327
  destinationIntentAddress: intent.destinationIntentAddress,
361
- calls: JSON.stringify(intent.calls, bigintReplacer, 2),
362
- preconditions: JSON.stringify(intent.preconditions, bigintReplacer, 2),
328
+ calls,
329
+ preconditions,
363
330
  })
364
331
 
365
332
  // Additional detailed precondition logging
366
- logger.console.log(
367
- "[trails-sdk] Detailed preconditions:",
368
- intent.preconditions,
369
- )
333
+ logger.console.log("[trails-sdk] Detailed preconditions:", preconditions)
370
334
 
371
335
  // Log each precondition individually for easier reading
372
- intent.preconditions.forEach((precondition, index) => {
336
+ preconditions.forEach((precondition, index) => {
373
337
  logger.console.log(`[trails-sdk] Precondition ${index}:`, {
374
338
  type: precondition.type,
375
339
  chainId: precondition.chainId,
@@ -388,18 +352,12 @@ export async function commitIntent(
388
352
  intent.destinationIntentAddress,
389
353
  )
390
354
 
391
- const originChainIdStr = intent.calls[0]?.chainId
392
- const destinationChainIdStr = intent.calls[1]?.chainId
355
+ const originChainIdStr = intent.quoteRequest.originChainId.toString()
356
+ const destinationChainIdStr =
357
+ intent.quoteRequest.destinationChainId.toString()
393
358
 
394
- // The executionInfos could be empty, so we need to handle the undefined case.
395
- const { originAddress: receivedAddress } =
396
- originChainIdStr && destinationChainIdStr
397
- ? findPreconditionAddresses(
398
- intent.preconditions,
399
- Number(originChainIdStr),
400
- Number(destinationChainIdStr),
401
- )
402
- : { originAddress: undefined }
359
+ // Get the origin precondition owner address directly
360
+ const receivedAddress = originPre?.ownerAddress
403
361
 
404
362
  logger.console.log("[trails-sdk] Address comparison:", {
405
363
  receivedAddress,
@@ -461,8 +419,6 @@ export async function executeIntent(
461
419
  depositTransactionHash?: string,
462
420
  depositSignature?: DepositSignature,
463
421
  ) {
464
- trailsClient = await getLocalClientIfEnabled(trailsClient)
465
-
466
422
  logger.console.log("[trails-sdk] executeIntent inputs:", {
467
423
  intentId,
468
424
  depositTransactionHash,
@@ -521,10 +477,11 @@ export async function sendOriginTransaction(
521
477
  ...additionalTrackingProps,
522
478
  })
523
479
 
524
- const publicClient = createPublicClient({
525
- chain: getChainInfo(originParams.chain.id)!,
526
- transport: http(),
527
- })
480
+ const chainInfo = getChainInfo(originParams.chain.id)
481
+ if (!chainInfo) {
482
+ throw new Error(`Chain ${originParams.chain.id} not found`)
483
+ }
484
+ const publicClient = getPublicRpcClient(chainInfo)
528
485
 
529
486
  // Use provided gasLimit if available, otherwise estimate
530
487
  let gasLimit: bigint
@@ -649,137 +606,6 @@ export async function sendOriginTransaction(
649
606
  }
650
607
  }
651
608
 
652
- export interface OriginTokenParam {
653
- address: Address.Address
654
- chainId: bigint
655
- }
656
-
657
- export interface DestinationTokenParam {
658
- address: Address.Address
659
- chainId: bigint
660
- amount: bigint
661
- }
662
-
663
- export function hashIntentParams({
664
- userAddress,
665
- nonce,
666
- originTokens,
667
- destinationCalls,
668
- destinationTokens,
669
- }: {
670
- userAddress: Address.Address
671
- nonce: bigint
672
- originTokens: OriginTokenParam[]
673
- destinationCalls: Array<IntentCalls>
674
- destinationTokens: DestinationTokenParam[]
675
- }): string {
676
- if (
677
- !userAddress ||
678
- userAddress === "0x0000000000000000000000000000000000000000"
679
- )
680
- throw new Error("UserAddress is zero")
681
- if (typeof nonce !== "bigint") throw new Error("Nonce is not a bigint")
682
- if (!originTokens || originTokens.length === 0)
683
- throw new Error("OriginTokens is empty")
684
- if (!destinationCalls || destinationCalls.length === 0)
685
- throw new Error("DestinationCalls is empty")
686
- if (!destinationTokens || destinationTokens.length === 0)
687
- throw new Error("DestinationTokens is empty")
688
- for (let i = 0; i < destinationCalls.length; i++) {
689
- const currentCall = destinationCalls[i]
690
- if (!currentCall) throw new Error(`DestinationCalls[${i}] is nil`)
691
- if (!currentCall.calls || currentCall.calls.length === 0) {
692
- throw new Error(`DestinationCalls[${i}] has no calls`)
693
- }
694
- }
695
-
696
- const originTokensForAbi = originTokens.map((token) => ({
697
- address: token.address,
698
- chainId: token.chainId,
699
- }))
700
-
701
- let cumulativeCallsHashBytes: Bytes.Bytes = Bytes.from(new Uint8Array(32))
702
-
703
- for (let i = 0; i < destinationCalls.length; i++) {
704
- const callPayload = destinationCalls[i]
705
- if (!callPayload) throw new Error(`DestinationCalls[${i}] is nil`)
706
-
707
- const currentDestCallPayloadHashBytes = Payload.hash(
708
- ATTESATION_SIGNER_ADDRESS,
709
- Number(callPayload.chainId),
710
- {
711
- type: "call",
712
- space: callPayload.space ? BigInt(callPayload.space) : 0n,
713
- nonce: callPayload.nonce ? BigInt(callPayload.nonce) : 0n,
714
- calls: callPayload.calls.map((call) => ({
715
- type: "call",
716
- to: call.to as `0x${string}`,
717
- value: BigInt(call.value?.toString() || "0"),
718
- data: Bytes.toHex(Bytes.from((call.data as Hex.Hex) || "0x")),
719
- gasLimit: BigInt(call.gasLimit?.toString() || "0"),
720
- delegateCall: !!call.delegateCall,
721
- onlyFallback: !!call.onlyFallback,
722
- behaviorOnError:
723
- call.behaviorOnError === 0
724
- ? "ignore"
725
- : call.behaviorOnError === 1
726
- ? "revert"
727
- : "abort",
728
- })),
729
- },
730
- )
731
-
732
- cumulativeCallsHashBytes = Hash.keccak256(
733
- Bytes.concat(cumulativeCallsHashBytes, currentDestCallPayloadHashBytes),
734
- {
735
- as: "Bytes",
736
- },
737
- )
738
- }
739
- const cumulativeCallsHashHex = Bytes.toHex(cumulativeCallsHashBytes)
740
-
741
- const destinationTokensForAbi = destinationTokens.map((token) => ({
742
- address: token.address,
743
- chainId: token.chainId,
744
- amount: token.amount,
745
- }))
746
-
747
- const abiSchema = [
748
- { type: "address" },
749
- { type: "uint256" },
750
- {
751
- type: "tuple[]",
752
- components: [
753
- { name: "address", type: "address" },
754
- { name: "chainId", type: "uint256" },
755
- ],
756
- },
757
- {
758
- type: "tuple[]",
759
- components: [
760
- { name: "address", type: "address" },
761
- { name: "chainId", type: "uint256" },
762
- { name: "amount", type: "uint256" },
763
- ],
764
- },
765
- { type: "bytes32" },
766
- ]
767
-
768
- const encodedHex = AbiParameters.encode(abiSchema, [
769
- userAddress,
770
- nonce,
771
- originTokensForAbi,
772
- destinationTokensForAbi,
773
- cumulativeCallsHashHex,
774
- ]) as Hex.Hex
775
-
776
- const encodedBytes = Bytes.fromHex(encodedHex)
777
- const hashBytes = Hash.keccak256(encodedBytes)
778
- const hashHex = Bytes.toHex(hashBytes)
779
-
780
- return hashHex
781
- }
782
-
783
609
  export function calculateIntentConfigurationAddress(
784
610
  mainSigner: Address.Address,
785
611
  calls: Array<IntentCalls>,
@@ -872,7 +698,7 @@ function createIntentConfiguration(
872
698
  // Print the topology
873
699
  logger.console.log(
874
700
  "[trails-sdk] Topology:",
875
- JSON.stringify([mainSignerLeaf, secondaryTopologyNode], bigintReplacer, 2),
701
+ JsonEncode([mainSignerLeaf, secondaryTopologyNode]),
876
702
  )
877
703
 
878
704
  return {
@@ -935,19 +761,20 @@ export function buildSameChainSameTokenTransactionParams({
935
761
  return {
936
762
  to: hasCustomCalldata
937
763
  ? recipient
938
- : effectiveOriginTokenAddress === zeroAddress
764
+ : isNativeToken(effectiveOriginTokenAddress)
939
765
  ? recipient
940
766
  : effectiveOriginTokenAddress,
941
767
  data: hasCustomCalldata
942
768
  ? destinationCalldata || "0x"
943
- : effectiveOriginTokenAddress === zeroAddress
769
+ : isNativeToken(effectiveOriginTokenAddress)
944
770
  ? "0x"
945
771
  : getERC20TransferData({
946
772
  recipient,
947
773
  amount: BigInt(swapAmount),
948
774
  }),
949
- value:
950
- effectiveOriginTokenAddress === zeroAddress ? BigInt(swapAmount) : "0",
775
+ value: isNativeToken(effectiveOriginTokenAddress)
776
+ ? BigInt(swapAmount)
777
+ : "0",
951
778
  chainId: effectiveOriginChainId,
952
779
  chain: effectiveOriginChain,
953
780
  }
@@ -975,18 +802,16 @@ export function buildCrossChainDepositParams({
975
802
  const totalAmount = BigInt(depositAmount) + BigInt(fee)
976
803
 
977
804
  return {
978
- to:
979
- originTokenAddress === zeroAddress
980
- ? originIntentAddress
981
- : originTokenAddress,
982
- data:
983
- originTokenAddress === zeroAddress
984
- ? "0x"
985
- : getERC20TransferData({
986
- recipient: originIntentAddress,
987
- amount: totalAmount,
988
- }),
989
- value: originTokenAddress === zeroAddress ? totalAmount : "0",
805
+ to: isNativeToken(originTokenAddress)
806
+ ? originIntentAddress
807
+ : originTokenAddress,
808
+ data: isNativeToken(originTokenAddress)
809
+ ? "0x"
810
+ : getERC20TransferData({
811
+ recipient: originIntentAddress,
812
+ amount: totalAmount,
813
+ }),
814
+ value: isNativeToken(originTokenAddress) ? totalAmount : "0",
990
815
  chainId: originChainId,
991
816
  chain,
992
817
  }
package/src/mutations.ts CHANGED
@@ -28,8 +28,9 @@ export function useCommitIntent() {
28
28
  originIntentAddress: intent.originIntentAddress,
29
29
  })
30
30
 
31
- const originChainIdStr = intent.calls[0]?.chainId
32
- const destinationChainIdStr = intent.calls[1]?.chainId
31
+ const originChainIdStr = intent.quoteRequest.originChainId.toString()
32
+ const destinationChainIdStr =
33
+ intent.quoteRequest.destinationChainId.toString()
33
34
 
34
35
  try {
35
36
  // Track intent commit start
@@ -1,6 +1,5 @@
1
1
  import type { Account, Chain, PublicClient, WalletClient } from "viem"
2
2
  import {
3
- createPublicClient,
4
3
  encodeFunctionData,
5
4
  encodePacked,
6
5
  http,
@@ -11,6 +10,7 @@ import {
11
10
  toHex,
12
11
  zeroAddress,
13
12
  } from "viem"
13
+ import { getPublicRpcClient } from "./chains.js"
14
14
  import type { UserOperation } from "viem/account-abstraction"
15
15
  import {
16
16
  createBundlerClient,
@@ -194,10 +194,7 @@ export async function getPaymasterGaslessTransaction({
194
194
  delegatorSmartAccount: ToSimpleSmartAccountReturnType
195
195
  }): Promise<{ to: string; data: string; value: string }[]> {
196
196
  // Initialize clients
197
- const publicClient = createPublicClient({
198
- chain,
199
- transport: http(),
200
- })
197
+ const publicClient = getPublicRpcClient(chain)
201
198
 
202
199
  if (!walletClient.account) {
203
200
  throw new Error("No account found")
@@ -1,7 +1,7 @@
1
1
  import { abortControllerRegistry } from "./abortController.js"
2
- import { createPublicClient, http, zeroAddress } from "viem"
3
2
  import { trackPaymentError, trackPaymentStarted } from "./analytics.js"
4
- import { getSlippageTolerance } from "./config.js"
3
+ import { getSlippageToleranceValue } from "./widget/components/SlippageToleranceSettings.js"
4
+ import { isNativeToken } from "./utils.js"
5
5
  import { getERC20TransferData } from "./encoders.js"
6
6
  import { getTokenPrice } from "./prices.js"
7
7
  import {
@@ -11,7 +11,7 @@ import {
11
11
  import type { TransactionState } from "./transactions.js"
12
12
  import { logger } from "./logger.js"
13
13
  import { getIsCustomCalldata } from "./contractUtils.js"
14
- import { getChainInfo } from "./chains.js"
14
+ import { getChainInfo, getPublicRpcClient } from "./chains.js"
15
15
 
16
16
  // Import from transactionIntent module
17
17
  import {
@@ -33,7 +33,6 @@ export type {
33
33
  PrepareSendQuote,
34
34
  PrepareSendReturn,
35
35
  SendReturn,
36
- SelectedFeeToken,
37
36
  } from "./transactionIntent/index.js"
38
37
 
39
38
  // Re-export validators for backward compatibility
@@ -73,20 +72,28 @@ export async function prepareSend(
73
72
  sourceTokenDecimals,
74
73
  destinationTokenDecimals,
75
74
  paymasterUrl,
76
- slippageTolerance = getSlippageTolerance(),
75
+ slippageTolerance: slippageToleranceFromOptions,
77
76
  originNativeTokenPriceUsd,
78
77
  quoteProvider,
79
78
  fundMethod,
80
79
  mode,
81
80
  checkoutOnHandlers,
82
- selectedFeeToken,
81
+ selectedFeeOption,
83
82
  walletId,
84
83
  abortSignal,
85
84
  commitIntentFn,
86
85
  executeIntentFn,
86
+ sequenceProjectAccessKey,
87
+ sequenceIndexerUrl,
87
88
  } = options
88
89
  let { sourceTokenPriceUsd, destinationTokenPriceUsd } = options
89
90
 
91
+ // Use slippage from options, or get from localStorage with config default fallback
92
+ // The config default (slippageToleranceFromOptions) comes from React component context
93
+ const slippageTolerance = getSlippageToleranceValue(
94
+ slippageToleranceFromOptions || "0.01",
95
+ )
96
+
90
97
  if (!sourceTokenDecimals) {
91
98
  throw new Error("Source token decimals not provided")
92
99
  }
@@ -99,7 +106,7 @@ export async function prepareSend(
99
106
  const transactionStates: TransactionState[] = []
100
107
 
101
108
  // Validate recipient is not zero address
102
- if (recipient === zeroAddress) {
109
+ if (isNativeToken(recipient)) {
103
110
  throw new Error("Recipient address cannot be zero address")
104
111
  }
105
112
 
@@ -116,7 +123,7 @@ export async function prepareSend(
116
123
  if (
117
124
  !hasCustomCalldata &&
118
125
  tradeType === TradeType.EXACT_INPUT &&
119
- destinationTokenAddress !== zeroAddress
126
+ !isNativeToken(destinationTokenAddress)
120
127
  ) {
121
128
  // we need to set custom calldata for the cctp transfer in order to have destination intent adddress execution needed for metatxn tracking
122
129
  effectiveDestinationCalldata = getERC20TransferData({
@@ -260,10 +267,7 @@ export async function prepareSend(
260
267
  logger.console.log("[trails-sdk] isToSameChain", isToSameChain)
261
268
  logger.console.log("[trails-sdk] isToSameToken", isToSameToken)
262
269
 
263
- const publicClient = createPublicClient({
264
- chain,
265
- transport: http(),
266
- })
270
+ const publicClient = getPublicRpcClient(chain)
267
271
 
268
272
  // origin tx
269
273
  transactionStates.push({
@@ -368,7 +372,6 @@ export async function prepareSend(
368
372
  checkoutOnHandlers,
369
373
  paymasterUrl,
370
374
  quoteProvider,
371
- selectedFeeToken,
372
375
  walletId,
373
376
  trailsClient,
374
377
  mode,
@@ -376,6 +379,8 @@ export async function prepareSend(
376
379
  abortSignal,
377
380
  commitIntentFn,
378
381
  executeIntentFn,
382
+ sequenceProjectAccessKey,
383
+ sequenceIndexerUrl,
379
384
  })
380
385
  }
381
386
 
@@ -412,11 +417,13 @@ export async function prepareSend(
412
417
  fundMethod,
413
418
  mode,
414
419
  checkoutOnHandlers,
415
- selectedFeeToken,
420
+ selectedFeeOption,
416
421
  walletId,
417
422
  abortSignal,
418
423
  commitIntentFn,
419
424
  executeIntentFn,
425
+ sequenceProjectAccessKey,
426
+ sequenceIndexerUrl,
420
427
  })
421
428
  }
422
429
 
package/src/sendUserOp.ts CHANGED
@@ -2,19 +2,18 @@ import {
2
2
  type Address,
3
3
  type Chain,
4
4
  concat,
5
- createPublicClient,
6
5
  createWalletClient,
7
6
  encodeAbiParameters,
8
7
  encodeFunctionData,
9
8
  getAddress,
10
9
  type Hex,
11
- http,
12
10
  keccak256,
13
11
  pad,
14
12
  size,
15
13
  slice,
16
14
  toHex,
17
15
  } from "viem"
16
+ import { getHttpTransport, getPublicRpcClient } from "./chains.js"
18
17
  import { privateKeyToAccount } from "viem/accounts"
19
18
  import { logger } from "./logger.js"
20
19
 
@@ -187,14 +186,11 @@ export async function sendUserOperationDirectly({
187
186
 
188
187
  const walletClient = createWalletClient({
189
188
  chain: chain,
190
- transport: http(),
189
+ transport: getHttpTransport(chain.id),
191
190
  account: relayerAccount,
192
191
  })
193
192
 
194
- const publicClient = createPublicClient({
195
- chain: chain,
196
- transport: http(),
197
- })
193
+ const publicClient = getPublicRpcClient(chain)
198
194
 
199
195
  const packedOp = toPackedUserOperation(userOp) // converts to PackedUserOperation
200
196
 
@@ -467,63 +463,6 @@ export const packUserOps = (userOps: UserOperation[]) => {
467
463
  return packedUserOps as PackedUserOperation[]
468
464
  }
469
465
 
470
- export type UnpackedUserOperation = {
471
- sender: Address
472
- nonce: bigint
473
- callData: Hex
474
- callGasLimit: bigint
475
- factory: Address | null
476
- factoryData: Hex | null
477
- verificationGasLimit: bigint
478
- preVerificationGas: bigint
479
- maxFeePerGas: bigint
480
- maxPriorityFeePerGas: bigint
481
- paymaster: Address | null
482
- paymasterVerificationGasLimit: bigint | null
483
- paymasterPostOpGasLimit: bigint | null
484
- paymasterData: Hex | null
485
- signature: Hex
486
- }
487
-
488
- export function toUnpackedUserOperation(
489
- packedUserOperation: PackedUserOperation,
490
- ): UnpackedUserOperation {
491
- const { factory, factoryData } = unPackInitCode(packedUserOperation.initCode)
492
-
493
- const { callGasLimit, verificationGasLimit } = unpackAccountGasLimits(
494
- packedUserOperation.accountGasLimits,
495
- )
496
-
497
- const { maxFeePerGas, maxPriorityFeePerGas } = unpackGasLimits(
498
- packedUserOperation.gasFees,
499
- )
500
-
501
- const {
502
- paymaster,
503
- paymasterVerificationGasLimit,
504
- paymasterPostOpGasLimit,
505
- paymasterData,
506
- } = unpackPaymasterAndData(packedUserOperation.paymasterAndData)
507
-
508
- return {
509
- sender: packedUserOperation.sender,
510
- nonce: packedUserOperation.nonce,
511
- factory: factory,
512
- factoryData: factoryData,
513
- callData: packedUserOperation.callData,
514
- callGasLimit: callGasLimit,
515
- verificationGasLimit: verificationGasLimit,
516
- preVerificationGas: packedUserOperation.preVerificationGas,
517
- maxFeePerGas: maxFeePerGas,
518
- maxPriorityFeePerGas: maxPriorityFeePerGas,
519
- paymaster: paymaster,
520
- paymasterVerificationGasLimit: paymasterVerificationGasLimit,
521
- paymasterPostOpGasLimit: paymasterPostOpGasLimit,
522
- paymasterData: paymasterData,
523
- signature: packedUserOperation.signature,
524
- }
525
- }
526
-
527
466
  export function unPackInitCode(initCode: Hex) {
528
467
  if (initCode === "0x") {
529
468
  return {
@@ -12,7 +12,6 @@ import {
12
12
  toHex,
13
13
  type WalletClient,
14
14
  } from "viem"
15
- import { getSequenceProjectAccessKey } from "./config.js"
16
15
  import { logger } from "./logger.js"
17
16
 
18
17
  export type FlatTransaction = {
@@ -221,7 +220,7 @@ export async function sequenceSendTransaction(
221
220
  publicClient: PublicClient,
222
221
  calls: any[],
223
222
  chain: Chain,
224
- sequenceProjectAccessKey: string = getSequenceProjectAccessKey(),
223
+ sequenceProjectAccessKey: string,
225
224
  ): Promise<string | null> {
226
225
  const chainId = chain.id
227
226
  if (!accountClient?.account?.address || !sequenceWalletAddress) {