0xtrails 0.2.0 → 0.2.1
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 +1 -0
- package/dist/analytics.d.ts.map +1 -1
- package/dist/{ccip-D6ToCrWc.js → ccip-BbfANth7.js} +1 -1
- package/dist/chains.d.ts.map +1 -1
- package/dist/config.d.ts +1 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +2 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/gasless.d.ts +19 -7
- package/dist/gasless.d.ts.map +1 -1
- package/dist/{index-BqgeTLL8.js → index-WpIVoh3X.js} +27626 -26572
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +68 -68
- package/dist/indexerClient.d.ts +10 -0
- package/dist/indexerClient.d.ts.map +1 -1
- package/dist/intentEntrypoint.d.ts +40 -14
- package/dist/intentEntrypoint.d.ts.map +1 -1
- package/dist/intents.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +11 -8
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/relayer.d.ts.map +1 -1
- package/dist/trails.d.ts.map +1 -1
- package/dist/trailsClient.d.ts.map +1 -1
- package/dist/trailsRouter.d.ts +22 -0
- package/dist/trailsRouter.d.ts.map +1 -0
- package/dist/transactions.d.ts +0 -1
- package/dist/transactions.d.ts.map +1 -1
- package/dist/widget/components/AccountSettings.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/ConnectWallet.d.ts.map +1 -1
- package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/FeeOption.d.ts +22 -0
- package/dist/widget/components/FeeOption.d.ts.map +1 -0
- package/dist/widget/components/FeeOptions.d.ts +13 -17
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundMethods.d.ts +1 -1
- package/dist/widget/components/FundMethods.d.ts.map +1 -1
- package/dist/widget/components/FundSendForm.d.ts.map +1 -1
- package/dist/widget/components/MeshConnectExchanges.d.ts +5 -2
- package/dist/widget/components/MeshConnectExchanges.d.ts.map +1 -1
- package/dist/widget/components/MeshConnectFlow.d.ts +2 -0
- package/dist/widget/components/MeshConnectFlow.d.ts.map +1 -1
- package/dist/widget/components/NativeGasOption.d.ts +12 -0
- package/dist/widget/components/NativeGasOption.d.ts.map +1 -0
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PaySendForm.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/TokenSelector.d.ts.map +1 -1
- package/dist/widget/components/UserPreferences.d.ts.map +1 -1
- package/dist/widget/hooks/useBack.d.ts +2 -0
- package/dist/widget/hooks/useBack.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/useDefaultTokenSelection.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedFeeToken.d.ts +32 -0
- package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +1 -0
- package/dist/widget/hooks/useSelectedMeshExchange.d.ts +14 -0
- package/dist/widget/hooks/useSelectedMeshExchange.d.ts.map +1 -0
- package/dist/widget/hooks/useSendForm.d.ts +8 -13
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/index.js +1 -1
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +29 -28
- package/src/analytics.ts +6 -0
- package/src/chains.ts +10 -0
- package/src/config.ts +25 -10
- package/src/constants.ts +11 -10
- package/src/gasless.ts +162 -109
- package/src/index.ts +1 -1
- package/src/indexerClient.ts +73 -1
- package/src/intentEntrypoint.ts +66 -101
- package/src/intents.ts +0 -2
- package/src/prepareSend.ts +1409 -887
- package/src/relayer.ts +4 -3
- package/src/trails.ts +1 -3
- package/src/trailsClient.ts +4 -1
- package/src/{balanceInjector.ts → trailsRouter.ts} +14 -14
- package/src/transactions.ts +4 -54
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/AccountSettings.tsx +7 -1
- package/src/widget/components/ClassicSwap.tsx +173 -175
- package/src/widget/components/ConfigDisplay.tsx +34 -1
- package/src/widget/components/ConnectWallet.tsx +168 -11
- package/src/widget/components/ConnectedWallets.tsx +184 -102
- package/src/widget/components/DebugToast.tsx +3 -3
- package/src/widget/components/Earn.tsx +4 -27
- package/src/widget/components/FeeOption.tsx +78 -0
- package/src/widget/components/FeeOptions.tsx +192 -127
- package/src/widget/components/Fund.tsx +18 -27
- package/src/widget/components/FundMethods.tsx +3 -3
- package/src/widget/components/FundSendForm.tsx +0 -33
- package/src/widget/components/MeshConnectExchanges.tsx +32 -3
- package/src/widget/components/MeshConnectFlow.tsx +23 -4
- package/src/widget/components/NativeGasOption.tsx +99 -0
- package/src/widget/components/Pay.tsx +36 -32
- package/src/widget/components/PaySendForm.tsx +0 -37
- package/src/widget/components/QuoteDetails.tsx +0 -29
- package/src/widget/components/TokenSelector.tsx +11 -0
- package/src/widget/components/TransferPendingVertical.tsx +1 -1
- package/src/widget/components/UserPreferences.tsx +3 -4
- package/src/widget/hooks/useBack.tsx +4 -0
- package/src/widget/hooks/useCurrentScreen.tsx +1 -0
- package/src/widget/hooks/useDefaultTokenSelection.tsx +3 -7
- package/src/widget/hooks/useSelectedFeeToken.tsx +299 -0
- package/src/widget/hooks/useSelectedMeshExchange.tsx +46 -0
- package/src/widget/hooks/useSendForm.ts +78 -23
- package/src/widget/widget.tsx +173 -111
- package/dist/balanceInjector.d.ts +0 -22
- package/dist/balanceInjector.d.ts.map +0 -1
package/src/index.ts
CHANGED
|
@@ -78,7 +78,7 @@ export { getTxTimeDiff } from "./transactions.js"
|
|
|
78
78
|
export { useTrails } from "./trails.js"
|
|
79
79
|
export type { WagmiAccount } from "./trails.js"
|
|
80
80
|
export type { Mode } from "./mode.js"
|
|
81
|
-
export {
|
|
81
|
+
export { TRAILS_ROUTER_PLACEHOLDER_AMOUNT } from "./trailsRouter.js"
|
|
82
82
|
export { getERC20TransferData } from "./encoders.js"
|
|
83
83
|
export { getRelayer, useRelayers } from "./relayer.js"
|
|
84
84
|
export { relayerSendMetaTx, getMetaTxnReceipt } from "./metaTxns.js"
|
package/src/indexerClient.ts
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
import { useConfig } from "@0xsequence/hooks"
|
|
2
2
|
import { SequenceIndexerGateway } from "@0xsequence/indexer"
|
|
3
3
|
import { useMemo } from "react"
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getSequenceIndexerUrl,
|
|
6
|
+
getSequenceProjectAccessKey,
|
|
7
|
+
getSequenceEnv,
|
|
8
|
+
} from "./config.js"
|
|
9
|
+
import {
|
|
10
|
+
arbitrum,
|
|
11
|
+
base,
|
|
12
|
+
baseSepolia,
|
|
13
|
+
optimism,
|
|
14
|
+
polygon,
|
|
15
|
+
mainnet,
|
|
16
|
+
apeChain,
|
|
17
|
+
arbitrumNova,
|
|
18
|
+
avalanche,
|
|
19
|
+
b3,
|
|
20
|
+
blast,
|
|
21
|
+
gnosis,
|
|
22
|
+
soneium,
|
|
23
|
+
xai,
|
|
24
|
+
bsc,
|
|
25
|
+
etherlink,
|
|
26
|
+
katana,
|
|
27
|
+
} from "viem/chains"
|
|
5
28
|
|
|
6
29
|
export type IndexerGatewayConfig = {
|
|
7
30
|
indexerGatewayUrl?: string
|
|
@@ -9,6 +32,55 @@ export type IndexerGatewayConfig = {
|
|
|
9
32
|
jwt?: string
|
|
10
33
|
}
|
|
11
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Get the indexer URL for a specific chain slug
|
|
37
|
+
* Dynamically determines the environment prefix
|
|
38
|
+
*/
|
|
39
|
+
export function getIndexerUrlFromChainSlug(chainSlug: string): string {
|
|
40
|
+
const env = getSequenceEnv()
|
|
41
|
+
let envPrefix = ""
|
|
42
|
+
|
|
43
|
+
if (env === "dev") {
|
|
44
|
+
envPrefix = "dev-"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return `https://${envPrefix}${chainSlug}-indexer.sequence.app`
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the chain-specific indexer URL by chain ID
|
|
52
|
+
* Returns the appropriate indexer URL based on the current environment
|
|
53
|
+
*/
|
|
54
|
+
export function getChainIndexerUrl(chainId: number): string | undefined {
|
|
55
|
+
const chainIdToSlug: Record<number, string> = {
|
|
56
|
+
[arbitrum.id]: "arbitrum",
|
|
57
|
+
[base.id]: "base",
|
|
58
|
+
[baseSepolia.id]: "base-sepolia",
|
|
59
|
+
[optimism.id]: "optimism",
|
|
60
|
+
[polygon.id]: "polygon",
|
|
61
|
+
[mainnet.id]: "mainnet",
|
|
62
|
+
[apeChain.id]: "apechain",
|
|
63
|
+
[arbitrumNova.id]: "arbitrum-nova",
|
|
64
|
+
[avalanche.id]: "avalanche",
|
|
65
|
+
[b3.id]: "b3",
|
|
66
|
+
[blast.id]: "blast",
|
|
67
|
+
[gnosis.id]: "gnosis",
|
|
68
|
+
[soneium.id]: "soneium",
|
|
69
|
+
[xai.id]: "xai",
|
|
70
|
+
[bsc.id]: "bsc",
|
|
71
|
+
421613: "arbitrum-nova-sepolia",
|
|
72
|
+
[etherlink.id]: "etherlink",
|
|
73
|
+
[katana.id]: "katana",
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const chainSlug = chainIdToSlug[chainId]
|
|
77
|
+
if (!chainSlug) {
|
|
78
|
+
return undefined
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return getIndexerUrlFromChainSlug(chainSlug)
|
|
82
|
+
}
|
|
83
|
+
|
|
12
84
|
export function getIndexerGatewayClient({
|
|
13
85
|
indexerGatewayUrl = getSequenceIndexerUrl(),
|
|
14
86
|
projectAccessKey = getSequenceProjectAccessKey(),
|
package/src/intentEntrypoint.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { Account, WalletClient, Hex, Address } from "viem"
|
|
1
|
+
import type { Account, WalletClient, Hex, Address, PublicClient } from "viem"
|
|
2
2
|
import { intentEntrypoints } from "./constants.js"
|
|
3
3
|
import type { TrailsAPIClient } from "@0xsequence/trails-api"
|
|
4
|
-
import { signIntent } from "./gasless.js"
|
|
5
4
|
|
|
6
5
|
// Intent Entrypoint ABI (partial - only the functions we need)
|
|
7
6
|
// TODO: Uncomment and use when implementing calldata injection
|
|
@@ -72,9 +71,41 @@ export type IntentEntrypointDepositResult = {
|
|
|
72
71
|
entrypointAddress: Address
|
|
73
72
|
}
|
|
74
73
|
|
|
74
|
+
export type IntentEntrypointFeeOptionsParams = {
|
|
75
|
+
userAddress: Address
|
|
76
|
+
tokenAddress: Address
|
|
77
|
+
amount: string
|
|
78
|
+
intentAddress: Address
|
|
79
|
+
chainID: number
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type FeeOption = {
|
|
83
|
+
tokenAddress: string
|
|
84
|
+
tokenSymbol: string
|
|
85
|
+
tokenDecimals: number
|
|
86
|
+
amount: string
|
|
87
|
+
amountUSD: number
|
|
88
|
+
feeCollector: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type GasEstimate = {
|
|
92
|
+
totalGas: number
|
|
93
|
+
gasPrice: string
|
|
94
|
+
nativeCost: string
|
|
95
|
+
nativeCostUSD: number
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type IntentEntrypointFeeOptionsResult = {
|
|
99
|
+
gasEstimate: GasEstimate
|
|
100
|
+
feeOptions: FeeOption[]
|
|
101
|
+
expiresAt: number
|
|
102
|
+
feeCollector: string
|
|
103
|
+
}
|
|
104
|
+
|
|
75
105
|
export type GaslessDepositOptions = {
|
|
76
106
|
trailsClient: TrailsAPIClient
|
|
77
107
|
walletClient: WalletClient
|
|
108
|
+
publicClient: PublicClient
|
|
78
109
|
account: Account
|
|
79
110
|
tokenAddress: Address
|
|
80
111
|
amount: bigint | string
|
|
@@ -94,105 +125,6 @@ export enum DepositStatus {
|
|
|
94
125
|
FAILED = "failed",
|
|
95
126
|
}
|
|
96
127
|
|
|
97
|
-
/**
|
|
98
|
-
* Execute a gasless deposit to an Intent Entrypoint
|
|
99
|
-
* This function handles the entire flow using the sign-first approach:
|
|
100
|
-
* 1. Gets message hash from API
|
|
101
|
-
* 2. User signs the message hash
|
|
102
|
-
* 3. Calls API with signature to get meta transaction
|
|
103
|
-
* 4. Submits meta transaction via relayer
|
|
104
|
-
*/
|
|
105
|
-
export async function executeGaslessDeposit({
|
|
106
|
-
trailsClient,
|
|
107
|
-
walletClient,
|
|
108
|
-
account,
|
|
109
|
-
tokenAddress,
|
|
110
|
-
amount,
|
|
111
|
-
intentAddress,
|
|
112
|
-
chainId,
|
|
113
|
-
deadline,
|
|
114
|
-
usePermit = false,
|
|
115
|
-
onStatusUpdate,
|
|
116
|
-
}: GaslessDepositOptions): Promise<{
|
|
117
|
-
txHash: string | null
|
|
118
|
-
receipt: unknown
|
|
119
|
-
depositWalletAddress: Address
|
|
120
|
-
}> {
|
|
121
|
-
try {
|
|
122
|
-
// Update status
|
|
123
|
-
onStatusUpdate?.(DepositStatus.PREPARING)
|
|
124
|
-
|
|
125
|
-
// Default deadline to 1 hour from now
|
|
126
|
-
const effectiveDeadline = deadline || Math.floor(Date.now() / 1000) + 3600
|
|
127
|
-
|
|
128
|
-
// Convert amount to string if it's bigint
|
|
129
|
-
const amountStr = typeof amount === "bigint" ? amount.toString() : amount
|
|
130
|
-
|
|
131
|
-
// 1. Get the entrypoint address for this chain
|
|
132
|
-
const entrypointAddress = getIntentEntrypointAddress(chainId)
|
|
133
|
-
if (!entrypointAddress) {
|
|
134
|
-
throw new Error(`Intent Entrypoint not deployed on chain ${chainId}`)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// 2. User signs using EIP-712 typed data
|
|
138
|
-
onStatusUpdate?.(DepositStatus.SIGNING)
|
|
139
|
-
const { signature: intentSignature } = await signIntent({
|
|
140
|
-
client: walletClient,
|
|
141
|
-
intentParams: {
|
|
142
|
-
user: account.address,
|
|
143
|
-
token: tokenAddress,
|
|
144
|
-
amount: BigInt(amountStr),
|
|
145
|
-
intentAddress,
|
|
146
|
-
deadline: BigInt(effectiveDeadline),
|
|
147
|
-
chainId,
|
|
148
|
-
contractAddress: entrypointAddress,
|
|
149
|
-
},
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
// 3. Call the deposit endpoint with the signature
|
|
153
|
-
onStatusUpdate?.(DepositStatus.SUBMITTING)
|
|
154
|
-
const depositDataResponse = await trailsClient.getIntentEntrypointDeposit({
|
|
155
|
-
params: {
|
|
156
|
-
userAddress: account.address,
|
|
157
|
-
tokenAddress,
|
|
158
|
-
amount: amountStr,
|
|
159
|
-
intentAddress,
|
|
160
|
-
chainID: chainId,
|
|
161
|
-
deadline: effectiveDeadline,
|
|
162
|
-
intentSignature,
|
|
163
|
-
usePermit,
|
|
164
|
-
// TODO: Support permit signature
|
|
165
|
-
// permitSignature: permitSig,
|
|
166
|
-
// permitDeadline: usePermit ? effectiveDeadline : undefined,
|
|
167
|
-
},
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
const depositData = depositDataResponse.result
|
|
171
|
-
|
|
172
|
-
// 4. Submit meta transaction via relayer
|
|
173
|
-
// TODO: Implement relayer submission
|
|
174
|
-
// This would typically be done through the Sequence relayer
|
|
175
|
-
// const receipt = await relayer.sendMetaTxn({
|
|
176
|
-
// ...depositData.metaTxn,
|
|
177
|
-
// feeQuote: depositData.feeQuote,
|
|
178
|
-
// })
|
|
179
|
-
|
|
180
|
-
// For now, just return the deposit data
|
|
181
|
-
console.log("Deposit data ready:", depositData)
|
|
182
|
-
|
|
183
|
-
onStatusUpdate?.(DepositStatus.CONFIRMED)
|
|
184
|
-
|
|
185
|
-
return {
|
|
186
|
-
txHash: null, // Would come from relayer response
|
|
187
|
-
receipt: null, // Would come from relayer response
|
|
188
|
-
depositWalletAddress: depositData.depositWalletAddress as Address,
|
|
189
|
-
}
|
|
190
|
-
} catch (error) {
|
|
191
|
-
onStatusUpdate?.(DepositStatus.FAILED)
|
|
192
|
-
throw error
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
128
|
/**
|
|
197
129
|
* Inject signatures into the meta transaction calldata
|
|
198
130
|
* This updates the placeholder signature values in the Intent Entrypoint call
|
|
@@ -251,3 +183,36 @@ export function getIntentEntrypointAddress(chainId: number): Address | null {
|
|
|
251
183
|
export function isIntentEntrypointSupported(chainId: number): boolean {
|
|
252
184
|
return chainId in intentEntrypoints
|
|
253
185
|
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Get fee options for intent entrypoint deposits
|
|
189
|
+
*/
|
|
190
|
+
export async function getIntentEntrypointFeeOptions({
|
|
191
|
+
trailsClient,
|
|
192
|
+
userAddress,
|
|
193
|
+
tokenAddress,
|
|
194
|
+
amount,
|
|
195
|
+
intentAddress,
|
|
196
|
+
chainId,
|
|
197
|
+
}: {
|
|
198
|
+
trailsClient: TrailsAPIClient
|
|
199
|
+
userAddress: Address
|
|
200
|
+
tokenAddress: Address
|
|
201
|
+
amount: bigint | string
|
|
202
|
+
intentAddress: Address
|
|
203
|
+
chainId: number
|
|
204
|
+
}): Promise<IntentEntrypointFeeOptionsResult> {
|
|
205
|
+
const params: IntentEntrypointFeeOptionsParams = {
|
|
206
|
+
userAddress,
|
|
207
|
+
tokenAddress,
|
|
208
|
+
amount: amount.toString(),
|
|
209
|
+
intentAddress,
|
|
210
|
+
chainID: chainId,
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const response = await trailsClient.getIntentEntrypointDepositFeeOptions({
|
|
214
|
+
params,
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
return response.result
|
|
218
|
+
}
|
package/src/intents.ts
CHANGED
|
@@ -185,10 +185,8 @@ export async function getIntentCallsPayloads(
|
|
|
185
185
|
trackIntentQuoteReceived({
|
|
186
186
|
quoteId: result.payloads.originIntentAddress || "unknown",
|
|
187
187
|
totalFeeUSD: result.payloads.trailsFee?.totalFeeUSD,
|
|
188
|
-
trailsFixedFeeUSD: result.payloads.trailsFee?.trailsFixedFeeUSD,
|
|
189
188
|
crossChainFeeTotalUSD:
|
|
190
189
|
result.payloads.trailsFee?.crossChainFee?.totalFeeUSD,
|
|
191
|
-
takerFeeUSD: result.payloads.trailsFee?.takerFeeUSD,
|
|
192
190
|
providerFeeUSD: result.payloads.trailsFee?.crossChainFee?.providerFeeUSD,
|
|
193
191
|
trailsSwapFeeUSD:
|
|
194
192
|
result.payloads.trailsFee?.crossChainFee?.trailsSwapFeeUSD,
|