0xtrails 0.4.2 → 0.5.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/{ccip-Dl3umoGg.js → ccip-DhEkQ6QC.js} +27 -27
- package/dist/cctpqueue.d.ts.map +1 -1
- package/dist/chains.d.ts +3 -1
- package/dist/chains.d.ts.map +1 -1
- package/dist/config.d.ts +17 -52
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +0 -6
- package/dist/constants.d.ts.map +1 -1
- package/dist/{index-sMS_ge1R.js → index-MhD2DA7_.js} +23613 -23893
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +319 -944
- package/dist/indexerClient.d.ts +9 -6
- package/dist/indexerClient.d.ts.map +1 -1
- package/dist/intents.d.ts +0 -1
- package/dist/intents.d.ts.map +1 -1
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/sequenceWallet.d.ts +1 -1
- package/dist/sequenceWallet.d.ts.map +1 -1
- package/dist/trailsClient.d.ts +3 -3
- package/dist/trailsClient.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts +3 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +1 -0
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/transactions.d.ts +8 -2
- package/dist/transactions.d.ts.map +1 -1
- package/dist/wallets.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
- package/dist/widget/components/FeeOptions.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/WalletConnect.d.ts.map +1 -1
- package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +2 -4
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.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 +18 -0
- package/dist/widget/providers/TrailsProvider.d.ts.map +1 -0
- package/dist/widget/widget.d.ts +3 -3
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/analytics.ts +2 -2
- package/src/cctpqueue.ts +6 -3
- package/src/chains.ts +62 -29
- package/src/config.ts +36 -210
- package/src/constants.ts +0 -9
- package/src/index.ts +12 -35
- package/src/indexerClient.ts +39 -48
- package/src/intents.ts +0 -21
- package/src/prepareSend.ts +16 -2
- package/src/sequenceWallet.ts +1 -2
- package/src/trailsClient.ts +17 -12
- package/src/transactionIntent/deposits/gaslessDeposit.ts +88 -43
- package/src/transactionIntent/deposits/standardDeposit.ts +91 -53
- package/src/transactionIntent/handlers/crossChain.ts +88 -0
- package/src/transactionIntent/handlers/sameChainSameToken.ts +22 -0
- package/src/transactionIntent/types.ts +1 -0
- package/src/transactions.ts +122 -24
- package/src/wallets.ts +5 -6
- package/src/widget/components/AccountIntentTransactionHistory.tsx +5 -0
- package/src/widget/components/ConfigDisplay.tsx +19 -59
- package/src/widget/components/FeeOptions.tsx +1 -1
- package/src/widget/components/SlippageToleranceSettings.tsx +63 -14
- package/src/widget/components/WalletConnect.tsx +37 -99
- package/src/widget/hooks/useIntentTransactionHistory.ts +9 -1
- package/src/widget/hooks/useQuote.ts +11 -17
- package/src/widget/hooks/useSendForm.ts +4 -0
- package/src/widget/index.tsx +8 -0
- package/src/widget/providers/TrailsProvider.tsx +95 -0
- package/src/widget/widget.tsx +49 -98
- package/dist/trails.d.ts +0 -110
- package/dist/trails.d.ts.map +0 -1
- package/src/trails.ts +0 -1303
package/src/chains.ts
CHANGED
|
@@ -35,10 +35,6 @@ import {
|
|
|
35
35
|
} from "viem/chains"
|
|
36
36
|
import { getRelaySupportedChains } from "./relaySdk.js"
|
|
37
37
|
import { getLifiSupportedChains } from "./lifi.js"
|
|
38
|
-
import {
|
|
39
|
-
getSequenceProjectAccessKey,
|
|
40
|
-
getSequenceNodeGatewayUrl,
|
|
41
|
-
} from "./config.js"
|
|
42
38
|
import type { QuoteProvider } from "./intents.js"
|
|
43
39
|
import { somnia } from "./customChains.js"
|
|
44
40
|
|
|
@@ -89,38 +85,62 @@ export function getAllChains(): Chain[] {
|
|
|
89
85
|
]
|
|
90
86
|
}
|
|
91
87
|
|
|
92
|
-
function getSequenceRpcUrlFromSlug(
|
|
93
|
-
|
|
88
|
+
function getSequenceRpcUrlFromSlug(
|
|
89
|
+
chainSlug: string,
|
|
90
|
+
sequenceNodeGatewayUrl: string,
|
|
91
|
+
): string {
|
|
92
|
+
return `${sequenceNodeGatewayUrl}/${chainSlug}`
|
|
94
93
|
}
|
|
95
94
|
|
|
96
95
|
// Dynamic function to get sequence RPC URLs (computed at runtime to respect environment changes)
|
|
97
|
-
function getSequenceRpcUrls(
|
|
96
|
+
function getSequenceRpcUrls(
|
|
97
|
+
sequenceNodeGatewayUrl: string,
|
|
98
|
+
): Record<number, string> {
|
|
98
99
|
return {
|
|
99
|
-
[arbitrum.id]: getSequenceRpcUrlFromSlug(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
[
|
|
104
|
-
[
|
|
105
|
-
[
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
[
|
|
110
|
-
[
|
|
111
|
-
[
|
|
112
|
-
[
|
|
113
|
-
[
|
|
114
|
-
[
|
|
115
|
-
|
|
100
|
+
[arbitrum.id]: getSequenceRpcUrlFromSlug(
|
|
101
|
+
"arbitrum",
|
|
102
|
+
sequenceNodeGatewayUrl,
|
|
103
|
+
),
|
|
104
|
+
[base.id]: getSequenceRpcUrlFromSlug("base", sequenceNodeGatewayUrl),
|
|
105
|
+
[mainnet.id]: getSequenceRpcUrlFromSlug("mainnet", sequenceNodeGatewayUrl),
|
|
106
|
+
[optimism.id]: getSequenceRpcUrlFromSlug(
|
|
107
|
+
"optimism",
|
|
108
|
+
sequenceNodeGatewayUrl,
|
|
109
|
+
),
|
|
110
|
+
[gnosis.id]: getSequenceRpcUrlFromSlug("gnosis", sequenceNodeGatewayUrl),
|
|
111
|
+
[polygon.id]: getSequenceRpcUrlFromSlug("polygon", sequenceNodeGatewayUrl),
|
|
112
|
+
[soneium.id]: getSequenceRpcUrlFromSlug("soneium", sequenceNodeGatewayUrl),
|
|
113
|
+
[somnia.id]: getSequenceRpcUrlFromSlug("somnia", sequenceNodeGatewayUrl),
|
|
114
|
+
[xai.id]: getSequenceRpcUrlFromSlug("xai", sequenceNodeGatewayUrl),
|
|
115
|
+
[apeChain.id]: getSequenceRpcUrlFromSlug(
|
|
116
|
+
"apechain",
|
|
117
|
+
sequenceNodeGatewayUrl,
|
|
118
|
+
),
|
|
119
|
+
[arbitrumNova.id]: getSequenceRpcUrlFromSlug(
|
|
120
|
+
"arbitrum-nova",
|
|
121
|
+
sequenceNodeGatewayUrl,
|
|
122
|
+
),
|
|
123
|
+
[avalanche.id]: getSequenceRpcUrlFromSlug(
|
|
124
|
+
"avalanche",
|
|
125
|
+
sequenceNodeGatewayUrl,
|
|
126
|
+
),
|
|
127
|
+
[b3.id]: getSequenceRpcUrlFromSlug("b3", sequenceNodeGatewayUrl),
|
|
128
|
+
[blast.id]: getSequenceRpcUrlFromSlug("blast", sequenceNodeGatewayUrl),
|
|
129
|
+
[bsc.id]: getSequenceRpcUrlFromSlug("bsc", sequenceNodeGatewayUrl),
|
|
130
|
+
[katana.id]: getSequenceRpcUrlFromSlug("katana", sequenceNodeGatewayUrl),
|
|
131
|
+
[etherlink.id]: getSequenceRpcUrlFromSlug(
|
|
132
|
+
"etherlink",
|
|
133
|
+
sequenceNodeGatewayUrl,
|
|
134
|
+
),
|
|
116
135
|
}
|
|
117
136
|
}
|
|
118
137
|
|
|
119
138
|
export const getRpcUrl = (
|
|
120
139
|
chainId: number,
|
|
121
|
-
sequenceProjectAccessKey: string
|
|
140
|
+
sequenceProjectAccessKey: string,
|
|
141
|
+
sequenceNodeGatewayUrl: string,
|
|
122
142
|
): string | null => {
|
|
123
|
-
const sequenceRpcUrls = getSequenceRpcUrls()
|
|
143
|
+
const sequenceRpcUrls = getSequenceRpcUrls(sequenceNodeGatewayUrl)
|
|
124
144
|
if (!sequenceRpcUrls[chainId]) {
|
|
125
145
|
return null
|
|
126
146
|
}
|
|
@@ -186,15 +206,28 @@ export const mainnetChainsToTestnetChains: Record<number, Chain> = {
|
|
|
186
206
|
// Helper to get chain info
|
|
187
207
|
export function getChainInfo(
|
|
188
208
|
chainId?: number,
|
|
189
|
-
options?: {
|
|
209
|
+
options?: {
|
|
210
|
+
usePublicRpc?: boolean
|
|
211
|
+
sequenceProjectAccessKey?: string
|
|
212
|
+
sequenceNodeGatewayUrl?: string
|
|
213
|
+
},
|
|
190
214
|
): Chain | null {
|
|
191
215
|
if (!chainId) return null
|
|
192
216
|
const chainInfo =
|
|
193
217
|
getAllChains().find((chain: Chain) => chain.id === chainId) || null
|
|
194
218
|
|
|
195
219
|
// Use Sequence RPC by default. We'll want to use public RPC when adding chains to user's metamask wallet.
|
|
196
|
-
if (
|
|
197
|
-
|
|
220
|
+
if (
|
|
221
|
+
chainInfo &&
|
|
222
|
+
!options?.usePublicRpc &&
|
|
223
|
+
options?.sequenceProjectAccessKey &&
|
|
224
|
+
options?.sequenceNodeGatewayUrl
|
|
225
|
+
) {
|
|
226
|
+
const rpcUrl = getRpcUrl(
|
|
227
|
+
chainId,
|
|
228
|
+
options.sequenceProjectAccessKey,
|
|
229
|
+
options.sequenceNodeGatewayUrl,
|
|
230
|
+
)
|
|
198
231
|
if (rpcUrl) {
|
|
199
232
|
chainInfo.rpcUrls = {
|
|
200
233
|
default: {
|
package/src/config.ts
CHANGED
|
@@ -3,128 +3,45 @@ import {
|
|
|
3
3
|
DEFAULT_WALLETCONNECT_PROJECT_ID,
|
|
4
4
|
DEFAULT_SLIPPAGE_TOLERANCE,
|
|
5
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
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
+
walletConnectProjectId?: string
|
|
18
|
+
slippageTolerance?: string
|
|
19
|
+
debug?: boolean
|
|
20
|
+
commitHash?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const globalConfig: TrailsConfig = {
|
|
24
|
+
trailsApiKey: PROD_SEQUENCE_PROJECT_ACCESS_KEY,
|
|
25
|
+
sequenceIndexerUrl: PROD_SEQUENCE_INDEXER_URL,
|
|
26
|
+
sequenceNodeGatewayUrl: PROD_SEQUENCE_NODE_GATEWAY_URL,
|
|
27
|
+
trailsApiUrl: PROD_TRAILS_API_URL,
|
|
37
28
|
walletConnectProjectId: DEFAULT_WALLETCONNECT_PROJECT_ID,
|
|
38
29
|
slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
39
30
|
debug: false,
|
|
31
|
+
commitHash: declareCommitHash(),
|
|
40
32
|
}
|
|
41
33
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
106
|
-
}
|
|
107
|
-
|
|
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
|
|
34
|
+
// DEPRECATED: Use TrailsProvider context instead
|
|
35
|
+
// This is kept only for backward compatibility during migration
|
|
36
|
+
export function getConfig<T extends keyof TrailsConfig | undefined = undefined>(
|
|
37
|
+
propName?: T,
|
|
38
|
+
): T extends undefined ? Readonly<TrailsConfig> : TrailsConfig[NonNullable<T>] {
|
|
39
|
+
console.warn(
|
|
40
|
+
"[trails-sdk] getConfig is deprecated. Use TrailsProvider context with useTrails() hook instead.",
|
|
41
|
+
propName,
|
|
42
|
+
)
|
|
43
|
+
return (propName ? globalConfig[propName] : globalConfig) as any
|
|
126
44
|
}
|
|
127
|
-
|
|
128
45
|
export function declareCommitHash() {
|
|
129
46
|
const cfPagesCommitHash = getEnvVar("CF_PAGES_COMMIT_SHA")
|
|
130
47
|
const viteCommitHash = getEnvVar("VITE_COMMIT_SHA")
|
|
@@ -141,121 +58,30 @@ export function declareCommitHash() {
|
|
|
141
58
|
return cfPagesCommitHash || viteCommitHash
|
|
142
59
|
}
|
|
143
60
|
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
}
|
|
61
|
+
// DEPRECATED: These getter functions are kept for backward compatibility
|
|
62
|
+
// New code should use TrailsProvider context with useTrails() hook
|
|
223
63
|
|
|
224
64
|
/**
|
|
225
|
-
*
|
|
226
|
-
* @returns Slippage tolerance as decimal string (e.g., "0.05" for 5%, "0.001" for 0.1%)
|
|
65
|
+
* @deprecated Use TrailsProvider context instead
|
|
227
66
|
*/
|
|
228
67
|
export function getSlippageTolerance() {
|
|
229
68
|
return globalConfig.slippageTolerance
|
|
230
69
|
}
|
|
231
70
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Use TrailsProvider context instead
|
|
73
|
+
*/
|
|
236
74
|
export function getDebug() {
|
|
237
75
|
return globalConfig.debug || getQueryParam("debug") === "true"
|
|
238
76
|
}
|
|
239
77
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
`[trails-sdk][config] commit hash manually set to: ${commitHash}`,
|
|
244
|
-
)
|
|
245
|
-
}
|
|
246
|
-
|
|
78
|
+
/**
|
|
79
|
+
* @deprecated Use TrailsProvider context instead
|
|
80
|
+
*/
|
|
247
81
|
export function getCommitHash() {
|
|
248
82
|
return globalConfig.commitHash
|
|
249
83
|
}
|
|
250
84
|
|
|
251
|
-
export function getAccountIntentTransactionHistory() {
|
|
252
|
-
return FeatureFlags.accountIntentTransactionHistory
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export const FeatureFlags = {
|
|
256
|
-
accountIntentTransactionHistory: false,
|
|
257
|
-
}
|
|
258
|
-
|
|
259
85
|
export function getEnvVar(name: string) {
|
|
260
86
|
// In Vite/browser environments, check import.meta.env first
|
|
261
87
|
// This is where Vite injects environment variables at build time
|
package/src/constants.ts
CHANGED
|
@@ -27,22 +27,13 @@ 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"
|
|
34
32
|
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
33
|
|
|
41
34
|
// This is used for Sequence Indexer and API
|
|
42
35
|
export const PROD_SEQUENCE_PROJECT_ACCESS_KEY =
|
|
43
36
|
"AQAAAAAAAKhGHJc3N5V2AWqfJ1v9xZ2u0nA"
|
|
44
|
-
export const DEV_SEQUENCE_PROJECT_ACCESS_KEY =
|
|
45
|
-
"AQAAAAAAAAaq1E41OU0QxifQgrVBMgfqg7k"
|
|
46
37
|
|
|
47
38
|
export const DATABEAT_SERVER = "https://databeat.sequence.app"
|
|
48
39
|
export const DATABEAT_KEY =
|
package/src/index.ts
CHANGED
|
@@ -12,15 +12,8 @@ export {
|
|
|
12
12
|
getAllChains,
|
|
13
13
|
type Chain,
|
|
14
14
|
} 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"
|
|
15
|
+
export { useIndexerGatewayClient } from "./indexerClient.js"
|
|
16
|
+
export type { OriginCallParams, QuoteProvider, TrailsFee } from "./intents.js"
|
|
24
17
|
export {
|
|
25
18
|
calculateIntentAddress,
|
|
26
19
|
calculateOriginAndDestinationIntentAddresses,
|
|
@@ -38,11 +31,7 @@ export {
|
|
|
38
31
|
type OnDestinationTransactionFound,
|
|
39
32
|
type OnReceiptUpdate,
|
|
40
33
|
} from "./intentReceiptPoller.js"
|
|
41
|
-
export {
|
|
42
|
-
prepareSend,
|
|
43
|
-
useQuote,
|
|
44
|
-
TradeType,
|
|
45
|
-
} from "./prepareSend.js"
|
|
34
|
+
export { prepareSend, useQuote, TradeType } from "./prepareSend.js"
|
|
46
35
|
export type {
|
|
47
36
|
UseQuoteReturn,
|
|
48
37
|
UseQuoteProps,
|
|
@@ -88,35 +77,23 @@ export {
|
|
|
88
77
|
} from "./tokens.js"
|
|
89
78
|
export type { SupportedToken } from "./tokens.js"
|
|
90
79
|
export { getTxTimeDiff } from "./transactions.js"
|
|
91
|
-
export {
|
|
92
|
-
export type { WagmiAccount } from "./trails.js"
|
|
93
|
-
export {
|
|
94
|
-
useCommitIntent,
|
|
95
|
-
useExecuteIntent,
|
|
96
|
-
} from "./mutations.js"
|
|
80
|
+
export { useCommitIntent, useExecuteIntent } from "./mutations.js"
|
|
97
81
|
export type { Mode } from "./mode.js"
|
|
98
82
|
export { TRAILS_ROUTER_PLACEHOLDER_AMOUNT } from "./trailsRouter.js"
|
|
99
83
|
export { getERC20TransferData } from "./encoders.js"
|
|
84
|
+
// Config functions - getters are deprecated, use TrailsProvider context instead
|
|
100
85
|
export {
|
|
101
|
-
|
|
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,
|
|
86
|
+
getConfig,
|
|
115
87
|
getSlippageTolerance,
|
|
116
|
-
setDebug,
|
|
117
88
|
getDebug,
|
|
89
|
+
getCommitHash,
|
|
118
90
|
} from "./config.js"
|
|
119
91
|
export * from "./widget/index.js"
|
|
92
|
+
export { TrailsProvider } from "./widget/providers/TrailsProvider.js"
|
|
93
|
+
export type {
|
|
94
|
+
TrailsConfig,
|
|
95
|
+
SequenceEnv,
|
|
96
|
+
} from "./widget/providers/TrailsProvider.js"
|
|
120
97
|
export { logger, getMinLogLevel } from "./logger.js"
|
|
121
98
|
export {
|
|
122
99
|
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 - Optional base indexer URL. If not provided, uses getConfig("sequenceIndexerUrl")
|
|
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 - Optional base indexer URL. If not provided, uses getConfig("sequenceIndexerUrl")
|
|
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"
|
package/src/intents.ts
CHANGED
|
@@ -52,7 +52,6 @@ import {
|
|
|
52
52
|
trackIntentCommitCompleted,
|
|
53
53
|
trackIntentCommitError,
|
|
54
54
|
} from "./analytics.js"
|
|
55
|
-
import { getQueryParam } from "./queryParams.js"
|
|
56
55
|
import { getFullErrorMessage } from "./error.js"
|
|
57
56
|
import { GAS_BUFFER, getFeeData } from "./estimate.js"
|
|
58
57
|
import { getERC20TransferData } from "./encoders.js"
|
|
@@ -135,27 +134,11 @@ export type SendOriginCallTxArgs = {
|
|
|
135
134
|
maxPriorityFeePerGas?: bigint // Optional: EIP-1559 max priority fee per gas
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
export async function getLocalClientIfEnabled(
|
|
139
|
-
trailsClient: TrailsApi,
|
|
140
|
-
): Promise<TrailsApi> {
|
|
141
|
-
const localApiIntent = getQueryParam("localapiintent") === "true"
|
|
142
|
-
if (localApiIntent) {
|
|
143
|
-
// for testing local api changes
|
|
144
|
-
const { getTrailsClient } = await import("./trailsClient.js")
|
|
145
|
-
trailsClient = getTrailsClient({
|
|
146
|
-
hostname: "http://localhost:4422",
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
return trailsClient
|
|
150
|
-
}
|
|
151
|
-
|
|
152
137
|
export async function quoteIntent(
|
|
153
138
|
trailsClient: TrailsApi,
|
|
154
139
|
args: QuoteIntentRequest,
|
|
155
140
|
additionalTrackingProps: Record<string, string> = {},
|
|
156
141
|
): Promise<{ intent: Intent; gasFeeOptions?: GasFeeOptions }> {
|
|
157
|
-
trailsClient = await getLocalClientIfEnabled(trailsClient)
|
|
158
|
-
|
|
159
142
|
// Track intent quote request
|
|
160
143
|
trackIntentQuoteRequested({
|
|
161
144
|
originChainId: args.originChainId || 0,
|
|
@@ -351,8 +334,6 @@ export async function commitIntent(
|
|
|
351
334
|
intent: Intent,
|
|
352
335
|
additionalTrackingProps: Record<string, string> = {},
|
|
353
336
|
): Promise<CommitIntentResponse> {
|
|
354
|
-
trailsClient = await getLocalClientIfEnabled(trailsClient)
|
|
355
|
-
|
|
356
337
|
logger.console.log("[trails-sdk] commitIntent inputs:", {
|
|
357
338
|
intentId: intent.intentId,
|
|
358
339
|
ownerAddress: intent.ownerAddress,
|
|
@@ -461,8 +442,6 @@ export async function executeIntent(
|
|
|
461
442
|
depositTransactionHash?: string,
|
|
462
443
|
depositSignature?: DepositSignature,
|
|
463
444
|
) {
|
|
464
|
-
trailsClient = await getLocalClientIfEnabled(trailsClient)
|
|
465
|
-
|
|
466
445
|
logger.console.log("[trails-sdk] executeIntent inputs:", {
|
|
467
446
|
intentId,
|
|
468
447
|
depositTransactionHash,
|