@babylonlabs-io/ts-sdk 0.77.0 → 0.78.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/{BTCVaultRegistry.abi-z7d_eP22.cjs → BTCVaultRegistry.abi-BJnjzEWD.cjs} +2 -2
- package/dist/BTCVaultRegistry.abi-BJnjzEWD.cjs.map +1 -0
- package/dist/{BTCVaultRegistry.abi-CJwWI2EO.js → BTCVaultRegistry.abi-BT3eo60h.js} +279 -2
- package/dist/BTCVaultRegistry.abi-BT3eo60h.js.map +1 -0
- package/dist/{PeginManager-DNimKlmw.js → PeginManager-Cz0Ytdwo.js} +3 -3
- package/dist/{PeginManager-DNimKlmw.js.map → PeginManager-Cz0Ytdwo.js.map} +1 -1
- package/dist/{PeginManager-DEByBX5R.cjs → PeginManager-DE2lTWMl.cjs} +2 -2
- package/dist/{PeginManager-DEByBX5R.cjs.map → PeginManager-DE2lTWMl.cjs.map} +1 -1
- package/dist/{buildAndBroadcastReclaim-Cqc6Jiqk.cjs → buildAndBroadcastReclaim-CB5VPETy.cjs} +2 -2
- package/dist/{buildAndBroadcastReclaim-Cqc6Jiqk.cjs.map → buildAndBroadcastReclaim-CB5VPETy.cjs.map} +1 -1
- package/dist/{buildAndBroadcastReclaim-DCGcupg7.js → buildAndBroadcastReclaim-DD50pVB1.js} +2 -2
- package/dist/{buildAndBroadcastReclaim-DCGcupg7.js.map → buildAndBroadcastReclaim-DD50pVB1.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +188 -186
- package/dist/{pegin-registration-client-CXK3B_D1.js → pegin-registration-client-7Vbtdypu.js} +287 -224
- package/dist/pegin-registration-client-7Vbtdypu.js.map +1 -0
- package/dist/pegin-registration-client-CSe1vOum.cjs +2 -0
- package/dist/pegin-registration-client-CSe1vOum.cjs.map +1 -0
- package/dist/tbv/core/clients/eth/index.cjs +1 -1
- package/dist/tbv/core/clients/eth/index.d.ts +1 -0
- package/dist/tbv/core/clients/eth/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/index.js +14 -12
- package/dist/tbv/core/clients/eth/registration-logs-error.d.ts +20 -0
- package/dist/tbv/core/clients/eth/registration-logs-error.d.ts.map +1 -0
- package/dist/tbv/core/clients/eth/types.d.ts +12 -0
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +19 -0
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +41 -39
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +227 -1
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/index.cjs +1 -1
- package/dist/tbv/core/contracts/index.js +1 -1
- package/dist/tbv/core/deposit-terms/commissionCeiling.d.ts +3 -2
- package/dist/tbv/core/deposit-terms/commissionCeiling.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +186 -184
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +186 -184
- package/dist/{toRefundInputs-meTyor7r.cjs → toRefundInputs-BH3wkNC4.cjs} +2 -2
- package/dist/{toRefundInputs-meTyor7r.cjs.map → toRefundInputs-BH3wkNC4.cjs.map} +1 -1
- package/dist/{toRefundInputs-BNSXIymn.js → toRefundInputs-D708M8MA.js} +2 -2
- package/dist/{toRefundInputs-BNSXIymn.js.map → toRefundInputs-D708M8MA.js.map} +1 -1
- package/dist/{types-BzSOthHH.cjs → types-BN0jOH8K.cjs} +2 -2
- package/dist/{types-BzSOthHH.cjs.map → types-BN0jOH8K.cjs.map} +1 -1
- package/dist/{types-C5DyrC8F.js → types-BwqkOoJ6.js} +3 -3
- package/dist/{types-C5DyrC8F.js.map → types-BwqkOoJ6.js.map} +1 -1
- package/package.json +1 -1
- package/dist/BTCVaultRegistry.abi-CJwWI2EO.js.map +0 -1
- package/dist/BTCVaultRegistry.abi-z7d_eP22.cjs.map +0 -1
- package/dist/pegin-registration-client-CXK3B_D1.js.map +0 -1
- package/dist/pegin-registration-client-DLsMNm8Z.cjs +0 -2
- package/dist/pegin-registration-client-DLsMNm8Z.cjs.map +0 -1
package/dist/{pegin-registration-client-CXK3B_D1.js → pegin-registration-client-7Vbtdypu.js}
RENAMED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { isAddress as
|
|
5
|
-
import { B as
|
|
6
|
-
import { B as
|
|
7
|
-
import { M as
|
|
8
|
-
import { waitForTransactionReceiptSmartAware as
|
|
9
|
-
import { a as
|
|
10
|
-
import { s as
|
|
11
|
-
import { c as
|
|
12
|
-
const k = 25,
|
|
13
|
-
function
|
|
14
|
-
if (!Number.isInteger(t) || t < 0 || t >=
|
|
1
|
+
var dt = Object.defineProperty;
|
|
2
|
+
var pt = (t, e, o) => e in t ? dt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o;
|
|
3
|
+
var y = (t, e, o) => pt(t, typeof e != "symbol" ? e + "" : e, o);
|
|
4
|
+
import { isAddress as gt, keccak256 as ft, encodeAbiParameters as mt, getAbiItem as N, encodeFunctionData as H, isAddressEqual as Pt, zeroAddress as bt } from "viem";
|
|
5
|
+
import { B as g } from "./BTCVaultRegistry.abi-BT3eo60h.js";
|
|
6
|
+
import { B as K, h as T } from "./BTCVaultRegistryKeyEpochs.abi-D8cIbMtH.js";
|
|
7
|
+
import { M as O, b as M } from "./constants-D5vORbQE.js";
|
|
8
|
+
import { waitForTransactionReceiptSmartAware as yt } from "./tbv/core/utils/eth/index.js";
|
|
9
|
+
import { a as C } from "./onChainBtcPubkey-C-6UWpD8.js";
|
|
10
|
+
import { s as j, b as E, a as wt } from "./secp256k1-D-H9jmd7.js";
|
|
11
|
+
import { c as Et, H as Ct, r as x, a as F, h as J, b as _, s as S } from "./sha2-CLpQd0Rd.js";
|
|
12
|
+
const k = 25, xt = 9999;
|
|
13
|
+
function U(t) {
|
|
14
|
+
if (!Number.isInteger(t) || t < 0 || t >= O)
|
|
15
15
|
throw new Error(
|
|
16
|
-
`Quoted commissionBps must be an integer in [0, ${
|
|
16
|
+
`Quoted commissionBps must be an integer in [0, ${O}), got ${t}`
|
|
17
17
|
);
|
|
18
18
|
return Math.min(
|
|
19
19
|
t + k,
|
|
20
|
-
|
|
20
|
+
xt
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
|
-
const
|
|
23
|
+
const It = /* @__PURE__ */ Uint8Array.from([
|
|
24
24
|
7,
|
|
25
25
|
4,
|
|
26
26
|
13,
|
|
@@ -37,25 +37,25 @@ const Ct = /* @__PURE__ */ Uint8Array.from([
|
|
|
37
37
|
14,
|
|
38
38
|
11,
|
|
39
39
|
8
|
|
40
|
-
]),
|
|
41
|
-
const o = [[
|
|
40
|
+
]), Z = Uint8Array.from(new Array(16).fill(0).map((t, e) => e)), Bt = Z.map((t) => (9 * t + 5) % 16), tt = /* @__PURE__ */ (() => {
|
|
41
|
+
const o = [[Z], [Bt]];
|
|
42
42
|
for (let n = 0; n < 4; n++)
|
|
43
|
-
for (let
|
|
44
|
-
|
|
43
|
+
for (let i of o)
|
|
44
|
+
i.push(i[n].map((a) => It[a]));
|
|
45
45
|
return o;
|
|
46
|
-
})(),
|
|
46
|
+
})(), et = tt[0], ot = tt[1], nt = /* @__PURE__ */ [
|
|
47
47
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
48
48
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
49
49
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
50
50
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
51
51
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
52
|
-
].map((t) => Uint8Array.from(t)),
|
|
52
|
+
].map((t) => Uint8Array.from(t)), $t = /* @__PURE__ */ et.map((t, e) => t.map((o) => nt[e][o])), Tt = /* @__PURE__ */ ot.map((t, e) => t.map((o) => nt[e][o])), vt = /* @__PURE__ */ Uint32Array.from([
|
|
53
53
|
0,
|
|
54
54
|
1518500249,
|
|
55
55
|
1859775393,
|
|
56
56
|
2400959708,
|
|
57
57
|
2840853838
|
|
58
|
-
]),
|
|
58
|
+
]), At = /* @__PURE__ */ Uint32Array.from([
|
|
59
59
|
1352829926,
|
|
60
60
|
1548603684,
|
|
61
61
|
1836072691,
|
|
@@ -66,38 +66,38 @@ function q(t, e, o, n) {
|
|
|
66
66
|
return t === 0 ? e ^ o ^ n : t === 1 ? e & o | ~e & n : t === 2 ? (e | ~o) ^ n : t === 3 ? e & n | o & ~n : e ^ (o | ~n);
|
|
67
67
|
}
|
|
68
68
|
const I = /* @__PURE__ */ new Uint32Array(16);
|
|
69
|
-
class
|
|
69
|
+
class Vt extends Ct {
|
|
70
70
|
constructor() {
|
|
71
71
|
super(64, 20, 8, !0);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
y(this, "h0", 1732584193);
|
|
73
|
+
y(this, "h1", -271733879);
|
|
74
|
+
y(this, "h2", -1732584194);
|
|
75
|
+
y(this, "h3", 271733878);
|
|
76
|
+
y(this, "h4", -1009589776);
|
|
77
77
|
}
|
|
78
78
|
get() {
|
|
79
|
-
const { h0: o, h1: n, h2:
|
|
80
|
-
return [o, n,
|
|
79
|
+
const { h0: o, h1: n, h2: i, h3: a, h4: c } = this;
|
|
80
|
+
return [o, n, i, a, c];
|
|
81
81
|
}
|
|
82
|
-
set(o, n,
|
|
83
|
-
this.h0 = o | 0, this.h1 = n | 0, this.h2 =
|
|
82
|
+
set(o, n, i, a, c) {
|
|
83
|
+
this.h0 = o | 0, this.h1 = n | 0, this.h2 = i | 0, this.h3 = a | 0, this.h4 = c | 0;
|
|
84
84
|
}
|
|
85
85
|
process(o, n) {
|
|
86
86
|
for (let r = 0; r < 16; r++, n += 4)
|
|
87
87
|
I[r] = o.getUint32(n, !0);
|
|
88
|
-
let
|
|
88
|
+
let i = this.h0 | 0, a = i, c = this.h1 | 0, h = c, d = this.h2 | 0, p = d, f = this.h3 | 0, P = f, s = this.h4 | 0, l = s;
|
|
89
89
|
for (let r = 0; r < 5; r++) {
|
|
90
|
-
const u = 4 - r, b =
|
|
90
|
+
const u = 4 - r, b = vt[r], at = At[r], ct = et[r], ut = ot[r], ht = $t[r], lt = Tt[r];
|
|
91
91
|
for (let m = 0; m < 16; m++) {
|
|
92
|
-
const $ =
|
|
93
|
-
|
|
92
|
+
const $ = x(i + q(r, c, d, f) + I[ct[m]] + b, ht[m]) + s | 0;
|
|
93
|
+
i = s, s = f, f = x(d, 10) | 0, d = c, c = $;
|
|
94
94
|
}
|
|
95
95
|
for (let m = 0; m < 16; m++) {
|
|
96
|
-
const $ =
|
|
97
|
-
a =
|
|
96
|
+
const $ = x(a + q(u, h, p, P) + I[ut[m]] + at, lt[m]) + l | 0;
|
|
97
|
+
a = l, l = P, P = x(p, 10) | 0, p = h, h = $;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
this.set(this.h1 + d + P | 0, this.h2 +
|
|
100
|
+
this.set(this.h1 + d + P | 0, this.h2 + f + l | 0, this.h3 + s + a | 0, this.h4 + i + h | 0, this.h0 + c + p | 0);
|
|
101
101
|
}
|
|
102
102
|
roundClean() {
|
|
103
103
|
F(I);
|
|
@@ -106,37 +106,37 @@ class Tt extends yt {
|
|
|
106
106
|
this.destroyed = !0, F(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
const
|
|
110
|
-
function
|
|
109
|
+
const St = /* @__PURE__ */ Et(() => new Vt()), kt = "5120", R = "0014", Rt = 20, W = 33, _t = 65, Nt = 2, Ht = 3, Kt = 4;
|
|
110
|
+
function it(t, e) {
|
|
111
111
|
const o = t.startsWith("0x") || t.startsWith("0X") ? t.slice(2) : t;
|
|
112
112
|
if (!/^(?:[0-9a-fA-F]{2})+$/.test(o))
|
|
113
113
|
throw new Error(`${e} must be non-empty, even-length hex`);
|
|
114
114
|
return `0x${o.toLowerCase()}`;
|
|
115
115
|
}
|
|
116
|
-
function
|
|
117
|
-
const e =
|
|
118
|
-
|
|
116
|
+
function Ot(t) {
|
|
117
|
+
const e = J(t), o = E.utils.lift_x(BigInt(`0x${t}`)), n = E.utils.bytesToNumberBE(
|
|
118
|
+
E.utils.taggedHash("TapTweak", e)
|
|
119
119
|
);
|
|
120
|
-
if (n >=
|
|
120
|
+
if (n >= j.CURVE.n)
|
|
121
121
|
throw new Error("Proof of possession BTC pubkey has an invalid TapTweak");
|
|
122
|
-
const
|
|
123
|
-
return `0x${
|
|
124
|
-
|
|
122
|
+
const i = n === 0n ? o : o.add(E.Point.BASE.multiply(n));
|
|
123
|
+
return `0x${kt}${_(
|
|
124
|
+
E.utils.pointToBytes(i)
|
|
125
125
|
)}`;
|
|
126
126
|
}
|
|
127
|
-
function
|
|
128
|
-
const e =
|
|
127
|
+
function Mt(t) {
|
|
128
|
+
const e = it(t, "depositorBtcPubkeyRaw"), o = J(e.slice(2));
|
|
129
129
|
if (o.length === 32)
|
|
130
130
|
return {
|
|
131
|
-
xOnlyPubkey:
|
|
131
|
+
xOnlyPubkey: C(e, "Payout BTC pubkey")
|
|
132
132
|
};
|
|
133
|
-
const n = o.length === W && (o[0] ===
|
|
134
|
-
if (!n && !
|
|
133
|
+
const n = o.length === W && (o[0] === Nt || o[0] === Ht), i = o.length === _t && o[0] === Kt;
|
|
134
|
+
if (!n && !i)
|
|
135
135
|
throw new Error(
|
|
136
136
|
"depositorBtcPubkeyRaw must be x-only, compressed, or uncompressed"
|
|
137
137
|
);
|
|
138
138
|
try {
|
|
139
|
-
|
|
139
|
+
j.Point.fromBytes(o);
|
|
140
140
|
} catch {
|
|
141
141
|
throw new Error("depositorBtcPubkeyRaw is not a valid BTC pubkey");
|
|
142
142
|
}
|
|
@@ -145,123 +145,123 @@ function Ht(t) {
|
|
|
145
145
|
compressedPubkey: n ? o : void 0
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
|
-
function
|
|
149
|
-
return `0x${R}${_(
|
|
148
|
+
function Ft(t) {
|
|
149
|
+
return `0x${R}${_(St(S(t)))}`;
|
|
150
150
|
}
|
|
151
|
-
function
|
|
152
|
-
const n =
|
|
151
|
+
function Ut(t, e, o) {
|
|
152
|
+
const n = it(
|
|
153
153
|
t,
|
|
154
154
|
"depositorPayoutScriptPubKey"
|
|
155
155
|
);
|
|
156
|
-
if ((n.length - 2) / 2 >
|
|
156
|
+
if ((n.length - 2) / 2 > M)
|
|
157
157
|
throw new Error(
|
|
158
|
-
`depositorPayoutScriptPubKey exceeds ${
|
|
158
|
+
`depositorPayoutScriptPubKey exceeds ${M} bytes`
|
|
159
159
|
);
|
|
160
|
-
const
|
|
161
|
-
`0x${
|
|
160
|
+
const i = e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e, a = C(
|
|
161
|
+
`0x${i}`,
|
|
162
162
|
"Proof of possession BTC pubkey"
|
|
163
|
-
), c =
|
|
163
|
+
), c = Mt(o);
|
|
164
164
|
if (c.xOnlyPubkey !== a)
|
|
165
165
|
throw new Error(
|
|
166
166
|
"depositorBtcPubkeyRaw does not match the proof of possession BTC pubkey"
|
|
167
167
|
);
|
|
168
|
-
if (n ===
|
|
168
|
+
if (n === Ot(a))
|
|
169
169
|
return n;
|
|
170
|
-
if (n.startsWith(`0x${R}`) && n.length === 2 + R.length +
|
|
170
|
+
if (n.startsWith(`0x${R}`) && n.length === 2 + R.length + Rt * 2) {
|
|
171
171
|
if (!c.compressedPubkey)
|
|
172
172
|
throw new Error("A P2WPKH payout requires a compressed BTC pubkey");
|
|
173
|
-
if (n ===
|
|
173
|
+
if (n === Ft(c.compressedPubkey))
|
|
174
174
|
return n;
|
|
175
175
|
}
|
|
176
176
|
throw new Error(
|
|
177
177
|
"depositorPayoutScriptPubKey does not match the proof of possession BTC pubkey"
|
|
178
178
|
);
|
|
179
179
|
}
|
|
180
|
-
function
|
|
180
|
+
function qt(t, e) {
|
|
181
181
|
const o = t.startsWith("0x") ? t.slice(2) : t;
|
|
182
182
|
if (o.length === 0 || o.length % 2 !== 0)
|
|
183
183
|
throw new Error(`${e} must be non-empty, even-length hex`);
|
|
184
184
|
if (!/^[0-9a-fA-F]+$/.test(o))
|
|
185
185
|
throw new Error(`${e} contains non-hex characters`);
|
|
186
186
|
const n = new Uint8Array(o.length / 2);
|
|
187
|
-
for (let
|
|
188
|
-
n[
|
|
187
|
+
for (let i = 0; i < n.length; i++)
|
|
188
|
+
n[i] = Number.parseInt(o.slice(i * 2, i * 2 + 2), 16);
|
|
189
189
|
return n;
|
|
190
190
|
}
|
|
191
|
-
function
|
|
191
|
+
function Wt(t) {
|
|
192
192
|
return Array.from(t, (e) => e.toString(16).padStart(2, "0")).join(
|
|
193
193
|
""
|
|
194
194
|
);
|
|
195
195
|
}
|
|
196
|
-
function
|
|
196
|
+
function Dt(t) {
|
|
197
197
|
const e = new Uint8Array(
|
|
198
|
-
t.reduce((n,
|
|
198
|
+
t.reduce((n, i) => n + i.length, 0)
|
|
199
199
|
);
|
|
200
200
|
let o = 0;
|
|
201
201
|
for (const n of t)
|
|
202
202
|
e.set(n, o), o += n.length;
|
|
203
203
|
return e;
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function Lt(t) {
|
|
206
206
|
let e = 0;
|
|
207
|
-
const o = (
|
|
208
|
-
if (!Number.isSafeInteger(
|
|
209
|
-
throw new Error(`Invalid ${
|
|
210
|
-
if (e +
|
|
211
|
-
throw new Error(`Truncated Bitcoin transaction while reading ${
|
|
212
|
-
const r = t.slice(e, e +
|
|
213
|
-
return e +=
|
|
214
|
-
}, n = (
|
|
215
|
-
const r = o(
|
|
207
|
+
const o = (s, l) => {
|
|
208
|
+
if (!Number.isSafeInteger(s) || s < 0)
|
|
209
|
+
throw new Error(`Invalid ${l} length ${s}`);
|
|
210
|
+
if (e + s > t.length)
|
|
211
|
+
throw new Error(`Truncated Bitcoin transaction while reading ${l}`);
|
|
212
|
+
const r = t.slice(e, e + s);
|
|
213
|
+
return e += s, r;
|
|
214
|
+
}, n = (s, l) => {
|
|
215
|
+
const r = o(s, l);
|
|
216
216
|
let u = 0n;
|
|
217
217
|
for (let b = r.length - 1; b >= 0; b--)
|
|
218
218
|
u = u << 8n | BigInt(r[b]);
|
|
219
219
|
return u;
|
|
220
|
-
},
|
|
221
|
-
const
|
|
220
|
+
}, i = (s) => {
|
|
221
|
+
const l = e, r = o(1, s)[0];
|
|
222
222
|
let u;
|
|
223
223
|
if (r < 253)
|
|
224
224
|
u = BigInt(r);
|
|
225
225
|
else if (r === 253) {
|
|
226
|
-
if (u = n(2,
|
|
226
|
+
if (u = n(2, s), u < 0xfdn) throw new Error(`Non-canonical ${s}`);
|
|
227
227
|
} else if (r === 254) {
|
|
228
|
-
if (u = n(4,
|
|
229
|
-
} else if (u = n(8,
|
|
228
|
+
if (u = n(4, s), u <= 0xffffn) throw new Error(`Non-canonical ${s}`);
|
|
229
|
+
} else if (u = n(8, s), u <= 0xffffffffn) throw new Error(`Non-canonical ${s}`);
|
|
230
230
|
if (u > BigInt(Number.MAX_SAFE_INTEGER))
|
|
231
|
-
throw new Error(`${
|
|
231
|
+
throw new Error(`${s} exceeds JavaScript's safe integer range`);
|
|
232
232
|
return {
|
|
233
|
-
encoded: t.slice(
|
|
233
|
+
encoded: t.slice(l, e),
|
|
234
234
|
value: Number(u)
|
|
235
235
|
};
|
|
236
236
|
}, a = o(4, "version"), c = t[e] === 0 && t[e + 1] === 1;
|
|
237
237
|
c && (e += 2);
|
|
238
|
-
const
|
|
239
|
-
for (let
|
|
240
|
-
const
|
|
241
|
-
o(32, `input ${
|
|
242
|
-
const r =
|
|
243
|
-
o(r.value, `input ${
|
|
244
|
-
}
|
|
245
|
-
const p =
|
|
246
|
-
for (let
|
|
247
|
-
const
|
|
248
|
-
o(8, `output ${
|
|
249
|
-
const r =
|
|
250
|
-
o(r.value, `output ${
|
|
238
|
+
const h = i("input count"), d = [];
|
|
239
|
+
for (let s = 0; s < h.value; s++) {
|
|
240
|
+
const l = e;
|
|
241
|
+
o(32, `input ${s} previous transaction hash`), o(4, `input ${s} previous output index`);
|
|
242
|
+
const r = i(`input ${s} script length`);
|
|
243
|
+
o(r.value, `input ${s} script`), o(4, `input ${s} sequence`), d.push(t.slice(l, e));
|
|
244
|
+
}
|
|
245
|
+
const p = i("output count"), f = [];
|
|
246
|
+
for (let s = 0; s < p.value; s++) {
|
|
247
|
+
const l = e;
|
|
248
|
+
o(8, `output ${s} value`);
|
|
249
|
+
const r = i(`output ${s} script length`);
|
|
250
|
+
o(r.value, `output ${s} script`), f.push(t.slice(l, e));
|
|
251
251
|
}
|
|
252
252
|
if (c) {
|
|
253
|
-
let
|
|
254
|
-
for (let
|
|
255
|
-
const r =
|
|
256
|
-
|
|
253
|
+
let s = !1;
|
|
254
|
+
for (let l = 0; l < h.value; l++) {
|
|
255
|
+
const r = i(`input ${l} witness item count`);
|
|
256
|
+
s || (s = r.value > 0);
|
|
257
257
|
for (let u = 0; u < r.value; u++) {
|
|
258
|
-
const b =
|
|
259
|
-
`input ${
|
|
258
|
+
const b = i(
|
|
259
|
+
`input ${l} witness item ${u} length`
|
|
260
260
|
);
|
|
261
|
-
o(b.value, `input ${
|
|
261
|
+
o(b.value, `input ${l} witness item ${u}`);
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
|
-
if (!
|
|
264
|
+
if (!s)
|
|
265
265
|
throw new Error("Bitcoin transaction has superfluous witness marker");
|
|
266
266
|
}
|
|
267
267
|
const P = o(4, "locktime");
|
|
@@ -269,43 +269,43 @@ function Wt(t) {
|
|
|
269
269
|
throw new Error(
|
|
270
270
|
`Bitcoin transaction has ${t.length - e} trailing byte(s)`
|
|
271
271
|
);
|
|
272
|
-
return
|
|
272
|
+
return Dt([
|
|
273
273
|
a,
|
|
274
|
-
|
|
274
|
+
h.encoded,
|
|
275
275
|
...d,
|
|
276
276
|
p.encoded,
|
|
277
|
-
...
|
|
277
|
+
...f,
|
|
278
278
|
P
|
|
279
279
|
]);
|
|
280
280
|
}
|
|
281
|
-
function
|
|
282
|
-
const e =
|
|
283
|
-
|
|
281
|
+
function Xt(t) {
|
|
282
|
+
const e = Lt(
|
|
283
|
+
qt(t, "transactionHex")
|
|
284
284
|
), o = S(S(e));
|
|
285
|
-
return o.reverse(), `0x${
|
|
285
|
+
return o.reverse(), `0x${Wt(o)}`;
|
|
286
286
|
}
|
|
287
|
-
function
|
|
287
|
+
function zt(t, e) {
|
|
288
288
|
const o = t.startsWith("0x") ? t : `0x${t}`;
|
|
289
289
|
if (!/^0x[0-9a-fA-F]{64}$/.test(o))
|
|
290
290
|
throw new Error("peginTxHash must be a 32-byte hex value");
|
|
291
291
|
const n = e.startsWith("0x") ? e : `0x${e}`;
|
|
292
|
-
if (!
|
|
292
|
+
if (!gt(n, { strict: !0 }))
|
|
293
293
|
throw new Error(`Invalid depositor Ethereum address: ${e}`);
|
|
294
|
-
return
|
|
295
|
-
|
|
294
|
+
return ft(
|
|
295
|
+
mt(
|
|
296
296
|
[{ type: "bytes32" }, { type: "address" }],
|
|
297
297
|
[o, n]
|
|
298
298
|
)
|
|
299
299
|
).slice(2);
|
|
300
300
|
}
|
|
301
|
-
const v = 65535,
|
|
302
|
-
function
|
|
301
|
+
const v = 65535, D = 1e4, B = 4294967295, L = 255;
|
|
302
|
+
function Gt(t) {
|
|
303
303
|
if (!Number.isInteger(t) || t < 0 || t > B)
|
|
304
304
|
throw new Error(
|
|
305
305
|
`Invalid offchainParamsVersion from contract: must be a uint32, got ${t}`
|
|
306
306
|
);
|
|
307
307
|
}
|
|
308
|
-
function
|
|
308
|
+
function Qt(t) {
|
|
309
309
|
const e = [];
|
|
310
310
|
if (t.timelockAssert <= 0n && e.push(
|
|
311
311
|
`timelockAssert must be positive, got ${t.timelockAssert}`
|
|
@@ -327,14 +327,14 @@ function zt(t) {
|
|
|
327
327
|
`babeInstancesToFinalize must be positive, got ${t.babeInstancesToFinalize}`
|
|
328
328
|
), t.babeInstancesToFinalize > t.babeTotalInstances && e.push(
|
|
329
329
|
`babeInstancesToFinalize (${t.babeInstancesToFinalize}) exceeds babeTotalInstances (${t.babeTotalInstances})`
|
|
330
|
-
), (t.minVpCommissionBps < 0 || t.minVpCommissionBps >
|
|
331
|
-
`minVpCommissionBps must be in [0, ${
|
|
330
|
+
), (t.minVpCommissionBps < 0 || t.minVpCommissionBps > D) && e.push(
|
|
331
|
+
`minVpCommissionBps must be in [0, ${D}], got ${t.minVpCommissionBps}`
|
|
332
332
|
), e.length > 0)
|
|
333
333
|
throw new Error(
|
|
334
334
|
`Invalid offchain protocol parameters: ${e.join("; ")}`
|
|
335
335
|
);
|
|
336
336
|
}
|
|
337
|
-
function
|
|
337
|
+
function Yt(t) {
|
|
338
338
|
const e = [];
|
|
339
339
|
if (t.minimumPegInAmount <= 0n && e.push(
|
|
340
340
|
`minimumPegInAmount must be positive, got ${t.minimumPegInAmount}`
|
|
@@ -344,23 +344,36 @@ function Lt(t) {
|
|
|
344
344
|
`pegInAckTimeout must be positive, got ${t.pegInAckTimeout}`
|
|
345
345
|
), t.pegInActivationTimeout <= 0n && e.push(
|
|
346
346
|
`pegInActivationTimeout must be positive, got ${t.pegInActivationTimeout}`
|
|
347
|
-
), (!Number.isInteger(t.maxHtlcOutputCount) || t.maxHtlcOutputCount <= 0 || t.maxHtlcOutputCount >
|
|
348
|
-
`maxHtlcOutputCount must be an integer in [1, ${
|
|
347
|
+
), (!Number.isInteger(t.maxHtlcOutputCount) || t.maxHtlcOutputCount <= 0 || t.maxHtlcOutputCount > L) && e.push(
|
|
348
|
+
`maxHtlcOutputCount must be an integer in [1, ${L}], got ${t.maxHtlcOutputCount}`
|
|
349
349
|
), (typeof t.expiredPegInGraceBlocks != "bigint" || t.expiredPegInGraceBlocks <= 0n) && e.push(
|
|
350
350
|
`expiredPegInGraceBlocks must be a positive bigint, got ${t.expiredPegInGraceBlocks}`
|
|
351
351
|
), e.length > 0)
|
|
352
352
|
throw new Error(`Invalid TBV protocol parameters: ${e.join("; ")}`);
|
|
353
353
|
}
|
|
354
|
-
function
|
|
355
|
-
if (
|
|
354
|
+
function pe(t) {
|
|
355
|
+
if (Yt(t), Qt(t.offchainParams), !Number.isInteger(t.offchainParamsVersion) || t.offchainParamsVersion < 0 || t.offchainParamsVersion > B)
|
|
356
356
|
throw new Error(
|
|
357
357
|
`Invalid peg-in configuration: offchainParamsVersion must be a uint32, got ${t.offchainParamsVersion}`
|
|
358
358
|
);
|
|
359
|
-
|
|
359
|
+
wt(
|
|
360
360
|
t.activeVaultCoreVersion,
|
|
361
361
|
"ProtocolParams.activeVaultCoreVersion()"
|
|
362
362
|
);
|
|
363
363
|
}
|
|
364
|
+
const st = "RegistrationLogsUnavailableError";
|
|
365
|
+
class rt extends Error {
|
|
366
|
+
constructor(o) {
|
|
367
|
+
super(
|
|
368
|
+
`The Ethereum node returned no registration logs for block ${o}, which holds a vault registration; the node may not have indexed that block yet. Try again.`
|
|
369
|
+
);
|
|
370
|
+
y(this, "blockNumber");
|
|
371
|
+
this.name = st, this.blockNumber = o;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function ge(t) {
|
|
375
|
+
return t instanceof rt ? !0 : typeof t != "object" || t === null ? !1 : t.name === st;
|
|
376
|
+
}
|
|
364
377
|
const X = 9999;
|
|
365
378
|
function z(t) {
|
|
366
379
|
return {
|
|
@@ -375,7 +388,7 @@ function z(t) {
|
|
|
375
388
|
}
|
|
376
389
|
function A(t) {
|
|
377
390
|
const e = Number(t.offchainParamsVersion);
|
|
378
|
-
return
|
|
391
|
+
return Gt(e), {
|
|
379
392
|
depositorSignedPeginTx: t.depositorSignedPeginTx,
|
|
380
393
|
universalChallengersVersion: t.universalChallengersVersion,
|
|
381
394
|
appVaultKeepersVersion: t.appVaultKeepersVersion,
|
|
@@ -390,9 +403,12 @@ function A(t) {
|
|
|
390
403
|
vaultCoreVersion: t.vaultCoreVersion
|
|
391
404
|
};
|
|
392
405
|
}
|
|
393
|
-
const
|
|
406
|
+
const jt = 1n << 64n, G = 0n, Jt = [
|
|
407
|
+
N({ abi: g, name: "PegInSubmitted" }),
|
|
408
|
+
N({ abi: g, name: "PegInSubmittedV2" })
|
|
409
|
+
];
|
|
394
410
|
function V(t, e, o) {
|
|
395
|
-
if (t < 0n || t >=
|
|
411
|
+
if (t < 0n || t >= jt)
|
|
396
412
|
throw new Error(
|
|
397
413
|
`getBtcVaultProtocolInfo returned ${e}=${t} for vault ${o}, outside the uint64 range — the registry may predate RFC-006`
|
|
398
414
|
);
|
|
@@ -409,7 +425,7 @@ function Q(t, e) {
|
|
|
409
425
|
ucKeyEpoch: V(t.ucKeyEpoch, "ucKeyEpoch", e)
|
|
410
426
|
};
|
|
411
427
|
}
|
|
412
|
-
class
|
|
428
|
+
class Zt {
|
|
413
429
|
constructor(e, o) {
|
|
414
430
|
this.publicClient = e, this.contractAddress = o;
|
|
415
431
|
}
|
|
@@ -439,14 +455,14 @@ class Gt {
|
|
|
439
455
|
async getVaultProviderGenesisBtcPubKey(e, o) {
|
|
440
456
|
const n = await this.publicClient.readContract({
|
|
441
457
|
address: this.contractAddress,
|
|
442
|
-
abi:
|
|
458
|
+
abi: g,
|
|
443
459
|
functionName: "getOperationBtcKeyAtEpoch",
|
|
444
|
-
args: [e,
|
|
460
|
+
args: [e, G],
|
|
445
461
|
blockNumber: o
|
|
446
462
|
});
|
|
447
|
-
return
|
|
463
|
+
return C(
|
|
448
464
|
n,
|
|
449
|
-
`getOperationBtcKeyAtEpoch (vp=${e}, epoch=${
|
|
465
|
+
`getOperationBtcKeyAtEpoch (vp=${e}, epoch=${G})`
|
|
450
466
|
);
|
|
451
467
|
}
|
|
452
468
|
/**
|
|
@@ -463,11 +479,11 @@ class Gt {
|
|
|
463
479
|
async getCurrentVaultProviderOperationBtcKey(e) {
|
|
464
480
|
const o = await this.publicClient.readContract({
|
|
465
481
|
address: this.contractAddress,
|
|
466
|
-
abi:
|
|
482
|
+
abi: g,
|
|
467
483
|
functionName: "getCurrentOperationBtcKey",
|
|
468
484
|
args: [e]
|
|
469
485
|
});
|
|
470
|
-
return
|
|
486
|
+
return C(
|
|
471
487
|
o,
|
|
472
488
|
`getCurrentOperationBtcKey (vp=${e})`
|
|
473
489
|
);
|
|
@@ -491,7 +507,7 @@ class Gt {
|
|
|
491
507
|
async getVaultKeyEpochs(e) {
|
|
492
508
|
const o = await this.publicClient.readContract({
|
|
493
509
|
address: this.contractAddress,
|
|
494
|
-
abi:
|
|
510
|
+
abi: K,
|
|
495
511
|
functionName: "getBtcVaultProtocolInfo",
|
|
496
512
|
args: [e]
|
|
497
513
|
});
|
|
@@ -501,19 +517,19 @@ class Gt {
|
|
|
501
517
|
return e.length === 0 ? [] : (await this.publicClient.multicall({
|
|
502
518
|
contracts: e.map((n) => ({
|
|
503
519
|
address: this.contractAddress,
|
|
504
|
-
abi:
|
|
520
|
+
abi: K,
|
|
505
521
|
functionName: "getBtcVaultProtocolInfo",
|
|
506
522
|
args: [n]
|
|
507
523
|
})),
|
|
508
524
|
allowFailure: !1
|
|
509
525
|
})).map(
|
|
510
|
-
(n,
|
|
526
|
+
(n, i) => Q(n, e[i])
|
|
511
527
|
);
|
|
512
528
|
}
|
|
513
529
|
async getVaultBasicInfo(e) {
|
|
514
530
|
const o = await this.publicClient.readContract({
|
|
515
531
|
address: this.contractAddress,
|
|
516
|
-
abi:
|
|
532
|
+
abi: g,
|
|
517
533
|
functionName: "getBtcVaultBasicInfo",
|
|
518
534
|
args: [e]
|
|
519
535
|
});
|
|
@@ -522,7 +538,7 @@ class Gt {
|
|
|
522
538
|
async getVaultProtocolInfo(e) {
|
|
523
539
|
const o = await this.publicClient.readContract({
|
|
524
540
|
address: this.contractAddress,
|
|
525
|
-
abi:
|
|
541
|
+
abi: g,
|
|
526
542
|
functionName: "getBtcVaultProtocolInfo",
|
|
527
543
|
args: [e]
|
|
528
544
|
});
|
|
@@ -532,16 +548,16 @@ class Gt {
|
|
|
532
548
|
return e.length === 0 ? [] : (await this.publicClient.multicall({
|
|
533
549
|
contracts: e.map((n) => ({
|
|
534
550
|
address: this.contractAddress,
|
|
535
|
-
abi:
|
|
551
|
+
abi: g,
|
|
536
552
|
functionName: "getBtcVaultProtocolInfo",
|
|
537
553
|
args: [n]
|
|
538
554
|
})),
|
|
539
555
|
allowFailure: !1
|
|
540
|
-
})).map((n,
|
|
556
|
+
})).map((n, i) => {
|
|
541
557
|
const a = n;
|
|
542
558
|
if (!a.depositorSignedPeginTx || a.depositorSignedPeginTx === "0x")
|
|
543
559
|
throw new Error(
|
|
544
|
-
`Vault ${e[
|
|
560
|
+
`Vault ${e[i]} not found on-chain or has no pegin transaction`
|
|
545
561
|
);
|
|
546
562
|
return A(a);
|
|
547
563
|
});
|
|
@@ -553,7 +569,7 @@ class Gt {
|
|
|
553
569
|
async getPegInFee(e) {
|
|
554
570
|
return await this.publicClient.readContract({
|
|
555
571
|
address: this.contractAddress,
|
|
556
|
-
abi:
|
|
572
|
+
abi: g,
|
|
557
573
|
functionName: "getPegInFee",
|
|
558
574
|
args: [e]
|
|
559
575
|
});
|
|
@@ -568,7 +584,7 @@ class Gt {
|
|
|
568
584
|
async getVaultProviderCommission(e) {
|
|
569
585
|
const o = await this.publicClient.readContract({
|
|
570
586
|
address: this.contractAddress,
|
|
571
|
-
abi:
|
|
587
|
+
abi: g,
|
|
572
588
|
functionName: "getVaultProviderCommission",
|
|
573
589
|
args: [e]
|
|
574
590
|
});
|
|
@@ -583,42 +599,87 @@ class Gt {
|
|
|
583
599
|
contracts: [
|
|
584
600
|
{
|
|
585
601
|
address: this.contractAddress,
|
|
586
|
-
abi:
|
|
602
|
+
abi: g,
|
|
587
603
|
functionName: "getBtcVaultBasicInfo",
|
|
588
604
|
args: [e]
|
|
589
605
|
},
|
|
590
606
|
{
|
|
591
607
|
address: this.contractAddress,
|
|
592
|
-
abi:
|
|
608
|
+
abi: g,
|
|
593
609
|
functionName: "getBtcVaultProtocolInfo",
|
|
594
610
|
args: [e]
|
|
595
611
|
}
|
|
596
612
|
],
|
|
597
613
|
allowFailure: !1
|
|
598
|
-
}),
|
|
614
|
+
}), i = z(o), a = A(n);
|
|
599
615
|
if (!a.depositorSignedPeginTx || a.depositorSignedPeginTx === "0x")
|
|
600
616
|
throw new Error(
|
|
601
617
|
`Vault ${e} not found on-chain or has no pegin transaction`
|
|
602
618
|
);
|
|
603
|
-
return { basic:
|
|
619
|
+
return { basic: i, protocol: a };
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Read the depositor's commission ceiling (`maxAcceptableCommissionBps`)
|
|
623
|
+
* for vaults registered in the same block, from their `PegInSubmittedV2`
|
|
624
|
+
* logs. Returned in `vaultIds` order.
|
|
625
|
+
*
|
|
626
|
+
* The contract bound-checks the ceiling and discards it (PeginLogic.sol,
|
|
627
|
+
* `VaultProviderCommissionExceeded`), so the registration log is its only
|
|
628
|
+
* on-chain source. One query at exactly `createdAt` — the `block.number`
|
|
629
|
+
* stamped at registration — so no block-range scan is needed and public-RPC
|
|
630
|
+
* range caps do not apply. Vault ids are matched case-insensitively.
|
|
631
|
+
*
|
|
632
|
+
* @throws {RegistrationLogsUnavailableError} (transient, retry) when the
|
|
633
|
+
* node answers with no registration logs for the block at all.
|
|
634
|
+
* @throws when a vault has only its `PegInSubmitted` log — registrations
|
|
635
|
+
* that predate the V2 event (vault-contracts-aave-v4 #548) never emitted
|
|
636
|
+
* the ceiling — no registration log in its own `createdAt` block, or more
|
|
637
|
+
* than one V2 log.
|
|
638
|
+
*/
|
|
639
|
+
async getMaxAcceptableCommissionBpsBatch(e, o) {
|
|
640
|
+
if (e.length === 0) return [];
|
|
641
|
+
const n = await this.publicClient.getLogs({
|
|
642
|
+
address: this.contractAddress,
|
|
643
|
+
events: Jt,
|
|
644
|
+
fromBlock: o,
|
|
645
|
+
toBlock: o,
|
|
646
|
+
strict: !0
|
|
647
|
+
});
|
|
648
|
+
if (n.length === 0)
|
|
649
|
+
throw new rt(o);
|
|
650
|
+
return e.map((i) => {
|
|
651
|
+
const a = i.toLowerCase();
|
|
652
|
+
let c = !1;
|
|
653
|
+
const h = [];
|
|
654
|
+
for (const d of n)
|
|
655
|
+
d.args.vaultId.toLowerCase() === a && (c = !0, d.eventName === "PegInSubmittedV2" && h.push(d.args.maxAcceptableCommissionBps));
|
|
656
|
+
if (h.length === 1) return h[0];
|
|
657
|
+
throw h.length > 1 ? new Error(
|
|
658
|
+
`Expected one PegInSubmittedV2 log for vault ${i} at block ${o}, found ${h.length} PegInSubmittedV2 logs`
|
|
659
|
+
) : c ? new Error(
|
|
660
|
+
`Vault ${i} was registered before the registry emitted the depositor's commission ceiling (no PegInSubmittedV2 log at block ${o}), so the ceiling cannot be recovered on-chain`
|
|
661
|
+
) : new Error(
|
|
662
|
+
`Vault ${i} has no registration log at its on-chain registration block ${o}`
|
|
663
|
+
);
|
|
664
|
+
});
|
|
604
665
|
}
|
|
605
666
|
}
|
|
606
|
-
const
|
|
607
|
-
function
|
|
667
|
+
const te = 0, ee = 255, oe = 12e4;
|
|
668
|
+
function w(t, e) {
|
|
608
669
|
const o = t.startsWith("0x") ? t : t.startsWith("0X") ? `0x${t.slice(2)}` : `0x${t}`;
|
|
609
670
|
if (!/^0x(?:[0-9a-fA-F]{2})+$/.test(o))
|
|
610
671
|
throw new Error(`${e} must be non-empty, even-length hex`);
|
|
611
672
|
return o;
|
|
612
673
|
}
|
|
613
|
-
function
|
|
674
|
+
function Y(t, e) {
|
|
614
675
|
if (!/^0x[0-9a-fA-F]{64}$/.test(t))
|
|
615
676
|
throw new Error(`${e} must be a 32-byte hex value`);
|
|
616
677
|
}
|
|
617
|
-
function
|
|
618
|
-
if (!Number.isInteger(t) || t < 0 || t >
|
|
678
|
+
function ne(t) {
|
|
679
|
+
if (!Number.isInteger(t) || t < 0 || t > ee)
|
|
619
680
|
throw new Error(`htlcVout must be a uint8, got ${t}`);
|
|
620
681
|
}
|
|
621
|
-
class
|
|
682
|
+
class fe {
|
|
622
683
|
constructor(e) {
|
|
623
684
|
this.config = e;
|
|
624
685
|
}
|
|
@@ -628,27 +689,27 @@ class he {
|
|
|
628
689
|
popSignature: { ...e.popSignature }
|
|
629
690
|
};
|
|
630
691
|
this.assertQuotedCommissionPresentWhenRequired(o.quotedCommissionBps);
|
|
631
|
-
const n = this.assertPopMatchesEthAccount(o.popSignature),
|
|
692
|
+
const n = this.assertPopMatchesEthAccount(o.popSignature), i = this.normalizeBtcPubkey(o.popSignature), a = w(
|
|
632
693
|
o.popSignature.btcPopSignature,
|
|
633
694
|
"btcPopSignature"
|
|
634
695
|
), c = this.normalizeRequest(
|
|
635
696
|
o,
|
|
636
697
|
n,
|
|
637
|
-
|
|
698
|
+
i
|
|
638
699
|
);
|
|
639
700
|
await this.assertVaultDoesNotExist(
|
|
640
701
|
c.vaultId,
|
|
641
702
|
c.peginTxHash
|
|
642
703
|
);
|
|
643
|
-
const
|
|
704
|
+
const h = await this.readPeginFee(o.vaultProvider), d = await this.resolveMaxAcceptableCommissionBps(
|
|
644
705
|
o.vaultProvider,
|
|
645
706
|
o.quotedCommissionBps
|
|
646
|
-
), p =
|
|
647
|
-
abi:
|
|
707
|
+
), p = H({
|
|
708
|
+
abi: g,
|
|
648
709
|
functionName: "submitPeginRequest",
|
|
649
710
|
args: [
|
|
650
711
|
n,
|
|
651
|
-
|
|
712
|
+
i,
|
|
652
713
|
a,
|
|
653
714
|
c.unsignedPrePeginTx,
|
|
654
715
|
c.depositorSignedPeginTx,
|
|
@@ -663,7 +724,7 @@ class he {
|
|
|
663
724
|
return {
|
|
664
725
|
ethTxHash: await this.sendAndWait(
|
|
665
726
|
p,
|
|
666
|
-
|
|
727
|
+
h,
|
|
667
728
|
!1,
|
|
668
729
|
n
|
|
669
730
|
),
|
|
@@ -680,13 +741,13 @@ class he {
|
|
|
680
741
|
if (o.requests.length === 0)
|
|
681
742
|
throw new Error("Batch pegin requires at least one request");
|
|
682
743
|
this.assertQuotedCommissionPresentWhenRequired(o.quotedCommissionBps);
|
|
683
|
-
const n = this.assertPopMatchesEthAccount(o.popSignature),
|
|
744
|
+
const n = this.assertPopMatchesEthAccount(o.popSignature), i = w(
|
|
684
745
|
o.unsignedPrePeginTx,
|
|
685
746
|
"unsignedPrePeginTx"
|
|
686
|
-
), a = this.normalizeBtcPubkey(o.popSignature), c =
|
|
747
|
+
), a = this.normalizeBtcPubkey(o.popSignature), c = w(
|
|
687
748
|
o.popSignature.btcPopSignature,
|
|
688
749
|
"btcPopSignature"
|
|
689
|
-
),
|
|
750
|
+
), h = [], d = [], p = /* @__PURE__ */ new Set();
|
|
690
751
|
for (const r of o.requests) {
|
|
691
752
|
const u = this.normalizeRequest(
|
|
692
753
|
{
|
|
@@ -700,37 +761,37 @@ class he {
|
|
|
700
761
|
);
|
|
701
762
|
if (p.has(u.vaultId))
|
|
702
763
|
throw new Error(`Duplicate vault in batch: ${u.vaultId}`);
|
|
703
|
-
p.add(u.vaultId),
|
|
764
|
+
p.add(u.vaultId), h.push({
|
|
704
765
|
vaultId: u.vaultId,
|
|
705
766
|
peginTxHash: u.peginTxHash
|
|
706
767
|
}), d.push({
|
|
707
768
|
depositorBtcPubKey: a,
|
|
708
769
|
btcPopSignature: c,
|
|
709
|
-
unsignedPrePeginTx:
|
|
770
|
+
unsignedPrePeginTx: i,
|
|
710
771
|
depositorSignedPeginTx: u.depositorSignedPeginTx,
|
|
711
772
|
hashlock: r.hashlock,
|
|
712
773
|
htlcVout: r.htlcVout,
|
|
713
|
-
referralCode:
|
|
774
|
+
referralCode: te,
|
|
714
775
|
depositorPayoutBtcAddress: u.payoutScript,
|
|
715
776
|
depositorWotsPkHash: r.depositorWotsPkHash
|
|
716
777
|
});
|
|
717
778
|
}
|
|
718
|
-
for (const r of
|
|
779
|
+
for (const r of h)
|
|
719
780
|
await this.assertVaultDoesNotExist(r.vaultId, r.peginTxHash);
|
|
720
|
-
const
|
|
781
|
+
const f = await this.readPeginFee(o.vaultProvider), P = await this.resolveMaxAcceptableCommissionBps(
|
|
721
782
|
o.vaultProvider,
|
|
722
783
|
o.quotedCommissionBps
|
|
723
|
-
),
|
|
724
|
-
abi:
|
|
784
|
+
), s = H({
|
|
785
|
+
abi: g,
|
|
725
786
|
functionName: "submitPeginRequestBatch",
|
|
726
787
|
args: [n, o.vaultProvider, P, d]
|
|
727
788
|
});
|
|
728
789
|
return { ethTxHash: await this.sendAndWait(
|
|
729
|
-
|
|
730
|
-
|
|
790
|
+
s,
|
|
791
|
+
f * BigInt(o.requests.length),
|
|
731
792
|
!0,
|
|
732
793
|
n
|
|
733
|
-
), vaults:
|
|
794
|
+
), vaults: h };
|
|
734
795
|
}
|
|
735
796
|
assertQuotedCommissionPresentWhenRequired(e) {
|
|
736
797
|
if (e === void 0 && this.config.requireQuotedCommissionBps)
|
|
@@ -744,46 +805,46 @@ class he {
|
|
|
744
805
|
assertEthAccount(e) {
|
|
745
806
|
const o = this.config.ethWallet.account;
|
|
746
807
|
if (!o) throw new Error("Ethereum wallet account not found");
|
|
747
|
-
if (!
|
|
808
|
+
if (!Pt(e, o.address))
|
|
748
809
|
throw new Error(
|
|
749
810
|
`Proof of possession was signed for ${e} but the Ethereum wallet is currently connected to ${o.address}. Reconnect the original account or sign a new proof of possession.`
|
|
750
811
|
);
|
|
751
812
|
return o.address;
|
|
752
813
|
}
|
|
753
814
|
normalizeBtcPubkey(e) {
|
|
754
|
-
return `0x${
|
|
755
|
-
|
|
815
|
+
return `0x${C(
|
|
816
|
+
w(e.depositorBtcPubkey, "Proof of possession BTC pubkey"),
|
|
756
817
|
"Proof of possession BTC pubkey"
|
|
757
818
|
)}`;
|
|
758
819
|
}
|
|
759
820
|
normalizeRequest(e, o, n) {
|
|
760
|
-
|
|
761
|
-
const
|
|
821
|
+
Y(e.hashlock, "hashlock"), Y(e.depositorWotsPkHash, "depositorWotsPkHash"), ne(e.htlcVout);
|
|
822
|
+
const i = w(
|
|
762
823
|
e.unsignedPrePeginTx,
|
|
763
824
|
"unsignedPrePeginTx"
|
|
764
|
-
), a =
|
|
825
|
+
), a = w(
|
|
765
826
|
e.depositorSignedPeginTx,
|
|
766
827
|
"depositorSignedPeginTx"
|
|
767
|
-
), c =
|
|
828
|
+
), c = Xt(a);
|
|
768
829
|
return {
|
|
769
|
-
unsignedPrePeginTx:
|
|
830
|
+
unsignedPrePeginTx: i,
|
|
770
831
|
depositorSignedPeginTx: a,
|
|
771
|
-
payoutScript:
|
|
832
|
+
payoutScript: Ut(
|
|
772
833
|
e.depositorPayoutScriptPubKey,
|
|
773
834
|
n,
|
|
774
835
|
e.depositorBtcPubkeyRaw
|
|
775
836
|
),
|
|
776
837
|
peginTxHash: c,
|
|
777
|
-
vaultId:
|
|
838
|
+
vaultId: w(zt(c, o), "vaultId")
|
|
778
839
|
};
|
|
779
840
|
}
|
|
780
841
|
async assertVaultDoesNotExist(e, o) {
|
|
781
842
|
if ((await this.config.publicClient.readContract({
|
|
782
843
|
address: this.config.btcVaultRegistry,
|
|
783
|
-
abi:
|
|
844
|
+
abi: g,
|
|
784
845
|
functionName: "getBtcVaultBasicInfo",
|
|
785
846
|
args: [e]
|
|
786
|
-
})).depositor !==
|
|
847
|
+
})).depositor !== bt)
|
|
787
848
|
throw new Error(
|
|
788
849
|
`Vault already exists (ID: ${e}, peginTxHash: ${o}). 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.`
|
|
789
850
|
);
|
|
@@ -792,7 +853,7 @@ class he {
|
|
|
792
853
|
try {
|
|
793
854
|
return await this.config.publicClient.readContract({
|
|
794
855
|
address: this.config.btcVaultRegistry,
|
|
795
|
-
abi:
|
|
856
|
+
abi: g,
|
|
796
857
|
functionName: "getPegInFee",
|
|
797
858
|
args: [e]
|
|
798
859
|
});
|
|
@@ -806,14 +867,14 @@ class he {
|
|
|
806
867
|
async resolveMaxAcceptableCommissionBps(e, o) {
|
|
807
868
|
let n;
|
|
808
869
|
try {
|
|
809
|
-
n = await new
|
|
870
|
+
n = await new Zt(
|
|
810
871
|
this.config.publicClient,
|
|
811
872
|
this.config.btcVaultRegistry
|
|
812
873
|
).getVaultProviderCommission(e);
|
|
813
|
-
} catch (
|
|
874
|
+
} catch (i) {
|
|
814
875
|
throw new Error(
|
|
815
876
|
"Failed to query vault provider commission from the contract. Please check your network connection and contract address.",
|
|
816
|
-
{ cause:
|
|
877
|
+
{ cause: i }
|
|
817
878
|
);
|
|
818
879
|
}
|
|
819
880
|
if (o !== void 0) {
|
|
@@ -821,12 +882,12 @@ class he {
|
|
|
821
882
|
throw new Error(
|
|
822
883
|
`Vault provider commission changed since quote: quoted ${o} bps, chain currently reports ${n} bps (allowed drift ${k} bps). Please refresh and try again.`
|
|
823
884
|
);
|
|
824
|
-
return
|
|
885
|
+
return U(o);
|
|
825
886
|
}
|
|
826
|
-
return
|
|
887
|
+
return U(n);
|
|
827
888
|
}
|
|
828
|
-
async sendAndWait(e, o, n,
|
|
829
|
-
let a = this.assertEthAccount(
|
|
889
|
+
async sendAndWait(e, o, n, i) {
|
|
890
|
+
let a = this.assertEthAccount(i), c;
|
|
830
891
|
try {
|
|
831
892
|
c = await this.config.publicClient.estimateGas({
|
|
832
893
|
to: this.config.btcVaultRegistry,
|
|
@@ -837,10 +898,10 @@ class he {
|
|
|
837
898
|
} catch (p) {
|
|
838
899
|
T(p);
|
|
839
900
|
}
|
|
840
|
-
a = this.assertEthAccount(
|
|
841
|
-
let
|
|
901
|
+
a = this.assertEthAccount(i);
|
|
902
|
+
let h;
|
|
842
903
|
try {
|
|
843
|
-
|
|
904
|
+
h = await this.config.ethWallet.sendTransaction({
|
|
844
905
|
to: this.config.btcVaultRegistry,
|
|
845
906
|
data: e,
|
|
846
907
|
value: o,
|
|
@@ -851,11 +912,11 @@ class he {
|
|
|
851
912
|
} catch (p) {
|
|
852
913
|
T(p);
|
|
853
914
|
}
|
|
854
|
-
const d = await
|
|
915
|
+
const d = await yt({
|
|
855
916
|
publicClient: this.config.publicClient,
|
|
856
|
-
walletAddress:
|
|
857
|
-
hash:
|
|
858
|
-
timeout: this.config.receiptTimeoutMs ??
|
|
917
|
+
walletAddress: i,
|
|
918
|
+
hash: h,
|
|
919
|
+
timeout: this.config.receiptTimeoutMs ?? oe
|
|
859
920
|
});
|
|
860
921
|
return d.status === "reverted" && T(
|
|
861
922
|
new Error(
|
|
@@ -866,17 +927,19 @@ class he {
|
|
|
866
927
|
}
|
|
867
928
|
export {
|
|
868
929
|
k as C,
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
Xt as
|
|
879
|
-
|
|
880
|
-
|
|
930
|
+
xt as M,
|
|
931
|
+
te as N,
|
|
932
|
+
rt as R,
|
|
933
|
+
fe as V,
|
|
934
|
+
pe as a,
|
|
935
|
+
Yt as b,
|
|
936
|
+
Zt as c,
|
|
937
|
+
zt as d,
|
|
938
|
+
U as e,
|
|
939
|
+
Xt as f,
|
|
940
|
+
Gt as g,
|
|
941
|
+
ge as i,
|
|
942
|
+
St as r,
|
|
943
|
+
Qt as v
|
|
881
944
|
};
|
|
882
|
-
//# sourceMappingURL=pegin-registration-client-
|
|
945
|
+
//# sourceMappingURL=pegin-registration-client-7Vbtdypu.js.map
|