0xtrails 0.1.2 → 0.1.4
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/address.d.ts.map +1 -1
- package/dist/analytics.d.ts +86 -1
- package/dist/analytics.d.ts.map +1 -1
- package/dist/apiClient.d.ts +1 -1
- package/dist/apiClient.d.ts.map +1 -1
- package/dist/{ccip-BmFTEOaB.js → ccip-dLSEJjCf.js} +55 -55
- package/dist/cctpqueue.d.ts +1 -1
- package/dist/cctpqueue.d.ts.map +1 -1
- package/dist/chains.d.ts +9 -3
- package/dist/chains.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/decoders.d.ts +58 -0
- package/dist/decoders.d.ts.map +1 -0
- package/dist/ens.d.ts +13 -0
- package/dist/ens.d.ts.map +1 -0
- package/dist/error.d.ts +9 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/{index-BPsVj7zK.js → index-BXbaLmtt.js} +28779 -25738
- package/dist/index.js +2 -2
- package/dist/intents.d.ts +4 -4
- package/dist/intents.d.ts.map +1 -1
- package/dist/lifi.d.ts +4 -0
- package/dist/lifi.d.ts.map +1 -0
- package/dist/metaTxns.d.ts +1 -1
- package/dist/metaTxns.d.ts.map +1 -1
- package/dist/mode.d.ts +1 -1
- package/dist/mode.d.ts.map +1 -1
- package/dist/preconditions.d.ts +1 -1
- package/dist/preconditions.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +32 -24
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/prices.d.ts +3 -1
- package/dist/prices.d.ts.map +1 -1
- package/dist/proxyCaller.d.ts +0 -1
- package/dist/proxyCaller.d.ts.map +1 -1
- package/dist/relaySdk.d.ts.map +1 -1
- package/dist/relayer.d.ts.map +1 -1
- package/dist/tokenBalances.d.ts +1 -1
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/tokens.d.ts +2 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/trails.d.ts +4 -4
- package/dist/trails.d.ts.map +1 -1
- package/dist/transactions.d.ts +4 -0
- package/dist/transactions.d.ts.map +1 -1
- package/dist/utils.d.ts +6 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/wallets.d.ts +247 -5
- package/dist/wallets.d.ts.map +1 -1
- package/dist/widget/components/ChainFilterDropdown.d.ts +2 -0
- package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
- package/dist/widget/components/ConnectWallet.d.ts +1 -0
- package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
- package/dist/widget/components/DebugScreensDropdown.d.ts.map +1 -1
- package/dist/widget/components/ErrorDisplay.d.ts +9 -0
- package/dist/widget/components/ErrorDisplay.d.ts.map +1 -0
- package/dist/widget/components/FundSendForm.d.ts +2 -2
- package/dist/widget/components/FundSendForm.d.ts.map +1 -1
- package/dist/widget/components/OriginTransferInformation.d.ts +10 -0
- package/dist/widget/components/OriginTransferInformation.d.ts.map +1 -0
- package/dist/widget/components/PaySendForm.d.ts +2 -2
- package/dist/widget/components/PaySendForm.d.ts.map +1 -1
- package/dist/widget/components/QrCode.d.ts +1 -1
- 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/Receive.d.ts +12 -0
- package/dist/widget/components/Receive.d.ts.map +1 -0
- package/dist/widget/components/RefundAddressInput.d.ts +13 -0
- package/dist/widget/components/RefundAddressInput.d.ts.map +1 -0
- package/dist/widget/components/Swap.d.ts +47 -0
- package/dist/widget/components/Swap.d.ts.map +1 -0
- package/dist/widget/components/SwapDisplay.d.ts +9 -0
- package/dist/widget/components/SwapDisplay.d.ts.map +1 -0
- package/dist/widget/components/TokenList.d.ts +0 -2
- package/dist/widget/components/TokenList.d.ts.map +1 -1
- package/dist/widget/components/TokenSelector.d.ts +26 -0
- package/dist/widget/components/TokenSelector.d.ts.map +1 -0
- package/dist/widget/components/TransferPendingVertical.d.ts +2 -0
- package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
- package/dist/widget/components/WalletConnect.d.ts.map +1 -1
- package/dist/widget/components/WalletConnectionPending.d.ts +12 -0
- package/dist/widget/components/WalletConnectionPending.d.ts.map +1 -0
- package/dist/widget/components/WalletList.d.ts.map +1 -1
- package/dist/widget/components/YellowWarningAnimation.d.ts +2 -0
- package/dist/widget/components/YellowWarningAnimation.d.ts.map +1 -0
- package/dist/widget/hooks/useAmountUsd.d.ts +1 -3
- package/dist/widget/hooks/useAmountUsd.d.ts.map +1 -1
- package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
- package/dist/widget/hooks/useDebugScreens.d.ts +22 -0
- package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -0
- package/dist/widget/hooks/useSendForm.d.ts +12 -6
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenList.d.ts +2 -3
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/index.js +1 -1
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +19 -15
- package/src/aave.ts +13 -13
- package/src/address.ts +3 -0
- package/src/analytics.ts +192 -8
- package/src/apiClient.ts +1 -1
- package/src/cctpqueue.ts +1 -1
- package/src/chains.ts +45 -7
- package/src/constants.ts +7 -4
- package/src/decoders.ts +310 -0
- package/src/ens.ts +32 -0
- package/src/error.ts +101 -1
- package/src/intents.ts +10 -2
- package/src/lifi.ts +58 -0
- package/src/metaTxns.ts +1 -1
- package/src/mode.ts +1 -1
- package/src/morpho.ts +3 -3
- package/src/pools.ts +18 -18
- package/src/preconditions.ts +1 -1
- package/src/prepareSend.ts +463 -113
- package/src/prices.ts +26 -1
- package/src/proxyCaller.ts +2 -14
- package/src/relaySdk.ts +1 -0
- package/src/relayer.ts +8 -0
- package/src/tokenBalances.ts +24 -17
- package/src/tokens.ts +147 -22
- package/src/trails.ts +4 -4
- package/src/transactions.ts +35 -17
- package/src/utils.ts +28 -0
- package/src/wallets.ts +275 -35
- package/src/widget/compiled.css +2 -2
- package/src/widget/components/ChainFilterDropdown.tsx +42 -33
- package/src/widget/components/ChainImage.tsx +1 -1
- package/src/widget/components/ConnectWallet.tsx +92 -128
- package/src/widget/components/DebugScreensDropdown.tsx +6 -0
- package/src/widget/components/ErrorDisplay.tsx +150 -0
- package/src/widget/components/FundSendForm.tsx +78 -11
- package/src/widget/components/OriginTransferInformation.tsx +59 -0
- package/src/widget/components/PaySendForm.tsx +80 -13
- package/src/widget/components/QRCodeDeposit.tsx +6 -6
- package/src/widget/components/QrCode.tsx +278 -17
- package/src/widget/components/QuoteDetails.tsx +93 -25
- package/src/widget/components/Receipt.tsx +296 -103
- package/src/widget/components/Receive.tsx +146 -0
- package/src/widget/components/RecentTokens.tsx +1 -1
- package/src/widget/components/RefundAddressInput.tsx +149 -0
- package/src/widget/components/Swap.tsx +769 -0
- package/src/widget/components/SwapDisplay.tsx +68 -0
- package/src/widget/components/TokenList.tsx +27 -363
- package/src/widget/components/TokenSelector.tsx +405 -0
- package/src/widget/components/TransferPendingVertical.tsx +162 -112
- package/src/widget/components/WalletConnect.tsx +9 -7
- package/src/widget/components/WalletConnectionPending.tsx +157 -0
- package/src/widget/components/WalletList.tsx +6 -5
- package/src/widget/components/YellowWarningAnimation.tsx +146 -0
- package/src/widget/hooks/useAmountUsd.ts +3 -8
- package/src/widget/hooks/useCheckout.ts +3 -2
- package/src/widget/hooks/useDebugScreens.ts +583 -0
- package/src/widget/hooks/useSendForm.ts +111 -35
- package/src/widget/hooks/useTokenList.ts +155 -122
- package/src/widget/widget.tsx +503 -523
package/src/prepareSend.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
GetIntentCallsPayloadsReturn,
|
|
4
4
|
IntentPrecondition,
|
|
5
5
|
SequenceAPIClient,
|
|
6
|
-
} from "@0xsequence/api"
|
|
6
|
+
} from "@0xsequence/trails-api"
|
|
7
7
|
import type { Relayer } from "@0xsequence/wallet-core"
|
|
8
8
|
import type { Payload } from "@0xsequence/wallet-primitives"
|
|
9
9
|
import { useQuery } from "@tanstack/react-query"
|
|
@@ -111,7 +111,14 @@ import { getTxTimeDiff, getAccountTransactionHistory } from "./transactions.js"
|
|
|
111
111
|
import { requestWithTimeout } from "./utils.js"
|
|
112
112
|
import { InsufficientBalanceError } from "./error.js"
|
|
113
113
|
import { estimateGasCostUsd } from "./estimate.js"
|
|
114
|
-
import {
|
|
114
|
+
import {
|
|
115
|
+
decodeGuestModuleEvents,
|
|
116
|
+
decodeTrailsTokenSweeperEvents,
|
|
117
|
+
} from "./decoders.js"
|
|
118
|
+
import {
|
|
119
|
+
TRAILS_CONTRACT_PLACEHOLDER_AMOUNT,
|
|
120
|
+
wrapCalldataWithProxyCallerIfNeeded,
|
|
121
|
+
} from "./proxyCaller.js"
|
|
115
122
|
import {
|
|
116
123
|
getSequenceUseV3Relayers,
|
|
117
124
|
getSequenceEnv,
|
|
@@ -135,6 +142,7 @@ export type PrepareSendOptions = {
|
|
|
135
142
|
destinationTokenAddress: string
|
|
136
143
|
swapAmount: string
|
|
137
144
|
tradeType?: TradeType
|
|
145
|
+
originTokenSymbol: string
|
|
138
146
|
destinationTokenSymbol: string
|
|
139
147
|
sequenceProjectAccessKey?: string
|
|
140
148
|
fee: string
|
|
@@ -154,8 +162,10 @@ export type PrepareSendOptions = {
|
|
|
154
162
|
slippageTolerance?: string
|
|
155
163
|
originNativeTokenPriceUsd?: number | null
|
|
156
164
|
quoteProvider?: string | null
|
|
157
|
-
fundMethod?: string
|
|
165
|
+
fundMethod?: string
|
|
166
|
+
mode?: "pay" | "fund" | "earn" | "swap" | "receive"
|
|
158
167
|
checkoutOnHandlers?: CheckoutOnHandlers
|
|
168
|
+
refundAddress?: string
|
|
159
169
|
}
|
|
160
170
|
|
|
161
171
|
export type PrepareSendFees = {
|
|
@@ -166,7 +176,8 @@ export type PrepareSendFees = {
|
|
|
166
176
|
}
|
|
167
177
|
|
|
168
178
|
export type PrepareSendQuote = {
|
|
169
|
-
|
|
179
|
+
originDepositAddress: string
|
|
180
|
+
destinationDepositAddress: string
|
|
170
181
|
destinationAddress: string
|
|
171
182
|
destinationCalldata: string
|
|
172
183
|
originChain: Chain
|
|
@@ -338,6 +349,7 @@ export async function prepareSend(
|
|
|
338
349
|
destinationTokenAddress,
|
|
339
350
|
swapAmount,
|
|
340
351
|
tradeType = TradeType.EXACT_OUTPUT,
|
|
352
|
+
originTokenSymbol,
|
|
341
353
|
destinationTokenSymbol,
|
|
342
354
|
fee,
|
|
343
355
|
client: walletClient,
|
|
@@ -357,10 +369,11 @@ export async function prepareSend(
|
|
|
357
369
|
originNativeTokenPriceUsd,
|
|
358
370
|
quoteProvider,
|
|
359
371
|
fundMethod,
|
|
372
|
+
mode,
|
|
360
373
|
checkoutOnHandlers,
|
|
361
374
|
} = options
|
|
362
375
|
|
|
363
|
-
|
|
376
|
+
let hasCustomCalldata = getIsCustomCalldata(destinationCalldata)
|
|
364
377
|
const mainSignerAddress = account.address
|
|
365
378
|
const transactionStates: TransactionState[] = []
|
|
366
379
|
|
|
@@ -374,6 +387,20 @@ export async function prepareSend(
|
|
|
374
387
|
let effectiveDestinationAddress = recipient
|
|
375
388
|
let effectiveDestinationCalldata = destinationCalldata
|
|
376
389
|
|
|
390
|
+
if (
|
|
391
|
+
!hasCustomCalldata &&
|
|
392
|
+
quoteProvider === "cctp" &&
|
|
393
|
+
tradeType === TradeType.EXACT_INPUT
|
|
394
|
+
) {
|
|
395
|
+
// we need to set custom calldata for the cctp transfer in order to have destination intent adddress execution needed for metatxn tracking
|
|
396
|
+
effectiveDestinationCalldata = getERC20TransferData({
|
|
397
|
+
recipient,
|
|
398
|
+
amount: BigInt(TRAILS_CONTRACT_PLACEHOLDER_AMOUNT),
|
|
399
|
+
})
|
|
400
|
+
effectiveDestinationAddress = destinationTokenAddress
|
|
401
|
+
hasCustomCalldata = true
|
|
402
|
+
}
|
|
403
|
+
|
|
377
404
|
if (
|
|
378
405
|
hasCustomCalldata &&
|
|
379
406
|
destinationTokenAddress !== zeroAddress &&
|
|
@@ -403,7 +430,10 @@ export async function prepareSend(
|
|
|
403
430
|
destinationChainId,
|
|
404
431
|
originTokenAddress,
|
|
405
432
|
destinationTokenAddress,
|
|
433
|
+
destinationTokenSymbol,
|
|
406
434
|
destinationTokenAmount: swapAmount,
|
|
435
|
+
mode,
|
|
436
|
+
fundMethod,
|
|
407
437
|
})
|
|
408
438
|
|
|
409
439
|
if (originTokenBalance === "0") {
|
|
@@ -414,6 +444,13 @@ export async function prepareSend(
|
|
|
414
444
|
trackPaymentError({
|
|
415
445
|
error: "Wallet client not provided",
|
|
416
446
|
userAddress: account.address,
|
|
447
|
+
mode,
|
|
448
|
+
fundMethod,
|
|
449
|
+
originChainId,
|
|
450
|
+
destinationChainId,
|
|
451
|
+
originTokenAddress,
|
|
452
|
+
destinationTokenAddress,
|
|
453
|
+
destinationTokenSymbol,
|
|
417
454
|
})
|
|
418
455
|
throw new Error("Wallet client not provided")
|
|
419
456
|
}
|
|
@@ -423,6 +460,13 @@ export async function prepareSend(
|
|
|
423
460
|
trackPaymentError({
|
|
424
461
|
error: `Chain ${originChainId} not found`,
|
|
425
462
|
userAddress: account.address,
|
|
463
|
+
mode,
|
|
464
|
+
fundMethod,
|
|
465
|
+
originChainId,
|
|
466
|
+
destinationChainId,
|
|
467
|
+
originTokenAddress,
|
|
468
|
+
destinationTokenAddress,
|
|
469
|
+
destinationTokenSymbol,
|
|
426
470
|
})
|
|
427
471
|
throw new Error(`Chain ${originChainId} not found`)
|
|
428
472
|
}
|
|
@@ -534,6 +578,7 @@ export async function prepareSend(
|
|
|
534
578
|
destinationChainId,
|
|
535
579
|
destinationTokenAddress,
|
|
536
580
|
swapAmount,
|
|
581
|
+
originTokenSymbol,
|
|
537
582
|
destinationTokenSymbol,
|
|
538
583
|
recipient: effectiveDestinationAddress,
|
|
539
584
|
destinationCalldata: effectiveDestinationCalldata,
|
|
@@ -559,6 +604,7 @@ export async function prepareSend(
|
|
|
559
604
|
originNativeTokenPriceUsd,
|
|
560
605
|
quoteProvider,
|
|
561
606
|
fundMethod,
|
|
607
|
+
mode,
|
|
562
608
|
checkoutOnHandlers,
|
|
563
609
|
})
|
|
564
610
|
}
|
|
@@ -571,6 +617,7 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
571
617
|
destinationChainId,
|
|
572
618
|
destinationTokenAddress,
|
|
573
619
|
swapAmount,
|
|
620
|
+
originTokenSymbol,
|
|
574
621
|
destinationTokenSymbol,
|
|
575
622
|
recipient,
|
|
576
623
|
destinationCalldata,
|
|
@@ -596,6 +643,7 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
596
643
|
originNativeTokenPriceUsd,
|
|
597
644
|
quoteProvider,
|
|
598
645
|
fundMethod,
|
|
646
|
+
mode,
|
|
599
647
|
checkoutOnHandlers,
|
|
600
648
|
}: {
|
|
601
649
|
mainSignerAddress: string
|
|
@@ -605,6 +653,7 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
605
653
|
destinationChainId: number
|
|
606
654
|
destinationTokenAddress: string
|
|
607
655
|
swapAmount: string
|
|
656
|
+
originTokenSymbol: string
|
|
608
657
|
destinationTokenSymbol: string
|
|
609
658
|
recipient: string
|
|
610
659
|
destinationCalldata?: string
|
|
@@ -629,7 +678,8 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
629
678
|
tradeType: TradeType
|
|
630
679
|
originNativeTokenPriceUsd?: number | null
|
|
631
680
|
quoteProvider?: string | null
|
|
632
|
-
fundMethod?: string
|
|
681
|
+
fundMethod?: string
|
|
682
|
+
mode?: "pay" | "fund" | "earn" | "swap" | "receive"
|
|
633
683
|
checkoutOnHandlers?: CheckoutOnHandlers
|
|
634
684
|
}): Promise<PrepareSendReturn> {
|
|
635
685
|
const testnet = isTestnetDebugMode()
|
|
@@ -860,7 +910,15 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
860
910
|
|
|
861
911
|
console.log("[trails-sdk] Creating intent with args:", intentArgs)
|
|
862
912
|
|
|
863
|
-
const intent = await getIntentCallsPayloadsFromIntents(
|
|
913
|
+
const intent = await getIntentCallsPayloadsFromIntents(
|
|
914
|
+
apiClient,
|
|
915
|
+
intentArgs,
|
|
916
|
+
{
|
|
917
|
+
originTokenSymbol,
|
|
918
|
+
destinationTokenSymbol,
|
|
919
|
+
feeTokenSymbol: originTokenSymbol,
|
|
920
|
+
},
|
|
921
|
+
)
|
|
864
922
|
console.log("[trails-sdk] Got intent:", intent)
|
|
865
923
|
|
|
866
924
|
if (!intent.preconditions?.length || !intent.calls?.length) {
|
|
@@ -875,6 +933,10 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
875
933
|
mainSignerAddress,
|
|
876
934
|
intent.calls,
|
|
877
935
|
intent.preconditions,
|
|
936
|
+
{
|
|
937
|
+
originTokenSymbol,
|
|
938
|
+
destinationTokenSymbol,
|
|
939
|
+
},
|
|
878
940
|
)
|
|
879
941
|
|
|
880
942
|
const firstPrecondition = findFirstPreconditionForChainId(
|
|
@@ -948,7 +1010,8 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
948
1010
|
}
|
|
949
1011
|
|
|
950
1012
|
const quote = await getNormalizedQuoteObject({
|
|
951
|
-
|
|
1013
|
+
originDepositAddress: intentAddress,
|
|
1014
|
+
destinationDepositAddress: intent.destinationIntentAddress,
|
|
952
1015
|
destinationAddress: recipient,
|
|
953
1016
|
destinationCalldata,
|
|
954
1017
|
originAmount: depositAmount,
|
|
@@ -1037,13 +1100,38 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
1037
1100
|
|
|
1038
1101
|
console.log("[trails-sdk] testnet", testnet)
|
|
1039
1102
|
|
|
1103
|
+
const destinationPublicClient = createPublicClient({
|
|
1104
|
+
chain: getChainInfo(destinationChainId)!,
|
|
1105
|
+
transport: http(),
|
|
1106
|
+
})
|
|
1107
|
+
|
|
1040
1108
|
const depositPromise = async () => {
|
|
1109
|
+
console.log(
|
|
1110
|
+
"[trails-sdk] depositPromise called - starting deposit transaction",
|
|
1111
|
+
)
|
|
1112
|
+
console.log("[trails-sdk] fundMethod value:", fundMethod)
|
|
1113
|
+
|
|
1041
1114
|
// Skip wallet deposit if fund method is qr-code
|
|
1042
1115
|
if (fundMethod === "qr-code" || fundMethod === "exchange") {
|
|
1043
|
-
console.log(
|
|
1116
|
+
console.log(
|
|
1117
|
+
"[trails-sdk] Skipping wallet deposit for QR code mode - fundMethod is:",
|
|
1118
|
+
fundMethod,
|
|
1119
|
+
)
|
|
1044
1120
|
return
|
|
1045
1121
|
}
|
|
1046
1122
|
|
|
1123
|
+
console.log("[trails-sdk] Calling attemptUserDepositTx with params:", {
|
|
1124
|
+
originTokenAddress: effectiveOriginTokenAddress,
|
|
1125
|
+
gasless,
|
|
1126
|
+
paymasterUrl,
|
|
1127
|
+
chain: effectiveOriginChain.id,
|
|
1128
|
+
account: account.address,
|
|
1129
|
+
firstPreconditionMin,
|
|
1130
|
+
intentAddress,
|
|
1131
|
+
fee,
|
|
1132
|
+
dryMode,
|
|
1133
|
+
})
|
|
1134
|
+
|
|
1047
1135
|
originUserTxReceipt = await attemptUserDepositTx({
|
|
1048
1136
|
originTokenAddress: effectiveOriginTokenAddress,
|
|
1049
1137
|
gasless,
|
|
@@ -1066,6 +1154,8 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
1066
1154
|
onTransactionStateChange,
|
|
1067
1155
|
transactionStates,
|
|
1068
1156
|
fundMethod,
|
|
1157
|
+
originTokenSymbol,
|
|
1158
|
+
destinationTokenSymbol,
|
|
1069
1159
|
})
|
|
1070
1160
|
|
|
1071
1161
|
if (!originUserTxReceipt) {
|
|
@@ -1130,84 +1220,147 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
1130
1220
|
}
|
|
1131
1221
|
}
|
|
1132
1222
|
|
|
1133
|
-
const
|
|
1223
|
+
const _checkForDestinationDepositTx: () => Promise<TransactionReceipt | null> =
|
|
1224
|
+
async () => {
|
|
1225
|
+
while (true) {
|
|
1226
|
+
try {
|
|
1227
|
+
const response = await getAccountTransactionHistory({
|
|
1228
|
+
chainId: destinationChainId,
|
|
1229
|
+
accountAddress:
|
|
1230
|
+
intent.destinationIntentAddress as `0x${string}`,
|
|
1231
|
+
})
|
|
1232
|
+
console.log(
|
|
1233
|
+
"[trails-sdk] getAccountTransactionHistory response",
|
|
1234
|
+
response,
|
|
1235
|
+
)
|
|
1236
|
+
if (response.transactions.length > 0) {
|
|
1237
|
+
const tx = response.transactions[0]
|
|
1238
|
+
if (!tx?.txnHash) {
|
|
1239
|
+
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
1240
|
+
continue
|
|
1241
|
+
}
|
|
1242
|
+
// const isReceive = tx.transfers.some(
|
|
1243
|
+
// (transfer) => transfer.transferType === "RECEIVE",
|
|
1244
|
+
// )
|
|
1245
|
+
// if (!isReceive) {
|
|
1246
|
+
// await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
1247
|
+
// continue
|
|
1248
|
+
// }
|
|
1249
|
+
const destinationDepositTxReceipt =
|
|
1250
|
+
await destinationPublicClient.getTransactionReceipt({
|
|
1251
|
+
hash: tx.txnHash as `0x${string}`,
|
|
1252
|
+
})
|
|
1253
|
+
|
|
1254
|
+
transactionStates[2] = getTransactionStateFromReceipt(
|
|
1255
|
+
destinationDepositTxReceipt,
|
|
1256
|
+
destinationChainId,
|
|
1257
|
+
transactionStates[2]?.label,
|
|
1258
|
+
)
|
|
1259
|
+
onTransactionStateChange(transactionStates)
|
|
1260
|
+
|
|
1261
|
+
return destinationDepositTxReceipt
|
|
1262
|
+
}
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
console.error("Error checking for deposit tx", error)
|
|
1265
|
+
}
|
|
1266
|
+
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// Variables to store the waitForReceipt functions
|
|
1271
|
+
let originMetaTxnReceiptPromise:
|
|
1272
|
+
| (() => Promise<MetaTxnReceipt | null>)
|
|
1273
|
+
| null = null
|
|
1274
|
+
let destinationMetaTxnReceiptPromise:
|
|
1275
|
+
| (() => Promise<MetaTxnReceipt | null>)
|
|
1276
|
+
| (() => Promise<TransactionReceipt | null>)
|
|
1277
|
+
| null = null
|
|
1278
|
+
|
|
1279
|
+
// First phase: Send meta transactions and queue CCTP
|
|
1280
|
+
const originSendMetaTxnPromise = async () => {
|
|
1134
1281
|
if (intent.metaTxns[0] && intent.preconditions[0]) {
|
|
1135
|
-
|
|
1282
|
+
const { waitForReceipt } = await sendMetaTxAndWaitForReceipt({
|
|
1136
1283
|
metaTx: intent.metaTxns[0] as MetaTxn,
|
|
1137
1284
|
relayer: originRelayer,
|
|
1138
1285
|
precondition: intent.preconditions[0] as IntentPrecondition,
|
|
1139
1286
|
})
|
|
1140
1287
|
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
originMetaTxnReceipt,
|
|
1144
|
-
originChainId,
|
|
1145
|
-
transactionStates[1]?.label,
|
|
1146
|
-
)
|
|
1147
|
-
onTransactionStateChange(transactionStates)
|
|
1148
|
-
}
|
|
1288
|
+
// Store the waitForReceipt function for later use
|
|
1289
|
+
originMetaTxnReceiptPromise = waitForReceipt
|
|
1149
1290
|
}
|
|
1150
1291
|
}
|
|
1151
1292
|
|
|
1152
|
-
const
|
|
1293
|
+
const destinationSendMetaTxnPromise = async () => {
|
|
1153
1294
|
if (
|
|
1154
1295
|
intent.quote.quoteProvider === "relay" &&
|
|
1155
1296
|
intent.quote.quoteProviderRequestId &&
|
|
1156
1297
|
!intent.preconditions[1] &&
|
|
1157
1298
|
!intent.metaTxns[1]
|
|
1158
1299
|
) {
|
|
1159
|
-
console.log("[trails-sdk]
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
)
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
transport: http(),
|
|
1169
|
-
})
|
|
1170
|
-
const destinationTxnReceipt =
|
|
1171
|
-
await destinationPublicClient.getTransactionReceipt({
|
|
1172
|
-
hash: txHash as `0x${string}`,
|
|
1173
|
-
})
|
|
1300
|
+
console.log("[trails-sdk] Setting up relay destination promise")
|
|
1301
|
+
// For relay, we'll wait for the receipt in the wait phase
|
|
1302
|
+
// Just store the requestId for later use
|
|
1303
|
+
destinationMetaTxnReceiptPromise = async () => {
|
|
1304
|
+
console.log("[trails-sdk] waitForRelayDestinationTx")
|
|
1305
|
+
try {
|
|
1306
|
+
const txHash = await waitForRelayDestinationTx(
|
|
1307
|
+
intent.quote.quoteProviderRequestId,
|
|
1308
|
+
)
|
|
1174
1309
|
console.log(
|
|
1175
|
-
"[trails-sdk]
|
|
1176
|
-
|
|
1310
|
+
"[trails-sdk] waitForRelayDestinationTx txHash",
|
|
1311
|
+
txHash,
|
|
1177
1312
|
)
|
|
1178
|
-
if (
|
|
1179
|
-
|
|
1313
|
+
if (txHash) {
|
|
1314
|
+
const destinationTxnReceipt =
|
|
1315
|
+
await destinationPublicClient.getTransactionReceipt({
|
|
1316
|
+
hash: txHash as `0x${string}`,
|
|
1317
|
+
})
|
|
1318
|
+
console.log(
|
|
1319
|
+
"[trails-sdk] relay destinationTxnReceipt",
|
|
1180
1320
|
destinationTxnReceipt,
|
|
1181
|
-
destinationChainId,
|
|
1182
|
-
transactionStates[2]?.label,
|
|
1183
1321
|
)
|
|
1322
|
+
if (transactionStates[2]) {
|
|
1323
|
+
transactionStates[2] = getTransactionStateFromReceipt(
|
|
1324
|
+
destinationTxnReceipt,
|
|
1325
|
+
destinationChainId,
|
|
1326
|
+
transactionStates[2]?.label,
|
|
1327
|
+
)
|
|
1328
|
+
}
|
|
1329
|
+
onTransactionStateChange(transactionStates)
|
|
1330
|
+
return destinationTxnReceipt
|
|
1184
1331
|
}
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1332
|
+
} catch (error: unknown) {
|
|
1333
|
+
console.error("Error waiting for relay destination tx", error)
|
|
1334
|
+
if (transactionStates?.[2]) {
|
|
1335
|
+
transactionStates[2].state = "failed"
|
|
1336
|
+
onTransactionStateChange(transactionStates)
|
|
1337
|
+
}
|
|
1338
|
+
throw error
|
|
1192
1339
|
}
|
|
1340
|
+
return null
|
|
1193
1341
|
}
|
|
1194
1342
|
} else {
|
|
1343
|
+
console.log(
|
|
1344
|
+
"[trails-sdk] Setting up destination meta transaction promise",
|
|
1345
|
+
)
|
|
1346
|
+
console.log("[trails-sdk] intent.metaTxns[1]", intent.metaTxns[1])
|
|
1347
|
+
console.log(
|
|
1348
|
+
"[trails-sdk] intent.preconditions[1]",
|
|
1349
|
+
intent.preconditions[1],
|
|
1350
|
+
)
|
|
1195
1351
|
if (intent.metaTxns[1] && intent.preconditions[1]) {
|
|
1196
|
-
|
|
1352
|
+
const { waitForReceipt } = await sendMetaTxAndWaitForReceipt({
|
|
1197
1353
|
metaTx: intent.metaTxns[1] as MetaTxn,
|
|
1198
1354
|
relayer: destinationRelayer,
|
|
1199
1355
|
precondition: intent.preconditions[1] as IntentPrecondition,
|
|
1200
1356
|
})
|
|
1201
1357
|
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
destinationMetaTxnReceipt,
|
|
1205
|
-
destinationChainId,
|
|
1206
|
-
transactionStates?.[2]?.label,
|
|
1207
|
-
)
|
|
1208
|
-
onTransactionStateChange(transactionStates)
|
|
1209
|
-
}
|
|
1358
|
+
// Store the waitForReceipt function for later use
|
|
1359
|
+
destinationMetaTxnReceiptPromise = waitForReceipt
|
|
1210
1360
|
}
|
|
1361
|
+
// } else if (intent.destinationIntentAddress) {
|
|
1362
|
+
// destinationMetaTxnReceiptPromise = checkForDestinationDepositTx
|
|
1363
|
+
// }
|
|
1211
1364
|
}
|
|
1212
1365
|
}
|
|
1213
1366
|
|
|
@@ -1238,12 +1391,129 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
1238
1391
|
console.error("Error checking for deposit tx", error)
|
|
1239
1392
|
})
|
|
1240
1393
|
|
|
1394
|
+
// Phase 1: Send meta transactions and queue CCTP
|
|
1395
|
+
console.log(
|
|
1396
|
+
"[trails-sdk] Starting Phase 1: Sending meta transactions and queuing CCTP",
|
|
1397
|
+
)
|
|
1398
|
+
|
|
1399
|
+
await Promise.all([
|
|
1400
|
+
originSendMetaTxnPromise(),
|
|
1401
|
+
destinationSendMetaTxnPromise(),
|
|
1402
|
+
])
|
|
1403
|
+
|
|
1404
|
+
console.log("[trails-sdk] Phase 1 completed successfully")
|
|
1405
|
+
|
|
1406
|
+
// Phase 2: Wait for receipts and execute deposit
|
|
1407
|
+
console.log(
|
|
1408
|
+
"[trails-sdk] Starting Phase 2: Waiting for receipts and executing deposit",
|
|
1409
|
+
)
|
|
1410
|
+
|
|
1411
|
+
const waitForOriginMetaTxnReceiptPromise = async () => {
|
|
1412
|
+
console.log("[trails-sdk] Waiting for origin meta transaction receipt")
|
|
1413
|
+
if (originMetaTxnReceiptPromise) {
|
|
1414
|
+
try {
|
|
1415
|
+
originMetaTxnReceipt = await originMetaTxnReceiptPromise()
|
|
1416
|
+
|
|
1417
|
+
if (originMetaTxnReceipt && transactionStates[1]) {
|
|
1418
|
+
transactionStates[1] = getTransactionStateFromReceipt(
|
|
1419
|
+
originMetaTxnReceipt,
|
|
1420
|
+
originChainId,
|
|
1421
|
+
transactionStates[1]?.label,
|
|
1422
|
+
)
|
|
1423
|
+
onTransactionStateChange(transactionStates)
|
|
1424
|
+
|
|
1425
|
+
try {
|
|
1426
|
+
const receipt = await publicClient.getTransactionReceipt({
|
|
1427
|
+
hash: originMetaTxnReceipt.txnHash as `0x${string}`,
|
|
1428
|
+
})
|
|
1429
|
+
transactionStates[1].decodedTrailsTokenSweeperEvents =
|
|
1430
|
+
decodeTrailsTokenSweeperEvents(receipt)
|
|
1431
|
+
transactionStates[1].decodedGuestModuleEvents =
|
|
1432
|
+
decodeGuestModuleEvents(receipt)
|
|
1433
|
+
} catch (error) {
|
|
1434
|
+
console.error("Error decoding origin tx events", error)
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
} catch (error) {
|
|
1438
|
+
console.error(
|
|
1439
|
+
"[trails-sdk] Error waiting for origin receipt:",
|
|
1440
|
+
error,
|
|
1441
|
+
)
|
|
1442
|
+
}
|
|
1443
|
+
} else {
|
|
1444
|
+
console.log(
|
|
1445
|
+
"[trails-sdk] No origin meta transaction receipt promise to wait for",
|
|
1446
|
+
)
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
const waitForDestinationMetaTxnReceiptPromise = async () => {
|
|
1451
|
+
console.log(
|
|
1452
|
+
"[trails-sdk] Waiting for destination meta transaction receipt",
|
|
1453
|
+
)
|
|
1454
|
+
if (destinationMetaTxnReceiptPromise) {
|
|
1455
|
+
try {
|
|
1456
|
+
destinationMetaTxnReceipt =
|
|
1457
|
+
(await destinationMetaTxnReceiptPromise()) as MetaTxnReceipt
|
|
1458
|
+
|
|
1459
|
+
console.log(
|
|
1460
|
+
"[trails-sdk] destinationMetaTxnReceipt",
|
|
1461
|
+
destinationMetaTxnReceipt,
|
|
1462
|
+
)
|
|
1463
|
+
|
|
1464
|
+
if (destinationMetaTxnReceipt && transactionStates[2]) {
|
|
1465
|
+
transactionStates[2] = getTransactionStateFromReceipt(
|
|
1466
|
+
destinationMetaTxnReceipt,
|
|
1467
|
+
destinationChainId,
|
|
1468
|
+
transactionStates[2]?.label,
|
|
1469
|
+
)
|
|
1470
|
+
onTransactionStateChange(transactionStates)
|
|
1471
|
+
|
|
1472
|
+
try {
|
|
1473
|
+
const receipt =
|
|
1474
|
+
await destinationPublicClient.getTransactionReceipt({
|
|
1475
|
+
hash: destinationMetaTxnReceipt.txnHash as `0x${string}`,
|
|
1476
|
+
})
|
|
1477
|
+
transactionStates[2].decodedTrailsTokenSweeperEvents =
|
|
1478
|
+
decodeTrailsTokenSweeperEvents(receipt)
|
|
1479
|
+
transactionStates[2].decodedGuestModuleEvents =
|
|
1480
|
+
decodeGuestModuleEvents(receipt)
|
|
1481
|
+
} catch (error) {
|
|
1482
|
+
console.error("Error decoding destination tx events", error)
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
} catch (error) {
|
|
1486
|
+
console.error(
|
|
1487
|
+
"[trails-sdk] Error waiting for destination receipt:",
|
|
1488
|
+
error,
|
|
1489
|
+
)
|
|
1490
|
+
// For relay transactions, this might be expected if still waiting
|
|
1491
|
+
if (intent.quote.quoteProvider === "relay") {
|
|
1492
|
+
console.log(
|
|
1493
|
+
"[trails-sdk] Relay transaction still waiting, this is normal",
|
|
1494
|
+
)
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
} else {
|
|
1498
|
+
console.log(
|
|
1499
|
+
"[trails-sdk] No destination meta transaction receipt promise to wait for",
|
|
1500
|
+
)
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
console.log("[trails-sdk] Executing Phase 2 Promise.all with deposit")
|
|
1505
|
+
console.log(
|
|
1506
|
+
"[trails-sdk] About to call depositPromise - fundMethod is:",
|
|
1507
|
+
fundMethod,
|
|
1508
|
+
)
|
|
1509
|
+
|
|
1241
1510
|
await Promise.all([
|
|
1242
1511
|
depositPromise(),
|
|
1512
|
+
waitForOriginMetaTxnReceiptPromise(),
|
|
1513
|
+
waitForDestinationMetaTxnReceiptPromise(),
|
|
1243
1514
|
queueCctpPromise(),
|
|
1244
|
-
originMetaTxnPromise(),
|
|
1245
|
-
destinationMetaTxnPromise(),
|
|
1246
1515
|
])
|
|
1516
|
+
console.log("[trails-sdk] Phase 2 completed successfully")
|
|
1247
1517
|
|
|
1248
1518
|
// Track payment completion
|
|
1249
1519
|
if (originUserTxReceipt && destinationMetaTxnReceipt) {
|
|
@@ -1256,6 +1526,12 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
1256
1526
|
?.txnHash,
|
|
1257
1527
|
originChainId,
|
|
1258
1528
|
destinationChainId,
|
|
1529
|
+
mode,
|
|
1530
|
+
fundMethod,
|
|
1531
|
+
originTokenSymbol,
|
|
1532
|
+
originTokenAddress,
|
|
1533
|
+
destinationTokenAddress,
|
|
1534
|
+
destinationTokenSymbol,
|
|
1259
1535
|
})
|
|
1260
1536
|
|
|
1261
1537
|
// Call onCheckoutComplete callback if provided
|
|
@@ -1268,6 +1544,14 @@ async function sendHandlerForDifferentChainDifferentToken({
|
|
|
1268
1544
|
error: "Payment transactions did not complete successfully",
|
|
1269
1545
|
userAddress: account.address,
|
|
1270
1546
|
intentAddress,
|
|
1547
|
+
mode,
|
|
1548
|
+
fundMethod,
|
|
1549
|
+
originChainId,
|
|
1550
|
+
destinationChainId,
|
|
1551
|
+
originTokenSymbol,
|
|
1552
|
+
originTokenAddress,
|
|
1553
|
+
destinationTokenAddress,
|
|
1554
|
+
destinationTokenSymbol,
|
|
1271
1555
|
})
|
|
1272
1556
|
|
|
1273
1557
|
// Call onCheckoutError callback if provided
|
|
@@ -1307,6 +1591,8 @@ async function sendHandlerForSameChainSameToken({
|
|
|
1307
1591
|
originNativeTokenPriceUsd,
|
|
1308
1592
|
slippageTolerance,
|
|
1309
1593
|
checkoutOnHandlers,
|
|
1594
|
+
mode,
|
|
1595
|
+
fundMethod,
|
|
1310
1596
|
}: {
|
|
1311
1597
|
originTokenAddress: string
|
|
1312
1598
|
swapAmount: string
|
|
@@ -1325,6 +1611,8 @@ async function sendHandlerForSameChainSameToken({
|
|
|
1325
1611
|
originNativeTokenPriceUsd?: number | null
|
|
1326
1612
|
slippageTolerance?: string
|
|
1327
1613
|
checkoutOnHandlers?: CheckoutOnHandlers
|
|
1614
|
+
mode?: "pay" | "fund" | "earn" | "swap" | "receive"
|
|
1615
|
+
fundMethod?: string
|
|
1328
1616
|
}): Promise<PrepareSendReturn> {
|
|
1329
1617
|
console.log("[trails-sdk] isToSameToken && isToSameChain")
|
|
1330
1618
|
const testnet = isTestnetDebugMode()
|
|
@@ -1353,7 +1641,8 @@ async function sendHandlerForSameChainSameToken({
|
|
|
1353
1641
|
}
|
|
1354
1642
|
|
|
1355
1643
|
const quote = await getNormalizedQuoteObject({
|
|
1356
|
-
|
|
1644
|
+
originDepositAddress: recipient,
|
|
1645
|
+
destinationDepositAddress: recipient,
|
|
1357
1646
|
destinationAddress: recipient,
|
|
1358
1647
|
destinationCalldata,
|
|
1359
1648
|
originAmount: swapAmount, // fromAmount is same as toAmount for same chain same token
|
|
@@ -1490,6 +1779,7 @@ async function sendHandlerForSameChainSameToken({
|
|
|
1490
1779
|
chainId: effectiveOriginChainId,
|
|
1491
1780
|
userAddress: account.address,
|
|
1492
1781
|
blockNumber: Number(receipt.blockNumber),
|
|
1782
|
+
originTokenAddress,
|
|
1493
1783
|
})
|
|
1494
1784
|
|
|
1495
1785
|
onTransactionStateChange([
|
|
@@ -1506,11 +1796,17 @@ async function sendHandlerForSameChainSameToken({
|
|
|
1506
1796
|
userAddress: account.address,
|
|
1507
1797
|
originTxHash: originUserTxReceipt.transactionHash,
|
|
1508
1798
|
originChainId: effectiveOriginChainId, // Same chain
|
|
1799
|
+
mode,
|
|
1800
|
+
fundMethod,
|
|
1801
|
+
originTokenAddress,
|
|
1509
1802
|
})
|
|
1510
1803
|
} else if (originUserTxReceipt) {
|
|
1511
1804
|
trackPaymentError({
|
|
1512
1805
|
error: "Transaction failed",
|
|
1513
1806
|
userAddress: account.address,
|
|
1807
|
+
mode,
|
|
1808
|
+
fundMethod,
|
|
1809
|
+
originTokenAddress,
|
|
1514
1810
|
})
|
|
1515
1811
|
}
|
|
1516
1812
|
}
|
|
@@ -1543,6 +1839,10 @@ async function _sendHandlerForSameChainDifferentToken({
|
|
|
1543
1839
|
sourceTokenPriceUsd,
|
|
1544
1840
|
destinationTokenPriceUsd,
|
|
1545
1841
|
originNativeTokenPriceUsd,
|
|
1842
|
+
mode,
|
|
1843
|
+
fundMethod,
|
|
1844
|
+
originTokenSymbol,
|
|
1845
|
+
destinationTokenSymbol,
|
|
1546
1846
|
}: {
|
|
1547
1847
|
originTokenAddress: string
|
|
1548
1848
|
swapAmount: string
|
|
@@ -1560,6 +1860,10 @@ async function _sendHandlerForSameChainDifferentToken({
|
|
|
1560
1860
|
sourceTokenPriceUsd?: number | null
|
|
1561
1861
|
destinationTokenPriceUsd?: number | null
|
|
1562
1862
|
originNativeTokenPriceUsd?: number | null
|
|
1863
|
+
mode?: "pay" | "fund" | "earn" | "swap" | "receive"
|
|
1864
|
+
fundMethod?: string
|
|
1865
|
+
originTokenSymbol: string
|
|
1866
|
+
destinationTokenSymbol: string
|
|
1563
1867
|
}): Promise<PrepareSendReturn> {
|
|
1564
1868
|
const destinationTxs: { to: string; value: string; data: string }[] = []
|
|
1565
1869
|
const hasCustomCalldata = getIsCustomCalldata(destinationCalldata)
|
|
@@ -1647,7 +1951,8 @@ async function _sendHandlerForSameChainDifferentToken({
|
|
|
1647
1951
|
}
|
|
1648
1952
|
|
|
1649
1953
|
const normalizedQuote = await getNormalizedQuoteObject({
|
|
1650
|
-
|
|
1954
|
+
originDepositAddress: depositOriginAddress,
|
|
1955
|
+
destinationDepositAddress: recipient,
|
|
1651
1956
|
destinationAddress: recipient,
|
|
1652
1957
|
destinationCalldata,
|
|
1653
1958
|
originAmount: depositAmount,
|
|
@@ -1713,11 +2018,23 @@ async function _sendHandlerForSameChainDifferentToken({
|
|
|
1713
2018
|
originTxHash: originUserTxReceipt.transactionHash,
|
|
1714
2019
|
originChainId,
|
|
1715
2020
|
destinationChainId: originChainId, // Same chain
|
|
2021
|
+
mode,
|
|
2022
|
+
fundMethod,
|
|
2023
|
+
originTokenAddress,
|
|
2024
|
+
originTokenSymbol,
|
|
2025
|
+
destinationTokenAddress,
|
|
2026
|
+
destinationTokenSymbol,
|
|
1716
2027
|
})
|
|
1717
2028
|
} else if (originUserTxReceipt) {
|
|
1718
2029
|
trackPaymentError({
|
|
1719
2030
|
error: "Relay transaction failed",
|
|
1720
2031
|
userAddress: account.address,
|
|
2032
|
+
mode,
|
|
2033
|
+
fundMethod,
|
|
2034
|
+
originTokenAddress,
|
|
2035
|
+
originTokenSymbol,
|
|
2036
|
+
destinationTokenAddress,
|
|
2037
|
+
destinationTokenSymbol,
|
|
1721
2038
|
})
|
|
1722
2039
|
}
|
|
1723
2040
|
|
|
@@ -1933,6 +2250,8 @@ export async function attemptNonGaslessUserDeposit({
|
|
|
1933
2250
|
intentAddress,
|
|
1934
2251
|
onTransactionStateChange,
|
|
1935
2252
|
transactionStates,
|
|
2253
|
+
originTokenSymbol,
|
|
2254
|
+
destinationTokenSymbol,
|
|
1936
2255
|
}: {
|
|
1937
2256
|
originTokenAddress: string
|
|
1938
2257
|
firstPreconditionMin: string
|
|
@@ -1952,6 +2271,8 @@ export async function attemptNonGaslessUserDeposit({
|
|
|
1952
2271
|
intentAddress: string
|
|
1953
2272
|
onTransactionStateChange: (transactionStates: TransactionState[]) => void
|
|
1954
2273
|
transactionStates: TransactionState[]
|
|
2274
|
+
originTokenSymbol: string
|
|
2275
|
+
destinationTokenSymbol: string
|
|
1955
2276
|
}): Promise<TransactionReceipt | null> {
|
|
1956
2277
|
let originUserTxReceipt: TransactionReceipt | null = null
|
|
1957
2278
|
const usingLIfi = false
|
|
@@ -2161,6 +2482,8 @@ export async function attemptNonGaslessUserDeposit({
|
|
|
2161
2482
|
userAddress: account.address,
|
|
2162
2483
|
blockNumber: Number(receipt.blockNumber),
|
|
2163
2484
|
intentAddress,
|
|
2485
|
+
originTokenSymbol,
|
|
2486
|
+
destinationTokenSymbol,
|
|
2164
2487
|
})
|
|
2165
2488
|
|
|
2166
2489
|
console.log("[trails-sdk] receipt", receipt)
|
|
@@ -2193,6 +2516,8 @@ async function attemptUserDepositTx({
|
|
|
2193
2516
|
onTransactionStateChange,
|
|
2194
2517
|
transactionStates,
|
|
2195
2518
|
fundMethod,
|
|
2519
|
+
originTokenSymbol,
|
|
2520
|
+
destinationTokenSymbol,
|
|
2196
2521
|
}: {
|
|
2197
2522
|
originTokenAddress: string
|
|
2198
2523
|
gasless: boolean
|
|
@@ -2214,14 +2539,24 @@ async function attemptUserDepositTx({
|
|
|
2214
2539
|
fee: string
|
|
2215
2540
|
onTransactionStateChange: (transactionStates: TransactionState[]) => void
|
|
2216
2541
|
transactionStates: TransactionState[]
|
|
2217
|
-
fundMethod?: string
|
|
2542
|
+
fundMethod?: string
|
|
2543
|
+
originTokenSymbol: string
|
|
2544
|
+
destinationTokenSymbol: string
|
|
2218
2545
|
}): Promise<TransactionReceipt | null> {
|
|
2219
2546
|
let originUserTxReceipt: TransactionReceipt | null = null
|
|
2220
2547
|
const originChainId = chain.id
|
|
2221
2548
|
|
|
2549
|
+
console.log(
|
|
2550
|
+
"[trails-sdk] attemptUserDepositTx called with fundMethod:",
|
|
2551
|
+
fundMethod,
|
|
2552
|
+
)
|
|
2553
|
+
|
|
2222
2554
|
// Skip wallet deposit if fund method is qr-code
|
|
2223
2555
|
if (fundMethod === "qr-code" || fundMethod === "exchange") {
|
|
2224
|
-
console.log(
|
|
2556
|
+
console.log(
|
|
2557
|
+
"[trails-sdk] Skipping wallet deposit for QR code mode - fundMethod is:",
|
|
2558
|
+
fundMethod,
|
|
2559
|
+
)
|
|
2225
2560
|
return null
|
|
2226
2561
|
}
|
|
2227
2562
|
|
|
@@ -2266,6 +2601,8 @@ async function attemptUserDepositTx({
|
|
|
2266
2601
|
sourceTokenDecimals,
|
|
2267
2602
|
onTransactionStateChange,
|
|
2268
2603
|
transactionStates,
|
|
2604
|
+
originTokenSymbol,
|
|
2605
|
+
destinationTokenSymbol,
|
|
2269
2606
|
})
|
|
2270
2607
|
}
|
|
2271
2608
|
|
|
@@ -2318,9 +2655,10 @@ async function sendMetaTxAndWaitForReceipt({
|
|
|
2318
2655
|
metaTx: MetaTxn
|
|
2319
2656
|
relayer: Relayer.Standard.Rpc.RpcRelayer
|
|
2320
2657
|
precondition: IntentPrecondition
|
|
2321
|
-
}): Promise<
|
|
2658
|
+
}): Promise<{
|
|
2659
|
+
waitForReceipt: () => Promise<MetaTxnReceipt | null>
|
|
2660
|
+
}> {
|
|
2322
2661
|
try {
|
|
2323
|
-
let originMetaTxnReceipt: MetaTxnReceipt | null = null
|
|
2324
2662
|
console.log("[trails-sdk] metaTx", metaTx)
|
|
2325
2663
|
trackRelayerCallStarted({
|
|
2326
2664
|
walletAddress: metaTx.walletAddress as `0x${string}`,
|
|
@@ -2335,31 +2673,6 @@ async function sendMetaTxAndWaitForReceipt({
|
|
|
2335
2673
|
contractAddress: metaTx.contract as `0x${string}`,
|
|
2336
2674
|
chainId: Number(metaTx.chainId),
|
|
2337
2675
|
})
|
|
2338
|
-
|
|
2339
|
-
// eslint-disable-next-line no-constant-condition
|
|
2340
|
-
while (true) {
|
|
2341
|
-
console.log(
|
|
2342
|
-
"[trails-sdk] polling status",
|
|
2343
|
-
metaTx.id as `0x${string}`,
|
|
2344
|
-
BigInt(metaTx.chainId),
|
|
2345
|
-
)
|
|
2346
|
-
const receipt: any = await getMetaTxStatus(
|
|
2347
|
-
relayer,
|
|
2348
|
-
metaTx.id,
|
|
2349
|
-
Number(metaTx.chainId),
|
|
2350
|
-
)
|
|
2351
|
-
console.log("[trails-sdk] status", receipt)
|
|
2352
|
-
if (receipt?.transactionHash) {
|
|
2353
|
-
originMetaTxnReceipt = receipt.data?.receipt
|
|
2354
|
-
if (!originMetaTxnReceipt) {
|
|
2355
|
-
throw new Error("No meta txn receipt found")
|
|
2356
|
-
}
|
|
2357
|
-
break
|
|
2358
|
-
}
|
|
2359
|
-
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
2360
|
-
}
|
|
2361
|
-
|
|
2362
|
-
return originMetaTxnReceipt
|
|
2363
2676
|
} catch (error) {
|
|
2364
2677
|
trackRelayerCallError({
|
|
2365
2678
|
walletAddress: metaTx.walletAddress as `0x${string}`,
|
|
@@ -2369,6 +2682,37 @@ async function sendMetaTxAndWaitForReceipt({
|
|
|
2369
2682
|
})
|
|
2370
2683
|
throw error
|
|
2371
2684
|
}
|
|
2685
|
+
|
|
2686
|
+
return {
|
|
2687
|
+
waitForReceipt: async () => {
|
|
2688
|
+
let originMetaTxnReceipt: MetaTxnReceipt | null = null
|
|
2689
|
+
|
|
2690
|
+
// eslint-disable-next-line no-constant-condition
|
|
2691
|
+
while (true) {
|
|
2692
|
+
console.log(
|
|
2693
|
+
"[trails-sdk] polling status",
|
|
2694
|
+
metaTx.id as `0x${string}`,
|
|
2695
|
+
BigInt(metaTx.chainId),
|
|
2696
|
+
)
|
|
2697
|
+
const receipt: any = await getMetaTxStatus(
|
|
2698
|
+
relayer,
|
|
2699
|
+
metaTx.id,
|
|
2700
|
+
Number(metaTx.chainId),
|
|
2701
|
+
)
|
|
2702
|
+
console.log("[trails-sdk] status", receipt)
|
|
2703
|
+
if (receipt?.transactionHash) {
|
|
2704
|
+
originMetaTxnReceipt = receipt.data?.receipt
|
|
2705
|
+
if (!originMetaTxnReceipt) {
|
|
2706
|
+
throw new Error("No meta txn receipt found")
|
|
2707
|
+
}
|
|
2708
|
+
break
|
|
2709
|
+
}
|
|
2710
|
+
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
2711
|
+
}
|
|
2712
|
+
|
|
2713
|
+
return originMetaTxnReceipt
|
|
2714
|
+
},
|
|
2715
|
+
}
|
|
2372
2716
|
}
|
|
2373
2717
|
|
|
2374
2718
|
/**
|
|
@@ -2554,25 +2898,27 @@ export type QuoteProviderInfo = {
|
|
|
2554
2898
|
url: string
|
|
2555
2899
|
}
|
|
2556
2900
|
|
|
2901
|
+
export type Quote = {
|
|
2902
|
+
fromAmount: string
|
|
2903
|
+
fromAmountMin: string
|
|
2904
|
+
toAmount: string
|
|
2905
|
+
toAmountMin: string
|
|
2906
|
+
originToken: SupportedToken
|
|
2907
|
+
destinationToken: SupportedToken
|
|
2908
|
+
originChain: Chain
|
|
2909
|
+
destinationChain: Chain
|
|
2910
|
+
fees: PrepareSendFees
|
|
2911
|
+
slippageTolerance: string
|
|
2912
|
+
priceImpact: string
|
|
2913
|
+
completionEstimateSeconds: number
|
|
2914
|
+
transactionStates?: TransactionState[]
|
|
2915
|
+
originTokenRate?: string
|
|
2916
|
+
quoteProvider?: QuoteProviderInfo | null
|
|
2917
|
+
destinationTokenRate?: string
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2557
2920
|
export type UseQuoteReturn = {
|
|
2558
|
-
quote:
|
|
2559
|
-
fromAmount: string
|
|
2560
|
-
fromAmountMin: string
|
|
2561
|
-
toAmount: string
|
|
2562
|
-
toAmountMin: string
|
|
2563
|
-
originToken: SupportedToken
|
|
2564
|
-
destinationToken: SupportedToken
|
|
2565
|
-
originChain: Chain
|
|
2566
|
-
destinationChain: Chain
|
|
2567
|
-
fees: PrepareSendFees
|
|
2568
|
-
slippageTolerance: string
|
|
2569
|
-
priceImpact: string
|
|
2570
|
-
completionEstimateSeconds: number
|
|
2571
|
-
transactionStates?: TransactionState[]
|
|
2572
|
-
originTokenRate?: string
|
|
2573
|
-
quoteProvider?: QuoteProviderInfo | null
|
|
2574
|
-
destinationTokenRate?: string
|
|
2575
|
-
} | null
|
|
2921
|
+
quote: Quote | null
|
|
2576
2922
|
swap: (() => Promise<SwapReturn | null>) | null
|
|
2577
2923
|
isLoadingQuote: boolean
|
|
2578
2924
|
quoteError: unknown
|
|
@@ -2672,6 +3018,7 @@ export function useQuote({
|
|
|
2672
3018
|
const sourceTokenDecimals = originToken?.decimals ?? 18
|
|
2673
3019
|
const destinationTokenDecimals = destinationToken?.decimals ?? 18
|
|
2674
3020
|
const destinationTokenSymbol = destinationToken?.symbol ?? ""
|
|
3021
|
+
const originTokenSymbol = originToken?.symbol ?? ""
|
|
2675
3022
|
|
|
2676
3023
|
const options = {
|
|
2677
3024
|
account: walletClient.account!,
|
|
@@ -2683,6 +3030,7 @@ export function useQuote({
|
|
|
2683
3030
|
destinationTokenAddress: toTokenAddress,
|
|
2684
3031
|
swapAmount: swapAmount.toString(),
|
|
2685
3032
|
tradeType: tradeType ?? TradeType.EXACT_OUTPUT,
|
|
3033
|
+
originTokenSymbol: originTokenSymbol,
|
|
2686
3034
|
destinationTokenSymbol: destinationTokenSymbol,
|
|
2687
3035
|
client: walletClient,
|
|
2688
3036
|
apiClient,
|
|
@@ -2790,8 +3138,7 @@ export function getFeesFromIntent(
|
|
|
2790
3138
|
toAmountUsd,
|
|
2791
3139
|
}: { tradeType: TradeType; fromAmountUsd: number; toAmountUsd: number },
|
|
2792
3140
|
): PrepareSendFees {
|
|
2793
|
-
|
|
2794
|
-
const totalFeeAmountUsd = (intent?.quote as any)?.quoteProviderFeeUsd ?? 0
|
|
3141
|
+
const totalFeeAmountUsd = intent?.trailsFee?.totalFeeUSD ?? 0
|
|
2795
3142
|
const totalFeeAmountUsdDisplay = formatUsdAmountDisplay(totalFeeAmountUsd)
|
|
2796
3143
|
|
|
2797
3144
|
console.log("[trails-sdk] getFeesFromIntent", {
|
|
@@ -2895,7 +3242,8 @@ export function getIsCustomCalldata(calldata: string | undefined): boolean {
|
|
|
2895
3242
|
}
|
|
2896
3243
|
|
|
2897
3244
|
export async function getNormalizedQuoteObject({
|
|
2898
|
-
|
|
3245
|
+
originDepositAddress,
|
|
3246
|
+
destinationDepositAddress,
|
|
2899
3247
|
destinationAddress,
|
|
2900
3248
|
destinationCalldata,
|
|
2901
3249
|
originChainId,
|
|
@@ -2918,7 +3266,8 @@ export async function getNormalizedQuoteObject({
|
|
|
2918
3266
|
noSufficientBalance,
|
|
2919
3267
|
minimumNotMet,
|
|
2920
3268
|
}: {
|
|
2921
|
-
|
|
3269
|
+
originDepositAddress?: string
|
|
3270
|
+
destinationDepositAddress?: string
|
|
2922
3271
|
destinationAddress?: string
|
|
2923
3272
|
destinationCalldata?: string
|
|
2924
3273
|
originChainId: number
|
|
@@ -3094,7 +3443,8 @@ export async function getNormalizedQuoteObject({
|
|
|
3094
3443
|
const priceImpactUsdDisplay = formatUsdAmountDisplay(priceImpactUsd)
|
|
3095
3444
|
|
|
3096
3445
|
return {
|
|
3097
|
-
|
|
3446
|
+
originDepositAddress: originDepositAddress || "",
|
|
3447
|
+
destinationDepositAddress: destinationDepositAddress || "",
|
|
3098
3448
|
destinationAddress: destinationAddress || "",
|
|
3099
3449
|
destinationCalldata: hasCustomCalldata ? destinationCalldata || "" : "",
|
|
3100
3450
|
originAmount: originAmount || "0",
|