0xtrails 0.2.5 → 0.3.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/aave.d.ts +2 -0
- package/dist/aave.d.ts.map +1 -1
- package/dist/abortController.d.ts +8 -0
- package/dist/abortController.d.ts.map +1 -0
- package/dist/{ccip-CXlshvBY.js → ccip-BMB3uDZt.js} +1 -1
- package/dist/config.d.ts +0 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +4 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/error.d.ts +4 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/fees.d.ts +19 -0
- package/dist/fees.d.ts.map +1 -0
- package/dist/{index-_QuyGrjU.js → index-QXPUrZVv.js} +48719 -50852
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +811 -784
- package/dist/intentReceiptMonitor.d.ts +24 -0
- package/dist/intentReceiptMonitor.d.ts.map +1 -0
- package/dist/intentReceiptPoller.d.ts +69 -0
- package/dist/intentReceiptPoller.d.ts.map +1 -0
- package/dist/intents.d.ts +15 -11
- package/dist/intents.d.ts.map +1 -1
- package/dist/morpho.d.ts +6 -5
- package/dist/morpho.d.ts.map +1 -1
- package/dist/mutations.d.ts +16 -0
- package/dist/mutations.d.ts.map +1 -0
- package/dist/preconditions.d.ts +5 -4
- package/dist/preconditions.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +7 -258
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/prices.d.ts +9 -6
- package/dist/prices.d.ts.map +1 -1
- package/dist/sequenceWallet.d.ts +3 -16
- package/dist/sequenceWallet.d.ts.map +1 -1
- package/dist/tokenBalances.d.ts +17 -13
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/trails.d.ts +24 -40
- package/dist/trails.d.ts.map +1 -1
- package/dist/transactionIntent/constants.d.ts +7 -0
- package/dist/transactionIntent/constants.d.ts.map +1 -0
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +44 -0
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -0
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +30 -0
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -0
- package/dist/transactionIntent/deposits/index.d.ts +4 -0
- package/dist/transactionIntent/deposits/index.d.ts.map +1 -0
- package/dist/transactionIntent/deposits/standardDeposit.d.ts +30 -0
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -0
- package/dist/transactionIntent/execution/index.d.ts +2 -0
- package/dist/transactionIntent/execution/index.d.ts.map +1 -0
- package/dist/transactionIntent/execution/transactionState.d.ts +5 -0
- package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -0
- package/dist/transactionIntent/handlers/crossChain.d.ts +82 -0
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -0
- package/dist/transactionIntent/handlers/index.d.ts +4 -0
- package/dist/transactionIntent/handlers/index.d.ts.map +1 -0
- package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts +62 -0
- package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts.map +1 -0
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +72 -0
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -0
- package/dist/transactionIntent/index.d.ts +9 -0
- package/dist/transactionIntent/index.d.ts.map +1 -0
- package/dist/transactionIntent/quote/feeExtractors.d.ts +17 -0
- package/dist/transactionIntent/quote/feeExtractors.d.ts.map +1 -0
- package/dist/transactionIntent/quote/index.d.ts +4 -0
- package/dist/transactionIntent/quote/index.d.ts.map +1 -0
- package/dist/transactionIntent/quote/normalizeQuote.d.ts +34 -0
- package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -0
- package/dist/transactionIntent/quote/quoteHelpers.d.ts +5 -0
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -0
- package/dist/transactionIntent/types.d.ts +131 -0
- package/dist/transactionIntent/types.d.ts.map +1 -0
- package/dist/transactionIntent/utils/balanceChecker.d.ts +18 -0
- package/dist/transactionIntent/utils/balanceChecker.d.ts.map +1 -0
- package/dist/transactionIntent/utils/index.d.ts +4 -0
- package/dist/transactionIntent/utils/index.d.ts.map +1 -0
- package/dist/transactionIntent/utils/lifiHelpers.d.ts +10 -0
- package/dist/transactionIntent/utils/lifiHelpers.d.ts.map +1 -0
- package/dist/transactionIntent/utils/testnetHelpers.d.ts +3 -0
- package/dist/transactionIntent/utils/testnetHelpers.d.ts.map +1 -0
- package/dist/transactionIntent/validators.d.ts +6 -0
- package/dist/transactionIntent/validators.d.ts.map +1 -0
- package/dist/transactions.d.ts +6 -3
- package/dist/transactions.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts +4 -0
- package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts.map +1 -0
- package/dist/widget/components/AccountSettings.d.ts.map +1 -1
- package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts +2 -3
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
- package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
- package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
- package/dist/widget/components/DynamicInputStyles.d.ts +18 -0
- package/dist/widget/components/DynamicInputStyles.d.ts.map +1 -0
- package/dist/widget/components/DynamicSizeInputField.d.ts +13 -0
- package/dist/widget/components/DynamicSizeInputField.d.ts.map +1 -0
- package/dist/widget/components/Earn.d.ts +2 -3
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/ErrorAnimationIcon.d.ts +2 -0
- package/dist/widget/components/ErrorAnimationIcon.d.ts.map +1 -0
- package/dist/widget/components/FeeBreakdown.d.ts +9 -0
- package/dist/widget/components/FeeBreakdown.d.ts.map +1 -0
- package/dist/widget/components/FeeOptions.d.ts +5 -13
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/Fund.d.ts +2 -3
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundMethods.d.ts.map +1 -1
- package/dist/widget/components/FundSwap.d.ts +2 -3
- package/dist/widget/components/FundSwap.d.ts.map +1 -1
- package/dist/widget/components/FundingMethodSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/Identicon.d.ts.map +1 -1
- package/dist/widget/components/MeshConnectExchanges.d.ts +0 -3
- package/dist/widget/components/MeshConnectExchanges.d.ts.map +1 -1
- package/dist/widget/components/Modal.d.ts.map +1 -1
- package/dist/widget/components/Pay.d.ts +2 -3
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts +3 -3
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/PoolWithdraw.d.ts +3 -20
- package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts +2 -0
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
- package/dist/widget/components/Swap.d.ts +2 -3
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
- package/dist/widget/components/TokenDisplayNonSelectable.d.ts +11 -0
- package/dist/widget/components/TokenDisplayNonSelectable.d.ts.map +1 -0
- package/dist/widget/components/TokenSelector.d.ts.map +1 -1
- package/dist/widget/components/TokenSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/Tooltip.d.ts +9 -0
- package/dist/widget/components/Tooltip.d.ts.map +1 -0
- package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
- package/dist/widget/components/WaasFeeOptions.d.ts +1 -0
- package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -1
- package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
- package/dist/widget/components/WalletConnect.d.ts.map +1 -1
- package/dist/widget/css/compiled.css +2 -2
- package/dist/widget/hooks/useCheckout.d.ts +17 -4
- package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +82 -0
- package/dist/widget/hooks/useQuote.d.ts.map +1 -0
- package/dist/widget/hooks/useSelectedFeeToken.d.ts +1 -0
- package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts +5 -6
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/hooks/useWalletConnectionContext.d.ts +25 -0
- package/dist/widget/hooks/useWalletConnectionContext.d.ts.map +1 -0
- package/dist/widget/index.js +2 -2
- package/dist/widget/widget.d.ts +17 -7
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +19 -21
- package/src/aave.ts +54 -1
- package/src/abortController.ts +35 -0
- package/src/config.ts +57 -58
- package/src/constants.ts +11 -9
- package/src/error.ts +21 -3
- package/src/fees.ts +210 -0
- package/src/index.ts +35 -13
- package/src/intentReceiptMonitor.ts +102 -0
- package/src/intentReceiptPoller.ts +299 -0
- package/src/intents.ts +205 -171
- package/src/morpho.ts +58 -9
- package/src/mutations.ts +129 -0
- package/src/preconditions.ts +16 -21
- package/src/prepareSend.ts +92 -4699
- package/src/prices.ts +26 -22
- package/src/relaySdk.ts +2 -2
- package/src/sequenceWallet.ts +6 -73
- package/src/tokenBalances.ts +175 -69
- package/src/trails.ts +230 -722
- package/src/transactionIntent/constants.ts +11 -0
- package/src/transactionIntent/deposits/depositOrchestrator.ts +210 -0
- package/src/transactionIntent/deposits/gaslessDeposit.ts +588 -0
- package/src/transactionIntent/deposits/index.ts +3 -0
- package/src/transactionIntent/deposits/standardDeposit.ts +379 -0
- package/src/transactionIntent/execution/index.ts +1 -0
- package/src/transactionIntent/execution/transactionState.ts +35 -0
- package/src/transactionIntent/handlers/crossChain.ts +1707 -0
- package/src/transactionIntent/handlers/index.ts +3 -0
- package/src/transactionIntent/handlers/sameChainDifferentToken.ts +323 -0
- package/src/transactionIntent/handlers/sameChainSameToken.ts +712 -0
- package/src/transactionIntent/index.ts +9 -0
- package/src/transactionIntent/quote/feeExtractors.ts +81 -0
- package/src/transactionIntent/quote/index.ts +3 -0
- package/src/transactionIntent/quote/normalizeQuote.ts +367 -0
- package/src/transactionIntent/quote/quoteHelpers.ts +53 -0
- package/src/transactionIntent/types.ts +157 -0
- package/src/transactionIntent/utils/balanceChecker.ts +96 -0
- package/src/transactionIntent/utils/index.ts +3 -0
- package/src/transactionIntent/utils/lifiHelpers.ts +68 -0
- package/src/transactionIntent/utils/testnetHelpers.ts +10 -0
- package/src/transactionIntent/validators.ts +57 -0
- package/src/transactions.ts +98 -71
- package/src/widget/compiled.css +2 -2
- package/src/widget/components/AccountIntentTransactionHistory.tsx +36 -36
- package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +22 -0
- package/src/widget/components/AccountSettings.tsx +70 -41
- package/src/widget/components/ChainFilterDropdown.tsx +24 -3
- package/src/widget/components/ClassicSwap.tsx +44 -107
- package/src/widget/components/ConfigDisplay.tsx +0 -11
- package/src/widget/components/ConnectWallet.tsx +4 -1
- package/src/widget/components/ConnectedWallets.tsx +51 -25
- package/src/widget/components/DynamicInputStyles.tsx +76 -0
- package/src/widget/components/DynamicSizeInputField.tsx +109 -0
- package/src/widget/components/Earn.tsx +34 -45
- package/src/widget/components/ErrorAnimationIcon.tsx +130 -0
- package/src/widget/components/FeeBreakdown.tsx +155 -0
- package/src/widget/components/FeeOption.tsx +2 -2
- package/src/widget/components/FeeOptions.tsx +151 -112
- package/src/widget/components/Fund.tsx +10 -29
- package/src/widget/components/FundMethods.tsx +4 -3
- package/src/widget/components/FundSwap.tsx +2 -3
- package/src/widget/components/FundingMethodSelectorButton.tsx +24 -14
- package/src/widget/components/Identicon.tsx +164 -95
- package/src/widget/components/MeshConnectExchanges.tsx +2 -15
- package/src/widget/components/Modal.tsx +0 -12
- package/src/widget/components/Pay.tsx +72 -75
- package/src/widget/components/PoolDeposit.tsx +221 -242
- package/src/widget/components/PoolWithdraw.tsx +347 -469
- package/src/widget/components/PriceImpactWarning.tsx +1 -1
- package/src/widget/components/QuoteDetails.tsx +906 -484
- package/src/widget/components/Receipt.tsx +16 -2
- package/src/widget/components/RecipientSelectorButton.tsx +7 -5
- package/src/widget/components/Recipients.tsx +1 -1
- package/src/widget/components/ScreenHeader.tsx +60 -36
- package/src/widget/components/Swap.tsx +2 -3
- package/src/widget/components/ThemeProvider.tsx +2 -1
- package/src/widget/components/TokenDisplayNonSelectable.tsx +40 -0
- package/src/widget/components/TokenImage.tsx +1 -1
- package/src/widget/components/TokenSelector.tsx +62 -53
- package/src/widget/components/TokenSelectorButton.tsx +38 -15
- package/src/widget/components/Tooltip.tsx +51 -0
- package/src/widget/components/TransferPendingVertical.tsx +12 -8
- package/src/widget/components/WaasFeeOptions.tsx +139 -4
- package/src/widget/components/WalletConfirmation.tsx +23 -13
- package/src/widget/components/WalletConnect.tsx +93 -29
- package/src/widget/hooks/useAmountUsd.ts +9 -9
- package/src/widget/hooks/useCheckout.ts +97 -9
- package/src/widget/hooks/useDefaultTokenSelection.tsx +27 -21
- package/src/widget/hooks/useQuote.ts +466 -0
- package/src/widget/hooks/useSelectedFeeToken.tsx +32 -37
- package/src/widget/hooks/useSendForm.ts +45 -51
- package/src/widget/hooks/useTokenList.ts +34 -26
- package/src/widget/hooks/useWalletConnectionContext.tsx +128 -0
- package/src/widget/widget.tsx +365 -390
- package/dist/apiClient.d.ts +0 -9
- package/dist/apiClient.d.ts.map +0 -1
- package/dist/intentEntrypoint.d.ts +0 -114
- package/dist/intentEntrypoint.d.ts.map +0 -1
- package/dist/metaTxnMonitor.d.ts +0 -15
- package/dist/metaTxnMonitor.d.ts.map +0 -1
- package/dist/metaTxns.d.ts +0 -11
- package/dist/metaTxns.d.ts.map +0 -1
- package/dist/relayer.d.ts +0 -43
- package/dist/relayer.d.ts.map +0 -1
- package/src/apiClient.ts +0 -35
- package/src/intentEntrypoint.ts +0 -203
- package/src/metaTxnMonitor.ts +0 -171
- package/src/metaTxns.ts +0 -45
- package/src/relayer.ts +0 -289
package/src/relayer.ts
DELETED
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { Relayer } from "@0xsequence/relayer"
|
|
2
|
-
import { useMemo } from "react"
|
|
3
|
-
import { getChainInfo, getRpcUrl } from "./chains.js"
|
|
4
|
-
import { Hex } from "ox"
|
|
5
|
-
import { getSequenceProjectAccessKey, getSequenceEnv } from "./config.js"
|
|
6
|
-
import { logger } from "./logger.js"
|
|
7
|
-
import { bigintReplacer } from "./utils.js"
|
|
8
|
-
import {
|
|
9
|
-
gnosis,
|
|
10
|
-
bsc,
|
|
11
|
-
katana,
|
|
12
|
-
soneium,
|
|
13
|
-
xai,
|
|
14
|
-
etherlink,
|
|
15
|
-
mainnet,
|
|
16
|
-
arbitrum,
|
|
17
|
-
base,
|
|
18
|
-
baseSepolia,
|
|
19
|
-
polygon,
|
|
20
|
-
apeChain,
|
|
21
|
-
arbitrumNova,
|
|
22
|
-
avalanche,
|
|
23
|
-
b3,
|
|
24
|
-
blast,
|
|
25
|
-
optimism,
|
|
26
|
-
} from "viem/chains"
|
|
27
|
-
import { somnia } from "./customChains.js"
|
|
28
|
-
|
|
29
|
-
export interface MetaTxnReceiptLog {
|
|
30
|
-
address: string
|
|
31
|
-
topics: Array<string>
|
|
32
|
-
data: string
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface MetaTxnReceipt {
|
|
36
|
-
id: string
|
|
37
|
-
status: string
|
|
38
|
-
revertReason?: string
|
|
39
|
-
index: number
|
|
40
|
-
logs: Array<MetaTxnReceiptLog>
|
|
41
|
-
receipts: Array<MetaTxnReceipt>
|
|
42
|
-
blockNumber: string
|
|
43
|
-
txnHash: string
|
|
44
|
-
txnReceipt: string
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type RelayerOperationStatus = Relayer.OperationStatus
|
|
48
|
-
export type RelayerOperationFailedStatus = Relayer.OperationFailedStatus
|
|
49
|
-
export type RelayerOperationPendingStatus = Relayer.OperationPendingStatus
|
|
50
|
-
export type RelayerOperationConfirmedStatus = Relayer.OperationConfirmedStatus
|
|
51
|
-
export type RelayerOperationUnknownStatus = Relayer.OperationUnknownStatus
|
|
52
|
-
|
|
53
|
-
export type RelayerConfig = {
|
|
54
|
-
hostname: string
|
|
55
|
-
chainId: number
|
|
56
|
-
rpcUrl: string
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export type RelayerEnv = "local" | "cors-anywhere" | "dev" | "prod"
|
|
60
|
-
|
|
61
|
-
export type RelayerEnvConfig = {
|
|
62
|
-
env?: RelayerEnv
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export type { Relayer }
|
|
66
|
-
|
|
67
|
-
const relayerChainIdToSlug: Record<number, string> = {
|
|
68
|
-
[arbitrum.id]: "arbitrum",
|
|
69
|
-
[base.id]: "base",
|
|
70
|
-
[baseSepolia.id]: "base-sepolia",
|
|
71
|
-
[polygon.id]: "polygon",
|
|
72
|
-
[mainnet.id]: "mainnet",
|
|
73
|
-
[apeChain.id]: "apechain",
|
|
74
|
-
[arbitrumNova.id]: "arbitrum-nova",
|
|
75
|
-
[avalanche.id]: "avalanche",
|
|
76
|
-
[optimism.id]: "optimism",
|
|
77
|
-
[b3.id]: "b3",
|
|
78
|
-
[blast.id]: "blast",
|
|
79
|
-
[gnosis.id]: "gnosis",
|
|
80
|
-
[soneium.id]: "soneium",
|
|
81
|
-
[somnia.id]: "somnia",
|
|
82
|
-
[xai.id]: "xai",
|
|
83
|
-
[bsc.id]: "bsc",
|
|
84
|
-
[katana.id]: "katana",
|
|
85
|
-
[etherlink.id]: "etherlink",
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const relayerLocalhostUrlMap: Record<number, string> = {
|
|
89
|
-
[mainnet.id]: "http://0.0.0.0:9969",
|
|
90
|
-
[katana.id]: "http://0.0.0.0:9994",
|
|
91
|
-
[apeChain.id]: "http://0.0.0.0:9995",
|
|
92
|
-
[base.id]: "http://0.0.0.0:9996",
|
|
93
|
-
[arbitrum.id]: "http://0.0.0.0:9997",
|
|
94
|
-
[optimism.id]: "http://0.0.0.0:9998",
|
|
95
|
-
[polygon.id]: "http://0.0.0.0:9999",
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function getRelayerLocalhostUrl(chainId: number): string {
|
|
99
|
-
return relayerLocalhostUrlMap[chainId] ?? ""
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function getRelayerChainIdToSlug(chainId: number): string {
|
|
103
|
-
return relayerChainIdToSlug[chainId] ?? ""
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Wrapped fetch function that includes access token header
|
|
107
|
-
function wrappedFetch(
|
|
108
|
-
input: RequestInfo,
|
|
109
|
-
init?: RequestInit,
|
|
110
|
-
): Promise<Response> {
|
|
111
|
-
if (typeof window === "undefined") {
|
|
112
|
-
return Promise.resolve(new Response("Not available in server environment"))
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const headers = new Headers(init?.headers)
|
|
116
|
-
headers.set("x-access-key", getSequenceProjectAccessKey())
|
|
117
|
-
|
|
118
|
-
return fetch(input, {
|
|
119
|
-
...init,
|
|
120
|
-
headers,
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function getBackupRelayer(
|
|
125
|
-
chainId: number,
|
|
126
|
-
): Relayer.RpcRelayer | undefined {
|
|
127
|
-
if (chainId === 42161) {
|
|
128
|
-
return new Relayer.RpcRelayer(
|
|
129
|
-
"https://a1b4a8c5d856.ngrok.app/",
|
|
130
|
-
chainId,
|
|
131
|
-
getRpcUrl(chainId)!,
|
|
132
|
-
)
|
|
133
|
-
} else if (chainId === 8453) {
|
|
134
|
-
return new Relayer.RpcRelayer(
|
|
135
|
-
"https://644a6aeb891e.ngrok.app/",
|
|
136
|
-
chainId,
|
|
137
|
-
getRpcUrl(chainId)!,
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return undefined
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// TODO: add relayer url to config
|
|
145
|
-
export function getRelayerUrl(
|
|
146
|
-
config: RelayerEnvConfig = {
|
|
147
|
-
env: getSequenceEnv() as RelayerEnv,
|
|
148
|
-
},
|
|
149
|
-
chainId: number,
|
|
150
|
-
): string {
|
|
151
|
-
let relayerUrl = ""
|
|
152
|
-
if (config.env === "local") {
|
|
153
|
-
relayerUrl = getRelayerLocalhostUrl(chainId)
|
|
154
|
-
return relayerUrl
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// For cors-anywhere, dev, and production environments
|
|
158
|
-
const baseUrl =
|
|
159
|
-
config.env === "cors-anywhere"
|
|
160
|
-
? "http://localhost:8080/https://"
|
|
161
|
-
: config.env === "dev"
|
|
162
|
-
? "https://dev-relayer.sequence.app"
|
|
163
|
-
: "https://"
|
|
164
|
-
|
|
165
|
-
const chainSlug = getRelayerChainIdToSlug(chainId)
|
|
166
|
-
|
|
167
|
-
if (!config.env || config.env === "prod") {
|
|
168
|
-
if (chainSlug) {
|
|
169
|
-
relayerUrl = `https://${chainSlug}-relayer.sequence.app`
|
|
170
|
-
} else {
|
|
171
|
-
relayerUrl = `${baseUrl}${getChainInfo(chainId)!.name?.replace(" ", "-")}-relayer.sequence.app`
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Chain-specific relayer endpoints
|
|
176
|
-
if (config.env === "dev") {
|
|
177
|
-
if (chainSlug) {
|
|
178
|
-
relayerUrl = `https://dev-${chainSlug}-relayer.sequence.app`
|
|
179
|
-
} else {
|
|
180
|
-
// Fallback to general dev relayer for other chains if V3 is specified but chain not V3-supported
|
|
181
|
-
relayerUrl = `${baseUrl}${getChainInfo(chainId)!.name?.replace(" ", "-")}-relayer.sequence.app`
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return relayerUrl
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export function getRelayer(
|
|
189
|
-
config: RelayerEnvConfig = {
|
|
190
|
-
env: getSequenceEnv() as RelayerEnv,
|
|
191
|
-
},
|
|
192
|
-
chainId: number,
|
|
193
|
-
): Relayer.RpcRelayer {
|
|
194
|
-
const chain = getChainInfo(chainId)
|
|
195
|
-
|
|
196
|
-
if (!chain) {
|
|
197
|
-
throw new Error(`Chain with id ${chainId} not found`)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const rpcUrl = chain.rpcUrls.default.http[0]
|
|
201
|
-
if (!rpcUrl) {
|
|
202
|
-
throw new Error(`No RPC URL found for chain ${chainId}`)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const relayerUrl = getRelayerUrl(config, chainId)
|
|
206
|
-
|
|
207
|
-
const relayer = new Relayer.RpcRelayer(
|
|
208
|
-
relayerUrl,
|
|
209
|
-
chainId,
|
|
210
|
-
rpcUrl,
|
|
211
|
-
wrappedFetch,
|
|
212
|
-
)
|
|
213
|
-
|
|
214
|
-
// Monkey-patch the sendMetaTxn method to handle quote correctly
|
|
215
|
-
// This fixes the double serialization issue where JSON.stringify was adding extra quotes
|
|
216
|
-
relayer.sendMetaTxn = async (
|
|
217
|
-
walletAddress,
|
|
218
|
-
to,
|
|
219
|
-
data,
|
|
220
|
-
_chainId,
|
|
221
|
-
quote,
|
|
222
|
-
preconditions,
|
|
223
|
-
) => {
|
|
224
|
-
const rpcCall: any = {
|
|
225
|
-
walletAddress: walletAddress,
|
|
226
|
-
contract: to,
|
|
227
|
-
input: data,
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const result = await (relayer as any).client.sendMetaTxn({
|
|
231
|
-
call: rpcCall,
|
|
232
|
-
quote: quote
|
|
233
|
-
? typeof (quote as any)._quote === "string"
|
|
234
|
-
? (quote as any)._quote
|
|
235
|
-
: (quote as any)._quote?.toJSON
|
|
236
|
-
? (quote as any)._quote.toJSON()
|
|
237
|
-
: JSON.stringify((quote as any)._quote, bigintReplacer, 2)
|
|
238
|
-
: undefined,
|
|
239
|
-
preconditions: preconditions,
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
if (!result.status) {
|
|
243
|
-
logger.console.error("RpcRelayer.relay failed", result)
|
|
244
|
-
throw new Error(`Relay failed: TxnHash ${result.txnHash}`)
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
opHash: Hex.fromString(
|
|
249
|
-
result.txnHash.startsWith("0x")
|
|
250
|
-
? result.txnHash
|
|
251
|
-
: `0x${result.txnHash}`,
|
|
252
|
-
),
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return relayer
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export function useRelayers(
|
|
260
|
-
config: RelayerEnvConfig = {
|
|
261
|
-
env: getSequenceEnv() as RelayerEnv,
|
|
262
|
-
},
|
|
263
|
-
): {
|
|
264
|
-
relayers: Map<number, Relayer.RpcRelayer>
|
|
265
|
-
getRelayer: (chainId: number) => Relayer.RpcRelayer
|
|
266
|
-
getBackupRelayer: (chainId: number) => Relayer.RpcRelayer | undefined
|
|
267
|
-
} {
|
|
268
|
-
const relayers = useMemo(() => {
|
|
269
|
-
const relayerMap = new Map<number, Relayer.RpcRelayer>()
|
|
270
|
-
return relayerMap
|
|
271
|
-
}, [])
|
|
272
|
-
|
|
273
|
-
const getCachedRelayer = (chainId: number): Relayer.RpcRelayer => {
|
|
274
|
-
let relayer = relayers.get(chainId)
|
|
275
|
-
|
|
276
|
-
if (!relayer) {
|
|
277
|
-
relayer = getRelayer(config, chainId)
|
|
278
|
-
relayers.set(chainId, relayer)
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return relayer
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return {
|
|
285
|
-
relayers,
|
|
286
|
-
getRelayer: getCachedRelayer,
|
|
287
|
-
getBackupRelayer,
|
|
288
|
-
}
|
|
289
|
-
}
|