0xtrails 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aave.d.ts +8 -0
- package/dist/aave.d.ts.map +1 -1
- package/dist/abortController.d.ts +8 -0
- package/dist/abortController.d.ts.map +1 -0
- package/dist/{ccip-BlV1Mry3.js → ccip-Xjh9d1gb.js} +7 -7
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/error.d.ts +1 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/estimate.d.ts +52 -0
- package/dist/estimate.d.ts.map +1 -1
- package/dist/fees.d.ts +19 -0
- package/dist/fees.d.ts.map +1 -0
- package/dist/{index-BNWCIGfQ.js → index-BnhdZ8Ho.js} +76406 -75798
- package/dist/index.js +726 -520
- package/dist/intents.d.ts +40 -0
- package/dist/intents.d.ts.map +1 -1
- package/dist/metaTxnMonitor.d.ts +3 -3
- package/dist/metaTxnMonitor.d.ts.map +1 -1
- package/dist/metaTxns.d.ts +3 -3
- package/dist/metaTxns.d.ts.map +1 -1
- package/dist/morpho.d.ts +8 -0
- package/dist/morpho.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +19 -75
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/queryParams.d.ts.map +1 -1
- package/dist/relayer.d.ts +6 -6
- package/dist/relayer.d.ts.map +1 -1
- package/dist/sequenceWallet.d.ts +2 -2
- package/dist/sequenceWallet.d.ts.map +1 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/transactions.d.ts +4 -2
- package/dist/transactions.d.ts.map +1 -1
- package/dist/wallets.d.ts.map +1 -1
- package/dist/widget/components/AccountActionsDropdown.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts +4 -0
- package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts.map +1 -0
- package/dist/widget/components/AccountSettings.d.ts.map +1 -1
- package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts +4 -2
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
- package/dist/widget/components/ConnectedWallets.d.ts +4 -0
- package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
- package/dist/widget/components/DynamicInputStyles.d.ts +18 -0
- package/dist/widget/components/DynamicInputStyles.d.ts.map +1 -0
- package/dist/widget/components/Earn.d.ts +2 -2
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/ErrorAnimationIcon.d.ts +2 -0
- package/dist/widget/components/ErrorAnimationIcon.d.ts.map +1 -0
- package/dist/widget/components/FeeBreakdown.d.ts +9 -0
- package/dist/widget/components/FeeBreakdown.d.ts.map +1 -0
- package/dist/widget/components/Fund.d.ts +2 -2
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundMethods.d.ts.map +1 -1
- package/dist/widget/components/{FundSendForm.d.ts → FundSwap.d.ts} +13 -7
- package/dist/widget/components/FundSwap.d.ts.map +1 -0
- package/dist/widget/components/FundingMethodSelectorButton.d.ts +4 -0
- package/dist/widget/components/FundingMethodSelectorButton.d.ts.map +1 -0
- package/dist/widget/components/Identicon.d.ts.map +1 -1
- package/dist/widget/components/MeshConnectExchanges.d.ts +0 -3
- package/dist/widget/components/MeshConnectExchanges.d.ts.map +1 -1
- package/dist/widget/components/Modal.d.ts.map +1 -1
- package/dist/widget/components/Pay.d.ts +2 -2
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PercentageMaxButtons.d.ts +12 -0
- package/dist/widget/components/PercentageMaxButtons.d.ts.map +1 -0
- package/dist/widget/components/{PaySendForm.d.ts → PoolDeposit.d.ts} +14 -36
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -0
- package/dist/widget/components/{SimpleSwap.d.ts → PoolWithdraw.d.ts} +19 -10
- package/dist/widget/components/PoolWithdraw.d.ts.map +1 -0
- package/dist/widget/components/QuoteDetails.d.ts +1 -0
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/Receive.d.ts.map +1 -1
- package/dist/widget/components/RecipientSelectorButton.d.ts +4 -0
- package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -0
- package/dist/widget/components/Recipients.d.ts.map +1 -1
- package/dist/widget/components/RequiredPropsError.d.ts +8 -0
- package/dist/widget/components/RequiredPropsError.d.ts.map +1 -0
- package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
- package/dist/widget/components/SlippageToleranceSettings.d.ts.map +1 -1
- package/dist/widget/components/Swap.d.ts +3 -2
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/SwapSettings.d.ts.map +1 -1
- package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
- package/dist/widget/components/TokenDisplayNonSelectable.d.ts +11 -0
- package/dist/widget/components/TokenDisplayNonSelectable.d.ts.map +1 -0
- package/dist/widget/components/TokenImage.d.ts +1 -0
- package/dist/widget/components/TokenImage.d.ts.map +1 -1
- package/dist/widget/components/TokenList.d.ts.map +1 -1
- package/dist/widget/components/TokenSelector.d.ts.map +1 -1
- package/dist/widget/components/TokenSelectorButton.d.ts +16 -0
- package/dist/widget/components/TokenSelectorButton.d.ts.map +1 -0
- package/dist/widget/components/Tooltip.d.ts +9 -0
- package/dist/widget/components/Tooltip.d.ts.map +1 -0
- package/dist/widget/components/UserPreferences.d.ts.map +1 -1
- package/dist/widget/components/WaasFeeOptions.d.ts +9 -0
- package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -0
- package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
- package/dist/widget/components/WalletConnect.d.ts.map +1 -1
- package/dist/widget/components/WalletList.d.ts.map +1 -1
- package/dist/widget/css/compiled.css +2 -0
- package/dist/widget/css/index.css +554 -0
- package/dist/widget/hooks/useBack.d.ts +1 -0
- package/dist/widget/hooks/useBack.d.ts.map +1 -1
- package/dist/widget/hooks/useCheckout.d.ts +1 -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/useDefaultTokenSelection.d.ts +3 -3
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
- package/dist/widget/hooks/usePayMessage.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +83 -0
- package/dist/widget/hooks/useQuote.d.ts.map +1 -0
- package/dist/widget/hooks/useSelectedFundMethod.d.ts +12 -0
- package/dist/widget/hooks/useSelectedFundMethod.d.ts.map +1 -0
- package/dist/widget/hooks/useSelectedRecipient.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts +2 -2
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/index.js +2 -2
- package/dist/widget/widget.d.ts +9 -4
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +18 -12
- package/src/aave.ts +32 -0
- package/src/abortController.ts +35 -0
- package/src/config.ts +12 -4
- package/src/constants.ts +5 -0
- package/src/error.ts +19 -1
- package/src/estimate.ts +416 -5
- package/src/fees.ts +199 -0
- package/src/intents.ts +161 -11
- package/src/metaTxnMonitor.ts +3 -3
- package/src/metaTxns.ts +3 -5
- package/src/morpho.ts +32 -0
- package/src/prepareSend.ts +714 -550
- package/src/queryParams.ts +2 -1
- package/src/relayer.ts +11 -11
- package/src/sequenceWallet.ts +2 -2
- package/src/tokens.ts +7 -1
- package/src/trails.ts +3 -3
- package/src/transactions.ts +62 -18
- package/src/wallets.ts +8 -0
- package/src/widget/compiled.css +2 -2
- package/src/widget/components/AccountActionsDropdown.tsx +3 -13
- package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +22 -0
- package/src/widget/components/AccountSettings.tsx +48 -54
- package/src/widget/components/ChainFilterDropdown.tsx +24 -3
- package/src/widget/components/ClassicSwap.tsx +131 -213
- package/src/widget/components/ConnectWallet.tsx +8 -38
- package/src/widget/components/ConnectedWallets.tsx +132 -77
- package/src/widget/components/DynamicInputStyles.tsx +76 -0
- package/src/widget/components/Earn.tsx +82 -593
- package/src/widget/components/ErrorAnimationIcon.tsx +130 -0
- package/src/widget/components/FeeBreakdown.tsx +155 -0
- package/src/widget/components/Fund.tsx +41 -108
- package/src/widget/components/FundMethods.tsx +82 -159
- package/src/widget/components/FundSwap.tsx +52 -0
- package/src/widget/components/FundingMethodSelectorButton.tsx +70 -0
- package/src/widget/components/Identicon.tsx +164 -95
- package/src/widget/components/MeshConnectExchanges.tsx +2 -15
- package/src/widget/components/Modal.tsx +0 -8
- package/src/widget/components/Pay.tsx +214 -237
- package/src/widget/components/PercentageMaxButtons.tsx +77 -0
- package/src/widget/components/PoolDeposit.tsx +569 -0
- package/src/widget/components/PoolWithdraw.tsx +884 -0
- package/src/widget/components/PriceImpactWarning.tsx +1 -1
- package/src/widget/components/QuoteDetails.tsx +43 -12
- package/src/widget/components/Receipt.tsx +16 -2
- package/src/widget/components/Receive.tsx +0 -2
- package/src/widget/components/RecipientSelectorButton.tsx +44 -0
- package/src/widget/components/Recipients.tsx +63 -157
- package/src/widget/components/RequiredPropsError.tsx +33 -0
- package/src/widget/components/ScreenHeader.tsx +62 -34
- package/src/widget/components/SlippageToleranceSettings.tsx +2 -1
- package/src/widget/components/Swap.tsx +4 -45
- package/src/widget/components/SwapSettings.tsx +2 -14
- package/src/widget/components/ThemeProvider.tsx +2 -1
- package/src/widget/components/TokenDisplayNonSelectable.tsx +40 -0
- package/src/widget/components/TokenImage.tsx +22 -5
- package/src/widget/components/TokenList.tsx +0 -1
- package/src/widget/components/TokenSelector.tsx +63 -53
- package/src/widget/components/TokenSelectorButton.tsx +98 -0
- package/src/widget/components/Tooltip.tsx +51 -0
- package/src/widget/components/TransferPendingVertical.tsx +1 -1
- package/src/widget/components/UserPreferences.tsx +6 -24
- package/src/widget/components/WaasFeeOptions.tsx +450 -0
- package/src/widget/components/WalletConfirmation.tsx +76 -14
- package/src/widget/components/WalletConnect.tsx +93 -29
- package/src/widget/components/WalletList.tsx +4 -2
- package/src/widget/hooks/useBack.tsx +2 -0
- package/src/widget/hooks/useCheckout.ts +36 -20
- package/src/widget/hooks/useCurrentScreen.tsx +1 -0
- package/src/widget/hooks/useDefaultTokenSelection.tsx +104 -28
- package/src/widget/hooks/usePayMessage.tsx +86 -11
- package/src/widget/hooks/useQuote.ts +413 -0
- package/src/widget/hooks/useSelectedFundMethod.tsx +41 -0
- package/src/widget/hooks/useSelectedRecipient.tsx +10 -0
- package/src/widget/hooks/useSendForm.ts +32 -6
- package/src/widget/index.css +27 -0
- package/src/widget/widget.tsx +326 -283
- package/dist/widget/components/FundSendForm.d.ts.map +0 -1
- package/dist/widget/components/PaySendForm.d.ts.map +0 -1
- package/dist/widget/components/SimpleSwap.d.ts.map +0 -1
- package/dist/widget/hooks/useSwapSettings.d.ts +0 -16
- package/dist/widget/hooks/useSwapSettings.d.ts.map +0 -1
- package/src/widget/components/FundSendForm.tsx +0 -903
- package/src/widget/components/PaySendForm.tsx +0 -869
- package/src/widget/components/SimpleSwap.tsx +0 -983
- package/src/widget/hooks/useSwapSettings.tsx +0 -100
package/dist/index.js
CHANGED
|
@@ -1,122 +1,328 @@
|
|
|
1
|
-
import { u as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { useSwitchChain as
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { u as qn, a as Ze, b as en, c as On, d as Rn, l as t, g as Un, T as Dn, p as Fn, e as je, f as Hn, h as Fe, i as $n, j as Ge, k as Nn, m as ae, S as Qe, n as _e, q as Bn, r as Ln, s as Ce, t as jn, v as Gn, w as We } from "./index-BnhdZ8Ho.js";
|
|
2
|
+
import { U as it, ag as rt, ai as ct, C as lt, ah as dt, Y as ut, x as gt, I as mt, F as ft, A as ht, ad as pt, J as It, K as vt, B as Tt, E as Ct, X as St, ae as yt, V as At, _ as wt, a0 as bt, a6 as kt, Z as Et, ab as Pt, y as xt, P as Mt, $ as qt, af as Ot, R as Rt, a9 as Ut, W as Dt, D as Ft, ac as Ht, a2 as $t, a7 as Nt, a4 as Bt, a5 as Lt, a1 as jt, aa as Gt, a3 as Qt, a8 as _t, L as Wt, G as Vt, M as Kt, N as zt, H as Xt, z as Yt, O as Jt, Q as Zt } from "./index-BnhdZ8Ho.js";
|
|
3
|
+
import { useQuery as nn, useMutation as He } from "@tanstack/react-query";
|
|
4
|
+
import { useRef as $e, useState as d, useCallback as Ve, useEffect as F, useMemo as Qn } from "react";
|
|
5
|
+
import { zeroAddress as Ne, isAddressEqual as me, isAddress as _n, createPublicClient as Ke, http as ze, createWalletClient as Xe, custom as Ye } from "viem";
|
|
6
|
+
import { useSwitchChain as Wn, useSendTransaction as Vn, useEstimateGas as Kn, useWaitForTransactionReceipt as zn } from "wagmi";
|
|
7
|
+
function tt({
|
|
8
|
+
walletClient: K,
|
|
9
|
+
fromTokenAddress: c,
|
|
10
|
+
fromChainId: k,
|
|
11
|
+
toTokenAddress: H,
|
|
12
|
+
toChainId: P,
|
|
13
|
+
swapAmount: T,
|
|
14
|
+
tradeType: x,
|
|
15
|
+
toRecipient: q,
|
|
16
|
+
toCalldata: Z,
|
|
17
|
+
slippageTolerance: ee,
|
|
18
|
+
onStatusUpdate: z,
|
|
19
|
+
quoteProvider: ie,
|
|
20
|
+
gasless: u,
|
|
21
|
+
paymasterUrl: $,
|
|
22
|
+
selectedFeeToken: A,
|
|
23
|
+
relayerEnv: N,
|
|
24
|
+
nodeGatewayEnv: C,
|
|
25
|
+
abortSignal: O
|
|
26
|
+
} = {}) {
|
|
27
|
+
C && (globalThis.__testNodeGatewayEnv = C);
|
|
28
|
+
const h = $e(new AbortController()), X = O ? (() => {
|
|
29
|
+
const S = new AbortController();
|
|
30
|
+
return O.addEventListener("abort", () => {
|
|
31
|
+
S.abort(), h.current?.abort();
|
|
32
|
+
}), h.current?.signal.addEventListener("abort", () => {
|
|
33
|
+
S.abort();
|
|
34
|
+
}), S.signal;
|
|
35
|
+
})() : h.current.signal, I = qn(), ne = Ze(), { getRelayer: R } = en({
|
|
36
|
+
env: N || $n()
|
|
37
|
+
}), U = On(), { supportedTokens: fe } = Rn(), { data: B, isLoading: L, error: Y, refetch: Se } = nn({
|
|
38
|
+
queryKey: [
|
|
39
|
+
"quote",
|
|
40
|
+
c,
|
|
41
|
+
k,
|
|
42
|
+
H,
|
|
43
|
+
P,
|
|
44
|
+
T?.toString(),
|
|
45
|
+
q,
|
|
46
|
+
Z,
|
|
47
|
+
x,
|
|
48
|
+
ee,
|
|
49
|
+
ie
|
|
50
|
+
],
|
|
51
|
+
queryFn: async () => {
|
|
52
|
+
try {
|
|
53
|
+
if (h.current.signal.aborted && (t.console.log(
|
|
54
|
+
"[trails-sdk] Resetting aborted controller for new query"
|
|
55
|
+
), h.current = new AbortController()), !K || !I || !ne || !c || !H || !T || !q || !k || !P || !U)
|
|
56
|
+
return null;
|
|
57
|
+
const { balances: S } = await Un({
|
|
58
|
+
account: K.account.address,
|
|
59
|
+
indexerGatewayClient: U,
|
|
60
|
+
apiClient: I
|
|
61
|
+
}), J = S.find(
|
|
62
|
+
(g) => g.chainId === k && (g.contractAddress?.toLowerCase() === c.toLowerCase() || !g.contractAddress && c === Ne)
|
|
63
|
+
)?.balance ?? "0", ye = R(P), he = R(k), j = fe?.find(
|
|
64
|
+
(g) => g.contractAddress?.toLowerCase() === c?.toLowerCase() && g.chainId === k
|
|
65
|
+
), G = fe?.find(
|
|
66
|
+
(g) => g.contractAddress?.toLowerCase() === H?.toLowerCase() && g.chainId === P
|
|
67
|
+
), re = j?.decimals;
|
|
68
|
+
if (!re)
|
|
69
|
+
throw t.console.error(
|
|
70
|
+
"[trails-sdk] [useQuote] Missing source token decimals:",
|
|
71
|
+
{
|
|
72
|
+
originToken: j,
|
|
73
|
+
fromTokenAddress: c,
|
|
74
|
+
fromChainId: k
|
|
75
|
+
}
|
|
76
|
+
), new Error("Source token decimals not found");
|
|
77
|
+
const Q = G?.decimals;
|
|
78
|
+
if (!Q)
|
|
79
|
+
throw t.console.error(
|
|
80
|
+
"[trails-sdk] Missing destination token decimals:",
|
|
81
|
+
{
|
|
82
|
+
destinationToken: G,
|
|
83
|
+
toTokenAddress: H,
|
|
84
|
+
toChainId: P
|
|
85
|
+
}
|
|
86
|
+
), new Error("Destination token decimals not found");
|
|
87
|
+
const Ae = G?.symbol ?? "", we = j?.symbol ?? "", _ = {
|
|
88
|
+
account: K.account,
|
|
89
|
+
originTokenAddress: c,
|
|
90
|
+
originChainId: k,
|
|
91
|
+
originTokenBalance: J,
|
|
92
|
+
destinationChainId: P,
|
|
93
|
+
recipient: q,
|
|
94
|
+
destinationTokenAddress: H,
|
|
95
|
+
swapAmount: T.toString(),
|
|
96
|
+
tradeType: x ?? Dn.EXACT_OUTPUT,
|
|
97
|
+
originTokenSymbol: we,
|
|
98
|
+
destinationTokenSymbol: Ae,
|
|
99
|
+
destinationCalldata: Z,
|
|
100
|
+
client: K,
|
|
101
|
+
apiClient: I,
|
|
102
|
+
trailsClient: ne,
|
|
103
|
+
originRelayer: he,
|
|
104
|
+
destinationRelayer: ye,
|
|
105
|
+
sourceTokenDecimals: re,
|
|
106
|
+
destinationTokenDecimals: Q,
|
|
107
|
+
fee: "0",
|
|
108
|
+
dryMode: !1,
|
|
109
|
+
onTransactionStateChange: z ?? (() => {
|
|
110
|
+
}),
|
|
111
|
+
slippageTolerance: ee?.toString(),
|
|
112
|
+
quoteProvider: ie,
|
|
113
|
+
gasless: u ?? !1,
|
|
114
|
+
paymasterUrl: $,
|
|
115
|
+
selectedFeeToken: A ?? void 0,
|
|
116
|
+
abortSignal: X
|
|
117
|
+
};
|
|
118
|
+
t.console.log("[trails-sdk] options", _);
|
|
119
|
+
const { quote: r, send: be } = await Fn(_);
|
|
120
|
+
return {
|
|
121
|
+
quote: {
|
|
122
|
+
fromAmount: r.originAmount,
|
|
123
|
+
toAmount: r.destinationAmount,
|
|
124
|
+
fromAmountMin: r.originAmountMin,
|
|
125
|
+
toAmountMin: r.destinationAmountMin,
|
|
126
|
+
originToken: r.originToken,
|
|
127
|
+
destinationToken: r.destinationToken,
|
|
128
|
+
originChain: r.originChain,
|
|
129
|
+
destinationChain: r.destinationChain,
|
|
130
|
+
fees: r.fees,
|
|
131
|
+
priceImpact: r.priceImpact,
|
|
132
|
+
completionEstimateSeconds: r.completionEstimateSeconds,
|
|
133
|
+
slippageTolerance: r.slippageTolerance,
|
|
134
|
+
transactionStates: r.transactionStates,
|
|
135
|
+
originTokenRate: r.originTokenRate,
|
|
136
|
+
destinationTokenRate: r.destinationTokenRate,
|
|
137
|
+
quoteProvider: r.quoteProvider,
|
|
138
|
+
fromAmountUsdDisplay: r.originAmountUsdDisplay ?? void 0,
|
|
139
|
+
toAmountUsdDisplay: r.destinationAmountUsdDisplay ?? void 0,
|
|
140
|
+
gasCostUsd: r.gasCostUsd ?? void 0,
|
|
141
|
+
gasCostUsdDisplay: r.gasCostUsdDisplay ?? void 0,
|
|
142
|
+
gasCost: r.gasCost ?? void 0,
|
|
143
|
+
gasCostFormatted: r.gasCostFormatted ?? void 0
|
|
144
|
+
},
|
|
145
|
+
swap: async () => {
|
|
146
|
+
const {
|
|
147
|
+
originUserTxReceipt: g,
|
|
148
|
+
destinationMetaTxnReceipt: ce,
|
|
149
|
+
totalCompletionSeconds: W
|
|
150
|
+
} = await be({
|
|
151
|
+
selectedFeeToken: A ?? void 0
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
originTransaction: {
|
|
155
|
+
transactionHash: g?.transactionHash,
|
|
156
|
+
explorerUrl: je({
|
|
157
|
+
txHash: g?.transactionHash,
|
|
158
|
+
chainId: k
|
|
159
|
+
}),
|
|
160
|
+
receipt: g
|
|
161
|
+
},
|
|
162
|
+
destinationTransaction: {
|
|
163
|
+
transactionHash: ce?.txnHash,
|
|
164
|
+
explorerUrl: je({
|
|
165
|
+
txHash: ce?.txnHash,
|
|
166
|
+
chainId: P
|
|
167
|
+
}),
|
|
168
|
+
receipt: ce
|
|
169
|
+
},
|
|
170
|
+
totalCompletionSeconds: W
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
} catch (S) {
|
|
175
|
+
throw t.console.error(
|
|
176
|
+
"[trails-sdk] [useQuote] Error getting quote:",
|
|
177
|
+
S
|
|
178
|
+
), Hn(S);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
// Prevent unnecessary refetching
|
|
182
|
+
enabled: !!(K && I && c && H && T && q && k && P && U),
|
|
183
|
+
staleTime: 30 * 1e3,
|
|
184
|
+
// Consider data fresh for 30 seconds
|
|
185
|
+
refetchOnWindowFocus: !1,
|
|
186
|
+
// Don't refetch when window regains focus
|
|
187
|
+
refetchOnMount: !1,
|
|
188
|
+
// Don't refetch on component remount if data exists
|
|
189
|
+
refetchInterval: !1,
|
|
190
|
+
// Disable automatic polling
|
|
191
|
+
retry: 2,
|
|
192
|
+
// Limit retry attempts
|
|
193
|
+
refetchOnReconnect: !0
|
|
194
|
+
// Refetch when network reconnects
|
|
195
|
+
});
|
|
196
|
+
return {
|
|
197
|
+
quote: B?.quote || null,
|
|
198
|
+
swap: B?.swap || null,
|
|
199
|
+
isLoadingQuote: L,
|
|
200
|
+
quoteError: Y,
|
|
201
|
+
refetchQuote: () => Se(),
|
|
202
|
+
abort: () => {
|
|
203
|
+
t.console.log("[trails-sdk] useQuote abort() called"), t.console.log(
|
|
204
|
+
"[trails-sdk] Active operations before abort:",
|
|
205
|
+
Fe.getAll()
|
|
206
|
+
), h.current.abort(), Fe.abortAll(), t.console.log(
|
|
207
|
+
"[trails-sdk] Abort completed, active operations:",
|
|
208
|
+
Fe.getAll()
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const Je = 1e4;
|
|
214
|
+
function st(K) {
|
|
9
215
|
const {
|
|
10
|
-
account:
|
|
11
|
-
disableAutoExecute:
|
|
12
|
-
env:
|
|
13
|
-
sequenceProjectAccessKey:
|
|
14
|
-
} =
|
|
15
|
-
projectAccessKey:
|
|
16
|
-
}), [x,
|
|
216
|
+
account: c,
|
|
217
|
+
disableAutoExecute: k = !1,
|
|
218
|
+
env: H,
|
|
219
|
+
sequenceProjectAccessKey: P
|
|
220
|
+
} = K, T = Ze({
|
|
221
|
+
projectAccessKey: P
|
|
222
|
+
}), [x, q] = d(!k), [Z, ee] = d(!1), [z, ie] = d(
|
|
17
223
|
{}
|
|
18
|
-
), [u,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
] =
|
|
224
|
+
), [u, $] = d(null), [A, N] = d(null), [C, O] = d(null), [h, X] = d(null), [I, ne] = d(), [R, U] = d(null), [
|
|
225
|
+
fe,
|
|
226
|
+
B
|
|
227
|
+
] = d(null), [L, Y] = d(
|
|
22
228
|
null
|
|
23
|
-
), [
|
|
24
|
-
switchChain:
|
|
25
|
-
isPending:
|
|
26
|
-
error:
|
|
27
|
-
} =
|
|
28
|
-
env:
|
|
229
|
+
), [Se, S] = d(null), [o, J] = d(null), [ye, he] = d({}), [j, G] = d(!1), [re, Q] = d(!1), {
|
|
230
|
+
switchChain: Ae,
|
|
231
|
+
isPending: we,
|
|
232
|
+
error: _
|
|
233
|
+
} = Wn(), r = Vn(), [be, ke] = d(!1), [M, g] = d(null), [ce, W] = d(null), [Ee, le] = d({}), [tn, pe] = d(null), { getRelayer: Pe, relayers: sn } = en({
|
|
234
|
+
env: H
|
|
29
235
|
}), {
|
|
30
|
-
data:
|
|
31
|
-
isError:
|
|
32
|
-
error:
|
|
33
|
-
} =
|
|
34
|
-
|
|
35
|
-
to:
|
|
36
|
-
data:
|
|
37
|
-
value:
|
|
38
|
-
chainId:
|
|
236
|
+
data: Ie,
|
|
237
|
+
isError: xe,
|
|
238
|
+
error: Me
|
|
239
|
+
} = Kn(
|
|
240
|
+
o?.to && o?.chainId && !o.error ? {
|
|
241
|
+
to: o.to || void 0,
|
|
242
|
+
data: o.data || void 0,
|
|
243
|
+
value: o.value || void 0,
|
|
244
|
+
chainId: o.chainId || void 0
|
|
39
245
|
} : void 0
|
|
40
|
-
),
|
|
246
|
+
), w = He({
|
|
41
247
|
mutationFn: async (e) => {
|
|
42
248
|
if (t.console.log(
|
|
43
249
|
"[useTrails] commitIntentConfigMutation started with args:",
|
|
44
250
|
e
|
|
45
|
-
), !
|
|
251
|
+
), !T)
|
|
46
252
|
throw t.console.error("[useTrails] API client not available"), new Error("API client not available");
|
|
47
253
|
if (!e.quoteProvider)
|
|
48
254
|
throw t.console.error("[useTrails] quoteProvider is required"), new Error("quoteProvider is required");
|
|
49
255
|
try {
|
|
50
256
|
t.console.log("[useTrails] Calculating intent address..."), t.console.log("[useTrails] Main signer:", e.mainSignerAddress), t.console.log("[useTrails] Calls:", e.calls);
|
|
51
|
-
const n =
|
|
257
|
+
const n = f.variables?.params.originChainId, a = f.variables?.params.destinationChainId;
|
|
52
258
|
if (!n || !a)
|
|
53
259
|
throw t.console.error(
|
|
54
260
|
"[useTrails] Could not determine origin/destination chain IDs for verification."
|
|
55
261
|
), new Error(
|
|
56
262
|
"Could not determine origin/destination chain IDs for verification."
|
|
57
263
|
);
|
|
58
|
-
const { originIntentAddress:
|
|
264
|
+
const { originIntentAddress: m, destinationIntentAddress: s } = Ge(
|
|
59
265
|
e.mainSignerAddress,
|
|
60
266
|
e.calls
|
|
61
267
|
), {
|
|
62
|
-
originAddress:
|
|
63
|
-
destinationAddress:
|
|
64
|
-
} =
|
|
268
|
+
originAddress: l,
|
|
269
|
+
destinationAddress: v
|
|
270
|
+
} = Nn(
|
|
65
271
|
e.preconditions,
|
|
66
272
|
n,
|
|
67
273
|
a
|
|
68
274
|
);
|
|
69
275
|
t.console.log("[useTrails] Verification addresses:", {
|
|
70
|
-
calculatedOrigin:
|
|
276
|
+
calculatedOrigin: m.toString(),
|
|
71
277
|
calculatedDestination: s.toString(),
|
|
72
|
-
preconditionOrigin:
|
|
73
|
-
preconditionDestination:
|
|
278
|
+
preconditionOrigin: l,
|
|
279
|
+
preconditionDestination: v
|
|
74
280
|
});
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
281
|
+
const p = !!l && me(
|
|
282
|
+
ae(l),
|
|
283
|
+
m
|
|
78
284
|
);
|
|
79
|
-
t.console.log("[useTrails] Origin verified:",
|
|
80
|
-
const
|
|
81
|
-
|
|
285
|
+
t.console.log("[useTrails] Origin verified:", p);
|
|
286
|
+
const i = v && me(
|
|
287
|
+
ae(v),
|
|
82
288
|
s
|
|
83
|
-
) || !
|
|
289
|
+
) || !v && n === a && me(s, Ne);
|
|
84
290
|
t.console.log(
|
|
85
291
|
"[useTrails] Destination verified:",
|
|
86
|
-
|
|
292
|
+
i
|
|
87
293
|
);
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
90
|
-
success:
|
|
91
|
-
receivedOriginAddress:
|
|
92
|
-
receivedDestinationAddress:
|
|
93
|
-
calculatedOriginAddress:
|
|
294
|
+
const y = p && i;
|
|
295
|
+
if (pe({
|
|
296
|
+
success: y,
|
|
297
|
+
receivedOriginAddress: l,
|
|
298
|
+
receivedDestinationAddress: v,
|
|
299
|
+
calculatedOriginAddress: m.toString(),
|
|
94
300
|
calculatedDestinationAddress: s.toString()
|
|
95
|
-
}), !
|
|
301
|
+
}), !y)
|
|
96
302
|
throw t.console.error("[useTrails] Address verification failed.", {
|
|
97
|
-
isOriginVerified:
|
|
98
|
-
isDestinationVerified:
|
|
303
|
+
isOriginVerified: p,
|
|
304
|
+
isDestinationVerified: i
|
|
99
305
|
}), new Error(
|
|
100
|
-
`Address verification failed. Origin verified: ${
|
|
306
|
+
`Address verification failed. Origin verified: ${p}, Destination verified: ${i}`
|
|
101
307
|
);
|
|
102
308
|
t.console.log("[useTrails] Committing intent config to API...");
|
|
103
|
-
const
|
|
309
|
+
const b = await T.commitIntentConfig({
|
|
104
310
|
params: {
|
|
105
|
-
originIntentAddress:
|
|
311
|
+
originIntentAddress: m.toString(),
|
|
106
312
|
destinationIntentAddress: s.toString(),
|
|
107
313
|
mainSigner: e.mainSignerAddress,
|
|
108
314
|
calls: e.calls,
|
|
109
315
|
preconditions: e.preconditions,
|
|
110
316
|
addressOverrides: {
|
|
111
|
-
...
|
|
317
|
+
...Qe,
|
|
112
318
|
...e.addressOverrides
|
|
113
319
|
}
|
|
114
320
|
}
|
|
115
321
|
});
|
|
116
|
-
return t.console.log("[useTrails] API Commit Response:",
|
|
117
|
-
originIntentAddress:
|
|
322
|
+
return t.console.log("[useTrails] API Commit Response:", b), {
|
|
323
|
+
originIntentAddress: m.toString(),
|
|
118
324
|
destinationIntentAddress: s.toString(),
|
|
119
|
-
response:
|
|
325
|
+
response: b
|
|
120
326
|
};
|
|
121
327
|
} catch (n) {
|
|
122
328
|
throw console.error("[useTrails] Error during commit intent mutation:", n), n;
|
|
@@ -129,96 +335,96 @@ function Qn(Be) {
|
|
|
129
335
|
), t.console.log(
|
|
130
336
|
"[useTrails] Setting committedOriginIntentAddress:",
|
|
131
337
|
e.originIntentAddress
|
|
132
|
-
),
|
|
338
|
+
), U(e.originIntentAddress), B(e.destinationIntentAddress);
|
|
133
339
|
},
|
|
134
340
|
onError: (e) => {
|
|
135
|
-
t.console.error("[useTrails] Failed to commit intent config:", e),
|
|
341
|
+
t.console.error("[useTrails] Failed to commit intent config:", e), U(null), B(null);
|
|
136
342
|
}
|
|
137
343
|
}), {
|
|
138
|
-
data:
|
|
139
|
-
isLoading:
|
|
140
|
-
error:
|
|
141
|
-
} =
|
|
142
|
-
queryKey: ["getIntentConfig",
|
|
344
|
+
data: on,
|
|
345
|
+
isLoading: an,
|
|
346
|
+
error: rn
|
|
347
|
+
} = nn({
|
|
348
|
+
queryKey: ["getIntentConfig", R],
|
|
143
349
|
queryFn: async () => {
|
|
144
|
-
if (!
|
|
350
|
+
if (!T || !R)
|
|
145
351
|
throw new Error("API client or committed intent address not available");
|
|
146
352
|
return t.console.log(
|
|
147
353
|
"Fetching intent config for address:",
|
|
148
|
-
|
|
149
|
-
), await
|
|
150
|
-
intentAddress:
|
|
354
|
+
R
|
|
355
|
+
), await T.getIntentConfig({
|
|
356
|
+
intentAddress: R
|
|
151
357
|
});
|
|
152
358
|
},
|
|
153
|
-
enabled:
|
|
359
|
+
enabled: !!R && !!T && w.isSuccess,
|
|
154
360
|
staleTime: 1e3 * 60 * 5,
|
|
155
361
|
// 5 minutes
|
|
156
362
|
retry: 1
|
|
157
363
|
});
|
|
158
|
-
async function
|
|
159
|
-
return
|
|
364
|
+
async function Be(e) {
|
|
365
|
+
return Gn(T, {
|
|
160
366
|
params: {
|
|
161
367
|
...e.params,
|
|
162
368
|
addressOverrides: {
|
|
163
|
-
...
|
|
369
|
+
...Qe,
|
|
164
370
|
...e.params.addressOverrides
|
|
165
371
|
}
|
|
166
372
|
}
|
|
167
373
|
});
|
|
168
374
|
}
|
|
169
|
-
const
|
|
375
|
+
const f = He({
|
|
170
376
|
mutationFn: async (e) => {
|
|
171
|
-
if (e.params.originChainId === e.params.destinationChainId &&
|
|
172
|
-
|
|
173
|
-
|
|
377
|
+
if (e.params.originChainId === e.params.destinationChainId && me(
|
|
378
|
+
ae(e.params.originTokenAddress),
|
|
379
|
+
ae(e.params.destinationTokenAddress)
|
|
174
380
|
))
|
|
175
381
|
throw new Error(
|
|
176
382
|
"The same token cannot be used as both the source and destination token."
|
|
177
383
|
);
|
|
178
|
-
if (!
|
|
384
|
+
if (!c.address)
|
|
179
385
|
throw new Error("Missing selected token or account address");
|
|
180
|
-
|
|
181
|
-
const n = await
|
|
182
|
-
return
|
|
386
|
+
U(null), B(null), pe(null), X(null), $(null), N(null), O(null), Y(null), S(null);
|
|
387
|
+
const n = await Be(e);
|
|
388
|
+
return $(n.payloads.metaTxns), N(n.payloads.calls), O(n.payloads.preconditions), X(n.payloads.trailsFee), Y(n.payloads.originIntentAddress), S(n.payloads.destinationIntentAddress), U(null), B(null), pe(null), n;
|
|
183
389
|
},
|
|
184
390
|
onSuccess: (e) => {
|
|
185
|
-
t.console.log("Intent Config Success:", e),
|
|
391
|
+
t.console.log("Intent Config Success:", e), X(e.payloads.trailsFee || null), Y(e.payloads.originIntentAddress), S(e.payloads.destinationIntentAddress), e.payloads?.calls && e.payloads.calls.length > 0 && e.payloads.preconditions && e.payloads.preconditions.length > 0 && e.payloads.metaTxns && e.payloads.metaTxns.length > 0 ? (N(e.payloads.calls), O(e.payloads.preconditions), $(e.payloads.metaTxns)) : (t.console.warn("API returned success but no operations found."), N(null), O(null), $(null));
|
|
186
392
|
},
|
|
187
393
|
onError: (e) => {
|
|
188
|
-
console.error("Intent Config Error:", e),
|
|
394
|
+
console.error("Intent Config Error:", e), N(null), O(null), $(null), X(null), Y(null), S(null);
|
|
189
395
|
}
|
|
190
396
|
});
|
|
191
|
-
function
|
|
192
|
-
|
|
397
|
+
function cn(e) {
|
|
398
|
+
f.mutate(e);
|
|
193
399
|
}
|
|
194
|
-
const
|
|
195
|
-
t.console.log("[Trails] Clearing intent state"),
|
|
196
|
-
}, []),
|
|
197
|
-
(e, n, a,
|
|
198
|
-
|
|
400
|
+
const ln = Ve(() => {
|
|
401
|
+
t.console.log("[Trails] Clearing intent state"), N(null), O(null), $(null), X(null), U(null), B(null), pe(null), Y(null), S(null), he({}), ee(!1), le({});
|
|
402
|
+
}, []), D = Ve(
|
|
403
|
+
(e, n, a, m, s) => {
|
|
404
|
+
g({
|
|
199
405
|
txnHash: e,
|
|
200
406
|
status: n === "success" ? "Success" : n === "reverted" ? "Failed" : n === "sending" ? "Sending..." : "Pending",
|
|
201
407
|
revertReason: n === "reverted" ? s || "Transaction reverted" : void 0,
|
|
202
408
|
gasUsed: a ? Number(a) : void 0,
|
|
203
|
-
effectiveGasPrice:
|
|
409
|
+
effectiveGasPrice: m?.toString()
|
|
204
410
|
});
|
|
205
411
|
},
|
|
206
412
|
[]
|
|
207
|
-
),
|
|
413
|
+
), dn = async () => {
|
|
208
414
|
if (t.console.log("Sending origin transaction..."), t.console.log(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
),
|
|
217
|
-
!
|
|
415
|
+
j,
|
|
416
|
+
o,
|
|
417
|
+
o?.error,
|
|
418
|
+
o?.to,
|
|
419
|
+
o?.data,
|
|
420
|
+
o?.value,
|
|
421
|
+
o?.chainId
|
|
422
|
+
), j || // Prevent duplicate transactions
|
|
423
|
+
!o || o.error || !o.to || o.data === null || o.value === null || o.chainId === null) {
|
|
218
424
|
t.console.error(
|
|
219
425
|
"Origin call parameters not available or invalid:",
|
|
220
|
-
|
|
221
|
-
),
|
|
426
|
+
o
|
|
427
|
+
), D(
|
|
222
428
|
void 0,
|
|
223
429
|
"reverted",
|
|
224
430
|
void 0,
|
|
@@ -227,102 +433,102 @@ function Qn(Be) {
|
|
|
227
433
|
);
|
|
228
434
|
return;
|
|
229
435
|
}
|
|
230
|
-
if (
|
|
231
|
-
|
|
436
|
+
if (c.chainId !== o.chainId) {
|
|
437
|
+
Q(!0), D(
|
|
232
438
|
void 0,
|
|
233
439
|
"pending",
|
|
234
440
|
void 0,
|
|
235
441
|
void 0,
|
|
236
|
-
`Switching to chain ${
|
|
442
|
+
`Switching to chain ${o.chainId}...`
|
|
237
443
|
);
|
|
238
|
-
const e =
|
|
239
|
-
chain:
|
|
240
|
-
transport:
|
|
444
|
+
const e = Xe({
|
|
445
|
+
chain: Ce(o.chainId),
|
|
446
|
+
transport: Ye(await c.connector.getProvider())
|
|
241
447
|
// TODO: Add proper type
|
|
242
448
|
});
|
|
243
449
|
try {
|
|
244
|
-
await
|
|
450
|
+
await We({
|
|
245
451
|
walletClient: e,
|
|
246
|
-
desiredChainId:
|
|
247
|
-
}),
|
|
452
|
+
desiredChainId: o.chainId
|
|
453
|
+
}), Q(!1);
|
|
248
454
|
} catch (n) {
|
|
249
|
-
t.console.error("Chain switch failed:", n), n instanceof Error && n.message.includes("User rejected") &&
|
|
455
|
+
t.console.error("Chain switch failed:", n), n instanceof Error && n.message.includes("User rejected") && q(!1), D(
|
|
250
456
|
void 0,
|
|
251
457
|
"reverted",
|
|
252
458
|
void 0,
|
|
253
459
|
void 0,
|
|
254
460
|
n instanceof Error ? n.message : "Unknown error switching chain"
|
|
255
|
-
),
|
|
461
|
+
), Q(!1);
|
|
256
462
|
return;
|
|
257
463
|
}
|
|
258
464
|
}
|
|
259
|
-
if (
|
|
465
|
+
if (j)
|
|
260
466
|
t.console.warn(
|
|
261
467
|
"Transaction already in progress. Skipping duplicate request."
|
|
262
468
|
);
|
|
263
469
|
else {
|
|
264
|
-
if (
|
|
470
|
+
if (G(!0), ne(void 0), D(void 0, "sending"), !Ie && !xe) {
|
|
265
471
|
ke(!0);
|
|
266
472
|
return;
|
|
267
473
|
}
|
|
268
|
-
if (
|
|
269
|
-
t.console.error("Gas estimation failed:",
|
|
474
|
+
if (xe) {
|
|
475
|
+
t.console.error("Gas estimation failed:", Me), D(
|
|
270
476
|
void 0,
|
|
271
477
|
"reverted",
|
|
272
478
|
void 0,
|
|
273
479
|
void 0,
|
|
274
|
-
`Gas estimation failed: ${
|
|
275
|
-
),
|
|
480
|
+
`Gas estimation failed: ${Me?.message}`
|
|
481
|
+
), G(!1);
|
|
276
482
|
return;
|
|
277
483
|
}
|
|
278
|
-
const e =
|
|
279
|
-
|
|
484
|
+
const e = Ie ? BigInt(Math.floor(Number(Ie) * 1.2)) : void 0;
|
|
485
|
+
r.sendTransaction(
|
|
280
486
|
{
|
|
281
|
-
to:
|
|
282
|
-
data:
|
|
283
|
-
value:
|
|
284
|
-
chainId:
|
|
487
|
+
to: o.to,
|
|
488
|
+
data: o.data,
|
|
489
|
+
value: o.value,
|
|
490
|
+
chainId: o.chainId,
|
|
285
491
|
gas: e
|
|
286
492
|
},
|
|
287
493
|
{
|
|
288
494
|
onSuccess: (n) => {
|
|
289
|
-
t.console.log("Transaction sent, hash:", n),
|
|
495
|
+
t.console.log("Transaction sent, hash:", n), ne(n), G(!1);
|
|
290
496
|
},
|
|
291
497
|
onError: (n) => {
|
|
292
|
-
t.console.error("Transaction failed:", n), n instanceof Error && (n.message.includes("User rejected") || n.message.includes("user rejected")) &&
|
|
498
|
+
t.console.error("Transaction failed:", n), n instanceof Error && (n.message.includes("User rejected") || n.message.includes("user rejected")) && q(!1), D(
|
|
293
499
|
void 0,
|
|
294
500
|
"reverted",
|
|
295
501
|
void 0,
|
|
296
502
|
void 0,
|
|
297
503
|
n instanceof Error ? n.message : "Unknown error"
|
|
298
|
-
),
|
|
504
|
+
), G(!1);
|
|
299
505
|
}
|
|
300
506
|
}
|
|
301
507
|
);
|
|
302
508
|
}
|
|
303
509
|
};
|
|
304
|
-
|
|
305
|
-
|
|
510
|
+
F(() => {
|
|
511
|
+
_ && (t.console.error("Chain switch error:", _), D(
|
|
306
512
|
void 0,
|
|
307
513
|
"reverted",
|
|
308
514
|
void 0,
|
|
309
515
|
void 0,
|
|
310
|
-
`Chain switch failed: ${
|
|
311
|
-
),
|
|
312
|
-
}, [
|
|
516
|
+
`Chain switch failed: ${_.message || "Unknown error"}`
|
|
517
|
+
), Q(!1));
|
|
518
|
+
}, [_, D]), F(() => {
|
|
313
519
|
ke(!1);
|
|
314
|
-
}, []),
|
|
315
|
-
|
|
316
|
-
}, [
|
|
317
|
-
if (
|
|
520
|
+
}, []), F(() => {
|
|
521
|
+
o?.chainId && c.chainId === o.chainId && (t.console.log("No chain switch required"), Q(!1));
|
|
522
|
+
}, [c.chainId, o?.chainId]), F(() => {
|
|
523
|
+
if (o?.chainId && c.chainId !== o.chainId) {
|
|
318
524
|
async function e() {
|
|
319
525
|
try {
|
|
320
|
-
const n =
|
|
321
|
-
chain:
|
|
322
|
-
transport:
|
|
526
|
+
const n = o.chainId, a = Xe({
|
|
527
|
+
chain: Ce(n),
|
|
528
|
+
transport: Ye(await c.connector.getProvider())
|
|
323
529
|
// TODO: Add proper type
|
|
324
530
|
});
|
|
325
|
-
await
|
|
531
|
+
await We({
|
|
326
532
|
walletClient: a,
|
|
327
533
|
desiredChainId: n
|
|
328
534
|
});
|
|
@@ -332,159 +538,159 @@ function Qn(Be) {
|
|
|
332
538
|
}
|
|
333
539
|
e().catch(t.console.error);
|
|
334
540
|
}
|
|
335
|
-
}, [
|
|
541
|
+
}, [c, o]);
|
|
336
542
|
const {
|
|
337
|
-
data:
|
|
338
|
-
isLoading:
|
|
339
|
-
isSuccess:
|
|
340
|
-
isError:
|
|
341
|
-
error:
|
|
342
|
-
} =
|
|
343
|
-
hash:
|
|
543
|
+
data: E,
|
|
544
|
+
isLoading: te,
|
|
545
|
+
isSuccess: qe,
|
|
546
|
+
isError: Oe,
|
|
547
|
+
error: ve
|
|
548
|
+
} = zn({
|
|
549
|
+
hash: I,
|
|
344
550
|
confirmations: 1,
|
|
345
551
|
query: {
|
|
346
|
-
enabled: !!
|
|
552
|
+
enabled: !!I
|
|
347
553
|
}
|
|
348
554
|
});
|
|
349
|
-
|
|
350
|
-
if (!
|
|
351
|
-
|
|
555
|
+
F(() => {
|
|
556
|
+
if (!I) {
|
|
557
|
+
M?.txnHash && g(null), W(null), Object.keys(z).length > 0 && ie({});
|
|
352
558
|
return;
|
|
353
559
|
}
|
|
354
|
-
if (!(
|
|
355
|
-
if (
|
|
356
|
-
|
|
357
|
-
...e?.txnHash ===
|
|
560
|
+
if (!(M?.txnHash === I && (M?.status === "Success" || M?.status === "Failed") && !te)) {
|
|
561
|
+
if (te) {
|
|
562
|
+
g((e) => ({
|
|
563
|
+
...e?.txnHash === I ? e : {
|
|
358
564
|
gasUsed: void 0,
|
|
359
565
|
effectiveGasPrice: void 0,
|
|
360
566
|
revertReason: void 0
|
|
361
567
|
},
|
|
362
|
-
txnHash:
|
|
568
|
+
txnHash: I,
|
|
363
569
|
status: "Pending"
|
|
364
570
|
}));
|
|
365
571
|
return;
|
|
366
572
|
}
|
|
367
|
-
if (
|
|
368
|
-
const e =
|
|
369
|
-
|
|
370
|
-
txnHash:
|
|
573
|
+
if (qe && E) {
|
|
574
|
+
const e = E.status === "success" ? "Success" : "Failed";
|
|
575
|
+
g({
|
|
576
|
+
txnHash: E.transactionHash,
|
|
371
577
|
status: e,
|
|
372
|
-
gasUsed:
|
|
373
|
-
effectiveGasPrice:
|
|
374
|
-
revertReason:
|
|
375
|
-
}), e === "Success" &&
|
|
578
|
+
gasUsed: E.gasUsed ? Number(E.gasUsed) : void 0,
|
|
579
|
+
effectiveGasPrice: E.effectiveGasPrice?.toString(),
|
|
580
|
+
revertReason: E.status === "reverted" ? ve?.message || "Transaction reverted by receipt" : void 0
|
|
581
|
+
}), e === "Success" && E.blockNumber ? (async () => {
|
|
376
582
|
try {
|
|
377
|
-
if (!
|
|
583
|
+
if (!o?.chainId) {
|
|
378
584
|
t.console.error(
|
|
379
585
|
"[Trails] Origin chainId not available for fetching origin block timestamp."
|
|
380
|
-
),
|
|
586
|
+
), W(null);
|
|
381
587
|
return;
|
|
382
588
|
}
|
|
383
|
-
const a =
|
|
589
|
+
const a = Ce(o.chainId), s = await Ke({
|
|
384
590
|
chain: a,
|
|
385
|
-
transport:
|
|
591
|
+
transport: ze()
|
|
386
592
|
}).getBlock({
|
|
387
|
-
blockNumber: BigInt(
|
|
593
|
+
blockNumber: BigInt(E.blockNumber)
|
|
388
594
|
});
|
|
389
|
-
|
|
595
|
+
W(Number(s.timestamp));
|
|
390
596
|
} catch (a) {
|
|
391
597
|
t.console.error(
|
|
392
598
|
"[Trails] Error fetching origin block timestamp:",
|
|
393
599
|
a
|
|
394
|
-
),
|
|
600
|
+
), W(null);
|
|
395
601
|
}
|
|
396
|
-
})() : e !== "Success" &&
|
|
602
|
+
})() : e !== "Success" && W(null), e === "Success" && u && u.length > 0 && x && !u.some((n) => z[`${n.chainId}-${n.id}`]) && (t.console.log(
|
|
397
603
|
"Origin transaction successful, auto-sending all meta transactions..."
|
|
398
|
-
),
|
|
399
|
-
} else
|
|
400
|
-
txnHash:
|
|
604
|
+
), se.mutate({ selectedId: null }));
|
|
605
|
+
} else Oe && (g({
|
|
606
|
+
txnHash: I,
|
|
401
607
|
status: "Failed",
|
|
402
|
-
revertReason:
|
|
608
|
+
revertReason: ve?.message || "Failed to get receipt",
|
|
403
609
|
gasUsed: void 0,
|
|
404
610
|
effectiveGasPrice: void 0
|
|
405
|
-
}),
|
|
611
|
+
}), W(null));
|
|
406
612
|
}
|
|
407
613
|
}, [
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
614
|
+
I,
|
|
615
|
+
te,
|
|
616
|
+
qe,
|
|
617
|
+
Oe,
|
|
618
|
+
E,
|
|
619
|
+
ve,
|
|
414
620
|
u,
|
|
415
|
-
|
|
621
|
+
z,
|
|
416
622
|
x,
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
]),
|
|
421
|
-
x &&
|
|
623
|
+
o?.chainId,
|
|
624
|
+
M?.status,
|
|
625
|
+
M?.txnHash
|
|
626
|
+
]), F(() => {
|
|
627
|
+
x && w.isSuccess && o?.chainId && c.chainId === o.chainId && !o.error && o.to && o.data !== null && o.value !== null && !r.isPending && !te && !I && !re && !M && !Z && (t.console.log("Auto-executing transaction: All conditions met."), ee(!0), g({
|
|
422
628
|
status: "Sending..."
|
|
423
|
-
}),
|
|
629
|
+
}), r.sendTransaction(
|
|
424
630
|
{
|
|
425
|
-
to:
|
|
426
|
-
data:
|
|
427
|
-
value:
|
|
428
|
-
chainId:
|
|
631
|
+
to: o.to,
|
|
632
|
+
data: o.data,
|
|
633
|
+
value: o.value,
|
|
634
|
+
chainId: o.chainId
|
|
429
635
|
},
|
|
430
636
|
{
|
|
431
637
|
onSuccess: (n) => {
|
|
432
|
-
t.console.log("Auto-executed transaction sent, hash:", n),
|
|
638
|
+
t.console.log("Auto-executed transaction sent, hash:", n), ne(n);
|
|
433
639
|
},
|
|
434
640
|
onError: (n) => {
|
|
435
|
-
t.console.error("Auto-executed transaction failed:", n), n instanceof Error && (n.message.includes("User rejected") || n.message.includes("user rejected")) &&
|
|
641
|
+
t.console.error("Auto-executed transaction failed:", n), n instanceof Error && (n.message.includes("User rejected") || n.message.includes("user rejected")) && q(!1), g({
|
|
436
642
|
status: "Failed",
|
|
437
643
|
revertReason: n instanceof Error ? n.message : "Unknown error"
|
|
438
|
-
}),
|
|
644
|
+
}), ee(!1);
|
|
439
645
|
}
|
|
440
646
|
}
|
|
441
647
|
));
|
|
442
648
|
}, [
|
|
443
649
|
x,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
]),
|
|
455
|
-
x &&
|
|
456
|
-
mainSignerAddress:
|
|
457
|
-
calls:
|
|
458
|
-
preconditions:
|
|
459
|
-
quoteProvider:
|
|
460
|
-
addressOverrides:
|
|
650
|
+
w.isSuccess,
|
|
651
|
+
o,
|
|
652
|
+
c.chainId,
|
|
653
|
+
r.isPending,
|
|
654
|
+
te,
|
|
655
|
+
I,
|
|
656
|
+
re,
|
|
657
|
+
M,
|
|
658
|
+
Z,
|
|
659
|
+
r
|
|
660
|
+
]), F(() => {
|
|
661
|
+
x && A && C && h && c.address && L && !w.isPending && !w.isSuccess && (t.console.log("Auto-committing intent configuration..."), w.mutate({
|
|
662
|
+
mainSignerAddress: c.address,
|
|
663
|
+
calls: A,
|
|
664
|
+
preconditions: C,
|
|
665
|
+
quoteProvider: h.quoteProvider,
|
|
666
|
+
addressOverrides: f.variables?.params.addressOverrides
|
|
461
667
|
}));
|
|
462
668
|
}, [
|
|
463
669
|
x,
|
|
464
|
-
y,
|
|
465
|
-
v,
|
|
466
670
|
A,
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
671
|
+
C,
|
|
672
|
+
h,
|
|
673
|
+
c.address,
|
|
674
|
+
L,
|
|
675
|
+
w,
|
|
676
|
+
f.variables
|
|
471
677
|
]);
|
|
472
|
-
const
|
|
678
|
+
const se = He({
|
|
473
679
|
mutationFn: async ({ selectedId: e }) => {
|
|
474
680
|
if (t.console.log("[trails-sdk] Starting sendMetaTxn mutation", {
|
|
475
681
|
selectedId: e,
|
|
476
|
-
hasIntentCallsPayloads: !!
|
|
477
|
-
hasIntentPreconditions: !!
|
|
682
|
+
hasIntentCallsPayloads: !!A,
|
|
683
|
+
hasIntentPreconditions: !!C,
|
|
478
684
|
hasMetaTxns: !!u,
|
|
479
|
-
hasAccountAddress: !!
|
|
480
|
-
quoteProvider:
|
|
481
|
-
}), !
|
|
685
|
+
hasAccountAddress: !!c.address,
|
|
686
|
+
quoteProvider: h?.quoteProvider
|
|
687
|
+
}), !A || !C || !u || !c.address)
|
|
482
688
|
throw new Error("Missing required data for meta-transaction");
|
|
483
|
-
if (!
|
|
689
|
+
if (!h?.quoteProvider)
|
|
484
690
|
throw new Error("quoteProvider is required");
|
|
485
|
-
const n =
|
|
486
|
-
|
|
487
|
-
|
|
691
|
+
const n = _e(
|
|
692
|
+
c.address,
|
|
693
|
+
A
|
|
488
694
|
), a = e ? [u.find((s) => s.id === e)] : u;
|
|
489
695
|
if (t.console.log("[trails-sdk] Selected transactions to send", {
|
|
490
696
|
selectedId: e,
|
|
@@ -498,12 +704,12 @@ function Qn(Be) {
|
|
|
498
704
|
}))
|
|
499
705
|
}), !a || e && !a[0])
|
|
500
706
|
throw new Error("Meta transaction not found");
|
|
501
|
-
const
|
|
707
|
+
const m = [];
|
|
502
708
|
for (const s of a) {
|
|
503
709
|
if (!s) continue;
|
|
504
|
-
const
|
|
710
|
+
const l = `${s.chainId}-${s.id}`, v = z[l], p = Date.now();
|
|
505
711
|
if (t.console.log(
|
|
506
|
-
`[trails-sdk] Processing meta transaction ${
|
|
712
|
+
`[trails-sdk] Processing meta transaction ${l}`,
|
|
507
713
|
{
|
|
508
714
|
metaTxnId: s.id,
|
|
509
715
|
chainId: s.chainId,
|
|
@@ -511,93 +717,93 @@ function Qn(Be) {
|
|
|
511
717
|
contract: s.contract,
|
|
512
718
|
intentAddress: n
|
|
513
719
|
}
|
|
514
|
-
),
|
|
515
|
-
const
|
|
516
|
-
(
|
|
720
|
+
), v && p - v < Je) {
|
|
721
|
+
const i = Math.ceil(
|
|
722
|
+
(Je - (p - v)) / 1e3
|
|
517
723
|
);
|
|
518
724
|
t.console.log(
|
|
519
|
-
`[trails-sdk] Meta transaction for ${
|
|
725
|
+
`[trails-sdk] Meta transaction for ${l} was sent recently. Wait ${i}s before retry`,
|
|
520
726
|
{
|
|
521
|
-
lastSentTime:
|
|
522
|
-
now:
|
|
523
|
-
timeLeft:
|
|
727
|
+
lastSentTime: v,
|
|
728
|
+
now: p,
|
|
729
|
+
timeLeft: i
|
|
524
730
|
}
|
|
525
731
|
);
|
|
526
732
|
continue;
|
|
527
733
|
}
|
|
528
734
|
try {
|
|
529
|
-
const
|
|
530
|
-
if (Number.isNaN(
|
|
735
|
+
const i = parseInt(s.chainId, 10);
|
|
736
|
+
if (Number.isNaN(i) || i <= 0)
|
|
531
737
|
throw t.console.error(
|
|
532
738
|
"[trails-sdk] Invalid chainId for meta transaction",
|
|
533
739
|
{
|
|
534
|
-
chainId:
|
|
535
|
-
operationKey:
|
|
740
|
+
chainId: i,
|
|
741
|
+
operationKey: l,
|
|
536
742
|
metaTxn: s
|
|
537
743
|
}
|
|
538
|
-
), new Error(`Invalid chainId for meta transaction: ${
|
|
539
|
-
const
|
|
540
|
-
if (!
|
|
744
|
+
), new Error(`Invalid chainId for meta transaction: ${i}`);
|
|
745
|
+
const y = Pe(i);
|
|
746
|
+
if (!y)
|
|
541
747
|
throw t.console.error("[trails-sdk] No relayer found for chainId", {
|
|
542
|
-
chainId:
|
|
543
|
-
operationKey:
|
|
544
|
-
availableRelayers: Array.from(
|
|
545
|
-
}), new Error(`No relayer found for chainId: ${
|
|
546
|
-
const
|
|
547
|
-
(
|
|
748
|
+
chainId: i,
|
|
749
|
+
operationKey: l,
|
|
750
|
+
availableRelayers: Array.from(sn.keys())
|
|
751
|
+
}), new Error(`No relayer found for chainId: ${i}`);
|
|
752
|
+
const b = C.filter(
|
|
753
|
+
(oe) => oe.chainId && parseInt(oe.chainId, 10) === i
|
|
548
754
|
);
|
|
549
755
|
t.console.log(
|
|
550
|
-
`[trails-sdk] Relaying meta transaction ${
|
|
756
|
+
`[trails-sdk] Relaying meta transaction ${l} to intent ${n} via relayer`,
|
|
551
757
|
{
|
|
552
|
-
chainId:
|
|
553
|
-
operationKey:
|
|
758
|
+
chainId: i,
|
|
759
|
+
operationKey: l,
|
|
554
760
|
intentAddress: n,
|
|
555
|
-
relayer: !!
|
|
556
|
-
preconditionsCount:
|
|
761
|
+
relayer: !!y,
|
|
762
|
+
preconditionsCount: b.length
|
|
557
763
|
}
|
|
558
764
|
);
|
|
559
|
-
const { opHash:
|
|
765
|
+
const { opHash: ge } = await y.sendMetaTxn(
|
|
560
766
|
s.walletAddress,
|
|
561
767
|
s.contract,
|
|
562
768
|
s.input,
|
|
563
769
|
Number(s.chainId),
|
|
564
770
|
void 0,
|
|
565
|
-
|
|
771
|
+
b
|
|
566
772
|
);
|
|
567
773
|
t.console.log(
|
|
568
|
-
`[trails-sdk] Successfully sent meta transaction ${
|
|
774
|
+
`[trails-sdk] Successfully sent meta transaction ${l}`,
|
|
569
775
|
{
|
|
570
|
-
operationKey:
|
|
571
|
-
opHash:
|
|
572
|
-
chainId:
|
|
776
|
+
operationKey: l,
|
|
777
|
+
opHash: ge,
|
|
778
|
+
chainId: i
|
|
573
779
|
}
|
|
574
780
|
);
|
|
575
|
-
const
|
|
576
|
-
|
|
577
|
-
operationKey:
|
|
578
|
-
opHash:
|
|
781
|
+
const Te = !1;
|
|
782
|
+
m.push({
|
|
783
|
+
operationKey: l,
|
|
784
|
+
opHash: ge,
|
|
579
785
|
success: !0
|
|
580
786
|
});
|
|
581
|
-
} catch (
|
|
582
|
-
const
|
|
787
|
+
} catch (i) {
|
|
788
|
+
const y = i instanceof Error ? i.message : "Unknown error";
|
|
583
789
|
t.console.error(
|
|
584
|
-
`[trails-sdk] Failed to send meta transaction ${
|
|
790
|
+
`[trails-sdk] Failed to send meta transaction ${l}`,
|
|
585
791
|
{
|
|
586
|
-
operationKey:
|
|
587
|
-
error:
|
|
792
|
+
operationKey: l,
|
|
793
|
+
error: y,
|
|
588
794
|
chainId: s.chainId,
|
|
589
795
|
metaTxnId: s.id,
|
|
590
796
|
walletAddress: s.walletAddress,
|
|
591
797
|
contract: s.contract
|
|
592
798
|
}
|
|
593
|
-
),
|
|
594
|
-
operationKey:
|
|
595
|
-
error:
|
|
799
|
+
), m.push({
|
|
800
|
+
operationKey: l,
|
|
801
|
+
error: y,
|
|
596
802
|
success: !1
|
|
597
803
|
});
|
|
598
804
|
}
|
|
599
805
|
}
|
|
600
|
-
return
|
|
806
|
+
return m;
|
|
601
807
|
},
|
|
602
808
|
onSuccess: (e) => {
|
|
603
809
|
t.console.log(
|
|
@@ -613,11 +819,11 @@ function Qn(Be) {
|
|
|
613
819
|
error: n.error || null
|
|
614
820
|
}))
|
|
615
821
|
}
|
|
616
|
-
), e.forEach(({ operationKey: n, opHash: a, success:
|
|
617
|
-
|
|
822
|
+
), e.forEach(({ operationKey: n, opHash: a, success: m }) => {
|
|
823
|
+
m && a ? (ie((s) => ({
|
|
618
824
|
...s,
|
|
619
825
|
[n]: Date.now()
|
|
620
|
-
})),
|
|
826
|
+
})), he((s) => ({
|
|
621
827
|
...s,
|
|
622
828
|
[n]: a
|
|
623
829
|
}))) : t.console.warn(
|
|
@@ -640,57 +846,57 @@ function Qn(Be) {
|
|
|
640
846
|
// Allow up to 2 retries
|
|
641
847
|
retryDelay: (e) => Math.min(1e3 * 2 ** e, 3e4)
|
|
642
848
|
// Exponential backoff
|
|
643
|
-
}), [
|
|
644
|
-
|
|
645
|
-
if (!
|
|
646
|
-
|
|
849
|
+
}), [de, un] = d(null), [ue, gn] = d(null);
|
|
850
|
+
F(() => {
|
|
851
|
+
if (!L || !A?.[0]?.chainId || !de || !ue || !C || !c.address) {
|
|
852
|
+
J(null);
|
|
647
853
|
return;
|
|
648
854
|
}
|
|
649
855
|
try {
|
|
650
|
-
const e =
|
|
651
|
-
if (!e || !
|
|
652
|
-
|
|
856
|
+
const e = L;
|
|
857
|
+
if (!e || !_n(e)) {
|
|
858
|
+
J(null);
|
|
653
859
|
return;
|
|
654
860
|
}
|
|
655
|
-
let n, a = "0x",
|
|
861
|
+
let n, a = "0x", m = 0n;
|
|
656
862
|
const s = e;
|
|
657
|
-
if (
|
|
658
|
-
const
|
|
659
|
-
(
|
|
863
|
+
if (de === Ne) {
|
|
864
|
+
const p = C.find(
|
|
865
|
+
(i) => (i.type === "transfer-native" || i.type === "native-balance") && i.chainId === ue.toString()
|
|
660
866
|
)?.data?.min?.toString();
|
|
661
|
-
if (
|
|
867
|
+
if (p === void 0)
|
|
662
868
|
throw new Error(
|
|
663
869
|
"Could not find native precondition (transfer-native or native-balance) or min amount"
|
|
664
870
|
);
|
|
665
|
-
|
|
871
|
+
m = BigInt(p), n = s;
|
|
666
872
|
} else {
|
|
667
|
-
const
|
|
668
|
-
(
|
|
669
|
-
|
|
670
|
-
|
|
873
|
+
const p = C.find(
|
|
874
|
+
(i) => i.type === "erc20-balance" && i.chainId === ue.toString() && i.data?.token && me(
|
|
875
|
+
ae(i.data.token),
|
|
876
|
+
ae(de)
|
|
671
877
|
)
|
|
672
878
|
)?.data?.min?.toString();
|
|
673
|
-
if (
|
|
879
|
+
if (p === void 0)
|
|
674
880
|
throw new Error(
|
|
675
881
|
"Could not find ERC20 balance precondition or min amount"
|
|
676
882
|
);
|
|
677
|
-
a =
|
|
883
|
+
a = Bn({
|
|
678
884
|
recipient: s,
|
|
679
|
-
amount: BigInt(
|
|
680
|
-
}), n =
|
|
885
|
+
amount: BigInt(p)
|
|
886
|
+
}), n = de;
|
|
681
887
|
}
|
|
682
|
-
|
|
888
|
+
J({
|
|
683
889
|
to: n,
|
|
684
890
|
data: a,
|
|
685
|
-
value:
|
|
686
|
-
chainId:
|
|
891
|
+
value: m,
|
|
892
|
+
chainId: ue,
|
|
687
893
|
error: void 0
|
|
688
894
|
});
|
|
689
895
|
} catch (e) {
|
|
690
896
|
t.console.error(
|
|
691
897
|
"[trails-sdk] Failed to calculate origin call params for UI:",
|
|
692
898
|
e
|
|
693
|
-
),
|
|
899
|
+
), J({
|
|
694
900
|
to: null,
|
|
695
901
|
data: null,
|
|
696
902
|
value: null,
|
|
@@ -699,55 +905,55 @@ function Qn(Be) {
|
|
|
699
905
|
});
|
|
700
906
|
}
|
|
701
907
|
}, [
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
908
|
+
A,
|
|
909
|
+
de,
|
|
910
|
+
ue,
|
|
911
|
+
C,
|
|
912
|
+
c.address,
|
|
913
|
+
L
|
|
708
914
|
]);
|
|
709
|
-
const
|
|
915
|
+
const V = Ln(
|
|
710
916
|
u,
|
|
711
|
-
|
|
917
|
+
Pe
|
|
712
918
|
);
|
|
713
|
-
|
|
714
|
-
const a =
|
|
919
|
+
Qn(() => !u || Object.keys(V).length === 0 ? "no_statuses" : u.map((n) => `${n.chainId}-${n.id}`).sort().map((n) => {
|
|
920
|
+
const a = V[n];
|
|
715
921
|
return `${n}:${a ? a.status : "loading"}`;
|
|
716
|
-
}).join(","), [u,
|
|
717
|
-
const
|
|
718
|
-
|
|
922
|
+
}).join(","), [u, V]);
|
|
923
|
+
const Re = $e(/* @__PURE__ */ new Set()), Ue = $e(null);
|
|
924
|
+
F(() => {
|
|
719
925
|
if (t.console.log(
|
|
720
926
|
"[trails-sdk] Running meta-transaction block timestamp effect:",
|
|
721
927
|
{
|
|
722
928
|
metaTxnsLength: u?.length,
|
|
723
|
-
monitorStatusesLength: Object.keys(
|
|
929
|
+
monitorStatusesLength: Object.keys(V).length
|
|
724
930
|
}
|
|
725
931
|
), !u || u.length === 0) {
|
|
726
932
|
t.console.log(
|
|
727
933
|
"[trails-sdk] No meta transactions, clearing timestamps"
|
|
728
|
-
),
|
|
934
|
+
), Re.current.clear(), Object.keys(Ee).length > 0 && le({});
|
|
729
935
|
return;
|
|
730
936
|
}
|
|
731
|
-
if (!Object.keys(
|
|
937
|
+
if (!Object.keys(V).length) {
|
|
732
938
|
t.console.log("[trails-sdk] No monitor statuses yet, waiting...");
|
|
733
939
|
return;
|
|
734
940
|
}
|
|
735
941
|
u.forEach(async (e, n) => {
|
|
736
942
|
const a = `${e.chainId}-${e.id}`;
|
|
737
|
-
if (
|
|
943
|
+
if (Re.current.has(a)) {
|
|
738
944
|
t.console.log(
|
|
739
945
|
`[trails-sdk] MetaTxn ${a}: Already processed, skipping`
|
|
740
946
|
);
|
|
741
947
|
return;
|
|
742
948
|
}
|
|
743
|
-
const
|
|
744
|
-
if (!
|
|
949
|
+
const m = V[a];
|
|
950
|
+
if (!m || m.status !== "confirmed") {
|
|
745
951
|
t.console.log(
|
|
746
952
|
`[trails-sdk] MetaTxn ${a}: Status not confirmed, skipping`
|
|
747
953
|
);
|
|
748
954
|
return;
|
|
749
955
|
}
|
|
750
|
-
const s =
|
|
956
|
+
const s = m.transactionHash;
|
|
751
957
|
if (!s) {
|
|
752
958
|
t.console.log(
|
|
753
959
|
`[trails-sdk] MetaTxn ${a}: No transaction hash, skipping`
|
|
@@ -756,256 +962,256 @@ function Qn(Be) {
|
|
|
756
962
|
}
|
|
757
963
|
t.console.log(
|
|
758
964
|
`[trails-sdk] MetaTxn ${a}: Processing transaction ${s}`
|
|
759
|
-
),
|
|
965
|
+
), Re.current.add(a);
|
|
760
966
|
try {
|
|
761
|
-
const
|
|
762
|
-
if (Number.isNaN(
|
|
967
|
+
const l = parseInt(e.chainId, 10);
|
|
968
|
+
if (Number.isNaN(l) || l <= 0)
|
|
763
969
|
throw new Error(
|
|
764
970
|
`Invalid chainId for meta transaction: ${e.chainId}`
|
|
765
971
|
);
|
|
766
|
-
const
|
|
767
|
-
chain:
|
|
768
|
-
transport:
|
|
769
|
-
}),
|
|
972
|
+
const v = Ce(l), p = Ke({
|
|
973
|
+
chain: v,
|
|
974
|
+
transport: ze()
|
|
975
|
+
}), i = await p.getTransactionReceipt({
|
|
770
976
|
hash: s
|
|
771
977
|
});
|
|
772
|
-
if (
|
|
773
|
-
const
|
|
774
|
-
blockNumber:
|
|
978
|
+
if (i && typeof i.blockNumber == "bigint") {
|
|
979
|
+
const y = await p.getBlock({
|
|
980
|
+
blockNumber: i.blockNumber
|
|
775
981
|
});
|
|
776
982
|
t.console.log(
|
|
777
|
-
`[trails-sdk] MetaTxn ${a}: Got block timestamp ${
|
|
778
|
-
),
|
|
779
|
-
...
|
|
983
|
+
`[trails-sdk] MetaTxn ${a}: Got block timestamp ${y.timestamp}`
|
|
984
|
+
), le((b) => ({
|
|
985
|
+
...b,
|
|
780
986
|
[a]: {
|
|
781
|
-
timestamp: Number(
|
|
987
|
+
timestamp: Number(y.timestamp),
|
|
782
988
|
error: void 0
|
|
783
989
|
}
|
|
784
990
|
}));
|
|
785
991
|
try {
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
).toLowerCase() : void 0,
|
|
789
|
-
t.console.log("[Trails] isCctp",
|
|
992
|
+
const b = h?.quoteProvider ? String(h.quoteProvider).toLowerCase() : void 0, ge = f.variables?.params.provider ? String(
|
|
993
|
+
f.variables.params.provider
|
|
994
|
+
).toLowerCase() : void 0, Te = b === "cctp" || ge === "cctp", oe = f.variables?.params.originChainId, De = f.variables?.params.destinationChainId;
|
|
995
|
+
t.console.log("[Trails] isCctp", Te), t.console.log("[Trails] providerFromQuote", b), t.console.log("[Trails] providerFromArgs", ge), t.console.log("[Trails] trailsFee", h), t.console.log(
|
|
790
996
|
"[Trails] createIntentMutation.variables",
|
|
791
|
-
|
|
997
|
+
f.variables
|
|
792
998
|
), t.console.log(
|
|
793
999
|
"[Trails] createIntentMutation.variables.params.provider",
|
|
794
|
-
|
|
1000
|
+
f.variables?.params.provider
|
|
795
1001
|
), t.console.log(
|
|
796
1002
|
"[Trails] createIntentMutation.variables.params.originChainId",
|
|
797
|
-
|
|
1003
|
+
f.variables?.params.originChainId
|
|
798
1004
|
), t.console.log(
|
|
799
1005
|
"[Trails] createIntentMutation.variables.params.destinationChainId",
|
|
800
|
-
|
|
1006
|
+
f.variables?.params.destinationChainId
|
|
801
1007
|
), t.console.log(
|
|
802
1008
|
"[Trails] lastQueuedCctpSourceTxHash",
|
|
803
|
-
|
|
1009
|
+
Ue.current
|
|
804
1010
|
), t.console.log("[Trails] transactionHash", s), t.console.log(
|
|
805
1011
|
"[Trails] originChainIdForCctp",
|
|
806
|
-
|
|
1012
|
+
oe
|
|
807
1013
|
), t.console.log(
|
|
808
1014
|
"[Trails] destinationChainIdForCctp",
|
|
809
|
-
|
|
810
|
-
),
|
|
811
|
-
trailsClient:
|
|
1015
|
+
De
|
|
1016
|
+
), Te && T && s && typeof oe == "number" && typeof De == "number" && Ue.current !== s && n === 0 && (Ue.current = s, await jn({
|
|
1017
|
+
trailsClient: T,
|
|
812
1018
|
sourceTxHash: s,
|
|
813
|
-
sourceChainId:
|
|
814
|
-
destinationChainId:
|
|
1019
|
+
sourceChainId: oe,
|
|
1020
|
+
destinationChainId: De
|
|
815
1021
|
}));
|
|
816
|
-
} catch (
|
|
1022
|
+
} catch (b) {
|
|
817
1023
|
t.console.error(
|
|
818
1024
|
`[trails-sdk] Queue CCTP on meta-tx error (${a}):`,
|
|
819
|
-
|
|
1025
|
+
b
|
|
820
1026
|
);
|
|
821
1027
|
}
|
|
822
1028
|
} else
|
|
823
1029
|
t.console.warn(
|
|
824
1030
|
`[trails-sdk] MetaTxn ${a}: No block number in receipt`
|
|
825
|
-
),
|
|
826
|
-
...
|
|
1031
|
+
), le((y) => ({
|
|
1032
|
+
...y,
|
|
827
1033
|
[a]: {
|
|
828
1034
|
timestamp: null,
|
|
829
1035
|
error: "Block number not found in receipt"
|
|
830
1036
|
}
|
|
831
1037
|
}));
|
|
832
|
-
} catch (
|
|
1038
|
+
} catch (l) {
|
|
833
1039
|
t.console.error(
|
|
834
1040
|
`[trails-sdk] MetaTxn ${a}: Error:`,
|
|
835
|
-
|
|
836
|
-
),
|
|
837
|
-
...
|
|
1041
|
+
l
|
|
1042
|
+
), le((v) => ({
|
|
1043
|
+
...v,
|
|
838
1044
|
[a]: {
|
|
839
1045
|
timestamp: null,
|
|
840
|
-
error:
|
|
1046
|
+
error: l.message || "Failed to fetch receipt/timestamp"
|
|
841
1047
|
}
|
|
842
1048
|
}));
|
|
843
1049
|
}
|
|
844
1050
|
});
|
|
845
1051
|
}, [
|
|
846
1052
|
u,
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
1053
|
+
V,
|
|
1054
|
+
Ee,
|
|
1055
|
+
h,
|
|
1056
|
+
f.variables,
|
|
1057
|
+
T
|
|
852
1058
|
]);
|
|
853
|
-
const
|
|
854
|
-
|
|
1059
|
+
const mn = (e) => {
|
|
1060
|
+
q(e);
|
|
855
1061
|
};
|
|
856
|
-
function
|
|
857
|
-
|
|
1062
|
+
function fn(e) {
|
|
1063
|
+
f.mutate({
|
|
858
1064
|
...e,
|
|
859
1065
|
destinationSalt: Date.now().toString()
|
|
860
1066
|
});
|
|
861
1067
|
}
|
|
862
|
-
function
|
|
863
|
-
t.console.log("[trails-sdk] commitIntentConfig", e),
|
|
1068
|
+
function hn(e) {
|
|
1069
|
+
t.console.log("[trails-sdk] commitIntentConfig", e), w.mutate(e);
|
|
864
1070
|
}
|
|
865
|
-
function
|
|
1071
|
+
function pn(e) {
|
|
866
1072
|
if (!e) {
|
|
867
|
-
|
|
1073
|
+
J(null);
|
|
868
1074
|
return;
|
|
869
1075
|
}
|
|
870
1076
|
const { originChainId: n, tokenAddress: a } = e;
|
|
871
|
-
|
|
1077
|
+
gn(n), un(a);
|
|
872
1078
|
}
|
|
873
|
-
function
|
|
874
|
-
|
|
1079
|
+
function In(e) {
|
|
1080
|
+
se.mutate({ selectedId: e });
|
|
875
1081
|
}
|
|
876
|
-
const { chainId:
|
|
1082
|
+
const { chainId: vn } = c, Le = o?.chainId, Tn = f.isPending, Cn = f.isSuccess, Sn = f.error, yn = f.variables, An = w.isPending, wn = w.isSuccess, bn = w.error, kn = w.variables, En = se.isPending, Pn = se.isSuccess, xn = se.error, Mn = se.variables;
|
|
877
1083
|
return {
|
|
878
|
-
trailsClient:
|
|
1084
|
+
trailsClient: T,
|
|
879
1085
|
metaTxns: u,
|
|
880
|
-
intentCallsPayloads:
|
|
881
|
-
intentPreconditions:
|
|
882
|
-
trailsFee:
|
|
883
|
-
txnHash:
|
|
884
|
-
committedOriginIntentAddress:
|
|
885
|
-
committedDestinationIntentAddress:
|
|
886
|
-
verificationStatus:
|
|
887
|
-
getRelayer:
|
|
888
|
-
estimatedGas:
|
|
889
|
-
isEstimateError:
|
|
890
|
-
estimateError:
|
|
891
|
-
calculateIntentAddress:
|
|
892
|
-
calculateOriginAndDestinationIntentAddresses:
|
|
893
|
-
committedIntentConfig:
|
|
894
|
-
isLoadingCommittedConfig:
|
|
895
|
-
committedConfigError:
|
|
896
|
-
commitIntentConfig:
|
|
897
|
-
commitIntentConfigPending:
|
|
898
|
-
commitIntentConfigSuccess:
|
|
899
|
-
commitIntentConfigError:
|
|
900
|
-
commitIntentConfigArgs:
|
|
901
|
-
getIntentCallsPayloads:
|
|
902
|
-
operationHashes:
|
|
903
|
-
callIntentCallsPayload:
|
|
904
|
-
sendOriginTransaction:
|
|
905
|
-
switchChain:
|
|
906
|
-
isSwitchingChain:
|
|
907
|
-
switchChainError:
|
|
908
|
-
isTransactionInProgress:
|
|
909
|
-
isChainSwitchRequired:
|
|
910
|
-
sendTransaction:
|
|
911
|
-
isSendingTransaction:
|
|
912
|
-
originCallStatus:
|
|
913
|
-
updateOriginCallStatus:
|
|
914
|
-
isEstimatingGas:
|
|
1086
|
+
intentCallsPayloads: A,
|
|
1087
|
+
intentPreconditions: C,
|
|
1088
|
+
trailsFee: h,
|
|
1089
|
+
txnHash: I,
|
|
1090
|
+
committedOriginIntentAddress: R,
|
|
1091
|
+
committedDestinationIntentAddress: fe,
|
|
1092
|
+
verificationStatus: tn,
|
|
1093
|
+
getRelayer: Pe,
|
|
1094
|
+
estimatedGas: Ie,
|
|
1095
|
+
isEstimateError: xe,
|
|
1096
|
+
estimateError: Me,
|
|
1097
|
+
calculateIntentAddress: _e,
|
|
1098
|
+
calculateOriginAndDestinationIntentAddresses: Ge,
|
|
1099
|
+
committedIntentConfig: on,
|
|
1100
|
+
isLoadingCommittedConfig: an,
|
|
1101
|
+
committedConfigError: rn,
|
|
1102
|
+
commitIntentConfig: hn,
|
|
1103
|
+
commitIntentConfigPending: An,
|
|
1104
|
+
commitIntentConfigSuccess: wn,
|
|
1105
|
+
commitIntentConfigError: bn,
|
|
1106
|
+
commitIntentConfigArgs: kn,
|
|
1107
|
+
getIntentCallsPayloads: Be,
|
|
1108
|
+
operationHashes: ye,
|
|
1109
|
+
callIntentCallsPayload: cn,
|
|
1110
|
+
sendOriginTransaction: dn,
|
|
1111
|
+
switchChain: Ae,
|
|
1112
|
+
isSwitchingChain: we,
|
|
1113
|
+
switchChainError: _,
|
|
1114
|
+
isTransactionInProgress: j,
|
|
1115
|
+
isChainSwitchRequired: vn !== Le && !!Le,
|
|
1116
|
+
sendTransaction: r.sendTransaction,
|
|
1117
|
+
isSendingTransaction: r.isPending,
|
|
1118
|
+
originCallStatus: M,
|
|
1119
|
+
updateOriginCallStatus: D,
|
|
1120
|
+
isEstimatingGas: be,
|
|
915
1121
|
isAutoExecute: x,
|
|
916
|
-
updateAutoExecute:
|
|
917
|
-
receipt:
|
|
918
|
-
isWaitingForReceipt:
|
|
919
|
-
receiptIsSuccess:
|
|
920
|
-
receiptIsError:
|
|
921
|
-
receiptError:
|
|
922
|
-
hasAutoExecuted:
|
|
923
|
-
originCallSuccess:
|
|
924
|
-
sentMetaTxns:
|
|
925
|
-
sendMetaTxn:
|
|
926
|
-
sendMetaTxnPending:
|
|
927
|
-
sendMetaTxnSuccess:
|
|
928
|
-
sendMetaTxnError:
|
|
929
|
-
sendMetaTxnArgs:
|
|
930
|
-
clearIntent:
|
|
931
|
-
metaTxnMonitorStatuses:
|
|
932
|
-
createIntent:
|
|
933
|
-
createIntentPending:
|
|
934
|
-
createIntentSuccess:
|
|
935
|
-
createIntentError:
|
|
936
|
-
createIntentArgs:
|
|
937
|
-
originCallParams:
|
|
938
|
-
updateOriginCallParams:
|
|
939
|
-
originBlockTimestamp:
|
|
940
|
-
metaTxnBlockTimestamps:
|
|
941
|
-
originIntentAddress:
|
|
942
|
-
destinationIntentAddress:
|
|
1122
|
+
updateAutoExecute: mn,
|
|
1123
|
+
receipt: E,
|
|
1124
|
+
isWaitingForReceipt: te,
|
|
1125
|
+
receiptIsSuccess: qe,
|
|
1126
|
+
receiptIsError: Oe,
|
|
1127
|
+
receiptError: ve,
|
|
1128
|
+
hasAutoExecuted: Z,
|
|
1129
|
+
originCallSuccess: r.isSuccess,
|
|
1130
|
+
sentMetaTxns: z,
|
|
1131
|
+
sendMetaTxn: In,
|
|
1132
|
+
sendMetaTxnPending: En,
|
|
1133
|
+
sendMetaTxnSuccess: Pn,
|
|
1134
|
+
sendMetaTxnError: xn,
|
|
1135
|
+
sendMetaTxnArgs: Mn,
|
|
1136
|
+
clearIntent: ln,
|
|
1137
|
+
metaTxnMonitorStatuses: V,
|
|
1138
|
+
createIntent: fn,
|
|
1139
|
+
createIntentPending: Tn,
|
|
1140
|
+
createIntentSuccess: Cn,
|
|
1141
|
+
createIntentError: Sn,
|
|
1142
|
+
createIntentArgs: yn,
|
|
1143
|
+
originCallParams: o,
|
|
1144
|
+
updateOriginCallParams: pn,
|
|
1145
|
+
originBlockTimestamp: ce,
|
|
1146
|
+
metaTxnBlockTimestamps: Ee,
|
|
1147
|
+
originIntentAddress: L,
|
|
1148
|
+
destinationIntentAddress: Se
|
|
943
1149
|
};
|
|
944
1150
|
}
|
|
945
1151
|
export {
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1152
|
+
it as TRAILS_ROUTER_PLACEHOLDER_AMOUNT,
|
|
1153
|
+
Dn as TradeType,
|
|
1154
|
+
rt as TrailsClient,
|
|
1155
|
+
ct as TrailsWidget,
|
|
1156
|
+
_e as calculateIntentAddress,
|
|
1157
|
+
Ge as calculateOriginAndDestinationIntentAddresses,
|
|
1158
|
+
lt as commitIntentConfig,
|
|
1159
|
+
dt as createModalController,
|
|
1160
|
+
ut as declareSequenceEnv,
|
|
1161
|
+
gt as getAPIClient,
|
|
1162
|
+
mt as getAccountTotalBalanceUsd,
|
|
1163
|
+
ft as getAccountTransactionHistory,
|
|
1164
|
+
ht as getAllChains,
|
|
1165
|
+
Ce as getChainInfo,
|
|
1166
|
+
pt as getDebug,
|
|
1167
|
+
Bn as getERC20TransferData,
|
|
1168
|
+
It as getHasSufficientBalanceToken,
|
|
1169
|
+
vt as getHasSufficientBalanceUsd,
|
|
1170
|
+
Tt as getIndexerGatewayClient,
|
|
1171
|
+
Gn as getIntentCallsPayloads,
|
|
1172
|
+
Ct as getIntentTransactionHistory,
|
|
1173
|
+
St as getMetaTxnReceipt,
|
|
1174
|
+
yt as getMinLogLevel,
|
|
1175
|
+
At as getRelayer,
|
|
1176
|
+
wt as getSequenceApiUrl,
|
|
1177
|
+
$n as getSequenceEnv,
|
|
1178
|
+
bt as getSequenceIndexerUrl,
|
|
1179
|
+
kt as getSequenceNodeGatewayUrl,
|
|
1180
|
+
Et as getSequenceProjectAccessKey,
|
|
1181
|
+
Pt as getSlippageTolerance,
|
|
1182
|
+
xt as getSupportedChains,
|
|
1183
|
+
Mt as getSupportedTokens,
|
|
1184
|
+
qt as getTrailsApiUrl,
|
|
1185
|
+
Ot as getTrailsClient,
|
|
1186
|
+
Rt as getTxTimeDiff,
|
|
1187
|
+
Ut as getWalletConnectProjectId,
|
|
982
1188
|
t as logger,
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1189
|
+
Fn as prepareSend,
|
|
1190
|
+
Dt as relayerSendMetaTx,
|
|
1191
|
+
Ft as sendOriginTransaction,
|
|
1192
|
+
Ht as setDebug,
|
|
1193
|
+
$t as setSequenceApiUrl,
|
|
1194
|
+
Nt as setSequenceEnv,
|
|
1195
|
+
Bt as setSequenceIndexerUrl,
|
|
1196
|
+
Lt as setSequenceNodeGatewayUrl,
|
|
1197
|
+
jt as setSequenceProjectAccessKey,
|
|
1198
|
+
Gt as setSlippageTolerance,
|
|
1199
|
+
Qt as setTrailsApiUrl,
|
|
1200
|
+
_t as setWalletConnectProjectId,
|
|
1201
|
+
qn as useAPIClient,
|
|
1202
|
+
Wt as useAccountTotalBalanceUsd,
|
|
1203
|
+
Vt as useAccountTransactionHistory,
|
|
1204
|
+
Kt as useHasSufficientBalanceToken,
|
|
1205
|
+
zt as useHasSufficientBalanceUsd,
|
|
1206
|
+
On as useIndexerGatewayClient,
|
|
1207
|
+
Xt as useIntentTransactionHistory,
|
|
1208
|
+
Ln as useMetaTxnsMonitor,
|
|
1209
|
+
tt as useQuote,
|
|
1210
|
+
en as useRelayers,
|
|
1211
|
+
Yt as useSupportedChains,
|
|
1212
|
+
Rn as useSupportedTokens,
|
|
1213
|
+
Jt as useTokenBalances,
|
|
1214
|
+
Zt as useTokenList,
|
|
1215
|
+
st as useTrails,
|
|
1216
|
+
Ze as useTrailsClient
|
|
1011
1217
|
};
|