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.
- package/dist/analytics.d.ts +8 -3
- package/dist/analytics.d.ts.map +1 -1
- package/dist/{ccip-C9CA3tIi.js → ccip-Dw5AN7oU.js} +27 -27
- package/dist/cctp.d.ts +0 -149
- package/dist/cctp.d.ts.map +1 -1
- package/dist/chains.d.ts +31 -4
- package/dist/chains.d.ts.map +1 -1
- package/dist/config.d.ts +28 -52
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -7
- package/dist/constants.d.ts.map +1 -1
- package/dist/contractUtils.d.ts.map +1 -1
- package/dist/estimate.d.ts.map +1 -1
- package/dist/fees.d.ts.map +1 -1
- package/dist/gasless.d.ts +12 -0
- package/dist/gasless.d.ts.map +1 -1
- package/dist/{index-CNB57v0n.js → index-BtVUTbEZ.js} +32255 -40547
- package/dist/index.d.ts +13 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +320 -944
- package/dist/indexerClient.d.ts +9 -6
- package/dist/indexerClient.d.ts.map +1 -1
- package/dist/intents.d.ts +0 -18
- package/dist/intents.d.ts.map +1 -1
- package/dist/mutations.d.ts.map +1 -1
- package/dist/paymasterSend.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +1 -1
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/sendUserOp.d.ts +0 -18
- package/dist/sendUserOp.d.ts.map +1 -1
- package/dist/sequenceWallet.d.ts +1 -1
- package/dist/sequenceWallet.d.ts.map +1 -1
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/tokens.d.ts +10 -8
- package/dist/tokens.d.ts.map +1 -1
- package/dist/trailsClient.d.ts +3 -3
- package/dist/trailsClient.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +4 -5
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +4 -5
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/standardDeposit.d.ts +2 -2
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/execution/transactionState.d.ts +2 -2
- package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts +6 -4
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/index.d.ts +0 -1
- package/dist/transactionIntent/handlers/index.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +4 -34
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
- package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts +2 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +7 -19
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/transactionIntent/utils/index.d.ts +0 -1
- package/dist/transactionIntent/utils/index.d.ts.map +1 -1
- package/dist/transactions.d.ts +6 -18
- package/dist/transactions.d.ts.map +1 -1
- package/dist/utils.d.ts +8 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/walletUtils.d.ts +21 -0
- package/dist/walletUtils.d.ts.map +1 -0
- package/dist/wallets.d.ts +33 -240
- package/dist/wallets.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
- package/dist/widget/components/FeeOption.d.ts +8 -13
- package/dist/widget/components/FeeOption.d.ts.map +1 -1
- package/dist/widget/components/FeeOptions.d.ts +11 -5
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/NativeGasOption.d.ts.map +1 -1
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/QRCodeDeposit.d.ts +5 -0
- package/dist/widget/components/QRCodeDeposit.d.ts.map +1 -1
- package/dist/widget/components/QRCodeWalletSelect.d.ts +13 -0
- package/dist/widget/components/QRCodeWalletSelect.d.ts.map +1 -0
- package/dist/widget/components/QrCode.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/ScreenHeader.d.ts +1 -1
- package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
- package/dist/widget/components/SlippageToleranceSettings.d.ts +1 -0
- package/dist/widget/components/SlippageToleranceSettings.d.ts.map +1 -1
- package/dist/widget/components/Toast.d.ts.map +1 -1
- package/dist/widget/components/TokenImage.d.ts.map +1 -1
- package/dist/widget/components/WalletConnect.d.ts.map +1 -1
- package/dist/widget/css/compiled.css +1 -1
- package/dist/widget/hooks/useCheckout.d.ts +15 -1
- package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
- package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
- package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
- package/dist/widget/hooks/useDebugScreens.d.ts +1 -1
- package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -1
- package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/hooks/useIsConnectedWalletSmartContract.d.ts +7 -0
- package/dist/widget/hooks/useIsConnectedWalletSmartContract.d.ts.map +1 -0
- package/dist/widget/hooks/useIsSequenceWallet.d.ts +6 -0
- package/dist/widget/hooks/useIsSequenceWallet.d.ts.map +1 -0
- package/dist/widget/hooks/useQuote.d.ts +6 -11
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useRecentTokens.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedFeeOption.d.ts +30 -0
- package/dist/widget/hooks/useSelectedFeeOption.d.ts.map +1 -0
- package/dist/widget/hooks/useSendForm.d.ts +6 -15
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/index.d.ts +1 -0
- package/dist/widget/index.d.ts.map +1 -1
- package/dist/widget/index.js +4 -2
- package/dist/widget/providers/TrailsProvider.d.ts +29 -0
- package/dist/widget/providers/TrailsProvider.d.ts.map +1 -0
- package/dist/widget/widget.d.ts +14 -3
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/analytics.ts +53 -21
- package/src/cctp.ts +0 -1016
- package/src/chains.ts +155 -68
- package/src/config.ts +51 -207
- package/src/constants.ts +1 -13
- package/src/contractUtils.ts +6 -6
- package/src/estimate.ts +3 -6
- package/src/fees.ts +5 -10
- package/src/gasless.ts +45 -0
- package/src/index.ts +18 -40
- package/src/indexerClient.ts +39 -48
- package/src/intents.ts +51 -226
- package/src/mutations.ts +3 -2
- package/src/paymasterSend.ts +2 -5
- package/src/prepareSend.ts +21 -14
- package/src/sendUserOp.ts +3 -64
- package/src/sequenceWallet.ts +1 -2
- package/src/tokenBalances.ts +2 -1
- package/src/tokens.ts +62 -133
- package/src/trailsClient.ts +17 -12
- package/src/transactionIntent/deposits/depositOrchestrator.ts +14 -15
- package/src/transactionIntent/deposits/gaslessDeposit.ts +70 -100
- package/src/transactionIntent/deposits/standardDeposit.ts +22 -28
- package/src/transactionIntent/execution/transactionState.ts +2 -2
- package/src/transactionIntent/handlers/crossChain.ts +179 -381
- package/src/transactionIntent/handlers/index.ts +0 -1
- package/src/transactionIntent/handlers/sameChainSameToken.ts +228 -94
- package/src/transactionIntent/quote/normalizeQuote.ts +4 -6
- package/src/transactionIntent/quote/quoteHelpers.ts +35 -3
- package/src/transactionIntent/types.ts +7 -27
- package/src/transactionIntent/utils/index.ts +0 -1
- package/src/transactions.ts +19 -118
- package/src/umd.tsx +1 -3
- package/src/utils.ts +28 -8
- package/src/walletUtils.ts +42 -0
- package/src/wallets.ts +365 -208
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/AccountIntentTransactionHistory.tsx +78 -4
- package/src/widget/components/AccountSettings.tsx +17 -17
- package/src/widget/components/ChainList.tsx +3 -3
- package/src/widget/components/ClassicSwap.tsx +19 -10
- package/src/widget/components/ConfigDisplay.tsx +19 -59
- package/src/widget/components/FeeOption.tsx +63 -20
- package/src/widget/components/FeeOptions.tsx +54 -123
- package/src/widget/components/NativeGasOption.tsx +3 -1
- package/src/widget/components/Pay.tsx +18 -11
- package/src/widget/components/PoolDeposit.tsx +23 -10
- package/src/widget/components/QRCodeDeposit.tsx +50 -30
- package/src/widget/components/QRCodeWalletSelect.tsx +77 -0
- package/src/widget/components/QrCode.tsx +188 -233
- package/src/widget/components/QuoteDetails.tsx +48 -2
- package/src/widget/components/Receipt.tsx +5 -2
- package/src/widget/components/ScreenHeader.tsx +10 -8
- package/src/widget/components/SlippageToleranceSettings.tsx +63 -14
- package/src/widget/components/Toast.tsx +10 -0
- package/src/widget/components/TokenImage.tsx +56 -13
- package/src/widget/components/WalletConnect.tsx +37 -99
- package/src/widget/hooks/useCheckout.ts +71 -0
- package/src/widget/hooks/useCurrentScreen.tsx +1 -0
- package/src/widget/hooks/useDebugScreens.ts +5 -0
- package/src/widget/hooks/useIntentTransactionHistory.ts +790 -412
- package/src/widget/hooks/useIsConnectedWalletSmartContract.ts +43 -0
- package/src/widget/hooks/useIsSequenceWallet.ts +17 -0
- package/src/widget/hooks/useQuote.ts +27 -34
- package/src/widget/hooks/useRecentTokens.ts +2 -1
- package/src/widget/hooks/useSelectedFeeOption.tsx +257 -0
- package/src/widget/hooks/useSendForm.ts +175 -46
- package/src/widget/hooks/useTokenList.ts +15 -2
- package/src/widget/index.tsx +8 -0
- package/src/widget/providers/TrailsProvider.tsx +123 -0
- package/src/widget/widget.tsx +165 -143
- package/dist/cctpqueue.d.ts +0 -18
- package/dist/cctpqueue.d.ts.map +0 -1
- package/dist/preconditions.d.ts +0 -12
- package/dist/preconditions.d.ts.map +0 -1
- package/dist/trails.d.ts +0 -110
- package/dist/trails.d.ts.map +0 -1
- package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts +0 -62
- package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts.map +0 -1
- package/dist/transactionIntent/utils/lifiHelpers.d.ts +0 -10
- package/dist/transactionIntent/utils/lifiHelpers.d.ts.map +0 -1
- package/dist/widget/hooks/useSelectedFeeToken.d.ts +0 -33
- package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +0 -1
- package/src/cctpqueue.ts +0 -66
- package/src/preconditions.ts +0 -47
- package/src/trails.ts +0 -1303
- package/src/transactionIntent/handlers/sameChainDifferentToken.ts +0 -323
- package/src/transactionIntent/utils/lifiHelpers.ts +0 -68
- 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
|
|
62
|
-
const
|
|
63
|
-
const
|
|
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
|
-
|
|
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 {
|
|
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,
|
package/src/indexerClient.ts
CHANGED
|
@@ -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(
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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
|
|
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(
|
|
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
|
|
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"
|