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/fees.ts CHANGED
@@ -58,10 +58,9 @@ export async function extractTrailsFeeBreakdown(
58
58
  return null
59
59
  }
60
60
 
61
- // Get chain IDs from the calls array to determine origin and destination chains
62
- const calls = intent?.calls || []
63
- const originChainId: number | undefined = calls[0]?.chainId // First call is origin chain
64
- const destinationChainId: number | undefined = calls[1]?.chainId // Second call is destination chain
61
+ // Get chain IDs from origin and destination calls
62
+ const originChainId = intent.quoteRequest.originChainId
63
+ const destinationChainId = intent.quoteRequest.destinationChainId
65
64
 
66
65
  // Use the origin and destination gas fees
67
66
  const originChainQuote = fees.originGas
@@ -84,8 +83,7 @@ export async function extractTrailsFeeBreakdown(
84
83
  // Extract origin relay fee if available
85
84
  if (originChainQuote && originChainId !== undefined) {
86
85
  const originTokenSymbol = originChainQuote.nativeTokenSymbol || "ETH"
87
- const originChainIdNum =
88
- typeof originChainId === "bigint" ? Number(originChainId) : originChainId
86
+ const originChainIdNum = originChainId
89
87
  const nativeTokenAddress = zeroAddress
90
88
 
91
89
  breakdown.originRelayFee = {
@@ -106,10 +104,7 @@ export async function extractTrailsFeeBreakdown(
106
104
  if (destinationChainQuote && destinationChainId !== undefined) {
107
105
  const destinationTokenSymbol =
108
106
  destinationChainQuote.nativeTokenSymbol || "ETH"
109
- const destinationChainIdNum =
110
- typeof destinationChainId === "bigint"
111
- ? Number(destinationChainId)
112
- : destinationChainId
107
+ const destinationChainIdNum = destinationChainId
113
108
  const nativeTokenAddress = zeroAddress
114
109
 
115
110
  breakdown.destinationRelayFee = {
package/src/gasless.ts CHANGED
@@ -597,3 +597,48 @@ export async function signIntent({
597
597
 
598
598
  return { signature, v, r, s }
599
599
  }
600
+
601
+ /**
602
+ * Calculates the byte length of a hex signature string.
603
+ * @param signature - The signature (hex string with or without 0x prefix)
604
+ * @returns The number of bytes in the signature
605
+ */
606
+ function getSignatureBytes(signature: string): number {
607
+ return signature.startsWith("0x")
608
+ ? (signature.length - 2) / 2
609
+ : signature.length / 2
610
+ }
611
+
612
+ /**
613
+ * Validates that a signature is exactly 65 bytes (standard ECDSA signature length).
614
+ * @param signature - The signature to validate (hex string with or without 0x prefix)
615
+ * @returns true if signature is 65 bytes, false otherwise
616
+ */
617
+ export function isValidGaslessSignature(signature: string): boolean {
618
+ // Standard ECDSA signatures are 65 bytes (32 bytes r + 32 bytes s + 1 byte v)
619
+ // Smart contract wallets return longer signatures which are not supported
620
+ return getSignatureBytes(signature) === 65
621
+ }
622
+
623
+ /**
624
+ * Validates that a signature is exactly 65 bytes and throws an appropriate error if invalid.
625
+ * @param signature - The signature to validate (hex string with or without 0x prefix)
626
+ * @throws Error if signature is not 65 bytes
627
+ */
628
+ export function validateGaslessSignature(signature: string): void {
629
+ const signatureBytes = getSignatureBytes(signature)
630
+
631
+ if (signatureBytes !== 65) {
632
+ if (signatureBytes > 65) {
633
+ throw new Error(
634
+ "Smart contract wallets are not supported for gasless transfers at the moment. " +
635
+ "Please use an EOA (Externally Owned Account) wallet for gasless transactions.",
636
+ )
637
+ } else {
638
+ throw new Error(
639
+ `Invalid signature length: expected 65 bytes, got ${signatureBytes} bytes. ` +
640
+ "The signature may be malformed.",
641
+ )
642
+ }
643
+ }
644
+ }
package/src/index.ts CHANGED
@@ -10,17 +10,11 @@ export {
10
10
  useSupportedChains,
11
11
  getChainInfo,
12
12
  getAllChains,
13
+ getRpcUrl,
13
14
  type Chain,
14
15
  } from "./chains.js"
15
- export {
16
- getIndexerGatewayClient,
17
- useIndexerGatewayClient,
18
- } from "./indexerClient.js"
19
- export type {
20
- OriginCallParams,
21
- QuoteProvider,
22
- TrailsFee,
23
- } from "./intents.js"
16
+ export { useIndexerGatewayClient } from "./indexerClient.js"
17
+ export type { OriginCallParams, QuoteProvider, TrailsFee } from "./intents.js"
24
18
  export {
25
19
  calculateIntentAddress,
26
20
  calculateOriginAndDestinationIntentAddresses,
@@ -38,11 +32,7 @@ export {
38
32
  type OnDestinationTransactionFound,
39
33
  type OnReceiptUpdate,
40
34
  } from "./intentReceiptPoller.js"
41
- export {
42
- prepareSend,
43
- useQuote,
44
- TradeType,
45
- } from "./prepareSend.js"
35
+ export { prepareSend, useQuote, TradeType } from "./prepareSend.js"
46
36
  export type {
47
37
  UseQuoteReturn,
48
38
  UseQuoteProps,
@@ -53,20 +43,20 @@ export type {
53
43
  TransactionState,
54
44
  IntentTransaction,
55
45
  IntentTransactionHistoryResponse,
56
- GetIntentTransactionHistoryParams,
57
46
  TransactionHistoryResponse,
58
47
  GetAccountTransactionHistoryParams,
59
48
  UseAccountTransactionHistoryParams,
60
49
  UseAccountTransactionHistoryReturn,
61
- UseIntentTransactionHistoryParams,
62
- UseIntentTransactionHistoryReturn,
63
50
  } from "./transactions.js"
64
51
  export {
65
- getIntentTransactionHistory,
66
52
  getAccountTransactionHistory,
67
53
  useAccountTransactionHistory,
68
- useIntentTransactionHistory,
69
54
  } from "./transactions.js"
55
+ export { useIntentTransactionHistory } from "./widget/hooks/useIntentTransactionHistory.js"
56
+ export type {
57
+ UseIntentTransactionHistoryParams,
58
+ UseIntentTransactionHistoryReturn,
59
+ } from "./widget/hooks/useIntentTransactionHistory.js"
70
60
  export {
71
61
  getAccountTotalBalanceUsd,
72
62
  getHasSufficientBalanceToken,
@@ -85,38 +75,26 @@ export {
85
75
  getSupportedTokens,
86
76
  useSupportedTokens,
87
77
  useTokenList,
78
+ useGetTokenImageUrl,
88
79
  } from "./tokens.js"
89
80
  export type { SupportedToken } from "./tokens.js"
90
81
  export { getTxTimeDiff } from "./transactions.js"
91
- export { useTrails } from "./trails.js"
92
- export type { WagmiAccount } from "./trails.js"
93
- export {
94
- useCommitIntent,
95
- useExecuteIntent,
96
- } from "./mutations.js"
82
+ export { useCommitIntent, useExecuteIntent } from "./mutations.js"
97
83
  export type { Mode } from "./mode.js"
98
84
  export { TRAILS_ROUTER_PLACEHOLDER_AMOUNT } from "./trailsRouter.js"
99
85
  export { getERC20TransferData } from "./encoders.js"
86
+ // Config functions - getters are deprecated, use TrailsProvider context instead
100
87
  export {
101
- declareSequenceEnv,
102
- getSequenceProjectAccessKey,
103
- getTrailsApiUrl,
104
- getSequenceIndexerUrl,
105
- getSequenceEnv,
106
- setSequenceProjectAccessKey,
107
- setTrailsApiUrl,
108
- setSequenceIndexerUrl,
109
- setSequenceNodeGatewayUrl,
110
- getSequenceNodeGatewayUrl,
111
- setSequenceEnv,
112
- setWalletConnectProjectId,
113
- getWalletConnectProjectId,
114
- setSlippageTolerance,
115
88
  getSlippageTolerance,
116
- setDebug,
117
89
  getDebug,
90
+ getCommitHash,
118
91
  } from "./config.js"
119
92
  export * from "./widget/index.js"
93
+ export { TrailsProvider } from "./widget/providers/TrailsProvider.js"
94
+ export type {
95
+ TrailsConfig,
96
+ SequenceEnv,
97
+ } from "./widget/providers/TrailsProvider.js"
120
98
  export { logger, getMinLogLevel } from "./logger.js"
121
99
  export {
122
100
  getTrailsClient,
@@ -1,11 +1,3 @@
1
- import { useConfig } from "@0xsequence/hooks"
2
- import { SequenceIndexerGateway } from "@0xsequence/indexer"
3
- import { useMemo } from "react"
4
- import {
5
- getSequenceIndexerUrl,
6
- getSequenceProjectAccessKey,
7
- getSequenceEnv,
8
- } from "./config.js"
9
1
  import {
10
2
  arbitrum,
11
3
  base,
@@ -34,24 +26,53 @@ export type IndexerGatewayConfig = {
34
26
 
35
27
  /**
36
28
  * Get the indexer URL for a specific chain slug
37
- * Dynamically determines the environment prefix
29
+ * Dynamically determines the environment prefix by parsing the base indexer URL
30
+ * @param chainSlug - The chain slug (e.g., "arbitrum", "base")
31
+ * @param baseIndexerUrl -Indexer URL
32
+ * @returns The chain-specific indexer URL with appropriate environment prefix
38
33
  */
39
- export function getIndexerUrlFromChainSlug(chainSlug: string): string {
40
- const env = getSequenceEnv()
41
- let envPrefix = ""
34
+ export function getIndexerUrlFromChainSlug(
35
+ chainSlug: string,
36
+ baseIndexerUrl: string,
37
+ ): string {
38
+ // Parse the URL to detect if it's a dev environment
39
+ // Check if the URL contains "dev" (e.g., "dev-indexer.sequence.app")
40
+ const isDev = baseIndexerUrl?.includes("dev")
41
+
42
+ // Extract the domain from the URL
43
+ // e.g., "https://indexer.sequence.app" -> "indexer.sequence.app"
44
+ // or "https://dev-indexer.sequence.app" -> "dev-indexer.sequence.app"
45
+ const urlObj = new URL(baseIndexerUrl)
46
+ const hostname = urlObj.hostname
42
47
 
43
- if (env === "dev") {
44
- envPrefix = "dev-"
48
+ // Construct the chain-specific indexer URL
49
+ // If dev environment: "dev-indexer.sequence.app" -> "dev-{chainSlug}-indexer.sequence.app"
50
+ // If prod environment: "indexer.sequence.app" -> "{chainSlug}-indexer.sequence.app"
51
+ let chainHostname: string
52
+ if (isDev) {
53
+ // Replace "dev-indexer" with "dev-{chainSlug}-indexer"
54
+ chainHostname = hostname.replace(
55
+ /^dev-indexer\./,
56
+ `dev-${chainSlug}-indexer.`,
57
+ )
58
+ } else {
59
+ // Replace "indexer" with "{chainSlug}-indexer"
60
+ chainHostname = hostname.replace(/^indexer\./, `${chainSlug}-indexer.`)
45
61
  }
46
62
 
47
- return `https://${envPrefix}${chainSlug}-indexer.sequence.app`
63
+ return `${urlObj.protocol}//${chainHostname}`
48
64
  }
49
65
 
50
66
  /**
51
67
  * Get the chain-specific indexer URL by chain ID
52
68
  * Returns the appropriate indexer URL based on the current environment
69
+ * @param chainId - The chain ID
70
+ * @param baseIndexerUrl - Indexer URL
53
71
  */
54
- export function getChainIndexerUrl(chainId: number): string | undefined {
72
+ export function getChainIndexerUrl(
73
+ chainId: number,
74
+ baseIndexerUrl: string,
75
+ ): string | undefined {
55
76
  const chainIdToSlug: Record<number, string> = {
56
77
  [arbitrum.id]: "arbitrum",
57
78
  [base.id]: "base",
@@ -78,37 +99,7 @@ export function getChainIndexerUrl(chainId: number): string | undefined {
78
99
  return undefined
79
100
  }
80
101
 
81
- return getIndexerUrlFromChainSlug(chainSlug)
82
- }
83
-
84
- export function getIndexerGatewayClient({
85
- indexerGatewayUrl = getSequenceIndexerUrl(),
86
- projectAccessKey = getSequenceProjectAccessKey(),
87
- jwt,
88
- }: IndexerGatewayConfig): SequenceIndexerGateway {
89
- return new SequenceIndexerGateway(
90
- indexerGatewayUrl as string,
91
- projectAccessKey,
92
- jwt,
93
- )
102
+ return getIndexerUrlFromChainSlug(chainSlug, baseIndexerUrl)
94
103
  }
95
104
 
96
- export const useIndexerGatewayClient = (config?: IndexerGatewayConfig) => {
97
- const { projectAccessKey, jwt, env } = useConfig()
98
-
99
- const indexerGatewayClient = useMemo(() => {
100
- return getIndexerGatewayClient({
101
- indexerGatewayUrl:
102
- getSequenceIndexerUrl() ??
103
- config?.indexerGatewayUrl ??
104
- env.indexerGatewayUrl,
105
- projectAccessKey:
106
- config?.projectAccessKey ??
107
- getSequenceProjectAccessKey() ??
108
- projectAccessKey,
109
- jwt: config?.jwt ?? jwt,
110
- })
111
- }, [projectAccessKey, jwt, env.indexerGatewayUrl, config])
112
-
113
- return indexerGatewayClient
114
- }
105
+ export { useIndexerGatewayClient } from "@0xsequence/hooks"