@secondlayer/stacks 2.14.1 → 2.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +37 -0
  2. package/dist/shared/{stacks-f66v961k.js → stacks-1k0kmpcw.js} +2 -2
  3. package/dist/shared/{stacks-6mhsf8hk.cjs → stacks-1xk4wby6.cjs} +10 -21
  4. package/dist/shared/{stacks-6mhsf8hk.cjs.map → stacks-1xk4wby6.cjs.map} +5 -6
  5. package/dist/shared/{stacks-tswh2xav.js → stacks-2x04a6ss.js} +12 -26
  6. package/dist/shared/{stacks-tswh2xav.js.map → stacks-2x04a6ss.js.map} +5 -6
  7. package/dist/shared/stacks-3kj51c6p.cjs +16 -0
  8. package/dist/shared/stacks-3kj51c6p.cjs.map +10 -0
  9. package/dist/shared/{stacks-jcgvn5v5.cjs → stacks-70xxh5h1.cjs} +15 -6
  10. package/dist/shared/{stacks-dmrvk1mz.js.map → stacks-70xxh5h1.cjs.map} +3 -3
  11. package/dist/shared/stacks-f0hfqaj5.js +22 -0
  12. package/dist/shared/stacks-f0hfqaj5.js.map +10 -0
  13. package/dist/shared/{stacks-3vyvtahh.js → stacks-ggxnnph5.cjs} +2 -46
  14. package/dist/shared/stacks-ggxnnph5.cjs.map +10 -0
  15. package/dist/shared/stacks-pdcz1w1d.js +33 -0
  16. package/dist/shared/stacks-pdcz1w1d.js.map +10 -0
  17. package/dist/shared/{stacks-fjrpnkt3.cjs → stacks-q45x3389.js} +20 -15
  18. package/dist/shared/stacks-q45x3389.js.map +10 -0
  19. package/dist/shared/{stacks-hxp7v905.js → stacks-refg7hca.js} +7 -5
  20. package/dist/shared/{stacks-hxp7v905.js.map → stacks-refg7hca.js.map} +2 -2
  21. package/dist/shared/{stacks-dmrvk1mz.js → stacks-y9w78e2b.js} +15 -6
  22. package/dist/shared/{stacks-jcgvn5v5.cjs.map → stacks-y9w78e2b.js.map} +3 -3
  23. package/dist/shared/stacks-yetejw9x.cjs +16 -0
  24. package/dist/shared/stacks-yetejw9x.cjs.map +10 -0
  25. package/dist/src/actions/index.js +12 -8
  26. package/dist/src/actions/index.js.map +1 -1
  27. package/dist/src/bns/index.js +5 -4
  28. package/dist/src/bns/index.js.map +2 -2
  29. package/dist/src/connect/index.cjs +47 -6
  30. package/dist/src/connect/index.cjs.map +8 -4
  31. package/dist/src/connect/index.js +47 -6
  32. package/dist/src/connect/index.js.map +8 -4
  33. package/dist/src/index.js +11 -7
  34. package/dist/src/index.js.map +2 -2
  35. package/dist/src/pox/index.js +5 -4
  36. package/dist/src/pox/index.js.map +2 -2
  37. package/dist/src/pox5/index.cjs +513 -0
  38. package/dist/src/pox5/index.cjs.map +16 -0
  39. package/dist/src/pox5/index.d.cts +646 -0
  40. package/dist/src/pox5/index.d.ts +646 -0
  41. package/dist/src/pox5/index.js +540 -0
  42. package/dist/src/pox5/index.js.map +16 -0
  43. package/dist/src/sbtc/index.js +5 -4
  44. package/dist/src/sbtc/index.js.map +2 -2
  45. package/dist/src/stackingdao/index.js +5 -4
  46. package/dist/src/stackingdao/index.js.map +2 -2
  47. package/dist/src/tools/btc/index.cjs +6 -5
  48. package/dist/src/tools/btc/index.cjs.map +3 -3
  49. package/dist/src/tools/btc/index.d.cts +2 -1
  50. package/dist/src/tools/btc/index.d.ts +2 -1
  51. package/dist/src/tools/btc/index.js +6 -5
  52. package/dist/src/tools/btc/index.js.map +3 -3
  53. package/dist/src/tools/index.cjs +323 -43
  54. package/dist/src/tools/index.cjs.map +10 -9
  55. package/dist/src/tools/index.js +323 -46
  56. package/dist/src/tools/index.js.map +10 -9
  57. package/dist/src/x402/index.js +2 -2
  58. package/package.json +7 -2
  59. package/dist/shared/stacks-3vyvtahh.js.map +0 -11
  60. package/dist/shared/stacks-fjrpnkt3.cjs.map +0 -11
  61. /package/dist/shared/{stacks-f66v961k.js.map → stacks-1k0kmpcw.js.map} +0 -0
@@ -0,0 +1,540 @@
1
+ import {
2
+ BITCOIN_NETWORK_PARAMS
3
+ } from "../../shared/stacks-0cdm20eh.js";
4
+ import {
5
+ bech32
6
+ } from "../../shared/stacks-5nmz5ad9.js";
7
+ import {
8
+ multicall
9
+ } from "../../shared/stacks-f0hfqaj5.js";
10
+ import {
11
+ callContract
12
+ } from "../../shared/stacks-q45x3389.js";
13
+ import {
14
+ readContract
15
+ } from "../../shared/stacks-msmgyerb.js";
16
+ import"../../shared/stacks-y9w78e2b.js";
17
+ import"../../shared/stacks-fh48neva.js";
18
+ import"../../shared/stacks-709tra19.js";
19
+ import"../../shared/stacks-ssndnbbd.js";
20
+ import {
21
+ Cl,
22
+ serializeCVBytes
23
+ } from "../../shared/stacks-2mm20wqf.js";
24
+ import"../../shared/stacks-azp00pve.js";
25
+ import {
26
+ bytesToHex,
27
+ concatBytes,
28
+ hexToBytes
29
+ } from "../../shared/stacks-qs5fzts5.js";
30
+ import"../../shared/stacks-cfazrteq.js";
31
+
32
+ // src/pox5/constants.ts
33
+ var POX5_CONTRACT_NAME = "pox-5";
34
+ var POX5_ACTIVATION_BURN_HEIGHT_MAINNET = 960230;
35
+ var BOND_LENGTH_CYCLES = 12;
36
+ var BOND_GAP_CYCLES = 2;
37
+ var MAX_NUM_CYCLES = 96;
38
+ var POX5_SIGNER_DOMAIN = {
39
+ name: "pox-5-signer",
40
+ version: "1.0.0"
41
+ };
42
+ var C_SCRIPT_NUM_MAX = 549755813888n;
43
+ var BITCOIN_LOCKTIME_THRESHOLD = 500000000n;
44
+
45
+ // src/pox5/activation.ts
46
+ async function getPox5Activation(client) {
47
+ const info = await client.request("/v2/pox", {
48
+ method: "GET"
49
+ });
50
+ const entry = info.contract_versions?.find((v) => v.contract_id.endsWith(`.${POX5_CONTRACT_NAME}`));
51
+ if (!entry)
52
+ return;
53
+ return {
54
+ contractId: entry.contract_id,
55
+ activationBurnchainBlockHeight: entry.activation_burnchain_block_height,
56
+ firstRewardCycleId: entry.first_reward_cycle_id
57
+ };
58
+ }
59
+ async function isPox5Active(client) {
60
+ const info = await client.request("/v2/pox", {
61
+ method: "GET"
62
+ });
63
+ const entry = info.contract_versions?.find((v) => v.contract_id.endsWith(`.${POX5_CONTRACT_NAME}`));
64
+ if (!entry || typeof info.current_burnchain_block_height !== "number")
65
+ return false;
66
+ return info.current_burnchain_block_height >= entry.activation_burnchain_block_height;
67
+ }
68
+ async function assertPox5Active(client) {
69
+ if (!await isPox5Active(client)) {
70
+ throw new Error("pox-5 is not active on this chain yet (Epoch 4.0 activates at Bitcoin block 960,230 on mainnet, ~2026-07-29). " + "Check getPox5Activation(client) for this network's activation height.");
71
+ }
72
+ }
73
+ // src/pox5/cycles.ts
74
+ function burnHeightToRewardCycle(burnHeight, params) {
75
+ if (burnHeight < params.firstBurnchainBlockHeight) {
76
+ throw new Error(`burnHeight ${burnHeight} precedes first burnchain block ${params.firstBurnchainBlockHeight}`);
77
+ }
78
+ return Math.floor((burnHeight - params.firstBurnchainBlockHeight) / params.rewardCycleLength);
79
+ }
80
+ function rewardCycleToBurnHeight(cycle, params) {
81
+ return params.firstBurnchainBlockHeight + cycle * params.rewardCycleLength;
82
+ }
83
+ function bondPeriodToRewardCycle(bondIndex, params) {
84
+ return params.firstBondPeriodCycle + bondIndex * BOND_GAP_CYCLES;
85
+ }
86
+ function bondPeriodToBurnHeight(bondIndex, params) {
87
+ return rewardCycleToBurnHeight(bondPeriodToRewardCycle(bondIndex, params), params);
88
+ }
89
+ function bondUnlockCycle(bondIndex, params) {
90
+ return bondPeriodToRewardCycle(bondIndex, params) + BOND_LENGTH_CYCLES;
91
+ }
92
+ function burnHeightToDistributionIndex(burnHeight, params) {
93
+ return Math.floor((burnHeight - params.firstBurnchainBlockHeight) / Math.floor(params.rewardCycleLength / 2));
94
+ }
95
+ function isInPreparePhase(burnHeight, params) {
96
+ const offset = (burnHeight - params.firstBurnchainBlockHeight) % params.rewardCycleLength;
97
+ return offset >= params.rewardCycleLength - params.prepareCycleLength;
98
+ }
99
+ function bondPhaseAtHeight(bondIndex, burnHeight, params) {
100
+ const cycle = burnHeightToRewardCycle(burnHeight, params);
101
+ const start = bondPeriodToRewardCycle(bondIndex, params);
102
+ const unlock = bondUnlockCycle(bondIndex, params);
103
+ if (cycle < start - BOND_GAP_CYCLES)
104
+ return "too-early";
105
+ if (cycle < start)
106
+ return "open";
107
+ if (cycle < unlock)
108
+ return "locked";
109
+ return "unlocked";
110
+ }
111
+ // src/pox5/script.ts
112
+ import { sha256 } from "@noble/hashes/sha2.js";
113
+ function serializeCScriptNum(n) {
114
+ const big = typeof n === "bigint" ? n : BigInt(n);
115
+ if (big < 0n)
116
+ throw new Error("serializeCScriptNum: negative value");
117
+ if (big >= C_SCRIPT_NUM_MAX) {
118
+ throw new Error("serializeCScriptNum: n >= 2^39 (contract rejects with ERR_INVALID_UNLOCK_HEIGHT)");
119
+ }
120
+ if (big === 0n)
121
+ return new Uint8Array(0);
122
+ const out = [];
123
+ let v = big;
124
+ while (v > 0n) {
125
+ out.push(Number(v & 0xffn));
126
+ v >>= 8n;
127
+ }
128
+ if (out[out.length - 1] & 128)
129
+ out.push(0);
130
+ return Uint8Array.from(out);
131
+ }
132
+ function pushScriptBytes(bytes) {
133
+ const len = bytes.length;
134
+ if (len > 65535)
135
+ throw new Error(`pushScriptBytes: payload too large (${len} > 65535)`);
136
+ let prefix;
137
+ if (len < 76)
138
+ prefix = Uint8Array.of(len);
139
+ else if (len < 256)
140
+ prefix = Uint8Array.of(76, len);
141
+ else
142
+ prefix = Uint8Array.of(77, len & 255, len >> 8);
143
+ return concatBytes(prefix, bytes);
144
+ }
145
+ function pushCScriptNum(n) {
146
+ const big = typeof n === "bigint" ? n : BigInt(n);
147
+ if (big === 0n)
148
+ return Uint8Array.of(0);
149
+ if (big >= 1n && big <= 16n)
150
+ return Uint8Array.of(80 + Number(big));
151
+ return pushScriptBytes(serializeCScriptNum(big));
152
+ }
153
+ function stakerConsensusBuff(stxAddress) {
154
+ return serializeCVBytes(Cl.principal(stxAddress));
155
+ }
156
+ function stakerPreimage(stxAddress) {
157
+ return sha256(stakerConsensusBuff(stxAddress));
158
+ }
159
+ function toBytes(input) {
160
+ return typeof input === "string" ? hexToBytes(input) : input;
161
+ }
162
+ function buildLockupScript(opts) {
163
+ const height = BigInt(opts.unlockBurnHeight);
164
+ if (height >= BITCOIN_LOCKTIME_THRESHOLD) {
165
+ throw new Error("unlockBurnHeight >= 500,000,000 would be read by Bitcoin as a timestamp (contract rejects it)");
166
+ }
167
+ const stakerHash = sha256(stakerPreimage(opts.stxAddress));
168
+ return concatBytes(Uint8Array.of(99), pushCScriptNum(height), Uint8Array.of(177, 103), hexToBytes("82012088a820"), stakerHash, Uint8Array.of(136), toBytes(opts.earlyUnlockBytes), Uint8Array.of(104, 105), toBytes(opts.stakerUnlockBytes));
169
+ }
170
+ function buildLockupOutputScript(opts) {
171
+ return concatBytes(Uint8Array.of(0, 32), sha256(buildLockupScript(opts)));
172
+ }
173
+ function buildLockupAddress(opts, network = "mainnet") {
174
+ const hash = sha256(buildLockupScript(opts));
175
+ return bech32.encode(BITCOIN_NETWORK_PARAMS[network].hrp, [
176
+ 0,
177
+ ...bech32.toWords(hash)
178
+ ]);
179
+ }
180
+ function buildDefaultStakerUnlockBytes(publicKey) {
181
+ const pubkey = toBytes(publicKey);
182
+ if (pubkey.length !== 33)
183
+ throw new Error(`Expected 33-byte compressed pubkey, got ${pubkey.length}`);
184
+ return concatBytes(pushScriptBytes(pubkey), Uint8Array.of(172));
185
+ }
186
+ // src/pox5/grants.ts
187
+ import { secp256k1 } from "@noble/curves/secp256k1.js";
188
+ import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
189
+ var SIP018_PREFIX = hexToBytes("534950303138");
190
+ function computeSignerGrantHash(opts) {
191
+ const domain = serializeCVBytes(Cl.tuple({
192
+ name: Cl.stringAscii(POX5_SIGNER_DOMAIN.name),
193
+ version: Cl.stringAscii(POX5_SIGNER_DOMAIN.version),
194
+ "chain-id": Cl.uint(opts.chainId)
195
+ }));
196
+ const message = serializeCVBytes(Cl.tuple({
197
+ topic: Cl.stringAscii("grant-authorization"),
198
+ "signer-manager": Cl.principal(opts.signerManager),
199
+ "auth-id": Cl.uint(opts.authId)
200
+ }));
201
+ return sha2562(concatBytes(SIP018_PREFIX, sha2562(domain), sha2562(message)));
202
+ }
203
+ async function signSignerGrant(account, opts) {
204
+ const vrs = await account.sign(computeSignerGrantHash(opts));
205
+ if (vrs.length !== 65)
206
+ throw new Error(`Expected 65-byte recoverable signature, got ${vrs.length}`);
207
+ return bytesToHex(concatBytes(vrs.slice(1), vrs.slice(0, 1)));
208
+ }
209
+ function verifySignerGrant(opts) {
210
+ try {
211
+ const sig = typeof opts.signature === "string" ? hexToBytes(opts.signature) : opts.signature;
212
+ if (sig.length !== 65)
213
+ return false;
214
+ const pubkey = typeof opts.publicKey === "string" ? hexToBytes(opts.publicKey) : opts.publicKey;
215
+ const hash = computeSignerGrantHash(opts);
216
+ const recovered = secp256k1.Signature.fromBytes(sig.slice(0, 64)).addRecoveryBit(sig[64]).recoverPublicKey(hash).toBytes(true);
217
+ return bytesToHex(recovered) === bytesToHex(pubkey);
218
+ } catch {
219
+ return false;
220
+ }
221
+ }
222
+ // src/pox5/actions.ts
223
+ function pox5ContractId(client) {
224
+ const boot = client.chain?.bootAddress;
225
+ if (!boot)
226
+ throw new Error("Client must have a chain with a bootAddress");
227
+ return `${boot}.${POX5_CONTRACT_NAME}`;
228
+ }
229
+ function call(client, functionName, functionArgs, options = {}) {
230
+ return callContract(client, {
231
+ contract: pox5ContractId(client),
232
+ functionName,
233
+ functionArgs,
234
+ ...options
235
+ });
236
+ }
237
+ function read(client, functionName, functionArgs = []) {
238
+ const [address, name] = pox5ContractId(client).split(".");
239
+ return readContract(client, {
240
+ contract: `${address}.${name}`,
241
+ functionName,
242
+ args: functionArgs
243
+ });
244
+ }
245
+ function bufferCV(input) {
246
+ return typeof input === "string" ? Cl.bufferFromHex(input) : Cl.buffer(input);
247
+ }
248
+ function btcLockupCV(lockup) {
249
+ if ("sbtcSats" in lockup)
250
+ return Cl.error(Cl.uint(lockup.sbtcSats));
251
+ return Cl.ok(Cl.tuple({
252
+ outputs: Cl.list(lockup.l1Outputs.map((o) => Cl.tuple({
253
+ height: Cl.uint(o.height),
254
+ tx: bufferCV(o.tx),
255
+ "output-index": Cl.uint(o.outputIndex),
256
+ header: bufferCV(o.header),
257
+ "leaf-hashes": Cl.list(o.leafHashes.map(bufferCV)),
258
+ "tx-count": Cl.uint(o.txCount),
259
+ "tx-index": Cl.uint(o.txIndex),
260
+ amount: Cl.uint(o.amount),
261
+ "unlock-burn-height": Cl.uint(o.unlockBurnHeight)
262
+ }))),
263
+ "staker-unlock-bytes": bufferCV(lockup.stakerUnlockBytes)
264
+ }));
265
+ }
266
+ function optionalBuffer(input) {
267
+ return input === undefined ? Cl.none() : Cl.some(bufferCV(input));
268
+ }
269
+ function setupBond(client, params) {
270
+ const {
271
+ bondIndex,
272
+ targetRate,
273
+ stxValueRatio,
274
+ minUstxRatio,
275
+ earlyUnlockBytes,
276
+ allowlist,
277
+ ...tx
278
+ } = params;
279
+ return call(client, "setup-bond", [
280
+ Cl.uint(bondIndex),
281
+ Cl.uint(targetRate),
282
+ Cl.uint(stxValueRatio),
283
+ Cl.uint(minUstxRatio),
284
+ bufferCV(earlyUnlockBytes),
285
+ Cl.list(allowlist.map((a) => Cl.tuple({
286
+ staker: Cl.principal(a.staker),
287
+ "max-sats": Cl.uint(a.maxSats)
288
+ })))
289
+ ], tx);
290
+ }
291
+ function registerForBond(client, params) {
292
+ const {
293
+ bondIndex,
294
+ signerManager,
295
+ amountUstx,
296
+ btcLockup,
297
+ signerCalldata,
298
+ ...tx
299
+ } = params;
300
+ return call(client, "register-for-bond", [
301
+ Cl.uint(bondIndex),
302
+ Cl.principal(signerManager),
303
+ Cl.uint(amountUstx),
304
+ btcLockupCV(btcLockup),
305
+ optionalBuffer(signerCalldata)
306
+ ], tx);
307
+ }
308
+ function updateBondRegistration(client, params) {
309
+ const { signerManager, oldSignerManager, signerCalldata, ...tx } = params;
310
+ return call(client, "update-bond-registration", [
311
+ Cl.principal(signerManager),
312
+ Cl.principal(oldSignerManager),
313
+ optionalBuffer(signerCalldata)
314
+ ], tx);
315
+ }
316
+ function stake(client, params) {
317
+ const {
318
+ signerManager,
319
+ amountUstx,
320
+ numCycles,
321
+ startBurnHeight,
322
+ signerCalldata,
323
+ ...tx
324
+ } = params;
325
+ return call(client, "stake", [
326
+ Cl.principal(signerManager),
327
+ Cl.uint(amountUstx),
328
+ Cl.uint(numCycles),
329
+ Cl.uint(startBurnHeight),
330
+ optionalBuffer(signerCalldata)
331
+ ], tx);
332
+ }
333
+ function stakeUpdate(client, params) {
334
+ const {
335
+ signerManager,
336
+ oldSignerManager,
337
+ cyclesToExtend,
338
+ amountIncrease,
339
+ signerCalldata,
340
+ ...tx
341
+ } = params;
342
+ return call(client, "stake-update", [
343
+ Cl.principal(signerManager),
344
+ Cl.principal(oldSignerManager),
345
+ Cl.uint(cyclesToExtend),
346
+ Cl.uint(amountIncrease),
347
+ optionalBuffer(signerCalldata)
348
+ ], tx);
349
+ }
350
+ function unstake(client, params) {
351
+ const { oldSignerManager, ...tx } = params;
352
+ return call(client, "unstake", [Cl.principal(oldSignerManager)], tx);
353
+ }
354
+ function unstakeSbtc(client, params) {
355
+ const { signerManager, amountSats, ...tx } = params;
356
+ return call(client, "unstake-sbtc", [Cl.principal(signerManager), Cl.uint(amountSats)], tx);
357
+ }
358
+ function announceL1EarlyExit(client, params) {
359
+ const { staker, oldSignerManager, ...tx } = params;
360
+ return call(client, "announce-l1-early-exit", [Cl.principal(staker), Cl.principal(oldSignerManager)], tx);
361
+ }
362
+ function calculateRewards(client, params) {
363
+ const { bondPeriods, ...tx } = params;
364
+ return call(client, "calculate-rewards", [Cl.list(bondPeriods.map((p) => Cl.uint(p)))], tx);
365
+ }
366
+ function claimRewards(client, params) {
367
+ const { bondPeriods, rewardCycle, ...tx } = params;
368
+ return call(client, "claim-rewards", [Cl.list(bondPeriods.map((p) => Cl.uint(p))), Cl.uint(rewardCycle)], tx);
369
+ }
370
+ function claimStakerRewardsForSigner(client, params) {
371
+ const { staker, rewardCycle, bondIndex, ...tx } = params;
372
+ return call(client, "claim-staker-rewards-for-signer", [
373
+ Cl.principal(staker),
374
+ Cl.uint(rewardCycle),
375
+ bondIndex === undefined ? Cl.none() : Cl.some(Cl.uint(bondIndex))
376
+ ], tx);
377
+ }
378
+ function grantSignerKey(client, params) {
379
+ const { signerKey, signerManager, authId, signerSig, ...tx } = params;
380
+ return call(client, "grant-signer-key", [
381
+ bufferCV(signerKey),
382
+ Cl.principal(signerManager),
383
+ Cl.uint(authId),
384
+ bufferCV(signerSig)
385
+ ], tx);
386
+ }
387
+ function revokeSignerGrant(client, params) {
388
+ const { signerManager, signerKey, ...tx } = params;
389
+ return call(client, "revoke-signer-grant", [Cl.principal(signerManager), bufferCV(signerKey)], tx);
390
+ }
391
+ function getStakerInfo(client, staker) {
392
+ return read(client, "get-staker-info", [Cl.principal(staker)]);
393
+ }
394
+ function getBondMembership(client, staker) {
395
+ return read(client, "get-bond-membership", [Cl.principal(staker)]);
396
+ }
397
+ function getProtocolBond(client, bondIndex) {
398
+ return read(client, "get-protocol-bond", [Cl.uint(bondIndex)]);
399
+ }
400
+ function getBondAllowance(client, bondIndex, staker) {
401
+ return read(client, "get-bond-allowance", [
402
+ Cl.uint(bondIndex),
403
+ Cl.principal(staker)
404
+ ]);
405
+ }
406
+ function getTotalSbtcStakedForBond(client, bondIndex) {
407
+ return read(client, "get-total-sbtc-staked-for-bond", [Cl.uint(bondIndex)]);
408
+ }
409
+ function getStakerCustodiedSbtc(client, staker) {
410
+ return read(client, "get-staker-custodied-sbtc", [Cl.principal(staker)]);
411
+ }
412
+ function hasAnnouncedL1EarlyExit(client, bondIndex, staker) {
413
+ return read(client, "has-announced-l1-early-exit", [
414
+ Cl.uint(bondIndex),
415
+ Cl.principal(staker)
416
+ ]);
417
+ }
418
+ function getBondL1UnlockHeight(client, bondIndex) {
419
+ return read(client, "get-bond-l1-unlock-height", [Cl.uint(bondIndex)]);
420
+ }
421
+ function getSignerInfo(client, signer) {
422
+ return read(client, "get-signer-info", [Cl.principal(signer)]);
423
+ }
424
+ function verifySignerKeyGrantOnChain(client, signerManager, signerKey) {
425
+ return read(client, "verify-signer-key-grant", [
426
+ Cl.principal(signerManager),
427
+ bufferCV(signerKey)
428
+ ]);
429
+ }
430
+ function getCurrentRewardCycle(client) {
431
+ return read(client, "current-pox-reward-cycle");
432
+ }
433
+ function getFirstPox5RewardCycle(client) {
434
+ return read(client, "get-first-pox-5-reward-cycle");
435
+ }
436
+ // src/pox5/extension.ts
437
+ async function getStakerState(client, staker) {
438
+ const contract = pox5ContractId(client);
439
+ const results = await multicall(client, {
440
+ allowFailure: false,
441
+ calls: [
442
+ {
443
+ contract,
444
+ functionName: "get-staker-info",
445
+ args: [Cl.principal(staker)]
446
+ },
447
+ {
448
+ contract,
449
+ functionName: "get-bond-membership",
450
+ args: [Cl.principal(staker)]
451
+ },
452
+ {
453
+ contract,
454
+ functionName: "get-staker-custodied-sbtc",
455
+ args: [Cl.principal(staker)]
456
+ },
457
+ { contract, functionName: "current-pox-reward-cycle", args: [] }
458
+ ]
459
+ });
460
+ const [stakerInfo, bondMembership, custodiedSbtc, currentCycle] = results;
461
+ return {
462
+ stakerInfo,
463
+ bondMembership,
464
+ custodiedSbtc,
465
+ currentCycle
466
+ };
467
+ }
468
+ function pox5() {
469
+ return (client) => ({
470
+ pox5: {
471
+ isActive: () => isPox5Active(client),
472
+ getActivation: () => getPox5Activation(client),
473
+ contractId: () => pox5ContractId(client),
474
+ getStakerState: (staker) => getStakerState(client, staker),
475
+ getStakerInfo: (staker) => getStakerInfo(client, staker),
476
+ getBondMembership: (staker) => getBondMembership(client, staker),
477
+ getProtocolBond: (bondIndex) => getProtocolBond(client, bondIndex),
478
+ getBondAllowance: (bondIndex, staker) => getBondAllowance(client, bondIndex, staker),
479
+ getTotalSbtcStakedForBond: (bondIndex) => getTotalSbtcStakedForBond(client, bondIndex),
480
+ getStakerCustodiedSbtc: (staker) => getStakerCustodiedSbtc(client, staker),
481
+ hasAnnouncedL1EarlyExit: (bondIndex, staker) => hasAnnouncedL1EarlyExit(client, bondIndex, staker),
482
+ getBondL1UnlockHeight: (bondIndex) => getBondL1UnlockHeight(client, bondIndex),
483
+ getSignerInfo: (signer) => getSignerInfo(client, signer),
484
+ verifySignerKeyGrant: (signerManager, signerKey) => verifySignerKeyGrantOnChain(client, signerManager, signerKey),
485
+ getCurrentRewardCycle: () => getCurrentRewardCycle(client),
486
+ getFirstRewardCycle: () => getFirstPox5RewardCycle(client),
487
+ setupBond: (params) => setupBond(client, params),
488
+ registerForBond: (params) => registerForBond(client, params),
489
+ updateBondRegistration: (params) => updateBondRegistration(client, params),
490
+ stake: (params) => stake(client, params),
491
+ stakeUpdate: (params) => stakeUpdate(client, params),
492
+ unstake: (params) => unstake(client, params),
493
+ unstakeSbtc: (params) => unstakeSbtc(client, params),
494
+ announceL1EarlyExit: (params) => announceL1EarlyExit(client, params),
495
+ calculateRewards: (params) => calculateRewards(client, params),
496
+ claimRewards: (params) => claimRewards(client, params),
497
+ claimStakerRewardsForSigner: (params) => claimStakerRewardsForSigner(client, params),
498
+ grantSignerKey: (params) => grantSignerKey(client, params),
499
+ revokeSignerGrant: (params) => revokeSignerGrant(client, params)
500
+ }
501
+ });
502
+ }
503
+ export {
504
+ verifySignerGrant,
505
+ stakerPreimage,
506
+ stakerConsensusBuff,
507
+ signSignerGrant,
508
+ serializeCScriptNum,
509
+ rewardCycleToBurnHeight,
510
+ pushScriptBytes,
511
+ pushCScriptNum,
512
+ pox5ContractId,
513
+ pox5,
514
+ isPox5Active,
515
+ isInPreparePhase,
516
+ getPox5Activation,
517
+ computeSignerGrantHash,
518
+ burnHeightToRewardCycle,
519
+ burnHeightToDistributionIndex,
520
+ buildLockupScript,
521
+ buildLockupOutputScript,
522
+ buildLockupAddress,
523
+ buildDefaultStakerUnlockBytes,
524
+ bondUnlockCycle,
525
+ bondPhaseAtHeight,
526
+ bondPeriodToRewardCycle,
527
+ bondPeriodToBurnHeight,
528
+ assertPox5Active,
529
+ POX5_SIGNER_DOMAIN,
530
+ POX5_CONTRACT_NAME,
531
+ POX5_ACTIVATION_BURN_HEIGHT_MAINNET,
532
+ MAX_NUM_CYCLES,
533
+ C_SCRIPT_NUM_MAX,
534
+ BOND_LENGTH_CYCLES,
535
+ BOND_GAP_CYCLES,
536
+ BITCOIN_LOCKTIME_THRESHOLD
537
+ };
538
+
539
+ //# debugId=922D98973998F42C64756E2164756E21
540
+ //# sourceMappingURL=index.js.map