0xtrails 0.2.0 → 0.2.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.
Files changed (119) hide show
  1. package/dist/aave.d.ts.map +1 -1
  2. package/dist/analytics.d.ts +1 -0
  3. package/dist/analytics.d.ts.map +1 -1
  4. package/dist/{ccip-D6ToCrWc.js → ccip-ConT1gDe.js} +1 -1
  5. package/dist/chains.d.ts.map +1 -1
  6. package/dist/config.d.ts +1 -2
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/constants.d.ts +2 -2
  9. package/dist/constants.d.ts.map +1 -1
  10. package/dist/gasless.d.ts +19 -7
  11. package/dist/gasless.d.ts.map +1 -1
  12. package/dist/{index-BqgeTLL8.js → index-CMh8uEbV.js} +27716 -26616
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +68 -68
  16. package/dist/indexerClient.d.ts +10 -0
  17. package/dist/indexerClient.d.ts.map +1 -1
  18. package/dist/intentEntrypoint.d.ts +40 -14
  19. package/dist/intentEntrypoint.d.ts.map +1 -1
  20. package/dist/intents.d.ts.map +1 -1
  21. package/dist/prepareSend.d.ts +11 -8
  22. package/dist/prepareSend.d.ts.map +1 -1
  23. package/dist/relayer.d.ts.map +1 -1
  24. package/dist/tokenBalances.d.ts.map +1 -1
  25. package/dist/trails.d.ts.map +1 -1
  26. package/dist/trailsClient.d.ts.map +1 -1
  27. package/dist/trailsRouter.d.ts +22 -0
  28. package/dist/trailsRouter.d.ts.map +1 -0
  29. package/dist/transactions.d.ts +0 -1
  30. package/dist/transactions.d.ts.map +1 -1
  31. package/dist/widget/components/AccountSettings.d.ts.map +1 -1
  32. package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
  33. package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
  34. package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
  35. package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
  36. package/dist/widget/components/Earn.d.ts.map +1 -1
  37. package/dist/widget/components/FeeOption.d.ts +22 -0
  38. package/dist/widget/components/FeeOption.d.ts.map +1 -0
  39. package/dist/widget/components/FeeOptions.d.ts +13 -17
  40. package/dist/widget/components/FeeOptions.d.ts.map +1 -1
  41. package/dist/widget/components/Fund.d.ts.map +1 -1
  42. package/dist/widget/components/FundMethods.d.ts +1 -1
  43. package/dist/widget/components/FundMethods.d.ts.map +1 -1
  44. package/dist/widget/components/FundSendForm.d.ts.map +1 -1
  45. package/dist/widget/components/MeshConnectExchanges.d.ts +5 -2
  46. package/dist/widget/components/MeshConnectExchanges.d.ts.map +1 -1
  47. package/dist/widget/components/MeshConnectFlow.d.ts +2 -0
  48. package/dist/widget/components/MeshConnectFlow.d.ts.map +1 -1
  49. package/dist/widget/components/NativeGasOption.d.ts +12 -0
  50. package/dist/widget/components/NativeGasOption.d.ts.map +1 -0
  51. package/dist/widget/components/Pay.d.ts.map +1 -1
  52. package/dist/widget/components/PaySendForm.d.ts.map +1 -1
  53. package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
  54. package/dist/widget/components/TokenSelector.d.ts.map +1 -1
  55. package/dist/widget/components/UserPreferences.d.ts.map +1 -1
  56. package/dist/widget/hooks/useBack.d.ts +2 -0
  57. package/dist/widget/hooks/useBack.d.ts.map +1 -1
  58. package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
  59. package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
  60. package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
  61. package/dist/widget/hooks/useSelectedFeeToken.d.ts +32 -0
  62. package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +1 -0
  63. package/dist/widget/hooks/useSelectedMeshExchange.d.ts +14 -0
  64. package/dist/widget/hooks/useSelectedMeshExchange.d.ts.map +1 -0
  65. package/dist/widget/hooks/useSendForm.d.ts +8 -13
  66. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  67. package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
  68. package/dist/widget/index.js +1 -1
  69. package/dist/widget/widget.d.ts.map +1 -1
  70. package/package.json +29 -28
  71. package/src/aave.ts +90 -74
  72. package/src/analytics.ts +6 -0
  73. package/src/chains.ts +10 -0
  74. package/src/config.ts +25 -10
  75. package/src/constants.ts +11 -10
  76. package/src/gasless.ts +162 -109
  77. package/src/index.ts +1 -1
  78. package/src/indexerClient.ts +73 -1
  79. package/src/intentEntrypoint.ts +66 -101
  80. package/src/intents.ts +0 -2
  81. package/src/prepareSend.ts +1425 -887
  82. package/src/relayer.ts +4 -3
  83. package/src/tokenBalances.ts +8 -1
  84. package/src/trails.ts +1 -3
  85. package/src/trailsClient.ts +4 -1
  86. package/src/{balanceInjector.ts → trailsRouter.ts} +14 -14
  87. package/src/transactions.ts +4 -54
  88. package/src/widget/compiled.css +1 -1
  89. package/src/widget/components/AccountSettings.tsx +7 -1
  90. package/src/widget/components/ClassicSwap.tsx +173 -175
  91. package/src/widget/components/ConfigDisplay.tsx +34 -1
  92. package/src/widget/components/ConnectWallet.tsx +168 -11
  93. package/src/widget/components/ConnectedWallets.tsx +184 -102
  94. package/src/widget/components/DebugToast.tsx +3 -3
  95. package/src/widget/components/Earn.tsx +4 -27
  96. package/src/widget/components/FeeOption.tsx +78 -0
  97. package/src/widget/components/FeeOptions.tsx +192 -127
  98. package/src/widget/components/Fund.tsx +18 -27
  99. package/src/widget/components/FundMethods.tsx +3 -3
  100. package/src/widget/components/FundSendForm.tsx +0 -33
  101. package/src/widget/components/MeshConnectExchanges.tsx +32 -3
  102. package/src/widget/components/MeshConnectFlow.tsx +23 -4
  103. package/src/widget/components/NativeGasOption.tsx +99 -0
  104. package/src/widget/components/Pay.tsx +36 -32
  105. package/src/widget/components/PaySendForm.tsx +0 -37
  106. package/src/widget/components/QuoteDetails.tsx +0 -29
  107. package/src/widget/components/TokenSelector.tsx +11 -0
  108. package/src/widget/components/TransferPendingVertical.tsx +1 -1
  109. package/src/widget/components/UserPreferences.tsx +3 -4
  110. package/src/widget/hooks/useBack.tsx +4 -0
  111. package/src/widget/hooks/useCurrentScreen.tsx +1 -0
  112. package/src/widget/hooks/useDefaultTokenSelection.tsx +8 -8
  113. package/src/widget/hooks/useSelectedFeeToken.tsx +299 -0
  114. package/src/widget/hooks/useSelectedMeshExchange.tsx +46 -0
  115. package/src/widget/hooks/useSendForm.ts +78 -23
  116. package/src/widget/hooks/useTokenList.ts +10 -1
  117. package/src/widget/widget.tsx +173 -111
  118. package/dist/balanceInjector.d.ts +0 -22
  119. package/dist/balanceInjector.d.ts.map +0 -1
package/src/relayer.ts CHANGED
@@ -84,11 +84,12 @@ const relayerChainIdToSlug: Record<number, string> = {
84
84
 
85
85
  const relayerLocalhostUrlMap: Record<number, string> = {
86
86
  [mainnet.id]: "http://0.0.0.0:9969",
87
- [arbitrum.id]: "http://0.0.0.0:9997",
87
+ [katana.id]: "http://0.0.0.0:9994",
88
+ [apeChain.id]: "http://0.0.0.0:9995",
88
89
  [base.id]: "http://0.0.0.0:9996",
89
- [polygon.id]: "http://0.0.0.0:9999",
90
+ [arbitrum.id]: "http://0.0.0.0:9997",
90
91
  [optimism.id]: "http://0.0.0.0:9998",
91
- [apeChain.id]: "http://0.0.0.0:9995",
92
+ [polygon.id]: "http://0.0.0.0:9999",
92
93
  }
93
94
 
94
95
  export function getRelayerLocalhostUrl(chainId: number): string {
@@ -378,7 +378,14 @@ export function getTokenBalanceUsd(
378
378
  const isNative = isNativeToken(token)
379
379
  const decimals = isNative ? 18 : token.contractInfo?.decimals
380
380
  if (!decimals) {
381
- throw new Error("Decimals not found")
381
+ logger.console.error(
382
+ "[trails-sdk] [getTokenBalanceUsd] Missing decimals for token:",
383
+ {
384
+ token: token,
385
+ isNative,
386
+ },
387
+ )
388
+ return 0 // Return 0 instead of throwing
382
389
  }
383
390
  const formattedBalance = formatRawAmount(token.balance, decimals)
384
391
 
package/src/trails.ts CHANGED
@@ -1341,9 +1341,7 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
1341
1341
  (p.type === "transfer-native" || p.type === "native-balance") &&
1342
1342
  p.chainId === originChainId.toString(),
1343
1343
  )
1344
- const nativeMinAmount =
1345
- nativePrecondition?.data?.minAmount?.toString() ??
1346
- nativePrecondition?.data?.min?.toString()
1344
+ const nativeMinAmount = nativePrecondition?.data?.min?.toString()
1347
1345
  if (nativeMinAmount === undefined) {
1348
1346
  throw new Error(
1349
1347
  "Could not find native precondition (transfer-native or native-balance) or min amount",
@@ -30,7 +30,10 @@ export const useTrailsClient = (config?: TrailsClientConfig) => {
30
30
  const trailsClient = useMemo(() => {
31
31
  return getTrailsClient({
32
32
  hostname: config?.hostname || getTrailsApiUrl(),
33
- projectAccessKey: config?.projectAccessKey || projectAccessKey,
33
+ projectAccessKey:
34
+ getSequenceProjectAccessKey() ||
35
+ config?.projectAccessKey ||
36
+ projectAccessKey,
34
37
  jwt: config?.jwt || jwt,
35
38
  })
36
39
  }, [
@@ -1,7 +1,7 @@
1
1
  import { encodeFunctionData, zeroAddress } from "viem"
2
- import { TRAILS_BALANCE_INJECTOR_ADDRESS } from "./constants.js"
2
+ import { TRAILS_ROUTER_ADDRESS } from "./constants.js"
3
3
 
4
- export const TRAILS_CONTRACT_PLACEHOLDER_AMOUNT =
4
+ export const TRAILS_ROUTER_PLACEHOLDER_AMOUNT =
5
5
  0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefn
6
6
 
7
7
  function getAmountOffset(calldata: `0x${string}`, placeholder: bigint): number {
@@ -14,7 +14,7 @@ function getAmountOffset(calldata: `0x${string}`, placeholder: bigint): number {
14
14
  return byteOffset
15
15
  }
16
16
 
17
- const balanceInjectorAbi = [
17
+ const trailsRouterAbi = [
18
18
  {
19
19
  type: "function",
20
20
  name: "injectAndCall",
@@ -30,7 +30,7 @@ const balanceInjectorAbi = [
30
30
  },
31
31
  ]
32
32
 
33
- export function encodeBalanceInjectorCalldata({
33
+ export function encodeTrailsRouterCalldata({
34
34
  token,
35
35
  target,
36
36
  calldata,
@@ -48,13 +48,13 @@ export function encodeBalanceInjectorCalldata({
48
48
  `0x${placeholder.toString(16).padStart(64, "0")}` as `0x${string}`
49
49
 
50
50
  return encodeFunctionData({
51
- abi: balanceInjectorAbi,
51
+ abi: trailsRouterAbi,
52
52
  functionName: "injectAndCall",
53
53
  args: [token, target, calldata, amountOffset, placeholderBytes32],
54
54
  })
55
55
  }
56
56
 
57
- export function wrapCalldataWithBalanceInjectorIfNeeded({
57
+ export function wrapCalldataWithTrailsRouterIfNeeded({
58
58
  token,
59
59
  target,
60
60
  calldata,
@@ -72,13 +72,13 @@ export function wrapCalldataWithBalanceInjectorIfNeeded({
72
72
  amount: string
73
73
  originTokenAddress: string
74
74
  destinationTokenAddress: string
75
- }): { encodedCalldata: `0x${string}`; balanceInjectorAddress: string } | null {
75
+ }): { encodedCalldata: `0x${string}`; trailsRouterAddress: string } | null {
76
76
  const isSameToken =
77
77
  originTokenAddress?.toLowerCase() === destinationTokenAddress?.toLowerCase()
78
78
  const isDestinationNativeToken = destinationTokenAddress === zeroAddress
79
79
  if (originChainId === destinationChainId && isSameToken) {
80
80
  const amountHex = BigInt(amount).toString(16).padStart(64, "0") // 32-byte hex (no 0x)
81
- const placeholderHex = TRAILS_CONTRACT_PLACEHOLDER_AMOUNT.toString(
81
+ const placeholderHex = TRAILS_ROUTER_PLACEHOLDER_AMOUNT.toString(
82
82
  16,
83
83
  ).padStart(64, "0")
84
84
 
@@ -89,31 +89,31 @@ export function wrapCalldataWithBalanceInjectorIfNeeded({
89
89
  const calldataWithAmount = calldata.replace(placeholderHex, amountHex)
90
90
  return {
91
91
  encodedCalldata: calldataWithAmount as `0x${string}`,
92
- balanceInjectorAddress: target,
92
+ trailsRouterAddress: target,
93
93
  }
94
94
  }
95
95
 
96
- const balanceInjectorAddress = TRAILS_BALANCE_INJECTOR_ADDRESS
96
+ const trailsRouterAddress = TRAILS_ROUTER_ADDRESS
97
97
 
98
98
  const amountOffset = isDestinationNativeToken
99
99
  ? 0
100
- : getAmountOffset(calldata, BigInt(TRAILS_CONTRACT_PLACEHOLDER_AMOUNT))
100
+ : getAmountOffset(calldata, BigInt(TRAILS_ROUTER_PLACEHOLDER_AMOUNT))
101
101
  if (amountOffset === -1) {
102
102
  return null
103
103
  }
104
104
 
105
- const encodedCalldata = encodeBalanceInjectorCalldata({
105
+ const encodedCalldata = encodeTrailsRouterCalldata({
106
106
  token,
107
107
  target,
108
108
  calldata,
109
109
  amountOffset,
110
110
  placeholder: isDestinationNativeToken
111
111
  ? BigInt(0)
112
- : TRAILS_CONTRACT_PLACEHOLDER_AMOUNT,
112
+ : TRAILS_ROUTER_PLACEHOLDER_AMOUNT,
113
113
  })
114
114
 
115
115
  return {
116
116
  encodedCalldata,
117
- balanceInjectorAddress,
117
+ trailsRouterAddress,
118
118
  }
119
119
  }
@@ -1,32 +1,14 @@
1
1
  import { createPublicClient, http } from "viem"
2
2
  import { useQuery } from "@tanstack/react-query"
3
3
  import { getChainInfo } from "./chains.js"
4
- import { getSequenceProjectAccessKey, getSequenceEnv } from "./config.js"
4
+ import { getSequenceProjectAccessKey } from "./config.js"
5
5
  import { getTrailsClient } from "./trailsClient.js"
6
6
  import type { GuestModuleEvent, TrailsTokenSweeperEvent } from "./decoders.js"
7
- import {
8
- arbitrum,
9
- base,
10
- baseSepolia,
11
- optimism,
12
- polygon,
13
- mainnet,
14
- apeChain,
15
- arbitrumNova,
16
- avalanche,
17
- b3,
18
- blast,
19
- gnosis,
20
- soneium,
21
- xai,
22
- bsc,
23
- etherlink,
24
- katana,
25
- } from "viem/chains"
26
7
  import { logger } from "./logger.js"
27
8
  import { bigintReplacer } from "./utils.js"
28
9
  import { getExplorerUrl } from "./explorer.js"
29
10
  import { SortOrder } from "@0xsequence/trails-api"
11
+ import { getChainIndexerUrl } from "./indexerClient.js"
30
12
 
31
13
  export type TransactionStateStatus =
32
14
  | "pending"
@@ -202,43 +184,12 @@ export async function getTxTimeDiff(
202
184
  }
203
185
  }
204
186
 
205
- export function getIndexerUrlFromChainSlug(chainSlug: string) {
206
- const env = getSequenceEnv()
207
- let envPrefix = ""
208
-
209
- if (env === "dev") {
210
- envPrefix = "dev-"
211
- }
212
-
213
- return `https://${envPrefix}${chainSlug}-indexer.sequence.app`
214
- }
215
-
216
- const chainIdToIndexerUrl = {
217
- [arbitrum.id]: getIndexerUrlFromChainSlug("arbitrum"),
218
- [base.id]: getIndexerUrlFromChainSlug("base"),
219
- [baseSepolia.id]: getIndexerUrlFromChainSlug("base-sepolia"),
220
- [optimism.id]: getIndexerUrlFromChainSlug("optimism"),
221
- [polygon.id]: getIndexerUrlFromChainSlug("polygon"),
222
- [mainnet.id]: getIndexerUrlFromChainSlug("mainnet"),
223
- [apeChain.id]: getIndexerUrlFromChainSlug("apechain"),
224
- [arbitrumNova.id]: getIndexerUrlFromChainSlug("arbitrum-nova"),
225
- [avalanche.id]: getIndexerUrlFromChainSlug("avalanche"),
226
- [b3.id]: getIndexerUrlFromChainSlug("b3"),
227
- [blast.id]: getIndexerUrlFromChainSlug("blast"),
228
- [gnosis.id]: getIndexerUrlFromChainSlug("gnosis"),
229
- [soneium.id]: getIndexerUrlFromChainSlug("soneium"),
230
- [xai.id]: getIndexerUrlFromChainSlug("xai"),
231
- [bsc.id]: getIndexerUrlFromChainSlug("bsc"),
232
- 421613: getIndexerUrlFromChainSlug("arbitrum-nova-sepolia"),
233
- [etherlink.id]: getIndexerUrlFromChainSlug("etherlink"),
234
- [katana.id]: getIndexerUrlFromChainSlug("katana"),
235
- }
236
-
237
187
  export async function getAccountTransactionHistory({
238
188
  chainId,
239
189
  accountAddress,
240
190
  pageSize = 10,
241
191
  page = 1,
192
+
242
193
  includeMetadata = true,
243
194
  }: GetAccountTransactionHistoryParams): Promise<TransactionHistoryResponse> {
244
195
  const accessKey = getSequenceProjectAccessKey()
@@ -248,8 +199,7 @@ export async function getAccountTransactionHistory({
248
199
  }
249
200
 
250
201
  // Get the chain-specific indexer URL
251
- const chainIndexerUrl =
252
- chainIdToIndexerUrl[chainId as keyof typeof chainIdToIndexerUrl]
202
+ const chainIndexerUrl = getChainIndexerUrl(chainId)
253
203
  if (!chainIndexerUrl) {
254
204
  throw new Error(`Unsupported chain ID: ${chainId}`)
255
205
  }