@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.
Files changed (53) hide show
  1. package/dist/PayoutManager-3-MzBVLj.js.map +1 -1
  2. package/dist/PayoutManager-PQqeqX41.cjs.map +1 -1
  3. package/dist/{PeginManager-m3IlM4wS.js → PeginManager-BvIZvqLp.js} +4 -4
  4. package/dist/PeginManager-BvIZvqLp.js.map +1 -0
  5. package/dist/{PeginManager-D_ZUfbIy.cjs → PeginManager-CdYTFgrY.cjs} +2 -2
  6. package/dist/PeginManager-CdYTFgrY.cjs.map +1 -0
  7. package/dist/buildAndBroadcastReclaim-CMjlyooo.cjs.map +1 -1
  8. package/dist/buildAndBroadcastReclaim-D8l-QJWo.js.map +1 -1
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.js +4 -4
  11. package/dist/pegin-registration-client-Cdgp5Ge_.cjs +2 -0
  12. package/dist/pegin-registration-client-Cdgp5Ge_.cjs.map +1 -0
  13. package/dist/{pegin-registration-client-BlrXyZpF.js → pegin-registration-client-Yc-Qs5kq.js} +232 -205
  14. package/dist/pegin-registration-client-Yc-Qs5kq.js.map +1 -0
  15. package/dist/signer-set-reader-CNEfzwuA.cjs +2 -0
  16. package/dist/signer-set-reader-CNEfzwuA.cjs.map +1 -0
  17. package/dist/{signer-set-reader-DiwLeqik.js → signer-set-reader-Csz8RXQi.js} +6 -5
  18. package/dist/signer-set-reader-Csz8RXQi.js.map +1 -0
  19. package/dist/tbv/core/clients/eth/__tests__/contract-address-resolver.test.d.ts +2 -0
  20. package/dist/tbv/core/clients/eth/__tests__/contract-address-resolver.test.d.ts.map +1 -0
  21. package/dist/tbv/core/clients/eth/contract-address-resolver.d.ts +3 -1
  22. package/dist/tbv/core/clients/eth/contract-address-resolver.d.ts.map +1 -1
  23. package/dist/tbv/core/clients/eth/index.cjs +1 -1
  24. package/dist/tbv/core/clients/eth/index.js +2 -2
  25. package/dist/tbv/core/clients/eth/pegin-registration-client.d.ts.map +1 -1
  26. package/dist/tbv/core/clients/index.cjs +1 -1
  27. package/dist/tbv/core/clients/index.js +2 -2
  28. package/dist/tbv/core/deposit-terms/depositTerms.d.ts +3 -3
  29. package/dist/tbv/core/deposit-terms/prePeginApproval.d.ts +2 -2
  30. package/dist/tbv/core/index.cjs +1 -1
  31. package/dist/tbv/core/index.js +4 -4
  32. package/dist/tbv/core/managers/index.cjs +1 -1
  33. package/dist/tbv/core/managers/index.js +1 -1
  34. package/dist/tbv/core/primitives/psbt/__tests__/depositorClaim.test.d.ts +1 -1
  35. package/dist/tbv/core/primitives/psbt/payout.d.ts +2 -1
  36. package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
  37. package/dist/tbv/index.cjs +1 -1
  38. package/dist/tbv/index.js +4 -4
  39. package/dist/{toRefundInputs-D5tx3eeA.js → toRefundInputs-CPtK0OgP.js} +2 -2
  40. package/dist/{toRefundInputs-D5tx3eeA.js.map → toRefundInputs-CPtK0OgP.js.map} +1 -1
  41. package/dist/{toRefundInputs-Df6eRITl.cjs → toRefundInputs-DYVCJ2SN.cjs} +2 -2
  42. package/dist/{toRefundInputs-Df6eRITl.cjs.map → toRefundInputs-DYVCJ2SN.cjs.map} +1 -1
  43. package/dist/verifyScriptPathSchnorrSignature-BVGPEZXW.js.map +1 -1
  44. package/dist/verifyScriptPathSchnorrSignature-p3sVoWQi.cjs.map +1 -1
  45. package/package.json +1 -1
  46. package/dist/PeginManager-D_ZUfbIy.cjs.map +0 -1
  47. package/dist/PeginManager-m3IlM4wS.js.map +0 -1
  48. package/dist/pegin-registration-client-BlrXyZpF.js.map +0 -1
  49. package/dist/pegin-registration-client-DOb-Iznp.cjs +0 -2
  50. package/dist/pegin-registration-client-DOb-Iznp.cjs.map +0 -1
  51. package/dist/signer-set-reader-CJfV-GDz.cjs +0 -2
  52. package/dist/signer-set-reader-CJfV-GDz.cjs.map +0 -1
  53. package/dist/signer-set-reader-DiwLeqik.js.map +0 -1
@@ -1,22 +1,22 @@
1
- import { getAbiItem as R, encodeFunctionData as E, isAddressEqual as $, zeroAddress as K } from "viem";
2
- import { B as a } from "./BTCVaultRegistry.abi-DnP4UkB5.js";
3
- import { B as v, h as b } from "./BTCVaultRegistryKeyEpochs.abi-Btg0nBz1.js";
4
- import { M as x } from "./constants-CmDDuM3L.js";
5
- import { waitForTransactionReceiptSmartAware as N } from "./tbv/core/utils/eth/index.js";
6
- import { a as P, R as _, g as H, V as M, j as O, h as F, k as q, d as L } from "./registration-records-D39ApuHS.js";
7
- const V = 25, U = 9999;
8
- function T(o) {
9
- if (!Number.isInteger(o) || o < 0 || o >= x)
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, ${x}), got ${o}`
11
+ `Quoted commissionBps must be an integer in [0, ${$}), got ${o}`
12
12
  );
13
13
  return Math.min(
14
- o + V,
15
- U
14
+ o + T,
15
+ Z
16
16
  );
17
17
  }
18
- const A = 9999;
19
- function S(o) {
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 C(o) {
30
+ function x(o) {
31
31
  const t = Number(o.offchainParamsVersion);
32
- return O(t), {
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 z = 1n << 64n, W = 0n, D = R({
49
- abi: a,
48
+ const J = 1n << 64n, tt = 0n, et = O({
49
+ abi: u,
50
50
  name: "PegInSubmitted"
51
- }), X = R({
52
- abi: a,
51
+ }), ot = O({
52
+ abi: u,
53
53
  name: "VaultClaimableBy"
54
- }), Q = 7200n;
55
- function G(o, t) {
54
+ }), rt = 7200n;
55
+ function it(o, t) {
56
56
  return o > t ? o : t;
57
57
  }
58
- function Y(o, t) {
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 w(o, t, e) {
77
- if (o < 0n || o >= z)
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 j = "not found on-chain or has no pegin transaction";
84
- function y(o, t) {
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} ${j}`);
86
+ throw new Error(`Vault ${t} ${nt}`);
87
87
  }
88
- function I(o, t) {
89
- return y(o, t), {
90
- vpKeyEpoch: w(o.vpKeyEpoch, "vpKeyEpoch", t),
91
- appKeeperKeyEpoch: w(
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: w(o.ucKeyEpoch, "ucKeyEpoch", t)
96
+ ucKeyEpoch: v(o.ucKeyEpoch, "ucKeyEpoch", t)
97
97
  };
98
98
  }
99
- class Z {
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
- W,
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 s = await this.publicClient.readContract({
142
+ const i = await this.publicClient.readContract({
143
143
  address: this.contractAddress,
144
- abi: a,
144
+ abi: u,
145
145
  functionName: "getOperationBtcKeyAtEpoch",
146
146
  args: [t, e],
147
147
  blockNumber: r
148
148
  });
149
- return P(
150
- s,
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: a,
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: a,
188
+ abi: u,
189
189
  functionName: "getCurrentOperationBtcKey",
190
190
  args: [t]
191
191
  });
192
- return P(
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: v,
216
+ abi: k,
217
217
  functionName: "getBtcVaultProtocolInfo",
218
218
  args: [t]
219
219
  });
220
- return I(e, t);
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: v,
226
+ abi: k,
227
227
  functionName: "getBtcVaultProtocolInfo",
228
228
  args: [r]
229
229
  })),
230
230
  allowFailure: !1
231
231
  })).map(
232
- (r, s) => I(r, t[s])
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: a,
238
+ abi: u,
239
239
  functionName: "getBtcVaultBasicInfo",
240
240
  args: [t]
241
241
  });
242
- return S(e);
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: a,
247
+ abi: u,
248
248
  functionName: "getBtcVaultProtocolInfo",
249
249
  args: [t]
250
250
  });
251
- return C(e);
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: a,
257
+ abi: u,
258
258
  functionName: "getBtcVaultProtocolInfo",
259
259
  args: [r]
260
260
  })),
261
261
  allowFailure: !1
262
- })).map((r, s) => {
263
- const i = r;
264
- return y(i, t[s]), C(i);
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: a,
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: a,
289
+ abi: u,
290
290
  functionName: "getVaultProviderCommission",
291
291
  args: [t]
292
292
  });
293
- if (!Number.isInteger(e) || e < 0 || e > A)
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, ${A}]`
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: a,
304
+ abi: u,
305
305
  functionName: "getBtcVaultBasicInfo",
306
306
  args: [t]
307
307
  },
308
308
  {
309
309
  address: this.contractAddress,
310
- abi: a,
310
+ abi: u,
311
311
  functionName: "getBtcVaultProtocolInfo",
312
312
  args: [t]
313
313
  }
314
314
  ],
315
315
  allowFailure: !1
316
- }), s = S(e), i = C(r);
317
- return y(i, t), { basic: s, protocol: i };
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: D,
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 _(t);
329
+ throw new z(t);
330
330
  const r = /* @__PURE__ */ new Map();
331
- for (const s of e) {
332
- const i = Y(s.args, s.blockNumber);
333
- if (r.has(i.vaultId))
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 ${i.vaultId} at block ${t}, found more than one`
335
+ `Expected one PegInSubmitted log for vault ${s.vaultId} at block ${t}, found more than one`
336
336
  );
337
- r.set(i.vaultId, i);
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
- (s) => H(r, s, e).maxAcceptableCommissionBps
358
+ (i) => D(r, i, e).maxAcceptableCommissionBps
359
359
  );
360
360
  }
361
361
  /** @inheritdoc */
362
362
  async getVaultClaimableBy(t, e, r) {
363
- const i = `0x${P(
363
+ const s = `0x${b(
364
364
  e,
365
365
  `getVaultClaimableBy claimer (vault=${t})`
366
- )}`, n = t.toLowerCase(), { number: c } = await this.publicClient.getBlock({
366
+ )}`, a = t.toLowerCase(), { number: l } = await this.publicClient.getBlock({
367
367
  blockTag: "finalized"
368
368
  });
369
- if (c < r)
369
+ if (l < r)
370
370
  throw new Error(
371
- `Finalized block ${c} is below vault ${t}'s registration block ${r}; the registration is not finalized yet, or the node is behind it`
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 u = c;
373
+ let d = l;
374
374
  for (; ; ) {
375
- const l = G(
375
+ const h = it(
376
376
  r,
377
- u - Q + 1n
377
+ d - rt + 1n
378
378
  ), p = await this.publicClient.getLogs({
379
379
  address: this.contractAddress,
380
- event: X,
381
- args: { vaultId: n, claimerPK: i },
382
- fromBlock: l,
383
- toBlock: u,
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 d = new Set(p.map((f) => f.transactionHash));
388
- if (d.size > 1)
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 ${i} across ${d.size} transactions in blocks ${l}..${u}; a vault is redeemed once, so the node's answer is inconsistent`
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 d = p[0];
394
+ const c = p[0];
395
395
  return {
396
- blockNumber: d.blockNumber,
397
- claimerPk: P(
398
- d.args.claimerPK,
396
+ blockNumber: c.blockNumber,
397
+ claimerPk: b(
398
+ c.args.claimerPK,
399
399
  `VaultClaimableBy.claimerPK (vault=${t})`
400
400
  ),
401
- peginTxHash: d.args.peginTxHash,
402
- vaultCoreVersion: d.args.vaultCoreVersion,
403
- proverCircuitVersion: d.args.proverCircuitVersion,
404
- offchainParamsVersion: d.args.offchainParamsVersion,
405
- universalChallengersVersion: d.args.universalChallengersVersion,
406
- appVaultKeepersVersion: d.args.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 (l === r)
410
- throw new M(
409
+ if (h === r)
410
+ throw new G(
411
411
  t,
412
- i,
412
+ s,
413
413
  r,
414
- c
414
+ l
415
415
  );
416
- u = l - 1n;
416
+ d = h - 1n;
417
417
  }
418
418
  }
419
419
  }
420
- const J = 0, tt = 255, et = 12e4;
421
- function m(o, t) {
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 B(o, t) {
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 ot = "0x0000000000000000000000000000000000000000000000000000000000000000";
432
- function k(o) {
433
- if (B(o, "expectedFingerprint"), o.toLowerCase() === ot)
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 rt(o) {
439
- if (!Number.isInteger(o) || o < 0 || o > tt)
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 dt {
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), k(e.expectedFingerprint);
452
- const r = this.assertPopMatchesEthAccount(e.popSignature), s = this.normalizeBtcPubkey(e.popSignature), i = m(
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
- ), n = this.normalizeRequest(
455
+ ), a = this.normalizeRequest(
456
456
  e,
457
457
  r,
458
- s
458
+ i
459
459
  );
460
460
  await this.assertVaultDoesNotExist(
461
- n.vaultId,
462
- n.peginTxHash
461
+ a.vaultId,
462
+ a.peginTxHash
463
463
  );
464
- const c = await this.readPeginFee(e.vaultProvider), u = await this.resolveMaxAcceptableCommissionBps(
464
+ const l = await this.readPeginFee(e.vaultProvider), d = await this.resolveMaxAcceptableCommissionBps(
465
465
  e.vaultProvider,
466
466
  e.quotedCommissionBps
467
- ), l = E({
468
- abi: a,
467
+ ), h = I({
468
+ abi: u,
469
469
  functionName: "submitPeginRequest",
470
470
  args: [
471
471
  r,
472
- s,
473
472
  i,
474
- n.unsignedPrePeginTx,
475
- n.depositorSignedPeginTx,
473
+ s,
474
+ a.unsignedPrePeginTx,
475
+ a.depositorSignedPeginTx,
476
476
  e.vaultProvider,
477
- u,
477
+ d,
478
478
  e.hashlock,
479
479
  e.htlcVout,
480
- n.payoutScript,
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: n.vaultId,
495
- peginTxHash: n.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((h) => ({ ...h }))
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), k(e.expectedFingerprint);
507
- const r = this.assertPopMatchesEthAccount(e.popSignature), s = m(
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
- ), i = this.normalizeBtcPubkey(e.popSignature), n = m(
510
+ ), s = this.normalizeBtcPubkey(e.popSignature), a = f(
511
511
  e.popSignature.btcPopSignature,
512
512
  "btcPopSignature"
513
- ), c = [], u = [], l = /* @__PURE__ */ new Set();
514
- for (const h of e.requests) {
513
+ ), l = [], d = [], h = /* @__PURE__ */ new Set();
514
+ for (const n of e.requests) {
515
515
  const g = this.normalizeRequest(
516
516
  {
517
- ...h,
517
+ ...n,
518
518
  unsignedPrePeginTx: e.unsignedPrePeginTx,
519
519
  vaultProvider: e.vaultProvider,
520
520
  depositorBtcPubkeyRaw: e.depositorBtcPubkeyRaw
521
521
  },
522
522
  r,
523
- i
523
+ s
524
524
  );
525
- if (l.has(g.vaultId))
525
+ if (h.has(g.vaultId))
526
526
  throw new Error(`Duplicate vault in batch: ${g.vaultId}`);
527
- l.add(g.vaultId), c.push({
527
+ h.add(g.vaultId), l.push({
528
528
  vaultId: g.vaultId,
529
529
  peginTxHash: g.peginTxHash
530
- }), u.push({
531
- depositorBtcPubKey: i,
532
- btcPopSignature: n,
533
- unsignedPrePeginTx: s,
530
+ }), d.push({
531
+ depositorBtcPubKey: s,
532
+ btcPopSignature: a,
533
+ unsignedPrePeginTx: i,
534
534
  depositorSignedPeginTx: g.depositorSignedPeginTx,
535
- hashlock: h.hashlock,
536
- htlcVout: h.htlcVout,
537
- referralCode: J,
535
+ hashlock: n.hashlock,
536
+ htlcVout: n.htlcVout,
537
+ referralCode: ct,
538
538
  depositorPayoutBtcAddress: g.payoutScript,
539
- depositorWotsPkHash: h.depositorWotsPkHash
539
+ depositorWotsPkHash: n.depositorWotsPkHash
540
540
  });
541
541
  }
542
- for (const h of c)
543
- await this.assertVaultDoesNotExist(h.vaultId, h.peginTxHash);
544
- const p = await this.readPeginFee(e.vaultProvider), d = await this.resolveMaxAcceptableCommissionBps(
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
- ), f = E({
548
- abi: a,
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
- d,
555
+ c,
556
556
  e.expectedFingerprint,
557
- u
557
+ d
558
558
  ]
559
559
  });
560
560
  return { ethTxHash: await this.sendAndWait(
561
- f,
561
+ m,
562
562
  p * BigInt(e.requests.length),
563
563
  !0,
564
564
  r
565
- ), vaults: c };
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 (!$(t, e.address))
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${P(
587
- m(t.depositorBtcPubkey, "Proof of possession BTC pubkey"),
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
- B(t.hashlock, "hashlock"), B(t.depositorWotsPkHash, "depositorWotsPkHash"), rt(t.htlcVout);
597
- const s = m(
596
+ S(t.hashlock, "hashlock"), S(t.depositorWotsPkHash, "depositorWotsPkHash"), pt(t.htlcVout);
597
+ const i = f(
598
598
  t.unsignedPrePeginTx,
599
599
  "unsignedPrePeginTx"
600
- ), i = m(
600
+ ), s = f(
601
601
  t.depositorSignedPeginTx,
602
602
  "depositorSignedPeginTx"
603
- ), n = F(i);
603
+ ), a = Q(s);
604
604
  return {
605
- unsignedPrePeginTx: s,
606
- depositorSignedPeginTx: i,
607
- payoutScript: q(
605
+ unsignedPrePeginTx: i,
606
+ depositorSignedPeginTx: s,
607
+ payoutScript: Y(
608
608
  t.depositorPayoutScriptPubKey,
609
609
  r,
610
610
  t.depositorBtcPubkeyRaw
611
611
  ),
612
- peginTxHash: n,
613
- vaultId: m(L(n, e), "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: a,
619
+ abi: u,
620
620
  functionName: "getBtcVaultBasicInfo",
621
621
  args: [t]
622
- })).depositor !== K)
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: a,
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 Z(
645
+ r = await new at(
646
646
  this.config.publicClient,
647
647
  this.config.btcVaultRegistry
648
648
  ).getVaultProviderCommission(t);
649
- } catch (s) {
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: s }
652
+ { cause: i }
653
653
  );
654
654
  }
655
655
  if (e !== void 0) {
656
- if (r > e + V)
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 ${V} bps). Please refresh and try again.`
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 T(e);
660
+ return N(e);
661
661
  }
662
- return T(r);
662
+ return N(r);
663
663
  }
664
- async sendAndWait(t, e, r, s) {
665
- let i = this.assertEthAccount(s), n;
666
- try {
667
- n = await this.config.publicClient.estimateGas({
668
- to: this.config.btcVaultRegistry,
669
- data: t,
670
- value: e,
671
- account: i
672
- });
673
- } catch (l) {
674
- b(l);
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
- i = this.assertEthAccount(s);
677
- let c;
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
- c = await this.config.ethWallet.sendTransaction({
706
+ m = await this.config.ethWallet.sendTransaction({
680
707
  to: this.config.btcVaultRegistry,
681
708
  data: t,
682
709
  value: e,
683
- gas: n,
684
- account: i,
710
+ ...d,
711
+ account: s,
685
712
  chain: this.config.ethChain
686
713
  });
687
- } catch (l) {
688
- b(l);
714
+ } catch (n) {
715
+ B(n);
689
716
  }
690
- const u = await N({
717
+ const y = await W({
691
718
  publicClient: this.config.publicClient,
692
- walletAddress: s,
693
- hash: c,
694
- timeout: this.config.receiptTimeoutMs ?? et
719
+ walletAddress: i,
720
+ hash: m,
721
+ timeout: this.config.receiptTimeoutMs ?? lt
695
722
  });
696
- return u.status === "reverted" && b(
723
+ return y.status === "reverted" && B(
697
724
  new Error(
698
- `${r ? "Batch transaction" : "Transaction"} reverted. Hash: ${u.transactionHash}. Check a block explorer for details.`
725
+ `${r ? "Batch transaction" : "Transaction"} reverted. Hash: ${y.transactionHash}. Check a block explorer for details.`
699
726
  )
700
- ), u.transactionHash;
727
+ ), y.transactionHash;
701
728
  }
702
729
  }
703
730
  export {
704
- V as C,
705
- U as M,
706
- dt as V,
707
- Z as a,
708
- T as c
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-BlrXyZpF.js.map
737
+ //# sourceMappingURL=pegin-registration-client-Yc-Qs5kq.js.map