0xtrails 0.5.0 → 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-DhEkQ6QC.js → ccip-Dw5AN7oU.js} +1 -1
- package/dist/cctp.d.ts +0 -149
- package/dist/cctp.d.ts.map +1 -1
- package/dist/chains.d.ts +28 -3
- package/dist/chains.d.ts.map +1 -1
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -1
- 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-MhD2DA7_.js → index-BtVUTbEZ.js} +30984 -38945
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -107
- package/dist/indexerClient.d.ts +2 -2
- package/dist/intents.d.ts +0 -17
- 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/tokenBalances.d.ts.map +1 -1
- package/dist/tokens.d.ts +10 -8
- package/dist/tokens.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 +4 -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 +6 -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 +2 -20
- 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/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/Toast.d.ts.map +1 -1
- package/dist/widget/components/TokenImage.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 +5 -8
- 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.js +1 -1
- package/dist/widget/providers/TrailsProvider.d.ts +23 -12
- package/dist/widget/providers/TrailsProvider.d.ts.map +1 -1
- package/dist/widget/widget.d.ts +11 -0
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/analytics.ts +53 -21
- package/src/cctp.ts +0 -1016
- package/src/chains.ts +93 -39
- package/src/config.ts +24 -6
- package/src/constants.ts +1 -4
- 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 +7 -6
- package/src/indexerClient.ts +2 -2
- package/src/intents.ts +52 -206
- package/src/mutations.ts +3 -2
- package/src/paymasterSend.ts +2 -5
- package/src/prepareSend.ts +9 -12
- package/src/sendUserOp.ts +3 -64
- package/src/tokenBalances.ts +2 -1
- package/src/tokens.ts +62 -133
- package/src/trailsClient.ts +1 -1
- 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 +165 -385
- 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 +6 -27
- package/src/transactionIntent/utils/index.ts +0 -1
- package/src/transactions.ts +6 -203
- package/src/umd.tsx +1 -3
- package/src/utils.ts +28 -8
- package/src/walletUtils.ts +42 -0
- package/src/wallets.ts +361 -203
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/AccountIntentTransactionHistory.tsx +73 -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 +1 -1
- 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/Toast.tsx +10 -0
- package/src/widget/components/TokenImage.tsx +56 -13
- 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 +788 -418
- package/src/widget/hooks/useIsConnectedWalletSmartContract.ts +43 -0
- package/src/widget/hooks/useIsSequenceWallet.ts +17 -0
- package/src/widget/hooks/useQuote.ts +16 -17
- package/src/widget/hooks/useRecentTokens.ts +2 -1
- package/src/widget/hooks/useSelectedFeeOption.tsx +257 -0
- package/src/widget/hooks/useSendForm.ts +172 -47
- package/src/widget/hooks/useTokenList.ts +15 -2
- package/src/widget/providers/TrailsProvider.tsx +53 -25
- package/src/widget/widget.tsx +119 -48
- 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/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 -69
- package/src/preconditions.ts +0 -47
- 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/intents.ts
CHANGED
|
@@ -3,44 +3,25 @@ import type {
|
|
|
3
3
|
CommitIntentResponse,
|
|
4
4
|
Intent,
|
|
5
5
|
IntentCalls,
|
|
6
|
-
TransactionPrecondition,
|
|
7
6
|
TrailsApi,
|
|
8
7
|
ExecuteIntentRequest,
|
|
9
8
|
GasFeeOptions,
|
|
10
9
|
DepositSignature,
|
|
11
10
|
} from "@0xsequence/trails-api"
|
|
11
|
+
import { JsonEncode } from "@0xsequence/trails-api"
|
|
12
12
|
import type { TrailsClient } from "./trailsClient.js"
|
|
13
13
|
import { logger } from "./logger.js"
|
|
14
|
-
import { bigintReplacer } from "./utils.js"
|
|
15
|
-
|
|
16
|
-
export type {
|
|
17
|
-
IntentCalls,
|
|
18
|
-
TransactionPrecondition,
|
|
19
|
-
} from "@0xsequence/trails-api"
|
|
20
14
|
|
|
21
15
|
import { Config, type Context, Payload } from "@0xsequence/wallet-primitives"
|
|
22
|
-
import {
|
|
23
|
-
AbiParameters,
|
|
24
|
-
Address,
|
|
25
|
-
Bytes,
|
|
26
|
-
ContractAddress,
|
|
27
|
-
Hash,
|
|
28
|
-
type Hex,
|
|
29
|
-
} from "ox"
|
|
16
|
+
import { Address, Bytes, ContractAddress, Hash, type Hex } from "ox"
|
|
30
17
|
import {
|
|
31
18
|
type Account,
|
|
32
19
|
type Chain,
|
|
33
20
|
isAddressEqual,
|
|
34
21
|
type WalletClient,
|
|
35
|
-
http,
|
|
36
|
-
createPublicClient,
|
|
37
22
|
} from "viem"
|
|
38
|
-
import {
|
|
39
|
-
|
|
40
|
-
SEQUENCE_V3_CONTRACT_ADDRESSES,
|
|
41
|
-
} from "./constants.js"
|
|
42
|
-
import { findPreconditionAddresses } from "./preconditions.js"
|
|
43
|
-
import { getChainInfo } from "./chains.js"
|
|
23
|
+
import { getChainInfo, getPublicRpcClient } from "./chains.js"
|
|
24
|
+
import { SEQUENCE_V3_CONTRACT_ADDRESSES } from "./constants.js"
|
|
44
25
|
import {
|
|
45
26
|
trackTransactionStarted,
|
|
46
27
|
trackTransactionSubmitted,
|
|
@@ -55,7 +36,7 @@ import {
|
|
|
55
36
|
import { getFullErrorMessage } from "./error.js"
|
|
56
37
|
import { GAS_BUFFER, getFeeData } from "./estimate.js"
|
|
57
38
|
import { getERC20TransferData } from "./encoders.js"
|
|
58
|
-
import {
|
|
39
|
+
import { isNativeToken } from "./utils.js"
|
|
59
40
|
|
|
60
41
|
export type IntentRequestParams = {
|
|
61
42
|
userAddress: string
|
|
@@ -160,17 +141,9 @@ export async function quoteIntent(
|
|
|
160
141
|
|
|
161
142
|
const result = response.intent
|
|
162
143
|
|
|
163
|
-
// Extract precondition amounts
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const originPrecondition = result.preconditions?.find(
|
|
167
|
-
(p: TransactionPrecondition) =>
|
|
168
|
-
Number(p.chainId) === Number(originChainId),
|
|
169
|
-
)
|
|
170
|
-
const destinationPrecondition = result.preconditions?.find(
|
|
171
|
-
(p: TransactionPrecondition) =>
|
|
172
|
-
Number(p.chainId) === Number(destinationChainId),
|
|
173
|
-
)
|
|
144
|
+
// Extract precondition amounts from origin and destination preconditions
|
|
145
|
+
const originPrecondition = result.originPrecondition
|
|
146
|
+
const destinationPrecondition = result.destinationPrecondition
|
|
174
147
|
|
|
175
148
|
// Track successful intent quote received
|
|
176
149
|
trackIntentQuoteReceived({
|
|
@@ -229,7 +202,7 @@ export function calculateIntentAddress(
|
|
|
229
202
|
): `0x${string}` {
|
|
230
203
|
logger.console.log("[trails-sdk] calculateIntentAddress inputs:", {
|
|
231
204
|
mainSigner,
|
|
232
|
-
calls
|
|
205
|
+
calls,
|
|
233
206
|
})
|
|
234
207
|
|
|
235
208
|
const context = SEQUENCE_V3_CONTRACT_ADDRESSES
|
|
@@ -334,23 +307,33 @@ export async function commitIntent(
|
|
|
334
307
|
intent: Intent,
|
|
335
308
|
additionalTrackingProps: Record<string, string> = {},
|
|
336
309
|
): Promise<CommitIntentResponse> {
|
|
310
|
+
// Build arrays for logging
|
|
311
|
+
const originIntentCalls = intent.originCalls
|
|
312
|
+
const destinationIntentCalls = intent.destinationCalls
|
|
313
|
+
const calls = []
|
|
314
|
+
if (originIntentCalls) calls.push(originIntentCalls)
|
|
315
|
+
if (destinationIntentCalls) calls.push(destinationIntentCalls)
|
|
316
|
+
|
|
317
|
+
const originPre = intent.originPrecondition
|
|
318
|
+
const destinationPre = intent.destinationPrecondition
|
|
319
|
+
const preconditions = []
|
|
320
|
+
if (originPre) preconditions.push(originPre)
|
|
321
|
+
if (destinationPre) preconditions.push(destinationPre)
|
|
322
|
+
|
|
337
323
|
logger.console.log("[trails-sdk] commitIntent inputs:", {
|
|
338
324
|
intentId: intent.intentId,
|
|
339
325
|
ownerAddress: intent.ownerAddress,
|
|
340
326
|
originIntentAddress: intent.originIntentAddress,
|
|
341
327
|
destinationIntentAddress: intent.destinationIntentAddress,
|
|
342
|
-
calls
|
|
343
|
-
preconditions
|
|
328
|
+
calls,
|
|
329
|
+
preconditions,
|
|
344
330
|
})
|
|
345
331
|
|
|
346
332
|
// Additional detailed precondition logging
|
|
347
|
-
logger.console.log(
|
|
348
|
-
"[trails-sdk] Detailed preconditions:",
|
|
349
|
-
intent.preconditions,
|
|
350
|
-
)
|
|
333
|
+
logger.console.log("[trails-sdk] Detailed preconditions:", preconditions)
|
|
351
334
|
|
|
352
335
|
// Log each precondition individually for easier reading
|
|
353
|
-
|
|
336
|
+
preconditions.forEach((precondition, index) => {
|
|
354
337
|
logger.console.log(`[trails-sdk] Precondition ${index}:`, {
|
|
355
338
|
type: precondition.type,
|
|
356
339
|
chainId: precondition.chainId,
|
|
@@ -369,18 +352,12 @@ export async function commitIntent(
|
|
|
369
352
|
intent.destinationIntentAddress,
|
|
370
353
|
)
|
|
371
354
|
|
|
372
|
-
const originChainIdStr = intent.
|
|
373
|
-
const destinationChainIdStr =
|
|
355
|
+
const originChainIdStr = intent.quoteRequest.originChainId.toString()
|
|
356
|
+
const destinationChainIdStr =
|
|
357
|
+
intent.quoteRequest.destinationChainId.toString()
|
|
374
358
|
|
|
375
|
-
//
|
|
376
|
-
const
|
|
377
|
-
originChainIdStr && destinationChainIdStr
|
|
378
|
-
? findPreconditionAddresses(
|
|
379
|
-
intent.preconditions,
|
|
380
|
-
Number(originChainIdStr),
|
|
381
|
-
Number(destinationChainIdStr),
|
|
382
|
-
)
|
|
383
|
-
: { originAddress: undefined }
|
|
359
|
+
// Get the origin precondition owner address directly
|
|
360
|
+
const receivedAddress = originPre?.ownerAddress
|
|
384
361
|
|
|
385
362
|
logger.console.log("[trails-sdk] Address comparison:", {
|
|
386
363
|
receivedAddress,
|
|
@@ -500,10 +477,11 @@ export async function sendOriginTransaction(
|
|
|
500
477
|
...additionalTrackingProps,
|
|
501
478
|
})
|
|
502
479
|
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
480
|
+
const chainInfo = getChainInfo(originParams.chain.id)
|
|
481
|
+
if (!chainInfo) {
|
|
482
|
+
throw new Error(`Chain ${originParams.chain.id} not found`)
|
|
483
|
+
}
|
|
484
|
+
const publicClient = getPublicRpcClient(chainInfo)
|
|
507
485
|
|
|
508
486
|
// Use provided gasLimit if available, otherwise estimate
|
|
509
487
|
let gasLimit: bigint
|
|
@@ -628,137 +606,6 @@ export async function sendOriginTransaction(
|
|
|
628
606
|
}
|
|
629
607
|
}
|
|
630
608
|
|
|
631
|
-
export interface OriginTokenParam {
|
|
632
|
-
address: Address.Address
|
|
633
|
-
chainId: bigint
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
export interface DestinationTokenParam {
|
|
637
|
-
address: Address.Address
|
|
638
|
-
chainId: bigint
|
|
639
|
-
amount: bigint
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
export function hashIntentParams({
|
|
643
|
-
userAddress,
|
|
644
|
-
nonce,
|
|
645
|
-
originTokens,
|
|
646
|
-
destinationCalls,
|
|
647
|
-
destinationTokens,
|
|
648
|
-
}: {
|
|
649
|
-
userAddress: Address.Address
|
|
650
|
-
nonce: bigint
|
|
651
|
-
originTokens: OriginTokenParam[]
|
|
652
|
-
destinationCalls: Array<IntentCalls>
|
|
653
|
-
destinationTokens: DestinationTokenParam[]
|
|
654
|
-
}): string {
|
|
655
|
-
if (
|
|
656
|
-
!userAddress ||
|
|
657
|
-
userAddress === "0x0000000000000000000000000000000000000000"
|
|
658
|
-
)
|
|
659
|
-
throw new Error("UserAddress is zero")
|
|
660
|
-
if (typeof nonce !== "bigint") throw new Error("Nonce is not a bigint")
|
|
661
|
-
if (!originTokens || originTokens.length === 0)
|
|
662
|
-
throw new Error("OriginTokens is empty")
|
|
663
|
-
if (!destinationCalls || destinationCalls.length === 0)
|
|
664
|
-
throw new Error("DestinationCalls is empty")
|
|
665
|
-
if (!destinationTokens || destinationTokens.length === 0)
|
|
666
|
-
throw new Error("DestinationTokens is empty")
|
|
667
|
-
for (let i = 0; i < destinationCalls.length; i++) {
|
|
668
|
-
const currentCall = destinationCalls[i]
|
|
669
|
-
if (!currentCall) throw new Error(`DestinationCalls[${i}] is nil`)
|
|
670
|
-
if (!currentCall.calls || currentCall.calls.length === 0) {
|
|
671
|
-
throw new Error(`DestinationCalls[${i}] has no calls`)
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
const originTokensForAbi = originTokens.map((token) => ({
|
|
676
|
-
address: token.address,
|
|
677
|
-
chainId: token.chainId,
|
|
678
|
-
}))
|
|
679
|
-
|
|
680
|
-
let cumulativeCallsHashBytes: Bytes.Bytes = Bytes.from(new Uint8Array(32))
|
|
681
|
-
|
|
682
|
-
for (let i = 0; i < destinationCalls.length; i++) {
|
|
683
|
-
const callPayload = destinationCalls[i]
|
|
684
|
-
if (!callPayload) throw new Error(`DestinationCalls[${i}] is nil`)
|
|
685
|
-
|
|
686
|
-
const currentDestCallPayloadHashBytes = Payload.hash(
|
|
687
|
-
ATTESATION_SIGNER_ADDRESS,
|
|
688
|
-
Number(callPayload.chainId),
|
|
689
|
-
{
|
|
690
|
-
type: "call",
|
|
691
|
-
space: callPayload.space ? BigInt(callPayload.space) : 0n,
|
|
692
|
-
nonce: callPayload.nonce ? BigInt(callPayload.nonce) : 0n,
|
|
693
|
-
calls: callPayload.calls.map((call) => ({
|
|
694
|
-
type: "call",
|
|
695
|
-
to: call.to as `0x${string}`,
|
|
696
|
-
value: BigInt(call.value?.toString() || "0"),
|
|
697
|
-
data: Bytes.toHex(Bytes.from((call.data as Hex.Hex) || "0x")),
|
|
698
|
-
gasLimit: BigInt(call.gasLimit?.toString() || "0"),
|
|
699
|
-
delegateCall: !!call.delegateCall,
|
|
700
|
-
onlyFallback: !!call.onlyFallback,
|
|
701
|
-
behaviorOnError:
|
|
702
|
-
call.behaviorOnError === 0
|
|
703
|
-
? "ignore"
|
|
704
|
-
: call.behaviorOnError === 1
|
|
705
|
-
? "revert"
|
|
706
|
-
: "abort",
|
|
707
|
-
})),
|
|
708
|
-
},
|
|
709
|
-
)
|
|
710
|
-
|
|
711
|
-
cumulativeCallsHashBytes = Hash.keccak256(
|
|
712
|
-
Bytes.concat(cumulativeCallsHashBytes, currentDestCallPayloadHashBytes),
|
|
713
|
-
{
|
|
714
|
-
as: "Bytes",
|
|
715
|
-
},
|
|
716
|
-
)
|
|
717
|
-
}
|
|
718
|
-
const cumulativeCallsHashHex = Bytes.toHex(cumulativeCallsHashBytes)
|
|
719
|
-
|
|
720
|
-
const destinationTokensForAbi = destinationTokens.map((token) => ({
|
|
721
|
-
address: token.address,
|
|
722
|
-
chainId: token.chainId,
|
|
723
|
-
amount: token.amount,
|
|
724
|
-
}))
|
|
725
|
-
|
|
726
|
-
const abiSchema = [
|
|
727
|
-
{ type: "address" },
|
|
728
|
-
{ type: "uint256" },
|
|
729
|
-
{
|
|
730
|
-
type: "tuple[]",
|
|
731
|
-
components: [
|
|
732
|
-
{ name: "address", type: "address" },
|
|
733
|
-
{ name: "chainId", type: "uint256" },
|
|
734
|
-
],
|
|
735
|
-
},
|
|
736
|
-
{
|
|
737
|
-
type: "tuple[]",
|
|
738
|
-
components: [
|
|
739
|
-
{ name: "address", type: "address" },
|
|
740
|
-
{ name: "chainId", type: "uint256" },
|
|
741
|
-
{ name: "amount", type: "uint256" },
|
|
742
|
-
],
|
|
743
|
-
},
|
|
744
|
-
{ type: "bytes32" },
|
|
745
|
-
]
|
|
746
|
-
|
|
747
|
-
const encodedHex = AbiParameters.encode(abiSchema, [
|
|
748
|
-
userAddress,
|
|
749
|
-
nonce,
|
|
750
|
-
originTokensForAbi,
|
|
751
|
-
destinationTokensForAbi,
|
|
752
|
-
cumulativeCallsHashHex,
|
|
753
|
-
]) as Hex.Hex
|
|
754
|
-
|
|
755
|
-
const encodedBytes = Bytes.fromHex(encodedHex)
|
|
756
|
-
const hashBytes = Hash.keccak256(encodedBytes)
|
|
757
|
-
const hashHex = Bytes.toHex(hashBytes)
|
|
758
|
-
|
|
759
|
-
return hashHex
|
|
760
|
-
}
|
|
761
|
-
|
|
762
609
|
export function calculateIntentConfigurationAddress(
|
|
763
610
|
mainSigner: Address.Address,
|
|
764
611
|
calls: Array<IntentCalls>,
|
|
@@ -851,7 +698,7 @@ function createIntentConfiguration(
|
|
|
851
698
|
// Print the topology
|
|
852
699
|
logger.console.log(
|
|
853
700
|
"[trails-sdk] Topology:",
|
|
854
|
-
|
|
701
|
+
JsonEncode([mainSignerLeaf, secondaryTopologyNode]),
|
|
855
702
|
)
|
|
856
703
|
|
|
857
704
|
return {
|
|
@@ -914,19 +761,20 @@ export function buildSameChainSameTokenTransactionParams({
|
|
|
914
761
|
return {
|
|
915
762
|
to: hasCustomCalldata
|
|
916
763
|
? recipient
|
|
917
|
-
: effectiveOriginTokenAddress
|
|
764
|
+
: isNativeToken(effectiveOriginTokenAddress)
|
|
918
765
|
? recipient
|
|
919
766
|
: effectiveOriginTokenAddress,
|
|
920
767
|
data: hasCustomCalldata
|
|
921
768
|
? destinationCalldata || "0x"
|
|
922
|
-
: effectiveOriginTokenAddress
|
|
769
|
+
: isNativeToken(effectiveOriginTokenAddress)
|
|
923
770
|
? "0x"
|
|
924
771
|
: getERC20TransferData({
|
|
925
772
|
recipient,
|
|
926
773
|
amount: BigInt(swapAmount),
|
|
927
774
|
}),
|
|
928
|
-
value:
|
|
929
|
-
|
|
775
|
+
value: isNativeToken(effectiveOriginTokenAddress)
|
|
776
|
+
? BigInt(swapAmount)
|
|
777
|
+
: "0",
|
|
930
778
|
chainId: effectiveOriginChainId,
|
|
931
779
|
chain: effectiveOriginChain,
|
|
932
780
|
}
|
|
@@ -954,18 +802,16 @@ export function buildCrossChainDepositParams({
|
|
|
954
802
|
const totalAmount = BigInt(depositAmount) + BigInt(fee)
|
|
955
803
|
|
|
956
804
|
return {
|
|
957
|
-
to:
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
}),
|
|
968
|
-
value: originTokenAddress === zeroAddress ? totalAmount : "0",
|
|
805
|
+
to: isNativeToken(originTokenAddress)
|
|
806
|
+
? originIntentAddress
|
|
807
|
+
: originTokenAddress,
|
|
808
|
+
data: isNativeToken(originTokenAddress)
|
|
809
|
+
? "0x"
|
|
810
|
+
: getERC20TransferData({
|
|
811
|
+
recipient: originIntentAddress,
|
|
812
|
+
amount: totalAmount,
|
|
813
|
+
}),
|
|
814
|
+
value: isNativeToken(originTokenAddress) ? totalAmount : "0",
|
|
969
815
|
chainId: originChainId,
|
|
970
816
|
chain,
|
|
971
817
|
}
|
package/src/mutations.ts
CHANGED
|
@@ -28,8 +28,9 @@ export function useCommitIntent() {
|
|
|
28
28
|
originIntentAddress: intent.originIntentAddress,
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
-
const originChainIdStr = intent.
|
|
32
|
-
const destinationChainIdStr =
|
|
31
|
+
const originChainIdStr = intent.quoteRequest.originChainId.toString()
|
|
32
|
+
const destinationChainIdStr =
|
|
33
|
+
intent.quoteRequest.destinationChainId.toString()
|
|
33
34
|
|
|
34
35
|
try {
|
|
35
36
|
// Track intent commit start
|
package/src/paymasterSend.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Account, Chain, PublicClient, WalletClient } from "viem"
|
|
2
2
|
import {
|
|
3
|
-
createPublicClient,
|
|
4
3
|
encodeFunctionData,
|
|
5
4
|
encodePacked,
|
|
6
5
|
http,
|
|
@@ -11,6 +10,7 @@ import {
|
|
|
11
10
|
toHex,
|
|
12
11
|
zeroAddress,
|
|
13
12
|
} from "viem"
|
|
13
|
+
import { getPublicRpcClient } from "./chains.js"
|
|
14
14
|
import type { UserOperation } from "viem/account-abstraction"
|
|
15
15
|
import {
|
|
16
16
|
createBundlerClient,
|
|
@@ -194,10 +194,7 @@ export async function getPaymasterGaslessTransaction({
|
|
|
194
194
|
delegatorSmartAccount: ToSimpleSmartAccountReturnType
|
|
195
195
|
}): Promise<{ to: string; data: string; value: string }[]> {
|
|
196
196
|
// Initialize clients
|
|
197
|
-
const publicClient =
|
|
198
|
-
chain,
|
|
199
|
-
transport: http(),
|
|
200
|
-
})
|
|
197
|
+
const publicClient = getPublicRpcClient(chain)
|
|
201
198
|
|
|
202
199
|
if (!walletClient.account) {
|
|
203
200
|
throw new Error("No account found")
|
package/src/prepareSend.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { abortControllerRegistry } from "./abortController.js"
|
|
2
|
-
import { createPublicClient, http, zeroAddress } from "viem"
|
|
3
2
|
import { trackPaymentError, trackPaymentStarted } from "./analytics.js"
|
|
4
3
|
import { getSlippageToleranceValue } from "./widget/components/SlippageToleranceSettings.js"
|
|
4
|
+
import { isNativeToken } from "./utils.js"
|
|
5
5
|
import { getERC20TransferData } from "./encoders.js"
|
|
6
6
|
import { getTokenPrice } from "./prices.js"
|
|
7
7
|
import {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import type { TransactionState } from "./transactions.js"
|
|
12
12
|
import { logger } from "./logger.js"
|
|
13
13
|
import { getIsCustomCalldata } from "./contractUtils.js"
|
|
14
|
-
import { getChainInfo } from "./chains.js"
|
|
14
|
+
import { getChainInfo, getPublicRpcClient } from "./chains.js"
|
|
15
15
|
|
|
16
16
|
// Import from transactionIntent module
|
|
17
17
|
import {
|
|
@@ -33,7 +33,6 @@ export type {
|
|
|
33
33
|
PrepareSendQuote,
|
|
34
34
|
PrepareSendReturn,
|
|
35
35
|
SendReturn,
|
|
36
|
-
SelectedFeeToken,
|
|
37
36
|
} from "./transactionIntent/index.js"
|
|
38
37
|
|
|
39
38
|
// Re-export validators for backward compatibility
|
|
@@ -79,7 +78,7 @@ export async function prepareSend(
|
|
|
79
78
|
fundMethod,
|
|
80
79
|
mode,
|
|
81
80
|
checkoutOnHandlers,
|
|
82
|
-
|
|
81
|
+
selectedFeeOption,
|
|
83
82
|
walletId,
|
|
84
83
|
abortSignal,
|
|
85
84
|
commitIntentFn,
|
|
@@ -107,7 +106,7 @@ export async function prepareSend(
|
|
|
107
106
|
const transactionStates: TransactionState[] = []
|
|
108
107
|
|
|
109
108
|
// Validate recipient is not zero address
|
|
110
|
-
if (recipient
|
|
109
|
+
if (isNativeToken(recipient)) {
|
|
111
110
|
throw new Error("Recipient address cannot be zero address")
|
|
112
111
|
}
|
|
113
112
|
|
|
@@ -124,7 +123,7 @@ export async function prepareSend(
|
|
|
124
123
|
if (
|
|
125
124
|
!hasCustomCalldata &&
|
|
126
125
|
tradeType === TradeType.EXACT_INPUT &&
|
|
127
|
-
destinationTokenAddress
|
|
126
|
+
!isNativeToken(destinationTokenAddress)
|
|
128
127
|
) {
|
|
129
128
|
// we need to set custom calldata for the cctp transfer in order to have destination intent adddress execution needed for metatxn tracking
|
|
130
129
|
effectiveDestinationCalldata = getERC20TransferData({
|
|
@@ -268,10 +267,7 @@ export async function prepareSend(
|
|
|
268
267
|
logger.console.log("[trails-sdk] isToSameChain", isToSameChain)
|
|
269
268
|
logger.console.log("[trails-sdk] isToSameToken", isToSameToken)
|
|
270
269
|
|
|
271
|
-
const publicClient =
|
|
272
|
-
chain,
|
|
273
|
-
transport: http(),
|
|
274
|
-
})
|
|
270
|
+
const publicClient = getPublicRpcClient(chain)
|
|
275
271
|
|
|
276
272
|
// origin tx
|
|
277
273
|
transactionStates.push({
|
|
@@ -376,7 +372,6 @@ export async function prepareSend(
|
|
|
376
372
|
checkoutOnHandlers,
|
|
377
373
|
paymasterUrl,
|
|
378
374
|
quoteProvider,
|
|
379
|
-
selectedFeeToken,
|
|
380
375
|
walletId,
|
|
381
376
|
trailsClient,
|
|
382
377
|
mode,
|
|
@@ -384,6 +379,8 @@ export async function prepareSend(
|
|
|
384
379
|
abortSignal,
|
|
385
380
|
commitIntentFn,
|
|
386
381
|
executeIntentFn,
|
|
382
|
+
sequenceProjectAccessKey,
|
|
383
|
+
sequenceIndexerUrl,
|
|
387
384
|
})
|
|
388
385
|
}
|
|
389
386
|
|
|
@@ -420,7 +417,7 @@ export async function prepareSend(
|
|
|
420
417
|
fundMethod,
|
|
421
418
|
mode,
|
|
422
419
|
checkoutOnHandlers,
|
|
423
|
-
|
|
420
|
+
selectedFeeOption,
|
|
424
421
|
walletId,
|
|
425
422
|
abortSignal,
|
|
426
423
|
commitIntentFn,
|
package/src/sendUserOp.ts
CHANGED
|
@@ -2,19 +2,18 @@ import {
|
|
|
2
2
|
type Address,
|
|
3
3
|
type Chain,
|
|
4
4
|
concat,
|
|
5
|
-
createPublicClient,
|
|
6
5
|
createWalletClient,
|
|
7
6
|
encodeAbiParameters,
|
|
8
7
|
encodeFunctionData,
|
|
9
8
|
getAddress,
|
|
10
9
|
type Hex,
|
|
11
|
-
http,
|
|
12
10
|
keccak256,
|
|
13
11
|
pad,
|
|
14
12
|
size,
|
|
15
13
|
slice,
|
|
16
14
|
toHex,
|
|
17
15
|
} from "viem"
|
|
16
|
+
import { getHttpTransport, getPublicRpcClient } from "./chains.js"
|
|
18
17
|
import { privateKeyToAccount } from "viem/accounts"
|
|
19
18
|
import { logger } from "./logger.js"
|
|
20
19
|
|
|
@@ -187,14 +186,11 @@ export async function sendUserOperationDirectly({
|
|
|
187
186
|
|
|
188
187
|
const walletClient = createWalletClient({
|
|
189
188
|
chain: chain,
|
|
190
|
-
transport:
|
|
189
|
+
transport: getHttpTransport(chain.id),
|
|
191
190
|
account: relayerAccount,
|
|
192
191
|
})
|
|
193
192
|
|
|
194
|
-
const publicClient =
|
|
195
|
-
chain: chain,
|
|
196
|
-
transport: http(),
|
|
197
|
-
})
|
|
193
|
+
const publicClient = getPublicRpcClient(chain)
|
|
198
194
|
|
|
199
195
|
const packedOp = toPackedUserOperation(userOp) // converts to PackedUserOperation
|
|
200
196
|
|
|
@@ -467,63 +463,6 @@ export const packUserOps = (userOps: UserOperation[]) => {
|
|
|
467
463
|
return packedUserOps as PackedUserOperation[]
|
|
468
464
|
}
|
|
469
465
|
|
|
470
|
-
export type UnpackedUserOperation = {
|
|
471
|
-
sender: Address
|
|
472
|
-
nonce: bigint
|
|
473
|
-
callData: Hex
|
|
474
|
-
callGasLimit: bigint
|
|
475
|
-
factory: Address | null
|
|
476
|
-
factoryData: Hex | null
|
|
477
|
-
verificationGasLimit: bigint
|
|
478
|
-
preVerificationGas: bigint
|
|
479
|
-
maxFeePerGas: bigint
|
|
480
|
-
maxPriorityFeePerGas: bigint
|
|
481
|
-
paymaster: Address | null
|
|
482
|
-
paymasterVerificationGasLimit: bigint | null
|
|
483
|
-
paymasterPostOpGasLimit: bigint | null
|
|
484
|
-
paymasterData: Hex | null
|
|
485
|
-
signature: Hex
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
export function toUnpackedUserOperation(
|
|
489
|
-
packedUserOperation: PackedUserOperation,
|
|
490
|
-
): UnpackedUserOperation {
|
|
491
|
-
const { factory, factoryData } = unPackInitCode(packedUserOperation.initCode)
|
|
492
|
-
|
|
493
|
-
const { callGasLimit, verificationGasLimit } = unpackAccountGasLimits(
|
|
494
|
-
packedUserOperation.accountGasLimits,
|
|
495
|
-
)
|
|
496
|
-
|
|
497
|
-
const { maxFeePerGas, maxPriorityFeePerGas } = unpackGasLimits(
|
|
498
|
-
packedUserOperation.gasFees,
|
|
499
|
-
)
|
|
500
|
-
|
|
501
|
-
const {
|
|
502
|
-
paymaster,
|
|
503
|
-
paymasterVerificationGasLimit,
|
|
504
|
-
paymasterPostOpGasLimit,
|
|
505
|
-
paymasterData,
|
|
506
|
-
} = unpackPaymasterAndData(packedUserOperation.paymasterAndData)
|
|
507
|
-
|
|
508
|
-
return {
|
|
509
|
-
sender: packedUserOperation.sender,
|
|
510
|
-
nonce: packedUserOperation.nonce,
|
|
511
|
-
factory: factory,
|
|
512
|
-
factoryData: factoryData,
|
|
513
|
-
callData: packedUserOperation.callData,
|
|
514
|
-
callGasLimit: callGasLimit,
|
|
515
|
-
verificationGasLimit: verificationGasLimit,
|
|
516
|
-
preVerificationGas: packedUserOperation.preVerificationGas,
|
|
517
|
-
maxFeePerGas: maxFeePerGas,
|
|
518
|
-
maxPriorityFeePerGas: maxPriorityFeePerGas,
|
|
519
|
-
paymaster: paymaster,
|
|
520
|
-
paymasterVerificationGasLimit: paymasterVerificationGasLimit,
|
|
521
|
-
paymasterPostOpGasLimit: paymasterPostOpGasLimit,
|
|
522
|
-
paymasterData: paymasterData,
|
|
523
|
-
signature: packedUserOperation.signature,
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
466
|
export function unPackInitCode(initCode: Hex) {
|
|
528
467
|
if (initCode === "0x") {
|
|
529
468
|
return {
|
package/src/tokenBalances.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { useIndexerGatewayClient } from "./indexerClient.js"
|
|
|
17
17
|
import { getTokenPrices, useTokenPrices } from "./prices.js"
|
|
18
18
|
import { logger } from "./logger.js"
|
|
19
19
|
import { getChainInfo } from "./chains.js"
|
|
20
|
-
import { getTokenImageUrl } from "./tokens.js"
|
|
20
|
+
import { useGetTokenImageUrl, getTokenImageUrl } from "./tokens.js"
|
|
21
21
|
import type { TrailsClient } from "./trailsClient.js"
|
|
22
22
|
import { useTrailsClient } from "./trailsClient.js"
|
|
23
23
|
import { getFullErrorMessage } from "./error.js"
|
|
@@ -183,6 +183,7 @@ export function useTokenBalances(
|
|
|
183
183
|
// Always call hooks unconditionally to fix React rules violation
|
|
184
184
|
const hookIndexerClient = useIndexerGatewayClient()
|
|
185
185
|
const hookTrailsClient = useTrailsClient()
|
|
186
|
+
const { getTokenImageUrl } = useGetTokenImageUrl()
|
|
186
187
|
|
|
187
188
|
// Use passed parameters if available, otherwise use hook results
|
|
188
189
|
const indexerClient = indexerGatewayClient ?? hookIndexerClient
|