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/chains.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { useQuery } from "@tanstack/react-query"
2
- import type { Chain as ViemChain } from "viem"
2
+ import type { Chain as ViemChain, PublicClient } from "viem"
3
+ import { createPublicClient, http } from "viem"
4
+ import { getConfig } from "./config.js"
3
5
 
4
6
  import {
5
7
  arbitrum,
@@ -35,10 +37,6 @@ import {
35
37
  } from "viem/chains"
36
38
  import { getRelaySupportedChains } from "./relaySdk.js"
37
39
  import { getLifiSupportedChains } from "./lifi.js"
38
- import {
39
- getSequenceProjectAccessKey,
40
- getSequenceNodeGatewayUrl,
41
- } from "./config.js"
42
40
  import type { QuoteProvider } from "./intents.js"
43
41
  import { somnia } from "./customChains.js"
44
42
 
@@ -89,44 +87,103 @@ export function getAllChains(): Chain[] {
89
87
  ]
90
88
  }
91
89
 
92
- function getSequenceRpcUrlFromSlug(chainSlug: string): string {
93
- return `${getSequenceNodeGatewayUrl()}/${chainSlug}`
90
+ function getSequenceRpcUrlFromSlug(
91
+ chainSlug: string,
92
+ sequenceNodeGatewayUrl: string,
93
+ ): string {
94
+ return `${sequenceNodeGatewayUrl}/${chainSlug}`
94
95
  }
95
96
 
96
97
  // Dynamic function to get sequence RPC URLs (computed at runtime to respect environment changes)
97
- function getSequenceRpcUrls(): Record<number, string> {
98
+ function getSequenceRpcUrls(
99
+ sequenceNodeGatewayUrl: string,
100
+ ): Record<number, string> {
98
101
  return {
99
- [arbitrum.id]: getSequenceRpcUrlFromSlug("arbitrum"),
100
- [base.id]: getSequenceRpcUrlFromSlug("base"),
101
- [mainnet.id]: getSequenceRpcUrlFromSlug("mainnet"),
102
- [optimism.id]: getSequenceRpcUrlFromSlug("optimism"),
103
- [gnosis.id]: getSequenceRpcUrlFromSlug("gnosis"),
104
- [polygon.id]: getSequenceRpcUrlFromSlug("polygon"),
105
- [soneium.id]: getSequenceRpcUrlFromSlug("soneium"),
106
- [somnia.id]: getSequenceRpcUrlFromSlug("somnia"),
107
- [xai.id]: getSequenceRpcUrlFromSlug("xai"),
108
- [apeChain.id]: getSequenceRpcUrlFromSlug("apechain"),
109
- [arbitrumNova.id]: getSequenceRpcUrlFromSlug("arbitrum-nova"),
110
- [avalanche.id]: getSequenceRpcUrlFromSlug("avalanche"),
111
- [b3.id]: getSequenceRpcUrlFromSlug("b3"),
112
- [blast.id]: getSequenceRpcUrlFromSlug("blast"),
113
- [bsc.id]: getSequenceRpcUrlFromSlug("bsc"),
114
- [katana.id]: getSequenceRpcUrlFromSlug("katana"),
115
- [etherlink.id]: getSequenceRpcUrlFromSlug("etherlink"),
102
+ [arbitrum.id]: getSequenceRpcUrlFromSlug(
103
+ "arbitrum",
104
+ sequenceNodeGatewayUrl,
105
+ ),
106
+ [base.id]: getSequenceRpcUrlFromSlug("base", sequenceNodeGatewayUrl),
107
+ [mainnet.id]: getSequenceRpcUrlFromSlug("mainnet", sequenceNodeGatewayUrl),
108
+ [optimism.id]: getSequenceRpcUrlFromSlug(
109
+ "optimism",
110
+ sequenceNodeGatewayUrl,
111
+ ),
112
+ [gnosis.id]: getSequenceRpcUrlFromSlug("gnosis", sequenceNodeGatewayUrl),
113
+ [polygon.id]: getSequenceRpcUrlFromSlug("polygon", sequenceNodeGatewayUrl),
114
+ [soneium.id]: getSequenceRpcUrlFromSlug("soneium", sequenceNodeGatewayUrl),
115
+ [somnia.id]: getSequenceRpcUrlFromSlug("somnia", sequenceNodeGatewayUrl),
116
+ [xai.id]: getSequenceRpcUrlFromSlug("xai", sequenceNodeGatewayUrl),
117
+ [apeChain.id]: getSequenceRpcUrlFromSlug(
118
+ "apechain",
119
+ sequenceNodeGatewayUrl,
120
+ ),
121
+ [arbitrumNova.id]: getSequenceRpcUrlFromSlug(
122
+ "arbitrum-nova",
123
+ sequenceNodeGatewayUrl,
124
+ ),
125
+ [avalanche.id]: getSequenceRpcUrlFromSlug(
126
+ "avalanche",
127
+ sequenceNodeGatewayUrl,
128
+ ),
129
+ [b3.id]: getSequenceRpcUrlFromSlug("b3", sequenceNodeGatewayUrl),
130
+ [blast.id]: getSequenceRpcUrlFromSlug("blast", sequenceNodeGatewayUrl),
131
+ [bsc.id]: getSequenceRpcUrlFromSlug("bsc", sequenceNodeGatewayUrl),
132
+ [katana.id]: getSequenceRpcUrlFromSlug("katana", sequenceNodeGatewayUrl),
133
+ [etherlink.id]: getSequenceRpcUrlFromSlug(
134
+ "etherlink",
135
+ sequenceNodeGatewayUrl,
136
+ ),
116
137
  }
117
138
  }
118
139
 
119
140
  export const getRpcUrl = (
120
141
  chainId: number,
121
- sequenceProjectAccessKey: string = getSequenceProjectAccessKey(),
142
+ sequenceProjectAccessKey: string,
143
+ sequenceNodeGatewayUrl: string,
122
144
  ): string | null => {
123
- const sequenceRpcUrls = getSequenceRpcUrls()
145
+ const sequenceRpcUrls = getSequenceRpcUrls(sequenceNodeGatewayUrl)
124
146
  if (!sequenceRpcUrls[chainId]) {
125
147
  return null
126
148
  }
127
149
  return `${sequenceRpcUrls[chainId]}/${sequenceProjectAccessKey}`
128
150
  }
129
151
 
152
+ /**
153
+ * Get HTTP transport for a chain using Sequence RPC URLs
154
+ * This is a temporary solution to use global config for RPC URLs
155
+ * @param chainId - The chain ID to get the transport for
156
+ * @returns Viem HTTP transport configured with Sequence RPC URL if available
157
+ */
158
+ export function getHttpTransport(chainId: number) {
159
+ const config = getConfig()
160
+ const trailsApiKey = config.trailsApiKey
161
+ const sequenceNodeGatewayUrl = config.sequenceNodeGatewayUrl
162
+
163
+ if (trailsApiKey && sequenceNodeGatewayUrl) {
164
+ const rpcUrl = getRpcUrl(chainId, trailsApiKey, sequenceNodeGatewayUrl)
165
+ if (rpcUrl) {
166
+ return http(rpcUrl)
167
+ }
168
+ }
169
+
170
+ // Fallback to default http() if Sequence RPC URL is not available
171
+ return http()
172
+ }
173
+
174
+ /**
175
+ * Create a public RPC client for a chain using Sequence RPC URLs
176
+ * This is a temporary solution to use global config for RPC URLs
177
+ * @param chain - The chain to create the public client for
178
+ * @returns Viem PublicClient configured with Sequence RPC URL if available
179
+ */
180
+ export function getPublicRpcClient(chain: Chain): PublicClient {
181
+ return createPublicClient({
182
+ chain,
183
+ transport: getHttpTransport(chain.id),
184
+ })
185
+ }
186
+
130
187
  export const supportedSequenceChains: Record<number, Chain> = {
131
188
  [apeChain.id]: getChainInfo(apeChain.id)!,
132
189
  [arbitrum.id]: getChainInfo(arbitrum.id)!,
@@ -186,15 +243,28 @@ export const mainnetChainsToTestnetChains: Record<number, Chain> = {
186
243
  // Helper to get chain info
187
244
  export function getChainInfo(
188
245
  chainId?: number,
189
- options?: { usePublicRpc?: boolean },
246
+ options?: {
247
+ usePublicRpc?: boolean
248
+ sequenceProjectAccessKey?: string
249
+ sequenceNodeGatewayUrl?: string
250
+ },
190
251
  ): Chain | null {
191
252
  if (!chainId) return null
192
253
  const chainInfo =
193
254
  getAllChains().find((chain: Chain) => chain.id === chainId) || null
194
255
 
195
256
  // Use Sequence RPC by default. We'll want to use public RPC when adding chains to user's metamask wallet.
196
- if (chainInfo && !options?.usePublicRpc) {
197
- const rpcUrl = getRpcUrl(chainId)
257
+ if (
258
+ chainInfo &&
259
+ !options?.usePublicRpc &&
260
+ options?.sequenceProjectAccessKey &&
261
+ options?.sequenceNodeGatewayUrl
262
+ ) {
263
+ const rpcUrl = getRpcUrl(
264
+ chainId,
265
+ options.sequenceProjectAccessKey,
266
+ options.sequenceNodeGatewayUrl,
267
+ )
198
268
  if (rpcUrl) {
199
269
  chainInfo.rpcUrls = {
200
270
  default: {
@@ -247,30 +317,67 @@ export async function getSupportedSequenceChains(): Promise<Chain[]> {
247
317
  return Object.values(supportedSequenceChains)
248
318
  }
249
319
 
250
- export async function getSupportedSequenceTestnetChains(): Promise<Chain[]> {
251
- return Object.values(supportedSequenceTestnetChains)
320
+ // Chain order for sorting (in the desired display order)
321
+ const CHAIN_ORDER = [
322
+ 1, // Ethereum
323
+ 8453, // Base
324
+ 42161, // Arbitrum
325
+ 137, // Polygon
326
+ 747474, // Katana
327
+ 56, // BNB Smart Chain
328
+ 10, // Optimism
329
+ 43114, // Avalanche
330
+ 42170, // Arbitrum Nova
331
+ 42793, // Etherlink
332
+ 100, // Gnosis
333
+ 8333, // B3
334
+ 33139, // Ape Chain
335
+ 1868, // Soneium
336
+ 5031, // Somnia
337
+ 660279, // Xai
338
+ ]
339
+
340
+ // Mapping of chain ID to normalized display name
341
+ const CHAIN_NAME_MAP: Record<number, string> = {
342
+ [arbitrum.id]: "Arbitrum", // Rename from "Arbitrum One"
343
+ [optimism.id]: "Optimism", // Rename from "OP Mainnet"
344
+ [soneium.id]: "Soneium", // Rename from "Soneium Mainnet"
345
+ [xai.id]: "Xai", // Rename from "Xai Mainnet"
252
346
  }
253
347
 
254
- // Priority chains that should appear first in the list
255
- const PRIORITY_CHAIN_IDS = [1, 8453, 42161, 10, 137]
348
+ /**
349
+ * Gets the normalized display name for a chain.
350
+ * @param chainId - The chain ID
351
+ * @param originalName - The original chain name from viem
352
+ * @returns The normalized chain name
353
+ */
354
+ export function getNormalizedChainName(
355
+ chainId: number,
356
+ originalName: string,
357
+ ): string {
358
+ return CHAIN_NAME_MAP[chainId] || originalName
359
+ }
256
360
 
257
- // Sort function for chains with priority order and then by name
258
- function sortChains(chainList: Chain[]): Chain[] {
361
+ /**
362
+ * Sorts chains by the predefined order, then alphabetically for chains not in the order.
363
+ * @param chainList - The list of chains to sort
364
+ * @returns The sorted list of chains
365
+ */
366
+ export function sortChainsByOrder(chainList: Chain[]): Chain[] {
259
367
  return chainList.sort((a, b) => {
260
- // 1. Priority chains first (1, 8453, 42161, 10, 137)
261
- const aPriority = PRIORITY_CHAIN_IDS.indexOf(a.id)
262
- const bPriority = PRIORITY_CHAIN_IDS.indexOf(b.id)
368
+ const aIndex = CHAIN_ORDER.indexOf(a.id)
369
+ const bIndex = CHAIN_ORDER.indexOf(b.id)
263
370
 
264
- // If both are priority chains, sort by priority order
265
- if (aPriority !== -1 && bPriority !== -1) {
266
- return aPriority - bPriority
371
+ // If both chains are in the order, sort by their position
372
+ if (aIndex !== -1 && bIndex !== -1) {
373
+ return aIndex - bIndex
267
374
  }
268
375
 
269
- // If only one is a priority chain, prioritize it
270
- if (aPriority !== -1) return -1
271
- if (bPriority !== -1) return 1
376
+ // If only one chain is in the order, prioritize it
377
+ if (aIndex !== -1) return -1
378
+ if (bIndex !== -1) return 1
272
379
 
273
- // 2. Sort by chain name alphabetically
380
+ // If neither chain is in the order, sort alphabetically
274
381
  return a.name.localeCompare(b.name)
275
382
  })
276
383
  }
@@ -312,10 +419,8 @@ export async function getSupportedChains({
312
419
  (chain, index, self) => index === self.findIndex((c) => c.id === chain.id),
313
420
  )
314
421
 
315
- const sortedChains = sortChains(uniqueChains)
316
-
317
- // Sort chains by priority and then by name
318
- return sortedChains
422
+ // Sort chains by predefined order
423
+ return sortChainsByOrder(uniqueChains)
319
424
  }
320
425
 
321
426
  export function useSupportedChains({
@@ -345,21 +450,3 @@ export function getIsTestnetChainId(chainId: number): boolean {
345
450
  const testnetChainIds = Object.keys(supportedSequenceTestnetChains)
346
451
  return testnetChainIds.includes(chainId.toString())
347
452
  }
348
-
349
- // Get chain color for UI styling
350
- export function getChainColor(chainId: number): string {
351
- switch (chainId) {
352
- case 1:
353
- return "bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-200" // More gray-blue for Ethereum
354
- case 8453:
355
- return "bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200" // Blue for Base
356
- case 42161:
357
- return "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200"
358
- case 137:
359
- return "bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200"
360
- case 10:
361
- return "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200"
362
- default:
363
- return "bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-200"
364
- }
365
- }
package/src/config.ts CHANGED
@@ -1,130 +1,57 @@
1
1
  import {
2
2
  PROD_SEQUENCE_INDEXER_URL,
3
+ PROD_SEQUENCE_METADATA_URL,
3
4
  DEFAULT_WALLETCONNECT_PROJECT_ID,
4
5
  DEFAULT_SLIPPAGE_TOLERANCE,
5
- PROD_SEQUENCE_PROJECT_ACCESS_KEY,
6
- DEV_SEQUENCE_INDEXER_URL,
7
- DEV_TRAILS_API_URL,
8
- DEV_SEQUENCE_PROJECT_ACCESS_KEY,
9
- DEFAULT_SEQUENCE_ENV,
10
6
  PROD_SEQUENCE_NODE_GATEWAY_URL,
11
- DEV_SEQUENCE_NODE_GATEWAY_URL,
12
7
  PROD_TRAILS_API_URL,
13
- LOCAL_TRAILS_API_URL,
14
8
  } from "./constants.js"
15
9
  import { getQueryParam } from "./queryParams.js"
16
10
  import { logger } from "./logger.js"
17
11
 
18
- export type SequenceEnv = "prod" | "dev" | "local" | "cors-anywhere"
19
-
20
- export const globalConfig: {
21
- sequenceProjectAccessKey: string
22
- sequenceIndexerUrl: string
23
- sequenceNodeGatewayUrl: string
24
- trailsApiUrl: string
25
- sequenceEnv: SequenceEnv
26
- walletConnectProjectId: string
27
- slippageTolerance: string
28
- debug: boolean
29
- commitHash: string | undefined
30
- } = {
31
- commitHash: declareCommitHash(),
32
- sequenceEnv: declareSequenceEnv(),
33
- sequenceProjectAccessKey: declareSequenceProjectAccessKey(),
34
- sequenceIndexerUrl: declareSequenceIndexerUrl(),
35
- sequenceNodeGatewayUrl: declareSequenceNodeGatewayUrl(),
36
- trailsApiUrl: declareTrailsApiUrl(),
12
+ export interface TrailsConfig {
13
+ trailsApiKey: string
14
+ trailsApiUrl?: string
15
+ sequenceIndexerUrl?: string
16
+ sequenceNodeGatewayUrl?: string
17
+ sequenceMetadataUrl?: string
18
+ walletConnectProjectId?: string
19
+ slippageTolerance?: string
20
+ debug?: boolean
21
+ commitHash?: string
22
+ }
23
+
24
+ const globalConfig: TrailsConfig = {
25
+ trailsApiKey: "",
26
+ sequenceIndexerUrl: PROD_SEQUENCE_INDEXER_URL,
27
+ sequenceNodeGatewayUrl: PROD_SEQUENCE_NODE_GATEWAY_URL,
28
+ sequenceMetadataUrl: PROD_SEQUENCE_METADATA_URL,
29
+ trailsApiUrl: PROD_TRAILS_API_URL,
37
30
  walletConnectProjectId: DEFAULT_WALLETCONNECT_PROJECT_ID,
38
31
  slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
39
32
  debug: false,
33
+ commitHash: declareCommitHash(),
40
34
  }
41
35
 
42
- export function declareSequenceEnv(): SequenceEnv {
43
- // Check for Vite development environment with HMR
44
- if (typeof window !== "undefined" && (import.meta as any)?.hot) {
45
- return "local"
46
- }
47
-
48
- // Check explicit ENV variable first
49
- const explicitEnv = getEnvVar("ENV")
50
- if (explicitEnv === "local") {
51
- return "local"
52
- }
53
- if (explicitEnv === "development" || explicitEnv === "dev") {
54
- return "dev"
55
- }
56
- if (explicitEnv === "production" || explicitEnv === "prod") {
57
- return "prod"
58
- }
59
-
60
- // Special handling for Cloudflare Pages branches
61
- const cfPagesBranch = getEnvVar("CF_PAGES_BRANCH")
62
- if (cfPagesBranch) {
63
- // If running on Cloudflare Pages, all branches except "production" default to dev
64
- if (cfPagesBranch === "prod" || cfPagesBranch === "production") {
65
- return "prod"
66
- }
67
- // Preview mode and other branches default to dev
68
- return "dev"
69
- }
70
-
71
- // If we're in a browser/Cloudflare environment but no explicit env is set,
72
- // check if we have dev environment variables set (indicating non-prod)
73
- // This helps with Cloudflare Workers preview mode
74
- if (typeof window !== "undefined" || typeof process === "undefined") {
75
- // In browser/Cloudflare Workers context, if no explicit prod indicators,
76
- // default to dev for safety (unless explicitly set to prod)
77
- // This prevents accidental prod usage in preview/staging environments
78
- return "dev"
79
- }
80
-
81
- return DEFAULT_SEQUENCE_ENV
82
- }
83
-
84
- export function declareSequenceIndexerUrl() {
85
- if (declareSequenceEnv() === "prod") {
86
- return PROD_SEQUENCE_INDEXER_URL
87
- }
88
- return DEV_SEQUENCE_INDEXER_URL
89
- }
90
-
91
- export function declareTrailsApiUrl() {
92
- if (declareSequenceEnv() === "prod") {
93
- return PROD_TRAILS_API_URL
94
- }
95
- if (declareSequenceEnv() === "local") {
96
- return LOCAL_TRAILS_API_URL
97
- }
98
- return DEV_TRAILS_API_URL
99
- }
100
-
101
- export function declareSequenceNodeGatewayUrl() {
102
- if (declareSequenceEnv() === "prod") {
103
- return PROD_SEQUENCE_NODE_GATEWAY_URL
104
- }
105
- return DEV_SEQUENCE_NODE_GATEWAY_URL
36
+ /**
37
+ * Updates the global config with new values
38
+ * This is a temporary solution to sync config from TrailsProvider
39
+ */
40
+ export function updateGlobalConfig(updates: Partial<TrailsConfig>) {
41
+ Object.assign(globalConfig, updates)
106
42
  }
107
43
 
108
- export function declareSequenceProjectAccessKey() {
109
- // Check for explicit env var override first (works in all environments)
110
- const envVarKey =
111
- getEnvVar("SEQUENCE_PROJECT_ACCESS_KEY") ||
112
- getEnvVar("PROJECT_ACCESS_KEY") ||
113
- getEnvVar("VITE_SEQUENCE_PROJECT_ACCESS_KEY") ||
114
- getEnvVar("VITE_PROJECT_ACCESS_KEY")
115
- if (envVarKey) {
116
- return envVarKey
117
- }
118
-
119
- // Use dev/prod keys based on environment
120
- const sequenceEnv = declareSequenceEnv()
121
- if (sequenceEnv === "prod") {
122
- return PROD_SEQUENCE_PROJECT_ACCESS_KEY
123
- }
124
-
125
- return DEV_SEQUENCE_PROJECT_ACCESS_KEY
44
+ // DEPRECATED: Use TrailsProvider context instead
45
+ // This is kept only for backward compatibility during migration
46
+ export function getConfig<T extends keyof TrailsConfig | undefined = undefined>(
47
+ propName?: T,
48
+ ): T extends undefined ? Readonly<TrailsConfig> : TrailsConfig[NonNullable<T>] {
49
+ // console.warn(
50
+ // "[trails-sdk] getConfig is deprecated. Use TrailsProvider context with useTrails() hook instead.",
51
+ // propName,
52
+ // )
53
+ return (propName ? globalConfig[propName] : globalConfig) as any
126
54
  }
127
-
128
55
  export function declareCommitHash() {
129
56
  const cfPagesCommitHash = getEnvVar("CF_PAGES_COMMIT_SHA")
130
57
  const viteCommitHash = getEnvVar("VITE_COMMIT_SHA")
@@ -141,121 +68,38 @@ export function declareCommitHash() {
141
68
  return cfPagesCommitHash || viteCommitHash
142
69
  }
143
70
 
144
- export function getSequenceConfig() {
145
- return globalConfig
146
- }
147
-
148
- export function getSequenceProjectAccessKey() {
149
- return globalConfig.sequenceProjectAccessKey
150
- }
151
-
152
- export function setSequenceProjectAccessKey(sequenceProjectAccessKey: string) {
153
- globalConfig.sequenceProjectAccessKey = sequenceProjectAccessKey
154
- }
155
-
156
- export function setSequenceIndexerUrl(sequenceIndexerUrl: string) {
157
- globalConfig.sequenceIndexerUrl = sequenceIndexerUrl
158
- }
159
-
160
- export function getSequenceIndexerUrl() {
161
- return globalConfig.sequenceIndexerUrl
162
- }
163
-
164
- export function setSequenceNodeGatewayUrl(sequenceNodeGatewayUrl: string) {
165
- globalConfig.sequenceNodeGatewayUrl = sequenceNodeGatewayUrl
166
- }
167
-
168
- export function getSequenceNodeGatewayUrl() {
169
- return globalConfig.sequenceNodeGatewayUrl
170
- }
171
-
172
- export function setTrailsApiUrl(trailsApiUrl: string) {
173
- globalConfig.trailsApiUrl = trailsApiUrl
174
- }
175
-
176
- export function getTrailsApiUrl() {
177
- return globalConfig.trailsApiUrl
178
- }
179
-
180
- export function setSequenceEnv(sequenceEnv: SequenceEnv) {
181
- globalConfig.sequenceEnv = sequenceEnv
182
-
183
- if (sequenceEnv === "prod") {
184
- setSequenceIndexerUrl(PROD_SEQUENCE_INDEXER_URL)
185
- setTrailsApiUrl(PROD_TRAILS_API_URL)
186
- setSequenceNodeGatewayUrl(PROD_SEQUENCE_NODE_GATEWAY_URL)
187
- setSequenceProjectAccessKey(PROD_SEQUENCE_PROJECT_ACCESS_KEY)
188
- }
189
-
190
- if (sequenceEnv === "local") {
191
- if (getEnvVar("TRAILS_API_URL")) {
192
- setTrailsApiUrl(getEnvVar("TRAILS_API_URL"))
193
- }
194
- }
195
-
196
- if (sequenceEnv === "dev") {
197
- setSequenceIndexerUrl(DEV_SEQUENCE_INDEXER_URL)
198
- setTrailsApiUrl(DEV_TRAILS_API_URL)
199
- setSequenceNodeGatewayUrl(DEV_SEQUENCE_NODE_GATEWAY_URL)
200
- setSequenceProjectAccessKey(DEV_SEQUENCE_PROJECT_ACCESS_KEY)
201
- }
202
- }
203
-
204
- export function getSequenceEnv() {
205
- return globalConfig.sequenceEnv
206
- }
207
-
208
- export function setWalletConnectProjectId(walletConnectProjectId: string) {
209
- globalConfig.walletConnectProjectId = walletConnectProjectId
210
- }
211
-
212
- export function getWalletConnectProjectId() {
213
- return globalConfig.walletConnectProjectId
214
- }
215
-
216
- /**
217
- * Set slippage tolerance for swaps
218
- * @param slippageTolerance - Slippage tolerance as decimal string (e.g., "0.05" for 5%, "0.001" for 0.1%)
219
- */
220
- export function setSlippageTolerance(slippageTolerance: string) {
221
- globalConfig.slippageTolerance = slippageTolerance
222
- }
71
+ // DEPRECATED: These getter functions are kept for backward compatibility
72
+ // New code should use TrailsProvider context with useTrails() hook
223
73
 
224
74
  /**
225
- * Get current slippage tolerance
226
- * @returns Slippage tolerance as decimal string (e.g., "0.05" for 5%, "0.001" for 0.1%)
75
+ * @deprecated Use TrailsProvider context instead
227
76
  */
228
77
  export function getSlippageTolerance() {
229
78
  return globalConfig.slippageTolerance
230
79
  }
231
80
 
232
- export function setDebug(debug: boolean) {
233
- globalConfig.debug = debug
234
- }
235
-
81
+ /**
82
+ * @deprecated Use TrailsProvider context instead
83
+ */
236
84
  export function getDebug() {
237
85
  return globalConfig.debug || getQueryParam("debug") === "true"
238
86
  }
239
87
 
240
- export function setCommitHash(commitHash: string) {
241
- globalConfig.commitHash = commitHash
242
- logger.console.log(
243
- `[trails-sdk][config] commit hash manually set to: ${commitHash}`,
244
- )
88
+ /**
89
+ * Sets the global debug mode for backward compatibility with getDebug()
90
+ * This is called by TrailsProvider to sync the debug state
91
+ */
92
+ export function setGlobalDebug(debug: boolean) {
93
+ globalConfig.debug = debug
245
94
  }
246
95
 
96
+ /**
97
+ * @deprecated Use TrailsProvider context instead
98
+ */
247
99
  export function getCommitHash() {
248
100
  return globalConfig.commitHash
249
101
  }
250
102
 
251
- export function getAccountIntentTransactionHistory() {
252
- return FeatureFlags.accountIntentTransactionHistory
253
- }
254
-
255
- export const FeatureFlags = {
256
- accountIntentTransactionHistory: false,
257
- }
258
-
259
103
  export function getEnvVar(name: string) {
260
104
  // In Vite/browser environments, check import.meta.env first
261
105
  // This is where Vite injects environment variables at build time
package/src/constants.ts CHANGED
@@ -27,22 +27,10 @@ export const TRAILS_INTENT_ENTRYPOINT_ADDRESS: Address.Address =
27
27
  export const ATTESATION_SIGNER_ADDRESS: Address.Address =
28
28
  "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
29
29
 
30
- export const DEFAULT_SEQUENCE_ENV = "prod"
31
-
32
30
  export const PROD_SEQUENCE_NODE_GATEWAY_URL = "https://nodes.sequence.app"
33
31
  export const PROD_SEQUENCE_INDEXER_URL = "https://indexer.sequence.app"
32
+ export const PROD_SEQUENCE_METADATA_URL = "https://metadata.sequence.app"
34
33
  export const PROD_TRAILS_API_URL = "https://trails-api.sequence.app"
35
- export const DEV_SEQUENCE_NODE_GATEWAY_URL = "https://dev-nodes.sequence.app"
36
- export const DEV_SEQUENCE_INDEXER_URL = "https://dev-indexer.sequence.app"
37
- export const DEV_TRAILS_API_URL = "https://dev-trails-api.sequence-dev.app"
38
-
39
- export const LOCAL_TRAILS_API_URL = "http://localhost:4422"
40
-
41
- // This is used for Sequence Indexer and API
42
- export const PROD_SEQUENCE_PROJECT_ACCESS_KEY =
43
- "AQAAAAAAAKhGHJc3N5V2AWqfJ1v9xZ2u0nA"
44
- export const DEV_SEQUENCE_PROJECT_ACCESS_KEY =
45
- "AQAAAAAAAAaq1E41OU0QxifQgrVBMgfqg7k"
46
34
 
47
35
  export const DATABEAT_SERVER = "https://databeat.sequence.app"
48
36
  export const DATABEAT_KEY =
@@ -1,12 +1,12 @@
1
- import { createPublicClient, http } from "viem"
2
- import { getChainInfo } from "./chains.js"
1
+ import { getChainInfo, getPublicRpcClient } from "./chains.js"
3
2
  import { logger } from "./logger.js"
4
3
 
5
4
  export async function getIsContract(address: `0x${string}`, chainId: number) {
6
- const client = createPublicClient({
7
- chain: getChainInfo(chainId)!,
8
- transport: http(),
9
- })
5
+ const chainInfo = getChainInfo(chainId)
6
+ if (!chainInfo) {
7
+ throw new Error(`Chain ${chainId} not found`)
8
+ }
9
+ const client = getPublicRpcClient(chainInfo)
10
10
 
11
11
  const code = await client.getCode({ address })
12
12
  const isNonZero = isNonZeroHexString(code)
package/src/estimate.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { type PublicClient, formatUnits, createPublicClient, http } from "viem"
2
- import { getChainInfo } from "./chains.js"
1
+ import { type PublicClient, formatUnits } from "viem"
2
+ import { getChainInfo, getPublicRpcClient } from "./chains.js"
3
3
  import { logger } from "./logger.js"
4
4
 
5
5
  // Default minimum gas limit for deposit transactions
@@ -360,10 +360,7 @@ export async function getDefaultGasCostEstimate(
360
360
  try {
361
361
  const chain = getChainInfo(chainId)
362
362
  if (chain) {
363
- const publicClient = createPublicClient({
364
- chain,
365
- transport: http(),
366
- })
363
+ const publicClient = getPublicRpcClient(chain)
367
364
 
368
365
  // Try to estimate gas if we have transaction details
369
366
  let gasLimit = DEFAULT_MIN_GASLIMIT