@babylonlabs-io/ts-sdk 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PayoutManager-9qwA76_B.cjs +2 -0
- package/dist/PayoutManager-9qwA76_B.cjs.map +1 -0
- package/dist/{PayoutManager-BVmU4UsM.js → PayoutManager-CvWBwdzd.js} +178 -204
- package/dist/PayoutManager-CvWBwdzd.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +72 -70
- package/dist/index.js.map +1 -1
- package/dist/shared/index.cjs +1 -1
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +5 -3
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/wallets/__tests__/signOptions.test.d.ts +2 -0
- package/dist/shared/wallets/__tests__/signOptions.test.d.ts.map +1 -0
- package/dist/shared/wallets/index.d.ts +1 -0
- package/dist/shared/wallets/index.d.ts.map +1 -1
- package/dist/shared/wallets/signOptions.d.ts +15 -0
- package/dist/shared/wallets/signOptions.d.ts.map +1 -0
- package/dist/signOptions-Deg5lCoC.cjs +2 -0
- package/dist/signOptions-Deg5lCoC.cjs.map +1 -0
- package/dist/signOptions-Drwr3bXB.js +16 -0
- package/dist/signOptions-Drwr3bXB.js.map +1 -0
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +1 -1
- package/dist/tbv/core/managers/PayoutManager.d.ts +1 -1
- package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts +1 -2
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +1 -1
- package/dist/tbv/integrations/aave/clients/abis/{AaveIntegrationController.abi.json.d.ts → AaveIntegrationAdapter.abi.json.d.ts} +39 -2
- package/dist/tbv/integrations/aave/clients/index.d.ts +1 -1
- package/dist/tbv/integrations/aave/clients/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/clients/query.d.ts +3 -3
- package/dist/tbv/integrations/aave/clients/transaction.d.ts +19 -7
- package/dist/tbv/integrations/aave/clients/transaction.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/constants.d.ts +2 -0
- package/dist/tbv/integrations/aave/constants.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.cjs +1 -1
- package/dist/tbv/integrations/aave/index.cjs.map +1 -1
- package/dist/tbv/integrations/aave/index.d.ts +6 -6
- package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.js +141 -94
- package/dist/tbv/integrations/aave/index.js.map +1 -1
- package/dist/tbv/integrations/aave/types.d.ts +1 -1
- package/dist/tbv/integrations/aave/utils/__tests__/seizureSimulation.test.d.ts +5 -0
- package/dist/tbv/integrations/aave/utils/__tests__/seizureSimulation.test.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/index.d.ts +2 -0
- package/dist/tbv/integrations/aave/utils/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/utils/seizureSimulation.d.ts +109 -0
- package/dist/tbv/integrations/aave/utils/seizureSimulation.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/vaultSplit.d.ts +1 -0
- package/dist/tbv/integrations/aave/utils/vaultSplit.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/PayoutManager-BVmU4UsM.js.map +0 -1
- package/dist/PayoutManager-Ba6cNgHC.cjs +0 -2
- package/dist/PayoutManager-Ba6cNgHC.cjs.map +0 -1
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import * as
|
|
5
|
-
import { script as
|
|
1
|
+
var L = Object.defineProperty;
|
|
2
|
+
var j = (n, t, e) => t in n ? L(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
+
var I = (n, t, e) => j(n, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import * as J from "bitcoinjs-lib";
|
|
5
|
+
import { script as Z, Transaction as B, address as G, Psbt as C } from "bitcoinjs-lib";
|
|
6
6
|
import { Buffer as g } from "buffer";
|
|
7
|
-
import { P as
|
|
8
|
-
import { createPublicClient as
|
|
9
|
-
import {
|
|
10
|
-
|
|
7
|
+
import { P as Q, x as Y, D as q, M as V, B as tt, T as et, A as U, t as k, b as nt, z as rt, a as st, d as at, e as ot, f as it, r as H, p as ct, w as W, g as K, h as N } from "./challengeAssert-D50t_Qyo.js";
|
|
8
|
+
import { createPublicClient as M, http as X, encodeFunctionData as ut, zeroAddress as lt } from "viem";
|
|
9
|
+
import { c as O } from "./signOptions-Drwr3bXB.js";
|
|
10
|
+
import { SINGLE_DEPOSIT_HTLC_VOUT as D } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
11
|
+
function dt(n, t, e) {
|
|
11
12
|
if (n.length === 0)
|
|
12
13
|
throw new Error("Insufficient funds: no UTXOs available");
|
|
13
|
-
const
|
|
14
|
+
const r = n.filter((a) => {
|
|
14
15
|
const u = g.from(a.scriptPubKey, "hex");
|
|
15
|
-
return !!
|
|
16
|
+
return !!Z.decompile(u);
|
|
16
17
|
});
|
|
17
|
-
if (
|
|
18
|
+
if (r.length === 0)
|
|
18
19
|
throw new Error(
|
|
19
20
|
"Insufficient funds: no valid UTXOs available (all have invalid scripts)"
|
|
20
21
|
);
|
|
21
|
-
const o = [...
|
|
22
|
+
const o = [...r].sort((a, u) => u.value - a.value), s = [];
|
|
22
23
|
let c = 0n, i = 0n;
|
|
23
24
|
for (const a of o) {
|
|
24
|
-
|
|
25
|
-
const u =
|
|
26
|
-
if (i = BigInt(Math.ceil(p * e)) + BigInt(
|
|
25
|
+
s.push(a), c += BigInt(a.value);
|
|
26
|
+
const u = s.length * Q, l = 2 * V, p = u + l + et;
|
|
27
|
+
if (i = BigInt(Math.ceil(p * e)) + BigInt(Y(e)), c - t - i > q) {
|
|
27
28
|
const f = BigInt(
|
|
28
|
-
Math.ceil(
|
|
29
|
+
Math.ceil(V * e)
|
|
29
30
|
);
|
|
30
31
|
i += f;
|
|
31
32
|
}
|
|
32
33
|
if (c >= t + i) {
|
|
33
34
|
const f = c - t - i;
|
|
34
35
|
return {
|
|
35
|
-
selectedUTXOs:
|
|
36
|
+
selectedUTXOs: s,
|
|
36
37
|
totalValue: c,
|
|
37
38
|
fee: i,
|
|
38
39
|
changeAmount: f
|
|
@@ -43,17 +44,17 @@ function lt(n, t, e) {
|
|
|
43
44
|
`Insufficient funds: need ${t + i} sats (${t} pegin + ${i} fee), have ${c} sats`
|
|
44
45
|
);
|
|
45
46
|
}
|
|
46
|
-
function
|
|
47
|
-
return n >
|
|
47
|
+
function Et(n) {
|
|
48
|
+
return n > q;
|
|
48
49
|
}
|
|
49
|
-
function
|
|
50
|
-
return
|
|
50
|
+
function St() {
|
|
51
|
+
return tt;
|
|
51
52
|
}
|
|
52
|
-
function
|
|
53
|
+
function _(n) {
|
|
53
54
|
const t = n.startsWith("0x") ? n.slice(2) : n;
|
|
54
|
-
return `0x${
|
|
55
|
+
return `0x${B.fromHex(t).getId()}`;
|
|
55
56
|
}
|
|
56
|
-
function
|
|
57
|
+
function Bt(n, t, e) {
|
|
57
58
|
if (n.length === 0)
|
|
58
59
|
throw new Error("No input UTXOs provided for split transaction");
|
|
59
60
|
if (t.length === 0)
|
|
@@ -63,24 +64,24 @@ function Et(n, t, e) {
|
|
|
63
64
|
throw new Error(
|
|
64
65
|
`Invalid output amount for ${a.address}: ${a.amount} satoshis. Amount must be greater than zero.`
|
|
65
66
|
);
|
|
66
|
-
const
|
|
67
|
+
const r = U(e), o = new B();
|
|
67
68
|
o.version = 2;
|
|
68
69
|
for (const a of n) {
|
|
69
70
|
const u = g.from(a.txid, "hex").reverse();
|
|
70
71
|
o.addInput(u, a.vout);
|
|
71
72
|
}
|
|
72
|
-
const
|
|
73
|
+
const s = [];
|
|
73
74
|
for (let a = 0; a < t.length; a++) {
|
|
74
75
|
const u = t[a];
|
|
75
76
|
let l;
|
|
76
77
|
try {
|
|
77
|
-
l =
|
|
78
|
+
l = G.toOutputScript(u.address, r);
|
|
78
79
|
} catch (p) {
|
|
79
80
|
throw new Error(
|
|
80
81
|
`Failed to decode address "${u.address}": ${p instanceof Error ? p.message : String(p)}`
|
|
81
82
|
);
|
|
82
83
|
}
|
|
83
|
-
o.addOutput(l, Number(u.amount)),
|
|
84
|
+
o.addOutput(l, Number(u.amount)), s.push({
|
|
84
85
|
txid: "",
|
|
85
86
|
// Will be set after txid calculation
|
|
86
87
|
vout: a,
|
|
@@ -89,38 +90,38 @@ function Et(n, t, e) {
|
|
|
89
90
|
});
|
|
90
91
|
}
|
|
91
92
|
const c = o.toHex(), i = o.getId();
|
|
92
|
-
for (const a of
|
|
93
|
+
for (const a of s)
|
|
93
94
|
a.txid = i;
|
|
94
95
|
return {
|
|
95
96
|
txHex: c,
|
|
96
97
|
txid: i,
|
|
97
|
-
outputs:
|
|
98
|
+
outputs: s
|
|
98
99
|
};
|
|
99
100
|
}
|
|
100
|
-
function
|
|
101
|
-
const
|
|
102
|
-
if (o.setVersion(
|
|
101
|
+
function It(n, t, e) {
|
|
102
|
+
const r = B.fromHex(n), o = new C();
|
|
103
|
+
if (o.setVersion(r.version), o.setLocktime(r.locktime), !g.isBuffer(e) || e.length !== 32)
|
|
103
104
|
throw new Error(
|
|
104
105
|
`Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${g.isBuffer(e) ? `${e.length}-byte Buffer` : typeof e}`
|
|
105
106
|
);
|
|
106
|
-
if (t.length !==
|
|
107
|
+
if (t.length !== r.ins.length)
|
|
107
108
|
throw new Error(
|
|
108
|
-
`UTXO count mismatch: transaction has ${
|
|
109
|
+
`UTXO count mismatch: transaction has ${r.ins.length} input${r.ins.length !== 1 ? "s" : ""}, but ${t.length} UTXO${t.length !== 1 ? "s were" : " was"} provided`
|
|
109
110
|
);
|
|
110
|
-
for (let
|
|
111
|
-
const c =
|
|
111
|
+
for (let s = 0; s < r.ins.length; s++) {
|
|
112
|
+
const c = r.ins[s], i = t[s];
|
|
112
113
|
if (!i)
|
|
113
|
-
throw new Error(`Missing UTXO data for input ${
|
|
114
|
+
throw new Error(`Missing UTXO data for input ${s}`);
|
|
114
115
|
const a = g.from(c.hash).reverse().toString("hex"), u = c.index;
|
|
115
116
|
if (i.txid !== a || i.vout !== u)
|
|
116
117
|
throw new Error(
|
|
117
|
-
`Input ${
|
|
118
|
+
`Input ${s} outpoint mismatch: transaction expects ${a}:${u}, but UTXO ${i.txid}:${i.vout} was provided. Ensure inputs array matches the order used in createSplitTransaction().`
|
|
118
119
|
);
|
|
119
120
|
const l = g.from(i.scriptPubKey, "hex");
|
|
120
121
|
if (!(l.length === 34 && l[0] === 81 && // OP_1 (witness version 1)
|
|
121
122
|
l[1] === 32))
|
|
122
123
|
throw new Error(
|
|
123
|
-
`Input ${
|
|
124
|
+
`Input ${s} must be P2TR (Taproot). createSplitTransactionPsbt() requires P2TR inputs because it uses tapInternalKey for Taproot signing. ScriptPubKey: ${i.scriptPubKey.substring(0, 20)}...`
|
|
124
125
|
);
|
|
125
126
|
const h = {
|
|
126
127
|
script: g.from(i.scriptPubKey, "hex"),
|
|
@@ -134,15 +135,15 @@ function St(n, t, e) {
|
|
|
134
135
|
tapInternalKey: e
|
|
135
136
|
});
|
|
136
137
|
}
|
|
137
|
-
for (const
|
|
138
|
+
for (const s of r.outs)
|
|
138
139
|
o.addOutput({
|
|
139
|
-
script:
|
|
140
|
-
value:
|
|
140
|
+
script: s.script,
|
|
141
|
+
value: s.value
|
|
141
142
|
});
|
|
142
143
|
return o.toHex();
|
|
143
144
|
}
|
|
144
145
|
var E = /* @__PURE__ */ ((n) => (n.P2PKH = "P2PKH", n.P2SH = "P2SH", n.P2WPKH = "P2WPKH", n.P2WSH = "P2WSH", n.P2TR = "P2TR", n.UNKNOWN = "UNKNOWN", n))(E || {});
|
|
145
|
-
function
|
|
146
|
+
function pt(n) {
|
|
146
147
|
const t = n.length;
|
|
147
148
|
return t === 25 && n[0] === 118 && // OP_DUP
|
|
148
149
|
n[1] === 169 && // OP_HASH160
|
|
@@ -155,9 +156,9 @@ function dt(n) {
|
|
|
155
156
|
n[1] === 32 ? "P2WSH" : t === 34 && n[0] === 81 && // OP_1
|
|
156
157
|
n[1] === 32 ? "P2TR" : "UNKNOWN";
|
|
157
158
|
}
|
|
158
|
-
function
|
|
159
|
-
const e = g.from(n.scriptPubKey, "hex"),
|
|
160
|
-
switch (
|
|
159
|
+
function ht(n, t) {
|
|
160
|
+
const e = g.from(n.scriptPubKey, "hex"), r = pt(e);
|
|
161
|
+
switch (r) {
|
|
161
162
|
case E.P2WPKH:
|
|
162
163
|
return {
|
|
163
164
|
witnessUtxo: {
|
|
@@ -191,10 +192,10 @@ function pt(n, t) {
|
|
|
191
192
|
};
|
|
192
193
|
}
|
|
193
194
|
default:
|
|
194
|
-
throw new Error(`Unsupported script type: ${
|
|
195
|
+
throw new Error(`Unsupported script type: ${r}`);
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
|
-
const
|
|
198
|
+
const yt = {
|
|
198
199
|
mainnet: "https://mempool.space/api",
|
|
199
200
|
testnet: "https://mempool.space/testnet/api",
|
|
200
201
|
signet: "https://mempool.space/signet/api"
|
|
@@ -208,13 +209,13 @@ async function S(n, t) {
|
|
|
208
209
|
`Mempool API error (${e.status}): ${o || e.statusText}`
|
|
209
210
|
);
|
|
210
211
|
}
|
|
211
|
-
const
|
|
212
|
-
return
|
|
212
|
+
const r = e.headers.get("content-type");
|
|
213
|
+
return r != null && r.includes("application/json") ? await e.json() : await e.text();
|
|
213
214
|
} catch (e) {
|
|
214
215
|
throw e instanceof Error ? new Error(`Failed to fetch from mempool API: ${e.message}`) : new Error("Failed to fetch from mempool API: Unknown error");
|
|
215
216
|
}
|
|
216
217
|
}
|
|
217
|
-
async function
|
|
218
|
+
async function gt(n, t) {
|
|
218
219
|
try {
|
|
219
220
|
const e = await fetch(`${t}/tx`, {
|
|
220
221
|
method: "POST",
|
|
@@ -225,14 +226,14 @@ async function yt(n, t) {
|
|
|
225
226
|
});
|
|
226
227
|
if (!e.ok) {
|
|
227
228
|
const o = await e.text();
|
|
228
|
-
let
|
|
229
|
+
let s;
|
|
229
230
|
try {
|
|
230
|
-
|
|
231
|
+
s = JSON.parse(o).message;
|
|
231
232
|
} catch {
|
|
232
|
-
|
|
233
|
+
s = o;
|
|
233
234
|
}
|
|
234
235
|
throw new Error(
|
|
235
|
-
|
|
236
|
+
s || `Failed to broadcast transaction: ${e.statusText}`
|
|
236
237
|
);
|
|
237
238
|
}
|
|
238
239
|
return await e.text();
|
|
@@ -240,16 +241,16 @@ async function yt(n, t) {
|
|
|
240
241
|
throw e instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${e.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
|
|
241
242
|
}
|
|
242
243
|
}
|
|
243
|
-
async function
|
|
244
|
+
async function ft(n, t) {
|
|
244
245
|
return S(`${t}/tx/${n}`);
|
|
245
246
|
}
|
|
246
|
-
async function
|
|
247
|
+
async function Ht(n, t) {
|
|
247
248
|
try {
|
|
248
249
|
const e = await fetch(`${t}/tx/${n}/hex`);
|
|
249
250
|
if (!e.ok) {
|
|
250
|
-
const
|
|
251
|
+
const r = await e.text();
|
|
251
252
|
throw new Error(
|
|
252
|
-
`Mempool API error (${e.status}): ${
|
|
253
|
+
`Mempool API error (${e.status}): ${r || e.statusText}`
|
|
253
254
|
);
|
|
254
255
|
}
|
|
255
256
|
return await e.text();
|
|
@@ -257,13 +258,13 @@ async function It(n, t) {
|
|
|
257
258
|
throw e instanceof Error ? new Error(`Failed to get transaction hex for ${n}: ${e.message}`) : new Error(`Failed to get transaction hex for ${n}: Unknown error`);
|
|
258
259
|
}
|
|
259
260
|
}
|
|
260
|
-
async function
|
|
261
|
-
const
|
|
262
|
-
if (t >=
|
|
261
|
+
async function bt(n, t, e) {
|
|
262
|
+
const r = await ft(n, e);
|
|
263
|
+
if (t >= r.vout.length)
|
|
263
264
|
throw new Error(
|
|
264
|
-
`Invalid vout ${t} for transaction ${n} (has ${
|
|
265
|
+
`Invalid vout ${t} for transaction ${n} (has ${r.vout.length} outputs)`
|
|
265
266
|
);
|
|
266
|
-
const o =
|
|
267
|
+
const o = r.vout[t];
|
|
267
268
|
return {
|
|
268
269
|
txid: n,
|
|
269
270
|
vout: t,
|
|
@@ -271,19 +272,19 @@ async function ft(n, t, e) {
|
|
|
271
272
|
scriptPubKey: o.scriptpubkey
|
|
272
273
|
};
|
|
273
274
|
}
|
|
274
|
-
async function
|
|
275
|
+
async function $t(n, t) {
|
|
275
276
|
try {
|
|
276
|
-
const e = await S(`${t}/address/${n}/utxo`),
|
|
277
|
-
if (!
|
|
277
|
+
const e = await S(`${t}/address/${n}/utxo`), r = await S(`${t}/v1/validate-address/${n}`);
|
|
278
|
+
if (!r.isvalid)
|
|
278
279
|
throw new Error(
|
|
279
280
|
`Invalid Bitcoin address: ${n}. Mempool API validation failed.`
|
|
280
281
|
);
|
|
281
|
-
return e.sort((
|
|
282
|
-
txid:
|
|
283
|
-
vout:
|
|
284
|
-
value:
|
|
285
|
-
scriptPubKey:
|
|
286
|
-
confirmed:
|
|
282
|
+
return e.sort((s, c) => c.value - s.value).map((s) => ({
|
|
283
|
+
txid: s.txid,
|
|
284
|
+
vout: s.vout,
|
|
285
|
+
value: s.value,
|
|
286
|
+
scriptPubKey: r.scriptPubKey,
|
|
287
|
+
confirmed: s.status.confirmed
|
|
287
288
|
}));
|
|
288
289
|
} catch (e) {
|
|
289
290
|
throw e instanceof Error ? new Error(
|
|
@@ -293,13 +294,13 @@ async function Bt(n, t) {
|
|
|
293
294
|
);
|
|
294
295
|
}
|
|
295
296
|
}
|
|
296
|
-
function
|
|
297
|
-
return
|
|
297
|
+
function Ct(n) {
|
|
298
|
+
return yt[n];
|
|
298
299
|
}
|
|
299
|
-
async function
|
|
300
|
+
async function Ut(n, t) {
|
|
300
301
|
return S(`${t}/address/${n}/txs`);
|
|
301
302
|
}
|
|
302
|
-
async function
|
|
303
|
+
async function Ot(n) {
|
|
303
304
|
const t = await fetch(`${n}/v1/fees/recommended`);
|
|
304
305
|
if (!t.ok)
|
|
305
306
|
throw new Error(
|
|
@@ -601,56 +602,56 @@ const $ = [
|
|
|
601
602
|
// InvalidPeginFee(uint256,uint256)
|
|
602
603
|
"0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."
|
|
603
604
|
};
|
|
604
|
-
function
|
|
605
|
+
function A(n) {
|
|
605
606
|
if (!n || typeof n != "object") return;
|
|
606
607
|
const t = n;
|
|
607
608
|
if (typeof t.data == "string" && t.data.startsWith("0x"))
|
|
608
609
|
return t.data;
|
|
609
610
|
if (typeof t.details == "string" && t.details.startsWith("0x"))
|
|
610
611
|
return t.details;
|
|
611
|
-
let e = t.cause,
|
|
612
|
+
let e = t.cause, r = 0;
|
|
612
613
|
const o = 5;
|
|
613
|
-
for (; e && typeof e == "object" &&
|
|
614
|
+
for (; e && typeof e == "object" && r < o; ) {
|
|
614
615
|
const i = e;
|
|
615
616
|
if (typeof i.data == "string" && i.data.startsWith("0x"))
|
|
616
617
|
return i.data;
|
|
617
|
-
e = i.cause,
|
|
618
|
+
e = i.cause, r++;
|
|
618
619
|
}
|
|
619
620
|
const c = (typeof t.message == "string" ? t.message : "").match(/\b(0x[a-fA-F0-9]{8})\b/);
|
|
620
621
|
if (c)
|
|
621
622
|
return c[1];
|
|
622
623
|
}
|
|
623
|
-
function
|
|
624
|
-
const t =
|
|
624
|
+
function At(n) {
|
|
625
|
+
const t = A(n);
|
|
625
626
|
if (t) {
|
|
626
627
|
const e = t.substring(0, 10);
|
|
627
628
|
return m[t] ?? m[e];
|
|
628
629
|
}
|
|
629
630
|
}
|
|
630
|
-
function
|
|
631
|
-
const t =
|
|
631
|
+
function Rt(n) {
|
|
632
|
+
const t = A(n);
|
|
632
633
|
if (t === void 0) return !1;
|
|
633
634
|
const e = t.substring(0, 10);
|
|
634
635
|
return t in m || e in m;
|
|
635
636
|
}
|
|
636
637
|
function z(n) {
|
|
637
638
|
console.error("[Contract Error] Raw error:", n);
|
|
638
|
-
const t =
|
|
639
|
+
const t = A(n);
|
|
639
640
|
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
640
|
-
const
|
|
641
|
+
const r = t.substring(0, 10), o = m[t] ?? m[r];
|
|
641
642
|
if (o)
|
|
642
643
|
throw console.error("[Contract Error] Known error:", o), new Error(o);
|
|
643
644
|
}
|
|
644
645
|
const e = (n == null ? void 0 : n.message) || "";
|
|
645
646
|
if (e.includes("gas limit too high") || e.includes("21000000") || e.includes("Internal JSON-RPC error")) {
|
|
646
|
-
const
|
|
647
|
+
const r = t ? ` (error code: ${t})` : "";
|
|
647
648
|
throw console.error(
|
|
648
649
|
"[Contract Error] Transaction rejected. Error code:",
|
|
649
650
|
t,
|
|
650
651
|
"Message:",
|
|
651
652
|
e
|
|
652
653
|
), new Error(
|
|
653
|
-
`Transaction failed: The contract rejected this transaction${
|
|
654
|
+
`Transaction failed: The contract rejected this transaction${r}. Possible causes: (1) Vault already exists for this transaction, (2) Invalid signature, (3) Unauthorized caller. Please check your transaction parameters and try again.`
|
|
654
655
|
);
|
|
655
656
|
}
|
|
656
657
|
throw n instanceof Error ? (console.error("[Contract Error] Unhandled error:", n.message), n) : new Error(`Contract call failed: ${String(n)}`);
|
|
@@ -662,7 +663,7 @@ class Ft {
|
|
|
662
663
|
* @param config - Manager configuration including wallets and contract addresses
|
|
663
664
|
*/
|
|
664
665
|
constructor(t) {
|
|
665
|
-
|
|
666
|
+
I(this, "config");
|
|
666
667
|
this.config = t;
|
|
667
668
|
}
|
|
668
669
|
/**
|
|
@@ -686,15 +687,15 @@ class Ft {
|
|
|
686
687
|
* @throws Error if wallet operations fail or insufficient funds
|
|
687
688
|
*/
|
|
688
689
|
async preparePegin(t) {
|
|
689
|
-
const e = await this.config.btcWallet.getPublicKeyHex(),
|
|
690
|
+
const e = await this.config.btcWallet.getPublicKeyHex(), r = e.length === 66 ? e.slice(2) : e, o = k(t.vaultProviderBtcPubkey), s = t.vaultKeeperBtcPubkeys.map(k), c = t.universalChallengerBtcPubkeys.map(k);
|
|
690
691
|
if (t.hashlocks.length !== 1)
|
|
691
692
|
throw new Error(
|
|
692
693
|
"hashlocks must contain exactly one entry (batched deposits not yet supported)"
|
|
693
694
|
);
|
|
694
|
-
const i =
|
|
695
|
-
depositorPubkey:
|
|
695
|
+
const i = s.length, a = {
|
|
696
|
+
depositorPubkey: r,
|
|
696
697
|
vaultProviderPubkey: o,
|
|
697
|
-
vaultKeeperPubkeys:
|
|
698
|
+
vaultKeeperPubkeys: s,
|
|
698
699
|
universalChallengerPubkeys: c,
|
|
699
700
|
hashlocks: t.hashlocks,
|
|
700
701
|
timelockRefund: t.timelockRefund,
|
|
@@ -704,47 +705,38 @@ class Ft {
|
|
|
704
705
|
councilQuorum: t.councilQuorum,
|
|
705
706
|
councilSize: t.councilSize,
|
|
706
707
|
network: this.config.btcNetwork
|
|
707
|
-
}, u = await
|
|
708
|
+
}, u = await nt(a), l = dt(
|
|
708
709
|
[...t.availableUTXOs],
|
|
709
710
|
u.totalOutputValue,
|
|
710
711
|
t.mempoolFeeRate
|
|
711
|
-
), p = U(this.config.btcNetwork), h =
|
|
712
|
+
), p = U(this.config.btcNetwork), h = rt({
|
|
712
713
|
unfundedTxHex: u.psbtHex,
|
|
713
714
|
selectedUTXOs: l.selectedUTXOs,
|
|
714
715
|
changeAddress: t.changeAddress,
|
|
715
716
|
changeAmount: l.changeAmount,
|
|
716
717
|
network: p
|
|
717
|
-
}), f = k(
|
|
718
|
+
}), f = k(_(h)), P = await st({
|
|
718
719
|
prePeginParams: a,
|
|
719
720
|
timelockPegin: t.timelockPegin,
|
|
720
721
|
fundedPrePeginTxHex: h,
|
|
721
|
-
htlcVout:
|
|
722
|
-
}), x = await
|
|
722
|
+
htlcVout: D
|
|
723
|
+
}), x = await at({
|
|
723
724
|
peginTxHex: P.txHex,
|
|
724
725
|
fundedPrePeginTxHex: h,
|
|
725
|
-
depositorPubkey:
|
|
726
|
+
depositorPubkey: r,
|
|
726
727
|
vaultProviderPubkey: o,
|
|
727
|
-
vaultKeeperPubkeys:
|
|
728
|
+
vaultKeeperPubkeys: s,
|
|
728
729
|
universalChallengerPubkeys: c,
|
|
729
730
|
hashlock: t.hashlocks[0],
|
|
730
731
|
timelockRefund: t.timelockRefund,
|
|
731
732
|
network: this.config.btcNetwork
|
|
732
733
|
}), d = await this.config.btcWallet.signPsbt(
|
|
733
734
|
x.psbtHex,
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
signInputs: [
|
|
737
|
-
{
|
|
738
|
-
index: 0,
|
|
739
|
-
publicKey: e,
|
|
740
|
-
disableTweakSigner: !0
|
|
741
|
-
}
|
|
742
|
-
]
|
|
743
|
-
}
|
|
744
|
-
), y = at(
|
|
735
|
+
O(e, 1)
|
|
736
|
+
), y = ot(
|
|
745
737
|
d,
|
|
746
|
-
|
|
747
|
-
), b =
|
|
738
|
+
r
|
|
739
|
+
), b = it(d);
|
|
748
740
|
return {
|
|
749
741
|
fundedPrePeginTxHex: h,
|
|
750
742
|
htlcValue: u.htlcValue,
|
|
@@ -775,12 +767,12 @@ class Ft {
|
|
|
775
767
|
* @throws Error if signing or broadcasting fails
|
|
776
768
|
*/
|
|
777
769
|
async signAndBroadcast(t) {
|
|
778
|
-
const { fundedPrePeginTxHex: e, depositorBtcPubkey:
|
|
779
|
-
if (
|
|
770
|
+
const { fundedPrePeginTxHex: e, depositorBtcPubkey: r } = t, o = e.startsWith("0x") ? e.slice(2) : e, s = B.fromHex(o);
|
|
771
|
+
if (s.ins.length === 0)
|
|
780
772
|
throw new Error("Transaction has no inputs");
|
|
781
773
|
const c = new C();
|
|
782
|
-
c.setVersion(
|
|
783
|
-
const i =
|
|
774
|
+
c.setVersion(s.version), c.setLocktime(s.locktime);
|
|
775
|
+
const i = r.startsWith("0x") ? r.slice(2) : r;
|
|
784
776
|
if (i.length !== 64 || !/^[0-9a-fA-F]+$/.test(i))
|
|
785
777
|
throw new Error(
|
|
786
778
|
"Invalid depositorBtcPubkey: expected 64 hex characters (x-only pubkey)"
|
|
@@ -790,9 +782,9 @@ class Ft {
|
|
|
790
782
|
throw new Error(
|
|
791
783
|
`Invalid depositorBtcPubkey length: expected 32 bytes, got ${a.length}`
|
|
792
784
|
);
|
|
793
|
-
const u = this.config.mempoolApiUrl, l =
|
|
785
|
+
const u = this.config.mempoolApiUrl, l = s.ins.map((d) => {
|
|
794
786
|
const y = g.from(d.hash).reverse().toString("hex"), b = d.index;
|
|
795
|
-
return
|
|
787
|
+
return bt(y, b, u).then((w) => ({
|
|
796
788
|
input: d,
|
|
797
789
|
utxoData: w,
|
|
798
790
|
txid: y,
|
|
@@ -800,7 +792,7 @@ class Ft {
|
|
|
800
792
|
}));
|
|
801
793
|
}), p = await Promise.all(l);
|
|
802
794
|
for (const { input: d, utxoData: y, txid: b, vout: w } of p) {
|
|
803
|
-
const T =
|
|
795
|
+
const T = ht(
|
|
804
796
|
{
|
|
805
797
|
value: y.value,
|
|
806
798
|
scriptPubKey: y.scriptPubKey
|
|
@@ -814,7 +806,7 @@ class Ft {
|
|
|
814
806
|
...T
|
|
815
807
|
});
|
|
816
808
|
}
|
|
817
|
-
for (const d of
|
|
809
|
+
for (const d of s.outs)
|
|
818
810
|
c.addOutput({
|
|
819
811
|
script: d.script,
|
|
820
812
|
value: d.value
|
|
@@ -831,7 +823,7 @@ class Ft {
|
|
|
831
823
|
);
|
|
832
824
|
}
|
|
833
825
|
const P = f.extractTransaction().toHex();
|
|
834
|
-
return await
|
|
826
|
+
return await gt(P, u);
|
|
835
827
|
}
|
|
836
828
|
/**
|
|
837
829
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -853,9 +845,9 @@ class Ft {
|
|
|
853
845
|
async registerPeginOnChain(t) {
|
|
854
846
|
const {
|
|
855
847
|
depositorBtcPubkey: e,
|
|
856
|
-
unsignedPrePeginTx:
|
|
848
|
+
unsignedPrePeginTx: r,
|
|
857
849
|
depositorSignedPeginTx: o,
|
|
858
|
-
vaultProvider:
|
|
850
|
+
vaultProvider: s,
|
|
859
851
|
hashlock: c,
|
|
860
852
|
onPopSigned: i,
|
|
861
853
|
depositorPayoutBtcAddress: a,
|
|
@@ -869,16 +861,16 @@ class Ft {
|
|
|
869
861
|
l
|
|
870
862
|
);
|
|
871
863
|
i && await i();
|
|
872
|
-
const f = H(e), P = H(
|
|
864
|
+
const f = H(e), P = H(r), x = H(o), d = await this.resolvePayoutScriptPubKey(
|
|
873
865
|
a
|
|
874
|
-
), y =
|
|
866
|
+
), y = _(x);
|
|
875
867
|
if (await this.checkVaultExists(y))
|
|
876
868
|
throw new Error(
|
|
877
869
|
`Vault already exists for this transaction (ID: ${y}). Vault IDs are deterministically derived from the unsigned Bitcoin transaction, so using the same UTXOs and amount will always produce the same vault. To create a new vault, please use different UTXOs or a different amount to generate a unique transaction.`
|
|
878
870
|
);
|
|
879
|
-
const w =
|
|
871
|
+
const w = M({
|
|
880
872
|
chain: this.config.ethChain,
|
|
881
|
-
transport:
|
|
873
|
+
transport: X()
|
|
882
874
|
});
|
|
883
875
|
let T;
|
|
884
876
|
try {
|
|
@@ -886,14 +878,14 @@ class Ft {
|
|
|
886
878
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
887
879
|
abi: $,
|
|
888
880
|
functionName: "getPegInFee",
|
|
889
|
-
args: [
|
|
881
|
+
args: [s]
|
|
890
882
|
});
|
|
891
883
|
} catch {
|
|
892
884
|
throw new Error(
|
|
893
885
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
894
886
|
);
|
|
895
887
|
}
|
|
896
|
-
const
|
|
888
|
+
const R = ut({
|
|
897
889
|
abi: $,
|
|
898
890
|
functionName: "submitPeginRequest",
|
|
899
891
|
args: [
|
|
@@ -902,18 +894,18 @@ class Ft {
|
|
|
902
894
|
h,
|
|
903
895
|
P,
|
|
904
896
|
x,
|
|
905
|
-
|
|
897
|
+
s,
|
|
906
898
|
c,
|
|
907
|
-
|
|
899
|
+
D,
|
|
908
900
|
d,
|
|
909
901
|
u
|
|
910
902
|
]
|
|
911
903
|
});
|
|
912
|
-
let
|
|
904
|
+
let F;
|
|
913
905
|
try {
|
|
914
|
-
|
|
906
|
+
F = await w.estimateGas({
|
|
915
907
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
916
|
-
data:
|
|
908
|
+
data: R,
|
|
917
909
|
value: T,
|
|
918
910
|
account: this.config.ethWallet.account.address
|
|
919
911
|
});
|
|
@@ -924,11 +916,11 @@ class Ft {
|
|
|
924
916
|
return {
|
|
925
917
|
ethTxHash: await this.config.ethWallet.sendTransaction({
|
|
926
918
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
927
|
-
data:
|
|
919
|
+
data: R,
|
|
928
920
|
value: T,
|
|
929
921
|
account: this.config.ethWallet.account,
|
|
930
922
|
chain: this.config.ethChain,
|
|
931
|
-
gas:
|
|
923
|
+
gas: F
|
|
932
924
|
}),
|
|
933
925
|
vaultId: y,
|
|
934
926
|
btcPopSignature: h
|
|
@@ -945,15 +937,15 @@ class Ft {
|
|
|
945
937
|
*/
|
|
946
938
|
async checkVaultExists(t) {
|
|
947
939
|
try {
|
|
948
|
-
return (await
|
|
940
|
+
return (await M({
|
|
949
941
|
chain: this.config.ethChain,
|
|
950
|
-
transport:
|
|
942
|
+
transport: X()
|
|
951
943
|
}).readContract({
|
|
952
944
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
953
945
|
abi: $,
|
|
954
946
|
functionName: "getBTCVault",
|
|
955
947
|
args: [t]
|
|
956
|
-
})).depositor !==
|
|
948
|
+
})).depositor !== lt;
|
|
957
949
|
} catch {
|
|
958
950
|
return !1;
|
|
959
951
|
}
|
|
@@ -972,7 +964,7 @@ class Ft {
|
|
|
972
964
|
else {
|
|
973
965
|
e = await this.config.btcWallet.getAddress();
|
|
974
966
|
const o = await this.config.btcWallet.getPublicKeyHex();
|
|
975
|
-
if (!
|
|
967
|
+
if (!ct(
|
|
976
968
|
e,
|
|
977
969
|
o,
|
|
978
970
|
this.config.btcNetwork
|
|
@@ -981,9 +973,9 @@ class Ft {
|
|
|
981
973
|
"The BTC address from your wallet does not match the wallet's public key. Please ensure your wallet is using a supported address type (Taproot or Native SegWit)."
|
|
982
974
|
);
|
|
983
975
|
}
|
|
984
|
-
const
|
|
976
|
+
const r = U(this.config.btcNetwork);
|
|
985
977
|
try {
|
|
986
|
-
return `0x${
|
|
978
|
+
return `0x${J.address.toOutputScript(e, r).toString("hex")}`;
|
|
987
979
|
} catch {
|
|
988
980
|
throw new Error(
|
|
989
981
|
`Invalid BTC payout address: "${e}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -999,11 +991,11 @@ class Ft {
|
|
|
999
991
|
async resolvePopSignature(t, e) {
|
|
1000
992
|
if (e)
|
|
1001
993
|
return e;
|
|
1002
|
-
const
|
|
994
|
+
const r = this.config.vaultContracts.btcVaultRegistry, o = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${r.toLowerCase()}`, s = await this.config.btcWallet.signMessage(
|
|
1003
995
|
o,
|
|
1004
996
|
"bip322-simple"
|
|
1005
997
|
);
|
|
1006
|
-
return
|
|
998
|
+
return s.startsWith("0x") ? s : `0x${g.from(s, "base64").toString("hex")}`;
|
|
1007
999
|
}
|
|
1008
1000
|
/**
|
|
1009
1001
|
* Gets the configured Bitcoin network.
|
|
@@ -1022,14 +1014,14 @@ class Ft {
|
|
|
1022
1014
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1023
1015
|
}
|
|
1024
1016
|
}
|
|
1025
|
-
class
|
|
1017
|
+
class Vt {
|
|
1026
1018
|
/**
|
|
1027
1019
|
* Creates a new PayoutManager instance.
|
|
1028
1020
|
*
|
|
1029
1021
|
* @param config - Manager configuration including wallet
|
|
1030
1022
|
*/
|
|
1031
1023
|
constructor(t) {
|
|
1032
|
-
|
|
1024
|
+
I(this, "config");
|
|
1033
1025
|
this.config = t;
|
|
1034
1026
|
}
|
|
1035
1027
|
/**
|
|
@@ -1055,35 +1047,26 @@ class At {
|
|
|
1055
1047
|
* @throws Error if wallet operations fail or signature extraction fails
|
|
1056
1048
|
*/
|
|
1057
1049
|
async signPayoutTransaction(t) {
|
|
1058
|
-
const e = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey:
|
|
1050
|
+
const e = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: r } = W(
|
|
1059
1051
|
e,
|
|
1060
1052
|
t.depositorBtcPubkey
|
|
1061
|
-
), o = await
|
|
1053
|
+
), o = await K({
|
|
1062
1054
|
payoutTxHex: t.payoutTxHex,
|
|
1063
1055
|
peginTxHex: t.peginTxHex,
|
|
1064
1056
|
assertTxHex: t.assertTxHex,
|
|
1065
|
-
depositorBtcPubkey:
|
|
1057
|
+
depositorBtcPubkey: r,
|
|
1066
1058
|
vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
|
|
1067
1059
|
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys,
|
|
1068
1060
|
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
1069
1061
|
timelockPegin: t.timelockPegin,
|
|
1070
1062
|
network: this.config.network
|
|
1071
|
-
}),
|
|
1063
|
+
}), s = await this.config.btcWallet.signPsbt(
|
|
1072
1064
|
o.psbtHex,
|
|
1073
|
-
|
|
1074
|
-
autoFinalized: !1,
|
|
1075
|
-
signInputs: [
|
|
1076
|
-
{
|
|
1077
|
-
index: 0,
|
|
1078
|
-
publicKey: e,
|
|
1079
|
-
disableTweakSigner: !0
|
|
1080
|
-
}
|
|
1081
|
-
]
|
|
1082
|
-
}
|
|
1065
|
+
O(e, 1)
|
|
1083
1066
|
);
|
|
1084
1067
|
return {
|
|
1085
|
-
signature:
|
|
1086
|
-
depositorBtcPubkey:
|
|
1068
|
+
signature: N(s, r),
|
|
1069
|
+
depositorBtcPubkey: r
|
|
1087
1070
|
};
|
|
1088
1071
|
}
|
|
1089
1072
|
/**
|
|
@@ -1116,14 +1099,14 @@ class At {
|
|
|
1116
1099
|
throw new Error(
|
|
1117
1100
|
"Wallet does not support batch signing (signPsbts method not available)"
|
|
1118
1101
|
);
|
|
1119
|
-
const e = await this.config.btcWallet.getPublicKeyHex(),
|
|
1102
|
+
const e = await this.config.btcWallet.getPublicKeyHex(), r = [], o = [], s = [];
|
|
1120
1103
|
for (const a of t) {
|
|
1121
|
-
const { depositorPubkey: u } =
|
|
1104
|
+
const { depositorPubkey: u } = W(
|
|
1122
1105
|
e,
|
|
1123
1106
|
a.depositorBtcPubkey
|
|
1124
1107
|
);
|
|
1125
|
-
|
|
1126
|
-
const l = await
|
|
1108
|
+
s.push(u);
|
|
1109
|
+
const l = await K({
|
|
1127
1110
|
payoutTxHex: a.payoutTxHex,
|
|
1128
1111
|
peginTxHex: a.peginTxHex,
|
|
1129
1112
|
assertTxHex: a.assertTxHex,
|
|
@@ -1134,19 +1117,10 @@ class At {
|
|
|
1134
1117
|
timelockPegin: a.timelockPegin,
|
|
1135
1118
|
network: this.config.network
|
|
1136
1119
|
});
|
|
1137
|
-
|
|
1138
|
-
autoFinalized: !1,
|
|
1139
|
-
signInputs: [
|
|
1140
|
-
{
|
|
1141
|
-
index: 0,
|
|
1142
|
-
publicKey: e,
|
|
1143
|
-
disableTweakSigner: !0
|
|
1144
|
-
}
|
|
1145
|
-
]
|
|
1146
|
-
});
|
|
1120
|
+
r.push(l.psbtHex), o.push(O(e, 1));
|
|
1147
1121
|
}
|
|
1148
1122
|
const c = await this.config.btcWallet.signPsbts(
|
|
1149
|
-
|
|
1123
|
+
r,
|
|
1150
1124
|
o
|
|
1151
1125
|
);
|
|
1152
1126
|
if (c.length !== t.length)
|
|
@@ -1155,7 +1129,7 @@ class At {
|
|
|
1155
1129
|
);
|
|
1156
1130
|
const i = [];
|
|
1157
1131
|
for (let a = 0; a < t.length; a++) {
|
|
1158
|
-
const u =
|
|
1132
|
+
const u = s[a], l = N(
|
|
1159
1133
|
c[a],
|
|
1160
1134
|
u
|
|
1161
1135
|
);
|
|
@@ -1170,29 +1144,29 @@ class At {
|
|
|
1170
1144
|
export {
|
|
1171
1145
|
E as B,
|
|
1172
1146
|
m as C,
|
|
1173
|
-
|
|
1147
|
+
yt as M,
|
|
1174
1148
|
Ft as P,
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1149
|
+
Et as a,
|
|
1150
|
+
Bt as b,
|
|
1151
|
+
_ as c,
|
|
1152
|
+
It as d,
|
|
1153
|
+
pt as e,
|
|
1154
|
+
ht as f,
|
|
1155
|
+
St as g,
|
|
1156
|
+
Vt as h,
|
|
1157
|
+
Ut as i,
|
|
1158
|
+
$t as j,
|
|
1159
|
+
Ct as k,
|
|
1160
|
+
Ot as l,
|
|
1161
|
+
Ht as m,
|
|
1162
|
+
ft as n,
|
|
1163
|
+
bt as o,
|
|
1164
|
+
gt as p,
|
|
1191
1165
|
$ as q,
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1166
|
+
A as r,
|
|
1167
|
+
dt as s,
|
|
1168
|
+
At as t,
|
|
1169
|
+
Rt as u,
|
|
1196
1170
|
z as v
|
|
1197
1171
|
};
|
|
1198
|
-
//# sourceMappingURL=PayoutManager-
|
|
1172
|
+
//# sourceMappingURL=PayoutManager-CvWBwdzd.js.map
|