@babylonlabs-io/ts-sdk 6.0.1 → 6.1.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-3-MzBVLj.js.map +1 -1
- package/dist/PayoutManager-PQqeqX41.cjs.map +1 -1
- package/dist/{PeginManager-m3IlM4wS.js → PeginManager-BvIZvqLp.js} +4 -4
- package/dist/PeginManager-BvIZvqLp.js.map +1 -0
- package/dist/{PeginManager-D_ZUfbIy.cjs → PeginManager-CdYTFgrY.cjs} +2 -2
- package/dist/PeginManager-CdYTFgrY.cjs.map +1 -0
- package/dist/buildAndBroadcastReclaim-CMjlyooo.cjs.map +1 -1
- package/dist/buildAndBroadcastReclaim-D8l-QJWo.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -4
- package/dist/pegin-registration-client-Cdgp5Ge_.cjs +2 -0
- package/dist/pegin-registration-client-Cdgp5Ge_.cjs.map +1 -0
- package/dist/{pegin-registration-client-BlrXyZpF.js → pegin-registration-client-Yc-Qs5kq.js} +232 -205
- package/dist/pegin-registration-client-Yc-Qs5kq.js.map +1 -0
- package/dist/signer-set-reader-CNEfzwuA.cjs +2 -0
- package/dist/signer-set-reader-CNEfzwuA.cjs.map +1 -0
- package/dist/{signer-set-reader-DiwLeqik.js → signer-set-reader-Csz8RXQi.js} +6 -5
- package/dist/signer-set-reader-Csz8RXQi.js.map +1 -0
- package/dist/tbv/core/clients/eth/__tests__/contract-address-resolver.test.d.ts +2 -0
- package/dist/tbv/core/clients/eth/__tests__/contract-address-resolver.test.d.ts.map +1 -0
- package/dist/tbv/core/clients/eth/contract-address-resolver.d.ts +3 -1
- package/dist/tbv/core/clients/eth/contract-address-resolver.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/index.cjs +1 -1
- package/dist/tbv/core/clients/eth/index.js +2 -2
- package/dist/tbv/core/clients/eth/pegin-registration-client.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +2 -2
- package/dist/tbv/core/deposit-terms/depositTerms.d.ts +3 -3
- package/dist/tbv/core/deposit-terms/prePeginApproval.d.ts +2 -2
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +4 -4
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +1 -1
- package/dist/tbv/core/primitives/psbt/__tests__/depositorClaim.test.d.ts +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts +2 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +4 -4
- package/dist/{toRefundInputs-D5tx3eeA.js → toRefundInputs-CPtK0OgP.js} +2 -2
- package/dist/{toRefundInputs-D5tx3eeA.js.map → toRefundInputs-CPtK0OgP.js.map} +1 -1
- package/dist/{toRefundInputs-Df6eRITl.cjs → toRefundInputs-DYVCJ2SN.cjs} +2 -2
- package/dist/{toRefundInputs-Df6eRITl.cjs.map → toRefundInputs-DYVCJ2SN.cjs.map} +1 -1
- package/dist/verifyScriptPathSchnorrSignature-BVGPEZXW.js.map +1 -1
- package/dist/verifyScriptPathSchnorrSignature-p3sVoWQi.cjs.map +1 -1
- package/package.json +1 -1
- package/dist/PeginManager-D_ZUfbIy.cjs.map +0 -1
- package/dist/PeginManager-m3IlM4wS.js.map +0 -1
- package/dist/pegin-registration-client-BlrXyZpF.js.map +0 -1
- package/dist/pegin-registration-client-DOb-Iznp.cjs +0 -2
- package/dist/pegin-registration-client-DOb-Iznp.cjs.map +0 -1
- package/dist/signer-set-reader-CJfV-GDz.cjs +0 -2
- package/dist/signer-set-reader-CJfV-GDz.cjs.map +0 -1
- package/dist/signer-set-reader-DiwLeqik.js.map +0 -1
package/dist/{pegin-registration-client-BlrXyZpF.js → pegin-registration-client-Yc-Qs5kq.js}
RENAMED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { getAbiItem as
|
|
2
|
-
import { B as
|
|
3
|
-
import { B as
|
|
4
|
-
import { M as
|
|
5
|
-
import { waitForTransactionReceiptSmartAware as
|
|
6
|
-
import { a as
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
if (!Number.isInteger(o) || o < 0 || o >=
|
|
1
|
+
import { getAbiItem as O, encodeFunctionData as I, isAddressEqual as R, zeroAddress as q, InsufficientFundsError as L, isAddress as U } from "viem";
|
|
2
|
+
import { B as u } from "./BTCVaultRegistry.abi-DnP4UkB5.js";
|
|
3
|
+
import { B as k, h as B } from "./BTCVaultRegistryKeyEpochs.abi-Btg0nBz1.js";
|
|
4
|
+
import { M as $ } from "./constants-CmDDuM3L.js";
|
|
5
|
+
import { waitForTransactionReceiptSmartAware as W } from "./tbv/core/utils/eth/index.js";
|
|
6
|
+
import { a as b, R as z, g as D, V as G, j as X, h as Q, k as Y, d as j } from "./registration-records-D39ApuHS.js";
|
|
7
|
+
const T = 25, Z = 9999;
|
|
8
|
+
function N(o) {
|
|
9
|
+
if (!Number.isInteger(o) || o < 0 || o >= $)
|
|
10
10
|
throw new Error(
|
|
11
|
-
`Quoted commissionBps must be an integer in [0, ${
|
|
11
|
+
`Quoted commissionBps must be an integer in [0, ${$}), got ${o}`
|
|
12
12
|
);
|
|
13
13
|
return Math.min(
|
|
14
|
-
o +
|
|
15
|
-
|
|
14
|
+
o + T,
|
|
15
|
+
Z
|
|
16
16
|
);
|
|
17
17
|
}
|
|
18
|
-
const
|
|
19
|
-
function
|
|
18
|
+
const K = 9999;
|
|
19
|
+
function _(o) {
|
|
20
20
|
return {
|
|
21
21
|
depositor: o.depositor,
|
|
22
22
|
depositorBtcPubKey: o.depositorBtcPubKey,
|
|
@@ -27,9 +27,9 @@ function S(o) {
|
|
|
27
27
|
createdAt: o.createdAt
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function x(o) {
|
|
31
31
|
const t = Number(o.offchainParamsVersion);
|
|
32
|
-
return
|
|
32
|
+
return X(t), {
|
|
33
33
|
depositorSignedPeginTx: o.depositorSignedPeginTx,
|
|
34
34
|
universalChallengersVersion: o.universalChallengersVersion,
|
|
35
35
|
appVaultKeepersVersion: o.appVaultKeepersVersion,
|
|
@@ -45,17 +45,17 @@ function C(o) {
|
|
|
45
45
|
vaultCoreVersion: o.vaultCoreVersion
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
const
|
|
49
|
-
abi:
|
|
48
|
+
const J = 1n << 64n, tt = 0n, et = O({
|
|
49
|
+
abi: u,
|
|
50
50
|
name: "PegInSubmitted"
|
|
51
|
-
}),
|
|
52
|
-
abi:
|
|
51
|
+
}), ot = O({
|
|
52
|
+
abi: u,
|
|
53
53
|
name: "VaultClaimableBy"
|
|
54
|
-
}),
|
|
55
|
-
function
|
|
54
|
+
}), rt = 7200n;
|
|
55
|
+
function it(o, t) {
|
|
56
56
|
return o > t ? o : t;
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function st(o, t) {
|
|
59
59
|
return {
|
|
60
60
|
vaultId: o.vaultId.toLowerCase(),
|
|
61
61
|
depositor: o.depositor,
|
|
@@ -73,30 +73,30 @@ function Y(o, t) {
|
|
|
73
73
|
blockNumber: t
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
function
|
|
77
|
-
if (o < 0n || o >=
|
|
76
|
+
function v(o, t, e) {
|
|
77
|
+
if (o < 0n || o >= J)
|
|
78
78
|
throw new Error(
|
|
79
79
|
`getBtcVaultProtocolInfo returned ${t}=${o} for vault ${e}, outside the uint64 range — the registry may predate RFC-006`
|
|
80
80
|
);
|
|
81
81
|
return o;
|
|
82
82
|
}
|
|
83
|
-
const
|
|
84
|
-
function
|
|
83
|
+
const nt = "not found on-chain or has no pegin transaction";
|
|
84
|
+
function A(o, t) {
|
|
85
85
|
if (!o.depositorSignedPeginTx || o.depositorSignedPeginTx === "0x")
|
|
86
|
-
throw new Error(`Vault ${t} ${
|
|
86
|
+
throw new Error(`Vault ${t} ${nt}`);
|
|
87
87
|
}
|
|
88
|
-
function
|
|
89
|
-
return
|
|
90
|
-
vpKeyEpoch:
|
|
91
|
-
appKeeperKeyEpoch:
|
|
88
|
+
function F(o, t) {
|
|
89
|
+
return A(o, t), {
|
|
90
|
+
vpKeyEpoch: v(o.vpKeyEpoch, "vpKeyEpoch", t),
|
|
91
|
+
appKeeperKeyEpoch: v(
|
|
92
92
|
o.appKeeperKeyEpoch,
|
|
93
93
|
"appKeeperKeyEpoch",
|
|
94
94
|
t
|
|
95
95
|
),
|
|
96
|
-
ucKeyEpoch:
|
|
96
|
+
ucKeyEpoch: v(o.ucKeyEpoch, "ucKeyEpoch", t)
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
-
class
|
|
99
|
+
class at {
|
|
100
100
|
constructor(t, e) {
|
|
101
101
|
this.publicClient = t, this.contractAddress = e;
|
|
102
102
|
}
|
|
@@ -126,7 +126,7 @@ class Z {
|
|
|
126
126
|
async getVaultProviderGenesisBtcPubKey(t, e) {
|
|
127
127
|
return this.getVaultProviderOperationBtcKeyAtEpoch(
|
|
128
128
|
t,
|
|
129
|
-
|
|
129
|
+
tt,
|
|
130
130
|
e
|
|
131
131
|
);
|
|
132
132
|
}
|
|
@@ -139,15 +139,15 @@ class Z {
|
|
|
139
139
|
* JSON-RPC bootstrap is signed by the provider's live key.
|
|
140
140
|
*/
|
|
141
141
|
async getVaultProviderOperationBtcKeyAtEpoch(t, e, r) {
|
|
142
|
-
const
|
|
142
|
+
const i = await this.publicClient.readContract({
|
|
143
143
|
address: this.contractAddress,
|
|
144
|
-
abi:
|
|
144
|
+
abi: u,
|
|
145
145
|
functionName: "getOperationBtcKeyAtEpoch",
|
|
146
146
|
args: [t, e],
|
|
147
147
|
blockNumber: r
|
|
148
148
|
});
|
|
149
|
-
return
|
|
150
|
-
|
|
149
|
+
return b(
|
|
150
|
+
i,
|
|
151
151
|
`getOperationBtcKeyAtEpoch (vp=${t}, epoch=${e})`
|
|
152
152
|
);
|
|
153
153
|
}
|
|
@@ -165,7 +165,7 @@ class Z {
|
|
|
165
165
|
async getVaultProviderApplication(t, e) {
|
|
166
166
|
return await this.publicClient.readContract({
|
|
167
167
|
address: this.contractAddress,
|
|
168
|
-
abi:
|
|
168
|
+
abi: u,
|
|
169
169
|
functionName: "getVaultProviderApplication",
|
|
170
170
|
args: [t],
|
|
171
171
|
blockNumber: e
|
|
@@ -185,11 +185,11 @@ class Z {
|
|
|
185
185
|
async getCurrentVaultProviderOperationBtcKey(t) {
|
|
186
186
|
const e = await this.publicClient.readContract({
|
|
187
187
|
address: this.contractAddress,
|
|
188
|
-
abi:
|
|
188
|
+
abi: u,
|
|
189
189
|
functionName: "getCurrentOperationBtcKey",
|
|
190
190
|
args: [t]
|
|
191
191
|
});
|
|
192
|
-
return
|
|
192
|
+
return b(
|
|
193
193
|
e,
|
|
194
194
|
`getCurrentOperationBtcKey (vp=${t})`
|
|
195
195
|
);
|
|
@@ -213,55 +213,55 @@ class Z {
|
|
|
213
213
|
async getVaultKeyEpochs(t) {
|
|
214
214
|
const e = await this.publicClient.readContract({
|
|
215
215
|
address: this.contractAddress,
|
|
216
|
-
abi:
|
|
216
|
+
abi: k,
|
|
217
217
|
functionName: "getBtcVaultProtocolInfo",
|
|
218
218
|
args: [t]
|
|
219
219
|
});
|
|
220
|
-
return
|
|
220
|
+
return F(e, t);
|
|
221
221
|
}
|
|
222
222
|
async getVaultKeyEpochsBatch(t) {
|
|
223
223
|
return t.length === 0 ? [] : (await this.publicClient.multicall({
|
|
224
224
|
contracts: t.map((r) => ({
|
|
225
225
|
address: this.contractAddress,
|
|
226
|
-
abi:
|
|
226
|
+
abi: k,
|
|
227
227
|
functionName: "getBtcVaultProtocolInfo",
|
|
228
228
|
args: [r]
|
|
229
229
|
})),
|
|
230
230
|
allowFailure: !1
|
|
231
231
|
})).map(
|
|
232
|
-
(r,
|
|
232
|
+
(r, i) => F(r, t[i])
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
235
|
async getVaultBasicInfo(t) {
|
|
236
236
|
const e = await this.publicClient.readContract({
|
|
237
237
|
address: this.contractAddress,
|
|
238
|
-
abi:
|
|
238
|
+
abi: u,
|
|
239
239
|
functionName: "getBtcVaultBasicInfo",
|
|
240
240
|
args: [t]
|
|
241
241
|
});
|
|
242
|
-
return
|
|
242
|
+
return _(e);
|
|
243
243
|
}
|
|
244
244
|
async getVaultProtocolInfo(t) {
|
|
245
245
|
const e = await this.publicClient.readContract({
|
|
246
246
|
address: this.contractAddress,
|
|
247
|
-
abi:
|
|
247
|
+
abi: u,
|
|
248
248
|
functionName: "getBtcVaultProtocolInfo",
|
|
249
249
|
args: [t]
|
|
250
250
|
});
|
|
251
|
-
return
|
|
251
|
+
return x(e);
|
|
252
252
|
}
|
|
253
253
|
async getProtocolInfoBatch(t) {
|
|
254
254
|
return t.length === 0 ? [] : (await this.publicClient.multicall({
|
|
255
255
|
contracts: t.map((r) => ({
|
|
256
256
|
address: this.contractAddress,
|
|
257
|
-
abi:
|
|
257
|
+
abi: u,
|
|
258
258
|
functionName: "getBtcVaultProtocolInfo",
|
|
259
259
|
args: [r]
|
|
260
260
|
})),
|
|
261
261
|
allowFailure: !1
|
|
262
|
-
})).map((r,
|
|
263
|
-
const
|
|
264
|
-
return
|
|
262
|
+
})).map((r, i) => {
|
|
263
|
+
const s = r;
|
|
264
|
+
return A(s, t[i]), x(s);
|
|
265
265
|
});
|
|
266
266
|
}
|
|
267
267
|
/**
|
|
@@ -271,7 +271,7 @@ class Z {
|
|
|
271
271
|
async getPegInFee(t) {
|
|
272
272
|
return await this.publicClient.readContract({
|
|
273
273
|
address: this.contractAddress,
|
|
274
|
-
abi:
|
|
274
|
+
abi: u,
|
|
275
275
|
functionName: "getPegInFee",
|
|
276
276
|
args: [t]
|
|
277
277
|
});
|
|
@@ -286,13 +286,13 @@ class Z {
|
|
|
286
286
|
async getVaultProviderCommission(t) {
|
|
287
287
|
const e = await this.publicClient.readContract({
|
|
288
288
|
address: this.contractAddress,
|
|
289
|
-
abi:
|
|
289
|
+
abi: u,
|
|
290
290
|
functionName: "getVaultProviderCommission",
|
|
291
291
|
args: [t]
|
|
292
292
|
});
|
|
293
|
-
if (!Number.isInteger(e) || e < 0 || e >
|
|
293
|
+
if (!Number.isInteger(e) || e < 0 || e > K)
|
|
294
294
|
throw new Error(
|
|
295
|
-
`getVaultProviderCommission returned ${e} bps for ${t}, outside the protocol range [0, ${
|
|
295
|
+
`getVaultProviderCommission returned ${e} bps for ${t}, outside the protocol range [0, ${K}]`
|
|
296
296
|
);
|
|
297
297
|
return e;
|
|
298
298
|
}
|
|
@@ -301,40 +301,40 @@ class Z {
|
|
|
301
301
|
contracts: [
|
|
302
302
|
{
|
|
303
303
|
address: this.contractAddress,
|
|
304
|
-
abi:
|
|
304
|
+
abi: u,
|
|
305
305
|
functionName: "getBtcVaultBasicInfo",
|
|
306
306
|
args: [t]
|
|
307
307
|
},
|
|
308
308
|
{
|
|
309
309
|
address: this.contractAddress,
|
|
310
|
-
abi:
|
|
310
|
+
abi: u,
|
|
311
311
|
functionName: "getBtcVaultProtocolInfo",
|
|
312
312
|
args: [t]
|
|
313
313
|
}
|
|
314
314
|
],
|
|
315
315
|
allowFailure: !1
|
|
316
|
-
}),
|
|
317
|
-
return
|
|
316
|
+
}), i = _(e), s = x(r);
|
|
317
|
+
return A(s, t), { basic: i, protocol: s };
|
|
318
318
|
}
|
|
319
319
|
/** @inheritdoc */
|
|
320
320
|
async getRegistrationRecordsAtBlock(t) {
|
|
321
321
|
const e = await this.publicClient.getLogs({
|
|
322
322
|
address: this.contractAddress,
|
|
323
|
-
event:
|
|
323
|
+
event: et,
|
|
324
324
|
fromBlock: t,
|
|
325
325
|
toBlock: t,
|
|
326
326
|
strict: !0
|
|
327
327
|
});
|
|
328
328
|
if (e.length === 0)
|
|
329
|
-
throw new
|
|
329
|
+
throw new z(t);
|
|
330
330
|
const r = /* @__PURE__ */ new Map();
|
|
331
|
-
for (const
|
|
332
|
-
const
|
|
333
|
-
if (r.has(
|
|
331
|
+
for (const i of e) {
|
|
332
|
+
const s = st(i.args, i.blockNumber);
|
|
333
|
+
if (r.has(s.vaultId))
|
|
334
334
|
throw new Error(
|
|
335
|
-
`Expected one PegInSubmitted log for vault ${
|
|
335
|
+
`Expected one PegInSubmitted log for vault ${s.vaultId} at block ${t}, found more than one`
|
|
336
336
|
);
|
|
337
|
-
r.set(
|
|
337
|
+
r.set(s.vaultId, s);
|
|
338
338
|
}
|
|
339
339
|
return [...r.values()];
|
|
340
340
|
}
|
|
@@ -355,91 +355,91 @@ class Z {
|
|
|
355
355
|
if (t.length === 0) return [];
|
|
356
356
|
const r = await this.getRegistrationRecordsAtBlock(e);
|
|
357
357
|
return t.map(
|
|
358
|
-
(
|
|
358
|
+
(i) => D(r, i, e).maxAcceptableCommissionBps
|
|
359
359
|
);
|
|
360
360
|
}
|
|
361
361
|
/** @inheritdoc */
|
|
362
362
|
async getVaultClaimableBy(t, e, r) {
|
|
363
|
-
const
|
|
363
|
+
const s = `0x${b(
|
|
364
364
|
e,
|
|
365
365
|
`getVaultClaimableBy claimer (vault=${t})`
|
|
366
|
-
)}`,
|
|
366
|
+
)}`, a = t.toLowerCase(), { number: l } = await this.publicClient.getBlock({
|
|
367
367
|
blockTag: "finalized"
|
|
368
368
|
});
|
|
369
|
-
if (
|
|
369
|
+
if (l < r)
|
|
370
370
|
throw new Error(
|
|
371
|
-
`Finalized block ${
|
|
371
|
+
`Finalized block ${l} is below vault ${t}'s registration block ${r}; the registration is not finalized yet, or the node is behind it`
|
|
372
372
|
);
|
|
373
|
-
let
|
|
373
|
+
let d = l;
|
|
374
374
|
for (; ; ) {
|
|
375
|
-
const
|
|
375
|
+
const h = it(
|
|
376
376
|
r,
|
|
377
|
-
|
|
377
|
+
d - rt + 1n
|
|
378
378
|
), p = await this.publicClient.getLogs({
|
|
379
379
|
address: this.contractAddress,
|
|
380
|
-
event:
|
|
381
|
-
args: { vaultId:
|
|
382
|
-
fromBlock:
|
|
383
|
-
toBlock:
|
|
380
|
+
event: ot,
|
|
381
|
+
args: { vaultId: a, claimerPK: s },
|
|
382
|
+
fromBlock: h,
|
|
383
|
+
toBlock: d,
|
|
384
384
|
strict: !0
|
|
385
385
|
});
|
|
386
386
|
if (p.length > 1) {
|
|
387
|
-
const
|
|
388
|
-
if (
|
|
387
|
+
const c = new Set(p.map((m) => m.transactionHash));
|
|
388
|
+
if (c.size > 1)
|
|
389
389
|
throw new Error(
|
|
390
|
-
`Found ${p.length} VaultClaimableBy logs for vault ${t} and claimer ${
|
|
390
|
+
`Found ${p.length} VaultClaimableBy logs for vault ${t} and claimer ${s} across ${c.size} transactions in blocks ${h}..${d}; a vault is redeemed once, so the node's answer is inconsistent`
|
|
391
391
|
);
|
|
392
392
|
}
|
|
393
393
|
if (p.length >= 1) {
|
|
394
|
-
const
|
|
394
|
+
const c = p[0];
|
|
395
395
|
return {
|
|
396
|
-
blockNumber:
|
|
397
|
-
claimerPk:
|
|
398
|
-
|
|
396
|
+
blockNumber: c.blockNumber,
|
|
397
|
+
claimerPk: b(
|
|
398
|
+
c.args.claimerPK,
|
|
399
399
|
`VaultClaimableBy.claimerPK (vault=${t})`
|
|
400
400
|
),
|
|
401
|
-
peginTxHash:
|
|
402
|
-
vaultCoreVersion:
|
|
403
|
-
proverCircuitVersion:
|
|
404
|
-
offchainParamsVersion:
|
|
405
|
-
universalChallengersVersion:
|
|
406
|
-
appVaultKeepersVersion:
|
|
401
|
+
peginTxHash: c.args.peginTxHash,
|
|
402
|
+
vaultCoreVersion: c.args.vaultCoreVersion,
|
|
403
|
+
proverCircuitVersion: c.args.proverCircuitVersion,
|
|
404
|
+
offchainParamsVersion: c.args.offchainParamsVersion,
|
|
405
|
+
universalChallengersVersion: c.args.universalChallengersVersion,
|
|
406
|
+
appVaultKeepersVersion: c.args.appVaultKeepersVersion
|
|
407
407
|
};
|
|
408
408
|
}
|
|
409
|
-
if (
|
|
410
|
-
throw new
|
|
409
|
+
if (h === r)
|
|
410
|
+
throw new G(
|
|
411
411
|
t,
|
|
412
|
-
|
|
412
|
+
s,
|
|
413
413
|
r,
|
|
414
|
-
|
|
414
|
+
l
|
|
415
415
|
);
|
|
416
|
-
|
|
416
|
+
d = h - 1n;
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
|
-
const
|
|
421
|
-
function
|
|
420
|
+
const ct = 0, ut = 255, lt = 12e4, dt = /^0xef0100[0-9a-f]{40}$/i;
|
|
421
|
+
function f(o, t) {
|
|
422
422
|
const e = o.startsWith("0x") ? o : o.startsWith("0X") ? `0x${o.slice(2)}` : `0x${o}`;
|
|
423
423
|
if (!/^0x(?:[0-9a-fA-F]{2})+$/.test(e))
|
|
424
424
|
throw new Error(`${t} must be non-empty, even-length hex`);
|
|
425
425
|
return e;
|
|
426
426
|
}
|
|
427
|
-
function
|
|
427
|
+
function S(o, t) {
|
|
428
428
|
if (!/^0x[0-9a-fA-F]{64}$/.test(o))
|
|
429
429
|
throw new Error(`${t} must be a 32-byte hex value`);
|
|
430
430
|
}
|
|
431
|
-
const
|
|
432
|
-
function
|
|
433
|
-
if (
|
|
431
|
+
const ht = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
432
|
+
function H(o) {
|
|
433
|
+
if (S(o, "expectedFingerprint"), o.toLowerCase() === ht)
|
|
434
434
|
throw new Error(
|
|
435
435
|
"expectedFingerprint must not be zero: the registry cannot resolve a zero fingerprint, so this submission would always revert"
|
|
436
436
|
);
|
|
437
437
|
}
|
|
438
|
-
function
|
|
439
|
-
if (!Number.isInteger(o) || o < 0 || o >
|
|
438
|
+
function pt(o) {
|
|
439
|
+
if (!Number.isInteger(o) || o < 0 || o > ut)
|
|
440
440
|
throw new Error(`htlcVout must be a uint8, got ${o}`);
|
|
441
441
|
}
|
|
442
|
-
class
|
|
442
|
+
class wt {
|
|
443
443
|
constructor(t) {
|
|
444
444
|
this.config = t;
|
|
445
445
|
}
|
|
@@ -448,36 +448,36 @@ class dt {
|
|
|
448
448
|
...t,
|
|
449
449
|
popSignature: { ...t.popSignature }
|
|
450
450
|
};
|
|
451
|
-
this.assertQuotedCommissionPresentWhenRequired(e.quotedCommissionBps),
|
|
452
|
-
const r = this.assertPopMatchesEthAccount(e.popSignature),
|
|
451
|
+
this.assertQuotedCommissionPresentWhenRequired(e.quotedCommissionBps), H(e.expectedFingerprint);
|
|
452
|
+
const r = this.assertPopMatchesEthAccount(e.popSignature), i = this.normalizeBtcPubkey(e.popSignature), s = f(
|
|
453
453
|
e.popSignature.btcPopSignature,
|
|
454
454
|
"btcPopSignature"
|
|
455
|
-
),
|
|
455
|
+
), a = this.normalizeRequest(
|
|
456
456
|
e,
|
|
457
457
|
r,
|
|
458
|
-
|
|
458
|
+
i
|
|
459
459
|
);
|
|
460
460
|
await this.assertVaultDoesNotExist(
|
|
461
|
-
|
|
462
|
-
|
|
461
|
+
a.vaultId,
|
|
462
|
+
a.peginTxHash
|
|
463
463
|
);
|
|
464
|
-
const
|
|
464
|
+
const l = await this.readPeginFee(e.vaultProvider), d = await this.resolveMaxAcceptableCommissionBps(
|
|
465
465
|
e.vaultProvider,
|
|
466
466
|
e.quotedCommissionBps
|
|
467
|
-
),
|
|
468
|
-
abi:
|
|
467
|
+
), h = I({
|
|
468
|
+
abi: u,
|
|
469
469
|
functionName: "submitPeginRequest",
|
|
470
470
|
args: [
|
|
471
471
|
r,
|
|
472
|
-
s,
|
|
473
472
|
i,
|
|
474
|
-
|
|
475
|
-
|
|
473
|
+
s,
|
|
474
|
+
a.unsignedPrePeginTx,
|
|
475
|
+
a.depositorSignedPeginTx,
|
|
476
476
|
e.vaultProvider,
|
|
477
|
-
|
|
477
|
+
d,
|
|
478
478
|
e.hashlock,
|
|
479
479
|
e.htlcVout,
|
|
480
|
-
|
|
480
|
+
a.payoutScript,
|
|
481
481
|
e.depositorWotsPkHash,
|
|
482
482
|
// Appended last on the singular overload; the batch takes it at
|
|
483
483
|
// position 4 instead. Order is the selector, so do not "tidy" either.
|
|
@@ -486,83 +486,83 @@ class dt {
|
|
|
486
486
|
});
|
|
487
487
|
return {
|
|
488
488
|
ethTxHash: await this.sendAndWait(
|
|
489
|
+
h,
|
|
489
490
|
l,
|
|
490
|
-
c,
|
|
491
491
|
!1,
|
|
492
492
|
r
|
|
493
493
|
),
|
|
494
|
-
vaultId:
|
|
495
|
-
peginTxHash:
|
|
494
|
+
vaultId: a.vaultId,
|
|
495
|
+
peginTxHash: a.peginTxHash
|
|
496
496
|
};
|
|
497
497
|
}
|
|
498
498
|
async registerPeginBatchOnChain(t) {
|
|
499
499
|
const e = {
|
|
500
500
|
...t,
|
|
501
501
|
popSignature: { ...t.popSignature },
|
|
502
|
-
requests: t.requests.map((
|
|
502
|
+
requests: t.requests.map((n) => ({ ...n }))
|
|
503
503
|
};
|
|
504
504
|
if (e.requests.length === 0)
|
|
505
505
|
throw new Error("Batch pegin requires at least one request");
|
|
506
|
-
this.assertQuotedCommissionPresentWhenRequired(e.quotedCommissionBps),
|
|
507
|
-
const r = this.assertPopMatchesEthAccount(e.popSignature),
|
|
506
|
+
this.assertQuotedCommissionPresentWhenRequired(e.quotedCommissionBps), H(e.expectedFingerprint);
|
|
507
|
+
const r = this.assertPopMatchesEthAccount(e.popSignature), i = f(
|
|
508
508
|
e.unsignedPrePeginTx,
|
|
509
509
|
"unsignedPrePeginTx"
|
|
510
|
-
),
|
|
510
|
+
), s = this.normalizeBtcPubkey(e.popSignature), a = f(
|
|
511
511
|
e.popSignature.btcPopSignature,
|
|
512
512
|
"btcPopSignature"
|
|
513
|
-
),
|
|
514
|
-
for (const
|
|
513
|
+
), l = [], d = [], h = /* @__PURE__ */ new Set();
|
|
514
|
+
for (const n of e.requests) {
|
|
515
515
|
const g = this.normalizeRequest(
|
|
516
516
|
{
|
|
517
|
-
...
|
|
517
|
+
...n,
|
|
518
518
|
unsignedPrePeginTx: e.unsignedPrePeginTx,
|
|
519
519
|
vaultProvider: e.vaultProvider,
|
|
520
520
|
depositorBtcPubkeyRaw: e.depositorBtcPubkeyRaw
|
|
521
521
|
},
|
|
522
522
|
r,
|
|
523
|
-
|
|
523
|
+
s
|
|
524
524
|
);
|
|
525
|
-
if (
|
|
525
|
+
if (h.has(g.vaultId))
|
|
526
526
|
throw new Error(`Duplicate vault in batch: ${g.vaultId}`);
|
|
527
|
-
|
|
527
|
+
h.add(g.vaultId), l.push({
|
|
528
528
|
vaultId: g.vaultId,
|
|
529
529
|
peginTxHash: g.peginTxHash
|
|
530
|
-
}),
|
|
531
|
-
depositorBtcPubKey:
|
|
532
|
-
btcPopSignature:
|
|
533
|
-
unsignedPrePeginTx:
|
|
530
|
+
}), d.push({
|
|
531
|
+
depositorBtcPubKey: s,
|
|
532
|
+
btcPopSignature: a,
|
|
533
|
+
unsignedPrePeginTx: i,
|
|
534
534
|
depositorSignedPeginTx: g.depositorSignedPeginTx,
|
|
535
|
-
hashlock:
|
|
536
|
-
htlcVout:
|
|
537
|
-
referralCode:
|
|
535
|
+
hashlock: n.hashlock,
|
|
536
|
+
htlcVout: n.htlcVout,
|
|
537
|
+
referralCode: ct,
|
|
538
538
|
depositorPayoutBtcAddress: g.payoutScript,
|
|
539
|
-
depositorWotsPkHash:
|
|
539
|
+
depositorWotsPkHash: n.depositorWotsPkHash
|
|
540
540
|
});
|
|
541
541
|
}
|
|
542
|
-
for (const
|
|
543
|
-
await this.assertVaultDoesNotExist(
|
|
544
|
-
const p = await this.readPeginFee(e.vaultProvider),
|
|
542
|
+
for (const n of l)
|
|
543
|
+
await this.assertVaultDoesNotExist(n.vaultId, n.peginTxHash);
|
|
544
|
+
const p = await this.readPeginFee(e.vaultProvider), c = await this.resolveMaxAcceptableCommissionBps(
|
|
545
545
|
e.vaultProvider,
|
|
546
546
|
e.quotedCommissionBps
|
|
547
|
-
),
|
|
548
|
-
abi:
|
|
547
|
+
), m = I({
|
|
548
|
+
abi: u,
|
|
549
549
|
functionName: "submitPeginRequestBatch",
|
|
550
550
|
// `expectedFingerprint` sits BEFORE `requests`, not appended. Reordering
|
|
551
551
|
// these five changes the selector and the call stops existing.
|
|
552
552
|
args: [
|
|
553
553
|
r,
|
|
554
554
|
e.vaultProvider,
|
|
555
|
-
|
|
555
|
+
c,
|
|
556
556
|
e.expectedFingerprint,
|
|
557
|
-
|
|
557
|
+
d
|
|
558
558
|
]
|
|
559
559
|
});
|
|
560
560
|
return { ethTxHash: await this.sendAndWait(
|
|
561
|
-
|
|
561
|
+
m,
|
|
562
562
|
p * BigInt(e.requests.length),
|
|
563
563
|
!0,
|
|
564
564
|
r
|
|
565
|
-
), vaults:
|
|
565
|
+
), vaults: l };
|
|
566
566
|
}
|
|
567
567
|
assertQuotedCommissionPresentWhenRequired(t) {
|
|
568
568
|
if (t === void 0 && this.config.requireQuotedCommissionBps)
|
|
@@ -576,15 +576,15 @@ class dt {
|
|
|
576
576
|
assertEthAccount(t) {
|
|
577
577
|
const e = this.config.ethWallet.account;
|
|
578
578
|
if (!e) throw new Error("Ethereum wallet account not found");
|
|
579
|
-
if (
|
|
579
|
+
if (!R(t, e.address))
|
|
580
580
|
throw new Error(
|
|
581
581
|
`Proof of possession was signed for ${t} but the Ethereum wallet is currently connected to ${e.address}. Reconnect the original account or sign a new proof of possession.`
|
|
582
582
|
);
|
|
583
583
|
return e.address;
|
|
584
584
|
}
|
|
585
585
|
normalizeBtcPubkey(t) {
|
|
586
|
-
return `0x${
|
|
587
|
-
|
|
586
|
+
return `0x${b(
|
|
587
|
+
f(t.depositorBtcPubkey, "Proof of possession BTC pubkey"),
|
|
588
588
|
"Proof of possession BTC pubkey"
|
|
589
589
|
)}`;
|
|
590
590
|
}
|
|
@@ -593,33 +593,33 @@ class dt {
|
|
|
593
593
|
// value through a per-request helper that has no use for it. It is validated
|
|
594
594
|
// once per call, at the top of each public method.
|
|
595
595
|
normalizeRequest(t, e, r) {
|
|
596
|
-
|
|
597
|
-
const
|
|
596
|
+
S(t.hashlock, "hashlock"), S(t.depositorWotsPkHash, "depositorWotsPkHash"), pt(t.htlcVout);
|
|
597
|
+
const i = f(
|
|
598
598
|
t.unsignedPrePeginTx,
|
|
599
599
|
"unsignedPrePeginTx"
|
|
600
|
-
),
|
|
600
|
+
), s = f(
|
|
601
601
|
t.depositorSignedPeginTx,
|
|
602
602
|
"depositorSignedPeginTx"
|
|
603
|
-
),
|
|
603
|
+
), a = Q(s);
|
|
604
604
|
return {
|
|
605
|
-
unsignedPrePeginTx:
|
|
606
|
-
depositorSignedPeginTx:
|
|
607
|
-
payoutScript:
|
|
605
|
+
unsignedPrePeginTx: i,
|
|
606
|
+
depositorSignedPeginTx: s,
|
|
607
|
+
payoutScript: Y(
|
|
608
608
|
t.depositorPayoutScriptPubKey,
|
|
609
609
|
r,
|
|
610
610
|
t.depositorBtcPubkeyRaw
|
|
611
611
|
),
|
|
612
|
-
peginTxHash:
|
|
613
|
-
vaultId:
|
|
612
|
+
peginTxHash: a,
|
|
613
|
+
vaultId: f(j(a, e), "vaultId")
|
|
614
614
|
};
|
|
615
615
|
}
|
|
616
616
|
async assertVaultDoesNotExist(t, e) {
|
|
617
617
|
if ((await this.config.publicClient.readContract({
|
|
618
618
|
address: this.config.btcVaultRegistry,
|
|
619
|
-
abi:
|
|
619
|
+
abi: u,
|
|
620
620
|
functionName: "getBtcVaultBasicInfo",
|
|
621
621
|
args: [t]
|
|
622
|
-
})).depositor !==
|
|
622
|
+
})).depositor !== q)
|
|
623
623
|
throw new Error(
|
|
624
624
|
`Vault already exists (ID: ${t}, peginTxHash: ${e}). Vault IDs are derived from the pegin transaction hash and depositor address. To create a new vault, use different UTXOs or a different amount to generate a unique transaction.`
|
|
625
625
|
);
|
|
@@ -628,7 +628,7 @@ class dt {
|
|
|
628
628
|
try {
|
|
629
629
|
return await this.config.publicClient.readContract({
|
|
630
630
|
address: this.config.btcVaultRegistry,
|
|
631
|
-
abi:
|
|
631
|
+
abi: u,
|
|
632
632
|
functionName: "getPegInFee",
|
|
633
633
|
args: [t]
|
|
634
634
|
});
|
|
@@ -642,69 +642,96 @@ class dt {
|
|
|
642
642
|
async resolveMaxAcceptableCommissionBps(t, e) {
|
|
643
643
|
let r;
|
|
644
644
|
try {
|
|
645
|
-
r = await new
|
|
645
|
+
r = await new at(
|
|
646
646
|
this.config.publicClient,
|
|
647
647
|
this.config.btcVaultRegistry
|
|
648
648
|
).getVaultProviderCommission(t);
|
|
649
|
-
} catch (
|
|
649
|
+
} catch (i) {
|
|
650
650
|
throw new Error(
|
|
651
651
|
"Failed to query vault provider commission from the contract. Please check your network connection and contract address.",
|
|
652
|
-
{ cause:
|
|
652
|
+
{ cause: i }
|
|
653
653
|
);
|
|
654
654
|
}
|
|
655
655
|
if (e !== void 0) {
|
|
656
|
-
if (r > e +
|
|
656
|
+
if (r > e + T)
|
|
657
657
|
throw new Error(
|
|
658
|
-
`Vault provider commission changed since quote: quoted ${e} bps, chain currently reports ${r} bps (allowed drift ${
|
|
658
|
+
`Vault provider commission changed since quote: quoted ${e} bps, chain currently reports ${r} bps (allowed drift ${T} bps). Please refresh and try again.`
|
|
659
659
|
);
|
|
660
|
-
return
|
|
660
|
+
return N(e);
|
|
661
661
|
}
|
|
662
|
-
return
|
|
662
|
+
return N(r);
|
|
663
663
|
}
|
|
664
|
-
async sendAndWait(t, e, r,
|
|
665
|
-
let
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
664
|
+
async sendAndWait(t, e, r, i) {
|
|
665
|
+
let s = this.assertEthAccount(i);
|
|
666
|
+
const a = await this.config.publicClient.getCode({ address: s }), l = a !== void 0 && a !== "0x" && !dt.test(a);
|
|
667
|
+
let d, h = e;
|
|
668
|
+
if (!l) {
|
|
669
|
+
let n;
|
|
670
|
+
try {
|
|
671
|
+
n = await this.config.publicClient.prepareTransactionRequest({
|
|
672
|
+
to: this.config.btcVaultRegistry,
|
|
673
|
+
data: t,
|
|
674
|
+
value: e,
|
|
675
|
+
account: s,
|
|
676
|
+
chain: this.config.ethChain,
|
|
677
|
+
parameters: ["gas", "fees", "type"]
|
|
678
|
+
});
|
|
679
|
+
} catch (M) {
|
|
680
|
+
B(M);
|
|
681
|
+
}
|
|
682
|
+
const { gas: g, type: w, gasPrice: V, maxFeePerGas: E, maxPriorityFeePerGas: C } = n, P = w === "eip1559" && typeof E == "bigint" && typeof C == "bigint" && C >= 0n && E >= C ? { type: w, maxFeePerGas: E, maxPriorityFeePerGas: C } : w === "legacy" && typeof V == "bigint" && V >= 0n ? { type: w, gasPrice: V } : void 0;
|
|
683
|
+
if (typeof g != "bigint" || g <= 0n || !P)
|
|
684
|
+
throw new Error(
|
|
685
|
+
"Failed to prepare registration gas and fees. Try again."
|
|
686
|
+
);
|
|
687
|
+
d = { gas: g, ...P }, h += g * (P.type === "eip1559" ? P.maxFeePerGas : P.gasPrice);
|
|
675
688
|
}
|
|
676
|
-
|
|
677
|
-
|
|
689
|
+
const p = await this.config.publicClient.getBalance({
|
|
690
|
+
address: this.assertEthAccount(i)
|
|
691
|
+
});
|
|
692
|
+
if (typeof p != "bigint" || p < 0n)
|
|
693
|
+
throw new Error("Failed to read the Ethereum balance. Try again.");
|
|
694
|
+
if (p < h)
|
|
695
|
+
throw new L();
|
|
696
|
+
const c = await this.config.ethWallet.getAddresses();
|
|
697
|
+
if (!Array.isArray(c) || !c.every(
|
|
698
|
+
(n) => typeof n == "string" && U(n)
|
|
699
|
+
) || !c.some((n) => R(n, i)))
|
|
700
|
+
throw new Error(
|
|
701
|
+
"The Ethereum wallet account is no longer available. Reconnect it and try again."
|
|
702
|
+
);
|
|
703
|
+
s = this.assertEthAccount(i);
|
|
704
|
+
let m;
|
|
678
705
|
try {
|
|
679
|
-
|
|
706
|
+
m = await this.config.ethWallet.sendTransaction({
|
|
680
707
|
to: this.config.btcVaultRegistry,
|
|
681
708
|
data: t,
|
|
682
709
|
value: e,
|
|
683
|
-
|
|
684
|
-
account:
|
|
710
|
+
...d,
|
|
711
|
+
account: s,
|
|
685
712
|
chain: this.config.ethChain
|
|
686
713
|
});
|
|
687
|
-
} catch (
|
|
688
|
-
|
|
714
|
+
} catch (n) {
|
|
715
|
+
B(n);
|
|
689
716
|
}
|
|
690
|
-
const
|
|
717
|
+
const y = await W({
|
|
691
718
|
publicClient: this.config.publicClient,
|
|
692
|
-
walletAddress:
|
|
693
|
-
hash:
|
|
694
|
-
timeout: this.config.receiptTimeoutMs ??
|
|
719
|
+
walletAddress: i,
|
|
720
|
+
hash: m,
|
|
721
|
+
timeout: this.config.receiptTimeoutMs ?? lt
|
|
695
722
|
});
|
|
696
|
-
return
|
|
723
|
+
return y.status === "reverted" && B(
|
|
697
724
|
new Error(
|
|
698
|
-
`${r ? "Batch transaction" : "Transaction"} reverted. Hash: ${
|
|
725
|
+
`${r ? "Batch transaction" : "Transaction"} reverted. Hash: ${y.transactionHash}. Check a block explorer for details.`
|
|
699
726
|
)
|
|
700
|
-
),
|
|
727
|
+
), y.transactionHash;
|
|
701
728
|
}
|
|
702
729
|
}
|
|
703
730
|
export {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
731
|
+
T as C,
|
|
732
|
+
Z as M,
|
|
733
|
+
wt as V,
|
|
734
|
+
at as a,
|
|
735
|
+
N as c
|
|
709
736
|
};
|
|
710
|
-
//# sourceMappingURL=pegin-registration-client-
|
|
737
|
+
//# sourceMappingURL=pegin-registration-client-Yc-Qs5kq.js.map
|