0xtrails 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/offlineRecovery.d.ts.map +1 -1
- package/dist/offlineRecovery.js +66 -71
- package/dist/package.js +1 -1
- package/dist/recover.d.ts +9 -2
- package/dist/recover.d.ts.map +1 -1
- package/dist/recover.js +443 -377
- package/dist/umd/trails.min.js +200 -200
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.js +151 -143
- package/dist/widget/components/TransactionHistoryItem.d.ts.map +1 -1
- package/dist/widget/components/TransactionHistoryItem.js +209 -154
- package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -1
- package/dist/widget/components/WaasFeeOptions.js +158 -154
- package/dist/widget/styles.gen.js +1 -1
- package/package.json +3 -3
package/dist/recover.js
CHANGED
|
@@ -1,51 +1,54 @@
|
|
|
1
|
-
import { logger as
|
|
2
|
-
import { getChainInfo as
|
|
3
|
-
import { normalizeAddress as
|
|
4
|
-
import { isPositiveBigInt as
|
|
5
|
-
import { getERC20TransferData as
|
|
6
|
-
import { attemptSwitchChain as
|
|
7
|
-
import { abortIntent as
|
|
8
|
-
import { decodeGuestModuleEvents as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import { logger as k } from "./logger/index.js";
|
|
2
|
+
import { getChainInfo as L, getPublicClient as D } from "./chains.js";
|
|
3
|
+
import { normalizeAddress as B } from "./utils/address.js";
|
|
4
|
+
import { isPositiveBigInt as ae } from "./utils/validation.js";
|
|
5
|
+
import { getERC20TransferData as se } from "./utils.js";
|
|
6
|
+
import { attemptSwitchChain as ie } from "./chainSwitch.js";
|
|
7
|
+
import { abortIntent as ce } from "./intents.js";
|
|
8
|
+
import { decodeGuestModuleEvents as W } from "./decoders.js";
|
|
9
|
+
import { getChainIndexerUrl as de } from "./indexerClient.js";
|
|
10
|
+
import { WIDGET_REFRESH_INTERVAL as le, useTokenBalancesForMultipleAccounts as ue } from "./query/balance.hooks.js";
|
|
11
|
+
import { useTrails as fe } from "./widget/providers/TrailsProvider.js";
|
|
12
|
+
import { useTrailsClient as M } from "./trailsClient.js";
|
|
13
|
+
import { useGetIntent as he } from "./hooks/useGetIntent.js";
|
|
14
|
+
import { useKeyMachineClient as ge } from "./keyMachineClient.js";
|
|
15
|
+
import { Constants as O, Erc6492 as ye, Payload as R, Signature as U } from "@0xsequence/wallet-primitives";
|
|
16
|
+
import { zeroAddress as E } from "viem";
|
|
17
|
+
import { useCallback as A, useMemo as I } from "react";
|
|
18
|
+
import { checkProviderHealth as K, signWithTimeout as V, wrapWalletClient as G } from "@0xtrails/wallet";
|
|
19
|
+
import { AbiFunction as pe, Address as f, Bytes as H } from "ox";
|
|
20
|
+
import { SequenceIndexer as we } from "@0xsequence/indexer";
|
|
21
|
+
async function ve(e, t) {
|
|
22
|
+
const n = await D(t).getCode({ address: e }), r = n !== void 0 && n !== "0x";
|
|
23
|
+
return k.console.log("[refund] Address deployment check:", {
|
|
21
24
|
address: e,
|
|
22
25
|
chainId: t,
|
|
23
|
-
codeLength:
|
|
24
|
-
isDeployed:
|
|
25
|
-
}),
|
|
26
|
+
codeLength: n?.length ?? 0,
|
|
27
|
+
isDeployed: r
|
|
28
|
+
}), r;
|
|
26
29
|
}
|
|
27
|
-
async function
|
|
30
|
+
async function en(e, t, n, r) {
|
|
28
31
|
if (!e.account) throw new Error("Wallet client account is required for signing");
|
|
29
|
-
await
|
|
30
|
-
const o =
|
|
32
|
+
await K(e);
|
|
33
|
+
const o = R.toTyped(f.from(t), n, r), a = await V(e.signTypedData({
|
|
31
34
|
account: e.account,
|
|
32
35
|
...o
|
|
33
36
|
}), "Payload signature");
|
|
34
|
-
return
|
|
37
|
+
return k.console.log("[refund] Signature received:", a), a;
|
|
35
38
|
}
|
|
36
|
-
async function
|
|
37
|
-
const { trailsClient: t, intentId:
|
|
39
|
+
async function nn(e) {
|
|
40
|
+
const { trailsClient: t, intentId: n, payload: r, intentAddress: o, signature: a } = e, s = r.calls[0];
|
|
38
41
|
if (!s) throw new Error("Refund call not found in payload");
|
|
39
|
-
if (f.isEqual(s.to,
|
|
40
|
-
if (!o || f.isEqual(o,
|
|
42
|
+
if (f.isEqual(s.to, E)) throw new Error("Refund call 'to' address cannot be zero address");
|
|
43
|
+
if (!o || f.isEqual(o, E)) throw new Error("Intent address cannot be zero address");
|
|
41
44
|
const i = {
|
|
42
45
|
kind: "v3_calls_payload",
|
|
43
46
|
encoding: "hex",
|
|
44
|
-
encoded:
|
|
47
|
+
encoded: H.toHex(R.encode(r)),
|
|
45
48
|
intentAddress: o,
|
|
46
|
-
chainId:
|
|
49
|
+
chainId: r.type === "call" ? Number(e.chainId) : void 0
|
|
47
50
|
}, d = await t.buildIntentRecoveryTransaction({
|
|
48
|
-
intentId:
|
|
51
|
+
intentId: n,
|
|
49
52
|
payload: i,
|
|
50
53
|
signature: a,
|
|
51
54
|
intentAddress: o
|
|
@@ -55,12 +58,12 @@ async function Fe(e) {
|
|
|
55
58
|
data: d.data
|
|
56
59
|
};
|
|
57
60
|
}
|
|
58
|
-
function
|
|
61
|
+
function Ie(e, t) {
|
|
59
62
|
if (e && typeof e == "object" && "kind" in e && e.kind === "v3_calls_payload") {
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
63
|
+
const n = e;
|
|
64
|
+
if (n.encoding !== "hex" || !n.encoded) throw new Error("PrepareIntentRecovery returned invalid canonical payload encoding");
|
|
65
|
+
const r = n.intentAddress ? f.from(n.intentAddress) : t, o = R.decode(H.fromHex(n.encoded), r);
|
|
66
|
+
if (!R.isCalls(o)) throw new Error("PrepareIntentRecovery returned non-call payload for recovery");
|
|
64
67
|
const a = o.calls?.[0];
|
|
65
68
|
if (!a) throw new Error("PrepareIntentRecovery returned invalid payload: refund call missing");
|
|
66
69
|
return {
|
|
@@ -70,90 +73,90 @@ function ue(e, t) {
|
|
|
70
73
|
}
|
|
71
74
|
throw new Error("PrepareIntentRecovery returned unsupported payload format (expected v3_calls_payload)");
|
|
72
75
|
}
|
|
73
|
-
function
|
|
76
|
+
function $(e) {
|
|
74
77
|
if (!e?.tokens) return 0;
|
|
75
78
|
let t = 0;
|
|
76
|
-
for (const
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
+
for (const n of e.tokens) {
|
|
80
|
+
const r = n.balanceUsd || 0;
|
|
81
|
+
r > t && (t = r);
|
|
79
82
|
}
|
|
80
83
|
return t;
|
|
81
84
|
}
|
|
82
|
-
function
|
|
85
|
+
function z(e) {
|
|
83
86
|
if (!e?.tokens) return 0n;
|
|
84
87
|
let t = 0n;
|
|
85
|
-
for (const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
+
for (const n of e.tokens) {
|
|
89
|
+
const r = BigInt(n.balance || "0");
|
|
90
|
+
r > t && (t = r);
|
|
88
91
|
}
|
|
89
92
|
return t;
|
|
90
93
|
}
|
|
91
|
-
function
|
|
92
|
-
const a =
|
|
93
|
-
let
|
|
94
|
-
o && (a > 0 && s > 0 ?
|
|
95
|
-
const
|
|
96
|
-
address:
|
|
94
|
+
function j(e, t, n, r, o) {
|
|
95
|
+
const a = $(t), s = $(n), i = z(t), d = z(n);
|
|
96
|
+
let c = !1;
|
|
97
|
+
o && (a > 0 && s > 0 ? c = s > a : s > 0 && a === 0 ? c = !0 : a > 0 && s === 0 ? c = !1 : c = d > i);
|
|
98
|
+
const u = () => !e.originIntentAddress || !r ? null : {
|
|
99
|
+
address: r,
|
|
97
100
|
chainId: Number(e.originChainId || 0),
|
|
98
101
|
intentAddress: f.from(e.originIntentAddress),
|
|
99
102
|
tokenBalancesData: t,
|
|
100
103
|
isOrigin: !0
|
|
101
104
|
};
|
|
102
|
-
if (
|
|
103
|
-
const
|
|
104
|
-
return !
|
|
105
|
+
if (c) {
|
|
106
|
+
const l = e.destinationChainId;
|
|
107
|
+
return !l || !e.destinationIntentAddress || !o ? u() : {
|
|
105
108
|
address: o,
|
|
106
|
-
chainId: Number(
|
|
109
|
+
chainId: Number(l),
|
|
107
110
|
intentAddress: f.from(e.destinationIntentAddress),
|
|
108
|
-
tokenBalancesData:
|
|
111
|
+
tokenBalancesData: n,
|
|
109
112
|
isOrigin: !1
|
|
110
113
|
};
|
|
111
114
|
}
|
|
112
|
-
return
|
|
115
|
+
return u();
|
|
113
116
|
}
|
|
114
|
-
function
|
|
115
|
-
const
|
|
116
|
-
if (!
|
|
117
|
-
for (const o of
|
|
117
|
+
function X(e, t) {
|
|
118
|
+
const n = (r) => {
|
|
119
|
+
if (!r?.tokens) return !1;
|
|
120
|
+
for (const o of r.tokens) if (ae(o.balance || "0")) return !0;
|
|
118
121
|
return !1;
|
|
119
122
|
};
|
|
120
|
-
return
|
|
123
|
+
return n(e) || n(t);
|
|
121
124
|
}
|
|
122
|
-
function
|
|
125
|
+
function Y(e) {
|
|
123
126
|
if (!e?.tokenBalancesData?.tokens) return null;
|
|
124
|
-
let t = null,
|
|
125
|
-
for (const
|
|
126
|
-
const o = BigInt(
|
|
127
|
-
o > 0n && o >
|
|
127
|
+
let t = null, n = 0n;
|
|
128
|
+
for (const r of e.tokenBalancesData.tokens) {
|
|
129
|
+
const o = BigInt(r.balance || "0");
|
|
130
|
+
o > 0n && o > n && (n = o, t = r);
|
|
128
131
|
}
|
|
129
132
|
return t;
|
|
130
133
|
}
|
|
131
|
-
function
|
|
134
|
+
function J(e) {
|
|
132
135
|
if (!e) throw new Error("Refund address is required. Provide refundToAddress or connect a wallet with a valid address");
|
|
133
|
-
if (f.isEqual(e,
|
|
136
|
+
if (f.isEqual(e, E)) throw new Error("Refund address cannot be zero address");
|
|
134
137
|
}
|
|
135
|
-
async function
|
|
136
|
-
const { txHash: t, chainId:
|
|
138
|
+
async function Q(e) {
|
|
139
|
+
const { txHash: t, chainId: n } = e, r = D(n);
|
|
137
140
|
try {
|
|
138
|
-
if (await
|
|
139
|
-
const o = await
|
|
140
|
-
return o.status === "reverted" ? { status: "fail" } :
|
|
141
|
+
if (await r.getTransaction({ hash: t })) try {
|
|
142
|
+
const o = await r.getTransactionReceipt({ hash: t });
|
|
143
|
+
return o.status === "reverted" ? { status: "fail" } : W(o).some((a) => a.type === "CallFailed") ? { status: "fail" } : { status: "success" };
|
|
141
144
|
} catch {
|
|
142
145
|
return { status: "pending" };
|
|
143
146
|
}
|
|
144
147
|
} catch {
|
|
145
148
|
try {
|
|
146
|
-
const o = await
|
|
147
|
-
return o.status === "reverted" ? { status: "fail" } :
|
|
149
|
+
const o = await r.getTransactionReceipt({ hash: t });
|
|
150
|
+
return o.status === "reverted" ? { status: "fail" } : W(o).some((a) => a.type === "CallFailed") ? { status: "fail" } : { status: "success" };
|
|
148
151
|
} catch {
|
|
149
152
|
return { status: "pending" };
|
|
150
153
|
}
|
|
151
154
|
}
|
|
152
155
|
return { status: "pending" };
|
|
153
156
|
}
|
|
154
|
-
function
|
|
157
|
+
function Z(e) {
|
|
155
158
|
if (!e) return null;
|
|
156
|
-
const t =
|
|
159
|
+
const t = L(e.chainId);
|
|
157
160
|
return {
|
|
158
161
|
address: e.address,
|
|
159
162
|
chainId: e.chainId,
|
|
@@ -162,46 +165,84 @@ function M(e) {
|
|
|
162
165
|
tokenBalancesData: e.tokenBalancesData
|
|
163
166
|
};
|
|
164
167
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
function me(e) {
|
|
169
|
+
if (e.length !== 132) throw new Error(`Invalid recovery signature length: expected 65 bytes, got ${(e.length - 2) / 2} bytes`);
|
|
170
|
+
const t = BigInt(`0x${e.slice(2, 66)}`), n = BigInt(`0x${e.slice(66, 130)}`), r = +`0x${e.slice(130)}`;
|
|
171
|
+
if (Number.isNaN(r)) throw new Error("Invalid recovery signature parity byte");
|
|
172
|
+
if (r === 0 || r === 27) return {
|
|
173
|
+
r: t,
|
|
174
|
+
s: n,
|
|
175
|
+
yParity: 0
|
|
176
|
+
};
|
|
177
|
+
if (r === 1 || r === 28) return {
|
|
178
|
+
r: t,
|
|
179
|
+
s: n,
|
|
180
|
+
yParity: 1
|
|
181
|
+
};
|
|
182
|
+
const o = r >= 27 ? (r - 27) % 2 : r % 2;
|
|
183
|
+
return k.console.warn("[recover] Normalizing non-standard signature parity", {
|
|
184
|
+
yParityOrV: r,
|
|
185
|
+
yParity: o
|
|
186
|
+
}), {
|
|
187
|
+
r: t,
|
|
188
|
+
s: n,
|
|
189
|
+
yParity: o
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function Ae(e, t) {
|
|
193
|
+
if (e.length !== 132) return {
|
|
194
|
+
type: "erc1271",
|
|
195
|
+
address: t,
|
|
196
|
+
data: e
|
|
197
|
+
};
|
|
198
|
+
const n = me(e);
|
|
199
|
+
return {
|
|
200
|
+
type: "hash",
|
|
201
|
+
r: n.r,
|
|
202
|
+
s: n.s,
|
|
203
|
+
yParity: n.yParity
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
async function Te(e) {
|
|
207
|
+
const { trailsClient: t, intentData: n, selected: r, effectiveRefundAddress: o, signature: a, payload: s } = e;
|
|
208
|
+
J(o);
|
|
168
209
|
const i = {
|
|
169
210
|
kind: "v3_calls_payload",
|
|
170
211
|
encoding: "hex",
|
|
171
|
-
encoded:
|
|
172
|
-
intentAddress:
|
|
173
|
-
chainId:
|
|
212
|
+
encoded: H.toHex(R.encode(s)),
|
|
213
|
+
intentAddress: r.intentAddress,
|
|
214
|
+
chainId: r.chainId
|
|
174
215
|
}, d = await t.buildIntentRecoveryTransaction({
|
|
175
|
-
intentId:
|
|
216
|
+
intentId: n.intentId,
|
|
176
217
|
payload: i,
|
|
177
218
|
signature: a,
|
|
178
|
-
intentAddress:
|
|
219
|
+
intentAddress: r.intentAddress,
|
|
179
220
|
refundToAddress: o
|
|
180
|
-
}),
|
|
181
|
-
if (!
|
|
182
|
-
const
|
|
183
|
-
if (!
|
|
221
|
+
}), c = Number(d.chainId), u = f.from(d.to);
|
|
222
|
+
if (!u || f.isEqual(u, E)) throw new Error("Refund transaction 'to' address cannot be zero address");
|
|
223
|
+
const l = L(c);
|
|
224
|
+
if (!l) throw new Error(`Chain info not found for chain ID: ${c}`);
|
|
184
225
|
return {
|
|
185
|
-
to:
|
|
226
|
+
to: u,
|
|
186
227
|
data: d.data,
|
|
187
|
-
chainId:
|
|
188
|
-
chain:
|
|
228
|
+
chainId: c,
|
|
229
|
+
chain: l
|
|
189
230
|
};
|
|
190
231
|
}
|
|
191
|
-
function
|
|
232
|
+
function be() {
|
|
192
233
|
if (!globalThis.crypto?.getRandomValues) throw new Error("Secure random generator not available for recovery space");
|
|
193
234
|
const e = new Uint8Array(20);
|
|
194
235
|
globalThis.crypto.getRandomValues(e);
|
|
195
|
-
const t = BigInt(`0x${Array.from(e, (
|
|
236
|
+
const t = BigInt(`0x${Array.from(e, (n) => n.toString(16).padStart(2, "0")).join("")}`);
|
|
196
237
|
if (t <= 1n) throw new Error("Generated reserved recovery space");
|
|
197
238
|
return t;
|
|
198
239
|
}
|
|
199
|
-
async function
|
|
200
|
-
const { trailsClient: t, intentData:
|
|
201
|
-
intentId:
|
|
202
|
-
intentAddress:
|
|
240
|
+
async function ke(e) {
|
|
241
|
+
const { trailsClient: t, intentData: n, selectedIntentAddress: r, effectiveRefundAddress: o } = e, a = await t.prepareIntentRecovery({
|
|
242
|
+
intentId: n.intentId,
|
|
243
|
+
intentAddress: r.intentAddress,
|
|
203
244
|
refundToAddress: o
|
|
204
|
-
}), { decodedPayload: s, refundCall: i } =
|
|
245
|
+
}), { decodedPayload: s, refundCall: i } = Ie(a.payload, r.intentAddress);
|
|
205
246
|
return {
|
|
206
247
|
payload: s,
|
|
207
248
|
refundCall: i,
|
|
@@ -209,55 +250,155 @@ async function Y(e) {
|
|
|
209
250
|
typedData: a.typedData
|
|
210
251
|
};
|
|
211
252
|
}
|
|
212
|
-
async function
|
|
213
|
-
const { walletClient: t, prepared:
|
|
253
|
+
async function ee(e) {
|
|
254
|
+
const { walletClient: t, prepared: n } = e;
|
|
214
255
|
if (!t.account) throw new Error("Wallet client account is required for signing");
|
|
215
|
-
return await
|
|
256
|
+
return await ie({
|
|
216
257
|
walletClient: t,
|
|
217
|
-
desiredChainId:
|
|
218
|
-
}), await
|
|
219
|
-
signature: await
|
|
258
|
+
desiredChainId: n.chainId
|
|
259
|
+
}), await K(t), {
|
|
260
|
+
signature: await V(t.signTypedData({
|
|
220
261
|
account: t.account,
|
|
221
|
-
...
|
|
262
|
+
...n.typedData
|
|
222
263
|
}), "Recovery signature"),
|
|
223
264
|
signerAddress: t.account.address,
|
|
224
|
-
payload:
|
|
225
|
-
refundCall:
|
|
265
|
+
payload: n.payload,
|
|
266
|
+
refundCall: n.refundCall
|
|
226
267
|
};
|
|
227
268
|
}
|
|
228
|
-
|
|
229
|
-
|
|
269
|
+
var Re = 2e3, Ee = 6e4;
|
|
270
|
+
function Ce(e) {
|
|
271
|
+
return new Promise((t) => setTimeout(t, e));
|
|
272
|
+
}
|
|
273
|
+
function xe(e) {
|
|
274
|
+
return typeof e == "string" && /^0x[0-9a-fA-F]{64}$/.test(e);
|
|
275
|
+
}
|
|
276
|
+
function _(e) {
|
|
277
|
+
if (xe(e)) return e;
|
|
278
|
+
if (typeof e == "string" && /^[0-9a-fA-F]{64}$/.test(e)) return `0x${e}`;
|
|
279
|
+
}
|
|
280
|
+
function P(e, t) {
|
|
281
|
+
let n = e;
|
|
282
|
+
for (const r of t) {
|
|
283
|
+
if (!n || typeof n != "object" || !(r in n)) return;
|
|
284
|
+
n = n[r];
|
|
285
|
+
}
|
|
286
|
+
return n;
|
|
287
|
+
}
|
|
288
|
+
function ne(e) {
|
|
289
|
+
const t = _(e);
|
|
290
|
+
if (t) return t;
|
|
291
|
+
const n = e, r = [
|
|
292
|
+
n?.data?.txHash,
|
|
293
|
+
n?.data?.nativeReceipt && P(n.data.nativeReceipt, ["transactionHash"]),
|
|
294
|
+
n?.data?.nativeReceipt && P(n.data.nativeReceipt, ["hash"]),
|
|
295
|
+
n?.data?.receipt && P(n.data.receipt, ["txHash"]),
|
|
296
|
+
n?.data?.receipt && P(n.data.receipt, ["transactionHash"]),
|
|
297
|
+
n?.response && ne(n.response)
|
|
298
|
+
];
|
|
299
|
+
for (const o of r) {
|
|
300
|
+
const a = _(o);
|
|
301
|
+
if (a) return a;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function te(e) {
|
|
305
|
+
if (!e || typeof e != "object") return;
|
|
306
|
+
const t = e;
|
|
307
|
+
return t.data?.metaTxHash ?? (t.response ? te(t.response) : void 0);
|
|
308
|
+
}
|
|
309
|
+
async function He(e) {
|
|
310
|
+
const { accountAddress: t, chainId: n, sentAtMs: r, pollingConfig: o } = e, a = o?.apiKey, s = o?.indexerUrl;
|
|
311
|
+
if (!a || !s) return null;
|
|
312
|
+
const i = de(n, s);
|
|
313
|
+
if (!i) return null;
|
|
314
|
+
const d = new we(i, a), c = D(n), u = Date.now();
|
|
315
|
+
for (; Date.now() - u < Ee; ) {
|
|
316
|
+
try {
|
|
317
|
+
const l = await d.getTransactionHistory({
|
|
318
|
+
filter: { accountAddress: B(t) },
|
|
319
|
+
includeMetadata: !1,
|
|
320
|
+
page: {
|
|
321
|
+
page: 1,
|
|
322
|
+
pageSize: 20
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
for (const v of l.transactions ?? []) {
|
|
326
|
+
const y = _(v.txnHash);
|
|
327
|
+
if (!y) continue;
|
|
328
|
+
const w = await c.getTransactionReceipt({ hash: y }).catch(() => null);
|
|
329
|
+
if (!w) continue;
|
|
330
|
+
const T = await c.getBlock({ blockNumber: w.blockNumber }).catch(() => null), g = T ? Number(T.timestamp) * 1e3 : 0;
|
|
331
|
+
if (!(g && g < r - 3e4))
|
|
332
|
+
return {
|
|
333
|
+
txHash: y,
|
|
334
|
+
receipt: w
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
} catch (l) {
|
|
338
|
+
k.console.warn("[recover] Failed to poll Sequence indexer for recovery tx hash", { error: l instanceof Error ? l.message : String(l) });
|
|
339
|
+
}
|
|
340
|
+
await Ce(Re);
|
|
341
|
+
}
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
async function Se(e) {
|
|
345
|
+
const { sendResult: t, trailsWalletClient: n, recoverTx: r, sentAtMs: o, pollingConfig: a } = e, s = D(r.chainId), i = ne(t);
|
|
346
|
+
if (i) return {
|
|
347
|
+
txHash: i,
|
|
348
|
+
receipt: await s.waitForTransactionReceipt({ hash: i })
|
|
349
|
+
};
|
|
350
|
+
const d = te(t);
|
|
351
|
+
k.console.warn("[recover] Recovery send returned no transaction hash; polling for mined transaction", { metaTxHash: d });
|
|
352
|
+
const c = await He({
|
|
353
|
+
accountAddress: n.account.address,
|
|
354
|
+
chainId: r.chainId,
|
|
355
|
+
sentAtMs: o,
|
|
356
|
+
pollingConfig: a
|
|
357
|
+
});
|
|
358
|
+
if (c) return c;
|
|
359
|
+
throw new Error("Recovery transaction was submitted, but the final transaction hash was not available yet. Please refresh transaction history in a moment.");
|
|
360
|
+
}
|
|
361
|
+
async function re(e) {
|
|
362
|
+
const { trailsWalletClient: t, recoverTx: n, trailsClient: r, intentId: o, pollingConfig: a, onTransactionSubmitted: s } = e;
|
|
230
363
|
if (!t.account) throw new Error("Wallet client with account is required for recovery");
|
|
231
|
-
const
|
|
364
|
+
const i = Date.now(), d = await t.sendTransaction({
|
|
232
365
|
account: t.account,
|
|
233
|
-
to:
|
|
234
|
-
data:
|
|
235
|
-
chain:
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
366
|
+
to: n.to,
|
|
367
|
+
data: n.data,
|
|
368
|
+
chain: n.chain
|
|
369
|
+
});
|
|
370
|
+
s?.();
|
|
371
|
+
const { txHash: c, receipt: u } = await Se({
|
|
372
|
+
sendResult: d,
|
|
373
|
+
trailsWalletClient: t,
|
|
374
|
+
recoverTx: n,
|
|
375
|
+
sentAtMs: i,
|
|
376
|
+
pollingConfig: a
|
|
377
|
+
});
|
|
378
|
+
if (o && r) try {
|
|
379
|
+
await ce(r, o, n.chainId, c);
|
|
380
|
+
} catch (l) {
|
|
381
|
+
k.console.error("[recover] Failed to abort intent after recovery:", {
|
|
382
|
+
error: l instanceof Error ? l.message : String(l),
|
|
242
383
|
intentId: o,
|
|
243
|
-
chainId:
|
|
244
|
-
txHash:
|
|
384
|
+
chainId: n.chainId,
|
|
385
|
+
txHash: c
|
|
245
386
|
});
|
|
246
387
|
}
|
|
247
388
|
return {
|
|
248
|
-
txHash:
|
|
249
|
-
receipt:
|
|
250
|
-
chainId:
|
|
389
|
+
txHash: c,
|
|
390
|
+
receipt: u,
|
|
391
|
+
chainId: n.chainId
|
|
251
392
|
};
|
|
252
393
|
}
|
|
253
|
-
function
|
|
254
|
-
const { selectedIntentAddress: t, refundToAddress:
|
|
394
|
+
function Be(e) {
|
|
395
|
+
const { selectedIntentAddress: t, refundToAddress: n } = e, r = [], o = t.tokenBalancesData?.tokens ?? [];
|
|
255
396
|
for (const a of o) {
|
|
256
397
|
const s = a.balance ?? "0", i = BigInt(s);
|
|
257
398
|
if (i <= 0n) continue;
|
|
258
|
-
const d = a.isNativeToken === !0,
|
|
259
|
-
if (!d && !
|
|
260
|
-
|
|
399
|
+
const d = a.isNativeToken === !0, c = a.contractAddress;
|
|
400
|
+
if (!d && !c) {
|
|
401
|
+
k.console.warn("[recover] Skipping invalid recovery token: missing contractAddress for non-native token", {
|
|
261
402
|
symbol: a.symbol || "unknown",
|
|
262
403
|
balance: s,
|
|
263
404
|
chainId: t.chainId,
|
|
@@ -265,10 +406,10 @@ function he(e) {
|
|
|
265
406
|
});
|
|
266
407
|
continue;
|
|
267
408
|
}
|
|
268
|
-
const
|
|
409
|
+
const u = c || E;
|
|
269
410
|
if (d) {
|
|
270
|
-
|
|
271
|
-
to:
|
|
411
|
+
r.push({
|
|
412
|
+
to: n,
|
|
272
413
|
value: i,
|
|
273
414
|
data: "0x",
|
|
274
415
|
gasLimit: 0n,
|
|
@@ -278,12 +419,12 @@ function he(e) {
|
|
|
278
419
|
});
|
|
279
420
|
continue;
|
|
280
421
|
}
|
|
281
|
-
let
|
|
422
|
+
let l;
|
|
282
423
|
try {
|
|
283
|
-
|
|
424
|
+
l = f.from(u);
|
|
284
425
|
} catch {
|
|
285
|
-
|
|
286
|
-
contractAddress:
|
|
426
|
+
k.console.warn("[recover] Skipping invalid recovery token: malformed contractAddress", {
|
|
427
|
+
contractAddress: u,
|
|
287
428
|
symbol: a.symbol || "unknown",
|
|
288
429
|
balance: s,
|
|
289
430
|
chainId: t.chainId,
|
|
@@ -291,67 +432,62 @@ function he(e) {
|
|
|
291
432
|
});
|
|
292
433
|
continue;
|
|
293
434
|
}
|
|
294
|
-
|
|
295
|
-
to:
|
|
435
|
+
r.push({
|
|
436
|
+
to: l,
|
|
296
437
|
value: 0n,
|
|
297
|
-
data:
|
|
438
|
+
data: se(n, i),
|
|
298
439
|
gasLimit: 0n,
|
|
299
440
|
delegateCall: !1,
|
|
300
441
|
onlyFallback: !1,
|
|
301
442
|
behaviorOnError: "revert"
|
|
302
443
|
});
|
|
303
444
|
}
|
|
304
|
-
if (
|
|
445
|
+
if (r.length === 0) throw new Error("No recoverable token balances found on selected intent");
|
|
305
446
|
return {
|
|
306
447
|
payload: {
|
|
307
448
|
type: "call",
|
|
308
|
-
space:
|
|
449
|
+
space: be(),
|
|
309
450
|
nonce: 0n,
|
|
310
|
-
calls:
|
|
451
|
+
calls: r
|
|
311
452
|
},
|
|
312
|
-
refundCall:
|
|
453
|
+
refundCall: r[0]
|
|
313
454
|
};
|
|
314
455
|
}
|
|
315
|
-
async function
|
|
316
|
-
const { keyMachineClient: t, selected:
|
|
456
|
+
async function Pe(e) {
|
|
457
|
+
const { keyMachineClient: t, selected: n, signerAddress: r, signature: o, payload: a } = e, s = n.intentAddress, i = n.chainId, d = L(i);
|
|
317
458
|
if (!d) throw new Error(`Chain info not found for chain ID: ${i}`);
|
|
318
|
-
const
|
|
319
|
-
if (!
|
|
320
|
-
const
|
|
321
|
-
if (!
|
|
322
|
-
const
|
|
323
|
-
let
|
|
324
|
-
const
|
|
325
|
-
if (f.isEqual(f.from(
|
|
326
|
-
return
|
|
327
|
-
type: "hash",
|
|
328
|
-
r: BigInt(k.r),
|
|
329
|
-
s: BigInt(k.s),
|
|
330
|
-
yParity: k.yParity
|
|
331
|
-
};
|
|
459
|
+
const c = await ve(s, i), u = await t.getDeploy(s);
|
|
460
|
+
if (!u) throw new Error("Deploy config not found for intent address");
|
|
461
|
+
const l = await t.getConfiguration(u.imageHash);
|
|
462
|
+
if (!l) throw new Error("Configuration not found for intent address");
|
|
463
|
+
const v = Ae(o, r);
|
|
464
|
+
let y = !1;
|
|
465
|
+
const w = U.fillLeaves(l.topology, (h) => {
|
|
466
|
+
if (f.isEqual(f.from(h.address), f.from(r)))
|
|
467
|
+
return y = !0, v;
|
|
332
468
|
});
|
|
333
|
-
if (!
|
|
334
|
-
const T =
|
|
469
|
+
if (!y) throw new Error(`Signer ${r} is not an authorized signer for intent wallet ${s}. Connect the correct wallet to recover.`);
|
|
470
|
+
const T = U.encodeSignature({
|
|
335
471
|
noChainId: !1,
|
|
336
472
|
configuration: {
|
|
337
|
-
threshold:
|
|
338
|
-
checkpoint:
|
|
339
|
-
checkpointer:
|
|
340
|
-
topology:
|
|
473
|
+
threshold: l.threshold,
|
|
474
|
+
checkpoint: l.checkpoint,
|
|
475
|
+
checkpointer: l.checkpointer,
|
|
476
|
+
topology: w
|
|
341
477
|
}
|
|
342
|
-
}),
|
|
343
|
-
if (!
|
|
344
|
-
const
|
|
478
|
+
}), g = pe.encodeData(O.EXECUTE, [H.toHex(R.encode(a)), H.toHex(T)]);
|
|
479
|
+
if (!c) {
|
|
480
|
+
const h = ye.deploy(u.imageHash, u.context), x = O.DefaultGuestAddress;
|
|
345
481
|
return {
|
|
346
|
-
to:
|
|
347
|
-
data:
|
|
482
|
+
to: x,
|
|
483
|
+
data: H.toHex(R.encode({
|
|
348
484
|
type: "call",
|
|
349
485
|
space: 0n,
|
|
350
486
|
nonce: 0n,
|
|
351
487
|
calls: [{
|
|
352
|
-
to:
|
|
488
|
+
to: h.to,
|
|
353
489
|
value: 0n,
|
|
354
|
-
data:
|
|
490
|
+
data: h.data,
|
|
355
491
|
gasLimit: 0n,
|
|
356
492
|
delegateCall: !1,
|
|
357
493
|
onlyFallback: !1,
|
|
@@ -359,119 +495,126 @@ async function ge(e) {
|
|
|
359
495
|
}, {
|
|
360
496
|
to: s,
|
|
361
497
|
value: 0n,
|
|
362
|
-
data:
|
|
498
|
+
data: g,
|
|
363
499
|
gasLimit: 0n,
|
|
364
500
|
delegateCall: !1,
|
|
365
501
|
onlyFallback: !1,
|
|
366
502
|
behaviorOnError: "revert"
|
|
367
503
|
}]
|
|
368
|
-
},
|
|
504
|
+
}, x)),
|
|
369
505
|
chainId: i,
|
|
370
506
|
chain: d
|
|
371
507
|
};
|
|
372
508
|
}
|
|
373
509
|
return {
|
|
374
510
|
to: s,
|
|
375
|
-
data:
|
|
511
|
+
data: g,
|
|
376
512
|
chainId: i,
|
|
377
513
|
chain: d
|
|
378
514
|
};
|
|
379
515
|
}
|
|
380
|
-
function
|
|
381
|
-
const
|
|
516
|
+
function tn({ intent: e, balancesByIntentAddress: t, walletClient: n, refundToAddress: r, keyMachineClient: o, onTransactionSubmitted: a }) {
|
|
517
|
+
const s = ge(), i = o ?? s, d = M(), { sequenceIndexerUrl: c, trailsApiKey: u } = fe(), l = I(() => ({
|
|
518
|
+
apiKey: u,
|
|
519
|
+
indexerUrl: c
|
|
520
|
+
}), [u, c]), v = I(() => n ? G(n) : void 0, [n]), y = e?.originIntentAddress ? t[B(e.originIntentAddress)]?.tokenBalancesData : void 0, w = e?.destinationIntentAddress ? t[B(e.destinationIntentAddress)]?.tokenBalancesData : void 0, T = e?.originIntentAddress ? f.from(e.originIntentAddress) : null, g = e?.destinationIntentAddress ? f.from(e.destinationIntentAddress) : null, h = I(() => e ? j(e, y, w, T, g) : null, [
|
|
382
521
|
e,
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
]),
|
|
388
|
-
const
|
|
389
|
-
return !
|
|
390
|
-
}, [
|
|
391
|
-
if (!
|
|
392
|
-
|
|
393
|
-
const { payload:
|
|
394
|
-
selectedIntentAddress:
|
|
395
|
-
refundToAddress:
|
|
522
|
+
y,
|
|
523
|
+
w,
|
|
524
|
+
T,
|
|
525
|
+
g
|
|
526
|
+
]), x = I(() => X(y, w), [y, w]), b = I(() => Y(h), [h]), q = I(() => Z(h), [h]), S = I(() => {
|
|
527
|
+
const p = r || v?.account?.address;
|
|
528
|
+
return !p || f.isEqual(p, E) ? null : p;
|
|
529
|
+
}, [r, v?.account?.address]), C = A(async () => {
|
|
530
|
+
if (!h) throw new Error("No intent address selected for recovery");
|
|
531
|
+
J(S);
|
|
532
|
+
const { payload: p, refundCall: N } = Be({
|
|
533
|
+
selectedIntentAddress: h,
|
|
534
|
+
refundToAddress: S
|
|
396
535
|
});
|
|
397
536
|
return {
|
|
398
|
-
payload:
|
|
399
|
-
refundCall:
|
|
400
|
-
chainId:
|
|
401
|
-
typedData:
|
|
537
|
+
payload: p,
|
|
538
|
+
refundCall: N,
|
|
539
|
+
chainId: h.chainId,
|
|
540
|
+
typedData: R.toTyped(h.intentAddress, h.chainId, p)
|
|
402
541
|
};
|
|
403
|
-
}, [
|
|
404
|
-
if (!
|
|
405
|
-
return
|
|
406
|
-
walletClient:
|
|
407
|
-
prepared:
|
|
542
|
+
}, [h, S]), m = A(async (p) => {
|
|
543
|
+
if (!v?.account) throw new Error("Wallet client with account is required for recovery");
|
|
544
|
+
return ee({
|
|
545
|
+
walletClient: v,
|
|
546
|
+
prepared: p ?? await C()
|
|
408
547
|
});
|
|
409
|
-
}, [
|
|
410
|
-
if (!
|
|
411
|
-
return
|
|
412
|
-
keyMachineClient:
|
|
413
|
-
selected:
|
|
414
|
-
signerAddress:
|
|
415
|
-
signature:
|
|
416
|
-
payload:
|
|
548
|
+
}, [v, C]), F = A(async (p) => {
|
|
549
|
+
if (!h) throw new Error("No intent address selected for recovery");
|
|
550
|
+
return Pe({
|
|
551
|
+
keyMachineClient: i,
|
|
552
|
+
selected: h,
|
|
553
|
+
signerAddress: p.signerAddress,
|
|
554
|
+
signature: p.signature,
|
|
555
|
+
payload: p.payload
|
|
417
556
|
});
|
|
418
|
-
}, [
|
|
557
|
+
}, [h, i]);
|
|
419
558
|
return {
|
|
420
559
|
intent: e,
|
|
421
|
-
hasIntentBalance:
|
|
422
|
-
recoverToken:
|
|
423
|
-
selectedRecoveryTarget:
|
|
560
|
+
hasIntentBalance: x,
|
|
561
|
+
recoverToken: b,
|
|
562
|
+
selectedRecoveryTarget: q,
|
|
424
563
|
signPayload: m,
|
|
425
|
-
getDataToSign:
|
|
426
|
-
getRecoverTx:
|
|
427
|
-
recover:
|
|
428
|
-
if (!
|
|
429
|
-
const { signature:
|
|
430
|
-
return
|
|
431
|
-
trailsWalletClient:
|
|
432
|
-
recoverTx: await
|
|
433
|
-
signature:
|
|
434
|
-
signerAddress:
|
|
435
|
-
payload:
|
|
564
|
+
getDataToSign: C,
|
|
565
|
+
getRecoverTx: F,
|
|
566
|
+
recover: A(async () => {
|
|
567
|
+
if (!v?.account) throw new Error("Wallet client with account is required for recovery");
|
|
568
|
+
const { signature: p, signerAddress: N, payload: oe } = await m(await C());
|
|
569
|
+
return re({
|
|
570
|
+
trailsWalletClient: v,
|
|
571
|
+
recoverTx: await F({
|
|
572
|
+
signature: p,
|
|
573
|
+
signerAddress: N,
|
|
574
|
+
payload: oe
|
|
436
575
|
}),
|
|
437
|
-
trailsClient:
|
|
438
|
-
intentId: e?.intentId
|
|
576
|
+
trailsClient: d,
|
|
577
|
+
intentId: e?.intentId,
|
|
578
|
+
pollingConfig: l,
|
|
579
|
+
onTransactionSubmitted: a
|
|
439
580
|
});
|
|
440
581
|
}, [
|
|
441
|
-
|
|
442
|
-
g,
|
|
443
|
-
m,
|
|
582
|
+
v,
|
|
444
583
|
C,
|
|
445
|
-
|
|
446
|
-
|
|
584
|
+
m,
|
|
585
|
+
F,
|
|
586
|
+
d,
|
|
587
|
+
e?.intentId,
|
|
588
|
+
l,
|
|
589
|
+
a
|
|
447
590
|
]),
|
|
448
|
-
getRecoverStatus:
|
|
591
|
+
getRecoverStatus: A((p) => Q(p), [])
|
|
449
592
|
};
|
|
450
593
|
}
|
|
451
|
-
function
|
|
452
|
-
const
|
|
594
|
+
function rn({ intentId: e, walletClient: t, refundToAddress: n }) {
|
|
595
|
+
const r = M(), o = I(() => t ? G(t) : void 0, [t]), a = o?.account?.address, s = De({
|
|
453
596
|
intentId: e,
|
|
454
597
|
walletAddress: a,
|
|
455
|
-
refundToAddress:
|
|
456
|
-
}), i =
|
|
598
|
+
refundToAddress: n || a
|
|
599
|
+
}), i = A(async () => {
|
|
457
600
|
if (!o?.account) throw new Error("Intent data and wallet client with account required");
|
|
458
|
-
return
|
|
601
|
+
return ee({
|
|
459
602
|
walletClient: o,
|
|
460
603
|
prepared: await s.getDataToSign()
|
|
461
604
|
});
|
|
462
|
-
}, [o, s]), d =
|
|
463
|
-
signature:
|
|
464
|
-
payload:
|
|
465
|
-
}), [s]),
|
|
605
|
+
}, [o, s]), d = A(async (u) => s.getRecoverTx({
|
|
606
|
+
signature: u.signedHash,
|
|
607
|
+
payload: u.payload
|
|
608
|
+
}), [s]), c = A(async () => {
|
|
466
609
|
if (!o?.account) throw new Error("Intent data and wallet client with account required");
|
|
467
|
-
const { signature:
|
|
468
|
-
return
|
|
610
|
+
const { signature: u, payload: l } = await i();
|
|
611
|
+
return re({
|
|
469
612
|
trailsWalletClient: o,
|
|
470
613
|
recoverTx: await d({
|
|
471
|
-
signedHash:
|
|
472
|
-
payload:
|
|
614
|
+
signedHash: u,
|
|
615
|
+
payload: l
|
|
473
616
|
}),
|
|
474
|
-
trailsClient:
|
|
617
|
+
trailsClient: r,
|
|
475
618
|
intentId: e
|
|
476
619
|
});
|
|
477
620
|
}, [
|
|
@@ -479,159 +622,82 @@ function Ne({ intentId: e, walletClient: t, refundToAddress: r }) {
|
|
|
479
622
|
d,
|
|
480
623
|
o,
|
|
481
624
|
e,
|
|
482
|
-
|
|
625
|
+
r
|
|
483
626
|
]);
|
|
484
627
|
return {
|
|
485
628
|
...s,
|
|
486
629
|
signPayload: i,
|
|
487
630
|
getRecoverTx: d,
|
|
488
|
-
recover:
|
|
631
|
+
recover: c
|
|
489
632
|
};
|
|
490
633
|
}
|
|
491
|
-
function
|
|
492
|
-
const { intent:
|
|
634
|
+
function De({ intentId: e, walletAddress: t, refundToAddress: n }) {
|
|
635
|
+
const { intent: r, isLoading: o, error: a, refetch: s } = he({
|
|
493
636
|
intentId: e,
|
|
494
637
|
enabled: !!e
|
|
495
|
-
}), i =
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
638
|
+
}), i = M(), d = r?.originIntentAddress ? f.from(r.originIntentAddress) : null, c = r?.destinationIntentAddress ? f.from(r.destinationIntentAddress) : null, { balancesByAccount: u, isLoading: l, error: v } = ue([d, c], { refetchInterval: le }), y = d ? u[B(d)]?.tokenBalancesData : void 0, w = c ? u[B(c)]?.tokenBalancesData : void 0, T = v, g = I(() => r ? j(r, y, w, d, c) : null, [
|
|
639
|
+
r,
|
|
640
|
+
y,
|
|
641
|
+
w,
|
|
499
642
|
d,
|
|
500
|
-
|
|
501
|
-
]),
|
|
502
|
-
const
|
|
503
|
-
return !
|
|
504
|
-
}, [
|
|
505
|
-
if (!
|
|
506
|
-
if (!
|
|
507
|
-
if (f.isEqual(
|
|
508
|
-
if (!
|
|
509
|
-
return
|
|
643
|
+
c
|
|
644
|
+
]), h = I(() => X(y, w), [y, w]), x = I(() => Y(g), [g]), b = I(() => {
|
|
645
|
+
const m = n ?? t;
|
|
646
|
+
return !m || f.isEqual(m, E) ? null : m;
|
|
647
|
+
}, [n, t]), q = A(async () => {
|
|
648
|
+
if (!r) throw new Error("Intent data required");
|
|
649
|
+
if (!b) throw new Error("Refund address required. Provide refundToAddress or walletAddress");
|
|
650
|
+
if (f.isEqual(b, E)) throw new Error("Refund address cannot be zero address");
|
|
651
|
+
if (!g) throw new Error("No intent address selected for recovery");
|
|
652
|
+
return ke({
|
|
510
653
|
trailsClient: i,
|
|
511
|
-
intentData:
|
|
512
|
-
selectedIntentAddress:
|
|
513
|
-
effectiveRefundAddress:
|
|
654
|
+
intentData: r,
|
|
655
|
+
selectedIntentAddress: g,
|
|
656
|
+
effectiveRefundAddress: b
|
|
514
657
|
});
|
|
515
658
|
}, [
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
659
|
+
r,
|
|
660
|
+
g,
|
|
661
|
+
b,
|
|
519
662
|
i
|
|
520
|
-
]),
|
|
521
|
-
if (!
|
|
522
|
-
if (!
|
|
523
|
-
return
|
|
663
|
+
]), S = A(async (m) => {
|
|
664
|
+
if (!r) throw new Error("Intent data required");
|
|
665
|
+
if (!g) throw new Error("No intent address selected for recovery");
|
|
666
|
+
return Te({
|
|
524
667
|
trailsClient: i,
|
|
525
|
-
intentData:
|
|
526
|
-
selected:
|
|
527
|
-
effectiveRefundAddress:
|
|
528
|
-
signature:
|
|
529
|
-
payload:
|
|
668
|
+
intentData: r,
|
|
669
|
+
selected: g,
|
|
670
|
+
effectiveRefundAddress: b,
|
|
671
|
+
signature: m.signature,
|
|
672
|
+
payload: m.payload
|
|
530
673
|
});
|
|
531
674
|
}, [
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
675
|
+
r,
|
|
676
|
+
g,
|
|
677
|
+
b,
|
|
535
678
|
i
|
|
536
|
-
]),
|
|
679
|
+
]), C = A((m) => Q(m), []);
|
|
537
680
|
return {
|
|
538
|
-
intent:
|
|
681
|
+
intent: r,
|
|
539
682
|
isLoadingIntent: o,
|
|
540
|
-
isLoadingBalances:
|
|
683
|
+
isLoadingBalances: l,
|
|
541
684
|
intentError: a,
|
|
542
685
|
balancesError: T,
|
|
543
|
-
hasIntentBalance: A,
|
|
544
|
-
recoverToken: g,
|
|
545
|
-
selectedRecoveryTarget: w(() => M(v), [v]),
|
|
546
|
-
refetchIntent: s,
|
|
547
|
-
getDataToSign: C,
|
|
548
|
-
getRecoverTx: y,
|
|
549
|
-
getRecoverStatus: S
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
function Le({ intent: e, balancesByIntentAddress: t, walletClient: r, refundToAddress: n }) {
|
|
553
|
-
const o = H(), a = w(() => r ? W(r) : void 0, [r]), s = e?.originIntentAddress ? t[x(e.originIntentAddress)]?.tokenBalancesData : void 0, i = e?.destinationIntentAddress ? t[x(e.destinationIntentAddress)]?.tokenBalancesData : void 0, d = e?.originIntentAddress ? f.from(e.originIntentAddress) : null, l = e?.destinationIntentAddress ? f.from(e.destinationIntentAddress) : null, c = w(() => e ? N(e, s, i, d, l) : null, [
|
|
554
|
-
e,
|
|
555
|
-
s,
|
|
556
|
-
i,
|
|
557
|
-
d,
|
|
558
|
-
l
|
|
559
|
-
]), h = w(() => L(s, i), [s, i]), k = w(() => _(c), [c]), u = w(() => {
|
|
560
|
-
const g = n || a?.account?.address;
|
|
561
|
-
return !g || f.isEqual(g, R) ? null : g;
|
|
562
|
-
}, [n, a?.account?.address]), p = I(async () => {
|
|
563
|
-
if (!e || !a?.account) throw new Error("Intent data and wallet client with account required");
|
|
564
|
-
if (O(u), !c) throw new Error("No intent address selected for recovery");
|
|
565
|
-
return U({
|
|
566
|
-
walletClient: a,
|
|
567
|
-
prepared: await Y({
|
|
568
|
-
trailsClient: o,
|
|
569
|
-
intentData: e,
|
|
570
|
-
selectedIntentAddress: c,
|
|
571
|
-
effectiveRefundAddress: u
|
|
572
|
-
})
|
|
573
|
-
});
|
|
574
|
-
}, [
|
|
575
|
-
e,
|
|
576
|
-
a,
|
|
577
|
-
c,
|
|
578
|
-
u,
|
|
579
|
-
o
|
|
580
|
-
]), T = I(async (g) => {
|
|
581
|
-
if (!e) throw new Error("Intent data required");
|
|
582
|
-
if (!c) throw new Error("No intent address selected for recovery");
|
|
583
|
-
return Q({
|
|
584
|
-
trailsClient: o,
|
|
585
|
-
intentData: e,
|
|
586
|
-
selected: c,
|
|
587
|
-
effectiveRefundAddress: u,
|
|
588
|
-
signature: g.signedHash,
|
|
589
|
-
payload: g.payload
|
|
590
|
-
});
|
|
591
|
-
}, [
|
|
592
|
-
e,
|
|
593
|
-
c,
|
|
594
|
-
u,
|
|
595
|
-
o
|
|
596
|
-
]), v = I(async () => {
|
|
597
|
-
if (!a?.account) throw new Error("Wallet client with account is required for recovery");
|
|
598
|
-
if (!e) throw new Error("Intent data is required for recovery");
|
|
599
|
-
const { signature: g, payload: m } = await p(), { txHash: C } = await D({
|
|
600
|
-
trailsWalletClient: a,
|
|
601
|
-
recoverTx: await T({
|
|
602
|
-
signedHash: g,
|
|
603
|
-
payload: m
|
|
604
|
-
}),
|
|
605
|
-
trailsClient: o,
|
|
606
|
-
intentId: e.intentId
|
|
607
|
-
});
|
|
608
|
-
return { txHash: C };
|
|
609
|
-
}, [
|
|
610
|
-
a,
|
|
611
|
-
e,
|
|
612
|
-
p,
|
|
613
|
-
T,
|
|
614
|
-
o
|
|
615
|
-
]), A = I((g) => z(g), []);
|
|
616
|
-
return {
|
|
617
|
-
intent: e,
|
|
618
686
|
hasIntentBalance: h,
|
|
619
|
-
recoverToken:
|
|
620
|
-
selectedRecoveryTarget:
|
|
621
|
-
refetchIntent:
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
recover: v,
|
|
626
|
-
getRecoverStatus: A
|
|
687
|
+
recoverToken: x,
|
|
688
|
+
selectedRecoveryTarget: I(() => Z(g), [g]),
|
|
689
|
+
refetchIntent: s,
|
|
690
|
+
getDataToSign: q,
|
|
691
|
+
getRecoverTx: S,
|
|
692
|
+
getRecoverStatus: C
|
|
627
693
|
};
|
|
628
694
|
}
|
|
629
695
|
export {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
696
|
+
nn as buildRefundTransactionWithSignature,
|
|
697
|
+
ve as isAddressDeployed,
|
|
698
|
+
Ae as recoverySignatureForSigner,
|
|
699
|
+
en as signPayload,
|
|
700
|
+
rn as useIntentRecover,
|
|
701
|
+
De as useIntentRecoverWithAddress,
|
|
702
|
+
tn as useKeymachineIntentRecovery
|
|
637
703
|
};
|